A language-based OS to run Rust on bare metal

Overview

RustOS

A simple, language-based OS.

Current features:

  • Simple VGA for seeing output
  • Some Rust libraries (core, alloc, collections) already in
  • Working (but limited) keyboard input
  • Beginnings of a network driver (RTL8139) and stack (it can send properly formatted UDP packets!)

Building:

  1. Dependencies:
  • qemu (emulator) or grub-mkrescue (run an iso on a VM or hardware)
  • as
  • ld
  • rustc (1.6.0-nightly)
  • cargo (1.6.0-nightly)
  1. Pull this repo git clone https://github.com/ryanra/RustOS.git
  2. Make sure to pull the submodules as well: git submodule update --init
  3. Run:
  • On qemu: make run
  • Or, make an iso make iso and run it on a VM or real hardware!

Organization:

  1. Main kernel code now in a fork of rust's libstd
  2. There is a libstd symlink to the bulk of the code (links to rust submodule at lib/rust/src/libstd/)
  3. Almost RustOS rust code is in src/libstd/sys/rustos/ which is a link to lib/rust/src/libstd/sys/rustos/

Design goals:

  1. Implement the entire Rust standard library on bare metal. Essentially, you should be able to write your program, link against std, add a bootloader, and run on bare metal. Of course, we'll need a little more to make the operating system extensible (specifically, an interface for adding drivers and libraries)

  2. The OS will be as simple as possible with as little as possible in it. Specifically, Rust type safety allows us to omit:

  • Paging. CPU memory protection is unecessary if you can only execute safe code
  • Syscalls. You can only call functions exported in std (there is the issue of unsafe though, which will need to be considered at some point)
  • (This simplicitly may also end up scoring in terms of performance!)
  1. Micro/Monolithic kernel is really irrelevant because everything is running in kernel mode and safety is enforced by the language, so there's no need for user mode. That said, the goal is to keep this code base small and enforce least-privledge with tight modules that also allow future additions.

  2. Security. That's the big advantage that Rust would bring to an OS (i.e., memory safety) and that current OSes are really lacking.

Short-term goals:

  1. Handle interrupts, specifically get the keyboard working. done!
  2. Threading/Multiprocessing
  • There's the beginnings of a single-core implementation, but it looks like libgreen can be slightly modified to this end
  1. Other architectures:
  • There's some beginnings of architecture-agnostic code, but it needs to be taken further

Longer-term goals:

  1. Basic drivers
  • This should include a modular and secure (least privledge) interface for adding your own drivers as well
  1. A filesystem
  2. Network stack
  3. Port rustc to RustOS
  4. That's probably it!

Current issues:

  1. Linkage probelms fixed!
  2. Threading is buggy and needs more attention and more features.
  3. The current allocator never actually frees data and is just there to get collections working.

License

Apache License, Version 2.0 or the MIT license, at your option. See LICENSE-APACHE and LICENSE-MIT for details.

Comments
  • I have a network stack

    I have a network stack

    Please excuse the frivolity of this pull request. Without a public issue tracker, this was the only way I could send you a message.

    I have written (for a class) a network stack in Rust, with the intention of adding it to an exokernel in Rust someday. You have the most actively-developed exokernel and, if the commit history is any indication, are currently adding networking support to it.

    I would need to get permission from the Professor and my assignment partner to open source it, as it is a school assignment. But other than that I could start working on integrating the two in about a month, as that is when school gets out.

    opened by Ericson2314 23
  • error while executing

    error while executing "make run"

    ➜ RustOS git:(master) make run
    cargo rustc --features rustos --target i686-unknown-linux-gnu --verbose -- -L . Compiling core v0.0.1 (file:///home/anuj/RustOS) Running rustc lib/rust/cargo/core/src/lib.rs --crate-name core --crate-type lib -g -C metadata=2839fe1be8c3a48a -C extra-filename=-2839fe1be8c3a48a --out-dir /home/anuj/RustOS/target/i686-unknown-linux-gnu/debug/deps --emit=dep-info,link --target i686-unknown-linux-gnu -L dependency=/home/anuj/RustOS/target/i686-unknown-linux-gnu/debug/deps -L dependency=/home/anuj/RustOS/target/i686-unknown-linux-gnu/debug/deps lib/rust/cargo/core/src/nonzero.rs:58:19: 58:25 error: expected identifier, found keyword unsafe lib/rust/cargo/core/src/nonzero.rs:58 pub const unsafe fn new(inner: T) -> NonZero { ^~~~~~ lib/rust/cargo/core/src/nonzero.rs:58:26: 58:28 error: expected :, found fn lib/rust/cargo/core/src/nonzero.rs:58 pub const unsafe fn new(inner: T) -> NonZero { ^~ Could not compile core.

    Caused by: Process didn't exit successfully: rustc lib/rust/cargo/core/src/lib.rs --crate-name core --crate-type lib -g -C metadata=2839fe1be8c3a48a -C extra-filename=-2839fe1be8c3a48a --out-dir /home/anuj/RustOS/target/i686-unknown-linux-gnu/debug/deps --emit=dep-info,link --target i686-unknown-linux-gnu -L dependency=/home/anuj/RustOS/target/i686-unknown-linux-gnu/debug/deps -L dependency=/home/anuj/RustOS/target/i686-unknown-linux-gnu/debug/deps (exit code: 101) make: *** [target/i686-unknown-linux-gnu/debug/libstd*.a] Error 101

    I am using rust version 1.2.0 nightly

    opened by anujfulia 10
  • OpenSuse 13.2  not running,

    OpenSuse 13.2 not running,

    make run ... ... src/libstd/rand/os.rs:38:34: 38:35 warning: unused variable: v, #[warn(unused_variables)] on by default src/libstd/rand/os.rs:38 fn fill_bytes(&mut self, v: &mut [u8]) { ^ note: link against the following native artifacts when linking against this static library note: the order and any duplication can be significant on some platforms, and so may need to be preserved note: library: c note: library: m as -march=i386 --32 -o interrupt.o src//arch/x86/interrupt.s as -march=i386 --32 -o context.o src//arch/x86/context.s as -march=i386 --32 -o dependencies.o src//arch/x86/dependencies.s ld -melf_i386 -nostdlib -o boot.bin -T src//arch/x86/link.ld boot.o target/i686-unknown-linux-gnu/debug/librustos_.a interrupt.o context.o dependencies.o ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 ld: BFD (GNU Binutils; openSUSE 13.2) 2.24.0.20140403-6.1 assertion fail ../../bfd/elf.c:4114 Makefile:31: recipe for target 'boot.bin' failed make: *_* [boot.bin] Error 1 rm morestack.o _context.o src//arch/x86/_context.s

    opened by ghost 5
  • Lazy-static.rs issue

    Lazy-static.rs issue

    Hi everyone,

    I'm new here, and just trying to compile, and it appears there's an issue with lazy-static.rs using the instructions as-is.

    Here's my log replicating this issue:

    charles@charles-desktop:~/Projects$ git clone https://github.com/ryanra/RustOS.git Cloning into 'RustOS'... remote: Counting objects: 1267, done. remote: Total 1267 (delta 0), reused 0 (delta 0), pack-reused 1267 Receiving objects: 100% (1267/1267), 647.38 KiB | 0 bytes/s, done. Resolving deltas: 100% (666/666), done. Checking connectivity... done. charles@charles-desktop:~/Projects$ cd RustOS/ charles@charles-desktop:~/Projects/RustOS$ ls bump-pointer Cargo.toml default.nix lib LICENSE-APACHE LICENSE-MIT Makefile README.md src charles@charles-desktop:~/Projects/RustOS$ git submodule update --init Submodule 'lib/lazy-static.rs' (https://github.com/ryanra/lazy-static.rs.git) registered for path 'lib/lazy-static.rs' Submodule 'lib/rlibc' (https://github.com/ryanra/rlibc.git) registered for path 'lib/rlibc' Submodule 'lib/rust' (https://github.com/ryanra/rust.git) registered for path 'lib/rust' Cloning into 'lib/lazy-static.rs'... remote: Counting objects: 228, done. remote: Total 228 (delta 0), reused 0 (delta 0), pack-reused 228 Receiving objects: 100% (228/228), 36.79 KiB | 0 bytes/s, done. Resolving deltas: 100% (108/108), done. Checking connectivity... done. Submodule path 'lib/lazy-static.rs': checked out '79112dfebb520054a9758c2e2d1dfc5a6974101b' Cloning into 'lib/rlibc'... remote: Counting objects: 102, done. remote: Total 102 (delta 0), reused 0 (delta 0), pack-reused 102 Receiving objects: 100% (102/102), 538.64 KiB | 0 bytes/s, done. Resolving deltas: 100% (39/39), done. Checking connectivity... done. Submodule path 'lib/rlibc': checked out '5187c106a4c94c35757b7a535a0798f117313003' Cloning into 'lib/rust'... remote: Counting objects: 466065, done. remote: Total 466065 (delta 0), reused 0 (delta 0), pack-reused 466065 Receiving objects: 100% (466065/466065), 284.09 MiB | 16.55 MiB/s, done. Resolving deltas: 100% (377414/377414), done. Checking connectivity... done. Submodule path 'lib/rust': checked out 'd4b1462f9085984ec7874b3eb433f926b1ed7b54' charles@charles-desktop:~/Projects/RustOS$ make run as -march=i386 --32 -o boot.o src//arch/x86/boot.s as -march=i386 --32 -o morestack.o src//morestack.s ar rcs libmorestack.a morestack.o as -march=i386 --32 -o compiler-rt.o src//dummy-compiler-rt.s ar rcs libcompiler-rt.a compiler-rt.o cc -E src//arch/x86/_context.S > src//arch/x86/_context.s as -march=i386 --32 -o _context.o src//arch/x86/_context.s ar rcs lib_context.a _context.o cargo rustc --features rustos --target i686-unknown-linux-gnu --verbose -- -L . Compiling lazy_static v0.1.11 (file:///home/charles/Projects/RustOS) Running rustc lib/lazy-static.rs/src/lib.rs --crate-name lazy_static --crate-type lib -g -C metadata=225304fa1109fb54 -C extra-filename=-225304fa1109fb54 --out-dir /home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps --emit=dep-info,link --target i686-unknown-linux-gnu -L dependency=/home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps -L dependency=/home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps Compiling core v0.0.1 (file:///home/charles/Projects/RustOS) Running rustc lib/rust/cargo/core/src/lib.rs --crate-name core --crate-type lib -g -C metadata=6032dbdcded5b6cd -C extra-filename=-6032dbdcded5b6cd --out-dir /home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps --emit=dep-info,link --target i686-unknown-linux-gnu -L dependency=/home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps -L dependency=/home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps

    lib/lazy-static.rs/src/lib.rs:1:1: 1:1 error: can't find crate for `core`
    lib/lazy-static.rs/src/lib.rs:1 /*!
                                    ^
    

    error: aborting due to previous error Build failed, waiting for other jobs to finish...

    lib/rust/cargo/core/src/ops.rs:408:5: 408:24 error: associated type defaults are unstable
    lib/rust/cargo/core/src/ops.rs:408     type Output = Self;
                                           ^~~~~~~~~~~~~~~~~~~
    

    lib/rust/cargo/core/src/ops.rs:408:5: 408:24 help: add #![feature(associated_type_defaults)] to the crate attributes to enable lib/rust/cargo/core/src/simd.rs:43:1: 46:50 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead lib/rust/cargo/core/src/simd.rs:43 pub struct i8x16(pub i8, pub i8, pub i8, pub i8, lib/rust/cargo/core/src/simd.rs:44 pub i8, pub i8, pub i8, pub i8, lib/rust/cargo/core/src/simd.rs:45 pub i8, pub i8, pub i8, pub i8, lib/rust/cargo/core/src/simd.rs:46 pub i8, pub i8, pub i8, pub i8); lib/rust/cargo/core/src/simd.rs:52:1: 53:54 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead lib/rust/cargo/core/src/simd.rs:52 pub struct i16x8(pub i16, pub i16, pub i16, pub i16, lib/rust/cargo/core/src/simd.rs:53 pub i16, pub i16, pub i16, pub i16); lib/rust/cargo/core/src/simd.rs:59:1: 59:54 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead

    lib/rust/cargo/core/src/simd.rs:59 pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    lib/rust/cargo/core/src/simd.rs:65:1: 65:36 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead

    lib/rust/cargo/core/src/simd.rs:65 pub struct i64x2(pub i64, pub i64);
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    lib/rust/cargo/core/src/simd.rs:71:1: 74:50 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead lib/rust/cargo/core/src/simd.rs:71 pub struct u8x16(pub u8, pub u8, pub u8, pub u8, lib/rust/cargo/core/src/simd.rs:72 pub u8, pub u8, pub u8, pub u8, lib/rust/cargo/core/src/simd.rs:73 pub u8, pub u8, pub u8, pub u8, lib/rust/cargo/core/src/simd.rs:74 pub u8, pub u8, pub u8, pub u8); lib/rust/cargo/core/src/simd.rs:80:1: 81:54 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead lib/rust/cargo/core/src/simd.rs:80 pub struct u16x8(pub u16, pub u16, pub u16, pub u16, lib/rust/cargo/core/src/simd.rs:81 pub u16, pub u16, pub u16, pub u16); lib/rust/cargo/core/src/simd.rs:87:1: 87:54 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead

    lib/rust/cargo/core/src/simd.rs:87 pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    lib/rust/cargo/core/src/simd.rs:93:1: 93:36 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead

    lib/rust/cargo/core/src/simd.rs:93 pub struct u64x2(pub u64, pub u64);
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    lib/rust/cargo/core/src/simd.rs:99:1: 99:54 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead

    lib/rust/cargo/core/src/simd.rs:99 pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    lib/rust/cargo/core/src/simd.rs:105:1: 105:36 warning: the #[simd] attribute is deprecated, use #[repr(simd)] instead

    lib/rust/cargo/core/src/simd.rs:105 pub struct f64x2(pub f64, pub f64);
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    error: aborting due to previous error Could not compile lazy_static.

    Caused by: Process didn't exit successfully: rustc lib/lazy-static.rs/src/lib.rs --crate-name lazy_static --crate-type lib -g -C metadata=225304fa1109fb54 -C extra-filename=-225304fa1109fb54 --out-dir /home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps --emit=dep-info,link --target i686-unknown-linux-gnu -L dependency=/home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps -L dependency=/home/charles/Projects/RustOS/target/i686-unknown-linux-gnu/debug/deps (exit code: 101) make: *** [target/i686-unknown-linux-gnu/debug/librustos*.a] Error 101 rm morestack.o _context.o src//arch/x86/_context.s

    Can anyone help me get this working?

    Thanks, Charles

    opened by ghost 4
  • How are you planning to enforce safety?

    How are you planning to enforce safety?

    Other language-based operating systems, which are based on e.g. JVM or CLR, get away with not having CPU-level user mode or memory protection by having a virtual machine, which is known to take safety precautions (including verifying safety of the user-mode executable bytecode).

    But Rust is compiled to native code. rustc invoked on RustOS will probably also just generate x86 (or whatever target architecture) code. How do you plan to distinguish between Rust-compiled, safe (I bet you plan to ban the unsafe keyword) binaries and some malicious code that one may put together using assembly or C or whatever and put on a RustOS machine?

    Or are you planning to take some form of bytecode and compile upon exec() (or equivalent)?

    opened by kFYatek 3
  • make error

    make error

    when I $make iso, there is a compile error. my rustc version is too new?

    error message

    rust/src/libcore/macros.rs:128:9: 128:27 error: macro undefined: 'format_args_method!' rust/src/libcore/macros.rs:128 format_args_method!($dst, write_fmt, $($arg)*)

    opened by zhurx4g 2
Owner
null
RCore-Tutorial-v3 - Let's write an OS which can run on RISC-V in Rust from zero!

rCore-Tutorial-v3 rCore-Tutorial version 3.5. See the Documentation in Chinese. Official QQ group number: 735045051 news 2021.11.20: Now we are updati

rCore OS 786 Jan 2, 2023
Let's write an OS which can run on ARM in Rust from scratch

rCore-Tutorial-v3 rCore-Tutorial version 3.5. See the Documentation in Chinese. news 2021.11.20: Now we are updating our labs. Please checkout chX-dev

rCore OS 10 Dec 17, 2022
Let's write an OS which can run on x86_64 in Rust from scratch

rCore-Tutorial-v3 rCore-Tutorial version 3.5. See the Documentation in Chinese. news 2021.11.20: Now we are updating our labs. Please checkout chX-dev

rCore OS 6 Apr 1, 2022
A library that makes it VERY easy to run Holochain as a library, from your own binary, with great defaults

embedded-holochain-runner A library that makes it VERY easy to run Holochain as a library, from your own binary, with great defaults How it will work

Sprillow 14 Jul 23, 2022
Distrod is a meta-distro for WSL 2 which runs Systemd as init process. You can run Ubuntu, Arch, and et.c with systemd in a minute. Distrod also has built-in auto-start feature on Windows startup and port forwarding abiltiy.

Distrod - WSL2 Distros with Systemd! Distrod is a systemd-based meta-distro for WSL2 that allows you to install Ubuntu, Arch Linux, Gentoo and many ot

Takaya Saeki 1.6k Jan 9, 2023
A lightweight microkernel/IPC based operating system built with Rust which is not a clone of any existing operating system

Noble Operating System Noble is a lightweight microkernel and IPC based operating system built with Rust which is not a clone of any existing operatin

Revolution Xenon 3 Jan 10, 2022
This project is based on code from freertos.rs and some additions to simplify the usage of FreeRTOS in embedded applications written in Rust

FreeRTOS-rust This project is based on code from freertos.rs and some additions to simplify the usage of FreeRTOS in embedded applications written in

Lobaro 196 Jan 4, 2023
A Rust-based userland which also adds compile-time assurances to seL4 development.

ferros Overview A Rust library to add extra assurances to seL4 development. ferros provides smart type-safe wrappers around seL4 features with an emph

Auxon Corporation 68 Dec 25, 2022
Aero is a new modern, unix based operating system. It is being developed for educational purposes.

Areo Aero is a new modern, unix based operating system written in Rust and is being developed for educational purposes. Aero follows the monolithic ke

Anhad Singh 623 Dec 24, 2022
suidsnoop is a tool based on eBPF LSM programs that logs whenever a suid binary is executed and implements custom allow/deny lists.

suidsnoop Log suid binaries and enforce per-uid suid policy. suidsnoop is a tool for logging whenever a suid binary is executed on your system and opt

William Findlay 11 Dec 22, 2022
A fresh FRAME-based Substrate node, ready for hacking

Substrate Node Template A fresh FRAME-based Substrate node, ready for hacking ?? Getting Started Follow the steps below to get started with the Node T

Worlddev5007 13 Aug 26, 2022
A comparison of operating systems written in Rust

Rust OS comparison A comparison of operating systems written in Rust. There are several open source operating systems written in Rust. Most of them ar

Markus Kohlhase 492 Jan 8, 2023
An OS kernel written in rust. Non POSIX

"Tifflin" Experimental Kernel (and eventually Operating System) This is an experiment in writing an OS Kernel in rust (http://rust-lang.org). Mostly t

John Hodge (Mutabah) 618 Jan 8, 2023
A hobby operating system, in Rust

intermezzOS: kernel intermezzOS is a hobby operating system. This repository is for its kernel. See the website for more. License This project is dual

intermezzOS 1.3k Jan 1, 2023
A Rust version of the Weenix OS

Reenix This is the start of a unix like operating system written in Rust. It is based on the Weenix Operating system written for Brown's CS167/9. At t

Alex Light 311 Dec 22, 2022
A tiny 32 bit kernel written in Rust

rustboot A tiny 32 bit kernel written in Rust. I was inspired to download Rust and try to do this after seeing zero.rs - a stub that lets Rust program

Charlie Somerville 1.5k Dec 30, 2022
Experimental kernel for embedded devices written in Rust

bkernel is an experimental kernel for embedded devices written in Rust. I'm mostly trying out Rust now to see how it applies to kernel development. Pr

Alexey Shmalko 84 Dec 13, 2022
Open Source Rust kernel; Runs WASM and WASI as lightweight containers.

?? etheryal Kernel etheryal kernel is an Open Source capability-based Kernel written in the Rust programming language. The kernel allows implementing

null 32 Dec 4, 2022
Basic Rust kernel using Limine

Rust Limine Barebones This is a small kernel that boots using Limine. Build First of all, download Rust ! (I guess you already did it if you are here

Quentincestino 16 Dec 23, 2022