Booting: int 13h not reading?

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
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Booting: int 13h not reading?

Post 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.
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Booting: int 13h not reading?

Post 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.
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Re: Booting: int 13h not reading?

Post 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. :)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Booting: int 13h not reading?

Post 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.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Booting: int 13h not reading?

Post by Troy Martin »

Well in this case, since ES=0 and it was loaded to 1000h, you'd jmp 0:1000h.

Voila.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply