Page 1 of 1

Bootloader 0x7C00

Posted: Sun Sep 11, 2011 6:38 pm
by skandalOS
Hello,

I've got a specific question about bootloader which I couldn't answer after googling or reading some
papers.

I know that it is a convention that the bootloader has to be loaded starting by adress 0x7C00 (31744), but
why exactly at this adress?

On Real mode: Registers operates with 16 bits, which may contain maximum 0xFFFF.
0xFFFF - 0x7C00 = 1 Kb, which leads me thinking that a bootloader can maximum have 1kb memory.
But, as well as i know that bootloader must have 512 byte. So, why this remainded 512 byte block(1kb - 512 byte) ?

So. why actually 0x7C00 ? convention ? but why?

thnx before

Re: Bootloader 0x7C00

Posted: Sun Sep 11, 2011 6:50 pm
by gerryg400
0xFFFF - 0x7C00
equals 0x83FF

Re: Bootloader 0x7C00

Posted: Sun Sep 11, 2011 7:03 pm
by skandalOS
ohh sorry, it was a mistake of me, because I assumed that 2^16 is 32768 instead of 65536.

But can I anybody give an answer why 0x7C00? and what is before (0-7bff)?

thanx

Re: Bootloader 0x7C00

Posted: Sun Sep 11, 2011 8:16 pm
by GReaper
skandalOS wrote:But can I anybody give an answer why 0x7C00? and what is before (0-7bff)?
You said convertion, I'd say tradition. Besides, below this address there is the possibility you'll run onto system reserved memory like memory-mapped hardware, important system data structures etc.

Re: Bootloader 0x7C00

Posted: Mon Sep 12, 2011 1:27 am
by mark3094
skandalOS wrote:what is before (0-7bff)?
Have a look at the large table o this page (about 1/3 of the way down):
http://www.brokenthorn.com/Resources/OSDev7.html

skandalOS wrote:why 0x7C00?
Because it has to be somewhere... :D

Re: Bootloader 0x7C00

Posted: Mon Sep 12, 2011 2:32 am
by Solar
skandalOS wrote:0xFFFF - 0x7C00 = 1 Kb, which leads me thinking that a bootloader can maximum have 1kb memory.
A bootloader has to fit into the MBR, and thus may be no larger than 446 bytes.

Re: Bootloader 0x7C00

Posted: Mon Sep 12, 2011 8:39 am
by Chandra
mark3094 wrote:
skandalOS wrote:why 0x7C00?
Because it has to be somewhere... :D
=D>
skandalOS wrote:But, as well as i know that bootloader must have 512 byte.
Actually it can be of size 512 bytes(fd,hd,sd) or 2048 bytes(cd).

Re: Bootloader 0x7C00

Posted: Mon Sep 12, 2011 8:47 am
by turdus
It cames from the IBM PC design, originally it was (in the XT era):
0-400h IVT
400h-500h BIOS area
500h-600h BIOS BASIC area
600h-7C00h boot loader memory (stack)
7C00h-7E00h place where the MBR code loaded (8000h-2 sector)
7E00h-8000h place where the VBR code loaded (8000h-1 sector)
8000h - first OS usable memory

As it turned out it was a bad design, MSDOS used 7C00h for VBR code as well, relocating the MBR to 600h. Using the same address gives the ability to chainload different loaders regardless of their type (MBR or VBR), so 7E00h left out pretty soon, 7C00h remains as a tradition (and it was impossible to change BIOS ROM in machines already shipped).

Re: Bootloader 0x7C00

Posted: Mon Sep 12, 2011 10:59 pm
by CelestialMechanic
This is my guess as to why the address 0x7C00 was chosen for loading the boot sector. Please note that I have never worked for IBM or Microsoft, this is just my inference from the state of the art at that time (1981).

The IBM PC was originally sold in configurations with 16, 64 and (I think) 32 kilobytes of RAM. (Yes! Kilobytes!) The original IBM PC came with BASIC on ROM, just like many of the home computers of that time, so the 16K configuration was just fine for a little BASIC, and maybe loading and saving short files from a cassette tape recorder. (Remember casette tapes? Our younger readers may want to ask their parents what saving and loading to cassette tape was like.)

32K seemed to be the logical minimum for loading an operating system from a floppy disk drive, so the load address for that boot sector was placed just before 0x8000 as a least common denominator location. (The original version of PC-DOS 1.0 used about 9K, if memory serves.)

A popular format for floppy disks of that time was called IBM Format 34, which allowed for sector sizes of 128, 256, 512, or 1024 bytes. Loading the sector at 0x8000 - 1024 = 0x7C00 (sorry for the mixed bases) meant that a boot sector of any size could be used no matter what sector size finally won out. Of course requiring the signature at 0x1FE tended to rule out the smaller sizes, and would have created a difficulty (though not insurmountable) for 1024 byte sectors.

Remember, this is an educated guess. It is only an educated guess. And now back to regular programming ...