Skip to content

Commit eec09b1

Browse files
committed
feat(sbi): remove heap & cleanup
1 parent 4875880 commit eec09b1

File tree

6 files changed

+166
-219
lines changed

6 files changed

+166
-219
lines changed

Cargo.lock

Lines changed: 3 additions & 36 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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ readme = "README.md"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
rustsbi = { git = "https://github.com/YdrMaster/rustsbi.git", rev = "e17920b" }
10+
rustsbi = { path = "../../rustsbi" }
1111
riscv = "0.8"
1212
spin = "0.9"
1313
r0 = "1"
14-
buddy_system_allocator = "0.8"
1514
uart_16550 = "0.2"
16-
dtb-walker = { git = "https://github.com/YdrMaster/dtb-walker.git", rev = "0ef2209" }
15+
dtb-walker = { git = "https://github.com/YdrMaster/dtb-walker.git", rev = "43cfda9" }

rustsbi-qemu/src/device_tree.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
use alloc::{string::String, vec, vec::Vec};
2-
use core::ops::Range;
1+
use core::{
2+
fmt::{Display, Formatter, Result},
3+
ops::Range,
4+
};
35

4-
#[derive(Debug)]
6+
/// 从设备树采集的板信息。
57
pub(crate) struct BoardInfo {
68
pub dtb: Range<usize>,
7-
pub model: String,
9+
pub model: StringInline<128>,
810
pub smp: usize,
9-
pub mem: Vec<Range<usize>>,
11+
pub mem: Range<usize>,
1012
pub uart: Range<usize>,
1113
pub test: Range<usize>,
1214
pub clint: Range<usize>,
1315
}
1416

17+
/// 在栈上存储有限长度字符串。
18+
pub(crate) struct StringInline<const N: usize>(usize, [u8; N]);
19+
20+
impl<const N: usize> Display for StringInline<N> {
21+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
22+
write!(f, "{}", unsafe {
23+
core::str::from_utf8_unchecked(&self.1[..self.0])
24+
})
25+
}
26+
}
27+
28+
/// 解析设备树。
1529
pub(crate) fn parse(opaque: usize) -> BoardInfo {
1630
use dtb_walker::{Dtb, DtbObj, Property, WalkOperation::*};
1731
const CPUS: &[u8] = b"cpus";
@@ -23,9 +37,9 @@ pub(crate) fn parse(opaque: usize) -> BoardInfo {
2337

2438
let mut ans = BoardInfo {
2539
dtb: opaque..opaque,
26-
model: String::new(),
40+
model: StringInline(0, [0u8; 128]),
2741
smp: 0,
28-
mem: vec![],
42+
mem: 0..0,
2943
uart: 0..0,
3044
test: 0..0,
3145
clint: 0..0,
@@ -55,9 +69,8 @@ pub(crate) fn parse(opaque: usize) -> BoardInfo {
5569
}
5670
}
5771
DtbObj::Property(Property::Model(model)) if path.last().is_empty() => {
58-
if let Ok(model) = model.as_str() {
59-
ans.model = model.into();
60-
}
72+
ans.model.0 = model.as_bytes().len();
73+
ans.model.1[..ans.model.0].copy_from_slice(model.as_bytes());
6174
StepOver
6275
}
6376
DtbObj::Property(Property::Reg(mut reg)) => {
@@ -72,7 +85,7 @@ pub(crate) fn parse(opaque: usize) -> BoardInfo {
7285
ans.clint = reg.next().unwrap();
7386
StepOut
7487
} else if node.starts_with(MEMORY) {
75-
ans.mem = reg.into_iter().collect();
88+
ans.mem = reg.next().unwrap();
7689
StepOut
7790
} else {
7891
StepOver

0 commit comments

Comments
 (0)