←back to thread

309 points LorenDB | 8 comments | | HN request time: 0.001s | source | bottom
1. siws ◴[] No.42641548[source]
Reading this post makes me think, how can someone start to get into the drivers and OSes world? This seems so complicated I really don’t know where to start.
replies(6): >>42641944 #>>42642133 #>>42643359 #>>42644209 #>>42645600 #>>42651669 #
2. saidinesh5 ◴[] No.42641944[source]
Honestly, step 1 is just understanding what the purpose of each component is.. OS, driver, device etc...

for eg. A device driver is about exposing an interface for other programs being run on your computer, to access and control a device...

https://m.youtube.com/watch?v=juGNPLdjLH4 this is a decent crash course on that.

You can create a toy USB device using an Arduino or something that can send / receive information to your PC. Eg: https://m.youtube.com/watch?v=yTc2GLXfCOY .

Then it's a matter of just understanding what the subsystem you're interested in writing drivers for your OS does, how to make it do something, just write code. Storage devices, graphics devices, etc...

A raspberry pi can be a decent starting point for these experiments too.. eg. Writing a bare metal operating system for the raspberry pi https://github.com/babbleberry/rpi4-osdev

3. agentkilo ◴[] No.42642133[source]
I started with LDD [1], which is a book from a decade ago, but should still be relevant these days. And at some later time I found this treasure trove [2] hidden in FreeBSD docs, among which, the FreeBSD Architecture Handbook and the FreeBSD Developers' Handbook may be of special interest to you.

[1] https://lwn.net/Kernel/LDD3/

[2] https://docs.freebsd.org/en/books/

4. rollcat ◴[] No.42643359[source]
I did an OS dev course in uni, that was some 15 years ago. We used Minix, which is super cleanly written (5kloc kernel) and is covered by many textbooks (sorry but can't remember which one I used, but there's also the official one).

I got to implement a simple server (Minix is a μkernel so that's how most drivers work) and do some kernel hacking. I read the course material in advance and didn't even attend any lectures, still got an 8/10 grade ^^

I've also heard many good things about NetBSD and of course SerenityOS (Andreas did a lot of development on live streams).

It is indeed easy once you know where to start.

replies(1): >>42649641 #
5. ultimaweapon ◴[] No.42644209[source]
Actually it is very simple to communicate with the modern hardware (both x86 and ARM). All you need to do is read/write the hardware memory. This called Memory-mapped I/O (or MMIO in short). Of course you cannot do this from the application that run on the OS since it is a job of the kernel to prevent the application to direct access the hardware memory. Here are the roughly steps if you want to get into this field:

1. You need a programming language that capable of output the machine code for your target CPU. Better to be a language that does not have GC or runtime like Rust/C++/C/Zig. If you are not familiar with low-level language I recommend C as a first step since it is easy to find examples on the internet.

2. Learn the basic of assembly language of your target CPU. You need this because the above language may not provide the intrinsic functions for some instructions.

3. Start writing a hello world kernel. You can find a bunch of tutorial on the internet, especially for x86.

4. With step 3 you should already learned how the CPU start your kernel and how many mode and privilege level available on the CPU. Usually the CPU will give you the highest privilege level when jumping into your code.

5. Now you need to setup the CPU into whatever you want. For example, you likely need to switch the CPU to long mode on x86 so you can use 64-bits instructions. In this step you likely need to setup a virtual memory. You can find a reference for your CPU from their website.

6. If you have reached this step then congratulations! You should already have some idea how the CPU is working with the OS and how to enumerate available devices to discover its memory location. There are a ton of works that need to be done once you are here like implementing filesystem, scheduler, etc.

Remember that the only different between the software that run on the OS and the OS kernel is mode of the CPU currently executing its code. With highest privilege level you can use some instructions that are not available to the normal application.

6. mfro ◴[] No.42645600[source]
I really enjoyed this tutorial:

https://wiki.osdev.org/Bare_Bones

7. nonrandomstring ◴[] No.42649641[source]
> can't remember which one I used, but there's also the official one

Andrew Tanenbaum "Modern Operating Systems" (The Red Book)

8. snvzz ◴[] No.42651669[source]
I'd start with ISBN-13: 978-0136386773.