Live data from Hacker News

Operating System in 1,000 Lines – Intro

operating-system-in-1000-lines.vercel.app

1–10 of 129 posts

Re: Operating System in 1,000 Lines – Intro

#2
I started a toy OS years ago based on the book Operating System Design by Douglas Comer. Personally I just couldn't get excited about anything that didn't run on real hardware, so I made mine for Raspberry Pi.

Is there any real hardware that this could run on?

Looking through this seems to use a lot of assembly. In the above the amount of assembly is kept to a minimum. Pretty much just bootstrapping and context switching. The rest is done in C.

Re: Operating System in 1,000 Lines – Intro

#4

I started a toy OS years ago based on the book Operating System Design by Douglas Comer. Personally I just couldn't get excited about anything that didn't run on real hardware, so I made mine for Raspberry Pi. Is there any real hardware that this could run on? Looking through this seems to use a lot of assembly. In the above the amount of assembly is kept to a minimum. Pretty much just bootstrapping and context switc…

Comer was also my introduction to OS design and I still like the approach used in his Xinu books.

I had a quick glance at the OS in the linked article. This seems to be based on a 32-bit RISC-V with MMU. However, AFAIK, all available RISC-V SoCs with MMU are 64-bit. The 32-bit cores are only used for embedded controllers (unless you want to start designing an FPGA-based system).

The 32 and 64 bit versions of RISC-V are _not_ binary compatible, but the differences are rather small. Porting the MMU code from 64 to 32 bit or the other way round is not very complex, see my RV32 port of xv6 at https://github.com/michaelengel/xv6-rv32 (the regular MIT xv6 version only supports RV64).

The major difference is that virtual address translation on RV32, sv32, uses a two-level page table (10 bit index for the first level, 10 bit index for the second and 12 bit offset) whereas there are several modes of translation for RV64. The most common one, sv39, uses 39 bits of the virtual address split into three 9-bit indexes (so you need a three-level page table for 4 kB pages) plus 12 bit offset.

If you make the modifications, running the OS on real hardware should not be too difficult. The Allwinner D1 is a relatively simply RV64 single code SoC (boards can be found for $20 upwards from aliexpress) and getting the CPU and a UART to work is not that difficult. You can check out my xv6 port to the D1 as a reference: https://github.com/michaelengel/xv6-d1

Re: Operating System in 1,000 Lines – Intro

#5
For any rust enthusiasts, phil-opp's guide is such a fun exercise to try out. It was actually the first thing I tried in Rust (very silly idea) and ended up only understanding ~5% of what I had just typed out.

I tried it again 2-3 years later and took the time to go over each subject. I even planned in advance to make sure I was going to finish it.

Re: Operating System in 1,000 Lines – Intro

#6
Very nice, I always enjoy some low-level discussion like this.

I found a small typo/editing glitch on the "RISC-V 101 page" [1]:

- It's a trending CPU ("Instruction Set Architecture") recent years.

It should probably say "ISA" instead of "CPU", and the word "in" is missing from after the parentheses, right?

Edit: Markdown, don't format the quote as code. Oops.

1: https://operating-system-in-1000-lines.vercel.app/en/02-asse...

Re: Operating System in 1,000 Lines – Intro

#7
post #3

I’m interested in the use of things like virtio instead of real hardware. Are there other virtualisation-driven designs for hardware devices out there rather than the qemu stuff?

Virtio is not qemu only. For example, the macOS virtualization framework on Apple Silicon Macs (and x86 machines IIRC) also provides virtio devices, other hypervisors.

An overview of the available devices can be found in this presentation:

https://crc.dev/blog/Container%20Plumbing%202023%20-%20vfkit...

Re: Operating System in 1,000 Lines – Intro

#8

I started a toy OS years ago based on the book Operating System Design by Douglas Comer. Personally I just couldn't get excited about anything that didn't run on real hardware, so I made mine for Raspberry Pi. Is there any real hardware that this could run on? Looking through this seems to use a lot of assembly. In the above the amount of assembly is kept to a minimum. Pretty much just bootstrapping and context switc…

I guess this could run on the Raspberry Pico - RP2040 / RP2350.
Post reply on HN