Skip to content

BSZKaneki/Basic_os

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚙️ Basic_os: A Minimal Rust Operating System Kernel

GitHub stars GitHub forks GitHub issues GitHub license

A foundational operating system kernel, meticulously crafted from the ground up using Rust.

📖 Overview

Basic_os is an experimental and educational project focused on building a minimal operating system kernel using the Rust programming language. It leverages Rust's powerful safety guarantees and low-level capabilities to create a robust and reliable foundation for an OS.

This project serves as an excellent starting point for anyone interested in bare-metal programming, understanding the internals of an operating system, or exploring Rust's potential beyond application development. It focuses on the essential components required to boot a custom kernel and interact directly with hardware.

✨ Features

  • Bare-metal Rust Development: Core kernel logic written entirely in Rust, interacting directly with hardware without an underlying OS.
  • Custom Target Configuration: Utilizes a custom target specification (rust_os.json) for precise control over the compilation environment, essential for OS development.
  • Cargo-managed Project: Leverages Cargo for robust dependency management, building, and testing of the kernel.
  • Minimalist Design: Aims for a lean and efficient kernel, focusing on fundamental OS primitives.
  • Modular Structure: Organized codebase to facilitate understanding and expansion of OS components.

🛠️ Tech Stack

Core Language: Rust

Build System & Tooling: Cargo Rustup

OS Development Tools (External): QEMU

🚀 Quick Start

To get Basic_os up and running in an emulated environment, follow these steps.

Prerequisites

Ensure you have the following installed on your system:

  • Rust Toolchain: Install rustup to manage Rust versions.
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Specific Rust Toolchain: This project requires a specific Rust toolchain version and components as defined in rust-toolchain.toml. Install it:
    rustup override set $(cat rust-toolchain.toml | grep -o 'channel = "[^"]*"' | cut -d'"' -f2)
    rustup target add x86_64-unknown-none # Add the bare-metal target for building
  • cargo-binutils: Essential for working with custom targets and generating bootable images.
    cargo install cargo-binutils
    rustup component add llvm-tools-preview
  • QEMU: A generic and open-source machine emulator and virtualizer, used to run the compiled OS kernel.
    # On Debian/Ubuntu
    sudo apt install qemu-system-x86
    
    # On Fedora
    sudo dnf install qemu-system-x86
    
    # On macOS with Homebrew
    brew install qemu

Installation

  1. Clone the repository

    git clone https://github.com/BSZKaneki/Basic_os.git
    cd Basic_os
  2. Add custom target specification The project uses a custom target named rust_os.json. You need to tell Cargo about this target.

    rustup target add --json rust_os.json

    Note: This command is a placeholder; typically, you'd place the rust_os.json file in a .cargo/config.toml defined build path, or a tool like bootloader handles this automatically.

  3. Build the kernel Compile the kernel for the custom rust_os target.

    cargo build --target rust_os.json

    This command will generate the kernel executable in target/rust_os/debug/basic_os. For a release build:

    cargo build --release --target rust_os.json
  4. Create a bootable image This step typically involves using bootimage (a common Rust OS dev crate) or cargo-binutils to link the kernel with a bootloader. Assuming the project is set up to use bootimage implicitly (as is common for Basic_os-style projects):

    cargo bootimage --target rust_os.json

    If bootimage is not integrated, you might need manual steps involving objcopy from cargo-binutils:

    # Example using cargo-objcopy, actual command might vary based on bootloader
    cargo objcopy -- -O binary target/rust_os/debug/basic_os target/basic_os.bin

    This will produce a bootable image (e.g., bootimage-basic_os.bin) in your target/rust_os/debug or target/x86_64-rust_os/debug directory.

  5. Run in QEMU Execute the bootable image using QEMU:

    qemu-system-x86_64 -drive format=raw,file=target/rust_os/debug/bootimage-basic_os # Or wherever the bootimage is located

    This will launch a QEMU window, where you should see the output from your kernel.

📁 Project Structure

Basic_os/
├── .cargo/             # Cargo configuration directory
├── .gitignore          # Git ignore file
├── Cargo.lock          # Locked dependencies for Cargo
├── Cargo.toml          # Project manifest and dependencies
├── rust-toolchain.toml # Specifies the Rust toolchain version
├── rust_os.json        # Custom target specification for the OS
├── src/                # Kernel source code
│   └── main.rs         # Main entry point of the kernel
└── tests/              # Integration and unit tests
    └── ...             # Test files

🔧 Development

Building

To build the kernel for development:

cargo build --target rust_os.json

For an optimized release build:

cargo build --release --target rust_os.json

Running in Emulator

After building, run the generated bootable image with QEMU:

qemu-system-x86_64 -drive format=raw,file=target/rust_os/debug/bootimage-basic_os

Replace target/rust_os/debug/bootimage-basic_os with the actual path to your bootable image.

🧪 Testing

This project includes tests to ensure the correctness of kernel components.

# Run all tests
cargo test

Note: Due to the nature of OS development, many kernel tests might require specific execution environments or custom test runners not directly invoked by cargo test. The tests/ directory likely contains integration tests or specific unit tests that can run in a hosted environment.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages