Loading Kernel With Int 0x13

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
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Loading Kernel With Int 0x13

Post by brodeur235 »

Here's my nasm floppy .img:

Code: Select all

[ORG 0x7C00]

main:
	mov ax,0x0000
	mov ds,ax
	
	mov si,waitmsg
	call print_string
	
	call load_kernel
	
	mov si,procexited
	call print_string
	
	jmp 0x7E00

;procedures
print_string:
	mov ah,0x0E
	mov bh,0x00
	mov bl,0x07
	.next_char
		lodsb                    ;(1)[si] loaded into al (2)si incremented by 1
		cmp al,0
		jz .done
		int 0x10
		jmp .next_char
	.done
		ret

load_kernel:
	mov si,prochit
	call print_string
	
	xor ax,ax
	mov es,ax
	mov bx,0x7E00
	mov dh,0x00
	mov dl,0x01
	mov ch,0x01
	mov cl,0x02
	mov bx,0x0000
	mov ah,0x02
	mov al,0x01
	int 0x13
	ret

;data
waitmsg db "Loading Kernel. Please Wait . . .",0xD,0xA,0
prochit db "Now In Kernel Loading Procedure . . .",0xD,0xA,0
procexited db "Now Returned From Kernel Loading Procedure . . .",0xD,0xA,0

;pad
times 510-($-$$) db 0

;make drive bootable
dw 0xAA55





;No longer in bootloader
;Now in sector 2
;begin kernel code
kernel:
	mov ax,0x0000
	mov ds,ax
	mov si,loaded
	call print_string
	
	jmp $

;data
loaded db "The kernel is loaded and executing.",0xD,0xA,0

;pad
times 512-($-kernel) db 0
The output is:

Code: Select all

Loading Kernel. Please Wait . . .
Now In Kernel Loading Procedure . . .
Now Returned From Kernel Loading Procedure . . .
I don't know why that last JMP of my bootloader didn't work to jump to the loaded kernel. Either my JMP didn't work, or int 0x13 didn't work (more likely wasn't used correctly). But these are just suspicions and I can't find a solid error anywhere, despite the fact my kernel is never executed...

All help is appreciated,

Brodeur235
User avatar
Blue
Member
Member
Posts: 31
Joined: Thu Aug 02, 2007 6:34 am
Location: on the stack

Re: Loading Kernel With Int 0x13

Post by Blue »

Heya,

One thing I noticed, which might be your problem is that you first load BX with 0x7E00(which i presume is what you want), but before calling int 0x13 you load it with 0x0000. ES is already set to 0x0000, so you will be loading it all to 0x0000:0x0000, and not to 0x0000:0x7E00 where you want to jump to.

Code: Select all

load_kernel:
        ...
	mov bx,0x7E00
        ...
	mov bx,0x0000
	mov ah,0x02
	mov al,0x01
	int 0x13
	ret
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Re: Loading Kernel With Int 0x13

Post by brodeur235 »

You are right... That was actually just one of a couple problems and thanks for pointing that out because it would have taken me more time and stress to catch it. The other problem was that head number starts at 0, not 1. So when I wanted to load from the top of the disk (head 0) I was actually reading from the bottom... Kinda funny actually. Thank you for your help Blue,

Brodeur235
lye
Posts: 8
Joined: Mon Jun 08, 2009 6:36 pm

Re: Loading Kernel With Int 0x13

Post by lye »

What I did was start with org 0. Then mov ax, 0x7c0 mov ds, ax for setup. Then do the same with 0x7e later before you load your kernel. Then your string will be found and should function.

Also, it should be a jmp 0000:0x7E00. Then from the little bit it should be good. I would add some error checking to the read. A simple jc error_msg_here will show if the read succeeded.
Post Reply