Skip to content

Commit 2f94aa0

Browse files
committed
fix: argument 0 is hart id, argument 1 is opaque
1 parent dd8e89f commit 2f94aa0

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

rustsbi-qemu/src/execute.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use riscv::register::{
1010
scause::{Exception, Trap},
1111
};
1212

13-
pub fn execute_supervisor(supervisor_mepc: usize, a0: usize, a1: usize, hsm: QemuHsm) -> ! {
14-
let mut rt = Runtime::new_sbi_supervisor(supervisor_mepc, a0, a1);
13+
pub fn execute_supervisor(supervisor_mepc: usize, hart_id: usize, a1: usize, hsm: QemuHsm) -> ! {
14+
let mut rt = Runtime::new_sbi_supervisor(supervisor_mepc, hart_id, a1);
1515
hsm.record_current_start_finished();
1616
loop {
1717
match Pin::new(&mut rt).resume(()) {
@@ -28,7 +28,8 @@ pub fn execute_supervisor(supervisor_mepc: usize, a0: usize, a1: usize, hsm: Qem
2828
}
2929
hsm.record_current_start_finished();
3030
ctx.mstatus = riscv::register::mstatus::read(); // get from modified sstatus
31-
ctx.a0 = opaque;
31+
ctx.a0 = hart_id;
32+
ctx.a1 = opaque;
3233
ctx.mepc = start_paddr;
3334
}
3435
} else {
@@ -67,14 +68,26 @@ pub fn execute_supervisor(supervisor_mepc: usize, a0: usize, a1: usize, hsm: Qem
6768
hsm.record_current_stop_finished();
6869
pause();
6970
if let Some(HsmCommand::Start(start_paddr, opaque)) = hsm.last_command() {
71+
// Resuming from a non-retentive suspend state is relatively more involved and requires software
72+
// to restore various hart registers and CSRs for all privilege modes.
73+
// Upon resuming from non-retentive suspend state, the hart will jump to supervisor-mode at address
74+
// specified by `resume_addr` with specific registers values described in the table below:
75+
//
76+
// | Register Name | Register Value
77+
// |:--------------|:--------------
78+
// | `satp` | 0
79+
// | `sstatus.SIE` | 0
80+
// | a0 | hartid
81+
// | a1 | `opaque` parameter
7082
unsafe {
7183
riscv::register::satp::write(0);
7284
riscv::register::sstatus::clear_sie();
7385
}
7486
hsm.record_current_start_finished();
7587
let ctx = rt.context_mut();
7688
ctx.mstatus = riscv::register::mstatus::read(); // get from modified sstatus
77-
ctx.a0 = opaque;
89+
ctx.a0 = hart_id;
90+
ctx.a1 = opaque;
7891
ctx.mepc = start_paddr;
7992
}
8093
}

rustsbi-qemu/src/qemu_hsm.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,6 @@ impl rustsbi::Hsm for QemuHsm {
230230
}
231231
// Resuming from a non-retentive suspend state is relatively more involved and requires software
232232
// to restore various hart registers and CSRs for all privilege modes.
233-
// Upon resuming from non-retentive suspend state, the hart will jump to supervisor-mode at address
234-
// specified by `resume_addr` with specific registers values described in the table below:
235-
//
236-
// | Register Name | Register Value
237-
// |:--------------|:--------------
238-
// | `satp` | 0
239-
// | `sstatus.SIE` | 0
240-
// | a0 | hartid
241-
// | a1 | `opaque` parameter
242233
SUSPEND_NON_RETENTIVE => {
243234
// try to set current target hart state to stop pending
244235
let hart_id = riscv::register::mhartid::read();

test-kernel/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
7474
}
7575
}
7676

77-
extern "C" fn hart_2_resume(param: usize) {
78-
println!("<< The parameter passed to hart 2 resume is: {:#x}", param);
77+
extern "C" fn hart_2_resume(hart_id: usize, param: usize) {
78+
println!("<< The parameter passed to hart {} resume is: {:#x}", hart_id, param);
7979
let param = 0x12345678;
8080
println!(">> Start hart 3 with parameter {:#x}", param);
8181
/* start_addr should be physical address, and here pa == va */
@@ -84,8 +84,8 @@ extern "C" fn hart_2_resume(param: usize) {
8484
loop {} // wait for machine shutdown
8585
}
8686

87-
extern "C" fn hart_3_start(param: usize) {
88-
println!("<< The parameter passed to hart 3 start is: {:#x}", param);
87+
extern "C" fn hart_3_start(hart_id: usize, param: usize) {
88+
println!("<< The parameter passed to hart {} start is: {:#x}", hart_id, param);
8989
println!("<< Test-kernel: All hart SBI test SUCCESS, shutdown");
9090
sbi::shutdown()
9191
}

0 commit comments

Comments
 (0)