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