Page 1 of 1
writing your own stdio.h sort of file?
Posted: Thu Aug 08, 2013 4:30 am
by MatthijsProgrammer
Hello everybody,
I am Matthijs, I'm 14 years old and I live in Holland.
Right now I'm busy programming my own hobby operating system.
I have made a basic bootloader and kernel (Printing onscreen, GDT, IDT, ISRs, IRQs, System clock, Keyboard and mouse support).
I was wondering if there's any possibility to write your own stdio.h sort of file?
Greetings,
Matthijs
Re: writing your own stdio.h sort of file?
Posted: Thu Aug 08, 2013 4:57 am
by Combuster
Certainly.
If you want to have a C library for your OS, you will need one anyway. You can use an existing one like PDClib or newlib's, but you can also write your own - the existing ones aren't created by magic either.
Writing the .h file isn't much of an intelligent job either. You will need to get a copy of the C standard, which typically lists exactly what the definitions and types should be like (or in cases where you have freedom, what effect they should have) so you'd end up copying significant bits of the standard itself. Writing the implementations however is a much bigger challenge, and the reason why people use existing code to get past the hassle.
Re: writing your own stdio.h sort of file?
Posted: Thu Aug 08, 2013 6:08 am
by sortie
Yes, it's perfectly possible to write your C standard library - I did exactly that for my OS. Writing the header itself is relatively simple, you just look up the applicable standard (C or POSIX or such) and write it. It's slightly more tricky to implement the standard functions in the header (fputc, printf, ...) though. I have written an (unfinished) article on the matter, but it is meant as a follow up to the OS-specific toolchain article:
http://wiki.osdev.org/Creating_a_C_Library
It's a lot of work creating your own C library. If you are willing to do it, I recommend making your kernel support program loading and system calls. Then you should set up a
OS_Specific_Toolchain (note that I am currently rewriting that article!) and begin construction of your own libc. I am currently documenting this process, stay tuned.