Re:Programming ARM μC in Rust at four different levels of ab...
by madez on Thursday February 22, 2018 @04:52AM
(#16436467)
Why is it necessary to mark the interrupt handler and the panic formatting function as extern C functions? Is the C way of doing that set in silicon?
[ Parent
| on HN ]
Re:Programming ARM μC in Rust at four different levels of ab...
by m1el on Thursday February 22, 2018 @05:18AM
(#16436576)
C and Rust (can) have different calling conventions. C is the de-facto standard calling convention. When you mark a function as `extern "C"`, it means that it can be called as if it is a C function.
Re:Programming ARM μC in Rust at four different levels of ab...
by madez on Thursday February 22, 2018 @05:48AM
(#16436685)
But what C code is running alongside the Rust code on the microcontroller that would make adhering to the C calling convention necessary? Is the hardware expecting the C calling convention?
Re:Programming ARM μC in Rust at four different levels of ab...
by TickleSteve on Thursday February 22, 2018 @07:43AM
(#16437149)
yes, ARM ISRs use the C calling convention, and they should be marked as extern because they're effectively at global scope and can be invoked from anywhere.
Re:Programming ARM μC in Rust at four different levels of ab...
by friendzis on Thursday February 22, 2018 @06:53AM
(#16436936)
I just skimmed over this, toolchain setup talks about TivaTi/Stellaris, code is for STM32F. My memory is muddy on this, so take it with a bit of salt. Cores have specific "interrupt context" (do not recall the actual name) with a specific set of call[er]-saved registers (EABI). Making fault handlers `extern C` is a way to ensure that these functions adhere to that EABI and do not clobber processor state. Probably.
Re:Programming ARM μC in Rust at four different levels of ab...
by TickleSteve on Thursday February 22, 2018 @07:45AM
(#16437158)
There is an interrupt-mode stack and a user-mode stack, the stacks are switched on interrupt invocation.
The value pushed on to the stack is a special value that causes a pop into SP to switch stacks back on return.
Re:Programming ARM μC in Rust at four different levels of ab...
by leggomylibro on Thursday February 22, 2018 @12:45PM
(#16439498)
I don't know much of anything about Rust, and I have a pretty limited knowledge of ARM, but I think that the 'Nested Vector Interrupt Controller' basically just pushes a stack frame and jumps to the memory location specified in a vector table that lives near the start of memory.
That sounds like how C functions are called; does Rust do something different?
Re:Programming ARM μC in Rust at four different levels of ab...
by dbaupp on Thursday February 22, 2018 @04:20PM
(#16441485)
The fundamentals of pushing a stack frame and jumping is the same, but the details of how arguments are passed (e.g. is a value in registers, or on the stack) and return values returned differ between the calling conventions.