Protected Mode problem
Posted: Thu Feb 16, 2012 9:29 am
Okay, I am trying to make an OS that goes into protected mode, but I get a triple fault.
Here's the code (I do not use GRUB):
bootloader.asm
Second Stage:
I build using
I test it using bochs.
But the problem lies in the jmp 0x08:begin instruction in the Second Stage File.
Whenever I remove that instruction, the OS doesn't triple fault and haults the cpu as expected.
Bochs log doesn't seem to be helpful either
It justs says '3rd Exception with no resolution " and starts to reboot.
Please explain what the problem is. Thanks in advance.
Here's the code (I do not use GRUB):
bootloader.asm
Code: Select all
[ORG 0x7c00]
[BITS 16]
jmp start
start:
mov ax,0x1000 ;code to read second sector(and second stage) from the floppy into memory location 0x1000:0
mov es,ax
xor bx,bx
xor ax,ax
mov ah,2
mov dl,0
mov al,1
mov ch,0
mov cl,2
mov dh,0
mov dl,0
int 0x13
jump:
jmp 0x1000:0x0000 ;jump to the memory location
TIMES 510-($-$$) db 0
db 0x55
db 0xAA
Code: Select all
[ORG 0x1000]
jmp main ;goto the main routine
;------------------------------------
;The GDT
gdt: ;main gdt function that sets up the gdt
cli
lgdt [addr]
ret
addr: ; Calculate required information for the gdt
dw end - gdt_t -1
dd gdt_t
;----------------------------------------------------
gdt_t:
; the real gdt
;----------------
;Null Descriptor
dd 0
dd 0
;----------------
;Code Descriptor
codeDes equ $-
dw 0xFFFF
dw 0
db 0
db 00011010b
db 11001111b
db 0
;----------------
;Data Descriptor
dw 0xFFFF
dw 0
db 0
db 00010010b
db 11001111b
db 0
end:
;------------------------------------------------------------
main:
call gdt ; call main gdt function
mov eax,cr0
or eax,1
mov cr0,eax ; move into protected mode
jmp 0x08:begin ; jump to clear real mode garbage from cs
[BITS 32]
begin:
cli
hlt
I build using
Code: Select all
nasm boot.asm -f bin -o boot.bin
nasm kernel.asm -f bin -o kernel.bin
dd if=/dev/zero of=image.img count=2880 bs=512
dd if=boot.bin of=image.img conv=notrunc status=noxfer
dd if=kernel.bin of=image.img conv=notrunc status=noxfer seek=1
But the problem lies in the jmp 0x08:begin instruction in the Second Stage File.
Whenever I remove that instruction, the OS doesn't triple fault and haults the cpu as expected.
Bochs log doesn't seem to be helpful either
Code: Select all
00126790189i[CPU0 ] CPU is in protected mode (active)
00126790189i[CPU0 ] CS.d_b = 16 bit
00126790189i[CPU0 ] SS.d_b = 16 bit
00126790189i[CPU0 ] EFER = 0x00000000
00126790189i[CPU0 ] | RAX=0000000060000011 RBX=0000000000000000
00126790189i[CPU0 ] | RCX=0000000000090002 RDX=0000000000000000
00126790189i[CPU0 ] | RSP=000000000000ffd6 RBP=0000000000000000
00126790189i[CPU0 ] | RSI=00000000000e472c RDI=000000000000ffac
00126790189i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00126790189i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00126790189i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00126790189i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00126790189i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
00126790189i[CPU0 ] | SEG selector base limit G D
00126790189i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00126790189i[CPU0 ] | CS:1000( 0004| 0| 0) 00010000 0000ffff 0 0
00126790189i[CPU0 ] | DS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00126790189i[CPU0 ] | SS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00126790189i[CPU0 ] | ES:1000( 0005| 0| 0) 00010000 0000ffff 0 0
00126790189i[CPU0 ] | FS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00126790189i[CPU0 ] | GS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00126790189i[CPU0 ] | MSR_FS_BASE:0000000000000000
00126790189i[CPU0 ] | MSR_GS_BASE:0000000000000000
00126790189i[CPU0 ] | RIP=0000000000000034 (0000000000000034)
00126790189i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
00126790189i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00126790189i[CPU0 ] 0x0000000000000034>> jmp far 0008:1039 : EA39100800
00126790189e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00126790189i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
Please explain what the problem is. Thanks in advance.