I must have done something wrong with the GDT setup
and the switch to protected mode
because it keeps constantly rebooting.
Here is my kernel.asm
that should setup the GDT
and switch to protected mode
:
bits 16
jmp main
%include "gdt.inc"
main:
cli
xor ax,ax
mov ds,ax
mov es,ax
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti
call InstallGDT
cli
mov eax,cr0
or eax,1
jmp 08h:Stage3
bits 32
Stage3:
mov ax,0x10
mov ds,ax
mov ss,ax
mov es,ax
mov esp,90000h
Stop:
mov byte [0xb8000],'A'
cli
hlt
and there is the gdt.inc
:
bits 16
InstallGDT:
cli
pusha
lgdt [toc]
sti
popa
ret
gdt_data:
dd 0
dd 0
dw 0ffffh
dw 0
db 0
db 10011010b
db 11001111b
db 0
dw 0ffffh
dw 0
db 0
db 10010010b
db 11001111b
db 0
end_of_gdt:
toc:
dw end_of_gdt - gdt_data -1
dd gdt_data
My bootloader.asm
loads 10 sectors to 0x1000:0x000
and then jumps there.
I test the code with the commands:
nasm -f bin -o bootloader.bin bootloader.asm
nasm -f bin -o kernel.bin kernel.asm
cat bootloader.bin kernel.bin>OS.bin
qemu-system-i386 OS.bin
Where is my fault?