summaryrefslogtreecommitdiff
path: root/src/switch_mode.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/switch_mode.asm')
-rw-r--r--src/switch_mode.asm38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/switch_mode.asm b/src/switch_mode.asm
new file mode 100644
index 0000000..32cca0b
--- /dev/null
+++ b/src/switch_mode.asm
@@ -0,0 +1,38 @@
+[bits 16]
+
+%include "gdt.asm"
+
+switch_to_protected_mode:
+ ; switch off interrupts for now
+ 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
+ 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]
+