Operating System in 1,000 Lines - Getting Started

  1. Intro
  2. Getting Started
  3. RISC-V 101
  4. Overview
  5. Boot
  6. Hello World!
  7. C Standard Library
  8. Kernel Panic
  9. Exception
  10. Memory Allocation
  11. Process
  12. Page Table
  13. Application
  14. User Mode
  15. System Call
  16. Disk I/O
  17. File System
  18. Outro

This book assumes you're using a UNIX or UNIX like OS such as macOS or Ubuntu. If you're on Windows, install Windows Subsystem for Linux (WSL2) and follow the Ubuntu instructions.

Install development tools

macOS

Install Homebrew and run this command to get all tools you need:

brew install llvm lld qemu

Ubuntu

Install packages with apt:

sudo apt update && sudo apt install -y clang llvm lld qemu-system-riscv32 curl

Also, download OpenSBI (think of it as BIOS/UEFI for PCs):

curl -LO https://github.com/qemu/qemu/raw/v8.0.4/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin

When you run QEMU, make sure opensbi-riscv32-generic-fw_dynamic.bin is in your current directory. If it's not, you'll see this error:

qemu-system-riscv32: Unable to load the RISC-V firmware "opensbi-riscv32-generic-fw_dynamic.bin"

Other OS users

If you are using other OSes, get the following tools:

To check if your clang supports 32-bit RISC-V CPU, run this command:

$ clang -print-targets | grep riscv32
    riscv32     - 32-bit RISC-V

You should see riscv32. Note pre-installed clang on macOS won't show this. That's why you need to install another clang in Homebrew's llvm package.

Setting up a Git repository (optional)

If you're using a Git repository, use the following .gitignore file:

.gitignore
/disk/* !/disk/.gitkeep *.map *.tar *.o *.elf *.bin *.log *.pcap

You're all set! Let's start building your first operating system!