Pmode
Posted: Tue Jan 15, 2002 6:40 pm
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
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