]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.nasm
UefiCpuPkg/PiSmmCpuDxeSmm: patch "gSmiCr3" with PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / MpFuncs.nasm
... / ...
CommitLineData
1;------------------------------------------------------------------------------ ;\r
2; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
3; This program and the accompanying materials\r
4; are licensed and made available under the terms and conditions of the BSD License\r
5; which accompanies this distribution. The full text of the license may be found at\r
6; http://opensource.org/licenses/bsd-license.php.\r
7;\r
8; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
9; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
10;\r
11; Module Name:\r
12;\r
13; MpFuncs.nasm\r
14;\r
15; Abstract:\r
16;\r
17; This is the assembly code for Multi-processor S3 support\r
18;\r
19;-------------------------------------------------------------------------------\r
20\r
21SECTION .text\r
22\r
23extern ASM_PFX(InitializeFloatingPointUnits)\r
24\r
25%define VacantFlag 0x0\r
26%define NotVacantFlag 0xff\r
27\r
28%define LockLocation RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
29%define StackStart LockLocation + 0x4\r
30%define StackSize LockLocation + 0x8\r
31%define RendezvousProc LockLocation + 0xC\r
32%define GdtrProfile LockLocation + 0x10\r
33%define IdtrProfile LockLocation + 0x16\r
34%define BufferStart LockLocation + 0x1C\r
35\r
36;-------------------------------------------------------------------------------------\r
37;RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
38;procedure serializes all the AP processors through an Init sequence. It must be\r
39;noted that APs arrive here very raw...ie: real mode, no stack.\r
40;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
41;IS IN MACHINE CODE.\r
42;-------------------------------------------------------------------------------------\r
43;RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
44\r
45BITS 16\r
46global ASM_PFX(RendezvousFunnelProc)\r
47ASM_PFX(RendezvousFunnelProc):\r
48RendezvousFunnelProcStart:\r
49\r
50; At this point CS = 0x(vv00) and ip= 0x0.\r
51\r
52 mov ax, cs\r
53 mov ds, ax\r
54 mov es, ax\r
55 mov ss, ax\r
56 xor ax, ax\r
57 mov fs, ax\r
58 mov gs, ax\r
59\r
60flat32Start:\r
61\r
62 mov si, BufferStart\r
63 mov edx,dword [si] ; EDX is keeping the start address of wakeup buffer\r
64\r
65 mov si, GdtrProfile\r
66o32 lgdt [cs:si]\r
67\r
68 mov si, IdtrProfile\r
69o32 lidt [cs:si]\r
70\r
71 xor ax, ax\r
72 mov ds, ax\r
73\r
74 mov eax, cr0 ; Get control register 0\r
75 or eax, 0x000000001 ; Set PE bit (bit #0)\r
76 mov cr0, eax\r
77\r
78FLAT32_JUMP:\r
79\r
80a32 jmp dword 0x20:0x0\r
81\r
82BITS 32\r
83PMODE_ENTRY: ; protected mode entry point\r
84\r
85 mov ax, 0x8\r
86o16 mov ds, ax\r
87o16 mov es, ax\r
88o16 mov fs, ax\r
89o16 mov gs, ax\r
90o16 mov ss, ax ; Flat mode setup.\r
91\r
92 mov esi, edx\r
93\r
94 mov edi, esi\r
95 add edi, LockLocation\r
96 mov al, NotVacantFlag\r
97TestLock:\r
98 xchg byte [edi], al\r
99 cmp al, NotVacantFlag\r
100 jz TestLock\r
101\r
102ProgramStack:\r
103\r
104 mov edi, esi\r
105 add edi, StackSize\r
106 mov eax, dword [edi]\r
107 mov edi, esi\r
108 add edi, StackStart\r
109 add eax, dword [edi]\r
110 mov esp, eax\r
111 mov dword [edi], eax\r
112\r
113Releaselock:\r
114\r
115 mov al, VacantFlag\r
116 mov edi, esi\r
117 add edi, LockLocation\r
118 xchg byte [edi], al\r
119\r
120 ;\r
121 ; Call assembly function to initialize FPU.\r
122 ;\r
123 mov ebx, ASM_PFX(InitializeFloatingPointUnits)\r
124 call ebx\r
125 ;\r
126 ; Call C Function\r
127 ;\r
128 mov edi, esi\r
129 add edi, RendezvousProc\r
130 mov eax, dword [edi]\r
131\r
132 test eax, eax\r
133 jz GoToSleep\r
134 call eax ; Call C function\r
135\r
136GoToSleep:\r
137 cli\r
138 hlt\r
139 jmp $-2\r
140\r
141RendezvousFunnelProcEnd:\r
142;-------------------------------------------------------------------------------------\r
143; AsmGetAddressMap (&AddressMap);\r
144;-------------------------------------------------------------------------------------\r
145global ASM_PFX(AsmGetAddressMap)\r
146ASM_PFX(AsmGetAddressMap):\r
147\r
148 pushad\r
149 mov ebp,esp\r
150\r
151 mov ebx, dword [ebp+0x24]\r
152 mov dword [ebx], RendezvousFunnelProcStart\r
153 mov dword [ebx+0x4], PMODE_ENTRY - RendezvousFunnelProcStart\r
154 mov dword [ebx+0x8], FLAT32_JUMP - RendezvousFunnelProcStart\r
155 mov dword [ebx+0xc], RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
156\r
157 popad\r
158 ret\r
159\r