int 13 AH=42 Extended Read, (Using Bochs)

Started by Artoo, November 09, 2006, 04:30:58 AM

Previous topic - Next topic

Artoo

Hello,

I hope someone can help me. I have written some boot code of which I am at the point that I want to read sectors of my hard drive. I am testing my boot code with Bochs' emulator. The config file has the following lines:


floppy_bootsig_check: disabled=0
floppya: 1_44="a.img", status=inserted
ata0-master: type=disk, path="c.img", mode=flat, cylinders=40, heads=16, spt=63, translation=lba
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15


c.img is approx a 20 megabyte file, of which is has two partitions.
a.img is my boot code.

All is working ok except when I try to read sectors of the hard drive (c.img) using hte extended bios interrupt (int 13 AH=42 Extended Read). I've used another floppy disk image (instead of a.img) that has no trouble reading the hard diskt useing the extended read interrupt. But I didnt write this image.

So I am 99.99% sure its not the way I have set up Bochs or c.img.  I am 99.99% sure its my ReadSector Proc:



S_DISK_ADDRESS_PACK STRUCT
        bySize        db SIZEOF S_DISK_ADDRESS_PACK
        byReserved        db 0
        wSectorCount        dw 0
        wBufferOffset         dw 0
        wBufferSegment         dw 0
        dwSectorNumberLo        dd 0
        dwSectorNumberHi        dd 0
S_DISK_ADDRESS_PACK ENDS


bySectorBuffer          db 512 dup (0)
g_DAP          S_DISK_ADDRESS_PACK <>


ReadSector PROC

        PUSHAD

        MOV        g_DAP.bySize,                10h
        MOV        g_DAP.byReserved,            0
        MOV        g_DAP.wBufferOffset,         offset bySectorBuffer
        MOV        g_DAP.wBufferSegment,        DS               
        MOV        g_DAP.wSectorCount,          1
        MOV        g_DAP.dwSectorNumberLo,      0
        MOV        g_DAP.dwSectorNumberHi,      0

;        MOV        SI, OFFSET g_DAP        ; DS:SI = ptr to S_DISK_ADDRESS_PACK
        LEA        SI, OFFSET g_DAP


        MOV        DL, 80h                                ; Drive
        MOV        AH, 42h
        INT        13h
        JNC        ReadSector_Ret                        ;Carry set on error

;todo remove
        PUSH        EAX
        CALL        Print_NewLine
        CALL        Print_NewLine
        POP        EAX
        CALL        Print_EAX_16
        CALL        Print_NewLine
        CALL        Print_NewLine
        Mov        AH,0               ; wait for key
        INT        016h

ReadSector_Ret:
        POPAD

        RET
ReadSector ENDP



On entry to this function, CS = DS = 0x7E00

In the function, Print_EAX_16, prints "C0000C01", thus AH (the error code) is 12.
According to Ralf Browns Interrupt listing, the error is "unsupported track or invalid media"

But the output from Bochs gives: "int13_harddisk: function 42, error 03 !"

So I ask, what am I missing here!?!   :dazzled:  Any help would be greatlfully appreciated.





ToutEnMasm

Hello,
I look at your structure in the SDK and don't find it.it's not very good for you.

follow some references in the SDK on the subject sectors
                            ToutEnMasm
Quote
C:\Program Files\Microsoft Platform SDK\Include\aviriff.h
34   : *             indx (3ff8)   <- size may vary, should be sector sized
38   : *             indx (3ff8)   <- size may vary, should be sector sized
41   : *         JUNK (size)       <- fill to align to sector - 12
42   : *     LIST (7f??????) movi  <- aligned on sector - 12
43   : *         00dc (size)       <- sector aligned
44   : *         01wb (size)       <- sector aligned
45   : *         ix00 (size)       <- sector aligned
46   : *     idx1 (00??????)       <- sector aligned
48   : *     JUNK (size)           <- fill to align to sector -12
50   : *         00dc (size)       <- sector aligned
52   : *     JUNK (size)           <- fill to align to sector - 12
54   : *         00dc (size)       <- sector aligned

C:\Program Files\Microsoft Platform SDK\Include\CiError.h
1186   : //  Page size is not an integral multiple of the sector size of the volume where index is located.

C:\Program Files\Microsoft Platform SDK\Include\clfs.h
316   : ULONG SectorSize;                                   // Underlying container sector size.

C:\Program Files\Microsoft Platform SDK\Include\clfsw32.h
316   : // Given a valid marshalling context calculate the sector algined aggregate

C:\Program Files\Microsoft Platform SDK\Include\esent.h
1437   : #define JET_errLogSectorSizeMismatch      -546  /* the log file sector size does not match the current volume's sector size */
1438   : #define JET_errLogSectorSizeMismatchDatabasesConsistent   -547  /* databases have been recovered, but the log file sector size (used during recovery) does not match the current volume's sector size */

C:\Program Files\Microsoft Platform SDK\Include\LMErr.h
468   : #define NERR_TooManyImageParams (NERR_BASE+409) /* Too many image parameters cross disk sector boundaries.*/

C:\Program Files\Microsoft Platform SDK\Include\LMErrlog.h
446   : * A defective sector on drive %1 has been replaced (hotfixed).
448   : * performance and replenish the volume's spare sector pool.

C:\Program Files\Microsoft Platform SDK\Include\ntstatus.h
1717   : //  {Sector Not Found}
1718   : //  The specified sector does not exist.
4852   : //  While accessing a floppy disk, the track address from the sector ID field was found to be different than the track address maintained by the controller.
7554   : //  Copy protection error - The given sector does not contain a valid key.
7572   : //  Copy protection error - The read failed because the sector is encrypted.
10373   : //  Log service found an invalid log sector.
10382   : //  Log service encountered a log sector with invalid block parity.
10391   : //  Log service encountered a remapped log sector.

C:\Program Files\Microsoft Platform SDK\Include\ObjBase.h
916   : ULONG ulSectorSize;          // docfile header sector size (512)

C:\Program Files\Microsoft Platform SDK\Include\storprop.h
38   : //     lowest bit indicating single-sector reads, and the high bit
39   : //     indictating 32-sector reads.  if reading a given number of

C:\Program Files\Microsoft Platform SDK\Include\WinError.h
334   : //  The drive cannot find the sector requested.
2652   : //  Mismatch between the floppy disk sector ID field and the floppy disk controller track address.
21131   : //  Copy Protection Error - The given sector does not have a valid CSS key.
21149   : //  Copy Protection Error - The read failed because the sector is encrypted.

C:\Program Files\Microsoft Platform SDK\Include\WinIoCtl.h
391   : // F5_1Pt2_512,            // 5.25", 1.2MB,  512 bytes/sector
392   : // F3_1Pt44_512,           // 3.5",  1.44MB, 512 bytes/sector
393   : // F3_2Pt88_512,           // 3.5",  2.88MB, 512 bytes/sector
394   : // F3_20Pt8_512,           // 3.5",  20.8MB, 512 bytes/sector
395   : // F3_720_512,             // 3.5",  720KB,  512 bytes/sector
396   : // F5_360_512,             // 5.25", 360KB,  512 bytes/sector
397   : // F5_320_512,             // 5.25", 320KB,  512 bytes/sector
398   : // F5_320_1024,            // 5.25", 320KB,  1024 bytes/sector
399   : // F5_180_512,             // 5.25", 180KB,  512 bytes/sector
400   : // F5_160_512,             // 5.25", 160KB,  512 bytes/sector
404   : // F3_640_512,             // 3.5" ,  640KB,  512 bytes/sector
405   : // F5_640_512,             // 5.25",  640KB,  512 bytes/sector
406   : // F5_720_512,             // 5.25",  720KB,  512 bytes/sector
407   : // F3_1Pt2_512,            // 3.5" ,  1.2Mb,  512 bytes/sector
408   : // F3_1Pt23_1024,          // 3.5" ,  1.23Mb, 1024 bytes/sector
409   : // F5_1Pt23_1024,          // 5.25",  1.23MB, 1024 bytes/sector
410   : // F3_128Mb_512,           // 3.5" MO 128Mb   512 bytes/sector
411   : // F3_230Mb_512,           // 3.5" MO 230Mb   512 bytes/sector
412   : // F8_256_128,             // 8",     256KB,  128 bytes/sector
826   : F5_1Pt2_512,            // 5.25", 1.2MB,  512 bytes/sector
827   : F3_1Pt44_512,           // 3.5",  1.44MB, 512 bytes/sector
828   : F3_2Pt88_512,           // 3.5",  2.88MB, 512 bytes/sector
829   : F3_20Pt8_512,           // 3.5",  20.8MB, 512 bytes/sector
830   : F3_720_512,             // 3.5",  720KB,  512 bytes/sector
831   : F5_360_512,             // 5.25", 360KB,  512 bytes/sector
832   : F5_320_512,             // 5.25", 320KB,  512 bytes/sector
833   : F5_320_1024,            // 5.25", 320KB,  1024 bytes/sector
834   : F5_180_512,             // 5.25", 180KB,  512 bytes/sector
835   : F5_160_512,             // 5.25", 160KB,  512 bytes/sector
839   : F3_640_512,             // 3.5" ,  640KB,  512 bytes/sector
840   : F5_640_512,             // 5.25",  640KB,  512 bytes/sector
841   : F5_720_512,             // 5.25",  720KB,  512 bytes/sector
842   : F3_1Pt2_512,            // 3.5" ,  1.2Mb,  512 bytes/sector
843   : F3_1Pt23_1024,          // 3.5" ,  1.23Mb, 1024 bytes/sector
844   : F5_1Pt23_1024,          // 5.25",  1.23MB, 1024 bytes/sector
845   : F3_128Mb_512,           // 3.5" MO 128Mb   512 bytes/sector
846   : F3_230Mb_512,           // 3.5" MO 230Mb   512 bytes/sector
847   : F8_256_128,             // 8",     256KB,  128 bytes/sector
1595   : BYTE     bSectorCountReg;        // IDE sector count register
1596   : BYTE     bSectorNumberReg;       // IDE sector number register
1609   : #define ATAPI_ID_CMD    0xA1            // Returns ID sector for ATAPI.
1610   : #define ID_CMD          0xEC            // Returns ID sector for ATA.




ToutEnMasm


follow this link
http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html
And will find that your structure is wrong
                               ToutEnMasm

Artoo

According to this Ralf Brown website:

www.ctyme.com/intr/rb-0708.htm

My structure is identical to the one described.


Anyone else have any other ides?

ToutEnMasm

missing is
10h    QWORD   (EDD-3.0, optional) 64-bit flat address of transfer buffer;
used if DWORD at 04h is FFFFh:FFFFh
size is incorrect
There is something that I don't find it's the meaning of error 3,seems to be a data error,but I am not sure.

japheth


> size is incorrect

no, size 10h is correct since content of field at offset 0004 is not ffff:ffff.

since AH and DL parameters are correct and the content of DAP as well, the error must be in DS:SI:

;        MOV        SI, OFFSET g_DAP        ; DS:SI = ptr to S_DISK_ADDRESS_PACK
        LEA        SI, OFFSET g_DAP

For MASM, the first line is correct (the second should give an error)

But you should create a listing file to actually see what code is generated. Since you didn't provide the full source, we cannot see what value DS has and should have. Must it be 0000h or 07C0h or what?

Regards

Japheth








Artoo

I am pretty sure DS:SI is correct, as I debugged it in Bochs, and it was 7E00:NNNN where NNNN is number in the list file.  (7E00 is the sector of my second stage boot code).

Also if I change th code so that dwSectorNumberHi is something other than 0 then Boch complains about not liking a 64Bit LBA number.  So if DS:SI was incorrect then Boch wouldnt detect the change in dwSectorNumberHi.  (I hope that makes sense).


I appreciate your help!  Any other suggetion would help greatly.  Anything I can dotyo make it easier for your guys? Supply a LST file?

japheth


Hi,

my suggestion is to do an int 13h, ah=41h before the read to make sure the drive is valid and the extensions are installed for that drive.

sinsi

I used an old DOS5 floppy to make a.img and an empty 20 meg file for c.img
Booting from A and using DEBUG I tried to read disk 80h using function 42h - no error, read sector 0 OK.

Post some code! At least the boot sector code.

PS I am using Bochs 2.3
Light travels faster than sound, that's why some people seem bright until you hear them.

Artoo

I do an AH=41 before my read sector. It is successful.


I'll post some code on Monday when I get back to my work pc.

Thanks again.

MichaelW

I tested the call from a MS-DOS 6.22 boot disk and it works OK.


eschew obfuscation