-
-
Save Tobba/5720dc8ee4d32606062c to your computer and use it in GitHub Desktop.
Baremetal Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 do handle label operands MASM style but didn't support any "offset of" syntax known to man last I checked). | |
* Use LTO to trim out unused references to libraries like libm (which can be generated by the compiler). | |
* librlibc provides reasonable baseline implementations of necessary libc functions such as memcpy and memmove. | |
* You can use a semi-undocumented environment variable RUST_TARGET_PATH to avoid specifying absolute paths to --target. | |
* To get an .o file without the compiler whining about entry points, use: --crate-type staticlib --emit obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This file was unfortunately very hard to read because it is Markdown saved as a
.txt
file, with very long lines, forcing you to scroll all the time.I forked the gist and changed the filename to
.md
in my file which makes the gist a lot easier to read: https://gist.github.com/perlun/ce77212a330765ed746a