]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/PiSmmCpuDxeSmm/X64/MpFuncs.nasm
UefiCpuPkg: Update PiSmmCpuDxeSmm pass XCODE5 tool chain
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / X64 / MpFuncs.nasm
1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2016 - 2018, 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 Multi-processor S3 support
18 ;
19 ;-------------------------------------------------------------------------------
20
21 %define VacantFlag 0x0
22 %define NotVacantFlag 0xff
23
24 %define LockLocation RendezvousFunnelProcEnd - RendezvousFunnelProcStart
25 %define StackStartAddressLocation LockLocation + 0x8
26 %define StackSizeLocation LockLocation + 0x10
27 %define CProcedureLocation LockLocation + 0x18
28 %define GdtrLocation LockLocation + 0x20
29 %define IdtrLocation LockLocation + 0x2A
30 %define BufferStartLocation LockLocation + 0x34
31 %define Cr3OffsetLocation LockLocation + 0x38
32 %define InitializeFloatingPointUnitsAddress LockLocation + 0x3C
33
34 ;-------------------------------------------------------------------------------------
35 ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This
36 ;procedure serializes all the AP processors through an Init sequence. It must be
37 ;noted that APs arrive here very raw...ie: real mode, no stack.
38 ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
39 ;IS IN MACHINE CODE.
40 ;-------------------------------------------------------------------------------------
41 ;RendezvousFunnelProc (&WakeUpBuffer,MemAddress);
42
43 ;text SEGMENT
44 DEFAULT REL
45 SECTION .text
46
47 BITS 16
48 global ASM_PFX(RendezvousFunnelProc)
49 ASM_PFX(RendezvousFunnelProc):
50 RendezvousFunnelProcStart:
51
52 ; At this point CS = 0x(vv00) and ip= 0x0.
53
54 mov ax, cs
55 mov ds, ax
56 mov es, ax
57 mov ss, ax
58 xor ax, ax
59 mov fs, ax
60 mov gs, ax
61
62 flat32Start:
63
64 mov si, BufferStartLocation
65 mov edx,dword [si] ; EDX is keeping the start address of wakeup buffer
66
67 mov si, Cr3OffsetLocation
68 mov ecx,dword [si] ; ECX is keeping the value of CR3
69
70 mov si, GdtrLocation
71 o32 lgdt [cs:si]
72
73 mov si, IdtrLocation
74 o32 lidt [cs:si]
75
76 xor ax, ax
77 mov ds, ax
78
79 mov eax, cr0 ; Get control register 0
80 or eax, 0x000000001 ; Set PE bit (bit #0)
81 mov cr0, eax
82
83 FLAT32_JUMP:
84
85 a32 jmp dword 0x20:0x0
86
87 BITS 32
88 PMODE_ENTRY: ; protected mode entry point
89
90 mov ax, 0x18
91 o16 mov ds, ax
92 o16 mov es, ax
93 o16 mov fs, ax
94 o16 mov gs, ax
95 o16 mov ss, ax ; Flat mode setup.
96
97 mov eax, cr4
98 bts eax, 5
99 mov cr4, eax
100
101 mov cr3, ecx
102
103 mov esi, edx ; Save wakeup buffer address
104
105 mov ecx, 0xc0000080 ; EFER MSR number.
106 rdmsr ; Read EFER.
107 bts eax, 8 ; Set LME=1.
108 wrmsr ; Write EFER.
109
110 mov eax, cr0 ; Read CR0.
111 bts eax, 31 ; Set PG=1.
112 mov cr0, eax ; Write CR0.
113
114 LONG_JUMP:
115
116 a16 jmp dword 0x38:0x0
117
118 BITS 64
119 LongModeStart:
120
121 mov ax, 0x30
122 o16 mov ds, ax
123 o16 mov es, ax
124 o16 mov ss, ax
125
126 mov edi, esi
127 add edi, LockLocation
128 mov al, NotVacantFlag
129 TestLock:
130 xchg byte [edi], al
131 cmp al, NotVacantFlag
132 jz TestLock
133
134 ProgramStack:
135
136 mov edi, esi
137 add edi, StackSizeLocation
138 mov rax, qword [edi]
139 mov edi, esi
140 add edi, StackStartAddressLocation
141 add rax, qword [edi]
142 mov rsp, rax
143 mov qword [edi], rax
144
145 Releaselock:
146
147 mov al, VacantFlag
148 mov edi, esi
149 add edi, LockLocation
150 xchg byte [edi], al
151
152 ;
153 ; Call assembly function to initialize FPU.
154 ;
155 mov rax, qword [esi + InitializeFloatingPointUnitsAddress]
156 sub rsp, 0x20
157 call rax
158 add rsp, 0x20
159
160 ;
161 ; Call C Function
162 ;
163 mov edi, esi
164 add edi, CProcedureLocation
165 mov rax, qword [edi]
166
167 test rax, rax
168 jz GoToSleep
169
170 sub rsp, 0x20
171 call rax
172 add rsp, 0x20
173
174 GoToSleep:
175 cli
176 hlt
177 jmp $-2
178
179 RendezvousFunnelProcEnd:
180
181 ;-------------------------------------------------------------------------------------
182 ; AsmGetAddressMap (&AddressMap);
183 ;-------------------------------------------------------------------------------------
184 ; comments here for definition of address map
185 global ASM_PFX(AsmGetAddressMap)
186 ASM_PFX(AsmGetAddressMap):
187 lea rax, [RendezvousFunnelProcStart]
188 mov qword [rcx], rax
189 mov qword [rcx+0x8], PMODE_ENTRY - RendezvousFunnelProcStart
190 mov qword [rcx+0x10], FLAT32_JUMP - RendezvousFunnelProcStart
191 mov qword [rcx+0x18], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
192 mov qword [rcx+0x20], LongModeStart - RendezvousFunnelProcStart
193 mov qword [rcx+0x28], LONG_JUMP - RendezvousFunnelProcStart
194 ret
195