]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm
c8bdc52e95ecaea1ca5129e895b7015657ffc636
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / Ia32 / MpFuncs.asm
1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
3 ; This program and the accompanying materials
4 ; are licensed and made available under the terms and conditions of the BSD License
5 ; which accompanies this distribution. The full text of the license may be found at
6 ; http://opensource.org/licenses/bsd-license.php.
7 ;
8 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10 ;
11 ; Module Name:
12 ;
13 ; MpFuncs32.asm
14 ;
15 ; Abstract:
16 ;
17 ; This is the assembly code for MP support
18 ;
19 ;-------------------------------------------------------------------------------
20
21 .686p
22 .model flat
23
24 include MpEqu.inc
25
26 .code
27
28 ;-------------------------------------------------------------------------------------
29 ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This
30 ;procedure serializes all the AP processors through an Init sequence. It must be
31 ;noted that APs arrive here very raw...ie: real mode, no stack.
32 ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
33 ;IS IN MACHINE CODE.
34 ;-------------------------------------------------------------------------------------
35 RendezvousFunnelProc PROC PUBLIC
36 RendezvousFunnelProcStart::
37 ; At this point CS = 0x(vv00) and ip= 0x0.
38 ; Save BIST information to ebp firstly
39 db 66h, 08bh, 0e8h ; mov ebp, eax ; save BIST information
40
41 db 8ch,0c8h ; mov ax,cs
42 db 8eh,0d8h ; mov ds,ax
43 db 8eh,0c0h ; mov es,ax
44 db 8eh,0d0h ; mov ss,ax
45 db 33h,0c0h ; xor ax,ax
46 db 8eh,0e0h ; mov fs,ax
47 db 8eh,0e8h ; mov gs,ax
48
49 db 0BEh ; opcode of mov si, mem16
50 dw BufferStartLocation ; mov si, BufferStartLocation
51 db 66h, 8Bh, 1Ch ; mov ebx,dword ptr [si]
52
53 db 0BFh ; opcode of mov di, mem16
54 dw PmodeOffsetLocation ; mov di, PmodeOffsetLocation
55 db 66h, 8Bh, 05h ; mov eax,dword ptr [di]
56 db 8Bh, 0F8h ; mov di, ax
57 db 83h, 0EFh,06h ; sub di, 06h
58 db 66h, 03h, 0C3h ; add eax, ebx
59 db 66h, 89h, 05h ; mov dword ptr [di],eax
60
61 db 0BEh ; opcode of mov si, mem16
62 dw GdtrLocation ; mov si, GdtrLocation
63 db 66h ; db 66h
64 db 2Eh, 0Fh, 01h, 14h ; lgdt fword ptr cs:[si]
65
66 db 0BEh
67 dw IdtrLocation ; mov si, IdtrLocation
68 db 66h ; db 66h
69 db 2Eh,0Fh, 01h, 1Ch ; lidt fword ptr cs:[si]
70
71 db 33h, 0C0h ; xor ax, ax
72 db 8Eh, 0D8h ; mov ds, ax
73
74 db 0Fh, 20h, 0C0h ; mov eax, cr0 ;Get control register 0
75 db 66h, 83h, 0C8h, 03h ; or eax, 000000003h ;Set PE bit (bit #0) & MP
76 db 0Fh, 22h, 0C0h ; mov cr0, eax
77
78 db 66h, 67h, 0EAh ; far jump
79 dd 0h ; 32-bit offset
80 dw PROTECT_MODE_CS ; 16-bit selector
81
82 Flat32Start:: ; protected mode entry point
83 mov ax, PROTECT_MODE_DS
84 mov ds, ax
85 mov es, ax
86 mov fs, ax
87 mov gs, ax
88 mov ss, ax
89
90 mov esi, ebx
91 mov edi, esi
92 add edi, LockLocation
93 mov eax, NotVacantFlag
94
95 TestLock:
96 xchg dword ptr [edi], eax
97 cmp eax, NotVacantFlag
98 jz TestLock
99
100 mov edi, esi
101 add edi, NumApsExecutingLoction
102 inc dword ptr [edi]
103 mov ebx, dword ptr [edi]
104
105 ProgramStack:
106 mov edi, esi
107 add edi, StackSizeLocation
108 mov eax, dword ptr [edi]
109 mov edi, esi
110 add edi, StackStartAddressLocation
111 add eax, dword ptr [edi]
112 mov esp, eax
113 mov dword ptr [edi], eax
114
115 Releaselock:
116 mov eax, VacantFlag
117 mov edi, esi
118 add edi, LockLocation
119 xchg dword ptr [edi], eax
120
121 CProcedureInvoke:
122 push ebp ; push BIST data at top of AP stack
123 xor ebp, ebp ; clear ebp for call stack trace
124 push ebp
125 mov ebp, esp
126
127
128 push ebx ; Push NumApsExecuting
129 mov eax, esi
130 add eax, LockLocation
131 push eax ; push address of exchange info data buffer
132
133 mov edi, esi
134 add edi, ApProcedureLocation
135 mov eax, dword ptr [edi]
136
137 call eax ; invoke C function
138
139 jmp $ ; never reach here
140
141 RendezvousFunnelProc ENDP
142 RendezvousFunnelProcEnd::
143
144
145 AsmInitializeGdt PROC near C PUBLIC
146 push ebp
147 mov ebp, esp
148 pushad
149 mov edi, [ebp + 8] ; Load GDT register
150
151 mov ax,cs ; Get the selector data from our code image
152 mov es,ax
153 lgdt FWORD PTR es:[edi] ; and update the GDTR
154
155 push PROTECT_MODE_CS
156 lea eax, SetCodeSelectorFarJump
157 push eax
158 retf
159 SetCodeSelectorFarJump:
160 mov ax, PROTECT_MODE_DS ; Update the Base for the new selectors, too
161 mov ds, ax
162 mov es, ax
163 mov fs, ax
164 mov gs, ax
165 mov ss, ax
166
167 popad
168 pop ebp
169 ret
170 AsmInitializeGdt ENDP
171
172 END