Page 1 of 1

Bootloader Issues

Posted: Mon Mar 04, 2013 2:08 am
by kohlrak
I've been working on this small kernel for a couple of weeks now, but I cannot, for the life of me, figure out what is wrong with this bootloader. The structure stuff was smarter and much cleaner, but then i decided to op in for what i'm doing here to try to get rid of the ISR returning 1 in AH every time i try to read something to location 0x8000. Could someone take a look at it and tell me what i'm doing wrong that could result in it refusing to go beyond 0x7f80? (NOTE: i intentionally only posted the bootloader because i'm sure the problem is there.)

Code: Select all

use16
	org	0x7c00
microkernelStart:
	jmp	xEntry
	nop
	db "ColKern "
xEntry:	xor ax, ax
	mov ds, ax	;set data segment to 0
	mov es, ax
	mov ss, ax
	mov sp, 0x7c00

tryBoot:
	
	mov ah, 0x42
	mov si, meow
	mov bx, 0x7c00
	mov word [meow+2], 1
	int 0x13
	jc tryBoot
	add word [meow+4], 0x80
	add word [meow+8], 1
	cmp word [meow+4], 0x9000
	jne tryBoot
	jmp boot

	mov ah,0Fh
	int 10h
	mov si,bootErrorMsg
	mov ah,0Eh
@@:	mov al,[si]
	int 10h
	inc si
	or al, al
	jne @b

	jmp	tryBoot ;try again (i hope if it fails it doesn't actually write the failures to RAM)

meow:	db 0x10
	db 0
	dw 0x1
	dd 0x00007c00
	dq 0x0000000000000000
bootErrorMsg db 'unable to read disk.', 0

	times (7DFEh-$) db 0
	dw 0xAA55

include "main.asm"
Also, i'm curious, to use the 0x18 byte version to use the qword, do i have to be on a processor capable of long mode? Also, offset 4 (location of where you want to put this stuff) is 4 bytes, but is that using flat style addressing or is it using realmode style addressing?

Re: Bootloader Issues

Posted: Mon Mar 04, 2013 2:27 am
by Combuster
You're not trying out EDD on a floppy drive, are you?

Re: Bootloader Issues

Posted: Mon Mar 04, 2013 2:36 am
by egos
kohlrak, each sector reading takes step 200h, not 80h. So maybe you have read all available sectors.

And don't try to overlap your boot code while it's still working :D

Re: Bootloader Issues

Posted: Mon Mar 04, 2013 8:29 am
by kohlrak
You're not trying out EDD on a floppy drive, are you?
No, hard drive image (which becomes a USB on real hardware). Actually it doesn't need EDD yet, as it's not even 4KB. I'm just setting it up for later, especially when i want to load a program that uses this kernel into high memory (after the ISA hole, of course: i'm using the area before the ISA hole for my double buffer).
kohlrak, each sector reading takes step 200h, not 80h. So maybe you have read all available sectors.
At first my problem was that it wasn't loading every sector, now apparently I actually did send it a bad number (well, my routine using it, not it itself). Anyway, thanks to you, now it works.
And don't try to overlap your boot code while it's still working :D
Yeah, i shouldn't. Most people do it fine, but all it needs to do is read that sector 0 in wrong when overwriting itself and it goes kaboom.

Anyway, I still have one issue: does that EDD function with the 64bit packet work without being in long mode on a long mode processor (this is more curiosity than anything, since my kernel's 32bit)? Also, that pointer to the starting address (offset 4), is the high word work like a 16bit segment register where it's a leftshift by a nibble then add the two together or will that allow me to point up to 0x80000000 (not that i hope i'll be writing that high, but I do want to write into high memory without implementing v86 mode [i'm really only using 16bit to set my video mode and load my kernel, and i'd prefer to keep it that way if possible])?

Re: Bootloader Issues

Posted: Mon Mar 04, 2013 11:54 am
by egos
Look at EDD Spec. I don't use extended DAP format. In the traditional form is used RM pointer segment:offset (offset goes first). So your "dd 7C00h" is correct RM pointer 0:7C00h. In fasm I can write "dd 0:7C00h" as well.

Re: Bootloader Issues

Posted: Mon Mar 04, 2013 7:58 pm
by kohlrak
egos wrote:Look at EDD Spec. I don't use extended DAP format. In the traditional form is used RM pointer segment:offset (offset goes first). So your "dd 7C00h" is correct RM pointer 0:7C00h. In fasm I can write "dd 0:7C00h" as well.
I'm using FASM. I'm still trying to decide whether i want to attempt to port fasm to C++ for portability or just switch to GNU AS for everything non-x86. The org here is assuming flat address since i didn't specify a segment. Anyway, i didn't know there was an EDD spec, but now that i do i have the pdf open in another window, so i thank you for your help.