Int $13, AH=$42 doesn't set CF, but does not load anything

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
charlemagne
Posts: 3
Joined: Sun Mar 21, 2010 5:57 am

Int $13, AH=$42 doesn't set CF, but does not load anything

Post by charlemagne »

Hello, all.

I'm writing a boot loader which will be hosted on a FAT32 filesystem. I am finding that Int13, AX=42 is succeeding (not setting CF), but the destination buffer is all zeroes after the call. I've reduced the code to something simple enough to post that still exhibits the problem -- so there's no BIOS Parameter Block, no checking for Int13 extensions (running Int13, AH=41 returns CX=7 in my install of VMWare), drive hard-coded to $80, etc in this post.

The code just tries to load the MBR into a buffer and check that the buffer's first word is not 0. Unfortunately, it is zero.

I'm running this in VMWare Player 3.0.0. It gives the same result in Bochs. (It prints 'a'.)

I'm assuming CS=DS=$07c0 because I read in a post somewhere that some BIOSes don't like DS=0. I'm setting up SS/SP, DS, ES, FS, and GS inside CLI/STI because I'm not sure how atomic the startup has to be wrt interrupts. Wikipedia's INT13 page tells me that the first sector is 0. This code is in FASM.

Thanks for the help.

Code: Select all

format binary
use16
org $0000



jmp $07c0:Start
Start:

cli
mov ax, $0050
mov ss, ax
mov sp, $0100
mov ax, $07c0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
sti


mov ah, $42
mov dl, $80
mov si, DAP
int $13
jc Failed2


mov ax, word [Buffer]
test ax, ax
jnz Success


Failed1:
mov al, 'a'
jmp ShowResult


Failed2:
mov al, 'b'
jmp ShowResult


Success:
mov al, 'c'


ShowResult:
mov ah, $0e
int $10

Halt:
jmp Halt


DAP:
.Size                                   db 16
.Reserved1                              db 0
.Count                                  db 1
.Reserved2                              db 0
.BufSeg                                 dw $07c0
.BufOfs                                 dw Buffer
.LBA                                    dq 0



times (510 - ($ - $$))                  db 0
                                        dw $aa55


Buffer:                                 rb 512
Selenic
Member
Member
Posts: 123
Joined: Sat Jan 23, 2010 2:56 pm

Re: Int $13, AH=$42 doesn't set CF, but does not load anything

Post by Selenic »

The wiki wrote: 4 DWORD -> transfer buffer (16 bit segment:16 bit offset)
It looks like you've misinterpreted this bit from the wiki (like I did at first). It looks like it says the segment goes first, followed by the offset, but remember that x86 is little-endian, so it's actually the other way around.
charlemagne
Posts: 3
Joined: Sun Mar 21, 2010 5:57 am

Re: Int $13, AH=$42 doesn't set CF, but does not load anything

Post by charlemagne »

Thank you; it worked. I've added a note to the wiki to stop others from stumbling over this.
Post Reply