Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/axhal/src/percpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ pub(crate) fn init_primary(cpu_id: usize) {
CPU_ID.write_current_raw(cpu_id);
IS_BSP.write_current_raw(true);
}
#[cfg(all(feature = "irq", target_arch = "riscv64"))]
{
axplat_riscv64_qemu_virt::register_this_cpu_id(this_cpu_id);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it’s essential on other riscv64 plat? I mean directly use axplat_riscv64_qemu_virt api here,it only works on this platform?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I feel sorry that I didn't consider other riscv64 plat right now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platforms/axplat-riscv64-qemu-virt/src/init.rs
maybe it should put here

Copy link
Copy Markdown

@AsakuraMizu AsakuraMizu Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platforms/axplat-riscv64-qemu-virt/src/init.rs maybe it should put here

That falls back to the same problem. The fundamental issue is that there's currently no way to obtain the CPU ID in axplat.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? PlatinitIf has cpu_id param? Doesn’t it?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? PlatinitIf has cpu_id param? Doesn’t it?

I apologize for the inaccuracy in my statement. The exact issue is that there's currently no way to obtain the hart ID at https://github.com/Starry-OS/axplat_crates/blob/main/platforms/axplat-riscv64-qemu-virt/src/irq.rs#L192.

}
}

#[allow(dead_code)]
Expand All @@ -89,4 +93,8 @@ pub(crate) fn init_secondary(cpu_id: usize) {
CPU_ID.write_current_raw(cpu_id);
IS_BSP.write_current_raw(false);
}
#[cfg(all(feature = "irq", target_arch = "riscv64"))]
{
axplat_riscv64_qemu_virt::register_this_cpu_id(this_cpu_id);
}
}
3 changes: 3 additions & 0 deletions modules/axruntime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ chrono = { workspace = true, optional = true }
crate_interface = { workspace = true }
indoc = "2"
percpu = { workspace = true, optional = true }

[target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies]
riscv = "0.14"
5 changes: 5 additions & 0 deletions modules/axruntime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! {
core::hint::spin_loop();
}

#[cfg(target_arch = "riscv64")]
unsafe {
use riscv::register::sstatus;
sstatus::set_sum();
}
Comment on lines +249 to +253
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this part should be moved into https://github.com/Starry-OS/axcpu/blob/main/src/riscv/init.rs. You may take a look at Starry-OS/axcpu#8, where they also encountered a similar issue to enable user memory access in supervisor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I will modify it later.

unsafe { main() };

#[cfg(feature = "multitask")]
Expand Down
8 changes: 8 additions & 0 deletions modules/axruntime/src/mp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ pub fn rust_main_secondary(cpu_id: usize) -> ! {
#[cfg(feature = "ipi")]
axipi::init();

#[cfg(target_arch = "riscv64")]
{
use riscv::register::sstatus;
unsafe {
sstatus::set_sum();
}
}

Comment on lines +54 to +61
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

info!("Secondary CPU {:x} init OK.", cpu_id);
super::INITED_CPUS.fetch_add(1, Ordering::Release);

Expand Down