1

I am developing a minimalistic Operating System. I created a MBR that looks in the Master Partition Table for active partition. The Problem I am facing is with the loading of sectors into memory.

With respect to loading sectors, I came across two schemes,

  • CHS addressing
  • LBA addressing

I read that CHS is supported by almost all BIOS but the problem lies in the fact that it can address atmost 8GB and this drawback is rectified with LBA.

With those being said, I would like to ask some questions:

Question 1:

What scheme is best to choose with? If CHS, Is there any way I could access above the 8GB mark?

Question 2:

In LBA, how will I be able to load a sector from (say)partition 4?

ie: How will I be able to find the starting block number of 4th partition?


Note: The scenario happens in 16 bit real mode.


Thanks.

OS : Ubuntu

Compiler : CC

Panther Coder
  • 1,058
  • 1
  • 16
  • 43
  • But this question is different at least with the sub questions I asked. Kindly answer the question. – Panther Coder Mar 14 '17 at 13:24
  • 2
    1. In short, forget CHS. 2. To load from partition 4 you should read about partition tables and understand how it works. Then you won't ask this question. Again, in short, you get starting LBA of partition 4 from MBR to be able to convert relative sector in partition to absolute LBA, then read – Alexander Zhak Mar 14 '17 at 13:28
  • So, Can I rely on LBA completely rather than CHS? @Alexander Zhak – Panther Coder Mar 14 '17 at 13:33
  • 1
    Asking two questions per post is not following the SO etiquette. You can't really argue that "one of your sub-question is not a duplicate" - there is no such thing as a sub-question. Even admitting their existence (which sometimes we do) in your case the first is an exact duplicate that **you** already asked. The second is too broad/not researched - which partition scheme? What seems to be the problem? – Margaret Bloom Mar 14 '17 at 13:33
  • 1
    I'm voting to close this question. Not because of the similarity to the duplicate, but because they are both authored by the same nick and are close to identical. – zx485 Mar 14 '17 at 13:35
  • 1
    BTW: CHS is ancient. Today, there's no alternative to LBA. – zx485 Mar 14 '17 at 13:37

1 Answers1

2

Use the BIOS extended read function, which uses a 64 bit LBA (a Sata drive would use the lower 48 bits of the LBA).

INT 13 - IBM/MS INT 13 Extensions - EXTENDED READ
       AH = 42h
       DL = drive number
       DS:SI -> disk address packet
Return: CF clear if successful
           AH = 00h
       CF set on error
           AH = error code
           disk address packet's block count field set to number of blocks
             successfully transferred

Format of disk address packet:
Offset Size     Description
 00h   BYTE     10h (size of packet)
 01h   BYTE     reserved (0)
 02h   WORD     number of blocks to transfer
 04h   DWORD    -> transfer buffer
 08h   QWORD    starting absolute block number  (LBA)

The question mentions MBR. Normally the first sector on a hard drive is a partition sector that includes a table of partitions (typically 4 of them), and which one is active. The partition boot code usually relocates itself (Microsoft relocates to 00000h:00600h), and reads in the MBR from the active partition into 00000h:07c00h, and then jumps to the MBR code.

rcgldr
  • 27,407
  • 3
  • 36
  • 61
  • The Starting Absolute Block address is `QWORD` which is 64 bit long. Where will I get this value from? The MBR partition table has a relative sector field which is same as starting sector of a partition but is 32 bits long. So, should I pad the remaining bits with `0`? Also should I consider `endianess` when moving the data from Partition table to Disk address packet? @rcgldr – Panther Coder Mar 15 '17 at 16:16
  • 1
    Store the 32 bit relative sector into the first (lower) dword of the qword block number and a zero in the second (upper) dword of the qword block number. This assumes you're using a normal 32 bit store which would be little endian. – rcgldr Mar 15 '17 at 17:46