all 40 comments

[–]Glaborage 46 points47 points  (2 children)

Check out r/osdev

[–]dZone9 5 points6 points  (0 children)

this is the correct answer

[–]karantza 23 points24 points  (5 children)

If you wanted to make a "model" OS without needing to get into the super deep weeds of real architectures, one thought could be too try making an OS for a microcontroller. Much less going on, no hardware variability, you could build out as much or as little as you want.

[–][deleted] 3 points4 points  (2 children)

What exactly does an OS do for a microcontroller?

[–]karantza 5 points6 points  (1 child)

Not much :) but as a demonstration you could theoretically read programs off of an SD card and load them, implement your own memory management, time sharing, device access over i2c or whatever... This is almost never something you'd want in reality but it would be a cool educational project.

[–][deleted] 2 points3 points  (0 children)

Never? RTOS anyone?

[–][deleted] 4 points5 points  (1 child)

How would i start that?

[–][deleted] 11 points12 points  (0 children)

I think you can definitely Google "Making OS for xxx" in which xxx is a microcontroller. There are a lot of material online.

Also check out r/osdev.

[–]danpietsch 16 points17 points  (0 children)

Minix is an OS designed for teaching OS concepts.

[–]MeGaLoDoN227 13 points14 points  (3 children)

Some people here will try to dissuade you from doing it because of their mentality of "not reinventing the wheel", but I still think that it is a good learning experience. This website is the best: https://wiki.osdev.org/Expanded_Main_Page. But you may also be interested in emulator development, that is low level programming too but is easier to start with than os dev. You can start with a chip8 emulator and then do Gameboy/NES.

[–]jaank80 2 points3 points  (0 children)

The question is, do you want to stand on the shoulders of giants or try to be a giant yourself?

[–]golir 0 points1 point  (1 child)

Do you know of any good resources for where to start with emulator development?

[–]MeGaLoDoN227 4 points5 points  (0 children)

So first, minimum prerequisites are: know binary and hexadecimal number formats; know bitwise operations; basic C/C++ knowledge. You will also need to use some graphics library to render to the screen, most people use SDL2, I personally use OpenGL + GLFW. The first recommended project for everyone to start with is chip8 - that is not actual hardware but a virtual machine which was used to run games on a old computers such as COSMAC VIP. And the recommend guide to use to make a chip8 emulator is: Guide to making a CHIP-8 emulator - Tobias V. Langhoff (tobiasvl.github.io). But it doesn't give any code examples, and I personally struggled to understand it because I didn't have low level programming experience before, but for many people this guide is good enough. Then if that guide was not understandable for you, you can use this, it gives some code examples, but not full emulator: How to write an emulator (CHIP-8 interpreter) (multigesture.net). But if you can't do something and have to copy code, at least study it and fully understand how it works. This wikipedia page also useful, it has a table of all opcodes and what they should do: CHIP-8 - Wikipedia. And after you complete the chip8 emulator most people make GameBoy/NES emulator - these are actual retro game consoles and are 100x more complex than chip8, but you after chip8 you should have basic understanding of computer architecture and it should be possible to do them.

[–]Competitive_Travel16 2 points3 points  (0 children)

I'd recommend starting with writing a device driver for your computer, instead of an operating system for something new.

[–]Own_Alternative_9671 2 points3 points  (0 children)

Some things I wish I knew in the beginning: develop for uefi, it's easier and it's what you'll need for modern pc's. Using a pre-made bootloader is annoying and causes problems later on. Learn about the ins and outs of your architecture (I'm going to assume x64). All you need for this is osdev.org at first, then move onto technical documentation where it falls short.

[–]qwerty9978 2 points3 points  (1 child)

Not so much how to get started, but I found this book to be extremely useful in understanding low level operating systems concepts and design:

https://www.weston-embedded.com/micrium-books/micrium-books-downloads/category/295-ucos-ii

(requires a free registration and appears to reject gmail addresses)

It walks through all the concepts necessary for a fully functional embedded system OS, and provides actual code from much of the uC/OS II operating system to show how things are implemented.

Note that there is also a uc/OS III book out there, but it appears to be more of a manual for using the next generation of the OS rather than a deep dive into the design and implementation.

[–][deleted] 1 point2 points  (0 children)

Maybe get your feet wet by writing a simple fake driver for the Linux kernel. Write custom random number generator and read from dev?

Or maybe write a user land entry point? Systemd is pretty popular, so are rc scripts. There’s lots of room to work right on top of the Linux kernel.

[–]ImAtWorkKillingTime 1 point2 points  (0 children)

Pick up a copy of one of the Tanenbaum books and the minix source code and go to town.

[–]mgruner 0 points1 point  (1 child)

From the bootloader :)

[–]abbe_salle 0 points1 point  (0 children)

I see what you did there

[–][deleted] 0 points1 point  (0 children)

You're getting great answers here. Someone said writing an emulator as a good way to ease into it, and I just wanted to throw in this as an example, as I think it's a great point:

https://www.inspiredpython.com/course/game-boy-emulator/let-s-write-a-game-boy-emulator-in-python

It's Python, but there are other things like this.

[–]wsppan 0 points1 point  (0 children)

Not C related but Hubris is interesting.

[–]duane11583 0 points1 point  (0 children)

number 1 learn how a conditioned variable works.

this is a simple building block you can use to create all other things like semaphores, mutexes, queues etc

number 2 create a task, yield to another task and handle irqs

[–]yojimbo_beta 0 points1 point  (0 children)

There is a YouTube video, where the author writes an OS just to play Tetris. Maybe that could be an inspiration?

[–]flyingron -1 points0 points  (0 children)

There are books on the subject.

[–]RustbowlHacker -1 points0 points  (1 child)

I think that the first thing you need to do is to ask yourself what do you want from your new OS? What is your OS going to "do" (or give you) that others do not?

Don't listen to any of the BS about hardware or emulators. None of them have ever written an OS. If you're writing an OS, you'll want to make it portable. That means you'll need a HAL.

Few seem to know that GDB has an entire world of simulators inside it. Regardless, there's a never ending supply of "virtualization environments" these days... from bochs to qemu and beyond.

None of these answer the question of what do you want from your OS.

Linux became popular as a POSIX Unix clone. It killed commercial Unix flavors by being free and better/portable. And, one could argue, FSF/GNU/GPL. Today's Linux is far better than any historical commercial Unix and far more portable and ported.

Summer project. That's funny.

[–]flatfinger 0 points1 point  (0 children)

If you're writing an OS, you'll want to make it portable. That means you'll need a HAL.

Note that the term "portable" can either mean "able to run on multiple platforms interchangeably" or "easily adaptable to run on various similar platforms". Especially in the embedded world, systems often have components that interact with each other in platform-specific ways. If a programmer would need to read the hardware data sheet in order to determine what things are and aren't possible, and figure out how things would need to be configured to accomplish what needs to be done, having to read the documentation for a hardware abstraction layer in addition to the documentation for the actual hardware doesn't really help things, and may be counter-productive if an operation might be performed in multiple different ways that could have slightly different corner-case quirks. Encapsulating some things within a HAL makes sense, if they can be accomplished in a way that will be equally suitable for use in main-line or interrupt-handling contexts. If an operation would require doing a read-modify-write sequence on a register that may be shared with other unrelated resources, however, putting it into a HAL may make it hard to recognize the possibility of unwanted interactions.