Skip to content

Commit 31d7e41

Browse files
authored
Merge branch 'main' into multicore
2 parents 666f3fd + ab6b260 commit 31d7e41

File tree

10 files changed

+293
-105
lines changed

10 files changed

+293
-105
lines changed

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// Prevent "can't find crate for `test`" error on no_std
3+
// 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:
8+
"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",
9+
"rust-analyzer.checkOnSave.allTargets": false
10+
}

Cargo.lock

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

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,31 @@ cargo qemu
99
When running `cargo qemu`, the test kernel will build and run. Expected output should be:
1010

1111
```
12+
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
13+
Running `target\debug\xtask.exe qemu`
1214
xtask: mode: Debug
13-
Compiling rustsbi-qemu v0.1.0 (D:\RustProjects\rustsbi-qemu\rustsbi-qemu)
14-
Finished dev [unoptimized + debuginfo] target(s) in 1.09s
15-
Finished dev [unoptimized + debuginfo] target(s) in 0.23s
16-
[rustsbi] RustSBI version 0.2.0-alpha.3
15+
Compiling rustsbi-qemu v0.0.2 (D:\RustSBI\rustsbi-qemu\rustsbi-qemu)
16+
Finished dev [unoptimized + debuginfo] target(s) in 0.44s
17+
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
18+
[rustsbi] RustSBI version 0.2.0-alpha.7
1719
.______ __ __ _______.___________. _______..______ __
1820
| _ \ | | | | / | | / || _ \ | |
1921
| |_) | | | | | | (----`---| |----`| (----`| |_) || |
2022
| / | | | | \ \ | | \ \ | _ < | |
2123
| |\ \----.| `--' |.----) | | | .----) | | |_) || |
2224
| _| `._____| \______/ |_______/ |__| |_______/ |______/ |__|
2325
24-
[rustsbi] Implementation: RustSBI-QEMU Version 0.0.1
25-
[rustsbi-dtb] Hart count: cluster0 with 1 cores
26+
[rustsbi] Implementation: RustSBI-QEMU Version 0.0.2
27+
[rustsbi-dtb] Hart count: cluster0 with 8 cores
2628
[rustsbi] misa: RV64ACDFIMSU
2729
[rustsbi] mideleg: ssoft, stimer, sext (0x222)
2830
[rustsbi] medeleg: ima, ia, bkpt, la, sa, uecall, ipage, lpage, spage (0xb1ab)
29-
[rustsbi] pmp0: 0x80000000 ..= 0x800fffff (rwx)
30-
[rustsbi] pmp1: 0x80200000 ..= 0x802fffff (rwx)
31-
[rustsbi] pmp2: 0x0 ..= 0xfffffffffffffffc (---)
31+
[rustsbi] pmp0: 0x10000000 ..= 0x10001fff (rwx)
32+
[rustsbi] pmp1: 0x80000000 ..= 0x8fffffff (rwx)
33+
[rustsbi] pmp2: 0x0 ..= 0xffffffffffffff (---)
34+
D:\Applications\Scoop\apps\qemu\current\qemu-system-riscv64.exe: clint: invalid write: 00000020
3235
[rustsbi] enter supervisor 0x80200000
33-
<< Test-kernel: Hart id = 0, DTB physical address = 0x87e00000
36+
<< Test-kernel: Hart id = 0, DTB physical address = 0x87000000
3437
>> Test-kernel: Testing base extension
3538
<< Test-kernel: Base extension version: 1
3639
<< Test-kernel: SBI specification version: 2
@@ -40,11 +43,25 @@ xtask: mode: Debug
4043
<< Test-kernel: Device marchid: 0
4144
<< Test-kernel: Device mimpid: 0
4245
>> Test-kernel: Testing SBI instruction emulation
43-
<< Test-kernel: Current time: 31918a
46+
<< Test-kernel: Current time: d1540
47+
<< Test-kernel: Time after operation: d407b
4448
>> Test-kernel: Trigger illegal exception
4549
<< Test-kernel: Value of scause: Exception(IllegalInstruction)
4650
<< Test-kernel: Illegal exception delegate success
47-
<< Test-kernel: SBI test SUCCESS, shutdown
51+
>> Stop hart 3, return value 0
52+
>> Hart 0 state return value: 0
53+
>> Hart 1 state return value: 4
54+
>> Hart 2 state return value: 4
55+
>> Hart 3 state return value: 1
56+
<< Test-kernel: test for hart 0 success, wake another hart
57+
>> Wake hart 1, sbi return value 0
58+
>> Start test for hart 1, retentive suspend return value 0
59+
>> Wake hart 2, sbi return value 0
60+
<< The parameter passed to hart 2 resume is: 0x4567890a
61+
>> Start hart 3 with parameter 0x12345678
62+
>> SBI return value: 0
63+
<< The parameter passed to hart 3 start is: 0x12345678
64+
<< Test-kernel: All hart SBI test SUCCESS, shutdown
4865
```
4966

5067
## Run test kernel

rustsbi-qemu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rustsbi = { version = "0.2.0-alpha.6" }
9+
rustsbi = { version = "0.2.0-alpha.7" }
1010
buddy_system_allocator = "0.8"
1111
lazy_static = { version = "1", features = ["spin_no_std"] }
1212
spin = "0.9"

rustsbi-qemu/src/execute.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,22 @@ pub fn execute_supervisor(supervisor_mepc: usize, a0: usize, a1: usize, hsm: Qem
1919
let ctx = rt.context_mut();
2020
let param = [ctx.a0, ctx.a1, ctx.a2, ctx.a3, ctx.a4, ctx.a5];
2121
let ans = rustsbi::ecall(ctx.a7, ctx.a6, param);
22-
ctx.a0 = ans.error;
23-
ctx.a1 = ans.value;
24-
ctx.mepc = ctx.mepc.wrapping_add(4);
22+
if ans.error == 0x233 { // hart non-retentive resume
23+
if let Some(HsmCommand::Start(start_paddr, opaque)) = hsm.last_command() {
24+
unsafe {
25+
riscv::register::satp::write(0);
26+
riscv::register::sstatus::clear_sie();
27+
}
28+
hsm.record_current_start_finished();
29+
ctx.mstatus = riscv::register::mstatus::read(); // get from modified sstatus
30+
ctx.a0 = opaque;
31+
ctx.mepc = start_paddr;
32+
}
33+
} else {
34+
ctx.a0 = ans.error;
35+
ctx.a1 = ans.value;
36+
ctx.mepc = ctx.mepc.wrapping_add(4);
37+
}
2538
}
2639
GeneratorState::Yielded(MachineTrap::IllegalInstruction()) => {
2740
let ctx = rt.context_mut();
@@ -45,38 +58,24 @@ pub fn execute_supervisor(supervisor_mepc: usize, a0: usize, a1: usize, hsm: Qem
4558
mie::clear_mtimer();
4659
},
4760
GeneratorState::Yielded(MachineTrap::MachineSoft()) => match hsm.last_command() {
48-
Some(HsmCommand::Start(start_addr, opaque)) => {
49-
unsafe {
50-
riscv::register::satp::write(0);
51-
riscv::register::sstatus::clear_sie();
52-
}
53-
hsm.record_current_start_finished();
54-
match () {
55-
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
56-
() => unsafe {
57-
asm!(
58-
"csrr a0, mhartid",
59-
"jr {start_addr}",
60-
start_addr = in(reg) start_addr,
61-
in("a1") opaque,
62-
options(noreturn)
63-
)
64-
},
65-
#[cfg(not(any(target_arch = "riscv32", target_arch = "riscv64")))]
66-
() => {
67-
drop((start_addr, opaque));
68-
unimplemented!("not RISC-V instruction set architecture")
69-
}
70-
};
71-
}
61+
Some(HsmCommand::Start(_start_paddr, _opaque)) => panic!("rustsbi-qemu: illegal state"),
7262
Some(HsmCommand::Stop) => {
7363
// no hart stop command in qemu, record stop state and pause
7464
hsm.record_current_stop_finished();
7565
pause();
76-
}
77-
None => panic!(
78-
"rustsbi-qemu: machine soft interrupt with no hart state monitor command"
79-
),
66+
if let Some(HsmCommand::Start(start_paddr, opaque)) = hsm.last_command() {
67+
unsafe {
68+
riscv::register::satp::write(0);
69+
riscv::register::sstatus::clear_sie();
70+
}
71+
hsm.record_current_start_finished();
72+
let ctx = rt.context_mut();
73+
ctx.mstatus = riscv::register::mstatus::read(); // get from modified sstatus
74+
ctx.a0 = opaque;
75+
ctx.mepc = start_paddr;
76+
}
77+
},
78+
None => panic!("rustsbi-qemu: machine soft interrupt with no hart state monitor command"),
8079
},
8180
GeneratorState::Complete(()) => {
8281
use rustsbi::Reset;

rustsbi-qemu/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_std]
22
#![no_main]
33
#![feature(naked_functions)]
4-
#![feature(asm)]
4+
#![feature(asm, asm_sym, asm_const)]
55
#![feature(generator_trait)]
66
#![feature(default_alloc_error_handler)]
77

@@ -122,7 +122,7 @@ fn init_test_device() {
122122
init_reset(test_device::Reset);
123123
}
124124

125-
// 委托终端;把S的中断全部委托给S层
125+
// 委托中断;把S的中断全部委托给S层
126126
fn delegate_interrupt_exception() {
127127
use riscv::register::{medeleg, mideleg, mie};
128128
unsafe {
@@ -149,6 +149,8 @@ fn delegate_interrupt_exception() {
149149

150150
fn set_pmp() {
151151
// todo: 根据QEMU的loader device等等,设置这里的权限配置
152+
// read fdt tree value, parse, and calculate proper pmp configuration for this device tree (issue #7)
153+
// integrate with `count_harts`
152154
unsafe {
153155
asm!(
154156
"li {tmp}, ((0x08 << 16) | (0x1F << 8) | (0x1F << 0) )", // 0 = NAPOT,ARWX; 1 = NAPOT,ARWX; 2 = TOR,A;

0 commit comments

Comments
 (0)