Flat Binary with GCC

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.
Post Reply
PlayOS

Flat Binary with GCC

Post 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.
Slasher

Re:Flat Binary with GCC

Post 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
crazybuddha

Re:Flat Binary with GCC

Post 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.
Tom

Re:Flat Binary with GCC

Post 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.
Post Reply