Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phip1611 opened this issue Dec 16, 2023 · 2 comments
Open

Comments

@phip1611
Copy link
Collaborator

phip1611 commented Dec 16, 2023

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

@phip1611 phip1611 self-assigned this Dec 16, 2023
@phip1611 phip1611 removed their assignment Jan 19, 2024
@an-owl
Copy link

an-owl commented May 1, 2024

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
Copy link
Collaborator Author

phip1611 commented May 1, 2024

Thanks @an-owl - that's awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants