]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/IA32/MpFuncs.S
4da7fd5011925c84b247486fb41a3859b37cf98b
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / IA32 / MpFuncs.S
1 #------------------------------------------------------------------------------
2 # IA32 assembly file for AP startup vector.
3 #
4 # Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13 #------------------------------------------------------------------------------
14
15 .equ VacantFlag, 0x0
16 .equ NotVacantFlag, 0xff
17
18 .equ LockLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart
19 .equ StackStart, LockLocation + 0x04
20 .equ StackSize, LockLocation + 0x08
21 .equ RendezvousProc, LockLocation + 0x0C
22 .equ GdtrProfile, LockLocation + 0x10
23 .equ BufferStart, LockLocation + 0x18
24
25 #-------------------------------------------------------------------------------------
26 #RendezvousFunnelProc procedure follows. All APs execute their procedure. This
27 #procedure serializes all the AP processors through an Init sequence. It must be
28 #noted that APs arrive here very raw...ie: real mode, no stack.
29 #ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
30 #IS IN MACHINE CODE.
31 #-------------------------------------------------------------------------------------
32 #RendezvousFunnelProc (&WakeUpBuffer,MemAddress);
33
34 ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)
35 ASM_PFX(RendezvousFunnelProc):
36 RendezvousFunnelProcStart:
37
38
39 # At this point CS = 0x(vv00) and ip= 0x0.
40
41 .byte 0x8c,0xc8 # mov ax, cs
42 .byte 0x8e,0xd8 # mov ds, ax
43 .byte 0x8e,0xc0 # mov es, ax
44 .byte 0x8e,0xd0 # mov ss, ax
45 .byte 0x33,0xc0 # xor ax, ax
46 .byte 0x8e,0xe0 # mov fs, ax
47 .byte 0x8e,0xe8 # mov gs, ax
48
49 # Switch to flat mode.
50
51 .byte 0xBE
52 .word BufferStart
53 .byte 0x66,0x8B,0xC # mov ecx,dword ptr [si] ; ECX is keeping the start address of wakeup buffer
54
55 .byte 0xFA # cli
56 .byte 0xBE
57 .word GdtrProfile
58 .byte 0x66 # db 66h
59 .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]
60
61 .byte 0xBE
62 .word IdtrProfile
63 .byte 0x66 # db 66h
64 .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]
65
66 .byte 0x33,0xC0 # xor ax, ax
67 .byte 0x8E,0xD8 # mov ds, ax
68 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0
69 .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)
70 .byte 0xF,0x22,0xC0 # mov cr0, eax
71
72
73 #step-4:
74
75 FLAT32_JUMP:
76 .byte 0x66
77 .byte 0x67
78 .byte 0xEA # far jump
79 .long 0x0
80 .word 0x10
81
82 ProtectedModeStart: # protected mode entry point
83
84 movw $0x8,%ax
85 .byte 0x66
86 movw %ax,%ds
87 .byte 0x66
88 movw %ax,%es
89 .byte 0x66
90 movw %ax,%fs
91 .byte 0x66
92 movw %ax,%gs
93 .byte 0x66
94 movw %ax,%ss # Flat mode setup.
95
96
97 movl %esi,%edi
98 addl $LockLocation, %edi
99 movb $NotVacantFlag, %al
100 TestLock:
101 xchgb (%edi), %al
102 cmpb $NotVacantFlag, %al
103 jz TestLock
104
105 ProgramStack:
106 movl %esi,%edi
107 addl $StackSize, %edi
108 movl (%edi), %eax
109 movl %esi,%edi
110 addl $StackStart, %edi
111 addl (%edi), %eax
112 movl %eax,%esp
113 movl %eax, (%edi)
114
115 Releaselock:
116 movb $VacantFlag, %al
117 movl %esi,%edi
118 addl $LockLocation, %edi
119 xchgb (%edi), %al
120
121 #
122 # Call C Function
123 #
124 movl %esi,%edi
125 addl $RendezvousProc, %edi
126 movl (%edi), %ebx
127
128 testl %ebx,%ebx
129 jz GoToSleep
130 call *%ebx # Call C function
131
132 #Step-6: Sleep
133
134 GoToSleep:
135
136 cli
137 hlt
138 jmp GoToSleep
139
140 RendezvousFunnelProcEnd:
141 #-------------------------------------------------------------------------------------
142 # AsmGetAddressMap (&AddressMap);
143 #-------------------------------------------------------------------------------------
144 ASM_GLOBAL ASM_PFX(AsmGetAddressMap)
145 ASM_PFX(AsmGetAddressMap):
146
147 pushal
148 movl %esp,%ebp
149
150 movl 0x24(%ebp), %ebx
151 movl $RendezvousFunnelProcStart, (%ebx)
152 movl $(ProtectedModeStart - RendezvousFunnelProcStart), 0x4(%ebx)
153 movl $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x8(%ebx)
154 movl $0, 0x0c(%ebx)
155 movl $0, 0x10(%ebx)
156 movl $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x14(%ebx)
157
158 popal
159 ret