ASM bootloader, C kernel

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
fuzzyhair2
Posts: 2
Joined: Fri Apr 20, 2012 4:25 pm

ASM bootloader, C kernel

Post 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
User avatar
eino
Member
Member
Posts: 49
Joined: Fri Sep 16, 2011 10:00 am
Location: Finland

Re: ASM bootloader, C kernel

Post 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.
I'm Eino Tuominen from Finland, a web software dev learning low level stuff and reading / trying out kernel dev
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: ASM bootloader, C kernel

Post 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.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: ASM bootloader, C kernel

Post 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.
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: ASM bootloader, C kernel

Post 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.
fuzzyhair2
Posts: 2
Joined: Fri Apr 20, 2012 4:25 pm

Re: ASM bootloader, C kernel

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