feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
//@ revisions: x64 i686 aarch64 arm riscv32 riscv64
|
2021-06-11 06:22:13 -05:00
|
|
|
//
|
|
|
|
//@ [x64] needs-llvm-components: x86
|
2021-08-27 11:36:18 -05:00
|
|
|
//@ [x64] compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib
|
2021-06-11 06:22:13 -05:00
|
|
|
//@ [i686] needs-llvm-components: x86
|
2021-08-27 11:36:18 -05:00
|
|
|
//@ [i686] compile-flags: --target=i686-unknown-linux-gnu --crate-type=rlib
|
2021-06-11 06:22:13 -05:00
|
|
|
//@ [aarch64] needs-llvm-components: aarch64
|
2021-08-27 11:36:18 -05:00
|
|
|
//@ [aarch64] compile-flags: --target=aarch64-unknown-linux-gnu --crate-type=rlib
|
|
|
|
//@ [arm] needs-llvm-components: arm
|
|
|
|
//@ [arm] compile-flags: --target=armv7-unknown-linux-gnueabihf --crate-type=rlib
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
//@ [riscv32] needs-llvm-components: riscv
|
|
|
|
//@ [riscv32] compile-flags: --target=riscv32i-unknown-none-elf --crate-type=rlib
|
|
|
|
//@ [riscv64] needs-llvm-components: riscv
|
|
|
|
//@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib
|
2021-06-11 06:22:13 -05:00
|
|
|
#![no_core]
|
|
|
|
#![feature(
|
|
|
|
no_core,
|
|
|
|
lang_items,
|
|
|
|
abi_ptx,
|
|
|
|
abi_msp430_interrupt,
|
|
|
|
abi_avr_interrupt,
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
abi_x86_interrupt,
|
2024-08-07 08:48:16 -05:00
|
|
|
abi_riscv_interrupt,
|
2024-09-23 07:15:20 -05:00
|
|
|
abi_c_cmse_nonsecure_call,
|
|
|
|
cmse_nonsecure_entry
|
2021-06-11 06:22:13 -05:00
|
|
|
)]
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
#[lang = "sized"]
|
|
|
|
trait Sized {}
|
2021-06-11 06:22:13 -05:00
|
|
|
|
2024-08-07 08:48:16 -05:00
|
|
|
#[lang = "copy"]
|
|
|
|
trait Copy {}
|
|
|
|
|
2021-06-11 06:22:13 -05:00
|
|
|
extern "ptx-kernel" fn ptx() {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn ptx_ptr(f: extern "ptx-kernel" fn()) {
|
|
|
|
//~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//~^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "ptx-kernel" {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
|
|
|
|
2021-06-11 06:22:13 -05:00
|
|
|
extern "aapcs" fn aapcs() {}
|
|
|
|
//[x64]~^ ERROR is not a supported ABI
|
|
|
|
//[i686]~^^ ERROR is not a supported ABI
|
2021-08-27 11:36:18 -05:00
|
|
|
//[aarch64]~^^^ ERROR is not a supported ABI
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
//[riscv32]~^^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn aapcs_ptr(f: extern "aapcs" fn()) {
|
|
|
|
//[x64]~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[x64]~^^ WARN this was previously accepted
|
|
|
|
//[i686]~^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[i686]~^^^^ WARN this was previously accepted
|
|
|
|
//[aarch64]~^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[aarch64]~^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv32]~^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv32]~^^^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv64]~^^^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv64]~^^^^^^^^^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "aapcs" {}
|
|
|
|
//[x64]~^ ERROR is not a supported ABI
|
|
|
|
//[i686]~^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv32]~^^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^^ ERROR is not a supported ABI
|
|
|
|
|
2021-06-11 06:22:13 -05:00
|
|
|
extern "msp430-interrupt" fn msp430() {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn msp430_ptr(f: extern "msp430-interrupt" fn()) {
|
|
|
|
//~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//~^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "msp430-interrupt" {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
|
|
|
|
2021-06-11 06:22:13 -05:00
|
|
|
extern "avr-interrupt" fn avr() {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn avr_ptr(f: extern "avr-interrupt" fn()) {
|
|
|
|
//~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//~^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "avr-interrupt" {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
|
|
|
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
extern "riscv-interrupt-m" fn riscv() {}
|
|
|
|
//[arm]~^ ERROR is not a supported ABI
|
|
|
|
//[x64]~^^ ERROR is not a supported ABI
|
|
|
|
//[i686]~^^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn riscv_ptr(f: extern "riscv-interrupt-m" fn()) {
|
|
|
|
//[arm]~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[arm]~^^ WARN this was previously accepted
|
|
|
|
//[x64]~^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[x64]~^^^^ WARN this was previously accepted
|
|
|
|
//[i686]~^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[i686]~^^^^^^ WARN this was previously accepted
|
|
|
|
//[aarch64]~^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[aarch64]~^^^^^^^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "riscv-interrupt-m" {}
|
|
|
|
//[arm]~^ ERROR is not a supported ABI
|
|
|
|
//[x64]~^^ ERROR is not a supported ABI
|
|
|
|
//[i686]~^^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^^ ERROR is not a supported ABI
|
|
|
|
|
2021-06-11 06:22:13 -05:00
|
|
|
extern "x86-interrupt" fn x86() {}
|
|
|
|
//[aarch64]~^ ERROR is not a supported ABI
|
2021-08-27 11:36:18 -05:00
|
|
|
//[arm]~^^ ERROR is not a supported ABI
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
//[riscv32]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn x86_ptr(f: extern "x86-interrupt" fn()) {
|
|
|
|
//[aarch64]~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[aarch64]~^^ WARN this was previously accepted
|
|
|
|
//[arm]~^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[arm]~^^^^ WARN this was previously accepted
|
|
|
|
//[riscv32]~^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv32]~^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv64]~^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv64]~^^^^^^^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "x86-interrupt" {}
|
|
|
|
//[aarch64]~^ ERROR is not a supported ABI
|
|
|
|
//[arm]~^^ ERROR is not a supported ABI
|
|
|
|
//[riscv32]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^ ERROR is not a supported ABI
|
|
|
|
|
2021-06-11 06:22:13 -05:00
|
|
|
extern "thiscall" fn thiscall() {}
|
2021-10-24 13:57:45 -05:00
|
|
|
//[x64]~^ ERROR is not a supported ABI
|
feat: `riscv-interrupt-{m,s}` calling conventions
Similar to prior support added for the mips430, avr, and x86 targets
this change implements the rough equivalent of clang's
[`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling
e.g.
```rust
static mut CNT: usize = 0;
pub extern "riscv-interrupt-m" fn isr_m() {
unsafe {
CNT += 1;
}
}
```
to produce highly effective assembly like:
```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0: 1141 addi sp,sp,-16
unsafe {
CNT += 1;
420003a2: c62a sw a0,12(sp)
420003a4: c42e sw a1,8(sp)
420003a6: 3fc80537 lui a0,0x3fc80
420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae: 0585 addi a1,a1,1
420003b0: 62b52e23 sw a1,1596(a0)
}
}
420003b4: 4532 lw a0,12(sp)
420003b6: 45a2 lw a1,8(sp)
420003b8: 0141 addi sp,sp,16
420003ba: 30200073 mret
```
(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)
This outcome is superior to hand-coded interrupt routines which, lacking
visibility into any non-assembly body of the interrupt handler, have to
be very conservative and save the [entire CPU state to the stack
frame][full-frame-save]. By instead asking LLVM to only save the
registers that it uses, we defer the decision to the tool with the best
context: it can more accurately account for the cost of spills if it
knows that every additional register used is already at the cost of an
implicit spill.
At the LLVM level, this is apparently [implemented by] marking every
register as "[callee-save]," matching the semantics of an interrupt
handler nicely (it has to leave the CPU state just as it found it after
its `{m|s}ret`).
This approach is not suitable for every interrupt handler, as it makes
no attempt to e.g. save the state in a user-accessible stack frame. For
a full discussion of those challenges and tradeoffs, please refer to
[the interrupt calling conventions RFC][rfc].
Inside rustc, this implementation differs from prior art because LLVM
does not expose the "all-saved" function flavor as a calling convention
directly, instead preferring to use an attribute that allows for
differentiating between "machine-mode" and "superivsor-mode" interrupts.
Finally, some effort has been made to guide those who may not yet be
aware of the differences between machine-mode and supervisor-mode
interrupts as to why no `riscv-interrupt` calling convention is exposed
through rustc, and similarly for why `riscv-interrupt-u` makes no
appearance (as it would complicate future LLVM upgrades).
[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469
[implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67
[callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-05-23 17:08:23 -05:00
|
|
|
//[arm]~^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv32]~^^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn thiscall_ptr(f: extern "thiscall" fn()) {
|
|
|
|
//[x64]~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[x64]~^^ WARN this was previously accepted
|
|
|
|
//[arm]~^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[arm]~^^^^ WARN this was previously accepted
|
|
|
|
//[aarch64]~^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[aarch64]~^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv32]~^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv32]~^^^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv64]~^^^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv64]~^^^^^^^^^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "thiscall" {}
|
|
|
|
//[x64]~^ ERROR is not a supported ABI
|
|
|
|
//[arm]~^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv32]~^^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^^ ERROR is not a supported ABI
|
|
|
|
|
2021-10-24 13:57:45 -05:00
|
|
|
extern "stdcall" fn stdcall() {}
|
2024-09-03 11:48:15 -05:00
|
|
|
//[x64]~^ ERROR is not a supported ABI
|
|
|
|
//[arm]~^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv32]~^^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
fn stdcall_ptr(f: extern "stdcall" fn()) {
|
|
|
|
//[x64]~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[x64]~^^ WARN this was previously accepted
|
|
|
|
//[arm]~^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[arm]~^^^^ WARN this was previously accepted
|
|
|
|
//[aarch64]~^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[aarch64]~^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv32]~^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv32]~^^^^^^^^ WARN this was previously accepted
|
|
|
|
//[riscv64]~^^^^^^^^^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//[riscv64]~^^^^^^^^^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "stdcall" {}
|
2024-09-03 11:48:15 -05:00
|
|
|
//[x64]~^ ERROR is not a supported ABI
|
|
|
|
//[arm]~^^ ERROR is not a supported ABI
|
|
|
|
//[aarch64]~^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv32]~^^^^ ERROR is not a supported ABI
|
|
|
|
//[riscv64]~^^^^^ ERROR is not a supported ABI
|
2024-08-07 08:48:16 -05:00
|
|
|
|
2024-09-23 07:15:20 -05:00
|
|
|
fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
|
2024-08-07 08:48:16 -05:00
|
|
|
//~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//~^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
2024-09-23 07:15:20 -05:00
|
|
|
|
|
|
|
extern "C-cmse-nonsecure-entry" fn cmse_entry() {}
|
|
|
|
//~^ ERROR is not a supported ABI
|
|
|
|
fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
|
|
|
|
//~^ WARN unsupported_fn_ptr_calling_conventions
|
|
|
|
//~^^ WARN this was previously accepted
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
extern "C-cmse-nonsecure-entry" {}
|
|
|
|
//~^ ERROR is not a supported ABI
|