Rust crate for parsing stivale and stivale 2 structures.

Overview

stivale-rs

workflow crates.io crates.io docs.rs

Rust crate for parsing stivale and stivale 2 structures.

Resources

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Comments
  • Add `stivale2_struct_tag_boot_volume` tag

    Add `stivale2_struct_tag_boot_volume` tag

    Fixes #10

    Here you go! This seemed like an important feature, especially for my hobby OS, which needs to basically fetch the entire rest of itself from the disk after two seconds; not knowing where that is would make it very difficult 🙃.

    This PR also pulls in the uuid crate. While this feature doesn't exactly require it to exist, it does provide an Into implementation for convenience.

    opened by rdrpenguin04 4
  • Putting StivalHeader in sub-module breaks protocol

    Putting StivalHeader in sub-module breaks protocol

    The problem

    I'm getting the following error message if I run qemu-system-x86_64 -m 4G my_os.iso:

    image

    Expected behaviour

    If I have the following code in my main.rs:

    #![no_std]
    #![no_main]
    
    use os::println;
    use stivale_boot::v2::{StivaleAnyVideoTag, StivaleHeader};
    
    pub const OS_STACK_SIZE: usize = 8_192;
    pub static OS_STACK: [u8; OS_STACK_SIZE] = [0; OS_STACK_SIZE];
    
    #[no_mangle]
    pub extern "C" fn os_entry() -> ! {
        println!("Starting OS...");
        loop {}
    }
    
    #[used]
    #[no_mangle]
    #[link_section = ".stivale2hdr"]
    pub static STIVALE_HEADER: StivaleHeader = StivaleHeader::new()
        .stack(unsafe { OS_STACK.as_ptr().offset(OS_STACK_SIZE as isize) })
        .flags(0b11110)
        .tags(&ANY_VIDEO_HEADER_TAG as *const StivaleAnyVideoTag as *const ());
    
    pub static ANY_VIDEO_HEADER_TAG: StivaleAnyVideoTag = StivaleAnyVideoTag::new().preference(1);
    

    then it's working and I'm getting:

    image

    Reproduction steps

    Do cargo new os first.

    You just have to copy+paste the following into the src directory:

    target.json

    {
        "llvm-target": "x86_64-unknown-none",
        "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
        "arch": "x86_64",
        "target-endian": "little",
        "target-pointer-width": "64",
        "target-c-int-width": "32",
        "os": "none",
        "executables": true,
        "linker-flavor": "ld.lld",
        "linker": "rust-lld",
        "panic-strategy": "abort",
        "disable-redzone": true,
        "features": "-mmx,-sse,+soft-float",
        "pre-link-args": {
            "ld.lld": [
                "-Tlinker.ld"
            ]
        }
    }
    

    linker.ld

    OUTPUT_FORMAT(elf64-x86-64)
    OUTPUT_ARCH(i386:x86-64)
    ENTRY(pornos_entry)
    
    PHDRS {
        null    PT_NULL    FLAGS(0) ;                   /* Null segment */
        text    PT_LOAD    FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
        rodata  PT_LOAD    FLAGS((1 << 2)) ;            /* Read only */
        data    PT_LOAD    FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
    }
     
    SECTIONS {
        . = 0xffffffff80000000;
    
        .text : {
            *(.text .text.*)
        } :text
    
        . += CONSTANT(MAXPAGESIZE);
    
        .stivale2hdr : {
            KEEP(*(.stivale2hdr))
        } :rodata
    
        .rodata : {
            *(.rodata .rodata.*)
        } :rodata
    
        . += CONSTANT(MAXPAGESIZE);
    
        .data : {
            *(.data .data.*)
        } :data
    
        .bss : {
            *(COMMON)
            *(.bss .bss.*)
        } :data
    }
    

    main.rs:

    #![no_std]
    #![no_main]
    
    use stivale_boot::v2::{StivaleAnyVideoTag, StivaleHeader};
    
    #[no_mangle]
    pub extern "C" fn os_entry() -> ! {
        loop {}
    }
    

    lib.rs:

    pub mod stivale;
    

    stivale/mod.rs (do mkdir -p stivale before)

    use stivale_boot::v2::{StivaleAnyVideoTag, StivaleHeader};
    
    pub const OS_STACK_SIZE: usize = 8_192;
    pub static OS_STACK: [u8; OS_STACK_SIZE] = [0; OS_STACK_SIZE];
    
    #[used]
    #[no_mangle]
    #[link_section = ".stivale2hdr"]
    pub static STIVALE_HEADER: StivaleHeader = StivaleHeader::new()
        .stack(unsafe { OS_STACK.as_ptr().offset(OS_STACK_SIZE as isize) })
        .flags(0b11110)
        .tags(&ANY_VIDEO_HEADER_TAG as *const StivaleAnyVideoTag as *const ());
    
    pub static ANY_VIDEO_HEADER_TAG: StivaleAnyVideoTag = StivaleAnyVideoTag::new().preference(1);
    

    .cargo/config.toml (do mkdir .cargo before)

    [build]
    target = "target.json"
    
    [unstable]
    build-std = ["core", "compiler_builtins"]
    build-std-features = ["compiler-builtins-mem"]
    

    <limine.cfg>

    # Timeout in seconds that Limine will use before automatically booting.
    TIMEOUT=5
     
    # The entry name that will be displayed in the boot menu
    :CustomOS
     
    # Change the protocol line depending on the used protocol.
    PROTOCOL=stivale2
     
    # Path to the kernel to boot. boot:/// represents the partition on which limine.cfg is located.
    KERNEL_PATH=boot:///os
    

    Also execute the following:

    cargo +nightly build -Zbuild-std
    cargo +nightly build
    
    git clone https://github.com/limine-bootloader/limine.git --branch=v2.0-branch-binary --depth=1
    mkdir isodir
    make -C limine
    
    cp -v target/target/debug/os limine.cfg limine/limine.sys limine/limine-cd.bin limine/limine-eltorito-efi.bin isodir/
    
    xorriso -as mkisofs -b limine-cd.bin \
            -no-emul-boot -boot-load-size 4 -boot-info-table \
            --efi-boot limine-eltorito-efi.bin \
            -efi-boot-part --efi-boot-image --protective-msdos-label \
            isodir/ -o os.iso
    

    Afterwards, start qemu with: qemu-system-x86_64 -m 4G os.iso and select the CustomOS entry. Afterwards the given error message should appear.

    opened by TornaxO7 3
  • Use dynamically sized slices to prevent UB from reading an array out of bounds

    Use dynamically sized slices to prevent UB from reading an array out of bounds

    This is a breaking change due to changing the type of publicly accessible fields. Bumps version to 0.3.0

    Using a [T; 0] to access more than 0 elements (that is, to access any data) at that location is undefined behavior. This PR moves to a dynamically sized slice approach to not cause undefined behavior in that way and better mirrors the exact data layout of the data being accessed.

    opened by asquared31415 3
  • Allow mutating `StivaleSmpInfo`

    Allow mutating `StivaleSmpInfo`

    The StivaleSmpInfo can be written to allow for example setting the AP stack and instruction pointer. the struct itself is writable but the only way to access it trough StivaleSmpTag which doesn't provide any API to get a mutable reference (one could possibly build a mutable slice directly from smp_info_array). It would also be needed for StivaleStruct to return a StivaleSmpTag that allowed mutation trough smp (It's possible using get_tag and some casts but it would be nicer to have an API for it).

    I would be available to implement just wanted to get your opinion on how the API should look.

    opened by JCapucho 3
  • Missing `stivale2_struct_tag_boot_volume`

    Missing `stivale2_struct_tag_boot_volume`

    Hello!

    You don't currently have an analog for stivale2_struct_tag_boot_volume. If you'd like, I can implement that; just wanted to make an issue so I don't forget.

    opened by rdrpenguin04 1
  • Allow mutating the SMP info tag

    Allow mutating the SMP info tag

    Allows getting a mutable reference to StivaleSmpTag and mutating the StivaleSmpInfo structs, this can be used to start the application processors.

    Closes #4

    opened by JCapucho 1
  • stivale2: Add the any video header tag

    stivale2: Add the any video header tag

    Implements the any video header tag for stivale2, also improves make_header_tag to allow for attributes (and by extension doc comments) for the generated setters.

    Documentation: https://github.com/stivale/stivale/blob/master/STIVALE2.md#any-video-header-tag

    opened by JCapucho 1
  • Rewrite the crate

    Rewrite the crate

    Rewrite the crate into an easier to work with interface. I already have added the stivale2 structure and ability to retrieve tags inside of it by their ID. I also added few helper methods to retrieve a specific tag with correct type. I still need to add all the missing tags that are specified in the stivale2 specification and document the code, since as of now it's left with no comments whatsoever. There is also the stivale2 header structure and few header tags that let you specify a simple terminal output so you can verify everything is working correctly.

    opened by czapek1337 1
  • StivaleTerminalTag::write is unsound

    StivaleTerminalTag::write is unsound

    https://github.com/Andy-Python-Programmer/stivale/blob/master/src/v2/tag.rs#L88 indicates a safety comment of

    This function is not thread safe

    but it's applied to a safe by-shared-reference reciever method of a Sync type, making this unsound.

    opened by chorman0773 1
  • Update crate to support latest Stivale2 features

    Update crate to support latest Stivale2 features

    From what I can tell this is missing (at least) the terminal callback function, at least in the public API, as well as the slide HHDM header tag. At present I think that that's all its missing but it might be missing more.

    opened by ethindp 0
Owner
Anhad Singh
13 year old programmer and free software enthusiast
Anhad Singh
A library for parsing and generating ESP-IDF partition tables

esp-idf-part A library for parsing and generating ESP-IDF partition tables. Supports parsing from and generating to both CSV and binary formats. This

esp-rs 5 Nov 16, 2022
Rust implementation for parsing StarCraft .chk files.

bwmap Rust implementation for parsing StarCraft .chk files. bounding.net uses this library to parse StarCraft and StarCraft: Brood War maps and store

null 8 Dec 19, 2022
A library for creating/parsing Serenity slash commands.

Serenity Commands A library for creating/parsing Serenity slash commands. Usage See the examples directory for more examples. use serenity::all::{

Vidhan Bhatt 4 Dec 9, 2023
A Rust proc-macro crate which derives functions to compile and parse back enums and structs to and from a bytecode representation

Bytecode A simple way to derive bytecode for you Enums and Structs. What is this This is a crate that provides a proc macro which will derive bytecode

null 4 Sep 3, 2022
Rust crate to generate, manipulate and traverse trees.

SOCAREL Rust crate to generate, manipulate and traverse trees. It provides iterators for eight different traversal algorithms. Add and remove nodes in

Andreu 8 Nov 14, 2021
A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use.

rs-cord A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use. Documentation • Crates.io • Discord Navigation M

Jay3332 4 Sep 24, 2022
A simple entity-component-system crate for rust with serialization support

Gallium A simple entity-component-system crate for rust with serialization support Usage You can include the library using carge: [dependencies] galli

null 7 Aug 31, 2021
Jonathan Kelley 33 Dec 6, 2022
A translation of Brendan Galea's Vulkan tutorial into Rust using the ash crate

Rust Light Vulkan Engine This is a translation of Brendan Galea's Vulkan tutorial into rust using the Ash crate. Original tutorial: Brendan Galea's Yo

Mot 6 Dec 25, 2022
Community SVD file, peripheral access crate in embedde Rust for WinnerMicro W800, W801 & W806 chip

Community SVD file, peripheral access crate in embedde Rust for WinnerMicro W800, W801 & W806 chip

Luo Jia 37 Jul 31, 2022
This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

kaiuri 1 Feb 11, 2022
An `abilists` parser crate for Rust

An `abilists` parser crate for Rust

Erich Gubler 24 Aug 28, 2022
Chains - a bot written in Rust using the serenity crate

Chains (Rusty) Chains is a bot written in Rust using the serenity crate. Chains primarily focuses on easy to set up, easy to use moderation tools such

Quin 3 Mar 28, 2022
A Rust crate to expressively declare bitfield-like structs

proc-bitfield A Rust crate to expressively declare bitfield-like structs, automatically ensuring their correctness at compile time and declaring acces

null 36 Dec 3, 2022
This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you specified.

prae This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you spec

null 96 Dec 4, 2022
This crate defines a single macro that is a brainfunct compile-time interpreter.

Compile Protection This crate defines a single macro that is a brainfunct compile-time interpreter. One example is as follows #![recursion_limit = "18

John Marsden 7 Nov 29, 2021
secmem-proc is a crate designed to harden a process against low-privileged attackers running on the same system trying to obtain secret memory contents of the current process.

secmem-proc is a crate designed to harden a process against low-privileged attackers running on the same system trying to obtain secret memory contents of the current process. More specifically, the crate disables core dumps and tries to disable tracing on unix-like OSes.

null 3 Dec 19, 2022
Example of structuring a proc macro crate for testability

testing-proc-macros Example of structuring a proc macro crate for testability. See accompanying blog post for details. License Licensed under either o

Ferrous Systems 12 Dec 11, 2022
🥳Yet another crate to create native nodejs addons :)

nodex Yet another crate to create native nodejs addons :) This crate aims to make creating native nodejs addons very easy and comfortable. It is in a

uuhan 4 Mar 29, 2022