]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/CpuMpPei/X64/MpFuncs.asm
54255476344585a770fb3473f80a681215904c05
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / X64 / 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 include MpEqu.inc
22 .code
23 ;-------------------------------------------------------------------------------------
24 ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This
25 ;procedure serializes all the AP processors through an Init sequence. It must be
26 ;noted that APs arrive here very raw...ie: real mode, no stack.
27 ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
28 ;IS IN MACHINE CODE.
29 ;-------------------------------------------------------------------------------------
30 RendezvousFunnelProc PROC PUBLIC
31 RendezvousFunnelProcStart::
32 ; At this point CS = 0x(vv00) and ip= 0x0.
33 ; Save BIST information to ebp firstly
34 db 66h, 08bh, 0e8h ; mov ebp, eax ; save BIST information
35
36 db 8ch,0c8h ; mov ax,cs
37 db 8eh,0d8h ; mov ds,ax
38 db 8eh,0c0h ; mov es,ax
39 db 8eh,0d0h ; mov ss,ax
40 db 33h,0c0h ; xor ax,ax
41 db 8eh,0e0h ; mov fs,ax
42 db 8eh,0e8h ; mov gs,ax
43
44 db 0BEh ; opcode of mov si, mem16
45 dw BufferStartLocation ; mov si, BufferStartLocation
46 db 66h, 8Bh, 1Ch ; mov ebx,dword ptr [si]
47
48 db 0BFh ; opcode of mov di, mem16
49 dw PmodeOffsetLocation ; mov di, PmodeOffsetLocation
50 db 66h, 8Bh, 05h ; mov eax,dword ptr [di]
51 db 8Bh, 0F8h ; mov di, ax
52 db 83h, 0EFh,06h ; sub di, 06h
53 db 66h, 03h, 0C3h ; add eax, ebx
54 db 66h, 89h, 05h ; mov dword ptr [di],eax
55
56 db 0BFh ; opcode of mov di, mem16
57 dw LmodeOffsetLocation ; mov di, LmodeOffsetLocation
58 db 66h, 8Bh, 05h ; mov eax,dword ptr [di]
59 db 8Bh, 0F8h ; mov di, ax
60 db 83h, 0EFh,06h ; sub di, 06h
61 db 66h, 03h, 0C3h ; add eax, ebx
62 db 66h, 89h, 05h ; mov dword ptr [di],eax
63
64 db 0BEh
65 dw Cr3Location ; mov si, Cr3Location
66 db 66h, 8Bh, 0Ch ; mov ecx,dword ptr [si] ; ECX is keeping the value of CR3
67
68 db 0BEh ; opcode of mov si, mem16
69 dw GdtrLocation ; mov si, GdtrLocation
70 db 66h ; db 66h
71 db 2Eh, 0Fh, 01h, 14h ; lgdt fword ptr cs:[si]
72
73 db 0BEh
74 dw IdtrLocation ; mov si, IdtrLocation
75 db 66h ; db 66h
76 db 2Eh,0Fh, 01h, 1Ch ; lidt fword ptr cs:[si]
77
78 db 33h, 0C0h ; xor ax, ax
79 db 8Eh, 0D8h ; mov ds, ax
80
81 db 0Fh, 20h, 0C0h ; mov eax, cr0 ;Get control register 0
82 db 66h, 83h, 0C8h, 03h ; or eax, 000000003h ;Set PE bit (bit #0) & MP
83 db 0Fh, 22h, 0C0h ; mov cr0, eax
84
85 db 66h, 67h, 0EAh ; far jump
86 dd 0h ; 32-bit offset
87 dw PROTECT_MODE_CS ; 16-bit selector
88
89 Flat32Start:: ; protected mode entry point
90 mov ax, PROTECT_MODE_DS
91 mov ds, ax
92 mov es, ax
93 mov fs, ax
94 mov gs, ax
95 mov ss, ax
96
97 db 0Fh, 20h, 0E0h ; mov eax, cr4
98 db 0Fh, 0BAh, 0E8h, 05h ; bts eax, 5
99 db 0Fh, 22h, 0E0h ; mov cr4, eax
100
101 db 0Fh, 22h, 0D9h ; mov cr3, ecx
102
103 db 0B9h
104 dd 0C0000080h ; mov ecx, 0c0000080h ; EFER MSR number.
105 db 0Fh, 32h ; rdmsr ; Read EFER.
106 db 0Fh, 0BAh, 0E8h, 08h ; bts eax, 8 ; Set LME=1.
107 db 0Fh, 30h ; wrmsr ; Write EFER.
108
109 db 0Fh, 20h, 0C0h ; mov eax, cr0 ; Read CR0.
110 db 0Fh, 0BAh, 0E8h, 1Fh ; bts eax, 31 ; Set PG=1.
111 db 0Fh, 22h, 0C0h ; mov cr0, eax ; Write CR0.
112
113 LONG_JUMP:
114 db 67h, 0EAh ; far jump
115 dd 0h ; 32-bit offset
116 dw LONG_MODE_CS ; 16-bit selector
117
118 LongModeStart::
119 mov ax, LONG_MODE_DS
120 mov ds, ax
121 mov es, ax
122 mov ss, ax
123
124 mov esi, ebx
125 mov edi, esi
126 add edi, LockLocation
127 mov rax, NotVacantFlag
128
129 TestLock:
130 xchg qword ptr [edi], rax
131 cmp rax, NotVacantFlag
132 jz TestLock
133
134 mov edi, esi
135 add edi, NumApsExecutingLoction
136 inc dword ptr [edi]
137 mov ebx, dword ptr [edi]
138
139 ProgramStack:
140 mov edi, esi
141 add edi, StackSizeLocation
142 mov rax, qword ptr [edi]
143 mov edi, esi
144 add edi, StackStartAddressLocation
145 add rax, qword ptr [edi]
146 mov rsp, rax
147 mov qword ptr [edi], rax
148
149 Releaselock:
150 mov rax, VacantFlag
151 mov edi, esi
152 add edi, LockLocation
153 xchg qword ptr [edi], rax
154
155 CProcedureInvoke:
156 push rbp ; push BIST data
157 xor rbp, rbp ; clear ebp for call stack trace
158 push rbp
159 mov rbp, rsp
160
161
162 mov edx, ebx ; edx is NumApsExecuting
163 mov ecx, esi
164 add ecx, LockLocation ; rcx is address of exchange info data buffer
165
166 mov edi, esi
167 add edi, ApProcedureLocation
168 mov rax, qword ptr [edi]
169
170 sub rsp, 20h
171 call rax ; invoke C function
172 add rsp, 20h
173 jmp $
174
175 RendezvousFunnelProc ENDP
176 RendezvousFunnelProcEnd::
177
178
179 AsmInitializeGdt PROC
180 push rbp
181 mov rbp, rsp
182
183 lgdt fword PTR [rcx] ; update the GDTR
184
185 sub rsp, 0x10
186 lea rax, SetCodeSelectorFarJump
187 mov [rsp], rax
188 mov rdx, LONG_MODE_CS
189 mov [rsp + 4], dx ; get new CS
190 jmp fword ptr [rsp]
191 SetCodeSelectorFarJump:
192 add rsp, 0x10
193
194 mov rax, LONG_MODE_DS ; get new DS
195 mov ds, ax
196 mov es, ax
197 mov fs, ax
198 mov gs, ax
199 mov ss, ax
200
201 pop rbp
202 ret
203 AsmInitializeGdt ENDP
204
205 END