Rust, cargo and QEMU setup for multi-architecture OS development.

Overview

rust-osdev-jumpstart

Rust, cargo and QEMU setup for multi-architecture OS development.

Goal

This repo should give you a boost in starting a bare-metal OS development project in Rust. You can go backwards from here if you just want something working as a starting point (but have different ideas for foundation), or you can go forward and exploit the testing setup.

Sources

These three are the great Rust bare-metal OS development blogs, and I have borrowed liberally from their ideas and code.

Features

  • Doc tests and unit tests run your development host OS for speed.
  • Integration tests are run under QEMU with cargo test --target <triple>.
  • Integration tests utilise custom test frameworks feature for convenient test suites.
  • QEMU passes back test result to cargo using qemu_exit.
  • make test_all runs doc, unit and integration tests for all three architectures.
  • QEMU definitions largely follow the platform-specific blogs above.

Example usage

$ make test_all
cargo test --doc --target=x86_64-apple-darwin
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
   Doc-tests libkernel

running 1 test
test src/lib.rs - (line 4) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.47s

cargo test --lib --target=x86_64-apple-darwin
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target/x86_64-apple-darwin/debug/deps/libkernel-910fb71f27dff6a6

running 1 test
test test::panics_ok ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

cargo test --target x86_64-unknown-none.json -Zunstable-options -Zbuild-std=core,compiler_builtins -Zbuild-std-features=compiler-builtins-mem
    Finished test [unoptimized + debuginfo] target(s) in 0.04s
     Running target/x86_64-unknown-none/debug/deps/000_kernel_init-f9ceeb28812f2f47
Building bootloader
   Compiling bootloader v0.9.11 (~/.cargo/registry/src/github.com-1ecc6299db9ec823/bootloader-0.9.11)
    Finished release [optimized + debuginfo] target(s) in 1.14s
Running: `qemu-system-x86_64 -drive format=raw,file=target/x86_64-unknown-none/debug/deps/bootimage-000_kernel_init-f9ceeb28812f2f47.bin -no-reboot -device isa
     Running target/x86_64-unknown-none/debug/deps/001_should_panic-6a56cc56ef6b6077
Building bootloader
   Compiling bootloader v0.9.11 (~/.cargo/registry/src/github.com-1ecc6299db9ec823/bootloader-0.9.11)
    Finished release [optimized + debuginfo] target(s) in 1.11s
Running: `qemu-system-x86_64 -drive format=raw,file=target/x86_64-unknown-none/debug/deps/bootimage-001_should_panic-6a56cc56ef6b6077.bin -no-reboot -device is
cargo test --target riscv64gc-unknown-none-elf
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target/riscv64gc-unknown-none-elf/debug/deps/000_kernel_init-af9782dbeaca1763
     Running target/riscv64gc-unknown-none-elf/debug/deps/001_should_panic-db251fb771fa34a8
cargo test --target aarch64-unknown-none-softfloat
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target/aarch64-unknown-none-softfloat/debug/deps/000_kernel_init-13b9d95425b9c0bb
     Running target/aarch64-unknown-none-softfloat/debug/deps/001_should_panic-e72d04dcc4d61eda

Known limitations and extensions

Pull requests welcome!

  • Only tested on Mac OS 11 Big Sur.
  • Running the doc and unit tests on the host means those tests can't interact with hardware. Even to unit test the architecture-independent code would require either a mock _arch/test or lots of cfg(test) peppered through-out.
  • Utilising -Zmultitarget would be an improvement, but the -Zbuild-std options required for x86_64 can't be pushed into [target.x86_64...] inside .cargo/config.toml. You would probably still need make as a shorthand.
  • Logging would be a great inclusion, but might be quite opinionated with quite a bit of serial device code.
  • Device tree management in the Makefile for RiscV and Arm.

Other influences

You might also like...
An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.
An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.

java-2-times-faster-than-c An experiment showing double performance of the code running on JVM comparing to equivalent native C code ⚠️ The title of t

probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device

probe-run Runs embedded programs just like native ones probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device.

A cargo plugin for showing a tree-like overview of a crate's modules.

cargo-modules Synopsis A cargo plugin for showing an overview of a crate's modules. Motivation With time, as your Rust projects grow bigger and bigger

A cargo subcommand to fetch the $OUT_DIR environment variable from build scripts

cargo-outdir A cargo subcommand to fetch the $OUT_DIR variable from build scripts. This is extremely useful to inspect the output of automatically gen

cargo-add command to make dependencies into dylibs

cargo add-dynamic This cargo command allows to wrap dependencies as dylibs. For why you might want this see Speeding up incremental Rust compilation w

In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

A comprehensive and FREE Online Rust hacking tutorial utilizing the x64, ARM64 and ARM32 architectures going step-by-step into the world of reverse engineering Rust from scratch.
A comprehensive and FREE Online Rust hacking tutorial utilizing the x64, ARM64 and ARM32 architectures going step-by-step into the world of reverse engineering Rust from scratch.

FREE Reverse Engineering Self-Study Course HERE Hacking Rust A comprehensive and FREE Online Rust hacking tutorial utilizing the x64, ARM64 and ARM32

An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous and blocking clients respectively.

eithers_rust An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous a

Comments
Owner
Alister Lee
Alister Lee
Elemental System Designs is an open source project to document system architecture design of popular apps and open source projects that we want to study

Elemental System Designs is an open source project to document system architecture design of popular apps and open source projects that we want to study

Jason Shin 9 Apr 10, 2022
Simple Event-Driven Microservice Architecture in Rust

Simple Event-Driven Microservice Architecture in Rust is an open-source project showcasing the simplicity and efficiency of building microservices in Rust. This minimalistic project demonstrates an e-commerce backend system, featuring just two microservices: Catalog and Order.

James Mallon 4 Dec 19, 2023
This blog provides detailed status updates and useful information about Theseus OS and its development

The Theseus OS Blog This blog provides detailed status updates and useful information about Theseus OS and its development. Attribution This blog was

Theseus OS 1 Apr 14, 2022
The source code that accompanies Hands-on Rust: Effective Learning through 2D Game Development and Play by Herbert Wolverson

Hands-on Rust Source Code This repository contains the source code for the examples found in Hands-on Rust. These are also available from my publisher

Herbert 261 Dec 14, 2022
The ray tracer challenge in rust - Repository to follow my development of "The Raytracer Challenge" book by Jamis Buck in the language Rust

The Ray Tracer Challenge This repository contains all the code written, while step by implementing Ray Tracer, based on the book "The Ray Tracer Chall

Jakob Westhoff 54 Dec 25, 2022
Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.

Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer ?? Download | Give it a Star ⭐ | Share it on Twitte

Julio Andres 73 Jun 15, 2023
Rust development environment for MIPS on NT4

Summary This is a project which allows us to run Rust "shellcode" in a MIPS environment on NT 4.0. TL;DR Setup NT Install NT 4.0 MIPS in QEMU using th

null 19 Dec 18, 2022
Code to follow along the "Zero To Production" book on API development in Rust.

Zero To Production / Code (Chapter 10 - Part 1) Zero To Production In Rust is an opinionated introduction to backend development using Rust. This repo

Luca Palmieri 2.8k Dec 31, 2022
Game development practices with Rust programming language. I want to use different crates for this.

Hazır Oyun Motorlarını Kullanarak Rust Dili Yardımıyla Oyunlar Geliştirmek Rust programlama dilinde oyun geliştirmek için popüler birkaç hazır çatıyı

Burak Selim Senyurt 16 Dec 27, 2022
A collection of crates to make minecraft development (client, server) with rust possible.

rust-craft rust-craft is a collection of crates to make minecraft development (client, server) with rust possible. Motivation There's no better way of

João Victor 15 Mar 23, 2023