Skip to content

multiboot2-header: construct header at build time [call for contribution] #198

@phip1611

Description

@phip1611
Member

It would be awesome to construct multiboot2-headers at runtime with macros.

For reference: That's how you write a header in assembly language: https://github.com/rust-osdev/multiboot2/blob/main/integration-test/bins/multiboot2_payload/src/multiboot2_header.S

Activity

self-assigned this
on Dec 16, 2023
removed their assignment
on Jan 19, 2024
an-owl

an-owl commented on May 1, 2024

@an-owl

I wrote a macro for my own project here feel free to use it. There are examples in the tests module and documentation in lib.rs. It does have a couple of quirks and issues, some that can be fixed easily and one which is a huge pain to deal with.

  • This resolves types names by trimming the last ident from the path to the constructor so constructing a tag using TagName{fields} will not work, you must use TagName::new(args)
  • Tags should have #[repr(align(8))], currently some tags need to be padded manually, which is a bit of a pain because of how the macro resolves type names.
  • Multiboot2BasicHeader doesn't have a public constructor, probably because of the size argument so the macro must define it's own.
  • Pointers cannot be cast to integers at compile time. rustc managed to foil all of my attempts to get a truncated pointer. There are ways to work around this, firstly store pointers using *const () on 32bit targets. 64bit targets are kinda SOL for this method, the way I'm working around this is just specifying addresses in in a linker script and giving the same address to tag constructors. I did notice that you can get a truncated pointer using inline asm but I'm pretty sure that exploiting this requires writing the entire header in an asm block.

I did also consider adding a "native" argument for the architecture to get the macro to resolve the arch itself, but with the huge selection of i386 or MIPS I think the user can handle this themselves.

phip1611

phip1611 commented on May 1, 2024

@phip1611
MemberAuthor

Thanks @an-owl - that's awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @phip1611@an-owl

        Issue actions

          multiboot2-header: construct header at build time [call for contribution] · Issue #198 · rust-osdev/multiboot2