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
41 ENTRY(trampoline_start)
42 cli # We should be safe anyway
43 wbinvd
44
45 LJMPW_RM(1f)
46 1:
47 mov %cs, %ax # Code and data in the same place
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 # Verify the cpu supports long mode
56 testl %eax, %eax # Check for return code
57 jnz no_longmode
58
59
60
61
62
63
64
65
66 lidtl tr_idt # load idt with 0, 0
67 lgdtl tr_gdt # load gdt with whatever is appropriate
68
69 movw $__KERNEL_DS, %dx # Data segment descriptor
70
71
72 movl $X86_CR0_PE, %eax # protected mode (PE) bit
73 movl %eax, %cr0 # into protected mode
74
75
76 ljmpl $__KERNEL32_CS, $pa_startup_32
77
78 no_longmode:
79 hlt
80 jmp no_longmode
81 #include "../kernel/verify_cpu.S"
82
83 .section ".text32","ax"
84 .code32
85 .balign 4
86 ENTRY(startup_32)
87 movl %edx, %ss
88 addl $pa_real_mode_base, %esp
89 movl %edx, %ds
90 movl %edx, %es
91 movl %edx, %fs
92 movl %edx, %gs
93
94
95
96
97
98
99
100
101
102 btl $TH_FLAGS_SME_ACTIVE_BIT, pa_tr_flags
103 jnc .Ldone
104 movl $MSR_K8_SYSCFG, %ecx
105 rdmsr
106 bts $MSR_K8_SYSCFG_MEM_ENCRYPT_BIT, %eax
107 jc .Ldone
108
109
110
111
112
113 wrmsr
114 .Ldone:
115
116 movl pa_tr_cr4, %eax
117 movl %eax, %cr4 # Enable PAE mode
118
119
120 movl $pa_trampoline_pgd, %eax
121 movl %eax, %cr3
122
123
124 movl pa_tr_efer, %eax
125 movl pa_tr_efer + 4, %edx
126 movl $MSR_EFER, %ecx
127 wrmsr
128
129
130 movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
131 movl %eax, %cr0
132
133
134
135
136
137
138
139 ljmpl $__KERNEL_CS, $pa_startup_64
140
141 .section ".text64","ax"
142 .code64
143 .balign 4
144 ENTRY(startup_64)
145
146 jmpq *tr_start(%rip)
147
148 .section ".rodata","a"
149
150
151 .balign 16
152 .globl tr_gdt
153 tr_gdt:
154 .short tr_gdt_end - tr_gdt - 1 # gdt limit
155 .long pa_tr_gdt
156 .short 0
157 .quad 0x00cf9b000000ffff # __KERNEL32_CS
158 .quad 0x00af9b000000ffff # __KERNEL_CS
159 .quad 0x00cf93000000ffff # __KERNEL_DS
160 tr_gdt_end:
161
162 .bss
163 .balign PAGE_SIZE
164 GLOBAL(trampoline_pgd) .space PAGE_SIZE
165
166 .balign 8
167 GLOBAL(trampoline_header)
168 tr_start: .space 8
169 GLOBAL(tr_efer) .space 8
170 GLOBAL(tr_cr4) .space 4
171 GLOBAL(tr_flags) .space 4
172 END(trampoline_header)
173
174 #include "trampoline_common.S"