https://github.com/o8vm/octox Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Customer Stories + White papers, Ebooks, Webinars + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. {{ message }} o8vm / octox Public * Notifications * Fork 7 * Star 162 xv6-riscv like OS written in Rust 162 stars 7 forks Activity Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights o8vm/octox This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/o] Use Git or checkout with SVN using the web URL. [gh repo clone o8vm/o] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @o8vm o8vm Initial Commit ... a4c755a Jul 25, 2023 Initial Commit a4c755a Git stats * 1 commit Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .cargo Initial Commit July 25, 2023 20:27 src Initial Commit July 25, 2023 20:27 .gitignore Initial Commit July 25, 2023 20:27 .projectile Initial Commit July 25, 2023 20:27 Cargo.toml Initial Commit July 25, 2023 20:27 README.org Initial Commit July 25, 2023 20:27 build.rs Initial Commit July 25, 2023 20:27 rust-toolchain.toml Initial Commit July 25, 2023 20:27 View code [ ] octox Getting Started Requirements Build and Run Play with the Shell Development Userland Application Kernel License Acknowledgments Contribution README.org octox octox is a Unix-like operating system inspired by xv6-riscv. octox loosely follows the structure and style of xv6, but is implemented in pure Rust. https://vhs.charm.sh/vhs-6MQBIyAo3DpBrARBxHxL35.gif * Everything from kernel, userland, mkfs, to build system is written in safe Rust as much as possible. * There are no dependencies on external crates. * The userland has a library similar to Rust's std with K&R malloc. * Multi-core support, buddy allocator as kernel-side memory allocator, file system with logging support, etc. Getting Started Requirements * Install the rust toolchain to have cargo installed by following this guide. * Install qemu-system-riscv * (option) Install gdb-multiarch Build and Run * Clone this project & enter: git clone ... && cd octox * Build: cargo build --target riscv64gc-unknown-none-elf. * Run: cargo run --target riscv64gc-unknown-none-elf, then qemu will boot octox. To exit, press Ctrl+a and x. Play with the Shell A very simple shell is implemented. In addition to executing commands, you can only do the following things. * Pipe: cat file | head | grep test * Dump processes: Ctrl + P * End of line: Ctrl + D * Redirect output: >, >> Development Userland Application The userland comes with a user library called ulib that is similar to Rust's std, so you can use it to develop your favorite commands. If you create a bin crate named _command in src/user, the build.rs and mkfs.rs will place a file named command in the file system and make it available for use. * In src/user/Cargo.toml, define a bin crate with the name of the command you want to create with a _ prefix [[bin]] name = "_rm" path = "rm.rs" * userland is also no_std, so don't forget to add #[no_std]. Use ulib to develop any command you like. Here is an example of the rm command. #![no_std] use ulib::{env, fs}; fn main() { let mut args = env::args().skip(1).peekable(); if args.peek().is_none() { panic!("Usage: rm files...") } for arg in args { fs::remove_file(arg).unwrap() } } * Then, cargo run --target riscv64gc-unknown-none-elf in the root of octox. * To use Vec and String, etc, do the following: extern crate alloc; use alloc::{string::String, vec::Vec}; Kernel Developing in src/kernel. Here is an example of adding a system call. If you want to add a new system call, you only need to add a definition to the system call table in libkernel, and the userland library will be automatically generated by build.rs. * Add a variant and Syscall Number to enum SysCalls in src/kernel/ syscall.rs. Here is Dup2 as an example: pub enum SysCalls { Fork = 1, ..., Dup2 = 23, Invalid = 0, } * Define the function signature of the system call in the TABLE of SysCalls. Use the enum type Fn to describe the return type(U (Unit), I (Integer), N (never)) and use &str to represent arguments. then, define kernel-side implementation as a method on SysCalls. cfg flag is used to control the compilation target for kernel and the rest. Here is an example of dup2: impl SysCalls { pub const TABLE: [(fn, &'static str); variant_count::()] = [ (Fn::N(Self::Invalid), ""), (Fn::I(Self::fork), "()"), (Fn::N(Self::exit), "(xstatus: i32)"), ..., (Fn::I(Self::dup2), "(src: usize, dst: usize)"), ]; pub fn dup2() -> Result { #[cfg(not(all(target_os = "none", feature = "kernel")))] return Ok(0); #[cfg(all(target_os = "none", feature = "kernel"))] { let p = Cpus::myproc().unwrap().data_mut(); let src_fd = argraw(0); let dst_fd = argraw(1); if src_fd != dst_fd { let mut src = p.ofile.get_mut(src_fd).unwrap() .take().unwrap(); src.clear_cloexec(); p.ofile.get_mut(dst_fd) .ok_or(FileDescriptorTooLarge)?.replace(src); } Ok(dst_fd) } } * With just these steps, the dup2 system call is implemented in both kernel and userland. License Licensed under either of * Apache License, Version 2.0 * MIT license at your option. Acknowledgments octox is inspired by xv6-riscv. I'm also grateful for the bug reports and discussion about the implementation contributed by Takahiro Itazuri and Kuniyuki Iwashima. Contribution This is a learning project for me, and I will not be accepting pull requests until I consider the implementation complete. However, discussions and advice are welcome. About xv6-riscv like OS written in Rust Topics rust osdev riscv xv6-riscv Resources Readme Activity Stars 162 stars Watchers 8 watching Forks 7 forks Report repository Releases No releases published Packages 0 No packages published Languages * Rust 100.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.