Skip to content

Commit aacf2af

Browse files
committed
fix: use wfi for all suspend
Signed-off-by: YdrMaster <ydrml@hotmail.com>
1 parent 050f55e commit aacf2af

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
// Prevent "can't find crate for `test`" error on no_std
33
// Ref: https://github.com/rust-lang/vscode-rust/issues/729
4-
// For vscode-rust plugin users:
5-
"rust.target": "riscv64imac-unknown-none-elf",
6-
"rust.all_targets": false,
7-
// For Rust Analyzer plugin users:
84
"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",
95
"rust-analyzer.checkOnSave.allTargets": false,
106
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919
- Use crate aclint version 0.0.0 in rustsbi-qemu for aclint structs
2020
- Use crate os-xtask-utils version 0.0.0 in xtask builder
2121
- Use crate sifive-test-device version 0.0.0 instead of qemu-exit
22+
- Use `wfi` without enable mie
2223

2324
### Fixed
2425

rustsbi-qemu/src/main.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ extern "C" fn fast_handler(
214214
});
215215
mie::write(mie::MSIE | mie::MTIE);
216216
trap_vec::load(true);
217+
unsafe {
218+
riscv::register::sstatus::clear_sie();
219+
riscv::register::satp::write(0);
220+
}
217221
ctx.regs().a[0] = hart_id;
218222
ctx.regs().a[1] = supervisor.opaque;
219223
ctx.regs().pc = supervisor.start_addr;
@@ -254,8 +258,13 @@ extern "C" fn fast_handler(
254258
if a6 == hsm::HART_SUSPEND
255259
&& ctx.a0() == hsm::HART_SUSPEND_TYPE_NON_RETENTIVE as usize
256260
{
257-
trap_vec::load(false);
258-
ctx.regs().pc = _stop as _;
261+
unsafe {
262+
riscv::register::sstatus::clear_sie();
263+
riscv::register::satp::write(0);
264+
}
265+
ctx.regs().a[0] = hart_id();
266+
ctx.regs().a[1] = a2;
267+
ctx.regs().pc = a1;
259268
return ctx.call(0);
260269
}
261270
}
@@ -389,23 +398,18 @@ impl rustsbi::Hsm for Hsm {
389398
}
390399
}
391400

392-
fn hart_suspend(&self, suspend_type: u32, resume_addr: usize, opaque: usize) -> SbiRet {
393-
use rustsbi::spec::hsm as spec;
394-
match suspend_type {
395-
spec::HART_SUSPEND_TYPE_NON_RETENTIVE => {
396-
local_hsm().suspend_non_retentive(Supervisor {
397-
start_addr: resume_addr,
398-
opaque,
399-
});
400-
SbiRet::success(0)
401-
}
402-
spec::HART_SUSPEND_TYPE_RETENTIVE => unsafe {
403-
local_hsm().suspend();
404-
riscv::asm::wfi();
405-
local_hsm().resume();
406-
SbiRet::success(0)
407-
},
408-
_ => SbiRet::not_supported(),
401+
fn hart_suspend(&self, suspend_type: u32, _resume_addr: usize, _opaque: usize) -> SbiRet {
402+
use rustsbi::spec::hsm::*;
403+
if matches!(
404+
suspend_type,
405+
HART_SUSPEND_TYPE_NON_RETENTIVE | HART_SUSPEND_TYPE_RETENTIVE
406+
) {
407+
local_hsm().suspend();
408+
unsafe { riscv::asm::wfi() };
409+
local_hsm().resume();
410+
SbiRet::success(0)
411+
} else {
412+
SbiRet::not_supported()
409413
}
410414
}
411415
}

0 commit comments

Comments
 (0)