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.
Could anybody, please, give me some information related to booting a kernel from HDD? I am creating my own File System and I need to know when/how the code is read from the HDD as the bootstrap?
[BITS 16]
[ORG 0x7C00]
%DEFINE PTR
MOV AX , 0xB800
MOV ES , AX
MOV BYTE PTR [ES:0x0000] , 'X'
JMP $
TIMES 510 - ($-$$) DB 0x00
DW 0xAA55
And put it as the first sector on my HDD. I have disabled the Floppy Disk Drive on both drives and when I start the PC, BIOS doesn't transfer the control to the HDD. I really don't know what I should do next!
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
>BIOS doesn't transfer the control to the HDD.
sure?
can´t you see the black 'X' on the black scren?
better try:
MOV WORD PTR [ES:0x0000] , 'X+'
or even better:
MOV WORD PTR [ES:1600] , 'X+'
in case of scroll happens.
The BIOS is looking for a master boot record with a partition table on the first sector of the hard disk.
When the computer boots the mbr is read into memory at 7c00. Then it usually relocates itself to 600h before scanning the partition table (also included in the first sector) for a partition which has the "active" flag set. It then reads the boot sector for that partition into memory at 7c00, jumps to it, and things then proceed as for a floppy.
If there is only one partition on the hard disk its boot sector is usually the first sector on track 1. You can google for information about the mbr.
If you don't fancy writing your own master boot record you can partition the disk with something like fdisk, and then copy your partition boot sector (much, although not exactly, like a floppy boot sector) to whichever partition you want. The partition boot sector will need the pointer to the partition table passed to it in ds:si if I remember rightly.
Thank you for the explanations. For now, all I have is a flat 32MB hard disk drive that I have configured in Bochs that I have filled with zeros 0x00000000. I think I am going to have to read about MBR and partitioning. I don't like to use fdisk or anything like that I rather learn how to do the partitioning myself
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
Okay now I understand it all about the MBR and its structure. My question is: do I have to create a MBR for my File System that complies with the IBM partitioning scheme for the MBR or can I just obey the rule for the boot signature and then go with my own MBR structure?
IBM’s partitioning scheme is rather dumb because it stores both the length of the partition and the address of the last sector in the partition. I don’t think you need to do that while you have both the address of the first sector in the partition and the length of the partition. You can save those bytes for something more important I think.
I like the MBR scheme described in the Wikipedia except for the structure of the Table of primary partitions block of the MBR!
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
XCHG wrote:Okay now I understand it all about the MBR and its structure. My question is: do I have to create a MBR for my File System that complies with the IBM partitioning scheme for the MBR or can I just obey the rule for the boot signature and then go with my own MBR structure?
to make it boot, no, but to make it readable (and not corrupted by) other OSs, then you do
IBM’s partitioning scheme is rather dumb because it stores both the length of the partition and the address of the last sector in the partition. I don’t think you need to do that while you have both the address of the first sector in the partition and the length of the partition. You can save those bytes for something more important I think.
not really -- the length is for use with the LBA entry (which contains no end of partition entry) and the end of partition is for use with the CHS fields (which contain no length entry)
if you are using CHS, i would recommend setting correctly when creating, but ignoring when reading all the LBA fields (and if you are using the LBA fields, then the end-of-partition field is not useful to you at all anyway)
Thank you for your response. About CHS, I remember having a lot of trouble converting LBA to CHS especially on floppy drives which was my first experience with LBA-><-CHS conversion and I just can't understand the point in using CHS for hard drives except for compatibility issues. But maybe you are right; I am going to use IBM's MBR scheme for now and then maybe extend it into a separate driver for my own FS' MBR.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
yes, definitely do use LBA unless its an older drive which doesnt support LBA
on newer HDDs (newer means anything larger than about 2GB, and many smaller ones) the drive cannot use CHS directly and must translate it into LBA before using it anyway (so your OS uses LBA, translates it into CHS, sends it to the drive, which immediately translates it back into LBA before translating it into its own internal form of CHS)
in fact any drive over 128GB must use LBA to access it (there is no CHS48 extension -- its LBA only)
with FDD, iirc, you must use CHS, but for HDDs, LBA was an optional part of the original spec, and has been well supported by all ATA drives (iirc, it was made mandatory very early in the ATA specification) the only reason CHS exists for HDDs is that the ATA specification is designed to be seamlessly compatible with the ST509 HDD, which did not support autodetect or LBA addressing
Thank you again. Regarding the C/H/S addressing: I was able to dump the MBR of my HDD into a 512-bytes-long binary file and I wrote a program that extracted the information of each of the partitions available in the HDD.
Then I decoded the C/H/S address. What I want to know is whether or not I have to increment the Head and the Sector values that I retrieve in the 3-bytes-long field in each of the partition's descriptors. I know that the Cylinder value should not be incremented and I do know that the Head must be incremented but don't know about the sectors. I'd appreciate it if you (or anybody else) could please help me with this.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.