Page 1 of 1

CanI use int 13h function 42h to read more than 1mb of disk

Posted: Fri May 19, 2017 10:31 am
by elad
theoretically you can specify the number of sectors you want to read from 0 - 65535 but how many can you actually read at once ? is this interrup limited to addressing memory that it's linear locarion is no bigger than 1mb ( 2 ^ 20 default real mode maximum memory size ) or does it using unreal mode or something like that and can read even 65535 sectors (16mb to the ram).

Re: CanI use int 13h function 42h to read more than 1mb of d

Posted: Fri May 19, 2017 11:28 am
by BrightLight
Theoretically, you can read up to 65535 sectors using this function, as the sectors count fields in the disk address packet structure is 16 bits wide. However, in practice, the majority of BIOSes, including Bochs, QEMU and one of my real PCs, don't allow you to cross a segment boundary. This depends on your segment:offset combinations. Assuming you're using a specific segment with offset 0, the maximum value is 127 sectors for most BIOSes. For compatibility's sake, you should split up large accesses into smaller accesses, each 127 sectors (or less) in size.

Re: CanI use int 13h function 42h to read more than 1mb of d

Posted: Fri May 19, 2017 11:36 am
by Brendan
Hi,
elad wrote:theoretically you can specify the number of sectors you want to read from 0 - 65535 but how many can you actually read at once ? does this interrup is limited to only addressing memory that it's linear loc is no bigger than 1mb ( 2 ^ 20 default real mode maximum memory size) or does it using unreal mode or something like that and can read even 65535 sectors (16mb to the ram) sorry for my english.
The maximum you can read at once depends on multiple things (which firmware, which device, etc). If you look at the Enhanced Disk Drive Specifications (at least up to version 3.0) you'll find that the "number of blocks to transfer" field is a 1 byte field (followed by a reserved byte that must be zero), and the specification will say:
  • "Number of blocks to transfer. This field has a maximum value of 127 (7Fh). If a value greater than 127 is supplied the request is rejected with CF=1 and AH=01. A block count of 0 means no data will be transferred."
Some implementations might not comply with the EDD specifications, and might allow more than 127 blocks to be transferred (by failing to reject the request with CF=1), and some might allow more than 255 blocks to be transferred (by failing to treat the reserved/"must be zero" byte as reserved).

For "absolute theoretical maximum", if you can invent/create a device where each sector is 4 GiB and find a computer where EDD is "very broken", you could load 262140 GiB.

Also note that I'd expect the firmware to use the controller's DMA/bus mastering to load data directly into the physical address you requested without using the CPU (and without needing unreal mode or protected mode); but there's no guarantee that the BIOS will do that, and there's no guarantee that the BIOS won't (e.g.) switch to protected mode or long mode (and do the transfer with PIO) and switch back to real mode after.


Cheers,

Brendan