]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/X64/MpFuncs.S
2c9feb07b05df4b0459fa398e0303d8c8a2743ec
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / X64 / MpFuncs.S
1 #------------------------------------------------------------------------------
2 # X64 assembly file for AP startup vector.
3 #
4 # Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 # 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
16 .equ VacantFlag, 0x0
17 .equ NotVacantFlag, 0xff
18
19 .equ LockLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart
20 .equ StackStartAddressLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08
21 .equ StackSizeLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10
22 .equ CProcedureLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x18
23 .equ GdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x20
24 .equ BufferStartLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x2C
25 .equ Cr3OffsetLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x30
26
27 #-------------------------------------------------------------------------------------
28
29 #-------------------------------------------------------------------------------------
30 #RendezvousFunnelProc procedure follows. All APs execute their procedure. This
31 #procedure serializes all the AP processors through an Init sequence. It must be
32 #noted that APs arrive here very raw...ie: real mode, no stack.
33 #ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
34 #IS IN MACHINE CODE.
35 #-------------------------------------------------------------------------------------
36 #RendezvousFunnelProc (&WakeUpBuffer,MemAddress);
37
38 .text
39
40 ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)
41 ASM_PFX(RendezvousFunnelProc):
42 RendezvousFunnelProcStart:
43
44 # At this point CS = 0x(vv00) and ip= 0x0.
45
46 .byte 0x8c,0xc8 # mov ax, cs
47 .byte 0x8e,0xd8 # mov ds, ax
48 .byte 0x8e,0xc0 # mov es, ax
49 .byte 0x8e,0xd0 # mov ss, ax
50 .byte 0x33,0xc0 # xor ax, ax
51 .byte 0x8e,0xe0 # mov fs, ax
52 .byte 0x8e,0xe8 # mov gs, ax
53
54 # Switch to flat mode.
55
56 .byte 0xBE
57 .word BufferStartLocation
58 .byte 0x66,0x8B,0x14 # mov edx,dword ptr [si] ; EDX is keeping the start address of wakeup buffer
59
60 .byte 0xBE
61 .word Cr3OffsetLocation
62 .byte 0x66,0x8B,0xC # mov ecx,dword ptr [si] ; ECX is keeping the value of CR3
63
64 .byte 0xBE
65 .word GdtrLocation
66 .byte 0x66 # db 66h
67 .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]
68
69 .byte 0xBE
70 .word IdtrLocation
71 .byte 0x66 # db 66h
72 .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]
73
74 .byte 0x33,0xC0 # xor ax, ax
75 .byte 0x8E,0xD8 # mov ds, ax
76
77 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0
78 .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)
79 .byte 0xF,0x22,0xC0 # mov cr0, eax
80
81 FLAT32_JUMP:
82
83 .byte 0x66,0x67,0xEA # far jump
84 .long 0x0 # 32-bit offset
85 .word 0x20 # 16-bit selector
86
87 ProtectedModeStart:
88
89 .byte 0x66,0xB8,0x18,0x0 # mov ax, 18h
90 .byte 0x66,0x8E,0xD8 # mov ds, ax
91 .byte 0x66,0x8E,0xC0 # mov es, ax
92 .byte 0x66,0x8E,0xE0 # mov fs, ax
93 .byte 0x66,0x8E,0xE8 # mov gs, ax
94 .byte 0x66,0x8E,0xD0 # mov ss, ax ; Flat mode setup.
95
96 .byte 0xF,0x20,0xE0 # mov eax, cr4
97 .byte 0xF,0xBA,0xE8,0x5 # bts eax, 5
98 .byte 0xF,0x22,0xE0 # mov cr4, eax
99
100 .byte 0xF,0x22,0xD9 # mov cr3, ecx
101
102 .byte 0x8B,0xF2 # mov esi, edx ; Save wakeup buffer address
103
104 .byte 0xB9
105 .long 0xC0000080 # mov ecx, 0c0000080h ; EFER MSR number.
106 .byte 0xF,0x32 # rdmsr ; Read EFER.
107 .byte 0xF,0xBA,0xE8,0x8 # bts eax, 8 ; Set LME=1.
108 .byte 0xF,0x30 # wrmsr ; Write EFER.
109
110 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Read CR0.
111 .byte 0xF,0xBA,0xE8,0x1F # bts eax, 31 ; Set PG=1.
112 .byte 0xF,0x22,0xC0 # mov cr0, eax ; Write CR0.
113
114 LONG_JUMP:
115
116 .byte 0x67,0xEA # far jump
117 .long 0x0 # 32-bit offset
118 .word 0x38 # 16-bit selector
119
120 LongModeStart:
121
122 movw $0x30,%ax
123 .byte 0x66
124 movw %ax,%ds
125 .byte 0x66
126 movw %ax,%es
127 .byte 0x66
128 movw %ax,%ss
129
130 movl %esi, %edi
131 addl $LockLocation, %edi
132 movb $NotVacantFlag, %al
133 TestLock:
134 xchgb (%edi), %al
135 cmpb $NotVacantFlag, %al
136 jz TestLock
137
138 ProgramStack:
139
140 movl %esi, %edi
141 addl $StackSizeLocation, %edi
142 movq (%edi), %rax
143 movl %esi, %edi
144 addl $StackStartAddressLocation, %edi
145 addq (%edi), %rax
146 movq %rax, %rsp
147 movq %rax, (%edi)
148
149 Releaselock:
150
151 movb $VacantFlag, %al
152 movl %esi, %edi
153 addl $LockLocation, %edi
154 xchgb (%edi), %al
155
156 #
157 # Call C Function
158 #
159 movl %esi,%edi
160 addl $CProcedureLocation, %edi
161 movq (%edi), %rax
162
163 testq %rax, %rax
164 jz GoToSleep
165
166 subq $0x20, %rsp
167 call *%rax
168 addq $0x20, %rsp
169
170 GoToSleep:
171
172 cli
173 hlt
174 jmp .-2
175
176 RendezvousFunnelProcEnd:
177
178
179 #-------------------------------------------------------------------------------------
180 # AsmGetAddressMap (&AddressMap);
181 #-------------------------------------------------------------------------------------
182 # comments here for definition of address map
183 ASM_GLOBAL ASM_PFX(AsmGetAddressMap)
184 ASM_PFX(AsmGetAddressMap):
185
186 movq $RendezvousFunnelProcStart, %rax
187 movq %rax, (%rcx)
188 movq $(ProtectedModeStart - RendezvousFunnelProcStart), 0x08(%rcx)
189 movq $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x10(%rcx)
190 movq $(LongModeStart - RendezvousFunnelProcStart), 0x18(%rcx)
191 movq $(LONG_JUMP - RendezvousFunnelProcStart), 0x20(%rcx)
192 movq $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x28(%rcx)
193
194 ret