Page 1 of 1

eugh, what's wrong? this should be real simple.

Posted: Sat Nov 26, 2005 12:00 am
by robert macabre
all right, everything was working 100% fine, until i did something to my bootloader. i don't even know what i did here. i don't remember editing it haha.

the goal here is to get to protected mode (which should be a quick and simple task) and then call the kernel.

what happens in bochs: it causes a reset during jmp [cs:clear_pipe]

i'm guessing this means it's not in protected mode, but i can't figure out why, maybe someone else can spot my error?

pretend the "checkpoints" that write single characters to the screen and hang i put in aren't there; it doesn't even make it to them, they're just left over from trying to spot the problematic line.

Code: Select all

[BITS 16]

	;read kernel into low memory temporarily
load_kernel:
	mov ah, 0h
	mov dl, 0h
	int 13h
	or ah,ah
	jnz load_kernel

	mov dl,0h
	mov dh,0h
	mov ch,0h
	mov cl,2h
	mov bx,0h
	mov ax,50h
	mov es,ax
	mov al,8h
	mov ah,02h
	int 13h
	jnc done_loading

disk_err:
	mov ah,0eh
	mov al,'E'
	int 10h
	mov al,'R'
	int 10h
	int 10h
	mov al,ah
	mov ah,0eh
	add al,'0'
	int 10h

	jmp $

gdt_desc:
	dw gdt_end - gdt - 1
	dd gdt

%include "a20line.asm"

done_loading:
	call enable_a20

	;move into protected mode
	cli

	xor ax,ax
	mov ds,ax

	lgdt [gdt_desc]

	mov eax,cr0
	or eax,1
	mov cr0,eax

	jmp [cs:clear_pipe]

[BITS 32]
clear_pipe:
	mov byte [ds:0b8000h],'A'
	jmp $
	mov ax,10h
	mov ds,ax
	mov ss,ax
	mov esp,90000h

	mov dword [ds:0b8000h],'P M '
	mov dword [ds:0b8004h],'O D '
	mov dword [ds:0b8008h],'E - '

	;move kernel code from 500h to 100000h
	mov ecx,500h	;original code buffer
	mov edx,100000h	;new code buffer
movekernelloop:
	mov ebx,[ds:ecx]
	mov [ds:edx],ebx
	add ecx,4
	add edx,4
	cmp edx,101000h
	jne movekernelloop

	;call [cs:100000h]
	mov byte [ds:0b8000h],'B'
	jmp $

gdt:
gdt_null:
	dd 0
	dd 0
gdt_code:
	dw 0ffffh
	dw 0h
	db 0h
	db 10011010b
	db 11001111b
	db 0h
gdt_data:
	dw 0ffffh
	dw 0h
	db 0h
	db 10010010b
	db 11001111b
	db 0h
gdt_end:

times 510-($-$$) db 0
	dw 0aa55h
and the included file, "a20line.asm" was basically a copy and paste from an online tutorial and is this (but i doubt the problem is here, this has worked since i included it, but it's here just in case)

Code: Select all

enable_a20:
	call    a20wait
        mov     al,0xAD
        out     0x64,al

        call    a20wait
        mov     al,0xD0
        out     0x64,al

        call    a20wait2
        in      al,0x60
        push    eax

        call    a20wait
        mov     al,0xD1
        out     0x64,al

        call    a20wait
        pop     eax
        or      al,2
        out     0x60,al

        call    a20wait
        mov     al,0xAE
        out     0x64,al

        call    a20wait
        sti
        ret

a20wait:
.l0:    in      al,0x64
        test    al,2
        jz      .l2
        jmp     .l0
.l2:    ret


a20wait2:
.l0:    in      al,0x64
        test    al,1
        jnz     .l2
        jmp     .l0
.l2:    ret
thanks in advance.[/code]

Re: eugh, what's wrong? this should be real simple.

Posted: Sat Nov 26, 2005 12:00 am
by robert macabre
oh, nevermind, it was just a few small mistakes. like forgetting [ORG 0x7C00] and putting that checkpoint in before DS was initialized. so uh.. if you're writing a bootloader, don't do those things.

Re: eugh, what's wrong? this should be real simple.

Posted: Sun Nov 27, 2005 12:00 am
by mrkaktus
I was fighting with this ORG mistake in my bootl about 7days ;/. So I know how much it pains :P.