views:

3461

answers:

15

What kind of C++(Restate to programming) would I have to learn to make my own OS kernel? (I know I would also have to learn assembly.) EDIT*Like interrupts , keyboard driver, getting input.*

Ok everyone I made a really * 3 basic OS and would like to share it.

Here you go. http://bcsy.hostzi.com/BytOS.zip

Compile on linux

A: 

All. This is not a trivial task, you need to learn most facets of the language, I would recommend looking up kernel programming. From the looks of it I would look up logical theories and paradigms for programming languages before embedding yourself in syntax. There are hardware layers and just so so much you will need to learn well more so than from an answer you are going to get on this site or by doing a google search.

Good Luck!

Quintin Robinson
+4  A: 

Given your choices today there's absolutely no reason to "make" an OS. Learn a language really well and get really comfortable with Windows or a variation of Linux. C or C++ is great to learn.

Edit for clarification - my point is that it's both unrealistic and borderline insanity to attempt to learn a language for the first time by making an Operating System. At minimum a really good background in C is a requirement, otherwise start making applications and leverage the power of existing OS's before attempting to roll your own.

routeNpingme
I can't agree with that, I have written a small OS and it's a fantastic way to learn about things like filesystems, concurrency, synchronization primitives, thread scheduling, I/O and interrupts, etc. etc. etc.
David Zaslavsky
@David I agree, but I bet you had to learn a language really well before you tackled that. It's insane to try and learn a language by writing your own OS.
routeNpingme
Sure, I had a decent knowledge of C (and slight of assembly) going in, but that doesn't mean there's no reason to program an operating system.
David Zaslavsky
Added above clarification to answer in an attempt to not get voted off the island :)
routeNpingme
any project can help you [learn], write an OS, windows apps, anything as long as its something that interests you.
Ric Tokyo
I'm not agreeing with your perspective, however it is a valid perspective and was voted a little harsh. I think the OP did not explain the question very well.
Tim Post
+4  A: 

There's only one kind, that should help narrow it down. Start by studying the CPU architecture manuals, Intel's are available for free. Getting documentation for the BIOS is going to be the hard part.

Hans Passant
There's only one kind - thank you! I was thinking the same thing!
NTDLS
A: 

I would not recommend using C++ when making a monolithic kernel, period. However, if you are contemplating a microkernel design, you could write the servers (networking, console, fs, vfs, etc) in C++, while keeping the kernel itself tight with C / inline asm.

Then again, if your just going for x86, it doesn't matter as much.

What are the design goals of your OS?

Tim Post
+6  A: 

I have a friend who wrote an OS kernel in C++:

http://sourceforge.net/projects/ekp/

So it is definitely possible. (Some of the comments above say it is impossible. Wrong.)

You may even want to steal his bootstrapping and build code, so that you can just dive right in and start implementing the "fun stuff".

jrockway
+4  A: 
Ric Tokyo
+6  A: 

Lots of resources in the following similar questions, including C++ OS information:

http://stackoverflow.com/questions/43180/how-to-get-started-in-operating-system-development

http://stackoverflow.com/questions/130065/os-development

Adam Davis
+2  A: 

I would recommend straight C for Kernel development. With OS development you really want to know what is happening 'under the covers.' I feel C++ hides too much for low-level development.

Good resources:

Paul Vincent Craven
A: 

Check out the linux kernel mailing list FAQ for common questions (that would apply to any kernel development), and don't get discouraged by this point.

tmatth
+1  A: 

For a number of technical reasons, Linux is not programmed in any language besides C. For various political reasons, few other os'es are programmed C++.

If you want to learn about programming kernels, the Minix operating system/microkernel is expressly designed for learning operating system design. It's small and minimal. It is also programmed in C.

TokenMacGuy
Just out of curiosity, what are those political reasons?
Angela
Google for Linus Torvalds' C++ rant and I think you'll understand.
Kristo
linus' rant is just stupid fud :/
Johannes Schaub - litb
@litb: indeed, because of c++'s pay only for what you use. It is just as easy to develop an OS with c++ as it is in c. Except now you have the benefits of objects, virtual functions, templates and more :-P.
Evan Teran
Let's put it this way - every modern production operating system is in C, not C++. This is not accidental.
Paul Betts
@Paul: agreed, it isn't accidental, it's historical.
Evan Teran
A: 

The only OS of any significant size I know of that's been programmed in C++ down to "bare metal" is the AS/400 operating system OS/400 (after v3r6).

There's nothing much that prevents you from doing any OS in C++ -- especially when you recall that vanilla C is "almost" valid C++ anyway. What becomes interesting is doing new/delete at the lowest levels, because you need to guarantee no leaks and such. This leads to a need to re-implement the new functions.

I helped do v3r6, but it's been about 13 years and I don't remember the hairy details. I'm not aware of any publications on it, but if you're really interested, try writing Marshall Cline at http://www.parashift.com.

(Augh. "delete" vice "free".)

Charlie Martin
implementing new/delete is trivial and can often be just short wrappers around malloc/free.The compile will emit the constructor/destructor code for you.I have a c++ OS of my own, the only real hard part is if you want exceptions/rtti.If you can do without those, not much work to get up and running.
Evan Teran
I guess, another thing worth noting is global contructors/destructors, since these need to be called before "main", but once again, it's a 5 line function to handle that, nothing epic.
Evan Teran
Evan, actually implementing new/delete for the low-level "bare metal" classes is *not* trivial; this goes doubly for classes that need to, say, map to specific physical addresses.
Charlie Martin
Consider, for example, where your malloc would come from.
Charlie Martin
Yes, You have to implement malloc/free. But that's the case for a C kernel too, so that's a wash. Implementing new/delete *is* definitely trivial (i can say so from experience). See http://wiki.osdev.org/C_PlusPlus#new_and_delete. All one liners that work perfect.
Evan Teran
As for "classes that need to, say, map to specific physical addresses". Placement new (which is even simpler) works just fine. There is no case where new/delete is more complicated than the malloc you'd have to implement either way.
Evan Teran
now you're quibbling. Yes, placement new is the answer. All I said was "it becoming interesting." Again, if you have malloc/free, new/delete is relatively easy -- but doing a good job with malloc/free, at bare metal, with memory management, isn't.
Charlie Martin
Not trying to quibble. My point is that the discussion was about possible disadvantages of c++ over c for kernel dev. Since malloc/free is something you have to do in *both* you can't count it against c++, so that issue is moot. There is nothing *more* complicated about new/delete over malloc/free.
Evan Teran
+1  A: 

I suggest taking a look at nachos (Not Another Completely Heuristic Operating System). It's the teaching OS we used for my operating systems course in college.

Kristo
+5  A: 

I recommend you look at the OSDev wiki. It is a fantastic source of information regarding programming an OS in many languages, including c++.

Specifically, see this section which tells you just about everything necessary to get going with a c++ kernel using gcc.

Finally, check out the OSDev forums, there are lots of users there ranging from newbies to highly experienced. They are usually more than happy to help people (so long as they show they tried before asking :-P)

Evan Teran
+1 for mentioning OSDev.
Jon Purdy
+1  A: 

Newos is a good C++ kernel. So are eCos, and L4. Newos is a microkernel by a former BeOS developer. L4 is also a microkernel, famous for its incredibly fast message passing. And eCos is a monolithic kernel.

Max Lybbert