Page 1 of 1

boot question

Posted: Wed Dec 31, 2003 12:00 am
by Rookie
hi, i'm a total noobie
so don't mind me askin
what does exactly go to the boot sector? is it just code or are there any headers or some stuff that go before code? i don't want to write the code in an assembler because i don't like any of them. i want to simply put the binary values on the floppy and try that. i mean if i need to add stuff before the code, ill have to use an assembler or c, but i don't wanna...

RE:boot question

Posted: Wed Dec 31, 2003 12:00 am
by Dangamoose
The boot sector is the first sector on a disk drive. It's 512bytes long.

It contains a program commonly known as the boot loader. A program that is written in plain binary format that loads the OS.

The idea behind the bootsector is to hold the bootloader program which loads the OS without putting restrictions on a computer while technology itself advances. I.e. the computer doesn't need to understand file formats creating restrictions in the industry.
What the bootloader does and how the OS then handles itself and the hardware once loaded by the bootloader is down to you (the developer).

The bootloader requires a special couple of bytes at the end of the 512byte program as a checksum for the motherboard (although some motherboards don't require them, they'll boot whatever is in the first sector anyway) and the program must be written in plain binary (no fileformat) and written to cater for real mode.

Because it has to be written for real mode, you can't use C or C++, they are protected mode programming languages. You can only use assembly to write the program.

If you don't like assembly, like you said, then you could cheat, like i did, and use a pre-made bootloader that uses a standard known as multiboot such as Grub. This bootloader will load your OS in a protected mode environment and allows you to write C/C++ or whatever language you might want to use. Sort of like skipping the part of messing around with real mode, you know longer need to specially cater for it on booting.

Dangamoose.

RE:boot question

Posted: Wed Dec 31, 2003 12:00 am
by carbonBased
>>>>>>
The bootloader requires a special couple of bytes at the end of the 512byte program as a checksum for the motherboard (although some motherboards don't require them, they'll boot whatever is in the first sector anyway) and the program must be written in plain binary (no fileformat) and written to cater for real mode.
<<<<<<

That signature being 0xAA55, btw... and at an offset of 510, of course.

>>>>>>
Because it has to be written for real mode, you can't use C or C++, they are protected mode programming languages. You can only use assembly to write the program.
<<<<<<

This blatantly IS NOT true.  Both C and C++ are portable languages that, quite frankly, don't care at all what mode the processor is in.  Besides, they were developed on non-intel unix systems (aka, systems that don't even have the distinction of these kludged up modes... (general sweeping statement that probably has exceptions))

You don't _have_ to use assembly language, no... there are some low level languages that will work (although very few).  Depending on what you want to do, it is conceivable (although certainly not wise or recommended) that a boot sector can be made in C... but you'd want to use inline assembly to read from the disk, no doubt).

Honestly, you'd be hard pressed to find a language better then assembly to write a boot sector in.

Cheers,
Jeff

RE:boot question

Posted: Sat Jan 03, 2004 12:00 am
by rexlunae
"i don't want to write the code in an assembler because i don't like any of them. i want to simply put the binary values on the floppy and try that. i mean if i need to add stuff before the code, ill have to use an assembler or c, but i don't wanna..."

If I understand what you are saying, you want to write the boot code in machine code directly.  I would highly recommend that you consider using as assembler, such as nasm or gas.  If you have a problem with assembly, you will not find machine code any more agreeable (in fact, even if you love assembly you will not find it any more agreeable).