I'm attempting to make a simple OS and can't seem to get into protected mode.
My code assembles fine and runs but it's in like a loop or something: the screen just flashes the booting message.
I'm pretty sure the problem is when I set cr0
in enter_pm.asm.
boot.asm
[org 0xc700]
mov bp, 0x8000
mov sp, bp
call switch_to_pm
jmp $
%include "enter_pm.asm"
%include "gdt.asm"
times 510-($-$$) db 0
db 0x55, 0xaa
times 512 db 'A'
gdt.asm
GDT_start:
GDT_null:
dd 0x0
dd 0x0
GDT_code:
dw 0xffff
dw 0x0
db 0x0
db 0b10011010
db 0b11001111
db 0x0
GDT_data:
dw 0xffff
dw 0x0
db 0x0
db 0b10010010
db 0b11001111
db 0x0
GDT_end:
GDT_desriptor:
dw GDT_end - GDT_start - 1
dd GDT_start
CODE_SEG equ GDT_code - GDT_start
DATA_SEG equ GDT_data - GDT_start
enter_pm.asm
[bits 16]
switch_to_pm:
cli
lgdt [GDT_desriptor]
mov eax, cr0
or eax, 0x1
mov cr0, eax
jmp CODE_SEG:init_pm
[bits 32]
init_pm:
mov al, 'A'
mov ah, 0x0f
mov [0xb8000], ax
compile command nasm -f bin boot/boot_read_disc/boot.asm -o boot.bin -i boot/boot_read_disc/
run command qemu-system-x86_64 boot.bin