Developing an OS with 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
hg02
Posts: 1
Joined: Tue Feb 25, 2025 2:48 am
Libera.chat IRC: hg02

Developing an OS with C++

Post by hg02 »

Hi guys!

I have always wanted to create an OS ever since high school. The thought has come up to me again recently. I know the forum says that you should be "intimately" familiar with the language of choice and have all the prerequists listed.

I coded in C wayyy back like 8 years ago and haven't touched it for the last 6/7 years. I have never coded in C++. The reason I wanted to do this project was because I always wanted to learn more about computers. I have been coding in python and Kotlin (for job purposes) for the last 3/4 years with some MATLAB as well.

With the context out of the way I want to build my own C++ OS. Why? I don't know. I am just trying to get a feel for the magnitude of the challenge and if there are any monetary reqs (like buying any specific hardware)? I work full time and also wanted to ask with my background and time limitations, how long do experienced developers think it would take (I know a stupid question, but any reply would help).

Thank you guys!
Klakap
Member
Member
Posts: 314
Joined: Sat Mar 10, 2018 10:16 am

Re: Developing an OS with C++

Post by Klakap »

I would suggest you to choose some more specific first goal than just “knowing more”. For example “I want to write simple command line interface”. That will help you to know where are you heading to with project, and where should you start.

Also, why exactly are you interested in developing in C++ if you do not know anything about this language yet? If you already know something about C, I think it will be easier option for you to start with.
monetary reqs
This highly depends on what you want from your project. If you want to run it on real hardware, it is probably good idea to buy some old computer just for testing. But otherwise only monetary requirement is paying for electricity.
how long will it take?
It depends on what exactly do you want to achieve and how much time will you spent on it. I do not think it is possible to measure it if you never did this before. But if you take it as hobby for fun, I think you will not need to worry about time.
User avatar
iansjack
Member
Member
Posts: 4759
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Developing an OS with C++

Post by iansjack »

If you have never coded in C++ then it would be extremely ambitious to make your first project an OS. Although it has a lot of advantages it also introduces a number of new complications. If you want to learn to program in C++ then find a good book or tutorial and start with some realistically simple projects.

If you want to program an OS - C was good enough for Ritchie and Thompson, so it's probably good enough for your first attempt.

When you have completed both the above you might be at a reasonable point to try C++ (or Rust, or Ada, or ... - they're all good) when writing another OS.

Assuming that you have a computer, no monetary outlay is required for any of the above. Life is much simpler than it used to be in the "good old days".
thewrongchristian
Member
Member
Posts: 442
Joined: Tue Apr 03, 2018 2:44 am

Re: Developing an OS with C++

Post by thewrongchristian »

hg02 wrote: Tue Feb 25, 2025 2:57 am Hi guys!

I have always wanted to create an OS ever since high school. The thought has come up to me again recently. I know the forum says that you should be "intimately" familiar with the language of choice and have all the prerequists listed.

I coded in C wayyy back like 8 years ago and haven't touched it for the last 6/7 years. I have never coded in C++. The reason I wanted to do this project was because I always wanted to learn more about computers. I have been coding in python and Kotlin (for job purposes) for the last 3/4 years with some MATLAB as well.
If you're happy with the concepts of pointers, what they represent and how, then hopefully you'll be fine. Sounds trivial, but it's not unheard of for C/C++ developers to not understand what pointers actually are.
hg02 wrote: Tue Feb 25, 2025 2:57 am With the context out of the way I want to build my own C++ OS. Why? I don't know. I am just trying to get a feel for the magnitude of the challenge and if there are any monetary reqs (like buying any specific hardware)? I work full time and also wanted to ask with my background and time limitations, how long do experienced developers think it would take (I know a stupid question, but any reply would help).
As someone with a full time job and a family, I've been developing my OS since just before new year 2017, so over eight years. The time spent is often evenings, with varying intensity (I can sometimes go months with no changes), but I estimate I've done at least a man year full time equivalent work, and for that I have:

- Mutli-tasking, multiple kernel threads and single threaded user space (no facility to create multiple user threads per process, but it won't be a big deal to add it as and when I need it.)
- Single CPU only, no SMP, but written with SMP in mind.
- Demand loaded, copy on write paged memory. No virtual memory yet, I have not implemented any facility to expel in use pages except once a memory segment is unmapped (such as at process exit.)
- A simple VFS
- A simple in memory temporary filesystem
- A read-only ustar filesystem for the initial ramdisk.
- A read-only FAT filesystem driver.
- A simple PIO IDE driver
- A simple PS/2 keyboard input driver
- A basic USB stack, with UHCI host controller driver, and simple boot protocol keyboard/mouse and bulk only transport block drivers.
- A simple user space based largely on xv6 user commands and pdclib
- A simple terminal console.

Crucially missing:
- Security (everything is root all the time)
- Capable libc. My pdclib is from 2018, hasn't been updated and is severely limited compared to what is available in a more complete libc.
- Comprehensive user space - my xv6 based user space is basically test code only. I'd prefer to port something like busybox or toybox to provide basic user commands.
- Any networking.

If all you're doing is learning and playing, like I am, then go for it and learn your kernel and C++. It'll keep you engaged for years!
Post Reply