]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/IA32/MpFuncs.asm
Fix the risk of AP stack conflict.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / IA32 / MpFuncs.asm
CommitLineData
768e2a90 1;------------------------------------------------------------------------------\r
2; IA32 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.686p\r
16.model flat \r
17.code \r
18\r
19include AsmInclude.inc\r
20;-------------------------------------------------------------------------------------\r
21FJMP32 MACRO Selector, Offset\r
22 DB 066h\r
23 DB 067h\r
24 DB 0EAh ; far jump\r
25 DD Offset ; 32-bit offset\r
26 DW Selector ; 16-bit selector\r
27 ENDM\r
28\r
29;-------------------------------------------------------------------------------------\r
30;RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
31;procedure serializes all the AP processors through an Init sequence. It must be\r
32;noted that APs arrive here very raw...ie: real mode, no stack.\r
33;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
34;IS IN MACHINE CODE.\r
35;-------------------------------------------------------------------------------------\r
36;RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
37\r
38RendezvousFunnelProc PROC near C PUBLIC\r
39RendezvousFunnelProcStart::\r
40\r
41\r
42; At this point CS = 0x(vv00) and ip= 0x0.\r
43\r
44 db 8ch, 0c8h ; mov ax, cs\r
45 db 8eh, 0d8h ; mov ds, ax\r
46 db 8eh, 0c0h ; mov es, ax\r
47 db 8eh, 0d0h ; mov ss, ax \r
48 db 33h, 0c0h ; xor ax, ax\r
49 db 8eh, 0e0h ; mov fs, ax\r
50 db 8eh, 0e8h ; mov gs, ax\r
51\r
52; Switch to flat mode.\r
53\r
54 db 0BEh\r
55 dw BufferStart ; mov si, BufferStart\r
56 db 66h, 8Bh, 0Ch ; mov ecx,dword ptr [si] ; ECX is keeping the start address of wakeup buffer\r
57\r
58 db 0FAh ; cli\r
59 db 0BEh\r
60 dw GdtrProfile ; mov si, GdtrProfile\r
61 db 66h ; db 66h\r
62 db 2Eh,0Fh, 01h, 14h ; lgdt fword ptr cs:[si]\r
de243ee4 63\r
64 db 0BEh\r
65 dw IdtrProfile ; mov si, IdtrProfile\r
66 db 66h ; db 66h\r
67 db 2Eh,0Fh, 01h, 1Ch ; lidt fword ptr cs:[si]\r
768e2a90 68 \r
69 db 33h, 0C0h ; xor ax, ax\r
70 db 8Eh, 0D8h ; mov ds, ax\r
71 db 0Fh, 20h, 0C0h ; mov eax, cr0 ; Get control register 0\r
72 db 66h, 83h, 0C8h, 01h ; or eax, 000000001h ; Set PE bit (bit #0)\r
73 db 0Fh, 22h, 0C0h ; mov cr0, eax\r
74\r
75\r
76FLAT32_JUMP::\r
77 FJMP32 010h,0h ; Far jmp using code segment descriptor\r
78\r
79ProtectedModeStart:: ; protected mode entry point\r
80\r
81 mov ax, 8h\r
82 mov ds, ax\r
83 mov es, ax\r
84 mov fs, ax\r
85 mov gs, ax\r
86 mov ss, ax ; Flat mode setup.\r
87\r
d6d858c4 88 ;\r
89 ; ProgramStack\r
90 ;\r
91 mov ecx, 1bh ; Read IA32_APIC_BASE MSR\r
92 rdmsr\r
93 and eax, 0fffff000h\r
94 add eax, 20h\r
95 mov ebx, dword ptr [eax]\r
96 shr ebx, 24\r
97 \r
98 xor ecx, ecx\r
768e2a90 99 mov edi, esi\r
d6d858c4 100 add edi, ProcessorNumber\r
101 mov ecx, dword ptr [edi + 4 * ebx] ; ECX = CpuNumber\r
768e2a90 102\r
103 mov edi, esi\r
104 add edi, StackSize\r
105 mov eax, dword ptr [edi]\r
d6d858c4 106 inc ecx\r
107 mul ecx ; EAX = StackSize * (CpuNumber + 1)\r
108\r
768e2a90 109 mov edi, esi\r
110 add edi, StackStart\r
d6d858c4 111 mov ebx, dword ptr [edi]\r
112 add eax, ebx ; EAX = StackStart + StackSize * (CpuNumber + 1)\r
768e2a90 113\r
d6d858c4 114 mov esp, eax\r
768e2a90 115\r
116 ;\r
117 ; Call C Function\r
118 ;\r
119 mov edi, esi\r
120 add edi, RendezvousProc\r
121 mov ebx, dword ptr [edi]\r
122\r
123 test ebx, ebx\r
124 jz GoToSleep\r
125 call ebx ; Call C function\r
126\r
127GoToSleep::\r
128\r
129 cli\r
130 hlt\r
131 jmp $-2\r
132 \r
133RendezvousFunnelProc ENDP\r
134RendezvousFunnelProcEnd::\r
135;-------------------------------------------------------------------------------------\r
136; AsmGetAddressMap (&AddressMap);\r
137;-------------------------------------------------------------------------------------\r
138AsmGetAddressMap PROC near C PUBLIC\r
139\r
140 pushad\r
141 mov ebp,esp\r
142 \r
143 mov ebx, dword ptr [ebp+24h]\r
144 mov dword ptr [ebx], RendezvousFunnelProcStart\r
145 mov dword ptr [ebx+4h], ProtectedModeStart - RendezvousFunnelProcStart\r
146 mov dword ptr [ebx+8h], FLAT32_JUMP - RendezvousFunnelProcStart\r
147 mov dword ptr [ebx+0ch], 0\r
148 mov dword ptr [ebx+10h], 0\r
149 mov dword ptr [ebx+14h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
150 \r
151 popad\r
152 ret\r
153AsmGetAddressMap ENDP\r
154\r
155END\r