Page 1 of 1

boot loader whit gcc?

Posted: Sat Feb 11, 2012 9:08 pm
by GABOSNAKE
Hi everyone, I am new in this forum, and i have a question:
I want to write a boot loader, for testing propose, only for display text whit the bios interrupt 0x10, but i don't get it whit GAS&LD, there is a way to do that?
It's posible to compile 16-bit real mode code whit GAS&LD?, i found the .code16 directive, but doesn't work, there is options for ld?...
I am new to os-programming...
Thanks.
Saludos.

Re: boot loader whit gcc?

Posted: Sat Feb 11, 2012 9:46 pm
by bubach
You're better off forgetting about realmode, or you'll not learn anything interesting. Do programming under FreeDOS & OpenWatcom C compiler as MZ executables if you want BIOS interrupts, you could even load the program with Alex bootprog if you really want it bootable.

For 32-bit OS-dev in GCC you should take a look at the wiki on how to set up a cross-compiler and read some tutorials on basic kernels and the screen. But remember, real men use assembly. :wink:
Haha, even if that's not for you I recommend playing around with bootsectors and second stage loaders a bit before committing to GRUB or anything else, you'll learn valuable stuff.

Re: boot loader whit gcc?

Posted: Sat Feb 11, 2012 9:58 pm
by Brynet-Inc
The file generated by the assembler is in whatever object format the toolchain is targeting, ELF, PE.. etc.

You can convert it to a headerless binary with objcopy, or alternatively you'll want to use a linker script with ld.

Re: boot loader whit gcc?

Posted: Sat Feb 11, 2012 10:16 pm
by GABOSNAKE
bubach wrote:You're better off forgetting about realmode, or you'll not learn anything interesting. Do programming under FreeDOS & OpenWatcom C compiler as MZ executables if you want BIOS interrupts, you could even load the program with Alex bootprog if you really want it bootable.

For 32-bit OS-dev in GCC you should take a look at the wiki on how to set up a cross-compiler and read some tutorials on basic kernels and the screen. But remember, real men use assembly. :wink:
Haha, even if that's not for you I recommend playing around with bootsectors and second stage loaders a bit before committing to GRUB or anything else, you'll learn valuable stuff.
Oh, great info!... reading.... thanks
Brynet-Inc wrote:The file generated by the assembler is in whatever object format the toolchain is targeting, ELF, PE.. etc.

You can convert it to a headerless binary with objcopy, or alternatively you'll want to use a linker script with ld.
I will try whit [objdump -O binary...], thanks....

Re: Boot loader with gcc?

Posted: Sat Feb 11, 2012 11:15 pm
by shikhin
Hi,
GABOSNAKE wrote:I will try whit [objdump -O binary...], thanks....
You seem to misspell it everywhere. It's with, and not whit.

Regards,
Shikhin

Re: Boot loader with gcc?

Posted: Sun Feb 12, 2012 1:46 pm
by GABOSNAKE
Shikhin wrote:Hi,
GABOSNAKE wrote:I will try whit [objdump -O binary...], thanks....
You seem to misspell it everywhere. It's with, and not whit.

Regards,
Shikhin
thank's for the advice :lol:

And... I found the way to assembly the bootloader using as&ld
We need to add at top of the source

Code: Select all

.code16 
Next, using ld:

Code: Select all

ld -Ttext 0x7c00 --oformat binary -o $@ $<
With -Ttext we tell to the linker the start address of the text segment, the boot sector is loaded at 0x7c00

At this point we have a flat binary, so the next part is format the bootloader:
512 bytes & and at offset 0x1FE the word 0xAA55
And it work's...