1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/linkage.h>
29#include <asm/pgtable_types.h>
30#include <asm/page_types.h>
31#include <asm/msr.h>
32#include <asm/segment.h>
33#include <asm/processor-flags.h>
34#include <asm/realmode.h>
35#include "realmode.h"
36
37 .text
38 .code16
39
40 .balign PAGE_SIZE
41SYM_CODE_START(trampoline_start)
42 cli
43 wbinvd
44
45 LJMPW_RM(1f)
461:
47 mov %cs, %ax
48 mov %ax, %ds
49 mov %ax, %es
50 mov %ax, %ss
51
52
53 movl $rm_stack_end, %esp
54
55 call verify_cpu
56 testl %eax, %eax
57 jnz no_longmode
58
59
60
61
62
63
64
65
66 lidtl tr_idt
67 lgdtl tr_gdt
68
69 movw $__KERNEL_DS, %dx
70
71
72 movl $X86_CR0_PE, %eax
73 movl %eax, %cr0
74
75
76 ljmpl $__KERNEL32_CS, $pa_startup_32
77
78no_longmode:
79 hlt
80 jmp no_longmode
81SYM_CODE_END(trampoline_start)
82
83#include "../kernel/verify_cpu.S"
84
85 .section ".text32","ax"
86 .code32
87 .balign 4
88SYM_CODE_START(startup_32)
89 movl %edx, %ss
90 addl $pa_real_mode_base, %esp
91 movl %edx, %ds
92 movl %edx, %es
93 movl %edx, %fs
94 movl %edx, %gs
95
96
97
98
99
100
101
102
103
104 btl $TH_FLAGS_SME_ACTIVE_BIT, pa_tr_flags
105 jnc .Ldone
106 movl $MSR_K8_SYSCFG, %ecx
107 rdmsr
108 bts $MSR_K8_SYSCFG_MEM_ENCRYPT_BIT, %eax
109 jc .Ldone
110
111
112
113
114
115 wrmsr
116.Ldone:
117
118 movl pa_tr_cr4, %eax
119 movl %eax, %cr4
120
121
122 movl $pa_trampoline_pgd, %eax
123 movl %eax, %cr3
124
125
126 movl pa_tr_efer, %eax
127 movl pa_tr_efer + 4, %edx
128 movl $MSR_EFER, %ecx
129 wrmsr
130
131
132 movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
133 movl %eax, %cr0
134
135
136
137
138
139
140
141 ljmpl $__KERNEL_CS, $pa_startup_64
142SYM_CODE_END(startup_32)
143
144 .section ".text64","ax"
145 .code64
146 .balign 4
147SYM_CODE_START(startup_64)
148
149 jmpq *tr_start(%rip)
150SYM_CODE_END(startup_64)
151
152 .section ".rodata","a"
153
154
155 .balign 16
156SYM_DATA_START(tr_gdt)
157 .short tr_gdt_end - tr_gdt - 1
158 .long pa_tr_gdt
159 .short 0
160 .quad 0x00cf9b000000ffff
161 .quad 0x00af9b000000ffff
162 .quad 0x00cf93000000ffff
163SYM_DATA_END_LABEL(tr_gdt, SYM_L_LOCAL, tr_gdt_end)
164
165 .bss
166 .balign PAGE_SIZE
167SYM_DATA(trampoline_pgd, .space PAGE_SIZE)
168
169 .balign 8
170SYM_DATA_START(trampoline_header)
171 SYM_DATA_LOCAL(tr_start, .space 8)
172 SYM_DATA(tr_efer, .space 8)
173 SYM_DATA(tr_cr4, .space 4)
174 SYM_DATA(tr_flags, .space 4)
175SYM_DATA_END(trampoline_header)
176
177#include "trampoline_common.S"
178