Skip to content

Commit a929ae1

Browse files
committed
Push all the changes together
1 parent a67367e commit a929ae1

32 files changed

+1316
-520
lines changed

.github/workflows/riscv-semihosting.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
build-riscv:
1212
strategy:
1313
matrix:
14-
# All generated code should be running on stable now, MRSV is 1.60.0
15-
toolchain: [ stable, nightly, 1.60.0 ]
14+
# All generated code should be running on stable now, MRSV is 1.61.0
15+
toolchain: [ stable, nightly, 1.61.0 ]
1616
target:
1717
- riscv32i-unknown-none-elf
1818
- riscv32imc-unknown-none-elf

.github/workflows/riscv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
build-riscv:
1212
strategy:
1313
matrix:
14-
# All generated code should be running on stable now, MRSV is 1.60.0
15-
toolchain: [ stable, nightly, 1.60.0 ]
14+
# All generated code should be running on stable now, MRSV is 1.61.0
15+
toolchain: [ stable, nightly, 1.61.0 ]
1616
target:
1717
- riscv32i-unknown-none-elf
1818
- riscv32imc-unknown-none-elf

riscv-peripheral/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ license = "ISC"
1616
[dependencies]
1717
embedded-hal = "1.0.0"
1818
embedded-hal-async = { version = "1.0.0", optional = true }
19-
riscv = { path = "../riscv", version = "0.11.1" }
19+
riscv = { path = "../riscv", version = "0.12.0" }
2020
riscv-pac = { path = "../riscv-pac", version = "0.2.0" }
2121

2222
[dev-dependencies]

riscv-peripheral/src/aclint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) mod test {
8787
Err(Error::InvalidVariant(number as usize))
8888
} else {
8989
// SAFETY: valid context number
90-
Ok(unsafe { core::mem::transmute(number) })
90+
Ok(unsafe { core::mem::transmute::<u16, HartId>(number) })
9191
}
9292
}
9393
}

riscv-rt/CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- Add `no-exceptions` feature to opt-out the default implementation of `_dispatch_exception`
13+
- Add `no-interrupts` feature to opt-out the default implementation of `_dispatch_core_interrupt`
1214
- Add `pre_init_trap` to detect early errors during the boot process.
1315
- Add `v-trap` feature to enable interrupt handling in vectored mode.
1416
- Add `interrupt` proc macro to help defining interrupt handlers.
15-
If `v-trap` feature is enabled, this macro also generates its corresponding trap.
17+
If `v-trap` feature is enabled, this macro also generates its corresponding trap.
1618
- Add `u-boot` feature, so that you can start your elf binary with u-boot and
1719
work with passed arguments.
1820

@@ -22,8 +24,8 @@ work with passed arguments.
2224
- Use `weak` symbols for functions such as `_mp_hook` or `_start_trap`
2325
- `abort` is now `weak`, so it is possible to link third-party libraries including this symbol.
2426
- Made `cfg` variable selection more robust for custom targets
25-
- `_start_trap_rust` now only deals with exceptions. When an interrupt is detected, it now calls
26-
to `_dispatch_interrupt`.
27+
- `_start_trap_rust` now relies on `_dispatch_exception` and `_dispatch_core_interrupt`.
28+
This change allows more flexibility for targets with non-standard exceptions and interrupts.
2729
- Upgrade rust-version to 1.61
2830
- Update `syn` to version 2.0
2931

riscv-rt/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2021"
1313
links = "riscv-rt" # Prevent multiple versions of riscv-rt being linked
1414

1515
[dependencies]
16-
riscv = {path = "../riscv", version = "0.11.1"}
16+
riscv = { path = "../riscv", version = "0.12.0" }
1717
riscv-rt-macros = { path = "macros", version = "0.2.1" }
1818

1919
[dev-dependencies]
@@ -24,3 +24,5 @@ s-mode = ["riscv-rt-macros/s-mode"]
2424
single-hart = []
2525
v-trap = ["riscv-rt-macros/v-trap"]
2626
u-boot = ["riscv-rt-macros/u-boot", "single-hart"]
27+
no-interrupts = []
28+
no-exceptions = []

riscv-rt/macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0"
1111
name = "riscv-rt-macros"
1212
repository = "https://github.com/rust-embedded/riscv"
1313
version = "0.2.1"
14+
edition = "2021"
1415

1516
[lib]
1617
proc-macro = true

riscv-rt/src/asm.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -287,38 +287,6 @@ riscv_rt_macros::vectored_interrupt_trap_riscv32!();
287287
#[cfg(all(riscv64, feature = "v-trap"))]
288288
riscv_rt_macros::vectored_interrupt_trap_riscv64!();
289289

290-
#[cfg(feature = "v-trap")]
291-
cfg_global_asm!(
292-
// Set the vector mode to vectored.
293-
r#".section .trap, "ax"
294-
.weak _vector_table
295-
.type _vector_table, @function
296-
297-
.option push
298-
.balign 0x4 // TODO check if this is the correct alignment
299-
.option norelax
300-
.option norvc
301-
302-
_vector_table:
303-
j _start_trap // Interrupt 0 is used for exceptions
304-
j _start_SupervisorSoft_trap
305-
j _start_DefaultHandler_trap // Interrupt 2 is reserved
306-
j _start_MachineSoft_trap
307-
j _start_DefaultHandler_trap // Interrupt 4 is reserved
308-
j _start_SupervisorTimer_trap
309-
j _start_DefaultHandler_trap // Interrupt 6 is reserved
310-
j _start_MachineTimer_trap
311-
j _start_DefaultHandler_trap // Interrupt 8 is reserved
312-
j _start_SupervisorExternal_trap
313-
j _start_DefaultHandler_trap // Interrupt 10 is reserved
314-
j _start_MachineExternal_trap
315-
316-
// default table does not include the remaining interrupts.
317-
// Targets with extra interrupts should override this table.
318-
319-
.option pop"#,
320-
);
321-
322290
#[rustfmt::skip]
323291
global_asm!(
324292
".section .text.abort

riscv-rt/src/exceptions.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use crate::TrapFrame;
2+
3+
extern "C" {
4+
fn InstructionMisaligned(trap_frame: &TrapFrame);
5+
fn InstructionFault(trap_frame: &TrapFrame);
6+
fn IllegalInstruction(trap_frame: &TrapFrame);
7+
fn Breakpoint(trap_frame: &TrapFrame);
8+
fn LoadMisaligned(trap_frame: &TrapFrame);
9+
fn LoadFault(trap_frame: &TrapFrame);
10+
fn StoreMisaligned(trap_frame: &TrapFrame);
11+
fn StoreFault(trap_frame: &TrapFrame);
12+
fn UserEnvCall(trap_frame: &TrapFrame);
13+
fn SupervisorEnvCall(trap_frame: &TrapFrame);
14+
fn MachineEnvCall(trap_frame: &TrapFrame);
15+
fn InstructionPageFault(trap_frame: &TrapFrame);
16+
fn LoadPageFault(trap_frame: &TrapFrame);
17+
fn StorePageFault(trap_frame: &TrapFrame);
18+
fn ExceptionHandler(trap_frame: &TrapFrame);
19+
}
20+
21+
#[doc(hidden)]
22+
#[no_mangle]
23+
pub static __EXCEPTIONS: [Option<unsafe extern "C" fn(&TrapFrame)>; 16] = [
24+
Some(InstructionMisaligned),
25+
Some(InstructionFault),
26+
Some(IllegalInstruction),
27+
Some(Breakpoint),
28+
Some(LoadMisaligned),
29+
Some(LoadFault),
30+
Some(StoreMisaligned),
31+
Some(StoreFault),
32+
Some(UserEnvCall),
33+
Some(SupervisorEnvCall),
34+
None,
35+
Some(MachineEnvCall),
36+
Some(InstructionPageFault),
37+
Some(LoadPageFault),
38+
None,
39+
Some(StorePageFault),
40+
];
41+
42+
#[export_name = "_dispatch_exception"]
43+
#[inline]
44+
unsafe extern "C" fn dispatch_exception(trap_frame: &TrapFrame, code: usize) {
45+
if code < __EXCEPTIONS.len() {
46+
match &__EXCEPTIONS[code] {
47+
Some(handler) => handler(trap_frame),
48+
None => ExceptionHandler(trap_frame),
49+
}
50+
} else {
51+
ExceptionHandler(trap_frame);
52+
}
53+
}

riscv-rt/src/interrupts.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
extern "C" {
2+
fn SupervisorSoft();
3+
fn MachineSoft();
4+
fn SupervisorTimer();
5+
fn MachineTimer();
6+
fn SupervisorExternal();
7+
fn MachineExternal();
8+
fn DefaultHandler();
9+
}
10+
11+
#[doc(hidden)]
12+
#[no_mangle]
13+
pub static __CORE_INTERRUPTS: [Option<unsafe extern "C" fn()>; 12] = [
14+
None,
15+
Some(SupervisorSoft),
16+
None,
17+
Some(MachineSoft),
18+
None,
19+
Some(SupervisorTimer),
20+
None,
21+
Some(MachineTimer),
22+
None,
23+
Some(SupervisorExternal),
24+
None,
25+
Some(MachineExternal),
26+
];
27+
28+
#[export_name = "_dispatch_core_interrupt"]
29+
#[inline]
30+
unsafe extern "C" fn dispatch_core_interrupt(code: usize) {
31+
if code < __CORE_INTERRUPTS.len() {
32+
match &__CORE_INTERRUPTS[code] {
33+
Some(handler) => handler(),
34+
None => DefaultHandler(),
35+
}
36+
} else {
37+
DefaultHandler();
38+
}
39+
}
40+
41+
#[cfg(all(riscv, feature = "v-trap"))]
42+
core::arch::global_asm!(
43+
r#" .section .trap, "ax"
44+
.weak _vector_table
45+
.type _vector_table, @function
46+
47+
.option push
48+
.balign 0x4 // TODO check if this is the correct alignment
49+
.option norelax
50+
.option norvc
51+
52+
_vector_table:
53+
j _start_trap // Interrupt 0 is used for exceptions
54+
j _start_SupervisorSoft_trap
55+
j _start_DefaultHandler_trap // Interrupt 2 is reserved
56+
j _start_MachineSoft_trap
57+
j _start_DefaultHandler_trap // Interrupt 4 is reserved
58+
j _start_SupervisorTimer_trap
59+
j _start_DefaultHandler_trap // Interrupt 6 is reserved
60+
j _start_MachineTimer_trap
61+
j _start_DefaultHandler_trap // Interrupt 8 is reserved
62+
j _start_SupervisorExternal_trap
63+
j _start_DefaultHandler_trap // Interrupt 10 is reserved
64+
j _start_MachineExternal_trap
65+
66+
.option pop"#
67+
);

0 commit comments

Comments
 (0)