Skip to content

Commit 05cbb4d

Browse files
authored
Merge pull request #27 from YdrMaster/main
Improve backward comptability to older QEMU; fix issue on not producing time interrupt on machine mode
2 parents e5ab409 + 62bee35 commit 05cbb4d

File tree

12 files changed

+168
-147
lines changed

12 files changed

+168
-147
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"rust.all_targets": false,
77
// For Rust Analyzer plugin users:
88
"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",
9-
"rust-analyzer.checkOnSave.enable": false,
9+
"rust-analyzer.checkOnSave.allTargets": false,
1010
// Other settings
1111
// For clap
1212
"rust-analyzer.procMacro.attributes.enable": true,

Cargo.lock

Lines changed: 27 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustsbi-qemu/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rustsbi = { git = "https://github.com/YdrMaster/rustsbi.git", rev = "bd3c092" }
9+
rustsbi = { git = "https://github.com/rustsbi/rustsbi", rev = "af60b02", features = [
10+
"legacy",
11+
] }
1012
riscv = "0.8"
1113
spin = "0.9"
1214
r0 = "1"
1315
uart_16550 = "0.2"
14-
dtb-walker = "0.1.1"
16+
dtb-walker = "=0.2.0-alpha.3"
1517
qemu-exit = "3.0"

rustsbi-qemu/src/clint.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ impl Timer for Clint {
5555
#[inline]
5656
fn set_timer(&self, time_value: u64) {
5757
unsafe {
58+
riscv::register::mip::clear_stimer();
59+
riscv::register::mie::set_mtimer();
5860
((self.base as *mut u8).offset(0x4000) as *mut u64)
5961
.add(hart_id())
6062
.write_volatile(time_value);

rustsbi-qemu/src/device_tree.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ impl<const N: usize> Display for StringInline<N> {
2727

2828
/// 解析设备树。
2929
pub(crate) fn parse(opaque: usize) -> BoardInfo {
30-
use dtb_walker::{Dtb, DtbObj, Property, WalkOperation::*};
31-
const CPUS: &[u8] = b"cpus";
32-
const MEMORY: &[u8] = b"memory";
33-
const SOC: &[u8] = b"soc";
34-
const UART: &[u8] = b"uart";
35-
const TEST: &[u8] = b"test";
36-
const CLINT: &[u8] = b"clint";
30+
use dtb_walker::{Dtb, DtbObj, HeaderError as E, Property, Str, WalkOperation::*};
31+
const CPUS: &str = "cpus";
32+
const MEMORY: &str = "memory";
33+
const SOC: &str = "soc";
34+
const UART: &str = "uart";
35+
const TEST: &str = "test";
36+
const CLINT: &str = "clint";
3737

3838
let mut ans = BoardInfo {
3939
dtb: opaque..opaque,
@@ -44,37 +44,42 @@ pub(crate) fn parse(opaque: usize) -> BoardInfo {
4444
test: 0..0,
4545
clint: 0..0,
4646
};
47-
let dtb = unsafe { Dtb::from_raw_parts(opaque as _) }.unwrap();
47+
let dtb = unsafe {
48+
Dtb::from_raw_parts_filtered(opaque as _, |e| {
49+
matches!(e, E::Misaligned(4) | E::LastCompVersion(16))
50+
})
51+
}
52+
.unwrap();
4853
ans.dtb.end += dtb.total_size();
49-
dtb.walk(|path, obj| match obj {
54+
dtb.walk(|ctx, obj| match obj {
5055
DtbObj::SubNode { name } => {
51-
let current = path.last();
52-
if current.is_empty() {
53-
if name == CPUS || name == SOC || name.starts_with(MEMORY) {
56+
let current = ctx.name();
57+
if ctx.is_root() {
58+
if name == Str::from(CPUS) || name == Str::from(SOC) || name.starts_with(MEMORY) {
5459
StepInto
5560
} else {
5661
StepOver
5762
}
58-
} else if current == SOC {
63+
} else if current == Str::from(SOC) {
5964
if name.starts_with(UART) || name.starts_with(TEST) || name.starts_with(CLINT) {
6065
StepInto
6166
} else {
6267
StepOver
6368
}
6469
} else {
65-
if current == CPUS && name.starts_with(b"cpu@") {
70+
if current == Str::from(CPUS) && name.starts_with("cpu@") {
6671
ans.smp += 1;
6772
}
6873
StepOver
6974
}
7075
}
71-
DtbObj::Property(Property::Model(model)) if path.last().is_empty() => {
76+
DtbObj::Property(Property::Model(model)) if ctx.is_root() => {
7277
ans.model.0 = model.as_bytes().len();
7378
ans.model.1[..ans.model.0].copy_from_slice(model.as_bytes());
7479
StepOver
7580
}
7681
DtbObj::Property(Property::Reg(mut reg)) => {
77-
let node = path.last();
82+
let node = ctx.name();
7883
if node.starts_with(UART) {
7984
ans.uart = reg.next().unwrap();
8085
StepOut

0 commit comments

Comments
 (0)