<re_irc>
<reitermarkus> Did anyone encounter something like this before? Compilation failure with undefined reference to "rust_begin_unwind" depends on the order or type of the "panic_*" crate's import.
<re_irc>
<allexoll> seems you have given people ideas with defmt!
<re_irc>
<James Munns> All credit to Japaric for coming up with the idea :)
explore has quit [Quit: Connection closed for inactivity]
<re_irc>
<heksa> Hey we were recently dynamically constructing a RISC-V interrupt vector table in Rust, which we found slightly unergonomic. As context, Cortex-M IVT is a list of plain function pointers ("data"), while RISC-V IVT is a list of (relative) jump instructions with the target address built in. So what we ended up doing is that we bitbang the full RISC-V relative jump instruction by calculating the function pointer's relative...
<re_irc>
... offset, then constructing the 32-bit wide instruction with the address built-in. Can someone think of a smarter way to do this? Is there some sensible abstraction or a library for this?
<re_irc>
<heksa> An important sub-problem there is: how would you construct an assembly instruction as data? asm! macro's great if you want to just run some assembly, but would it be possible to use existing syntax to make that into data (like, something you can place in a variable)?
<re_irc>
<adamgreig> heksa: perhaps you can use global_asm to place assembly instructions/directives/data anywhere in memory?
<re_irc>
<adamgreig> no stable "sym" in asm yet though so that might complicate making the interrupt table
<re_irc>
<heksa> I'm getting the sense that the global_asm macro is resolved at compile-time, so it wouldn't allow creating assembly instructions as data at runtime. That would be easy to work around, we could live with that.
<Shell>
yes
<re_irc>
<adamgreig> the normal asm macro is also compile time, there's no runtime assembler
<XMPPwocky>
no runtime assembler in rust itself, that is; obviously you can pull in various assembler libraries
<XMPPwocky>
that's a lot of potential code bloat, though
<XMPPwocky>
i don't trust LTO that much :P
<XMPPwocky>
<re_irc> "<heksa> Hey we were recently..." <- and fwiw this is basically how everybody does it
<XMPPwocky>
if you end up needing to assemble a lot of different instructions, it may make sense to build an Abstract Runtime Assembler Thingy or pull in a library
<XMPPwocky>
if you need to create a jump for an IVT, you do bitmask hackery, laugh at how awful it is, and then go finish the thing you're actually trying to make :P
<XMPPwocky>
a "sensible abstraction" here is a function called make_jump_instruction(instruction_address, jump_target_address), imo
<XMPPwocky>
does it call a library under the hood? who knows, that's why it's an abstraction
<re_irc>
<riskable> I figured it out:
<re_irc>
Ok(result) => result,
<re_irc>
let ir_samplerate = match Hertz(20_000_u32).to_duration() {
<re_irc>
};
<re_irc>
Err(_) => Microseconds(50_u32), // Fallback to 20Khz
<re_irc>
<riskable> * ir_samplerate: Microseconds
<re_irc>
<riskable> (in my actual code I'm using a value taken from the user configuration instead of "20_000_u32" which is why I have the "Err(_)" check and fallback)
gsalazar has quit [Ping timeout: 260 seconds]
crabbedhaloablut has quit [Quit: No Ping reply in 180 seconds.]