Are you using 32-bit registers?
Might I suggest that you pass three parameters to your read routine?
Starting LBA -> (edx:)eax
Count of sectors to read -> (e)cx
Physical address to read to -> ebx
Then in your read routine, you can easily change the physical address to a segmented address.
offset = ebx & 0xF
segment = ebx >> 4
Place the offset in BX and the segment in ES and you're done.
Some code I have does just this.
Also, I wanted to comment on:
Quote:
I have now solved the issue, my stack was setup at 0x07C0:0x0000, I wanted it to grow down from where the bootloader starts,
If you initially set ss:sp to 0x07C0:0x0000, you realize that even though your stack grows down, it grows down from 0x07C0:0xFFFF + 1, 65536 bytes above where you think it does.
Next,
Quote:
I'm using INT 13H with AH=42H. I've also used AH=02H but that also fails.
You can check to see if the BIOS supports the Extended Services for that drive, reverting to the CHS services if needed. Most BIOSes support the Extended Services, as long as it isn't a floppy. (Fun fact: I have a machine with an odd-ball BIOS that supports the Extended Services for the floppy as well.)
Anyway, I may be wrong, so I apologize if I am, but I think you don't quite understand segmentation. Segments aren't a consecutive set of 64k blocks, one right after the other. Segments can reside at any 16-byte boundary.
For example, the following segmented addresses all point to the same physical address:
Code:
0x07C0:0x0000
0x0600:0x1C00
0x0555:0x26B0
0x0000:0x7C00
Anyway, I suggest that you split up your code so that you call a routine to read from the disk. This routine can decide which BIOS service to call, leaving your initial code to not have any concern which was used. Simply pass the Staring LBA, the count of sectors to read, and the physical address to place the data. Let the called routine worry about how to read from the disk.
Hope this helps,
Ben
-
https://www.fysnet.net/osdesign_book_series.htm