Protected Mode problem
Posted: Sat Aug 13, 2011 10:04 am
I have tried to make a bootloader that reads the first file from a custom filesystem, and then loads it as a kernel. However, something fails when entering Protected Mode. The bootloader does not work in QEMU or VirtualBox, but VirtualBox detects an "unexpected problem" during operation (but the log does not say what instruction caused it). Here is the code:
Any help?
Code: Select all
; bootloader.asm -- the GigaDOS bootloader
bits 16
org 0x7C00
mov ax, 0
mov ds, ax
jmp 0x0:go
go:
cli
mov si, str_booting
call puts
; the area used for reading the kernel record and finally
; transferring control to the kernel
mov ax, 0x7E0
mov es, ax
; read the file header from floppy
mov ah, 0x02
mov al, 1
mov cx, 1
xor dx, dx
xor bx, bx
int 13h
; now read the file
mov ah, 0x02
mov al, [es:0x10]
mov cl, 2
int 13h
; reset the ES segment
mov ax, 0
mov es, ax
mov si, str_pmode
call puts
; load the GDT
lgdt [gdt_desc]
; enter Protected Mode
mov eax, cr0
or eax, 1
mov cr0, eax
jmp 0x08:clear_pipe
; put a string on the screen
; DS:SI -> NUL-terminated string
; AX = destroyed
puts:
mov ah, 0x0E
.loop:
lodsb
cmp al, 0
je .end
int 10h
jmp .loop
.end:
ret
str_booting db 'GigaDOS booting up....', 0
str_pmode db 'Entering protected mode...', 0
; the default GDT
gdt:
.null dq 0
.code:
dw 0xFFFF
dw 0
db 0
db 0x9A
db 0xCF
db 0
.data:
dw 0xFFFF
dw 0
db 0
db 0x92
db 0xCF
db 0
.end:
; the GDT pointer
gdt_desc:
db gdt.end - gdt
dw gdt
[BITS 32]
clear_pipe:
mov ax, 0x10
mov ds, ax
mov ss, ax
mov ax, 0x4040
mov [0xB8000], ax
jmp 0x7E00
times 510 - ($ - $$) db 0
db 0x55, 0xAA