]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - UefiCpuPkg/PiSmmCpuDxeSmm/X64/MpFuncs.S
MdePkg/BaseLib: add PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / X64 / MpFuncs.S
... / ...
CommitLineData
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
4# This program and the accompanying materials\r
5# are licensed and made available under the terms and conditions of the BSD License\r
6# which accompanies this distribution. The full text of the license may be found at\r
7# http://opensource.org/licenses/bsd-license.php.\r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11#\r
12# Module Name:\r
13#\r
14# MpFuncs.S\r
15#\r
16# Abstract:\r
17#\r
18# This is the assembly code for Multi-processor S3 support\r
19#\r
20#------------------------------------------------------------------------------\r
21\r
22.equ VacantFlag, 0x0\r
23.equ NotVacantFlag, 0xff\r
24\r
25.equ LockLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
26.equ StackStartAddressLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08\r
27.equ StackSizeLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r
28.equ CProcedureLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x18\r
29.equ GdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x20\r
30.equ IdtrLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x2A\r
31.equ BufferStartLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x34\r
32.equ Cr3OffsetLocation, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x38\r
33\r
34#-------------------------------------------------------------------------------------\r
35#RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
36#procedure serializes all the AP processors through an Init sequence. It must be\r
37#noted that APs arrive here very raw...ie: real mode, no stack.\r
38#ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
39#IS IN MACHINE CODE.\r
40#-------------------------------------------------------------------------------------\r
41#RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
42\r
43.code:\r
44\r
45ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)\r
46ASM_PFX(RendezvousFunnelProc):\r
47RendezvousFunnelProcStart:\r
48\r
49# At this point CS = 0x(vv00) and ip= 0x0.\r
50\r
51 .byte 0x8c,0xc8 # mov ax, cs\r
52 .byte 0x8e,0xd8 # mov ds, ax\r
53 .byte 0x8e,0xc0 # mov es, ax\r
54 .byte 0x8e,0xd0 # mov ss, ax\r
55 .byte 0x33,0xc0 # xor ax, ax\r
56 .byte 0x8e,0xe0 # mov fs, ax\r
57 .byte 0x8e,0xe8 # mov gs, ax\r
58\r
59flat32Start:\r
60\r
61 .byte 0xBE\r
62 .word BufferStartLocation\r
63 .byte 0x66,0x8B,0x14 # mov edx,dword ptr [si] ; EDX is keeping the start address of wakeup buffer\r
64\r
65 .byte 0xBE\r
66 .word Cr3OffsetLocation\r
67 .byte 0x66,0x8B,0xC # mov ecx,dword ptr [si] ; ECX is keeping the value of CR3\r
68\r
69 .byte 0xBE\r
70 .word GdtrLocation\r
71 .byte 0x66 # db 66h\r
72 .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]\r
73\r
74 .byte 0xBE\r
75 .word IdtrLocation\r
76 .byte 0x66 # db 66h\r
77 .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]\r
78\r
79 .byte 0x33,0xC0 # xor ax, ax\r
80 .byte 0x8E,0xD8 # mov ds, ax\r
81\r
82 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0\r
83 .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)\r
84 .byte 0xF,0x22,0xC0 # mov cr0, eax\r
85\r
86FLAT32_JUMP:\r
87\r
88 .byte 0x66,0x67,0xEA # far jump\r
89 .long 0x0 # 32-bit offset\r
90 .word 0x20 # 16-bit selector\r
91\r
92PMODE_ENTRY: # protected mode entry point\r
93\r
94 .byte 0x66,0xB8,0x18,0x0 # mov ax, 18h\r
95 .byte 0x66,0x8E,0xD8 # mov ds, ax\r
96 .byte 0x66,0x8E,0xC0 # mov es, ax\r
97 .byte 0x66,0x8E,0xE0 # mov fs, ax\r
98 .byte 0x66,0x8E,0xE8 # mov gs, ax\r
99 .byte 0x66,0x8E,0xD0 # mov ss, ax ; Flat mode setup.\r
100\r
101 .byte 0xF,0x20,0xE0 # mov eax, cr4\r
102 .byte 0xF,0xBA,0xE8,0x5 # bts eax, 5\r
103 .byte 0xF,0x22,0xE0 # mov cr4, eax\r
104\r
105 .byte 0xF,0x22,0xD9 # mov cr3, ecx\r
106\r
107 .byte 0x8B,0xF2 # mov esi, edx ; Save wakeup buffer address\r
108\r
109 .byte 0xB9\r
110 .long 0xC0000080 # mov ecx, 0c0000080h ; EFER MSR number.\r
111 .byte 0xF,0x32 # rdmsr ; Read EFER.\r
112 .byte 0xF,0xBA,0xE8,0x8 # bts eax, 8 ; Set LME=1.\r
113 .byte 0xF,0x30 # wrmsr ; Write EFER.\r
114\r
115 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Read CR0.\r
116 .byte 0xF,0xBA,0xE8,0x1F # bts eax, 31 ; Set PG=1.\r
117 .byte 0xF,0x22,0xC0 # mov cr0, eax ; Write CR0.\r
118\r
119LONG_JUMP:\r
120\r
121 .byte 0x67,0xEA # far jump\r
122 .long 0x0 # 32-bit offset\r
123 .word 0x38 # 16-bit selector\r
124\r
125LongModeStart:\r
126\r
127 movw $0x30,%ax\r
128 .byte 0x66\r
129 movw %ax,%ds\r
130 .byte 0x66\r
131 movw %ax,%es\r
132 .byte 0x66\r
133 movw %ax,%ss\r
134\r
135 movl %esi,%edi\r
136 addl $LockLocation, %edi\r
137 movb $NotVacantFlag, %al\r
138TestLock:\r
139 xchgb (%edi), %al\r
140 cmpb $NotVacantFlag, %al\r
141 jz TestLock\r
142\r
143ProgramStack:\r
144\r
145 movl %esi,%edi\r
146 addl $StackSizeLocation, %edi\r
147 movq (%edi), %rax\r
148 movl %esi,%edi\r
149 addl $StackStartAddressLocation, %edi\r
150 addq (%edi), %rax\r
151 movq %rax, %rsp\r
152 movq %rax, (%edi)\r
153\r
154Releaselock:\r
155\r
156 movb $VacantFlag, %al\r
157 movl %esi,%edi\r
158 addl $LockLocation, %edi\r
159 xchgb (%edi), %al\r
160\r
161 #\r
162 # Call assembly function to initialize FPU.\r
163 #\r
164 movabsq $ASM_PFX(InitializeFloatingPointUnits), %rax\r
165 subq $0x20, %rsp\r
166 call *%rax\r
167 addq $0x20, %rsp\r
168 #\r
169 # Call C Function\r
170 #\r
171 movl %esi,%edi\r
172 addl $CProcedureLocation, %edi\r
173 movq (%edi), %rax\r
174\r
175 testq %rax, %rax\r
176 jz GoToSleep\r
177\r
178 subq $0x20, %rsp\r
179 call *%rax\r
180 addq $0x20, %rsp\r
181\r
182GoToSleep:\r
183 cli\r
184 hlt\r
185 jmp .-2\r
186\r
187RendezvousFunnelProcEnd:\r
188\r
189\r
190#-------------------------------------------------------------------------------------\r
191# AsmGetAddressMap (&AddressMap);\r
192#-------------------------------------------------------------------------------------\r
193# comments here for definition of address map\r
194ASM_GLOBAL ASM_PFX(AsmGetAddressMap)\r
195ASM_PFX(AsmGetAddressMap):\r
196 movabsq $RendezvousFunnelProcStart, %rax\r
197 movq %rax, (%rcx)\r
198 movq $(PMODE_ENTRY - RendezvousFunnelProcStart), 0x08(%rcx)\r
199 movq $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x10(%rcx)\r
200 movq $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x18(%rcx)\r
201 movq $(LongModeStart - RendezvousFunnelProcStart), 0x20(%rcx)\r
202 movq $(LONG_JUMP - RendezvousFunnelProcStart), 0x28(%rcx)\r
203 ret\r
204\r