Skip to content

Commit d6365e0

Browse files
committed
compatibility with RV32E
1 parent fdc3bb6 commit d6365e0

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

riscv-rt/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12+
- Add documentation to trap frame fields.
13+
- Avoid using `t3`+ in startup assembly to ensure compatibility with RVE32.
1214
- `link.x.in`: remove references to `eh_frame`.
1315
- Rename start/end section symbols to align with `cortex-m-rt`:
1416
- `_stext`: it remains, as linker files can modify it.

riscv-rt/src/asm.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ cfg_global_asm!(
107107
#[cfg(riscvm)]
108108
"mul t0, t2, t0",
109109
#[cfg(not(riscvm))]
110-
"beqz t2, 2f // Jump if single-hart
111-
mv t1, t2
112-
mv t3, t0
110+
"beqz t2, 2f // skip if hart ID is 0
111+
mv t1, t0
113112
1:
114-
add t0, t0, t3
115-
addi t1, t1, -1
116-
bnez t1, 1b
113+
add t0, t0, t1
114+
addi t2, t2, -1
115+
bnez t2, 1b
117116
2: ",
118117
);
119118
cfg_global_asm!(
@@ -153,22 +152,22 @@ cfg_global_asm!(
153152
"call __pre_init
154153
// Copy .data from flash to RAM
155154
la t0, __sdata
156-
la t2, __edata
155+
la a0, __edata
157156
la t1, __sidata
158-
bgeu t0, t2, 2f
157+
bgeu t0, a0, 2f
159158
1: ",
160159
#[cfg(target_arch = "riscv32")]
161-
"lw t3, 0(t1)
160+
"lw t2, 0(t1)
162161
addi t1, t1, 4
163-
sw t3, 0(t0)
162+
sw t2, 0(t0)
164163
addi t0, t0, 4
165-
bltu t0, t2, 1b",
164+
bltu t0, a0, 1b",
166165
#[cfg(target_arch = "riscv64")]
167-
"ld t3, 0(t1)
166+
"ld t2, 0(t1)
168167
addi t1, t1, 8
169-
sd t3, 0(t0)
168+
sd t2, 0(t0)
170169
addi t0, t0, 8
171-
bltu t0, t2, 1b",
170+
bltu t0, a0, 1b",
172171
"
173172
2: // Zero out .bss
174173
la t0, __sbss

riscv-rt/src/lib.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -567,25 +567,40 @@ pub use riscv_rt_macros::core_interrupt_riscv64 as core_interrupt; // just for d
567567
pub static __ONCE__: () = ();
568568

569569
/// Registers saved in trap handler
570-
#[allow(missing_docs)]
571570
#[repr(C)]
572571
#[derive(Debug)]
573572
pub struct TrapFrame {
573+
/// `x1`: return address, stores the address to return to after a function call or interrupt.
574574
pub ra: usize,
575+
/// `x5`: temporary register `t0`, used for intermediate values.
575576
pub t0: usize,
577+
/// `x6`: temporary register `t1`, used for intermediate values.
576578
pub t1: usize,
579+
/// `x7`: temporary register `t2`, used for intermediate values.
577580
pub t2: usize,
581+
/// `x28`: temporary register `t3`, used for intermediate values.
578582
pub t3: usize,
583+
/// `x29`: temporary register `t4`, used for intermediate values.
579584
pub t4: usize,
585+
/// `x30`: temporary register `t5`, used for intermediate values.
580586
pub t5: usize,
587+
/// `x31`: temporary register `t6`, used for intermediate values.
581588
pub t6: usize,
589+
/// `x10`: argument register `a0`. Used to pass the first argument to a function.
582590
pub a0: usize,
591+
/// `x11`: argument register `a1`. Used to pass the second argument to a function.
583592
pub a1: usize,
593+
/// `x12`: argument register `a2`. Used to pass the third argument to a function.
584594
pub a2: usize,
595+
/// `x13`: argument register `a3`. Used to pass the fourth argument to a function.
585596
pub a3: usize,
597+
/// `x14`: argument register `a4`. Used to pass the fifth argument to a function.
586598
pub a4: usize,
599+
/// `x15`: argument register `a5`. Used to pass the sixth argument to a function.
587600
pub a5: usize,
601+
/// `x16`: argument register `a6`. Used to pass the seventh argument to a function.
588602
pub a6: usize,
603+
/// `x17`: argument register `a7`. Used to pass the eighth argument to a function.
589604
pub a7: usize,
590605
}
591606

0 commit comments

Comments
 (0)