@@ -152,14 +152,14 @@ align 16
152152BITS 64
153153
154154startap64:
155- xor eax , eax ; aka r0
156- xor ebx , ebx ; aka r3
157- xor ecx , ecx ; aka r1
158- xor edx , edx ; aka r2
159- xor esi , esi ; aka r6
160- xor edi , edi ; aka r7
161- xor ebp , ebp ; aka r5
162- xor esp , esp ; aka r4
155+ xor eax , eax
156+ xor ebx , ebx
157+ xor ecx , ecx
158+ xor edx , edx
159+ xor esi , esi
160+ xor edi , edi
161+ xor ebp , ebp
162+ xor esp , esp
163163 xor r8 , r8
164164 xor r9 , r9
165165 xor r10 , r10
@@ -169,28 +169,31 @@ startap64:
169169 xor r14 , r14
170170 xor r15 , r15
171171
172- mov ax , 0x10 ; TODO Is this needed?
172+ mov ax , 0x10 ; TODO Is this needed?
173173 mov ds , ax ; Clear the legacy segment registers
174174 mov es , ax
175175 mov ss , ax
176176 mov fs , ax
177177 mov gs , ax
178178
179- ; Reset the stack. Each CPU gets a 1024-byte unique stack location
180- mov rsi , [ p_LocalAPICAddress ] ; We would call p_smp_get_id here but the stack is not ...
181- add rsi , 0x20 ; ... yet defined. It is safer to find the value directly.
182- lodsd ; Load a 32-bit value. We only want the high 8 bits
183- shr rax , 24 ; Shift to the right and AL now holds the CPU's APIC ID
184- shl rax , 10 ; shift left 10 bits for a 1024byte stack
185- add rax , 0x0000000000090000 ; stacks decrement when you "push", start at 1024 bytes in
186- mov rsp , rax ; Leave 0x50000-0x9FFFF free so we use that
179+ ;; Reset the stack. Each CPU gets a 1024-byte unique stack location.
180+ mov rsi , [ p_LocalAPICAddress ] ;; We would call p_smp_get_id here but stack
181+ ;; is not yet defined. It is safer to find t
182+ ;; he value directly.
183+ add rsi , 0x20
184+ lodsd ;; Load a 32-bit value. We only want the high 8 bits.
185+ shr rax , 24 ;; al = CPU APIC ID.
186+ shl rax , 10 ;; Shift left 10 bits for a 1024 byte stack.
187+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;add rax, 0x00090000
188+ add rax , 0x00050000
189+ mov rsp , rax ;; 0x50000 - 0x9FFFF free so we use that
187190
188- lgdt [ GDTR64 ] ; Load the GDT
189- lidt [ IDTR64 ] ; Load the IDT
191+ lgdt [ GDTR64 ] ; ; Load the GDT
192+ lidt [ IDTR64 ] ; ; Load the IDT
190193
191- call init_ cpu ; Setup CPU
194+ call init_ cpu ; ; Setup CPU
192195
193- sti ; Activate interrupts for SMP
196+ sti ; ; Activate interrupts for SMP
194197 jmp ap_sleep
195198
196199align 16
@@ -200,14 +203,6 @@ ap_sleep:
200203 jmp ap_sleep ; just-in-case of an NMI
201204
202205
203-
204-
205- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
207-
208-
209-
210-
211206;;==============================================================================
212207;; 32-bit code. Instructions must also be 64 bit compatible. If a 'U' is stored
213208;; at 0x5FFF then we know it was a UEFI boot and immediately proceed to start64.
0 commit comments