r/osdev • u/[deleted] • May 16 '23
how to start making a kernel in c++
hello i want to dive in os developement by creating a kernel first i know c++ maybe c because they are a bit similare but c++ better i just want resources or tutorials please
4
u/not_a_novel_account May 17 '23
Freestanding C++ has a far smaller subset of the STL than what you are used to.
The stuff you "love" about C++ and that make modern C++ worth using are far fewer and less applicable in a freestanding environment. There are proposals, notably P2268, trying to alleviate some of this but stuff like std::vector or anything that does memory allocation will never be available in an OS dev environment.
That means to make C++ very useful you would need to re-implement a lot of the stuff you would normally want from the stdlib. That's a lot of start-up work.
Not that C++ is entirely irrelevant, but often it's easier to start with C until you understand the shape of the problem you're trying to solve and then maybe transition that code to C++ once you know what needs to happen and now you're making the "clean" implementation.
2
1
u/Ok_Firefighter4117 May 19 '23
I agree that you should start with C to get a grasp of the system and parts you will need to implement. But in C you would need to implement the most things you would also need to implement in C++. While in C you would miss the little nice things C++ has to offer. Think about namespaces, classes templates. While you need to implement the data structures i don't see a big difference between C and C++ on that part.
12
u/kodirovsshik May 16 '23
Check out wiki.osdev.org, it's got a ton of material about x86 os development and low level programming in general (including tutorials)
1
May 17 '23
thanks all i found a you tube tutorial but first i will learn basics of assembly and learn more about c and c++ then i will start my journey
2
1
u/kodirovsshik May 21 '23
Generally, you would probably want to first get a lot of experience dealing with C and assembly and a solid CS background before trying to write an OS
2
u/northrupthebandgeek May 17 '23
If you're looking for examples on how things might be done in C++, Haiku's kernel is probably the best-known reference.
3
1
u/mpetch May 17 '23
There is a fellow who did a Write Your Own Operating System video tutorial that uses C++ (G++). You can find it here: https://www.youtube.com/playlist?list=PLHh55M_Kq4OApWScZyPl5HhgsTJS9MZ6M
1
u/Vivid-Intention158 May 20 '23
What's your experience? Do you know OS theory? If it's none, I'd recommend complete the labs for xv6 and read Operating Systems: Three Easy Pieces.
5
u/nekokattt May 16 '23
do you want to make use of the idiomatic c++ features?
using stuff like the fs API, std::thread, etc kind of falls apart if you are trying to implement those things on the OS level.
other stuff will work fine but it is worth being aware of.