]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.S
MdePkg/BaseLib: add PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / MpFuncs.S
CommitLineData
7947da3c
MK
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 StackStart, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x04\r
27.equ StackSize, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08\r
28.equ RendezvousProc, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x0C\r
29.equ GdtrProfile, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r
30.equ IdtrProfile, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x16\r
31.equ BufferStart, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x1C\r
32\r
33#-------------------------------------------------------------------------------------\r
34#RendezvousFunnelProc procedure follows. All APs execute their procedure. This\r
35#procedure serializes all the AP processors through an Init sequence. It must be\r
36#noted that APs arrive here very raw...ie: real mode, no stack.\r
37#ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
38#IS IN MACHINE CODE.\r
39#-------------------------------------------------------------------------------------\r
40#RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
41\r
42ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)\r
43ASM_PFX(RendezvousFunnelProc):\r
44RendezvousFunnelProcStart:\r
45\r
46# At this point CS = 0x(vv00) and ip= 0x0.\r
47\r
48 .byte 0x8c,0xc8 # mov ax, cs\r
49 .byte 0x8e,0xd8 # mov ds, ax\r
50 .byte 0x8e,0xc0 # mov es, ax\r
51 .byte 0x8e,0xd0 # mov ss, ax\r
52 .byte 0x33,0xc0 # xor ax, ax\r
53 .byte 0x8e,0xe0 # mov fs, ax\r
54 .byte 0x8e,0xe8 # mov gs, ax\r
55\r
56flat32Start:\r
57\r
58 .byte 0xBE\r
59 .word BufferStart\r
60 .byte 0x66,0x8B,0x14 # mov edx,dword ptr [si] ; EDX is keeping the start address of wakeup buffer\r
61\r
62 .byte 0xBE\r
63 .word GdtrProfile\r
64 .byte 0x66 # db 66h\r
65 .byte 0x2E,0xF,0x1,0x14 # lgdt fword ptr cs:[si]\r
66\r
67 .byte 0xBE\r
68 .word IdtrProfile\r
69 .byte 0x66 # db 66h\r
70 .byte 0x2E,0xF,0x1,0x1C # lidt fword ptr cs:[si]\r
71\r
72 .byte 0x33,0xC0 # xor ax, ax\r
73 .byte 0x8E,0xD8 # mov ds, ax\r
74\r
75 .byte 0xF,0x20,0xC0 # mov eax, cr0 ; Get control register 0\r
76 .byte 0x66,0x83,0xC8,0x1 # or eax, 000000001h ; Set PE bit (bit #0)\r
77 .byte 0xF,0x22,0xC0 # mov cr0, eax\r
78\r
79FLAT32_JUMP:\r
80\r
81 .byte 0x66,0x67,0xEA # far jump\r
82 .long 0x0 # 32-bit offset\r
83 .word 0x20 # 16-bit selector\r
84\r
85PMODE_ENTRY: # protected mode entry point\r
86\r
87 movw $0x8,%ax\r
88 .byte 0x66\r
89 movw %ax,%ds\r
90 .byte 0x66\r
91 movw %ax,%es\r
92 .byte 0x66\r
93 movw %ax,%fs\r
94 .byte 0x66\r
95 movw %ax,%gs\r
96 .byte 0x66\r
97 movw %ax,%ss # Flat mode setup.\r
98\r
99 movl %edx,%esi\r
100\r
101 movl %esi,%edi\r
102 addl $LockLocation, %edi\r
103 movb $NotVacantFlag, %al\r
104TestLock:\r
105 xchgb (%edi), %al\r
106 cmpb $NotVacantFlag, %al\r
107 jz TestLock\r
108\r
109ProgramStack:\r
110\r
111 movl %esi,%edi\r
112 addl $StackSize, %edi\r
113 movl (%edi),%eax\r
114 movl %esi,%edi\r
115 addl $StackStart, %edi\r
116 addl (%edi),%eax\r
117 movl %eax,%esp\r
118 movl %eax,(%edi)\r
119\r
120Releaselock:\r
121\r
122 movb $VacantFlag, %al\r
123 movl %esi,%edi\r
124 addl $LockLocation, %edi\r
125 xchgb (%edi), %al\r
126\r
127 #\r
128 # Call assembly function to initialize FPU.\r
129 #\r
130 lea ASM_PFX(InitializeFloatingPointUnits), %ebx\r
131 call *%ebx\r
132 #\r
133 # Call C Function\r
134 #\r
135 movl %esi,%edi\r
136 addl $RendezvousProc, %edi\r
137 movl (%edi),%eax\r
138\r
139 testl %eax,%eax\r
140 jz GoToSleep\r
141 call *%eax # Call C function\r
142\r
143GoToSleep:\r
144 cli\r
145 hlt\r
146 jmp GoToSleep\r
147\r
148RendezvousFunnelProcEnd:\r
149#-------------------------------------------------------------------------------------\r
150# AsmGetAddressMap (&AddressMap);\r
151#-------------------------------------------------------------------------------------\r
152ASM_GLOBAL ASM_PFX(AsmGetAddressMap)\r
153ASM_PFX(AsmGetAddressMap):\r
154\r
155 pushal\r
156 movl %esp,%ebp\r
157\r
158 movl 0x24(%ebp), %ebx\r
159 movl $RendezvousFunnelProcStart, (%ebx)\r
160 movl $(PMODE_ENTRY - RendezvousFunnelProcStart), 0x4(%ebx)\r
161 movl $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x8(%ebx)\r
162 movl $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x0c(%ebx)\r
163\r
164 popal\r
165 ret\r