8 ms·
How to write a simple operating system
- Jeaye 10y agoThat's not an operating system; it's a trivial kernel. Linux, in all its complexity, is still not an operating system; it's a kernel. For anyone seriously interested in building something less trivial, I recommend starting here: http://wiki.osdev.org/Getting_Started http://wiki.osdev.org/Getting_Started
- gumby 10y agoI've always thought of the operating system basically being everything in kernel space and as user space being peripheral. I think we both have our biases.
- jacquesm 10y agoNo, we don't have 'our biases' you're just plain wrong. An operating system is everything needed to run a machine, a kernel is the foundation on top of which all that user space code runs. So from a unix perspective everything in /usr/bin /bin /usr/local /etc, /boot and whatever other directories are there after you install makes up the operating system. Whatever you install after you get the base system up and running are applications, the programs we run on top of operating systems. Now, the line can get a little blurry: is 'X' part of the operating system or not? Is your window manager, are the various built ins? Probably yes, but not always. Is a text editor part of your OS? Probably not, but there is a good case to be made for the fact that without a text editor of any kind an operating system is fairly useless. But that doesn't make 'libreoffice' or 'sublime' part of your OS, those are applications. For myself, I draw the line where a minimum base install stops, so everything up to and including window manager for a desktop machine (for a headless machine or server much less than that). From a very technical perspective you could have an operating system that consists of just a kernel and one user space program, in that case the kernel really would be the entirety of the operating system. But that's a pretty rare case (though it can be done). This is all written from a UNIX/Linux perspectie, for OS you might draw the lines a little different and for MS/Windows different still. But those basic principles apply.
- epboyd 10y agoAnd what about a microkernel environment where device drivers, filesystems, etc. are in user space?
- jacquesm 10y agoThey're still part of the operating system. What you are trying to get at is that everything in userspace is not part of the kernel and that is correct. But the kernel does not make a complete operating system. This is also the reason why the whole GNU/Linux thing existed, without the userland that GNU provided the Linux kernel would have been pretty useless.
- kiriakasis 10y agoMy position is a little in between, an OS is the finished you are delivering. Linux is an OS, just a terrible one without any GNU.
- JustSomeNobody 10y ago> No, we don't have 'our biases' you're just plain wrong. You sound defensive.
- JustSomeNobody 10y agoI'm with you. An OS is the core functionality on which everything else is hung. Code to fork a process? That's OS. Window manager? Not OS.
- oneweekwonder 10y agoHow up to date is minix3? http://wiki.minix3.org/doku.php?id=www:documentation:start http://wiki.minix3.org/doku.php?id=www:documentation:start
- greenhouse_gas 10y agoI think that it's a semantic thing, but most "simple OS in 24 hours" projects only talk about the kernel because the rest is easy/off-topic. ls? Basic sh (without the scripting part, but there are tutorials on building compilers/interpreters)? Basic init?
- DSMan195276 10y agoI think it's worth adding though - articles like these aren't kernel's, they're just programs running on the bare-metal. This stuff (booting the computer and getting to a sane environment) is really the easy part, designing the kernel and creating the kernel's facilities that it provides to programs is the bulk of the work when writing a kernel/OS. That's not to say these articles are bad, they're still fun, but it's like having a "simple emulator in 24 hours" that just sets up a simple GUI and doesn't actually start designing the emulator. It's technically the start of an emulator, but while that part might actually be complicated it's still not really that relevant to designing an emulator.
- wonderous 10y ago(2014) should be in the title. https://web.archive.org/web/20140719115200/http://mikeos.sourceforge.net/write-your-own-os.html https://web.archive.org/web/20140719115200/http://mikeos.sou... Maybe even (2011): https://news.ycombinator.com/item?id=2100115 https://news.ycombinator.com/item?id=2100115
- roryisok 10y agoI'm not sure why, but whenever I see a link pointing to sourceforge my instant gut reaction is that it'll be a decade+ aged code that doesn't work properly anymore. I always avoid sourceforge when searching for solutions. I don't know why I have this bias
- justin66 10y agoBecause it's true in 90% of the cases?
- nerdponx 10y agoSame with Bitbucket, although maybe just 3-4 years instead of a decade.
- pavlov 10y agoI like Bitbucket. For Git hosting, it's faster than Github (maybe their servers are closer to me?). I also find my way around Bitbucket's UI more easily.
- dang 10y agoDiscussed in 2011: https://news.ycombinator.com/item?id=2100115 https://news.ycombinator.com/item?id=2100115
- alxmdev 10y agoWell-written primer, so cool to see something complex reduced to its simplest form that captures the essence. Funny to read how PC memory can be "millions of bytes on modern machines". To be fair, I was using a computer with only 128MB as recently as 7 years ago :-)
- analognoise 10y agoTo be fair, that's still millions of bytes.
- H4CK3RM4N 10y agoBut, like, less millions.
- rbanffy 10y agoIf one is going to use an emulator to test an OS, why be confined to the x86 ISA and all the historic warts of the PC? Design a decent computer first, then write an OS for it.
- nickpsecurity 10y agoOr just use a simple, stack machine. Or a RISC CPU. Preferrably on an emulator or FPGA already. Oberon did this.
- rbanffy 10y agoIt pains me when someone decides to submit to the pain of building something directly on the legacy of the ugliest computer ever built.
- nickpsecurity 10y agoI hear you. Pains me it won out instead of i960 with an emulation mode for backward compatibility. Far as learning on x86, there's two counterpoints come to mind: 1. Most sample code out there for "real" OS's might be x86. Most projects that aren't embedded will target it. So, might bite the bullet for that reason. 2. Other reason is if the end goal is to improve software on x86 hardware. As in, learner explicitly wants to take advantage of high-performance, x86 chips or code. A shortcut might be porting more sample OS's to non-x86 CPU's. They learn each thing for simple architecture followed by ugly one later. Alternatively, abstract away what one can like Fluxkit project did. That was how a number of OS's were built in high-level languages without having to redo all the low-level stuff.
- bogomipz 10y agoI would like to hear more about Oberon OS running on an emulator. Might you have a link, this sounds interesting?
- Someone 10y agoI think the OP, when saying "Preferrably on an emulator or FPGA already. Oberon did this.” meant that Oberon (second edition; the first one ran on a NS32032) ran on a FPGA (https://lists.inf.ethz.ch/pipermail/oberon/2013/006922.html https://lists.inf.ethz.ch/pipermail/oberon/2013/006922.html, https://www.inf.ethz.ch/personal/wirth/ProjectOberon/PO.Computer.pdf https://www.inf.ethz.ch/personal/wirth/ProjectOberon/PO.Comp...)
- krat0sprakhar 10y agoThere's also "How to Make a Computer Operating System in C/C++" in a nice, readable Gitbook: https://samypesse.gitbooks.io/how-to-create-an-operating-system/content/ https://samypesse.gitbooks.io/how-to-create-an-operating-sys...
- bogomipz 10y agoWhat a great link! I have not seen this before. Thanks for sharing.
- mark_l_watson 10y agoNice. And the author started the project in high school?
- cr0sh 10y agoUnfortunately, nothing more seems to be written after the "Memory management: physical and virtual" chapter...? https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System https://github.com/SamyPesse/How-to-Make-a-Computer-Operatin... Disappointing...
- giancarlostoro 10y agoAnyone know any such resources for the Raspberry Pi 3? Only found some for the first Raspberry Pi
- laumars 10y agoWriting an OS for the Raspberry Pi is harder work that it should be because of the Broadcom SoC. It's a closed, proprietary chip that does a lot of the heavy lifting (including the initial boot mechanism). My advice to you if you want to write an OS targeting a developer board is to use one of the many open hardware platforms rather than the Raspberry Pi specifically. The Raspberry Pi's are better for tinkering with stuff that runs atop of the OS rather than designing kernels.
- Zaak 10y agoHow is bare-metal coding on something like the beagleboard black? Does it have the same issues, or is it a more open platform?
- giancarlostoro 10y agoWhich platforms (hardware) are good for this? I mostly want to mess with Linux on the Pi, but wouldn't mind trying some assembly on a cheaper board to learn more about bare metal programming.
- drewg123 10y agoAwesome. We need resources like this to get people into low level programming. The best class I ever took when I was an undergrad was a class where we built our own OS for a Data General Aviion workstation. Our systems staff was already under contract to help port 4.3BSD to the Aviion, and they had tons of test hardware and docs. So one of the group taught an OS class where whey basically turned us loose with a cross-toolchain and a manual and let us hack all semester. I think by the time we were done, we had something that booted and interacted with a very basic shell (but could not fork, no multi-tasking, no mem prot, etc). If it were not for this class, I think the more theoretical OS class that I took later in grad school (all dreadfully boring queueing theory style stuff) would have turned me off to doing OS work. Instead, I've had a career doing lots of low-level stuff (drivers, OS ports to new CPUs, network stack improvements, etc).
- fellellor 10y agoWhat kind of hardware would I require to do this project on my own?
- tbrock 10y agoSeems cool, anyone know how this compares to similar projects out there? In thinking of doing an OS course soon as a refresher.
- partycoder 10y agoSome resources for writing OSes: - Andrew Tannenbaum's MINIX, and his Operating system books - The OSDev wiki: http://wiki.osdev.org http://wiki.osdev.org
- z3t4 10y agoI wonder if assembly languages will have a comeback now in the era of virtualization ... ?
- Ultimatt 10y agoReaders understand this isn't close to being an operating system right? You get the first boot sector of a floppy for free from the BIOS. This isn't even as complex as the most simple boot loader. It doesn't handle loading more sectors of the floppy let alone being like an OS. It's hello world in assembly, loaded onto the first sector of an emulated floppy. That's neat, but nothing to do with operating systems. Other than you've now learnt the very first stage of bootstrapping from a floppy disk back in the 90s. Which is cool, and good info to know and start out with. I get the vast majority of people seeing this post have probably only ever experienced nodejs, or Ruby on Rails or something equally high level. But this is trivial with respect to an operating system or even a boot loader.