summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/boot/apboot.asm
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-11-17 19:18:01 -0500
committerIan Moffett <ian@osmora.org>2025-11-17 19:21:45 -0500
commit96f377cc12baf1ab808925ac5ce7f3b3a9a2be19 (patch)
tree73feee6fa2b0fc4ff36708d9e026f2ae58ab0e6b /sys/arch/amd64/boot/apboot.asm
parentbf94209175e843462ef9965fc7003452d55ea041 (diff)
kern/amd64: Bring application cores to long mode
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/arch/amd64/boot/apboot.asm')
-rw-r--r--sys/arch/amd64/boot/apboot.asm54
1 files changed, 51 insertions, 3 deletions
diff --git a/sys/arch/amd64/boot/apboot.asm b/sys/arch/amd64/boot/apboot.asm
index b9c3ad7..8c16319 100644
--- a/sys/arch/amd64/boot/apboot.asm
+++ b/sys/arch/amd64/boot/apboot.asm
@@ -30,9 +30,57 @@
[bits 16]
[org 0x1000]
+%define AP_BUDA 0x3000
+%define IA32_EFER 0xC0000080
+
+[bits 16]
_start:
- cli
- hlt
- jmp _start
+ mov al, 0xFF ;; Mask i8259 inputs
+ out 0x21, al ;; Disable master PIC
+ out 0xA1, al ;; Disable slave PIC
+
+ mov eax, dword [AP_BUDA] ;; BUDA.CR3 -> EAX
+ mov cr3, eax ;; EAX -> CR3
+
+ mov eax, cr4 ;; CR4 -> EAX
+ or eax, 0xA0 ;; Enable physical address extension + PGE
+ mov cr4, eax ;; Write it back
+
+ mov ecx, IA32_EFER ;; Read IA32_EFER
+ rdmsr ;; -> EAX
+ or eax, 0xD00 ;; Set EFER.LME + defaults
+ wrmsr ;; Write it back
+
+ mov eax, cr0 ;; CR0 -> EAX
+ or eax, 0x80000001 ;; CR0 |= PG/PM
+ mov cr0, eax ;; Write it back
+
+ lgdt [GDTR]
+ jmp 0x08:thunk64
+
+GDT:
+.NULL:
+ dq 0x0000000000000000 ;; NULL DESCRIPTOR
+.CODE: ;; ---------------
+ dq 0x00209A0000000000 ;; CODE DESCRIPTOR
+.DATA: ;; ---------------
+ dq 0x0000920000000000 ;; DATA DESCRIPTOR
+GDTR: ;; ---------------
+ dw $ - GDT - 1 ;; LIMIT
+ dq GDT ;; OFFSET
+
+[bits 64]
+thunk64:
+ mov ax, 0x10
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov ss, ax
+ xor ax, ax
+ mov gs, ax
+ mov rsp, qword [AP_BUDA + 0x08]
+ mov rbx, qword [AP_BUDA + 0x10]
+ cld
+ jmp rbx
times 4096 - ($ - $$) db 0