Page 1 of 1

Flat Binary with GCC

Posted: Sat Sep 28, 2002 8:53 am
by PlayOS
Hi,

How can I create a flat binary file out of a single C source file, that can be loaded into a certain address and jumped to?

Lets say I have this in the c source file:

void k_main()
{
char *vid = ( char * ) 0xb8000;
int i = 0;
vid = 'A';
i++;
vid = 0x07;

while ( 1 )
{
}
}

I want this to be put into a flat binary file that can be loaded at an address and jumped to, it would then print the 'A' and then hang.

I have tried many tutorials on writing a simple c kernel, but I dont like them it should be much more simple, if gcc is so complex to use I will not use it. :)

Thanks.

Re:Flat Binary with GCC

Posted: Sat Sep 28, 2002 9:45 am
by Slasher
You are going to have to use a linker script to tell gcc how to link the file. read the docs that come with gcc, it has an example simple linker script that does what you are looking for

Re:Flat Binary with GCC

Posted: Sat Sep 28, 2002 9:06 pm
by crazybuddha
ld -Ttext 0x600 -oformat binary -o kmain.bin kmain.o

where 0x600 is the absolute address where this code is going to reside. This assumes the GDT gives the base address as 0x0 and that you switch to pmode before you jump there.

There are several complications in practice, but this should get you something working.

Re:Flat Binary with GCC

Posted: Sun Sep 29, 2002 7:01 am
by Tom
Look at my FritzOS web site...it has stuff that'll help you.

You need to look at the install.sh file for how to compile it.