Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.
/ marvelos Public archive

Marvelous RISC-V Operating System, by donaldsebleung

License

Notifications You must be signed in to change notification settings

DonaldKellett/marvelos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

maRVelOS

Marvelous RISC-V Operating System, by donaldsebleung

Quickstart

make run (or make debug to debug with GDB)

Prerequisites

  • Experience with Unix/Linux systems, such as would be had from on-the-job Unix/Linux administration, RHCSA/LFCS certification or above, or having successfully completed Linux From Scratch
  • Familiarity with concepts in computer architecture and operating systems pertaining to Unix/Linux, such as would be had from attending and passing relevant introductory undergraduate level courses or above
  • A strong desire to learn!

Dependencies

The reference host environment is Ubuntu 22.04 (Linux). The project may build and run with minor modifications on other Unix/Linux systems such as Arch Linux, macOS or FreeBSD. Windows WSL2 may or may not work. Native Windows and Unix compatibility layers like Cygwin/MinGW/WSL1 are not supported.

  • QEMU full system emulator for 64-bit RISC-V, of which your distribution-provided package should suffice. E.g. on Ubuntu, install with sudo apt install -y qemu-system
  • A cross-compiler toolchain targeting 64-bit RISC-V as described on the OSDev wiki. Though you might be able to install it from your system package manager, it's recommended you build the toolchain from source for the newest features and to minimize differences between platforms. For reference, my riscv64-elf-* toolchain uses GCC 12.2.0 and Binutils 2.39
  • (Optional, required for debugging) GNU debugger targeting 64-bit RISC-V. Again, you may wish to build from source instead of installing directly from your system package manager. For reference, the riscv64-elf-gdb I used is at version 12.1

Project structure

A Makefile is provided for building the project using make.

  • src/: C source code files and other assets for building the kernel image
    • src/kmain.c: Kernel entry point
    • src/asm/: Assembly files, for hardware initialization and other low-level stuff not doable in C
    • src/lds/: Linker scripts for linking object files generated by our cross-compiler, specialized for our OS kernel
  • misc/: Miscellaneous files and utilities
    • misc/riscv64-virt.dts: Device tree file for 64-bit RISC-V virt board provided by QEMU
    • misc/gallery/: Image gallery containing screenshots and other artefacts documenting my progress through the project

References

My initial project setup is based on RISC-V from scratch and I intend to follow The Adventures of OS closely after that, though this may be subject to change.

Apart from those two guiding texts, the following resources have been helpful for me:

  • The OSDev wiki, for building my cross toolchain
  • Linux From Scratch, for their section on GDB in Beyond Linux From Scratch (BLFS)

Why C? Why not Rust?

You make it sound so easy ;-)

Basically, despite having gone through "The Rust Programming Language" ("the book"), I couldn't figure out how to build the code from "The Adventures of OS" properly even by directly git cloneing the official repository. Some issues I encountered were:

  • Some features from Rust nightly were promoted to stable in the meantime so the code no longer compiles as-is
  • Compiler panics from rustc when I tried to just copy over the project files with my own project layout
  • Linking errors about "soft floats" and "hard floats" (or something to that effect) when I switched to git cloneing the official repository and using the distribution-provided (Ubuntu 22.04) 64-bit RISC-V cross-compiler

So C seems the saner and more familiar option that works for me (so far) in the meantime and I'll stick with that for the time being ;-) Maybe I'll come back to Rust at a later date (-:

License

MIT