Skip to content

Commit 4b4e24f

Browse files
committed
rustsbi: enable H extension; reformat
1 parent c1bdb76 commit 4b4e24f

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

rustsbi-qemu/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ mod runtime;
2121
mod test_device;
2222

2323
use buddy_system_allocator::LockedHeap;
24-
use core::panic::PanicInfo;
2524
use core::arch::asm;
25+
use core::panic::PanicInfo;
2626

2727
const PER_HART_STACK_SIZE: usize = 4 * 4096; // 16KiB
2828
const SBI_STACK_SIZE: usize = 8 * PER_HART_STACK_SIZE; // assume 8 cores in QEMU
@@ -61,7 +61,10 @@ extern "C" fn rust_main(hartid: usize, opqaue: usize) -> ! {
6161
init_legacy_stdio();
6262
init_clint();
6363
init_test_device();
64-
println!("[rustsbi] RustSBI version {}", rustsbi::VERSION);
64+
println!(
65+
"[rustsbi] RustSBI version {}, adapting to RISC-V SBI v0.3",
66+
rustsbi::VERSION
67+
);
6568
println!("{}", rustsbi::LOGO);
6669
println!(
6770
"[rustsbi] Implementation: RustSBI-QEMU Version {}",
@@ -78,6 +81,11 @@ extern "C" fn rust_main(hartid: usize, opqaue: usize) -> ! {
7881
unsafe {
7982
// enable wake by ipi
8083
riscv::register::mstatus::set_mie();
84+
// enable H extension
85+
asm!(
86+
"csrr {val}, misa", "li {h}, 0x80", "or {val}, {val}, {h}", "csrw misa, {val}",
87+
val = lateout(reg) _, h = lateout(reg) _
88+
);
8189
}
8290
if hartid == 0 {
8391
// print hart csr configuration
@@ -92,6 +100,7 @@ extern "C" fn rust_main(hartid: usize, opqaue: usize) -> ! {
92100
}
93101
println!("[rustsbi] enter supervisor 0x80200000");
94102
}
103+
// start SBI environment
95104
execute::execute_supervisor(0x80200000, hartid, opqaue, HSM.clone());
96105
}
97106

rustsbi-qemu/src/test_device.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
// This is a test finisher memory mapped device used to exit simulation
44
//
55
// Ref: https://github.com/qemu/qemu/blob/master/hw/misc/sifive_test.c
6-
use rustsbi::{Reset, SbiRet, reset::{
7-
RESET_TYPE_SHUTDOWN, RESET_TYPE_COLD_REBOOT, RESET_TYPE_WARM_REBOOT,
8-
RESET_REASON_NO_REASON, RESET_REASON_SYSTEM_FAILURE
9-
}};
6+
use rustsbi::{
7+
reset::{
8+
RESET_REASON_NO_REASON, RESET_REASON_SYSTEM_FAILURE, RESET_TYPE_COLD_REBOOT,
9+
RESET_TYPE_SHUTDOWN, RESET_TYPE_WARM_REBOOT,
10+
},
11+
Reset, SbiRet,
12+
};
1013

1114
// Zero sized structure for a static write-only device
1215
pub struct SiFiveTest;
@@ -26,7 +29,7 @@ impl Reset for SiFiveTest {
2629
RESET_TYPE_SHUTDOWN => match reset_reason {
2730
RESET_REASON_NO_REASON => TEST_PASS,
2831
RESET_REASON_SYSTEM_FAILURE => TEST_FAIL | (QEMU_ERR_EXIT_CODE << 16),
29-
// pass unknown reason from [2, 0xFFFF] to qemu return value output
32+
// pass unknown reason from [2, 0xFFFF] to qemu return value output
3033
// reason if reason <= 0xFFFF => TEST_FAIL | (((reason & 0xFFFF) as u32) << 16),
3134
_ => return SbiRet::invalid_param(),
3235
},

test-kernel/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
7676
}
7777

7878
extern "C" fn hart_2_resume(hart_id: usize, param: usize) {
79-
println!("<< The parameter passed to hart {} resume is: {:#x}", hart_id, param);
79+
println!(
80+
"<< The parameter passed to hart {} resume is: {:#x}",
81+
hart_id, param
82+
);
8083
let param = 0x12345678;
8184
println!(">> Start hart 3 with parameter {:#x}", param);
8285
/* start_addr should be physical address, and here pa == va */
@@ -86,7 +89,10 @@ extern "C" fn hart_2_resume(hart_id: usize, param: usize) {
8689
}
8790

8891
extern "C" fn hart_3_start(hart_id: usize, param: usize) {
89-
println!("<< The parameter passed to hart {} start is: {:#x}", hart_id, param);
92+
println!(
93+
"<< The parameter passed to hart {} start is: {:#x}",
94+
hart_id, param
95+
);
9096
println!("<< Test-kernel: All hart SBI test SUCCESS, shutdown");
9197
sbi::shutdown()
9298
}

test-kernel/src/sbi.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(unused)]
2-
use core::fmt;
32
use core::arch::asm;
3+
use core::fmt;
44

55
pub const EXTENSION_BASE: usize = 0x10;
66
pub const EXTENSION_TIMER: usize = 0x54494D45;
@@ -97,11 +97,21 @@ pub const RESET_REASON_SYSTEM_FAILURE: usize = 0x0000_0001;
9797

9898
#[inline]
9999
pub fn reset(reset_type: usize, reset_reason: usize) -> SbiRet {
100-
sbi_call_2(EXTENSION_SRST, FUNCTION_SYSTEM_RESET, reset_type, reset_reason)
100+
sbi_call_2(
101+
EXTENSION_SRST,
102+
FUNCTION_SYSTEM_RESET,
103+
reset_type,
104+
reset_reason,
105+
)
101106
}
102107

103108
pub fn shutdown() -> ! {
104-
sbi_call_2(EXTENSION_SRST, FUNCTION_SYSTEM_RESET, RESET_TYPE_SHUTDOWN, RESET_REASON_NO_REASON);
109+
sbi_call_2(
110+
EXTENSION_SRST,
111+
FUNCTION_SYSTEM_RESET,
112+
RESET_TYPE_SHUTDOWN,
113+
RESET_REASON_NO_REASON,
114+
);
105115
unreachable!()
106116
}
107117

xtask/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,13 @@ fn check_tool<S: AsRef<str>>(tool: S) -> Option<String> {
308308
return Some(format!("riscv64-unknown-elf-{}", tool.as_ref()));
309309
}
310310
}
311-
println!("
311+
println!(
312+
"
312313
No binutils found, try install using:
313314
314315
rustup component add llvm-tools-preview
315-
cargo install cargo-binutils");
316+
cargo install cargo-binutils"
317+
);
316318
return None;
317319
}
318320

0 commit comments

Comments
 (0)