Skip to content

Commit 52acbbf

Browse files
committed
fix: 在 entry 重设 a0 = mhartid
1 parent a6c8f38 commit 52acbbf

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

rustsbi-qemu/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ unsafe extern "C" fn entry(hartid: usize, opaque: usize) -> ! {
7070

7171
core::arch::asm!("
7272
csrw mie, zero
73+
csrr a0, mhartid
7374
la sp, {stack}
7475
li t0, {per_hart_stack_size}
7576
addi t1, a0, 1
@@ -134,12 +135,14 @@ extern "C" fn rust_main(_hartid: usize, opaque: usize) {
134135
// 解析设备树,需要堆来保存结果里的字符串等
135136
let board_info = BOARD_INFO.call_once(|| device_tree::parse(opaque));
136137
// 初始化外设
138+
rustsbi::legacy_stdio::init_legacy_stdio(
139+
SERIAL.call_once(|| unsafe { ns16550a::Ns16550a::new(board_info.uart.start) }),
140+
);
141+
137142
clint::init(board_info.clint.start);
138143
test_device::init(board_info.test.start);
139-
let serial = SERIAL.call_once(|| unsafe { ns16550a::Ns16550a::new(board_info.uart.start) });
140144
let hsm = HSM.call_once(|| qemu_hsm::QemuHsm::new(clint::get(), NUM_HART_MAX, opaque));
141145
// 初始化 SBI 服务
142-
rustsbi::legacy_stdio::init_legacy_stdio(serial);
143146
rustsbi::init_ipi(clint::get());
144147
rustsbi::init_timer(clint::get());
145148
rustsbi::init_reset(test_device::get());

test-kernel/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ pub(crate) fn start_stop_harts(hartid: usize, smp: usize) {
103103

104104
extern "C" fn secondary_rust_main(hart_id: usize) -> ! {
105105
BARRIER.wait().wait();
106-
println!("stop [{hart_id}] but {:?}", sbi::hart_stop());
107-
unreachable!()
106+
let ret = sbi::hart_stop();
107+
unreachable!("stop [{hart_id}] but {ret:?}");
108108
}
109109

110110
println!(

xtask/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn xtask_qemu_run(xtask_env: &XtaskEnv) {
216216
.args(&["-machine", "virt"])
217217
.args(&["-bios", "rustsbi-qemu.bin"])
218218
.args(&["-kernel", "test-kernel.bin"])
219-
.args(&["-smp", "3"]) // 8 cores
219+
.args(&["-smp", "8"]) // 8 cores
220220
.arg("-nographic")
221221
.status()
222222
.unwrap();
@@ -233,7 +233,7 @@ fn xtask_qemu_debug(xtask_env: &XtaskEnv) {
233233
.args(&["-machine", "virt"])
234234
.args(&["-bios", "rustsbi-qemu.bin"])
235235
.args(&["-kernel", "test-kernel.bin"])
236-
.args(&["-smp", "3"]) // 8 cores
236+
.args(&["-smp", "8"]) // 8 cores
237237
.arg("-nographic")
238238
.args(&["-gdb", "tcp::1234", "-S"])
239239
.status()

0 commit comments

Comments
 (0)