]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/X64/MpFuncs.S
ECP MpServicesOnFrameworkMpServicesThunk: Fix build with GCC
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / X64 / MpFuncs.S
CommitLineData
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
16.equ VacantFlag, 0x0\r
17.equ NotVacantFlag, 0xff\r
18\r
19.equ LockLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
20.equ StackStartAddressLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08\r
21.equ StackSizeLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r
22.equ CProcedureLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x18\r
23.equ GdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x20\r
19e2bfe8 24.equ IdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x2A\r
25.equ BufferStartLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x34\r
26.equ Cr3OffsetLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x38\r
768e2a90 27\r
28#-------------------------------------------------------------------------------------\r
29\r
30#-------------------------------------------------------------------------------------\r
31#RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
32#procedure serializes all the AP processors through an Init sequence. It must be\r
33#noted that APs arrive here very raw...ie: real mode, no stack.\r
34#ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
35#IS IN MACHINE CODE.\r
36#-------------------------------------------------------------------------------------\r
37#RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
38\r
39.text\r
40\r
41ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)\r
42ASM_PFX(RendezvousFunnelProc):\r
43RendezvousFunnelProcStart:\r
44\r
45# At this point CS = 0x(vv00) and ip= 0x0.\r
46\r
47 .byte 0x8c,0xc8 # mov ax, cs\r
48 .byte 0x8e,0xd8 # mov ds, ax\r
49 .byte 0x8e,0xc0 # mov es, ax\r
50 .byte 0x8e,0xd0 # mov ss, ax \r
51 .byte 0x33,0xc0 # xor ax, ax\r
52 .byte 0x8e,0xe0 # mov fs, ax\r
53 .byte 0x8e,0xe8 # mov gs, ax\r
54\r
55# Switch to flat mode.\r
56\r
57 .byte 0xBE\r
58 .word BufferStartLocation\r
59 .byte 0x66,0x8B,0x14 # mov edx,dword ptr [si] ; EDX is keeping the start address of wakeup buffer\r
60\r
61 .byte 0xBE\r
62 .word Cr3OffsetLocation\r
63 .byte 0x66,0x8B,0xC # mov ecx,dword ptr [si] ; ECX is keeping the value of CR3\r
64\r
65 .byte 0xBE\r
66 .word GdtrLocation\r
67 .byte 0x66 # db 66h\r
68 .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]\r
69\r
de243ee4 70 .byte 0xBE\r
71 .word IdtrLocation\r
72 .byte 0x66 # db 66h\r
73 .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]\r
74\r
768e2a90 75 .byte 0x33,0xC0 # xor ax, ax\r
76 .byte 0x8E,0xD8 # mov ds, ax\r
77\r
78 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0\r
79 .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)\r
80 .byte 0xF,0x22,0xC0 # mov cr0, eax\r
81\r
82FLAT32_JUMP:\r
83\r
84 .byte 0x66,0x67,0xEA # far jump\r
85 .long 0x0 # 32-bit offset\r
86 .word 0x20 # 16-bit selector\r
87\r
88ProtectedModeStart:\r
89\r
90 .byte 0x66,0xB8,0x18,0x0 # mov ax, 18h\r
91 .byte 0x66,0x8E,0xD8 # mov ds, ax\r
92 .byte 0x66,0x8E,0xC0 # mov es, ax\r
93 .byte 0x66,0x8E,0xE0 # mov fs, ax\r
94 .byte 0x66,0x8E,0xE8 # mov gs, ax\r
95 .byte 0x66,0x8E,0xD0 # mov ss, ax ; Flat mode setup.\r
96\r
97 .byte 0xF,0x20,0xE0 # mov eax, cr4\r
98 .byte 0xF,0xBA,0xE8,0x5 # bts eax, 5\r
99 .byte 0xF,0x22,0xE0 # mov cr4, eax\r
100\r
101 .byte 0xF,0x22,0xD9 # mov cr3, ecx\r
102\r
103 .byte 0x8B,0xF2 # mov esi, edx ; Save wakeup buffer address\r
104\r
105 .byte 0xB9\r
106 .long 0xC0000080 # mov ecx, 0c0000080h ; EFER MSR number.\r
107 .byte 0xF,0x32 # rdmsr ; Read EFER.\r
108 .byte 0xF,0xBA,0xE8,0x8 # bts eax, 8 ; Set LME=1.\r
109 .byte 0xF,0x30 # wrmsr ; Write EFER.\r
110\r
111 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Read CR0.\r
112 .byte 0xF,0xBA,0xE8,0x1F # bts eax, 31 ; Set PG=1.\r
113 .byte 0xF,0x22,0xC0 # mov cr0, eax ; Write CR0.\r
114\r
115LONG_JUMP:\r
116\r
117 .byte 0x67,0xEA # far jump\r
118 .long 0x0 # 32-bit offset\r
119 .word 0x38 # 16-bit selector\r
120\r
121LongModeStart:\r
122\r
123 movw $0x30,%ax\r
124 .byte 0x66\r
125 movw %ax,%ds\r
126 .byte 0x66\r
127 movw %ax,%es\r
128 .byte 0x66\r
129 movw %ax,%ss\r
130\r
131 movl %esi, %edi\r
132 addl $LockLocation, %edi\r
133 movb $NotVacantFlag, %al\r
134TestLock:\r
135 xchgb (%edi), %al\r
136 cmpb $NotVacantFlag, %al\r
137 jz TestLock\r
138\r
139ProgramStack:\r
140\r
141 movl %esi, %edi\r
142 addl $StackSizeLocation, %edi \r
143 movq (%edi), %rax\r
144 movl %esi, %edi\r
145 addl $StackStartAddressLocation, %edi\r
146 addq (%edi), %rax\r
147 movq %rax, %rsp\r
148 movq %rax, (%edi) \r
149\r
150Releaselock:\r
151\r
152 movb $VacantFlag, %al\r
153 movl %esi, %edi\r
154 addl $LockLocation, %edi\r
155 xchgb (%edi), %al\r
156\r
157 #\r
158 # Call C Function\r
159 #\r
160 movl %esi,%edi\r
161 addl $CProcedureLocation, %edi\r
162 movq (%edi), %rax\r
163\r
164 testq %rax, %rax\r
165 jz GoToSleep\r
166\r
167 subq $0x20, %rsp\r
168 call *%rax\r
169 addq $0x20, %rsp\r
170\r
171GoToSleep:\r
172\r
173 cli\r
174 hlt\r
175 jmp .-2\r
176\r
177RendezvousFunnelProcEnd:\r
178\r
179\r
180#-------------------------------------------------------------------------------------\r
181# AsmGetAddressMap (&AddressMap);\r
182#-------------------------------------------------------------------------------------\r
183# comments here for definition of address map\r
184ASM_GLOBAL ASM_PFX(AsmGetAddressMap)\r
185ASM_PFX(AsmGetAddressMap):\r
186\r
187 movq $RendezvousFunnelProcStart, %rax\r
188 movq %rax, (%rcx)\r
189 movq $(ProtectedModeStart - RendezvousFunnelProcStart), 0x08(%rcx)\r
190 movq $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x10(%rcx)\r
191 movq $(LongModeStart - RendezvousFunnelProcStart), 0x18(%rcx)\r
192 movq $(LONG_JUMP - RendezvousFunnelProcStart), 0x20(%rcx)\r
193 movq $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x28(%rcx)\r
194\r
195 ret\r