I need to build a OS, a very small and basic one, with actually least functionality, coded in C.
Probably a CUI OS which does some memory management and has at least a text editor and a calculator, its just going to be a experimentation about how to make a code that has full and direct control over your hardware.
Still I’ll be requiring an interface, that will need input/output functions like printf(&args), scanf(&args). Now my basic question is should I use existing headers or go for coding actually from scratch, and why so ?
I’d be more than very thankful to you guys for and help.
First, you can’t link against anything from
libc… you’re going to have to code everything from scratch.Now having worked on a micro-kernel myself, I would not use the actual
stdioheaders that come withlibcsince they are going to be cluttered with a lot of extra information that will be either irrelevant for your OS, or will create compiler errors due to missing definitions, etc. What I would do though is keep the function signatures for these standard functions the same … so in the end you would have a file calledstdio.hfor your OS, but it would be a very stripped down header file with the basic minimum requirements for your needs, and only having the standard I/O functions you need, with the correct standard signatures.Keep in mind on the back-end, i.e., in your
stdio.cfile, you’re going to have to point these functions to a custom console-driver or some other type of character drive for your display. Either that, or you could just use them as wrappers for some other kernel-level display printing routine. You are also going to want to make sure that even though you may use a#include <stdio.h>directive in your other OS code modules to access these printing functions, you do not link againstlibc. This can be done usinggcc -ffreestanding.