how does the bootblock know in what sector it is?

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
frank

how does the bootblock know in what sector it is?

Post by frank »

When lilo (or another bootsector) boots the 512b bootblock,
how does the bootblock know in what sector it is?
anton

RE:how does the bootblock know in what sector it is?

Post by anton »

Only the first sector of the disk is booted(or the first sector of the logical disk(lilo), in wich case, this sector will contain the physical sector humber).
frank

RE:how does the bootblock know in what sector it is?

Post by frank »

yes, but I mean the partition boot block.
lilo (at mbr) loads the first sector of the partition.
(which should load the os), but how does to first sector of the partion
knows in what sector it is?
anton

RE:how does the bootblock know in what sector it is?

Post by anton »

It looks in to the partition table to find it's entry(compares some signatures or what ever) and so it finds the beg of the partition(boot sector).
anton
Basant

RE:how does the bootblock know in what sector it is?

Post by Basant »

fine... so far so good... now if i have an os on the 2nd partition of my hdd what exactly will my boot sector code be in order to access the program in exactly the next block of the hdd?...
Note:
im writing the the two programs using dd as follows
for bootloader>>   dd if=boot.app of=/dev/hda2
for program>>      dd if=prog.app of=/dev/hda2 seek 1 (or something like that)
anton

RE:how does the bootblock know in what sector it is?

Post by anton »

You'll need to read the first sector of the HDD : that is where the partition table is. It contains the beg sector , cylinder, head of all 4 partitions(a HDD may have at most 4 partitions). Look it(partition table) up in some reference to find out more detail.

If you know on what partition you will be installing the os, you can hard code it. If you whant your os to determine what partition it was loaded from, you will need to have signature for your os.
Anton.
Basant

RE:how does the bootblock know in what sector it is?

Post by Basant »

well...anton thanks a lot... but its still unclear.... ok... i know its on the 2nd partition...now i understand that by first sector you mean the mbr...but i dont understand how it tells me something bout the partition number...
well ...it would be much easier if you told me the code ...n terms of the interrupt and the regieter values....
thanks anyways...youve been really helpfull...
anton

RE:how does the bootblock know in what sector it is?

Post by anton »

typedef struct {
unsigned char boot_indicator;
unsigned char beg_boot_head;
unsigned char beg_boot_sector_cylinder;//2 high bits of cylinder #
unsigned char beg_boot_cylinder;//lower bits
unsigned char sys_indicator;
unsigned char end_boot_head;
unsigned char end_boot_sector_cylinder;
unsigned char end_boot_cylinder;
unsigned long sectors_preceding_partition;
unsigned long sectors_in_partition;
}Partition;//should be size 16

Now let's suppose that mbr points to the data in mbr.
unsigned char *mbr;

Partition *second = (Partiton *)(0x1CE+mbr);//Partition table starts at 0x1be in 16 byte inc.

Now you can retrive the beg head,sector and cylinder:
unsigned char beg_head = second->beg_boot_head;
unsigned char beg_sector = 0x3f & second->beg_boot_sector_cylinder;
unsigned int    beg_cylinder =  (0xC & second->beg_boot_sector_cylinder)+second->beg_boot_cylinder;

anton
LightCone

RE:how does the bootblock know in what sector it is?

Post by LightCone »

Hello, Mr. anton.

When I read these articles, I had had the question whether there are
more simple or direct methods to determine the number of currently booted
sector(CHS) without a hard coding of sector number into the IPL of the OS nor
seeking the entries in the partition table for the signature of the OS.

For example, at the time of jumping to the IPL of the OS,
CPU DL register contains the drive number of DISK BIOS(int 13h).
So, the IPL of the OS can determine the drive number where itself is, without
hard coding of the drive number.

By the way, Japanese personal computer PC-98x1 series of NEC corporation,
CPU si register contains the offset address of the entry within the partition
table of hard disk. So that, you can determine the sector number(CHS) of
itself without hard coding of the sector number(CHS).

(PC-98x1 seriers have original architecture without compatibility of
the architecutre of IBM PC/AT or PS/2.)
Basant

RE:how does the bootblock know in what sector it is?

Post by Basant »

thanks anton...youve been of great help... im trying to work on this....ill definitely inform you the moment some results show up
Post Reply