Page 1 of 1

small problem with my bootloader

Posted: Sun Oct 28, 2007 3:37 am
by 0z0
I'm having problems with my bootloader, it works when you do simple stuff like printing 1 character, but my print code fails. It is probably because I have not set the data registers etc properly after the jmp, but I can't find any info how to do that.. The error is not in the print code, I've tested it elsewhere..

Code: Select all

;=====================
;real mode boot loader
;=====================

[BITS 16]
[ORG 0x7C00]


main:
	mov [bdrive],dl
	
	
	;reset floppy for reading
	resetd:
		mov ah, 0
		mov dl,[bdrive]


		int 13h
		jc resetd


	;loop until sectors read
	readd:
		mov ax,1000h
		mov es,ax
		mov bx,0 ;ES:BX = 1000:0
			;load kernel to here

		mov ah,02h ;read sectors
		mov al,0Ah ;read 10 sectors ;remember to change..
		mov ch,0 ;cylinder 0
		mov cl,02h ;sector 2
		mov dh,0 ;head 0
		mov dl,[bdrive]
		

		int 13h
		jc readd

	;stop floppy disk motor
	mov dx,0x3f2
        mov al,0
        out dx,al 

	;jump to kernel
	jmp 1000h:0


;boot loader data
bdrive db 0


;boot sig
times 510-($-$$) db 0
dw 0xAA55

;===========================
;START OF ACTUAL KERNEL CODE
;===========================
	;set registers (the problem is probably here)
	cli
	mov ax,1000h
	mov es,ax
	mov ds,ax


	;stack to 0x9000:0xFFFE
	mov ax,0x9000
	mov ss,ax
	mov sp, 0XFFFE
	sti


	mov ah,0x0E
	mov al,'q'
	mov bh,0x00
	int 10h

	mov si, string1
	call print

	
	.halt
	jmp .halt

	;proper end
	cli
	hlt


print:

	mov ah,0x0E
	mov bh,0x00

	.printl
		lodsb
 		or al,al
 		jz .printdone
 		int 10h
 	jmp .printl
	.printdone
 	ret


;DATA
string1 db 'kernel started',13,10,0

times 5000 db 0

Posted: Sun Oct 28, 2007 9:51 am
by 0z0
It was fixed by splitting the bootloader and kernel to 2 different files, then merging them after compiling.

Posted: Sun Oct 28, 2007 4:25 pm
by Dex
If you add a ORG after the " dw 0xAA55" with the load address, it should work as one file too.