Skip to content

Commit 3e4c04f

Browse files
committed
SMODE: rename feature sbi to s-mode
1 parent 67b2fcd commit 3e4c04f

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

riscv-rt/CHANGELOG.md

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

1010
### Added
1111

12-
- Optional cargo feature `sbi` for SBI compatibility, including conditional compilation for machine mode instructions.
12+
- Optional cargo feature `s-mode` for supervisor mode, including conditional compilation for supervisor/machine mode instructions.
1313

1414
### Changed
1515

1616
- Remove superfluous parentheses from link.x, which caused linker errors with nightly.
17-
- Changed `mp_hook` signature, hartid as passed as usize parameter by the caller (required for `sbi` feature).
17+
- Changed `mp_hook` signature, hartid as passed as usize parameter by the caller (required for `s-mode` feature).
1818

1919
## [v0.9.0] - 2022-07-01
2020

riscv-rt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "ISC"
1111
edition = "2018"
1212

1313
[features]
14-
sbi = []
14+
s-mode = []
1515

1616
[dependencies]
1717
r0 = "1.0.0"

riscv-rt/asm.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ _abs_start:
4646
.cfi_startproc
4747
.cfi_undefined ra
4848

49-
#ifdef SBI
49+
#ifdef SMODE
5050
csrw sie, 0 // interrupt disable
5151
csrw sip, 0 // no pending interrupts
5252
#else
@@ -90,9 +90,9 @@ _abs_start:
9090
la gp, __global_pointer$
9191
.option pop
9292

93-
#ifdef SBI
93+
#ifdef SMODE
9494
// there is no equivalent of mhartid in supervisor mode.
95-
// instead, the hartid is passed as paramter by SBI
95+
// instead, the hartid is passed as paramter by SMODE
9696
mv t2, a0
9797
#else
9898
csrr t2, mhartid
@@ -176,7 +176,7 @@ default_start_trap:
176176
LOAD a7, 15*REGBYTES(sp)
177177

178178
addi sp, sp, 16*REGBYTES
179-
#ifdef SBI
179+
#ifdef SMODE
180180
sret
181181
#else
182182
mret

riscv-rt/assemble.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ do
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
3434

35-
#sbi
36-
riscv64-unknown-elf-gcc -DSBI -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-sbi.a bin/$crate.o
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
3838

39-
riscv64-unknown-elf-gcc -DSBI -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-sbi.a bin/$crate.o
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
4141

4242
done
4343

riscv-rt/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fn main() {
1515
let mut target = Target::from_target_str(&target);
1616
target.retain_extensions("imfdc");
1717
let archive: String;
18-
if cfg!(feature = "sbi") {
19-
println!("======== compiling riscv-rt for sbi");
20-
archive = format!("bin/{}-sbi.a", target.to_string());
18+
if cfg!(feature = "s-mode") {
19+
println!("======== compiling riscv-rt for s-mode");
20+
archive = format!("bin/{}-smode.a", target.to_string());
2121
} else {
2222
archive = format!("bin/{}.a", target.to_string());
2323
}

riscv-rt/examples/multi_core.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ extern crate riscv;
66
extern crate riscv_rt;
77

88
use riscv::asm::wfi;
9-
use riscv::register::{mhartid, mie, mip};
9+
use riscv::register::{mie, mip};
1010
use riscv_rt::entry;
1111

1212
#[export_name = "_mp_hook"]
1313
#[rustfmt::skip]
1414
pub extern "Rust" fn user_mp_hook(hartid: usize) -> bool {
15-
let hartid = mhartid::read();
1615
if hartid == 0 {
1716
true
1817
} else {

riscv-rt/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//!
2323
//! - A `_sheap` symbol at whose address you can locate a heap.
2424
//!
25-
//! - Support for a runtime in supervisor mode, bootstrapped via [Supervisor Binary Interface (SBI)](https://github.com/riscv-non-isa/riscv-sbi-doc)
25+
//! - Support for a runtime in supervisor mode, that can be bootstrapped via [Supervisor Binary Interface (SBI)](https://github.com/riscv-non-isa/riscv-sbi-doc)
2626
//!
2727
//! ``` text
2828
//! $ cargo new --bin app && cd $_
@@ -325,23 +325,23 @@
325325
//!
326326
//! # Features
327327
//!
328-
//! ## `sbi`
328+
//! ## `s-mode`
329329
//!
330-
//! The SBI runtime feature (`sbi`) can be activated via [Cargo features](https://doc.rust-lang.org/cargo/reference/features.html).
330+
//! The supervisor mode feature (`s-mode`) can be activated via [Cargo features](https://doc.rust-lang.org/cargo/reference/features.html).
331331
//!
332332
//! For example:
333333
//! ``` text
334334
//! [dependencies]
335-
//! riscv-rt = {features=["sbi"]}
335+
//! riscv-rt = {features=["s-mode"]}
336336
//! ```
337-
//! Using the SBI requires riscv-rt to be run in supervisor mode instead of machine code.
338337
//! Internally, riscv-rt uses different versions of precompiled static libraries
339-
//! for (i) machine mode and (ii) sbi. If the `sbi` feature was activated,
340-
//! the build script selects the sbi library. While most registers/instructions have variants for
338+
//! for (i) machine mode and (ii) supervisor mode. If the `s-mode` feature was activated,
339+
//! the build script selects the s-mode library. While most registers/instructions have variants for
341340
//! both `mcause` and `scause`, the `mhartid` hardware thread register is not available in supervisor
342-
//! mode. Instead, the hartid is passed as parameter by the calling SBI.
341+
//! mode. Instead, the hartid is passed as parameter by a bootstrapping firmware (i.e., SBI).
343342
//!
344-
//! QEMU supports [OpenSBI](https://github.com/riscv-software-src/opensbi) as default firmware.
343+
//! Use case: QEMU supports [OpenSBI](https://github.com/riscv-software-src/opensbi) as default firmware.
344+
//! Using the SBI requires riscv-rt to be run in supervisor mode instead of machine mode.
345345
//! ``` text
346346
//! APP_BINARY=$(find target -name app)
347347
//! sudo qemu-system-riscv64 -m 2G -nographic -machine virt -kernel $APP_BINARY
@@ -401,7 +401,7 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
401401

402402
// sbi passes hartid as first parameter (a0)
403403
let hartid: usize;
404-
if cfg!(feature = "sbi") {
404+
if cfg!(feature = "s-mode") {
405405
hartid = a0;
406406
} else {
407407
hartid = mhartid::read();
@@ -461,7 +461,7 @@ pub extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) {
461461
let code: usize;
462462
let is_exception: bool;
463463

464-
if cfg!(feature = "sbi") {
464+
if cfg!(feature = "s-mode") {
465465
let cause = scause::read();
466466
is_exception = cause.is_exception();
467467
code = cause.code();
@@ -601,7 +601,7 @@ pub unsafe extern "Rust" fn default_setup_interrupts() {
601601
fn _start_trap();
602602
}
603603

604-
if cfg!(feature = "sbi") {
604+
if cfg!(feature = "s-mode") {
605605
use riscv::register::stvec::{self, TrapMode};
606606
stvec::write(_start_trap as usize, TrapMode::Direct);
607607
} else {

0 commit comments

Comments
 (0)