]>
Commit | Line | Data |
---|---|---|
768e2a90 | 1 | #------------------------------------------------------------------------------\r |
2 | # X64 assembly file for AP startup vector.\r | |
3 | #\r | |
de243ee4 | 4 | # Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r |
584d5652 | 5 | # This program and the accompanying materials\r |
768e2a90 | 6 | # are licensed and made available under the terms and conditions of the BSD License\r |
7 | # which accompanies this distribution. The full text of the license may be found at\r | |
8 | # http://opensource.org/licenses/bsd-license.php\r | |
9 | #\r | |
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | #\r | |
13 | #------------------------------------------------------------------------------\r | |
14 | \r | |
15 | \r | |
271d2c7f | 16 | .set VacantFlag, 0x0\r |
17 | .set NotVacantFlag, 0xff\r | |
18 | \r | |
19 | .set LockLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r | |
20 | .set StackStartAddressLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08\r | |
21 | .set StackSizeLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r | |
22 | .set CProcedureLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x18\r | |
23 | .set GdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x20\r | |
24 | .set IdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x2A\r | |
25 | .set BufferStartLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x34\r | |
26 | .set Cr3OffsetLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x38\r | |
27 | .set ProcessorNumberLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x38\r | |
768e2a90 | 28 | \r |
29 | #-------------------------------------------------------------------------------------\r | |
30 | \r | |
31 | #-------------------------------------------------------------------------------------\r | |
32 | #RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r | |
33 | #procedure serializes all the AP processors through an Init sequence. It must be\r | |
34 | #noted that APs arrive here very raw...ie: real mode, no stack.\r | |
35 | #ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r | |
36 | #IS IN MACHINE CODE.\r | |
37 | #-------------------------------------------------------------------------------------\r | |
38 | #RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r | |
39 | \r | |
40 | .text\r | |
41 | \r | |
42 | ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)\r | |
43 | ASM_PFX(RendezvousFunnelProc):\r | |
44 | RendezvousFunnelProcStart:\r | |
45 | \r | |
46 | # At this point CS = 0x(vv00) and ip= 0x0.\r | |
47 | \r | |
48 | .byte 0x8c,0xc8 # mov ax, cs\r | |
49 | .byte 0x8e,0xd8 # mov ds, ax\r | |
50 | .byte 0x8e,0xc0 # mov es, ax\r | |
51 | .byte 0x8e,0xd0 # mov ss, ax \r | |
52 | .byte 0x33,0xc0 # xor ax, ax\r | |
53 | .byte 0x8e,0xe0 # mov fs, ax\r | |
54 | .byte 0x8e,0xe8 # mov gs, ax\r | |
55 | \r | |
56 | # Switch to flat mode.\r | |
57 | \r | |
58 | .byte 0xBE\r | |
59 | .word BufferStartLocation\r | |
60 | .byte 0x66,0x8B,0x14 # mov edx,dword ptr [si] ; EDX is keeping the start address of wakeup buffer\r | |
61 | \r | |
62 | .byte 0xBE\r | |
63 | .word Cr3OffsetLocation\r | |
64 | .byte 0x66,0x8B,0xC # mov ecx,dword ptr [si] ; ECX is keeping the value of CR3\r | |
65 | \r | |
66 | .byte 0xBE\r | |
67 | .word GdtrLocation\r | |
68 | .byte 0x66 # db 66h\r | |
69 | .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]\r | |
70 | \r | |
de243ee4 | 71 | .byte 0xBE\r |
72 | .word IdtrLocation\r | |
73 | .byte 0x66 # db 66h\r | |
74 | .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]\r | |
75 | \r | |
768e2a90 | 76 | .byte 0x33,0xC0 # xor ax, ax\r |
77 | .byte 0x8E,0xD8 # mov ds, ax\r | |
78 | \r | |
79 | .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0\r | |
80 | .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)\r | |
81 | .byte 0xF,0x22,0xC0 # mov cr0, eax\r | |
82 | \r | |
83 | FLAT32_JUMP:\r | |
84 | \r | |
85 | .byte 0x66,0x67,0xEA # far jump\r | |
86 | .long 0x0 # 32-bit offset\r | |
87 | .word 0x20 # 16-bit selector\r | |
88 | \r | |
89 | ProtectedModeStart:\r | |
90 | \r | |
91 | .byte 0x66,0xB8,0x18,0x0 # mov ax, 18h\r | |
92 | .byte 0x66,0x8E,0xD8 # mov ds, ax\r | |
93 | .byte 0x66,0x8E,0xC0 # mov es, ax\r | |
94 | .byte 0x66,0x8E,0xE0 # mov fs, ax\r | |
95 | .byte 0x66,0x8E,0xE8 # mov gs, ax\r | |
96 | .byte 0x66,0x8E,0xD0 # mov ss, ax ; Flat mode setup.\r | |
97 | \r | |
98 | .byte 0xF,0x20,0xE0 # mov eax, cr4\r | |
99 | .byte 0xF,0xBA,0xE8,0x5 # bts eax, 5\r | |
100 | .byte 0xF,0x22,0xE0 # mov cr4, eax\r | |
101 | \r | |
102 | .byte 0xF,0x22,0xD9 # mov cr3, ecx\r | |
103 | \r | |
104 | .byte 0x8B,0xF2 # mov esi, edx ; Save wakeup buffer address\r | |
105 | \r | |
106 | .byte 0xB9\r | |
107 | .long 0xC0000080 # mov ecx, 0c0000080h ; EFER MSR number.\r | |
108 | .byte 0xF,0x32 # rdmsr ; Read EFER.\r | |
109 | .byte 0xF,0xBA,0xE8,0x8 # bts eax, 8 ; Set LME=1.\r | |
110 | .byte 0xF,0x30 # wrmsr ; Write EFER.\r | |
111 | \r | |
112 | .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Read CR0.\r | |
113 | .byte 0xF,0xBA,0xE8,0x1F # bts eax, 31 ; Set PG=1.\r | |
114 | .byte 0xF,0x22,0xC0 # mov cr0, eax ; Write CR0.\r | |
115 | \r | |
116 | LONG_JUMP:\r | |
117 | \r | |
118 | .byte 0x67,0xEA # far jump\r | |
119 | .long 0x0 # 32-bit offset\r | |
120 | .word 0x38 # 16-bit selector\r | |
121 | \r | |
122 | LongModeStart:\r | |
123 | \r | |
124 | movw $0x30,%ax\r | |
125 | .byte 0x66\r | |
126 | movw %ax,%ds\r | |
127 | .byte 0x66\r | |
128 | movw %ax,%es\r | |
129 | .byte 0x66\r | |
130 | movw %ax,%ss\r | |
131 | \r | |
d6d858c4 | 132 | #\r |
133 | # ProgramStack\r | |
134 | #\r | |
135 | movl $0x1b, %ecx\r | |
136 | rdmsr\r | |
137 | andl $0xfffff000, %eax\r | |
138 | addl $0x20, %eax\r | |
139 | movl (%eax), %ebx\r | |
140 | shrl $24, %ebx\r | |
141 | \r | |
142 | xorq %rcx, %rcx\r | |
143 | movl %esi,%edi\r | |
144 | addl $ProcessorNumberLocation, %edi\r | |
145 | movl (%edi, %ebx, 4), %ecx\r | |
768e2a90 | 146 | \r |
d6d858c4 | 147 | movl %esi,%edi\r |
148 | addl $StackSizeLocation, %edi\r | |
768e2a90 | 149 | movq (%edi), %rax\r |
d6d858c4 | 150 | incq %rcx\r |
151 | mulq %rcx\r | |
768e2a90 | 152 | \r |
d6d858c4 | 153 | movl %esi,%edi\r |
154 | addl $StackStartAddressLocation, %edi\r | |
155 | movq (%edi), %rbx\r | |
156 | addq %rbx, %rax\r | |
768e2a90 | 157 | \r |
d6d858c4 | 158 | movq %rax, %rsp\r |
768e2a90 | 159 | \r |
160 | #\r | |
161 | # Call C Function\r | |
162 | #\r | |
163 | movl %esi,%edi\r | |
164 | addl $CProcedureLocation, %edi\r | |
165 | movq (%edi), %rax\r | |
166 | \r | |
167 | testq %rax, %rax\r | |
168 | jz GoToSleep\r | |
169 | \r | |
170 | subq $0x20, %rsp\r | |
171 | call *%rax\r | |
172 | addq $0x20, %rsp\r | |
173 | \r | |
174 | GoToSleep:\r | |
175 | \r | |
176 | cli\r | |
177 | hlt\r | |
178 | jmp .-2\r | |
179 | \r | |
180 | RendezvousFunnelProcEnd:\r | |
181 | \r | |
182 | \r | |
183 | #-------------------------------------------------------------------------------------\r | |
184 | # AsmGetAddressMap (&AddressMap);\r | |
185 | #-------------------------------------------------------------------------------------\r | |
186 | # comments here for definition of address map\r | |
187 | ASM_GLOBAL ASM_PFX(AsmGetAddressMap)\r | |
188 | ASM_PFX(AsmGetAddressMap):\r | |
271d2c7f | 189 | #ifdef __APPLE__\r |
190 | int $3\r | |
191 | #else\r | |
768e2a90 | 192 | movq $RendezvousFunnelProcStart, %rax\r |
193 | movq %rax, (%rcx)\r | |
194 | movq $(ProtectedModeStart - RendezvousFunnelProcStart), 0x08(%rcx)\r | |
195 | movq $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x10(%rcx)\r | |
196 | movq $(LongModeStart - RendezvousFunnelProcStart), 0x18(%rcx)\r | |
197 | movq $(LONG_JUMP - RendezvousFunnelProcStart), 0x20(%rcx)\r | |
198 | movq $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x28(%rcx)\r | |
271d2c7f | 199 | #endif\r |
768e2a90 | 200 | ret\r |