What happens when reading disk to an address greater than 0xffff

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
mtjq
Posts: 1
Joined: Mon Jan 13, 2025 5:11 pm
Libera.chat IRC: mtjq

What happens when reading disk to an address greater than 0xffff

Post by mtjq »

Hi,

Like many, I started writing a bootloader and os for x86. I just spent a lot of time trying to debug a step where I read several sectors (my kernel) from my disk image to load them in memory and jump to the entry point. But when jumping to the entry point, bytes were all to 0. More precisely, I loaded the binary to the address 0x7e00. But I realised that I loaded to many sectors (something like 0x50), loading only 0x40 sectors worked. My understanding is that I was writing 0x50 * 0x200 = 0x8000 bytes, starting at address 0x7e00, which will go beyond 0xffff. As I was still in 16-bit mode, I guess that it triggered some behaviour I did not expect, like maybe "wrap around" to 0x0 after writing to 0xffff, thus overwriting the IVT, BDA etc? Does `int 0x13` actually increments a register with the current writing address, and that overflows and wraps around?
Octocontrabass
Member
Member
Posts: 5623
Joined: Mon Mar 25, 2013 7:01 pm

Re: What happens when reading disk to an address greater than 0xffff

Post by Octocontrabass »

Did you check the INT 0x13 return values? You should have received an error. The ISA DMA controllers have 16-bit address registers, so your data buffer can't cross a 64kB boundary without causing address wraparound. The BIOS is smart enough to catch this problem and return an error instead of blindly corrupting memory.

ISA DMA is only used for floppy drives, but many BIOSes enforce the limit for hard drives too.
Post Reply