Skip to content

Commit 207fe36

Browse files
committed
feat(riscv platform vf2): vf2 platform adapted to riscv architecture
- Add necessary platform driver support - Modify some startup processes and assert - Fixed some issues Signed-off-by: JensenWei007 <[email protected]>
1 parent 8aa3b7c commit 207fe36

File tree

15 files changed

+1694
-23
lines changed

15 files changed

+1694
-23
lines changed

kernel/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ x86_64 = "=0.14.10"
9898
riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", rev = "4241a97", features = [
9999
"s-mode",
100100
] }
101+
byte-slice-cast = { version = "1.2.2", default-features = false }
101102
sbi-rt = { version = "=0.0.3", features = ["legacy"] }
102103

103104
# target为loongarch64时,使用下面的依赖
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod of;
22
pub mod sbi;
3+
pub mod vf2;

kernel/src/arch/riscv64/driver/sbi.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ use core::ptr::addr_of;
2020
/// console_putstr(message);
2121
/// ```
2222
pub fn console_putstr(s: &[u8]) {
23-
if SbiDriver::extensions().contains(SBIExtensions::CONSOLE) {
24-
for c in s {
25-
sbi_rt::console_write_byte(*c);
26-
}
27-
return;
28-
} else {
29-
for c in s {
30-
#[allow(deprecated)]
31-
sbi_rt::legacy::console_putchar(*c as usize);
23+
// 原本的是适配opensbi的, 但是对rustsbi的适配存在问题, 不能正确的解析'\r'
24+
for &c in s {
25+
match c {
26+
b'\n' => {
27+
#[allow(deprecated)]
28+
sbi_rt::legacy::console_putchar(b'\r' as usize);
29+
#[allow(deprecated)]
30+
sbi_rt::legacy::console_putchar(b'\n' as usize);
31+
}
32+
b'\r' => {
33+
#[allow(deprecated)]
34+
sbi_rt::legacy::console_putchar(b'\r' as usize);
35+
}
36+
_ => {
37+
#[allow(deprecated)]
38+
sbi_rt::legacy::console_putchar(c as usize);
39+
}
3240
}
3341
}
3442
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use bitfield_struct::bitfield;
2+
3+
#[bitfield(u32)]
4+
pub struct DES0 {
5+
_reserved0: bool,
6+
disable_interrupt_on_completion: bool,
7+
last_decriptor: bool,
8+
first_descriptor: bool,
9+
second_address_chained: bool,
10+
end_of_ring: bool,
11+
#[bits(24)]
12+
_reserved1: usize,
13+
card_error_summary: bool,
14+
15+
// Is owned by the card.
16+
own: bool,
17+
}
18+
#[bitfield(u32)]
19+
pub struct DES1 {
20+
#[bits(13)]
21+
buffer_1_size: usize,
22+
#[bits(13)]
23+
buffer_2_size: usize,
24+
#[bits(6)]
25+
_reserved0: usize,
26+
}
27+
#[bitfield(u32)]
28+
pub struct DES2 {
29+
#[bits(32)]
30+
pub buffer_addr1: usize,
31+
}
32+
#[bitfield(u32)]
33+
pub struct DES3 {
34+
#[bits(32)]
35+
pub buffer_addr2: usize,
36+
}
37+
38+
#[repr(C)]
39+
#[derive(Debug, Copy, Clone)]
40+
pub struct Descriptor {
41+
pub des0: DES0,
42+
pub des1: DES1,
43+
pub des2: DES2,
44+
pub des3: DES3,
45+
}
46+
47+
#[allow(dead_code)]
48+
impl Descriptor {
49+
pub fn new(size: usize, buffer_paddr: usize, next_paddr: usize) -> Self {
50+
Descriptor {
51+
des0: DES0::new().with_second_address_chained(true).with_own(true),
52+
des1: DES1::new().with_buffer_1_size(size),
53+
des2: DES2::new().with_buffer_addr1(buffer_paddr),
54+
des3: DES3::new().with_buffer_addr2(next_paddr),
55+
}
56+
}
57+
pub fn own_by_card(&self) -> bool {
58+
self.des0.own()
59+
}
60+
pub fn set_own_by_card(&mut self) {
61+
self.des0.set_own(true);
62+
}
63+
}

0 commit comments

Comments
 (0)