Why is INT 0x13 AH=0x02 crashing?

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.
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

Hi. I'm trying to write a stage 1 boot loader. I setup all the registers to call int 0x13:

Code: Select all

mov bx,0x1000
mov es,bx
mov bx,0x0
mov dh,0
mov al,4
mov cl,16
mov ah,0x02
mov ch,1
Now I call int 0x13 and try to read stage 2 from the disk:

Code: Select all

int 0x13
jc .error
jmp $
.error:
mov bx,ERROR
call print_string
jmp $
But it fails. .error gets called and it prints an error message. Why?
Last edited by Isaac on Sun Apr 27, 2014 7:05 pm, edited 3 times in total.
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Octocontrabass »

How did you get the values that you're using to call int 0x13?
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

The values I stored in those registers tell the BIOS where to read from and where to write to.
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Octocontrabass »

Well yes, I know that's what they're supposed to do. :P

I want to know how you chose those values specifically.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Why is INT 0x13 AH=0x02 crashing?

Post by iansjack »

You don't specify the drive number. It's probably trying to read a non-existant drive.
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

ES:BX - I chose where to store the data based on a map that I saw. The map shows where everything is loaded into RAM. I just looked around for a big empty space.
DH,CH,CL - I chose these values based on the structure of an ISO 9660 filesystem. I'm trying to load the primary volume descriptor so that I can find out where the root directory is and where stage 2 is.
AH - This has to be 0x02.
AL - This is the size of the primary volume descriptor.

I can change some of these values if that's the problem.

The drive number is automatically stored in DL when the BIOS loads this code.
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Octocontrabass »

Isaac wrote:ISO 9660
Are you booting from a CD in no-emulation mode?
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

Yes. Is that a problem?

Actually, I tested this code on both qemu and real hardware.
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Octocontrabass »

I think you should look at the El Torito specification (PDF). In particular, read section 5.3.
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

I read it. But what are you trying to point out?
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Octocontrabass »

After the boot process has been initiated the INT 13 Extensions (functions 41-48) will access the CD using 800 byte sectors and the LBA address provided to INT 13 is an absolute sector number.
You must use int 0x13 ah=0x42 to read the disk.
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

I tried that and it still fails. Is there any way I can know way it fails? Can I watch what goes on while I run the bootsector on qemu?
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Octocontrabass »

The function will return an error code if it fails. Display the error code on the screen, then look up what it means in RBIL or some other source.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Why is INT 0x13 AH=0x02 crashing?

Post by iansjack »

Isaac wrote:I tried that and it still fails. Is there any way I can know way it fails? Can I watch what goes on while I run the bootsector on qemu?
We have now determined that your original code is never going to work. So what code are you now using to do the Extended Read Sectors call? It's almost certain that your DAP isn't valid.
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Why is INT 0x13 AH=0x02 crashing?

Post by Isaac »

My DAP:

Code: Select all

mov byte [bx],0x10
mov byte [bx+1],0x0
mov word [bx+2],4
mov dword [bx+4],0x9000
mov byte [bx+8],2
mov si,bx
BX contains the location of my DAP... Anything wrong with my DAP?
Post Reply