
Learn to write your first OS kernel (2018) - razerblader7
https://github.com/arjun024/mkernel
======
minism
As others have stated there are much better guides than this.

I did this recently for fun, including the bootloader (I considered GRUB
cheating!) The best tutorial IMO was [https://samypesse.gitbook.io/how-to-
create-an-operating-syst...](https://samypesse.gitbook.io/how-to-create-an-
operating-system/)

Some other useful resources I found:

    
    
      - http://3zanders.co.uk/2017/10/13/writing-a-bootloader/
      - http://mikeos.sourceforge.net/write-your-own-os.html
      - https://www.nasm.us/doc/
      - http://faydoc.tripod.com/cpu/
      - https://github.com/cfenollosa/os-tutorialjos

~~~
gen_greyface
Clickable links

[http://3zanders.co.uk/2017/10/13/writing-a-
bootloader/](http://3zanders.co.uk/2017/10/13/writing-a-bootloader/)

[http://mikeos.sourceforge.net/write-your-own-
os.html](http://mikeos.sourceforge.net/write-your-own-os.html)

[https://www.nasm.us/doc/](https://www.nasm.us/doc/)

[http://faydoc.tripod.com/cpu/](http://faydoc.tripod.com/cpu/)

[https://github.com/cfenollosa/os-
tutorialjos](https://github.com/cfenollosa/os-tutorialjos)

------
g82918
I waited a few hours and didn't see any mention of the big one :
[https://wiki.osdev.org/Bare_Bones](https://wiki.osdev.org/Bare_Bones). In
general osdev has a lot of good resources although the good threads get buried
in the forum. Sortix came from there and the threads about trying to minimize
the source dependency graph helped a lot in my first startup.

------
fwsgonzo
I have made a codebase where all the C and C++ glue is already taken care of,
as well as the build system:

[https://github.com/fwsGonzo/barebones](https://github.com/fwsGonzo/barebones)

However, nothing else. So it's a starting point for a beginner. I don't know
if its the perfect starting point or not, but at least you won't be stuck with
all the setup. If you are writing an OS in another language you can probably
get some inspiration as well, as for example I did implement basic ubsan
support.

Some fun facts:

There is a C++ exceptions example that shows that with the compiler runtime as
well as a libunwind you can catch C++ exceptions, but only if you create the
exception fully yourself, as there is no standard library. It does add a bit
of bloat, so it's not really intended for OS development.

There is an example of how to runtime load a library, and call into it. No
runtime linking, just an exchange of call table.

There is very primitive backtrace functionality in the panic function simply
by using compiler builtins. No way to convert the addresses to function +
offset because there is no symbol table. One cool way to do this is to link
the kernel, generate an ELF section that contains only the function symbols,
and then append it to the end of your kernel. During initialization you can
then use it for backtraces. It's also fairly architecture independent, as you
will only have to distinguish between 32- and 64-bit symbols.

------
feiss
What I'd love to have is a tutorial or a base OS that initializes all the
hardware stuff (I/O, memory, discs, video, processor...) and let you build the
software stack on top of it. Anything outthere? The closest I found is
baremetal
[https://en.wikipedia.org/wiki/BareMetal](https://en.wikipedia.org/wiki/BareMetal)

------
rs23296008n1
Well it does what it says on the tin. So its fine.

Whats your next step? Perhaps put a version of snake in there. That will
provoke input/output etc... I'd suggest text mode first but then aim for VGA
and beyond.

If you want a bigger challenge, implement serial port I/O so you could hook it
via virtualbox etc to another running machine and network your snake game etc.

Then from there dig into ethernet and use raw ethernet or even UDP. Now you
have a full working network client from the ground up.

------
rvz
That's it?

While the point of this project is to go for developing a very small kernel, I
afraid I can't recommend this as a way to "learn to write your first OS
kernel".

Particularly, this project has been fossilised for two years, (last commit was
in 2018) with a single commit each year hardly qualifies as an updated
tutorial for writing OS kernels.

My first recommendation would be the "writing an OS in Rust" tutorials [0] and
the xv6 tutorials [1].

[0] [https://os.phil-opp.com/](https://os.phil-opp.com/)

[1]
[https://pdos.csail.mit.edu/6.828/2019/xv6.html](https://pdos.csail.mit.edu/6.828/2019/xv6.html)

~~~
yardshop
His blog post goes into a lot more detail about things, and he has a part 2
where he adds keyboard input and screen output via interrupt handlers. It's
useful as a "Hello World" level intro to the topic.

Kernels 101 – Let's write a Kernel
[http://arjunsreedharan.org/post/82710718100/kernel-101-lets-...](http://arjunsreedharan.org/post/82710718100/kernel-101-lets-
write-a-kernel)

Kernels 201 - Let’s write a Kernel with keyboard and screen support
[https://arjunsreedharan.org/post/99370248137/kernels-201-let...](https://arjunsreedharan.org/post/99370248137/kernels-201-lets-
write-a-kernel-with-keyboard)

------
rkachowski
The link says 2018, but this was published in 2014

