]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/IA32/MpFuncs.S
Fix the risk of AP stack conflict.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / IA32 / MpFuncs.S
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
830db412 15#define VacantFlag 0x0\r
16#define NotVacantFlag 0xff\r
768e2a90 17\r
830db412 18#define LockLocation RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
19#define StackStart RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x04\r
20#define StackSize RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08\r
21#define RendezvousProc RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x0C\r
22#define GdtrProfile RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r
23#define IdtrProfile RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x16\r
24#define BufferStart RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x1C\r
d6d858c4 25#define ProcessorNumber, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x20\r
768e2a90 26\r
27#-------------------------------------------------------------------------------------\r
28#RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
29#procedure serializes all the AP processors through an Init sequence. It must be\r
30#noted that APs arrive here very raw...ie: real mode, no stack.\r
31#ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
32#IS IN MACHINE CODE.\r
33#-------------------------------------------------------------------------------------\r
34#RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
35\r
36ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)\r
37ASM_PFX(RendezvousFunnelProc):\r
38RendezvousFunnelProcStart:\r
39\r
40\r
41# At this point CS = 0x(vv00) and ip= 0x0.\r
42\r
43 .byte 0x8c,0xc8 # mov ax, cs\r
44 .byte 0x8e,0xd8 # mov ds, ax\r
45 .byte 0x8e,0xc0 # mov es, ax\r
46 .byte 0x8e,0xd0 # mov ss, ax \r
47 .byte 0x33,0xc0 # xor ax, ax\r
48 .byte 0x8e,0xe0 # mov fs, ax\r
49 .byte 0x8e,0xe8 # mov gs, ax\r
50\r
51# Switch to flat mode.\r
52\r
53 .byte 0xBE\r
54 .word BufferStart\r
55 .byte 0x66,0x8B,0xC # mov ecx,dword ptr [si] ; ECX is keeping the start address of wakeup buffer\r
56\r
57 .byte 0xFA # cli\r
58 .byte 0xBE\r
59 .word GdtrProfile\r
60 .byte 0x66 # db 66h\r
61 .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]\r
62\r
de243ee4 63 .byte 0xBE\r
64 .word IdtrProfile\r
65 .byte 0x66 # db 66h\r
66 .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]\r
67\r
768e2a90 68 .byte 0x33,0xC0 # xor ax, ax\r
69 .byte 0x8E,0xD8 # mov ds, ax\r
70 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0\r
71 .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)\r
72 .byte 0xF,0x22,0xC0 # mov cr0, eax\r
73\r
74\r
75#step-4:\r
76\r
77FLAT32_JUMP:\r
78 .byte 0x66\r
79 .byte 0x67\r
80 .byte 0xEA # far jump\r
81 .long 0x0\r
82 .word 0x10\r
83\r
84ProtectedModeStart: # protected mode entry point\r
85\r
86 movw $0x8,%ax\r
87 .byte 0x66\r
88 movw %ax,%ds\r
89 .byte 0x66\r
90 movw %ax,%es\r
91 .byte 0x66\r
92 movw %ax,%fs\r
93 .byte 0x66\r
94 movw %ax,%gs\r
95 .byte 0x66\r
96 movw %ax,%ss # Flat mode setup.\r
97\r
d6d858c4 98 #\r
99 # ProgramStack\r
100 #\r
101 movl $0x1b, %ecx\r
102 rdmsr\r
103 andl $0xfffff000, %eax\r
104 addl $0x20, %eax\r
105 movl (%eax), %ebx\r
106 shrl $24, %ebx\r
107 \r
108 xorl %ecx, %ecx\r
768e2a90 109 movl %esi,%edi\r
d6d858c4 110 addl $ProcessorNumber, %edi\r
111 movl (%edi, %ebx, 4), %ecx\r
112\r
768e2a90 113 movl %esi,%edi\r
114 addl $StackSize, %edi\r
115 movl (%edi), %eax\r
d6d858c4 116 incl %ecx\r
117 mull %ecx\r
118\r
768e2a90 119 movl %esi,%edi\r
120 addl $StackStart, %edi\r
d6d858c4 121 movl (%edi), %ebx\r
122 addl %ebx, %eax\r
768e2a90 123\r
d6d858c4 124 movl %eax, %esp\r
768e2a90 125\r
126 #\r
127 # Call C Function\r
128 #\r
129 movl %esi,%edi\r
130 addl $RendezvousProc, %edi\r
131 movl (%edi), %ebx\r
132\r
133 testl %ebx,%ebx\r
134 jz GoToSleep\r
135 call *%ebx # Call C function\r
136\r
137#Step-6: Sleep\r
138\r
139GoToSleep:\r
140\r
141 cli\r
142 hlt\r
143 jmp GoToSleep\r
144\r
145RendezvousFunnelProcEnd:\r
146#-------------------------------------------------------------------------------------\r
147# AsmGetAddressMap (&AddressMap);\r
148#-------------------------------------------------------------------------------------\r
149ASM_GLOBAL ASM_PFX(AsmGetAddressMap)\r
150ASM_PFX(AsmGetAddressMap):\r
151\r
152 pushal\r
153 movl %esp,%ebp\r
154\r
155 movl 0x24(%ebp), %ebx\r
156 movl $RendezvousFunnelProcStart, (%ebx)\r
157 movl $(ProtectedModeStart - RendezvousFunnelProcStart), 0x4(%ebx)\r
158 movl $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x8(%ebx)\r
159 movl $0, 0x0c(%ebx)\r
160 movl $0, 0x10(%ebx)\r
161 movl $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x14(%ebx)\r
162\r
163 popal\r
164 ret\r