Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fcfe3da
Add RISC-V support and IRQ handling improvements
ZR233 May 26, 2026
de5a67a
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 26, 2026
bda78dc
fix(axvisor): enable riscv64 qemu platform feature in CI
ZR233 May 26, 2026
afdffdb
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 26, 2026
ef54984
fix(axvisor): boot riscv64 dynamic hv
ZR233 May 26, 2026
81da8da
feat(riscv64): support dynamic platform drivers
ZR233 May 26, 2026
ee9cacd
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 27, 2026
9f22f02
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 27, 2026
30fbf97
fix(ax-driver): correct feature handling for plat-static and plat-dyn
ZR233 May 27, 2026
784fa4b
fix(somehal): use runtime CPU id for riscv64 PLIC context
ZR233 May 27, 2026
f33b1dd
fix(build): replace pci driver feature with plat-dyn in configuration
ZR233 May 27, 2026
068a923
Refactor platform feature configurations across various board TOML files
ZR233 May 27, 2026
459e14e
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 27, 2026
201d431
fix(build): remove unnecessary parameter from build_cargo_args call
ZR233 May 27, 2026
8508ed5
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 27, 2026
59410b1
feat: add riscv_goldfish dependency and support for Goldfish RTC
ZR233 May 27, 2026
af3e110
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 27, 2026
4a35043
refactor(smp): replace cpu_idx with early_current_cpu_idx for better …
ZR233 May 27, 2026
dc007ca
Merge remote-tracking branch 'upstream/dev' into feat/rv64-dyn2
ZR233 May 27, 2026
954843b
feat(build): add starry-kernel/input feature to the build configuration
ZR233 May 27, 2026
25f9dbd
refactor(axruntime): remove alloc feature, make it unconditional (#985)
ZR233 May 27, 2026
2109d06
Remove range-alloc-arceos crate and its associated files (#991)
ZCShou May 27, 2026
00b427c
Refactor linker scripts and CI configuration (#992)
ZCShou May 27, 2026
0394eed
feat(deps): update spin to version 0.12.0 and bump other dependencies
ZR233 May 27, 2026
d61404a
Merge branch 'dev' into feat/rv64-dyn2
ZR233 May 27, 2026
d7f95f1
feat: remove riscv64-qemu-virt references and update platform support…
ZR233 May 27, 2026
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
388 changes: 193 additions & 195 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
target = "aarch64-unknown-none-softfloat"
env = {}
features = [
"ax-hal/plat-dyn",
"starry-kernel/plat-dyn",
"ax-driver/irq",
"ax-driver/pci-list-devices",
"ax-driver/list-pci-devices",
"ax-driver/rk3588-pcie",
"ax-driver/realtek-rtl8125",
"ax-driver/rockchip-soc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
target = "aarch64-unknown-none-softfloat"
env = {}
features = [
"ax-hal/plat-dyn",
"starry-kernel/plat-dyn",
"ax-driver/rockchip-soc",
"ax-driver/rockchip-dwc-xhci",
"ax-driver/rockchip-sdhci",
Expand Down
24 changes: 18 additions & 6 deletions components/axcpu/src/exception_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::TrapFrame;
#[repr(C)]
#[derive(Debug, PartialEq, Eq)]
struct ExceptionTableEntry {
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
from: i32,
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
to: i32,
#[cfg(not(target_arch = "aarch64"))]
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
from: usize,
#[cfg(not(target_arch = "aarch64"))]
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
to: usize,
}

Expand All @@ -22,7 +22,13 @@ impl ExceptionTableEntry {
(base + self.from as isize) as usize
}

#[cfg(not(target_arch = "aarch64"))]
#[cfg(target_arch = "riscv64")]
{
let base = unsafe { _ex_table_start.as_ptr() } as isize;
(base + self.from as isize) as usize
}

#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
{
self.from
}
Expand All @@ -36,7 +42,13 @@ impl ExceptionTableEntry {
(base + self.to as isize) as usize
}

#[cfg(not(target_arch = "aarch64"))]
#[cfg(target_arch = "riscv64")]
{
let base = unsafe { _ex_table_start.as_ptr() } as isize;
(base + self.to as isize) as usize
}

#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
{
self.to
}
Expand Down
10 changes: 5 additions & 5 deletions components/axcpu/src/riscv/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ macro_rules! __asm_macros {
.macro _asm_extable, from, to
.pushsection __ex_table, "a"
.balign 4
.word \from
.word \to
.word \from - _ex_table_start
.word \to - _ex_table_start
.popsection
.endm

Expand All @@ -40,9 +40,9 @@ macro_rules! __asm_macros {

.macro _asm_extable, from, to
.pushsection __ex_table, "a"
.balign 8
.quad \from
.quad \to
.balign 4
.word \from - _ex_table_start
.word \to - _ex_table_start
.popsection
.endm

Expand Down
1 change: 1 addition & 0 deletions components/someboot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ efi = []
hv = []
mmu = []
percpu-prealloc = []
thead-mae = []
uspace = ["mmu"]

[dependencies]
Expand Down
3 changes: 1 addition & 2 deletions components/someboot/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ fn main() {
} else if build.uspace {
println!("cargo:rustc-cfg=uspace");
}

if build.page_size == 4096 {
println!("cargo:rustc-cfg=page_size_4k");
} else if build.page_size == 16384 {
Expand Down Expand Up @@ -158,7 +157,7 @@ impl Build {
fn prepare_riscv64(&mut self) {
let ld_src = "src/arch/riscv64/link.ld";

if self.uspace {
if self.uspace || self.hv {
self.kernel_vaddr = 0xffff_ffff_8000_0000;
} else {
self.kernel_vaddr = 0x8020_0000;
Expand Down
5 changes: 5 additions & 0 deletions components/someboot/src/acpi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ fn rsdp() -> Option<NonNull<u8>> {
NonNull::new(ptr)
}

pub fn rsdp_addr_phys() -> Option<usize> {
let rsdp = unsafe { RSDP };
(rsdp != 0).then_some(rsdp)
}

pub fn tables() -> Result<AcpiTables<AcpiHandle>, acpi::AcpiError> {
unsafe {
let rsdp = if RSDP == 0 {
Expand Down
2 changes: 1 addition & 1 deletion components/someboot/src/arch/aarch64/paging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn enable_mmu() -> ! {
let mmu_entry_phys = super::entry::mmu_entry as *const () as usize;
println!("MMU Entry point at physical address: {:#x}", mmu_entry_phys);

let meta = crate::smp::cpu_meta(crate::smp::cpu_idx()).unwrap();
let meta = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()).unwrap();
let v_sp = meta.stack_top_virt;
let v_entry = __kimage_va(mmu_entry_phys) as usize;

Expand Down
8 changes: 4 additions & 4 deletions components/someboot/src/arch/riscv64/addrspace.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include!(concat!(env!("OUT_DIR"), "/defines.rs"));

#[cfg(uspace)]
#[cfg(any(uspace, hv))]
pub const PAGE_OFFSET: usize = 0xffff_ffc0_0000_0000;
#[cfg(not(uspace))]
#[cfg(not(any(uspace, hv)))]
pub const PAGE_OFFSET: usize = 0;

#[cfg(uspace)]
#[cfg(any(uspace, hv))]
pub const PERCPU_BASE: usize = 0xffff_ffe0_0000_0000;
#[cfg(not(uspace))]
#[cfg(not(any(uspace, hv)))]
pub const PERCPU_BASE: usize = PAGE_OFFSET;
6 changes: 4 additions & 2 deletions components/someboot/src/arch/riscv64/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ pub unsafe extern "C" fn kernel_entry(_hart_id: usize, _fdt_addr: usize) -> ! {
"mv t0, a1",
"lla sp, __cpu0_stack_top",
"mv a0, t0",
"j {primary_head_entry}",
"lla t1, {primary_head_entry}",
"jr t1",
primary_head_entry = sym primary_head_entry,
)
}
Expand Down Expand Up @@ -98,7 +99,8 @@ pub(crate) unsafe extern "C" fn _secondary_entry(_hartid: usize, _cpu_meta_paddr
"mv t0, a1",
"ld sp, {stack_top_offset}(t0)",
"mv a0, t0",
"j {secondary_start}",
"lla t1, {secondary_start}",
"jr t1",
secondary_start = sym secondary_start,
stack_top_offset = const offset_of!(PerCpuMeta, stack_top),
)
Expand Down
17 changes: 16 additions & 1 deletion components/someboot/src/arch/riscv64/link.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROVIDE(PAGE_SIZE = 0x1000);
PROVIDE(STACK_SIZE = 0x4000);
PROVIDE(STACK_SIZE = 0x40000);
VM_LOAD_ADDRESS = ${kernel_load_vaddr};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

STACK_SIZE 从 0x4000 (16KB) 增至 0x40000 (256KB),16 倍增长。HV 场景下确实可能需要更大栈空间,可接受。建议后续如有内存压力可以测量实际栈深度再调整。

OUTPUT_ARCH(riscv)
Expand Down Expand Up @@ -54,6 +54,21 @@ SECTIONS
_edata = .;
__kernel_load_end = .;
__bss_start = .;

.tdata : {
_stdata = .;
*(.tdata .tdata.*)
_etdata = .;
}

.tbss : {
_stbss = .;
*(.tbss .tbss.*)
*(.init.bss)
*(.tcommon)
_etbss = .;
}

.sbss : {
*(.dynsbss)
*(.sbss .sbss.*)
Expand Down
66 changes: 56 additions & 10 deletions components/someboot/src/arch/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ mod trap;
use core::sync::atomic::{AtomicUsize, Ordering};

pub(crate) use entry::_secondary_entry;
use page_table_generic::{PageTableEntry, PhysAddr, PteConfig, TableMeta, VirtAddr};
use page_table_generic::{MemAttributes, PageTableEntry, PhysAddr, PteConfig, TableMeta, VirtAddr};
pub use relocate::apply as relocate;

use crate::{
ArchTrait, DCacheOp,
mem::{PageTableInfo, mmu},
power::CpuOnError,
};
#[cfg(uspace)]
#[cfg(any(uspace, hv))]
use crate::{mem::__kimage_va_to_pa, smp::percpu_va_range};

const KERNEL_LOAD_ADDRESS: usize = 0x8020_0000;
Expand All @@ -37,10 +37,59 @@ const PTE_U: usize = 1 << 4;
const PTE_G: usize = 1 << 5;
const PTE_A: usize = 1 << 6;
const PTE_D: usize = 1 << 7;
const PTE_PPN_MASK: usize = (1 << 44) - 1;

#[cfg(feature = "thead-mae")]
const PTE_THEAD_SEC: usize = 1 << 59;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_SH: usize = 1 << 60;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_B: usize = 1 << 61;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_C: usize = 1 << 62;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_SO: usize = 1 << 63;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_PMA: usize = PTE_THEAD_C | PTE_THEAD_B | PTE_THEAD_SH;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_NOCACHE: usize = PTE_THEAD_B | PTE_THEAD_SH;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_IO: usize = PTE_THEAD_SO | PTE_THEAD_SH;
#[cfg(feature = "thead-mae")]
const PTE_THEAD_MT_MASK: usize =
PTE_THEAD_SEC | PTE_THEAD_SH | PTE_THEAD_B | PTE_THEAD_C | PTE_THEAD_SO;

static KERNEL_PAGE_TABLE_ADDR: AtomicUsize = AtomicUsize::new(0);
static TIMEBASE_FREQ: AtomicUsize = AtomicUsize::new(0);

#[cfg(feature = "thead-mae")]
fn thead_mae_pte_bits(mem_attr: MemAttributes) -> usize {
match mem_attr {
MemAttributes::Device => PTE_THEAD_IO,
MemAttributes::Uncached => PTE_THEAD_NOCACHE,
MemAttributes::Normal | MemAttributes::PerCpu => PTE_THEAD_PMA,
}
}

#[cfg(not(feature = "thead-mae"))]
fn thead_mae_pte_bits(_mem_attr: MemAttributes) -> usize {
0
}

#[cfg(feature = "thead-mae")]
fn thead_mae_mem_attr(bits: usize) -> MemAttributes {
match bits & PTE_THEAD_MT_MASK {
PTE_THEAD_IO => MemAttributes::Device,
PTE_THEAD_NOCACHE => MemAttributes::Uncached,
_ => MemAttributes::Normal,
}
}

#[cfg(not(feature = "thead-mae"))]
fn thead_mae_mem_attr(_bits: usize) -> MemAttributes {
MemAttributes::Normal
}

#[derive(Clone, Copy, Debug, Default)]
#[repr(transparent)]
pub struct Entry(usize);
Expand Down Expand Up @@ -75,9 +124,10 @@ impl PageTableEntry for Entry {
if config.writable || config.dirty {
bits |= PTE_D;
}
bits |= thead_mae_pte_bits(config.mem_attr);
}

bits |= (config.paddr.raw() >> 12) << SV39_PPN_SHIFT;
bits |= ((config.paddr.raw() >> 12) & PTE_PPN_MASK) << SV39_PPN_SHIFT;
Self(bits)
}

Expand All @@ -91,7 +141,7 @@ impl PageTableEntry for Entry {
let global = (bits & PTE_G) != 0;
let dirty = (bits & PTE_D) != 0;
let huge = is_dir && (read || writable || executable);
let paddr = PhysAddr::new((bits >> SV39_PPN_SHIFT) << 12);
let paddr = PhysAddr::new(((bits >> SV39_PPN_SHIFT) & PTE_PPN_MASK) << 12);

PteConfig {
paddr,
Expand All @@ -104,7 +154,7 @@ impl PageTableEntry for Entry {
global,
is_dir,
huge,
mem_attr: Default::default(),
mem_attr: thead_mae_mem_attr(bits),
}
}

Expand Down Expand Up @@ -176,7 +226,7 @@ impl ArchTrait for Arch {

fn virt_to_phys(vaddr: *const u8) -> usize {
let vaddr = vaddr as usize;
#[cfg(uspace)]
#[cfg(any(uspace, hv))]
{
if mmu::is_mmu_enabled() {
if percpu_va_range().contains(&vaddr) {
Expand Down Expand Up @@ -237,10 +287,6 @@ impl ArchTrait for Arch {
}

fn cpu_on(hartid: usize, entry: usize, arg: usize) -> Result<(), CpuOnError> {
if hartid == Self::cpu_current_hartid() {
return Err(CpuOnError::AlreadyOn);
}

match sbi::hart_start(hartid, entry, arg) {
Ok(()) => Ok(()),
Err(sbi::HartStartError::AlreadyAvailable | sbi::HartStartError::AlreadyStarted) => {
Expand Down
2 changes: 1 addition & 1 deletion components/someboot/src/arch/riscv64/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn enable_mmu() -> ! {
}

let mmu_entry_phys = super::entry::mmu_entry as *const () as usize;
let meta = crate::smp::cpu_meta(crate::smp::cpu_idx()).unwrap();
let meta = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()).unwrap();
let v_sp = meta.stack_top_virt;
let v_entry = __kimage_va(mmu_entry_phys) as usize;

Expand Down
8 changes: 2 additions & 6 deletions components/someboot/src/arch/riscv64/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use core::{arch::global_asm, mem::offset_of};
use crate::irq;

const SCAUSE_INTERRUPT_BIT: usize = 1usize << (usize::BITS as usize - 1);
const SCAUSE_SUPERVISOR_TIMER: usize = 5;

#[repr(C)]
struct TrapFrame {
Expand Down Expand Up @@ -66,11 +65,8 @@ pub fn trap_addr() -> usize {
extern "C" fn __riscv64_handle_trap(tf: &mut TrapFrame) {
let scause = tf.scause;
if (scause & SCAUSE_INTERRUPT_BIT) != 0 {
let cause = scause & !SCAUSE_INTERRUPT_BIT;
if cause == SCAUSE_SUPERVISOR_TIMER {
irq::handle_irq(irq::systimer_irq());
return;
}
irq::handle_irq(irq::IrqId::new(scause));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

将完整 raw scause(含中断位)作为 IrqId 传递,替代原来仅判断 timer 的硬编码。这对动态平台是必要的——PLIC 外部中断、IPI 等都需要通过统一路径分发。逻辑正确。

return;
}

panic!(
Expand Down
2 changes: 1 addition & 1 deletion components/someboot/src/arch/x86_64/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn enable_mmu() -> ! {
panic!("failed to setup x86_64 page table: {err:?}");
}

let meta = crate::smp::cpu_meta(crate::smp::cpu_idx()).unwrap();
let meta = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()).unwrap();
let v_sp = meta.stack_top_virt;
let v_entry = __kimage_va(super::entry::mmu_entry as *const () as usize) as usize;

Expand Down
9 changes: 8 additions & 1 deletion components/someboot/src/arch/x86_64/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,15 @@ pub(crate) fn notify_ap_started(apic_id: usize) {
AP_BOOTED_ID.store(apic_id, Ordering::Release);
}

fn current_apic_id() -> usize {
x86::cpuid::CpuId::new()
.get_feature_info()
.map(|info| info.initial_local_apic_id() as usize)
.unwrap_or(0)
}

pub(crate) fn cpu_on(apic_id: usize, entry: usize, arg: usize) -> Result<(), CpuOnError> {
if apic_id == crate::smp::cpu_hart_id() {
if apic_id == current_apic_id() {
return Err(CpuOnError::AlreadyOn);
}
let apic_id = u8::try_from(apic_id).map_err(|_| CpuOnError::InvalidParameters)?;
Expand Down
2 changes: 1 addition & 1 deletion components/someboot/src/fdt/earlycon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn set_by_stdout() -> Option<()> {
installed = true;
break;
}
"snps,dw-apb-uart" => {
"snps,dw-apb-uart" | "ns16550a" | "ns16550" => {
let mut serial = ns16550::Ns16550::new_mmio(addr, clock, reg_width);
serial.open();
let tx = serial.take_tx()?;
Expand Down
Loading