Tripple fault after long jump to protected mode
Posted: Wed Sep 24, 2014 3:27 am
Hello all,
I wrote simple bootloader and trying to jump to protected mode, but bochs reboots everytime after jump.
Here is first stage of bootloader. It loads at 0x7c00 and loads second stage:
Here is my second stage. It loads gdt and here i'm trying to jmp to protected mode:
I'm building it with:
And starting with bochs:
After starting, i'm getting tripple fault and:
Thank you.
I wrote simple bootloader and trying to jump to protected mode, but bochs reboots everytime after jump.
Here is first stage of bootloader. It loads at 0x7c00 and loads second stage:
Code: Select all
bits 16
[org 0x7c00]
ot:
; All segments set to 0, flat memory model
;; initialize segment registers
mov ax, 0
mov es, ax
mov ds, ax
mov ss, ax
mov gs, ax
mov fs, ax
mov sp, 4096
;;-------------------------
;; reset disk
mov ah, 0x00 ; reset function
mov dl, 0x00 ; drive
int 0x13 ; disk int
jc diskResetFailMsg
;;-------------------------
;; load 'asm' kernel
mov bx, 0x7e0 ;segment
mov es, bx
mov bx, 0x000 ; offset
mov ah, 0x02
mov al, 0x03
mov ch, 0x00
mov cl, 0x02
mov dh, 0x00
mov dl, 0x00
int 0x13
;; check error loading
jc diskReadFailMsg
;; jump to header
jmp dword 0x0000:0x7e00
;; finish boot sector
times 510-($-$$) db 0
dw 0xaa55
Code: Select all
[bits 16]
[org 0x7e00]
_start:
;; dissable interupts
cli
;; load descriptor data table
lgdt [gdt_descriptor]
;; switch to protected mode
mov eax, cr0
or al, 0x1
mov cr0, eax
jmp CODE_SEG:PMode
[BITS 32]
PMode:
hlt
jmp $
;;
;; Global descriptor table
;;
gdt_start:
gdt_null:
;; null selector
dd 0
dd 0
gdt_code:
dw 0xffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data:
dw 0xffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end:
gdt_descriptor:
dw gdt_end - gdt_start - 1
db gdt_start
times 1024-($-$$) db 0
Code: Select all
OS.img: loader.bin stage1.bin
cat loader.bin > os.bin
cat stage1.bin >> os.bin
dd status=noxfer conv=notrunc if=os.bin of=OS.img
loader.bin: loader.asm
nasm -w+all -f bin -o loader.bin loader.asm
stage1.bin: stage1.asm
nasm -w+all -f bin -o stage1.bin stage1.asm
Code: Select all
display_library: sdl
megs: 64
boot: floppy
floppya: 1_44=OS.img, status=inserted
Code: Select all
0x0000000000007e67>> jmp far 0008:7e6c : EA6CE0800
exception(): 3rd (13) execption with no resolution, shutdown status is 00h, reseting