This is a very small toy OS written in about 1000 lines following the below guide.
https://operating-system-in-1000-lines.vercel.app/ja/welcome
$ tokei *.c *.h *.ld
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Language Files Lines Code Comments Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
C 6 1112 861 114 137
C Header 3 98 75 8 15
LD Script 2 78 48 15 15
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total 11 1288 984 137 167
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
common.c
,common.h
: Common libraries shared by both kernel and user (e.g.printf
,memset
)- Kernel land
kernel.h
: Constants and declarations shared within kernelkernel.c
: Entry point, allocation, paging, system calls, exception handlerfs.c
: Device (virtio-blk) driver and filesystemproc.c
: Multiple processes management with context switchkernel.ld
: Linker script for memory layout of kernel land
- User land
stdlib.c
,stdlib.h
: Standard libraryshell.c
: Command line shell (user program)user.ld
: Linker script for memory layout of user land
disk/*.txt
: Filesystem contentMakefile
: Build scriptrun.bash
: Script to run kernel with QEMUenv.sh
: Script to prepare development environment (for macOS)
source env.sh # For macOS
make
./run.bash
- RISC-V specification: https://github.com/riscv/riscv-isa-manual/releases/download/Priv-v1.12/riscv-privileged-20211203.pdf
- QEMU
virt
machine: https://www.qemu.org/docs/master/system/riscv/virt.html - Open SBI specification releases: https://github.com/riscv-non-isa/riscv-sbi-doc/releases
- VIRTIO specification: https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html