os_metal_primitives 0.1.0

Dependency-free bare-metal primitives for Rust OS development: typed MMIO, registers, bitfields, port I/O, IRQ tables, and driver state patterns.
Documentation
  • Coverage
  • 100%
    92 out of 92 items documented7 out of 68 items with examples
  • Size
  • Source code size: 78.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • alisio85/os_metal_primitives
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • alisio85

os_metal_primitives

os_metal_primitives is a dependency-free, no_std-first crate that provides small, strongly typed building blocks for bare-metal / OS kernel development in Rust (edition 2024).

This crate focuses on low-level primitives you can reuse across kernels and architectures:

  • Typed MMIO registers with volatile reads/writes (mmio::MmioCell)
  • Bitfield helpers and a compact declarative macro (os_metal_primitives::bitfield!)
  • Register access modes (RO/WO/RW) and a register block helper macro (os_metal_primitives::define_register_block!)
  • Port I/O wrapper types (port_io::{Port8, Port16, Port32}) via an architecture-provided trait
  • IRQ types and a fixed-size, allocation-free dispatch table (irq::IrqTable)
  • Driver state helpers for explicit driver lifecycles (driver_state::DriverState)

Relationship with your other crates

This crate is intentionally independent and does not depend on:

  • os_kernel_foundry (kernel architecture & boot orchestration)
  • os_dev_toolkit (logging, diagnostics, fixed buffers, etc.)

Instead, it complements them by handling different concerns: typed hardware register access, bit manipulation primitives, and small kernel-friendly patterns.

Quick example: MMIO + bitfields

use os_metal_primitives::mmio::MmioCell;

os_metal_primitives::bitfield! {
    /// A tiny control register.
    pub struct Ctrl(u32) {
        /// Enable bit.
        pub const EN: 0,
        /// 3-bit mode field.
        pub field MODE: 8..=10,
    }
}

#[repr(C)]
pub struct DevRegs {
    pub ctrl: MmioCell<u32>,
}

fn enable_and_set_mode(regs: &DevRegs, mode: u32) {
    regs.ctrl.update(|raw| {
        let c = Ctrl::from_bits(raw)
            .with(Ctrl::EN)
            .set(Ctrl::MODE, mode);
        c.bits()
    });
}

Documentation

  • API docs: build locally with cargo doc --open
  • Project docs: see the docs/ directory, starting from docs/MANUAL.md

License

MIT. See LICENSE.

Attribution

This crate was created by an AI assistant based on an idea and requirements by alisio85.