Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit db5aa93

Browse files
sethponsdagens
andauthored
feat: use vectoring to jump straight to interruptN (#11)
* feat: use vectoring to jump straight to interruptN Previously, the vector table was set up in a pseudo-direct mode where all interrupts were redirected to a single `_start_trap` handler regardless of number. This change introduces 31 new `_start_trapN` targets that encode which `interruptN` function to jump to, at a cost of 180 bytes per function (~5kb total). Not shown (because the linker scripts live in the HAL) are the big block of `PROVIDES`: ```ld PROVIDE(_start_trap1 = default_start_trap1) PROVIDE(_start_trap2 = default_start_trap2) ... PROVIDE(_start_trap31 = default_start_trap31) ``` As a side benefit, this does enable overriding on a per-irq basis and could even allow someone to switch back to the current psuedo-direct mode if they so chose (though, I think they wouldn't see anything get GC'd yet). Potential improvements include: * Shrinking the saved register set to just being the callee-save parts of the C ABI, since only `default_start_trap` really has a use for the full frame * Finer-grained control around which interrupts are vectored, and which are semi-direct: maybe we can get away with just three modes at the start (all direct, only 1-16 vectored, all vectored), but I'm curious if we could find a way to precisely express in a downstream crate "I want precisely 1, 2, 4..." to be vectored. Maybe a proc macro or other generator script? * fix(ci): use nightly clippy Required if we want to use `#![feature(...)]`s, else clippy complains: ``` error[E0554]: `#![feature]` may not be used on the stable release channel --> src/lib.rs:18:1 | 18 | #![feature(naked_functions)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0554`. error: could not compile `esp-riscv-rt` due to previous error Error: Process completed with exit code 101. ``` * Revert "feat: use vectoring to jump straight to interruptN" This reverts commit 9b77193. * feat: allow vectoring per-slot overrides Previously, the vector table was set up in a pseudo-direct mode where all interrupts were redirected to a single `_start_trap` handler regardless of number. This change introduces 31 new `_start_trapN` targets that, by default, retain the pseudo-direct behavior. However, they're weak symbols, so they allow for individually overriding entries in the _vector_table, as well as overriding the entire _vector_table itself. This is in contrast with the earlier attempt in 9b77193 that jumped straight to the corresponding `extern "C" interruptN`; instead, this defers that work to the HAL and other downstream crates. * fix: restore per-slot handlers Unless any of the `.weak` symbols are overridden, this produces the exact same assembly as before. But it permits overriding handlers on a slot-by-slot basis by overriding those `.weak` symbols individually. Co-Authored-By: onsdagens <[email protected]> Co-Authored-By: sethp <[email protected]> --------- Co-authored-by: onsdagens <[email protected]>
1 parent 9281af2 commit db5aa93

File tree

2 files changed

+102
-11
lines changed

2 files changed

+102
-11
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@v3
4141
- uses: dtolnay/rust-toolchain@v1
4242
with:
43-
toolchain: stable
43+
toolchain: nightly
4444
components: clippy
4545
- uses: Swatinem/rust-cache@v2
4646

src/lib.rs

Lines changed: 101 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,78 @@ _abs_start:
426426
.cfi_endproc
427427
428428
/*
429-
Trap entry point (_start_trap)
429+
Trap entry points (_start_trap, _start_trapN for N in 1..=31)
430430
431-
Saves caller saved registers ra, t0..6, a0..7, calls _start_trap_rust,
432-
restores caller saved registers and then returns.
431+
The default implementation saves all registers to the stack and calls
432+
_start_trap_rust, then restores all saved registers before `mret`
433433
*/
434434
.section .trap, "ax"
435-
.global default_start_trap
436-
437-
default_start_trap:
435+
.weak _start_trap
436+
.weak _start_trap1
437+
.weak _start_trap2
438+
.weak _start_trap3
439+
.weak _start_trap4
440+
.weak _start_trap5
441+
.weak _start_trap6
442+
.weak _start_trap7
443+
.weak _start_trap8
444+
.weak _start_trap9
445+
.weak _start_trap10
446+
.weak _start_trap11
447+
.weak _start_trap12
448+
.weak _start_trap13
449+
.weak _start_trap14
450+
.weak _start_trap15
451+
.weak _start_trap16
452+
.weak _start_trap17
453+
.weak _start_trap18
454+
.weak _start_trap19
455+
.weak _start_trap20
456+
.weak _start_trap21
457+
.weak _start_trap22
458+
.weak _start_trap23
459+
.weak _start_trap24
460+
.weak _start_trap25
461+
.weak _start_trap26
462+
.weak _start_trap27
463+
.weak _start_trap28
464+
.weak _start_trap29
465+
.weak _start_trap30
466+
.weak _start_trap31
467+
468+
_start_trap1:
469+
_start_trap2:
470+
_start_trap3:
471+
_start_trap4:
472+
_start_trap5:
473+
_start_trap6:
474+
_start_trap7:
475+
_start_trap8:
476+
_start_trap9:
477+
_start_trap10:
478+
_start_trap11:
479+
_start_trap12:
480+
_start_trap13:
481+
_start_trap14:
482+
_start_trap15:
483+
_start_trap16:
484+
_start_trap17:
485+
_start_trap18:
486+
_start_trap19:
487+
_start_trap20:
488+
_start_trap21:
489+
_start_trap22:
490+
_start_trap23:
491+
_start_trap24:
492+
_start_trap25:
493+
_start_trap26:
494+
_start_trap27:
495+
_start_trap28:
496+
_start_trap29:
497+
_start_trap30:
498+
_start_trap31:
499+
500+
_start_trap:
438501
addi sp, sp, -40*4
439502
440503
sw ra, 0*4(sp)
@@ -534,7 +597,7 @@ abort:
534597
*/
535598
536599
.section .trap, "ax"
537-
.global _vector_table
600+
.weak _vector_table
538601
.type _vector_table, @function
539602
540603
.option push
@@ -544,9 +607,37 @@ abort:
544607
545608
_vector_table:
546609
j _start_trap
547-
.rept 31
548-
j _start_trap
549-
.endr
610+
j _start_trap1
611+
j _start_trap2
612+
j _start_trap3
613+
j _start_trap4
614+
j _start_trap5
615+
j _start_trap6
616+
j _start_trap7
617+
j _start_trap8
618+
j _start_trap9
619+
j _start_trap10
620+
j _start_trap11
621+
j _start_trap12
622+
j _start_trap13
623+
j _start_trap14
624+
j _start_trap15
625+
j _start_trap16
626+
j _start_trap17
627+
j _start_trap18
628+
j _start_trap19
629+
j _start_trap20
630+
j _start_trap21
631+
j _start_trap22
632+
j _start_trap23
633+
j _start_trap24
634+
j _start_trap25
635+
j _start_trap26
636+
j _start_trap27
637+
j _start_trap28
638+
j _start_trap29
639+
j _start_trap30
640+
j _start_trap31
550641
551642
.option pop
552643
"#,

0 commit comments

Comments
 (0)