Page 1 of 1

C++ OS?

Posted: Tue Apr 20, 2004 11:00 pm
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?

RE:C++ OS?

Posted: Thu Apr 29, 2004 11:00 pm
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.