Page 1 of 1

ASM bootloader, C kernel

Posted: Tue Sep 25, 2012 5:44 pm
by fuzzyhair2
I'm trying to keep it simple here. So I'm making an OS on a FAT12 formatted floppy (antique, I know). I have written a bootloader that can load a single flat binary file into RAM and jump to it.

Here's the question: How could I compile a C program to be in a flat binary format? Also, how would I get many of the functions to work, such as printf, etc.

Thanks,
fuzzyhair2

Re: ASM bootloader, C kernel

Posted: Tue Sep 25, 2012 11:53 pm
by eino
There you go. Read the links on the top first http://wiki.osdev.org/Bare_Bones

I assume you are still in real addressing mode? http://wiki.osdev.org/Babystep2

I realize this is not a direct answer but it's not intented as one.

Re: ASM bootloader, C kernel

Posted: Wed Sep 26, 2012 1:46 am
by Antti
There are many things that must be taken into account. Do you switch to 32-bit protected mode? It is harder to find a C compiler that can compile 16-bit code. Do you use gcc?

Study linker scripts so you can output flat binary files. You have to realize that basically all the "C functions" available are the ones you have written by yourself. Basically it is like writing assembly.

Of course you can port some C library to your OS but that is an advanced topic and it is not what you want now.

Re: ASM bootloader, C kernel

Posted: Mon Oct 01, 2012 3:55 pm
by Casm
"Also, how would I get many of the functions to work, such as printf, etc."

A lot of C functions, including the ones which send output to the screen, rely upon operating system calls. Since the thing you are writing is an operating system, you can't use them until you have implemented the relevant functionality in your operating system, and then written the beginnings of a C library.

Re: ASM bootloader, C kernel

Posted: Mon Oct 01, 2012 9:59 pm
by linguofreak
fuzzyhair2 wrote: Also, how would I get many of the functions to work, such as printf, etc.
As others have said: write them yourself. It's the entire point of writing an OS.

Re: ASM bootloader, C kernel

Posted: Wed Oct 03, 2012 6:36 pm
by fuzzyhair2
Thanks for the help guys, really appreciate it! =D>

I realized that my problem was that I didn't read Bare Bones carefully enough. I guess I learned my lesson...read carefully. Anyway, it worked flawlessly and I will continue to learn more!

:)

Thanks,
fuzzyhair2