Kernel in C++

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
DR

Kernel in C++

Post by DR »

Hello again, I've been away for quite a while (4 months or so) due to college exams, vacation, and stuff. I just had my bootsectors done and now I was thinking about starting a kernel in C++. Can anyone advise me on where to start? There's so much to be done :(
mikeleany

RE:Kernel in C++

Post by mikeleany »

Memory management. And what's that frowny face for? That should be a smiley. You're making an OS afterall!
DR

RE:Kernel in C++

Post by DR »

lol I guess I tend to lose heart when I complete something and see what's left to do :)

Any hints and tricks to do memory management in C++? Please go nuts because I'm quite an OOP freak :)
Legend

RE:Kernel in C++

Post by Legend »

Okay, first thing to keep in mind, is that you can't use new and delete right of the start - you go to implemnt that yourself, like rtti and exceptions, but I guess disabling those features is not as much a problem like not using new and delete would be.

So you need some memory managment first. (Perhaps with paging, perhaps at first not ...) You should write malloc first. (At least in msvc++, new is a call to a malloc function and then it calls the class constructor)

Oh, and freestanding vars (like globals or static ones) need special treatement, too!
DR

RE:Kernel in C++

Post by DR »

Alright, I just implemented some code so I can use freestanding vars in my kernel. So far, so good, but now I have problem: I want to use the new and delete operators but I don't have a clue how to start with that (anyone knows of a good tutor about implementing those?).

I could also use some good info on paging and implementing GDT/IDT in C++.

I got it to print my name, but I'm still not satisfied ;)
Adek336

RE:Kernel in C++

Post by Adek336 »

If you try to use new/delete when you do not declare them, you get a link error 'bout unresolved symbols... so: you have to declare like any other function.

void *operator new(uint32 size)
{
   return kmalloc(size);
}

Declare simillar funcs for new[], delete and delete[]. Creating a simple kmalloc without the ability of freeing, should be useful enough, and simple enough.
DR

RE:Kernel in C++

Post by DR »

Dargh... I still don't get it...

What I know is:

* I should implement global new, new[], delete and delete[] operators.
* I should write a function or class (preferably, for I'm using C++) that keeps track of what memory is used and what not, and provide a function that returns the address of a free piece, and one that marks a given piece as free.

Thanks for the help
Post Reply