Is it possible to write an OS completely 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
User avatar
djnorthyy
Member
Member
Posts: 49
Joined: Mon Apr 09, 2007 10:50 am
Location: UK, Hants
Contact:

Is it possible to write an OS completely in C++???

Post by djnorthyy »

Hi,

I am a complete beginner to OS development, and I am an intermediate developer in C++ and I don't know ASM.

So I was wondering if I could make an OS in C++. I am a complete begginer so any help on OS Design or programming would help!!!

Many Thanks!
Harry.
Reflect Desktop Operating System - ' You only remember the name of the OS when it crashes '
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Re: Is it possible to write an OS completely in C++???

Post by mystran »

djnorthyy wrote:Hi,

I am a complete beginner to OS development, and I am an intermediate developer in C++ and I don't know ASM.

So I was wondering if I could make an OS in C++. I am a complete begginer so any help on OS Design or programming would help!!!
Yes you can make an OS in C++, but you will need a small amout of assembler (about the same as for a C kernel). For an idea of how much assembler you need, my kernel has long gone past the point where I need to use assembler (all the necessary assembler is more or less there) and currently I've got:

- about 7000 lines of C-code, headers and comments included
- about 500-600 lines of assembler, comments and inline-asm included

Well over half of the quoted amount of assembler is comments, so the real amount is probably somewhere around 200 instructions. Most of this is very simple stuff, like PUSH/POP/ADD/MOV and such.

To me that basicly indicates that you'll need to understand the processor well enough to write assembler, but you don't really need to know assembler as such, since the amount is small enough that you can lookup almost every instruction from the manuals separately. :)

---

As for advice, before anybody comes in an suggest you start writing a bootsector, I use my opportunity to say DO NOT. Instead, get yourself GRUB, read the multiboot specification, look at the example "Hello,World!" kernel included, and try to get it boot.

After that, write some basic console output routine. It mainly needs to dump stuff to screen, and scroll when it hits the bottom of the screen. Our Wiki should have info about how textmode screen works on PC. If you feel like it, write a printf as well (makes it easier to provide good diagnostics) or C++ style, if your console is a class, make it accept strings and numbers with overloaded operator<<. Which ever you prefer.

Once that works, you need interrupts/exceptions. When those work, you might want to start wondering about paging. Once that works as well, and you've written a malloc/free (or new/delete for C++ style), it's probably good idea to make a scheduler, so you can have multiple threads. I'd also add semaphores and timers at this point.

Once those are done, you can start worrying about userspace programs, or device drivers, or filesystems, or whatever you feel like is the most important thing.
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
User avatar
djnorthyy
Member
Member
Posts: 49
Joined: Mon Apr 09, 2007 10:50 am
Location: UK, Hants
Contact:

Thanks.

Post by djnorthyy »

:D Thanks for that!
:D
Cheers,
Harry.
Reflect Desktop Operating System - ' You only remember the name of the OS when it crashes '
Andrew275
Member
Member
Posts: 30
Joined: Tue Feb 27, 2007 2:29 pm
Contact:

Post by Andrew275 »

I agree with what mystran said. You'll also more than likely want to disable a couple of C++ features, like RTTI and exceptions. I use C++ almost exclusively in my kernel, with a bit of asm, and one plain C file.
My operating system: Desktop OS
Content management system/forum: Deluxe Portal
Post Reply