Skip to content

FnCtrlOption/xv6-riscv-zig

 
 

Repository files navigation

xv6-riscv-zig

xv6-riscv ported to the Zig build system

Requirements

  • Zig
  • QEMU (riscv64)
  • GDB (riscv64 or multiarch; for debugging)

Ubuntu

$ apt-get install qemu-system-misc gdb-multiarch

macOS

$ brew install qemu riscv64-elf-gdb

Building

$ zig build
$ ls zig-out/bin
_cat       _forktest  _grind     _ln        _mkdir     _stressfs  _zombie
_dorphan   _forphan   _init      _logstress _rm        _usertests kernel
_echo      _grep      _kill      _ls        _sh        _wc        mkfs

Running

$ zig build qemu
*** Loading ./.zig-cache/o/66e5103f4307166ed7059e40ee48255a/fs.img

xv6 kernel is booting

hart 2 starting
hart 1 starting
init: starting sh
$ usertests -q
usertests starting
test copyin: OK
test copyout: OK
test copyinstr1: OK
...

Debugging

$ zig build qemu-gdb
*** Now run 'zig build gdb' in another window.

Ubuntu

$ zig build gdb

macOS

$ zig build gdb -Dgdb=riscv64-elf-gdb

License

MIT

Related

  • (2025) Sped0n/zv6: Zig reimplementation of xv6-riscv's kernel
    • Uses hardcoded paths to zig-out
  • (2024) pYtato-KK/xv6-riscv-zig: xv6-riscv ported to the Zig build system
    • Installs a copy of fs.img in zig-out but uses a different copy in .zig-cache when running QEMU
  • (2024) aryalaadi/zinit-xv6-riscv: Zig reimplementation of xv6-riscv's init system
    • Not really idiomatic Zig
  • (2023) binarycraft007/xv6-riscv-zig: partial Zig reimplementation of xv6-riscv
    • Uses custom build steps (in Zig) instead of standalone programs for generating fs.img and usys.S
  • (2023) candrewlee14/xv6-riscv-zig: partial Zig reimplementation of xv6-riscv
    • Based on binarycraft007/xv6-riscv-zig
  • (2022) chaoyangnz/rvz: incomplete Zig reimplementation of xv6-riscv
    • Only implements drivers for clock and UART
  • (2022) saza-ku/xv6-zig: Zig reimplementation of xv6-x86's kernel
    • xv6-x86 is old and unmaintained

About

xv6-riscv ported to the Zig build system

Resources

License

Stars

Watchers

Forks

Languages

  • C 91.5%
  • Zig 3.3%
  • Assembly 2.5%
  • Python 2.1%
  • Other 0.6%