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

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
elad
Posts: 8
Joined: Sat May 06, 2017 11:35 am
Libera.chat IRC: elad

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

Post 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).
Last edited by elad on Sat Oct 26, 2024 7:42 pm, edited 1 time in total.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

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

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply