1 | ;------------------------------------------------------------------------------ ;
|
---|
2 | ; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
3 | ; SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
4 | ;
|
---|
5 | ; Module Name:
|
---|
6 | ;
|
---|
7 | ; MpFuncs.nasm
|
---|
8 | ;
|
---|
9 | ; Abstract:
|
---|
10 | ;
|
---|
11 | ; This is the assembly code for Multi-processor S3 support
|
---|
12 | ;
|
---|
13 | ;-------------------------------------------------------------------------------
|
---|
14 |
|
---|
15 | %define VacantFlag 0x0
|
---|
16 | %define NotVacantFlag 0xff
|
---|
17 |
|
---|
18 | %define LockLocation RendezvousFunnelProcEnd - RendezvousFunnelProcStart
|
---|
19 | %define StackStartAddressLocation LockLocation + 0x8
|
---|
20 | %define StackSizeLocation LockLocation + 0x10
|
---|
21 | %define CProcedureLocation LockLocation + 0x18
|
---|
22 | %define GdtrLocation LockLocation + 0x20
|
---|
23 | %define IdtrLocation LockLocation + 0x2A
|
---|
24 | %define BufferStartLocation LockLocation + 0x34
|
---|
25 | %define Cr3OffsetLocation LockLocation + 0x38
|
---|
26 | %define InitializeFloatingPointUnitsAddress LockLocation + 0x3C
|
---|
27 |
|
---|
28 | ;-------------------------------------------------------------------------------------
|
---|
29 | ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This
|
---|
30 | ;procedure serializes all the AP processors through an Init sequence. It must be
|
---|
31 | ;noted that APs arrive here very raw...ie: real mode, no stack.
|
---|
32 | ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
|
---|
33 | ;IS IN MACHINE CODE.
|
---|
34 | ;-------------------------------------------------------------------------------------
|
---|
35 | ;RendezvousFunnelProc (&WakeUpBuffer,MemAddress);
|
---|
36 |
|
---|
37 | ;text SEGMENT
|
---|
38 | DEFAULT REL
|
---|
39 | SECTION .text
|
---|
40 |
|
---|
41 | BITS 16
|
---|
42 | global ASM_PFX(RendezvousFunnelProc)
|
---|
43 | ASM_PFX(RendezvousFunnelProc):
|
---|
44 | RendezvousFunnelProcStart:
|
---|
45 |
|
---|
46 | ; At this point CS = 0x(vv00) and ip= 0x0.
|
---|
47 |
|
---|
48 | mov ax, cs
|
---|
49 | mov ds, ax
|
---|
50 | mov es, ax
|
---|
51 | mov ss, ax
|
---|
52 | xor ax, ax
|
---|
53 | mov fs, ax
|
---|
54 | mov gs, ax
|
---|
55 |
|
---|
56 | flat32Start:
|
---|
57 |
|
---|
58 | mov si, BufferStartLocation
|
---|
59 | mov edx,dword [si] ; EDX is keeping the start address of wakeup buffer
|
---|
60 |
|
---|
61 | mov si, Cr3OffsetLocation
|
---|
62 | mov ecx,dword [si] ; ECX is keeping the value of CR3
|
---|
63 |
|
---|
64 | mov si, GdtrLocation
|
---|
65 | o32 lgdt [cs:si]
|
---|
66 |
|
---|
67 | mov si, IdtrLocation
|
---|
68 | o32 lidt [cs:si]
|
---|
69 |
|
---|
70 | xor ax, ax
|
---|
71 | mov ds, ax
|
---|
72 |
|
---|
73 | mov eax, cr0 ; Get control register 0
|
---|
74 | or eax, 0x000000001 ; Set PE bit (bit #0)
|
---|
75 | mov cr0, eax
|
---|
76 |
|
---|
77 | FLAT32_JUMP:
|
---|
78 |
|
---|
79 | a32 jmp dword 0x20:0x0
|
---|
80 |
|
---|
81 | BITS 32
|
---|
82 | PMODE_ENTRY: ; protected mode entry point
|
---|
83 |
|
---|
84 | mov ax, 0x18
|
---|
85 | o16 mov ds, ax
|
---|
86 | o16 mov es, ax
|
---|
87 | o16 mov fs, ax
|
---|
88 | o16 mov gs, ax
|
---|
89 | o16 mov ss, ax ; Flat mode setup.
|
---|
90 |
|
---|
91 | mov eax, cr4
|
---|
92 | bts eax, 5
|
---|
93 | mov cr4, eax
|
---|
94 |
|
---|
95 | mov cr3, ecx
|
---|
96 |
|
---|
97 | mov esi, edx ; Save wakeup buffer address
|
---|
98 |
|
---|
99 | mov ecx, 0xc0000080 ; EFER MSR number.
|
---|
100 | rdmsr ; Read EFER.
|
---|
101 | bts eax, 8 ; Set LME=1.
|
---|
102 | wrmsr ; Write EFER.
|
---|
103 |
|
---|
104 | mov eax, cr0 ; Read CR0.
|
---|
105 | bts eax, 31 ; Set PG=1.
|
---|
106 | mov cr0, eax ; Write CR0.
|
---|
107 |
|
---|
108 | LONG_JUMP:
|
---|
109 |
|
---|
110 | a16 jmp dword 0x38:0x0
|
---|
111 |
|
---|
112 | BITS 64
|
---|
113 | LongModeStart:
|
---|
114 |
|
---|
115 | mov ax, 0x30
|
---|
116 | o16 mov ds, ax
|
---|
117 | o16 mov es, ax
|
---|
118 | o16 mov ss, ax
|
---|
119 |
|
---|
120 | mov edi, esi
|
---|
121 | add edi, LockLocation
|
---|
122 | mov al, NotVacantFlag
|
---|
123 | TestLock:
|
---|
124 | xchg byte [edi], al
|
---|
125 | cmp al, NotVacantFlag
|
---|
126 | jz TestLock
|
---|
127 |
|
---|
128 | ProgramStack:
|
---|
129 |
|
---|
130 | mov edi, esi
|
---|
131 | add edi, StackSizeLocation
|
---|
132 | mov rax, qword [edi]
|
---|
133 | mov edi, esi
|
---|
134 | add edi, StackStartAddressLocation
|
---|
135 | add rax, qword [edi]
|
---|
136 | mov rsp, rax
|
---|
137 | mov qword [edi], rax
|
---|
138 |
|
---|
139 | Releaselock:
|
---|
140 |
|
---|
141 | mov al, VacantFlag
|
---|
142 | mov edi, esi
|
---|
143 | add edi, LockLocation
|
---|
144 | xchg byte [edi], al
|
---|
145 |
|
---|
146 | ;
|
---|
147 | ; Call assembly function to initialize FPU.
|
---|
148 | ;
|
---|
149 | mov rax, qword [esi + InitializeFloatingPointUnitsAddress]
|
---|
150 | sub rsp, 0x20
|
---|
151 | call rax
|
---|
152 | add rsp, 0x20
|
---|
153 |
|
---|
154 | ;
|
---|
155 | ; Call C Function
|
---|
156 | ;
|
---|
157 | mov edi, esi
|
---|
158 | add edi, CProcedureLocation
|
---|
159 | mov rax, qword [edi]
|
---|
160 |
|
---|
161 | test rax, rax
|
---|
162 | jz GoToSleep
|
---|
163 |
|
---|
164 | sub rsp, 0x20
|
---|
165 | call rax
|
---|
166 | add rsp, 0x20
|
---|
167 |
|
---|
168 | GoToSleep:
|
---|
169 | cli
|
---|
170 | hlt
|
---|
171 | jmp $-2
|
---|
172 |
|
---|
173 | RendezvousFunnelProcEnd:
|
---|
174 |
|
---|
175 | ;-------------------------------------------------------------------------------------
|
---|
176 | ; AsmGetAddressMap (&AddressMap);
|
---|
177 | ;-------------------------------------------------------------------------------------
|
---|
178 | ; comments here for definition of address map
|
---|
179 | global ASM_PFX(AsmGetAddressMap)
|
---|
180 | ASM_PFX(AsmGetAddressMap):
|
---|
181 | lea rax, [RendezvousFunnelProcStart]
|
---|
182 | mov qword [rcx], rax
|
---|
183 | mov qword [rcx+0x8], PMODE_ENTRY - RendezvousFunnelProcStart
|
---|
184 | mov qword [rcx+0x10], FLAT32_JUMP - RendezvousFunnelProcStart
|
---|
185 | mov qword [rcx+0x18], RendezvousFunnelProcEnd - RendezvousFunnelProcStart
|
---|
186 | mov qword [rcx+0x20], LongModeStart - RendezvousFunnelProcStart
|
---|
187 | mov qword [rcx+0x28], LONG_JUMP - RendezvousFunnelProcStart
|
---|
188 | ret
|
---|
189 |
|
---|