C++ OS?

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
ltos

C++ OS?

Post by ltos »

What support stubs, etc... would I have to write to write an OS kernel in C++?  Also, what C++ features should I turn off while compiling?
bregmasoft

RE:C++ OS?

Post by bregmasoft »

Really, there isn't much.  If you're using GCC, you just need the following.

(1) Basic C runtime library with malloc/realloc/free.  I use the newlib library that I can build with the rest if te GCC toolchain, which mean I only have to supply an sbrk() function underneath malloc et al.

(2) Basic C++ runtime startup:  this requires a prologue and epilogue written in assembler.  One assembler file, 3 lines.  The rest is linker script magic.

(3) Interrupt trampoline stubs, one per interrupt/trap.  You need this for a C-based kernel, too.  One assembler file, about 20 lines.

(4) Boot code -- if you're using a multiboot-compliant bootloader all you need to do is set up the stack, push some args, and call out into C++.  One assembler file, three lines.

That's it.  The rest is all C++, including virtual functions, RTTI, exceptions, dynamic allocation, STL, templates.

I don't turn off any C++ features while compiling, since I use them all.  It just works.
Post Reply