Ok for the pass three days i have tried to get this stupid bootsector to work but it causes a triple fault every single time I try to switch to protected mode! WHAT THE HELL IS WRONG WITH THIS CODE! here is my whole program written to be compiled in NASM:
Can anybody help me! PMODE is a pain!
----------------------------
[BITS 16]
;-----------------------------
jmp start ; Jump to start
;----------------------------
message: ; Dump ds:si to screen.
lodsb ; load byte at ds:si into al
or al,al ; test if character is 0 (end)
jz done
mov ah,0eh ; put character
mov bx,0007 ; attribute
int 0x10 ; call BIOS
jmp message
done:
ret
; --------------------
getkey:
mov ah, 0
int 016h
ret
; --------------------
start:
mov ax,0x7c0
mov ds,ax
mov [bootdrv], dl
cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti
mov si,bootmsg ; display our startup message
call message
.386
mov si, a20msg
call message
;--Activating A20 line
clear_buf:
in al, 64h
test al, 02h
loopnz clear_buf
mov al, 0D1h
out 64h, al
clear_buf2:
in al, 64h
test al, 02h
loopnz clear_buf2
mov al, 0dfh
out 60h, al
mov cx, 14h
wait_kbc:
out 0edh, ax
loop wait_kbc
call getkey
mov si, pmodemsg
call message
; Switch to pmode
lidt[ds:idtReg]
lgdt[ds:gdtReg]
mov eax, cr0
or al, 1
mov cr0, eax
jmp ME_SEL:pmode ; far jump
[bits 32]
pmode:
mov ax, DATA_SEL
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0xffff
repeat: jmp CODE_SEL:repeat
[bits 16]
;-----------------------------
bootdrv db 0
bootmsg db 'Loading...',13,10,0
a20msg db 'Turning A20 Address line on!',13,10,0
pmodemsg db 'Entering 32-bit Protected Mode!',13,10,0
gdtReg:
dw GDT_END - GDT - 1
dd 0x9000*16+0xFD00+GDT
GDT:
dw 0,0,0,0
codeSel:
dw 0xFFFF
dw 0
db 0
db 0x9A
db 0xC0
db 0
dataSel:
dw 0xFFFF
dw 0
db 0
db 0x92
db 0xC0
db 0
meSel:
dw 0xFFFF
dw 0x9000*16+0xFD00
db 0x9000 >> 12
db 0x9A
db 0x40
db 0
GDT_END
CODE_SEL equ codeSel - GDT
DATA_SEL equ dataSel - GDT
ME_SEL equ meSel - GDT
idtReg dw 0
dd 0
times 512-($-$$)-2 db 0
dw 0AA55h
PMODE is making me very very mad! HELP!!
RE:PMODE is making me very very mad! HELP!!
>On 2002-01-15 22:01:09, crazysurfmonkey wrote:
>Ok for the pass three days i have tried to get this stupid bootsector to work but it causes a triple fault every single time I try to switch to protected mode! WHAT THE HELL IS WRONG WITH THIS CODE! here is my whole program written to be compiled in NASM:
>Can anybody help me! PMODE is a pain!
Looks awfully familiar...
Usually, it's an IDT/GDT problem. I don't have the
intel specs on me, so I can't check that, but there
are a couple possibilities...
>
> ; Switch to pmode
> lidt[ds:idtReg]
> lgdt[ds:gdtReg]
The ds: is irrelavent. I never used it in my
code and it worked fine.
> mov eax, cr0
> or al, 1
> mov cr0, eax
add the following:
jmp stuff
nop
nop
nop
stuff:
I don't claim to understand why that's needed. I thought
your jump below was enough to clear the pre-fetch
queue, but I seem to recall needed this.
I'm a little rusty, I must admit... I wrote my
boot code years ago (which you seemed to have
adopted
> jmp ME_SEL:pmode ; far jump
you might need to code that in asm, in case
nasm is fudging that into a 16 bit jump...
db 0xea
dd pmode
dw ME_SEL
>gdtReg:
> dw GDT_END - GDT - 1
> dd 0x9000*16+0xFD00+GDT
+ 0xFD00? What's that all about?
>codeSel:
> dw 0xFFFF
> dw 0
> db 0
> db 0x9A
> db 0xC0
> db 0
Uhm... this is probably your problem right here, dude.
At the end of your code, you loop with a jump to
CODE_SEL:repeat. CODE_SEL is a descriptor for
a memory block starting at 0x0, and your code hasn't
been moved there... it's still at 0x90000!!!!
Jeff
>Ok for the pass three days i have tried to get this stupid bootsector to work but it causes a triple fault every single time I try to switch to protected mode! WHAT THE HELL IS WRONG WITH THIS CODE! here is my whole program written to be compiled in NASM:
>Can anybody help me! PMODE is a pain!
Looks awfully familiar...
Usually, it's an IDT/GDT problem. I don't have the
intel specs on me, so I can't check that, but there
are a couple possibilities...
>
> ; Switch to pmode
> lidt[ds:idtReg]
> lgdt[ds:gdtReg]
The ds: is irrelavent. I never used it in my
code and it worked fine.
> mov eax, cr0
> or al, 1
> mov cr0, eax
add the following:
jmp stuff
nop
nop
nop
stuff:
I don't claim to understand why that's needed. I thought
your jump below was enough to clear the pre-fetch
queue, but I seem to recall needed this.
I'm a little rusty, I must admit... I wrote my
boot code years ago (which you seemed to have
adopted
> jmp ME_SEL:pmode ; far jump
you might need to code that in asm, in case
nasm is fudging that into a 16 bit jump...
db 0xea
dd pmode
dw ME_SEL
>gdtReg:
> dw GDT_END - GDT - 1
> dd 0x9000*16+0xFD00+GDT
+ 0xFD00? What's that all about?
>codeSel:
> dw 0xFFFF
> dw 0
> db 0
> db 0x9A
> db 0xC0
> db 0
Uhm... this is probably your problem right here, dude.
At the end of your code, you loop with a jump to
CODE_SEL:repeat. CODE_SEL is a descriptor for
a memory block starting at 0x0, and your code hasn't
been moved there... it's still at 0x90000!!!!
Jeff