summaryrefslogtreecommitdiff
path: root/src/boot/stage2_switch_mode.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot/stage2_switch_mode.asm')
-rw-r--r--src/boot/stage2_switch_mode.asm40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/boot/stage2_switch_mode.asm b/src/boot/stage2_switch_mode.asm
new file mode 100644
index 0000000..9259e08
--- /dev/null
+++ b/src/boot/stage2_switch_mode.asm
@@ -0,0 +1,40 @@
+[bits 16]
+
+%include "boot/boot_gdt.asm"
+
+switch_to_protected_mode:
+ ; switch off interrupts for now, we don't
+ ; have a valid IDT installed yet
+ cli
+
+ ; load GDT (global descriptor table)
+ lgdt [gdt_descriptor]
+
+ ; do the actual switch
+ mov eax, cr0
+ or eax, 0x1
+ mov cr0, eax
+
+ ; unconditional far jump into code segment,
+ ; wipes the instruction prefetch pipeline
+ jmp CODE_SEGMENT:init_pm
+
+[bits 32]
+
+; initialize registers and stack for protected mode
+init_pm:
+ mov ax, DATA_SEGMENT
+ mov ds, ax
+ mov ss, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+
+ ; a new stack
+ mov ebp, 0x90000
+ mov esp, ebp
+
+ call BEGIN_PROTECTED_MODE
+
+[bits 16]
+