Page 1 of 1
C++ kernel
Posted: Thu Jul 18, 2002 9:43 am
by crazybuddha
Although this forum is typically about boot loaders, I thought I'd ask if anyone has ventured into writing their kernel in C++ (not C)??
I can get plenty of nay-saying (practical or otherwise) at alt.os.development. I'm wondering about actual coding attempts.
Re:C++ kernel
Posted: Thu Jul 18, 2002 9:57 am
by The_Legend
I tried it.
There are two problems, the second may be a bug.
The first problem is that the compiler needs some built-in functions for some c++-features, more than the C-ones like _ftol, this will be a real problem when you use RTTI and Exceptions.
There are two solutions: Either reprogram those functions (hard work), or, for example, gcc has a library containing those functions, but this library requires other functions, which are of course easier to write, but still not really easy.
I had a problem with global vars. I had two instances created as global vars:
PhysRAM prRAM;
GDT gdtGDT;
and only the constructor of prRAM was called for some reason.
Solution: Is this a compiler bug which is removed in a newer version?
A cleaner solution would be to use singletons.
Re:C++ kernel
Posted: Thu Jul 18, 2002 10:06 am
by crazybuddha
Legend-
Did you abandon it in favor of C??
For anyone interested in OS in C++, here is a friendly tour through a version of NachOS:
http://www-ali.cs.umass.edu/salsa/topics.html
Re:C++ kernel
Posted: Fri Jul 19, 2002 1:25 am
by The_Legend
No, I just stopped my OS until I could fix that, as C++ would be more natural for an OS then C is. I'll try again soon ...
Re:C++ kernel
Posted: Fri Jul 19, 2002 3:08 am
by Pype.Clicker
The_Legend wrote:
I tried it.
There are two solutions: Either reprogram those functions (hard work), or, for example, gcc has a library containing those functions, but this library requires other functions, which are of course easier to write, but still not really easy.
The first approach (reprogramming the exceptions or RTTI runtime) is not feasible, as their behaviour and interface may change from compiler to compiler (unlike say, malloc and main API which are the same for every C compiler).
as i show it
here, even the same compiler (gcc) changed the way processing exceptions from one version to another
Thus you can either disable them (-fno-exception ...) or link your kernel statically to libgcc++.a so that you have the runtime support you need. Once this is done, you still need to reimplement what the runtime requires like malloc, etc.
I had a problem with global vars. I had two instances created as global vars:
PhysRAM prRAM;
GDT gdtGDT;
and only the constructor of prRAM was called for some reason.
Very strange behaviour ... did you reproduced the bug with some other code using the same compiler or with same code on some other compiler.
Re:C++ kernel
Posted: Fri Jul 19, 2002 9:37 am
by The_Legend
I wanted to try gcc 3.03, but when I compiled with this compiler, it suddenly wanted another function, for which I couldn't guess the use of it. Just like what you have explained.
Re:C++ kernel
Posted: Fri Jul 19, 2002 12:34 pm
by anubis
Hi
I almost thought to write an OS kernel in c++ for my term project that could boot independently from a bootloader
.
Is there any way around to avoid the problems for writing a kernel in c++. ???
If that is the case i will have to write code in c that emulates c++ object oriented approach . Thats a big project in itself.
:'(
Re:C++ kernel
Posted: Sun Jul 21, 2002 1:29 pm
by The_Legend
First, just like Pype.Clicker said, either disable special features of C++ like RTTI and Exceptions, leaving virtual functions, operator overloading etc. in it (I hope ...) or
link with that lib and implement all functions needed by it.
Second, Singletons are much cleaner then global vars.
Re:C++ kernel
Posted: Sun Aug 18, 2002 1:26 pm
by FSQUID
TC++ with a specail self-written start-module works ok. Except the vararg-functions like cprintf, sprintf, usw...