Skip to content

Commit e53deef

Browse files
bors[bot]pgraubner
andauthored
Merge #104
104: SBI mode r=almindor a=pgraubner Introducing Supervisor Binary Interface (SBI) compatibility as a build-time feature. Main goal is to allow riscv-rt based implementations to be bootstrapped by a SBI-firmware (like in `qemu-system-riscv64`). * Introduce compiler switches for assembly in order to switch between machine mode / supervisor mode * Introduce cargo feature for conditional compilation * Patch lib.rs for supervisor-mode compatibility The only interface this PR is braking is `mp_hook`, which needs a mhartid replacement for smode. The hart id is passed by the caller. Tested with `qemu-system-riscv64`. See also documentation/features/sbi for further implementation details. Co-authored-by: Pablo Graubner <[email protected]>
2 parents 93bc768 + 68e99b3 commit e53deef

File tree

55 files changed

+104
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+104
-25
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 5 additions & 0 deletions

riscv-rt/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ keywords = ["riscv", "runtime", "startup"]
1010
license = "ISC"
1111
edition = "2018"
1212

13+
[features]
14+
s-mode = []
15+
1316
[dependencies]
1417
r0 = "1.0.0"
1518
riscv = "0.8"

riscv-rt/asm.S

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ _abs_start:
4646
.cfi_startproc
4747
.cfi_undefined ra
4848

49+
#ifdef SMODE
50+
csrw sie, 0 // interrupt disable
51+
csrw sip, 0 // no pending interrupts
52+
#else
4953
csrw mie, 0
5054
csrw mip, 0
55+
#endif
56+
5157

5258
li x1, 0
5359
li x2, 0
@@ -84,8 +90,13 @@ _abs_start:
8490
la gp, __global_pointer$
8591
.option pop
8692

87-
// Check hart id
93+
#ifdef SMODE
94+
// there is no equivalent of mhartid in supervisor mode.
95+
// instead, the hartid is passed as paramter by SMODE
96+
mv t2, a0
97+
#else
8898
csrr t2, mhartid
99+
#endif
89100
lui t0, %hi(_max_hart_id)
90101
add t0, t0, %lo(_max_hart_id)
91102
bgtu t2, t0, abort
@@ -165,7 +176,11 @@ default_start_trap:
165176
LOAD a7, 15*REGBYTES(sp)
166177

167178
addi sp, sp, 16*REGBYTES
179+
#ifdef SMODE
180+
sret
181+
#else
168182
mret
183+
#endif
169184

170185
/* Make sure there is an abort when linking */
171186
.section .text.abort

riscv-rt/assemble.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ do
3131

3232
riscv64-unknown-elf-gcc -ggdb3 -fdebug-prefix-map=$(pwd)=/riscv-rt -c -mabi=lp64${abi} -march=rv64${ext} asm.S -o bin/$crate.o
3333
riscv64-unknown-elf-ar crs bin/riscv64${ext}-unknown-none-elf.a bin/$crate.o
34+
35+
#s-mode
36+
riscv64-unknown-elf-gcc -DSMODE -ggdb3 -fdebug-prefix-map=$(pwd)=/riscv-rt -c -mabi=ilp32${abi} -march=rv32${ext} asm.S -o bin/$crate.o
37+
riscv64-unknown-elf-ar crs bin/riscv32${ext}-unknown-none-elf-smode.a bin/$crate.o
38+
39+
riscv64-unknown-elf-gcc -DSMODE -ggdb3 -fdebug-prefix-map=$(pwd)=/riscv-rt -c -mabi=lp64${abi} -march=rv64${ext} asm.S -o bin/$crate.o
40+
riscv64-unknown-elf-ar crs bin/riscv64${ext}-unknown-none-elf-smode.a bin/$crate.o
41+
3442
done
3543

3644
rm bin/$crate.o
7.55 KB
Binary file not shown.
20 Bytes
Binary file not shown.
7.42 KB
Binary file not shown.
20 Bytes
Binary file not shown.
7.55 KB
Binary file not shown.
20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)