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