Skip to content

Instantly share code, notes, and snippets.

View perlun's full-sized avatar

Per Lundberg perlun

View GitHub Profile
@perlun
perlun / gist:ce77212a330765ed746a
Last active September 20, 2016 09:59 — forked from Tobba/gist:5720dc8ee4d32606062c
Baremetal Rust

What you need to write low level Rust code

  • Avoid cargo, it it may seem tempting, but you'll just keep running into untested code paths and design flaws; it's not meant to do it.
  • Using a target specification to describe your platform is recommended, and you'll likely need one for one reason or another anyways (example: https://github.com/hackndev/zinc/blob/master/thumbv6-none-eabi.json ). Pass it to rustc via --target=target.json
  • You wan work without the standard library, by following those instructions: https://doc.rust-lang.org/book/no-stdlib.html
  • Inline assembly (asm!) blocks are fed directly into LLVM and have horrible error checking, tread lightly and verify the output.
  • LLVM can end up generating dodgy versions of certain instructions on certain versions, it may for example turn "lgdt" into the utterly useless 16-bit version (which truncates the upper 8 bits of the address). Specify operand sizes.
  • An "intel" option is supported, but it seems to be somewhat dodgy (for example, it seemed to d