NEED HELP AGAIN

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
crazysurfmonkey

NEED HELP AGAIN

Post by crazysurfmonkey »

HEY CAN SOMEONE HELP ME WITH THIS I CAN'T FIGURE OUT WHY THIS IS CAUSING A TRIPLE FAULT CAN SOMEBODY HELP ME! THIS IS MY BOOTSECTOR:
THANKS
;
;
;
;
[BITS 16]
;----------------------------
jmp start ; Jump to start
;-----------------------------
STACKSEG EQU 0x8000
INITSEG EQU 0x07c0
VIDEOSEG EQU 0xb800
NEWSEG EQU 0x9000

CODESEL EQU 0x08
DATASEL EQU 0x10
VIDEOSEL EQU 0x18
;------------------------------
gdtr
dw 0x1000
dd 0

idtr
dw 0
dd 0x1000

gdt
dd 0
dd 0

dw 0xffff
dw 0x0
db 0x0
db 0x9a
db 0xcf
db 0

dw 0xffff
dw 0x0
db 0x0
db 0x92
db 0xcf
db 0
gdt_end

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
pmodeinmsg db 'Starting Up!', 0

;----------------------------
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 [bootdrv], dl

cld
mov ax,0x7c0
mov ds,ax
mov ax,0x9000
mov es,ax
xor di,di
xor si,si
mov cx,0x200
cli
rep movsb

jmp 0x9000:there

there:
sti

mov ax, STACKSEG
mov ss, ax
mov ax, 0xff

mov sp, ax

mov ax, NEWSEG
mov ds, ax
xor si, si

mov es, ax
xor bp, bp

mov ax, VIDEOSEG
mov gs, ax

mov si,bootmsg ; display our startup message
call message
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

push dword 0
popfd

in al,0x70
or al,0x80
out 0x70,al

call getkey
;--------------------------

mov si, pmodemsg
call message
;--------------------------
push es
xor ax,ax
mov es,ax
xor di,di

mov si,gdtr
mov cx,gdt_end-gdt
rep movsb
pop es

; Switch to pmode
lidt[idtr]
lgdt[gdtr]

mov eax, cr0
inc eax
mov cr0, eax
jmp short flush

flush:
mov bx, 0x10
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
mov ss, bx


jmp dword 0x08:0x90000 + pmode ; far jump
[bits 32]
pmode:
mov ebx, 0x9000 + pmodeinmsg
mov ecx, 0xb8002
call putmsg32
repeat: jmp repeat
;------------PUTMSG32-------------------
putmsg32:
push eax
.continue:
mov byte al, [ebx]
cmp al, 0
jz .end

mov byte al, [ebx]
mov byte [ecx], al
inc ebx
mov byte al, [ebx]
cmp al, 0
jz .end
add ecx, 2
jmp .continue
.end
pop eax
ret

times 510-($-$$) db 0
dw 0AA55h
J. Weeks

RE:NEED HELP AGAIN

Post by J. Weeks »

>On 2002-01-18 00:10:08, crazysurfmonkey wrote:
> HEY CAN SOMEONE HELP ME WITH THIS I CAN'T FIGURE
> OUT WHY THIS IS CAUSING A TRIPLE FAULT CAN
> SOMEBODY HELP ME! THIS IS MY BOOTSECTOR:

> gdtr
> dw 0x1000
> dd 0

so... starting at 0x0 with a limit of 0x1000?
That's pretty large. The biggest GDT is 256 * 8,
which is 0x800.

> idtr
> dw 0
> dd 0x1000

Same with the idt, and it'd start at 0x800

> push es
> xor ax,ax
> mov es,ax
> xor di,di
>
> mov si,gdtr
> mov cx,gdt_end-gdt
> rep movsb
> pop es

You're overwritting the real mode interrupts.

> ; Switch to pmode
> lidt[idtr]
> lgdt[gdtr]

Again, your gdt is bigger than the largest gdt possible. That might cause an internal logic error or something.

Jeff
Post Reply