views:

91

answers:

2

I'm trying a new approach to int 0x13 (just to learn more about the way the system works): using stack to create a DAP..

Assuming that DL contains the disk number, AX contains the address of the bootable entry in PT, DS is updated to the right segment and the stack is correctly set, this is the code:

push DWORD 0x00000000
add ax, 0x0008
mov si, ax
push DWORD [ds:(si)]
push DWORD 0x00007c00
push WORD 0x0001
push WORD 0x0010
push ss
pop ds
mov si, sp
mov sp, bp
mov ah, 0x42
int 0x13

As you can see: I push the dap structure onto the stack, update DS:SI in order to point to it, DL is already set, then set AX to 0x42 and call int 0x13

the result is error 0x01 in AH and obviously CF set. No sectors are transferred. I checked the stack trace endlessly and it is ok, the partition table is ok too.. I cannot figure out what I'm missing...

This is the stack trace portion of the disk address packet:

   0x000079ea:    10 00   adc    %al,(%bx,%si)
   0x000079ec:    01 00   add    %ax,(%bx,%si)
   0x000079ee:    00 7c 00   add    %bh,0x0(%si)
   0x000079f1:    00 00   add    %al,(%bx,%si)
   0x000079f3:    08 00   or     %al,(%bx,%si)
   0x000079f5:    00 00   add    %al,(%bx,%si)
   0x000079f7:    00 00   add    %al,(%bx,%si)
   0x000079f9:    00 a0 07 be   add    %ah,-0x41f9(%bx,%si)

I'm using qemu latest version and trying to read from hard drive (0x80), have also tried with a 4bytes alignment for the structure with the same result (CF 1 AH 0x01), the extensions are present.

A: 

Did you make sure INT 13 extensions are supported?

MOV AH, 41H
MOV BX, 55AAH          
MOV DL, 80H                ; drive number
INT 13H
JC Unsupported
I. J. Kennedy
Of course yes, as I said at the end of the question, extensions are present.
IceCoder
+2  A: 

What is the mov sp, bp doing - where does BP point? Is it at (or close to) SP before the code fragment above?

My guess is that you're resetting the stack pointer in such a way that your DAP is being corrupted by the stack usage of the INT 13 call. e.g.:

1) Initial state:           2) After pushing DAP:

|  (stuff)  |               |  (stuff)  |
+-----------+ <-SP          +-----------+ <-BP?
             (== BP?)       |           |
                            |    DAP    |
                            |           |
                            +-----------+ <-SP


3) After mov sp, bp         4) INT 13 stack usage corrupts DAP:

|  (stuff)  |               |  (stuff)  |
+-----------+ <-SP?         +-----------+ SP
|           |               |XXXXXXXXXXX| | INT 13 uses stack 
|    DAP    |               |XXXXXXXXXXX| v
|           |               |corrupt DAP|
+-----------+ <-DS:SI       +-----------+
Matthew Slattery
bp points exactly before the DAP.. I think you got it, I inspected the stack after calling int 0x13 and the DAP structure was completely wrong but I didn't figure out why, that moment..
IceCoder