18 ms·
> They're not using C or Rust either, they're writing some kind of machine-specific stub, probably in that machine's assembly language. But that's what's so in
by tialaramex 5y ago
> They're not using C or Rust either, they're writing some kind of machine-specific stub, probably in that machine's assembly language.
But that's what's so interesting at the bottom of the rabbit hole.
Unlike the languages you've mentioned, the ones used at the bottom of the rabbithole, such as C and Rust, actually provide a mechanism to do exactly that sort of bit-banging.
let x: u64;
unsafe {
asm!("mov {}, 5", out(reg) x);
}
Isn't that nice? All the surrounding code that isn't doing bit-banging still interoperates with this just fine, so you can do your bit-banging to talk to a memory controller and then... return a freshly allocated chunk of RAM to the rest of the high level code which has whizzy generic types and whatever.
Because of Rust's safety rules we're obliged to explicitly flag that we know the compiler can't check our work. If this was serious work, we'd want to provide a comment for humans explaining why this is both necessary and safe, but in this toy example the answer is "No reason at all" so that's redundant.
In C, partly due to lack of name spacing, the mechanism is compiler-specific (of course today Rust is effectively wedded to LLVM so for now this is a difference without practical distinction). And there's no safety oversight, you're no more or less at risk when trying to make yet another linked list than when bit-banging. But otherwise it's very similar.
- lmm 5y ago> Isn't that nice? All the surrounding code that isn't doing bit-banging still interoperates with this just fine, so you can do your bit-banging to talk to a memory controller and then... return a freshly allocated chunk of RAM to the rest of the high level code which has whizzy generic types and whatever. It's fine, but it's such a tiny fraction of what matters when producing a product that I wouldn't base my language choice on how good the language's support for that kind of thing is. I don't know exactly how e.g. Singularity or MirageOS do their bit-banging - for all I know they might even use a little bit of C or Rust to bridge the gap - but that bit-banging is such a miniscule proportion of what's important to an OS implementation (much less to an actual product built on that OS) that it shouldn't move the needle on language choice. I've never seen anyone put a genuine effort into running general-purpose language x on bare-metal hardware y and have it fail - it's always "we've tried nothing and we're all out of ideas".