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.
C++ kernel
Re:C++ kernel
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.
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
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
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
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 ...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:C++ kernel
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).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.
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.
Very strange behaviour ... did you reproduced the bug with some other code using the same compiler or with same code on some other compiler.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.
Re:C++ kernel
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
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. :'(
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
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.
link with that lib and implement all functions needed by it.
Second, Singletons are much cleaner then global vars.
Re:C++ kernel
TC++ with a specail self-written start-module works ok. Except the vararg-functions like cprintf, sprintf, usw...