]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/X64/MpFuncs.asm
Check in thunk driver to produce PI MP Services Protocol based on Framework MP Servic...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / X64 / MpFuncs.asm
1 ;------------------------------------------------------------------------------
2 ; X64 assembly file for AP startup vector.
3 ;
4 ; Copyright (c) 2009, Intel Corporation
5 ; All rights reserved. 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 .code
16
17 include AsmInclude.inc
18 ;-------------------------------------------------------------------------------------
19
20 ;-------------------------------------------------------------------------------------
21 ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This
22 ;procedure serializes all the AP processors through an Init sequence. It must be
23 ;noted that APs arrive here very raw...ie: real mode, no stack.
24 ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
25 ;IS IN MACHINE CODE.
26 ;-------------------------------------------------------------------------------------
27 ;RendezvousFunnelProc (&WakeUpBuffer,MemAddress);
28
29 RendezvousFunnelProc PROC PUBLIC
30 RendezvousFunnelProcStart::
31
32 ; At this point CS = 0x(vv00) and ip= 0x0.
33
34 db 8ch, 0c8h ; mov ax, cs
35 db 8eh, 0d8h ; mov ds, ax
36 db 8eh, 0c0h ; mov es, ax
37 db 8eh, 0d0h ; mov ss, ax
38 db 33h, 0c0h ; xor ax, ax
39 db 8eh, 0e0h ; mov fs, ax
40 db 8eh, 0e8h ; mov gs, ax
41
42 ; Switch to flat mode.
43
44 db 0BEh
45 dw BufferStartLocation ; mov si, BufferStartLocation
46 db 66h, 8Bh, 14h ; mov edx,dword ptr [si] ; EDX is keeping the start address of wakeup buffer
47
48 db 0BEh
49 dw Cr3OffsetLocation ; mov si, Cr3Location
50 db 66h, 8Bh, 0Ch ; mov ecx,dword ptr [si] ; ECX is keeping the value of CR3
51
52 db 0BEh
53 dw GdtrLocation ; mov si, GdtrProfile
54 db 66h ; db 66h
55 db 2Eh, 0Fh, 01h, 14h ; lgdt fword ptr cs:[si]
56
57 db 33h, 0C0h ; xor ax, ax
58 db 8Eh, 0D8h ; mov ds, ax
59
60 db 0Fh, 20h, 0C0h ; mov eax, cr0 ; Get control register 0
61 db 66h, 83h, 0C8h, 01h ; or eax, 000000001h ; Set PE bit (bit #0)
62 db 0Fh, 22h, 0C0h ; mov cr0, eax
63
64 FLAT32_JUMP::
65
66 db 66h, 67h, 0EAh ; far jump
67 dd 0h ; 32-bit offset
68 dw 20h ; 16-bit selector
69
70 ProtectedModeStart::
71
72 db 66h, 0B8h, 18h, 00h ; mov ax, 18h
73 db 66h, 8Eh, 0D8h ; mov ds, ax
74 db 66h, 8Eh, 0C0h ; mov es, ax
75 db 66h, 8Eh, 0E0h ; mov fs, ax
76 db 66h, 8Eh, 0E8h ; mov gs, ax
77 db 66h, 8Eh, 0D0h ; mov ss, ax ; Flat mode setup.
78
79 db 0Fh, 20h, 0E0h ; mov eax, cr4
80 db 0Fh, 0BAh, 0E8h, 05h ; bts eax, 5
81 db 0Fh, 22h, 0E0h ; mov cr4, eax
82
83 db 0Fh, 22h, 0D9h ; mov cr3, ecx
84
85 db 8Bh, 0F2h ; mov esi, edx ; Save wakeup buffer address
86
87 db 0B9h
88 dd 0C0000080h ; mov ecx, 0c0000080h ; EFER MSR number.
89 db 0Fh, 32h ; rdmsr ; Read EFER.
90 db 0Fh, 0BAh, 0E8h, 08h ; bts eax, 8 ; Set LME=1.
91 db 0Fh, 30h ; wrmsr ; Write EFER.
92
93 db 0Fh, 20h, 0C0h ; mov eax, cr0 ; Read CR0.
94 db 0Fh, 0BAh, 0E8h, 1Fh ; bts eax, 31 ; Set PG=1.
95 db 0Fh, 22h, 0C0h ; mov cr0, eax ; Write CR0.
96
97 LONG_JUMP::
98
99 db 67h, 0EAh ; far jump
100 dd 0h ; 32-bit offset
101 dw 38h ; 16-bit selector
102
103 LongModeStart::
104
105 mov ax, 30h
106 mov ds, ax
107 mov es, ax
108 mov ss, ax
109
110 mov edi, esi
111 add edi, LockLocation
112 mov al, NotVacantFlag
113 TestLock::
114 xchg byte ptr [edi], al
115 cmp al, NotVacantFlag
116 jz TestLock
117
118 ProgramStack::
119
120 mov edi, esi
121 add edi, StackSizeLocation
122 mov rax, qword ptr [edi]
123 mov edi, esi
124 add edi, StackStartAddressLocation
125 add rax, qword ptr [edi]
126 mov rsp, rax
127 mov qword ptr [edi], rax
128
129 Releaselock::
130
131 mov al, VacantFlag
132 mov edi, esi
133 add edi, LockLocation
134 xchg byte ptr [edi], al
135
136 ;
137 ; Call C Function
138 ;
139 mov edi, esi
140 add edi, CProcedureLocation
141 mov rax, qword ptr [edi]
142
143 test rax, rax
144 jz GoToSleep
145
146 sub rsp, 20h
147 call rax
148 add rsp, 20h
149
150 GoToSleep::
151
152 cli
153 hlt
154 jmp $-2
155
156 RendezvousFunnelProc ENDP
157 RendezvousFunnelProcEnd::
158
159
160 ;-------------------------------------------------------------------------------------
161 ; AsmGetAddressMap (&AddressMap);
162 ;-------------------------------------------------------------------------------------
163 AsmGetAddressMap PROC
164
165 mov rax, offset RendezvousFunnelProcStart
166 mov qword ptr [rcx], rax
167 mov qword ptr [rcx+8h], ProtectedModeStart - RendezvousFunnelProcStart
168 mov qword ptr [rcx+10h], FLAT32_JUMP - RendezvousFunnelProcStart
169 mov qword ptr [rcx+18h], LongModeStart - RendezvousFunnelProcStart
170 mov qword ptr [rcx+20h], LONG_JUMP - RendezvousFunnelProcStart
171 mov qword ptr [rcx+28h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
172
173 ret
174
175 AsmGetAddressMap ENDP
176
177 END