I am creating a basic MBR that reads the Partition Table and loads the first sector of the Bootable Partition. I am confused by the CHS and LBA addressing modes. I read in a tutorial that CHS is more or less not used except for compatibility reasons. So, I opted to use LBA(INT 13h extensions). To load the sector of the drive, I have to read the CHS value from the Partition table of that partition. Only then I could convert it to LBA and store it in "Disk Address Packet".
My doubt is, The CHS in Partition table is 1 byte each. Should I take this value directly and convert it into LBA (or) I have to first convert it into,
Cylinder = 10 bits
Sector = 6 bits
Head = 8 bits
and then convert it into LBA?
Note: My MBR must be able to access sectors on both HDD and USB - That is the motive.
OS : Ubuntu
Assembler : Gas
Partition table entries use CHS only for backward compatibility with very old OSes.
They also have fields for the LBA address:
Note that this use LBA32, thus there is a limit on the partition size and position. Quoting Wikipedia:
The same is also true for CHS addressing.
OSes that use the CHS fields have a limitation of about 8 GiB in size.
So if you want to be compatible with them, you need to stay under that limit.
The formula for converting LBA <-> CHS can be easily derived or found on the Internet, you can think in term of sector numbers (i.e. LBA) and convert into CHS when creating the partition entry (or use the defaults 1023, 255, 63 tuble for partition too big for CHS).
Bottom of the line, use the LBA fields.
Or go for GPT.