#kernel #embedded #no-std #x86

nightly no-std bin+lib rustos

Writing an OS in Rust

8 releases

0.4.3 Apr 10, 2020
0.4.2 Apr 8, 2020
0.3.3 Apr 7, 2020
0.2.2 Apr 5, 2020

#186 in Operating systems

Download history 1/week @ 2022-01-20 1/week @ 2022-01-27 1/week @ 2022-02-03 11/week @ 2022-02-17 2/week @ 2022-02-24 3/week @ 2022-03-03 4/week @ 2022-03-10 62/week @ 2022-03-17 2/week @ 2022-04-07 2/week @ 2022-04-14 4/week @ 2022-04-21 65/week @ 2022-04-28 50/week @ 2022-05-05

122 downloads per month

Apache-2.0 OR MIT

44KB
1K SLoC

rustos

drone crate docs

Philipp Oppermann's awesome Writing an OS in Rust

main.rs

Current main.rs:

#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(rustos::test_runner)]
#![reexport_test_harness_main = "test_main"]
extern crate bootloader;
extern crate rustos;
use bootloader::{entry_point, BootInfo};
use core::panic::PanicInfo;
use rustos::{println, task};

entry_point!(start_kernel);

fn start_kernel(boot_info: &'static BootInfo) -> ! {
    println!("Welcome to the real world!");

    // Initialize the kernel.
    rustos::init();
    rustos::memory::init(boot_info);

    // Spawn async task(s).
    let mut executor = task::Executor::new();
    executor.spawn(task::Task::new(example_task()));

    #[cfg(test)]
    test_main();
    println!("It did not crash!!!");

    // Run forever.
    executor.run()
}

#[cfg(not(test))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    println!("{}", info);
    rustos::hlt_loop();
}

#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    rustos::test_panic_handler(info)
}

async fn example_task() {
    let number = async_number().await;
    println!("async number: {}", number);
}

async fn async_number() -> u32 {
    42
}

Execution

You can run the current [main.rs] with make run:

make run

or the previous posts, e.g. [post01.rs] with make run-post_name as:

make run-post01

Tests

You can run all the integration test with make test:

make test

or specific tests with `make tsst-test_name as:

make test-heap_allocation

Happy Hackin'!

Dependencies

~2MB
~34K SLoC