Page 1 of 1

Booting: int 13h not reading?

Posted: Sat Mar 14, 2009 5:57 am
by instance
Hey,
I'm trying to do a simple 2 stage bootloader for an OS. However, when I tried to load the 2nd part of the boot loader using the int 13 (ah=02) interrupt, though I get no error, I don't think my code gets loaded, because when I dump the memory of the location I've loaded the 2nd part to, I simply get null's all over.
The following are my codes-

boot1.asm

Code: Select all

[BITS 16]
[ORG 0x7c00]
;To load into memory first
mov ah,0  ;dh is already filled by drive letter
int 13h
mov ax,0
mov es,ax
mov bx,0x1000
mov ah,02h
mov al,02  ; number of sectors to read
mov ch,0
mov cl,02h
mov dh,0
int 10h
jc prerror
lea si,[strsuccess]
jmp printstring
prerror:
lea si,[strerror]
jmp printstring
printstring:
	mov ah,0Eh
	mov al,[si]
	cmp al,'$'
	je progend
	mov bh,0
	mov bl,0fh
	inc si
	int 10h
	jmp printstring
progend:
	jmp progend
strsuccess db 'Loaded Successfully$'
strerror db 'Unable to Load$'
times 510-($-$$) db 0
db 055h
db 0aah

boot2.asm:

Code: Select all

times 1024-($-$$) db 'A'

My compilation:

Code: Select all

nasm boot1.asm
nasm boot2.asm
concat final boot1 boot2
(concat is a small C++ code to concat 2 binary files, and it works, cause I get a 1.5 kb file with both files included in it)


When I ran it with bochs (with experimental windows debugger)-
1. Put breakpoint at 0x7c00
2. "proceed" until the int 13 for loading
3. Do a physical dump of location: 0x00001000

I get only 00's being there, instead of hex ascii value of 'A' (whatever it maybe)


Could sum1 please help me. Its been bugging me for a few days now.

Re: Booting: int 13h not reading?

Posted: Sat Mar 14, 2009 6:29 am
by JohnnyTheDon

Code: Select all

[BITS 16]
[ORG 0x7c00]
mov ax,0
mov es,ax
mov bx,0x1000
mov ah,02h
mov al,02  ; number of sectors to read
mov ch,0
mov cl,02h
mov dh,0
int 13h
jc prerror
lea si,[strsuccess]
jmp printstring
prerror:
lea si,[strerror]
jmp printstring
printstring:
   mov ah,0Eh
   mov al,[si]
   cmp al,'$'
   je progend
   mov bh,0
   mov bl,0fh
   inc si
   int 10h
   jmp printstring
progend:
   jmp progend
strsuccess db 'Loaded Successfully$'
strerror db 'Unable to Load$'
times 510-($-$$) db 0
db 055h
db 0aah
That should do the trick. You have to load the registers before you call the interrupt. You were calling the interrupt, and then loading the parameters.

There are some other things that will work, but could be better. 'lodsb' will replace both 'mov al, [si]' and 'inc si'. 'lea si, [strsuccess]' and 'lea si, [strerror]' can be replaced with 'mov si, strsuccess' and 'mov si, strerror' respectively. lea is unnecessary because you aren't trying to do any funky arithmetic in the address.

Re: Booting: int 13h not reading?

Posted: Sat Mar 14, 2009 6:36 am
by instance
Thank you for your reply.
Actually, the initial int 13h was for resetting drives... read it somewhere its better to do it. But I realized the problem. A typo of 10h instead of 13h :) (The area I was hardly looking at. Instead I kept thinking my loading of registers was wrong)
Thank you for your suggestions about the program. :)

Re: Booting: int 13h not reading?

Posted: Sat Mar 14, 2009 10:39 am
by Dex
Most coder's have a problem with the next part, the jump to the 2nd stage loader and getting the addressing to work right.

Re: Booting: int 13h not reading?

Posted: Sat Mar 14, 2009 12:16 pm
by Troy Martin
Well in this case, since ES=0 and it was loaded to 1000h, you'd jmp 0:1000h.

Voila.