:: commit 70676a97d37552fea6747dae7d41bfcb6a9cc931

Mintsuki <mintsuki@protonmail.com> — 2026-02-22 17:21

parents: b2c265f2be

lib/spinup: Load TR and zero CR3 before protocol entry

diff --git a/common/lib/spinup.asm_bios_ia32 b/common/lib/spinup.asm_bios_ia32
index bc01663c..53bc2986 100644
--- a/common/lib/spinup.asm_bios_ia32
+++ b/common/lib/spinup.asm_bios_ia32
@@ -33,6 +33,16 @@ common_spinup:
 
     xor eax, eax
     mov cr4, eax
+    mov cr3, eax
+
+    ; Clear TSS busy bit and load TR with base 0, limit 0
+    sub esp, 8
+    sgdt [esp]
+    mov eax, [esp + 2]
+    add esp, 8
+    mov byte [eax + 0x3d], 0x89
+    mov ax, 0x38
+    ltr ax
 
     call edi
 
diff --git a/common/lib/spinup.asm_uefi_ia32 b/common/lib/spinup.asm_uefi_ia32
index ba70a08c..397e4d80 100644
--- a/common/lib/spinup.asm_uefi_ia32
+++ b/common/lib/spinup.asm_uefi_ia32
@@ -58,6 +58,16 @@ common_spinup:
 
     xor eax, eax
     mov cr4, eax
+    mov cr3, eax
+
+    ; Clear TSS busy bit and load TR with base 0, limit 0
+    sub esp, 8
+    sgdt [esp]
+    mov eax, [esp + 2]
+    add esp, 8
+    mov byte [eax + 0x3d], 0x89
+    mov ax, 0x38
+    ltr ax
 
     call edi
 
diff --git a/common/lib/spinup.asm_uefi_x86_64 b/common/lib/spinup.asm_uefi_x86_64
index afb37574..a2bf7ecc 100644
--- a/common/lib/spinup.asm_uefi_x86_64
+++ b/common/lib/spinup.asm_uefi_x86_64
@@ -95,6 +95,16 @@ bits 32
 
     xor eax, eax
     mov cr4, eax
+    mov cr3, eax
+
+    ; Clear TSS busy bit and load TR with base 0, limit 0
+    sub esp, 8
+    sgdt [esp]
+    mov eax, [esp + 2]
+    add esp, 8
+    mov byte [eax + 0x3d], 0x89
+    mov ax, 0x38
+    ltr ax
 
     call edi
 
diff --git a/common/protos/limine_32.asm_x86 b/common/protos/limine_32.asm_x86
index 5fb50f70..75819e4b 100644
--- a/common/protos/limine_32.asm_x86
+++ b/common/protos/limine_32.asm_x86
@@ -80,12 +80,6 @@ bits 64
     mov eax, [rsp+28] ; local_gdt
     lgdt [rax]
 
-    ; Clear TSS busy bit and load TR
-    mov rax, [rax + 2]
-    mov byte [rax + 0x3d], 0x89
-    mov ax, 0x38
-    ltr ax
-
     ; Jump to higher half
     mov rax, qword [rsp+36]
     add rsp, rax
tab: 248 wrap: offon