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