Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d5d8ae9
feat(vcpu): add interrupt injection support and enhance system regist…
luodeb Mar 27, 2025
1b8da5e
feat(sysreg): update handle_read and handle_write to use unused param…
luodeb Mar 31, 2025
32866b4
update dependecies
aarkegz Apr 7, 2025
28b357c
Merge remote-tracking branch 'origin/debin/timer_api' into debin/time…
aarkegz Apr 7, 2025
4017f66
update percpu
aarkegz Apr 14, 2025
1b465d2
Merge branch 'master' into debin/timer_api
aarkegz Jun 5, 2025
2143f59
try setting ich_hcr_el2.en
aarkegz Jun 5, 2025
1df97f2
[feat] use 4 level paging for ept
hky1999 Jun 6, 2025
a860bfd
better code and comment for setting ich_hcr_el2
aarkegz Jun 7, 2025
7da58d1
Merge branch 'master' into vgicv3
aarkegz Jun 8, 2025
a9bde35
add error messages for `current_el_sync_handler`
aarkegz Jun 8, 2025
d393aee
pin rust toolchain version
aarkegz Jun 8, 2025
a4f1c10
set `CNTHCTL_EL2::EL1PCEN` and `CNTHCTL_EL2::EL1PTCEN`, unset `HCR_EL…
aarkegz Jun 9, 2025
47f4598
[STINKS] embed vgicv3 devices with HARD-CODED qemu gicv3 address loca…
aarkegz Jun 9, 2025
fcfd6ec
[feat] introduce set_return_value API
hky1999 Jun 10, 2025
1fb5ac1
[WIP!][TOBEREWRITE!] add gic-vdevice cofigs
aarkegz Jun 10, 2025
211289e
Merge remote-tracking branch 'origin/ivc_and_4lpt' into vgicv3
aarkegz Jun 11, 2025
7171d99
fixes after merging ivc code
aarkegz Jun 11, 2025
f8e6514
fix branch names for `axvcpu`
aarkegz Jun 11, 2025
ad1d617
emulate `ICC_SGI1R_EL1`
aarkegz Jun 13, 2025
17f554c
update to newest dependencies
aarkegz Jul 11, 2025
0e36a62
de-coupling `arm_vcpu` and `arm_vgic`, fix some warnings
aarkegz Jul 13, 2025
ce67fce
fix a missing doc
aarkegz Jul 13, 2025
e8eb890
remove `arm_vgic` dependency
aarkegz Jul 14, 2025
a64648e
add `builtin_sysreg_access_handler`, add interrupt and timer passthro…
aarkegz Jul 14, 2025
b3e1169
remove sysreg emu devices
aarkegz Jul 14, 2025
1753965
rollback `tock-registers` to 0.9
aarkegz Jul 14, 2025
2cdca35
reformatted
aarkegz Jul 14, 2025
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
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ edition = "2024"
log = "0.4.21"
spin = "0.9"

aarch64-cpu = "9.3"
tock-registers = "0.8"
aarch64-cpu = "10.0"
tock-registers = "0.9"
numeric-enum-macro = "0.2"

axerrno = "0.1.0"
percpu = { version = "0.2.0", features = ["arm-el2"] }
aarch64_sysreg = "0.1.1"

axaddrspace = { git = "https://github.com/arceos-hypervisor/axaddrspace.git" }
axvcpu = { git = "https://github.com/arceos-hypervisor/axvcpu.git" }
axdevice_base = { git = "https://github.com/arceos-hypervisor/axdevice_crates.git" }
axvisor_api = { git = "https://github.com/arceos-hypervisor/axvisor_api.git" }
8 changes: 8 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[toolchain]
profile = "minimal"
channel = "nightly-2024-12-25"
components = ["rust-src", "llvm-tools", "rustfmt", "clippy"]
targets = [
"aarch64-unknown-none",
"aarch64-unknown-none-softfloat",
]
6 changes: 4 additions & 2 deletions src/context_frame.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::arch::asm;
use core::fmt::Formatter;
use core::{arch::asm, fmt::Formatter};

use aarch64_cpu::registers::*;

Expand Down Expand Up @@ -156,6 +155,7 @@ pub struct GuestSystemRegisters {
cntv_ctl_el0: u32,
cntp_tval_el0: u32,
cntv_tval_el0: u32,
pub cnthctl_el2: u64,

// vpidr and vmpidr
vpidr_el2: u32,
Expand Down Expand Up @@ -220,6 +220,7 @@ impl GuestSystemRegisters {
asm!("mrs {0:x}, CNTP_TVAL_EL0", out(reg) self.cntp_tval_el0);
asm!("mrs {0:x}, CNTV_TVAL_EL0", out(reg) self.cntv_tval_el0);
asm!("mrs {0}, CNTVCT_EL0", out(reg) self.cntvct_el0);
asm!("mrs {0}, CNTHCTL_EL2", out(reg) self.cnthctl_el2);
// MRS!("self.vpidr_el2, VPIDR_EL2, "x");
asm!("mrs {0}, VMPIDR_EL2", out(reg) self.vmpidr_el2);

Expand Down Expand Up @@ -265,6 +266,7 @@ impl GuestSystemRegisters {
asm!("msr CNTV_CVAL_EL0, {0}", in(reg) self.cntv_cval_el0);
asm!("msr CNTKCTL_EL1, {0:x}", in (reg) self.cntkctl_el1);
asm!("msr CNTV_CTL_EL0, {0:x}", in (reg) self.cntv_ctl_el0);
asm!("msr CNTHCTL_EL2, {0}", in(reg) self.cnthctl_el2);
// The restoration of SP_EL0 is done in `exception_return_el2`,
// which move the value from `self.ctx.sp_el0` to `SP_EL0`.
// asm!("msr SP_EL0, {0}", in(reg) self.sp_el0);
Expand Down
32 changes: 23 additions & 9 deletions src/exception.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
use aarch64_cpu::registers::{ESR_EL2, HCR_EL2, Readable, SCTLR_EL1, VTCR_EL2, VTTBR_EL2};

use axaddrspace::GuestPhysAddr;
use axaddrspace::device::AccessWidth;
use axerrno::{AxError, AxResult};
use axvcpu::AxVCpuExitReason;

use crate::TrapFrame;
use crate::exception_utils::{
exception_class, exception_class_value, exception_data_abort_access_is_write,
Expand All @@ -15,6 +8,15 @@ use crate::exception_utils::{
exception_sysreg_direction_write, exception_sysreg_gpr,
};

use aarch64_cpu::registers::{ESR_EL2, HCR_EL2, Readable, SCTLR_EL1, VTCR_EL2, VTTBR_EL2};
use axaddrspace::{
GuestPhysAddr,
device::{AccessWidth, SysRegAddr},
};
use axerrno::{AxError, AxResult};
use axvcpu::AxVCpuExitReason;
use log::error;

numeric_enum_macro::numeric_enum! {
#[repr(u8)]
#[derive(Debug)]
Expand Down Expand Up @@ -179,6 +181,7 @@ fn handle_data_abort(context_frame: &mut TrapFrame) -> AxResult<AxVCpuExitReason
width,
reg,
reg_width,
signed_ext: false,
})
}

Expand All @@ -204,11 +207,14 @@ fn handle_system_register(context_frame: &mut TrapFrame) -> AxResult<AxVCpuExitR
context_frame.set_exception_pc(val);
if write {
return Ok(AxVCpuExitReason::SysRegWrite {
addr,
addr: SysRegAddr::new(addr),
value: context_frame.gpr(reg as usize) as u64,
});
}
Ok(AxVCpuExitReason::SysRegRead { addr, reg })
Ok(AxVCpuExitReason::SysRegRead {
addr: SysRegAddr::new(addr),
reg,
})
}

/// Handles HVC or SMC exceptions that serve as psci (Power State Coordination Interface) calls.
Expand Down Expand Up @@ -284,6 +290,14 @@ fn current_el_irq_handler(_tf: &mut TrapFrame) {
/// Handles synchronous exceptions that occur from the current exception level.
#[unsafe(no_mangle)]
fn current_el_sync_handler(tf: &mut TrapFrame) {
let esr = ESR_EL2.extract();
let ec = ESR_EL2.read(ESR_EL2::EC);
let iss = ESR_EL2.read(ESR_EL2::ISS);

error!("ESR_EL2: {:#x}", esr.get());
error!("Exception Class: {:#x}", ec);
error!("Instruction Specific Syndrome: {:#x}", iss);

panic!(
"Unhandled synchronous exception from current EL: {:#x?}",
tf
Expand Down
3 changes: 1 addition & 2 deletions src/exception_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use aarch64_cpu::registers::{ESR_EL2, FAR_EL2, PAR_EL1};
use tock_registers::interfaces::*;

use axaddrspace::GuestPhysAddr;
use axerrno::{AxResult, ax_err};
use tock_registers::interfaces::*;

/// Retrieves the Exception Syndrome Register (ESR) value from EL2.
///
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod smc;
mod vcpu;

pub use self::pcpu::Aarch64PerCpu;
pub use self::vcpu::{Aarch64VCpu, Aarch64VCpuCreateConfig};
pub use self::vcpu::{Aarch64VCpu, Aarch64VCpuCreateConfig, Aarch64VCpuSetupConfig};

/// context frame for aarch64
pub type TrapFrame = context_frame::Aarch64ContextFrame;
Expand Down
16 changes: 14 additions & 2 deletions src/pcpu.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use core::{cell::OnceCell, marker::PhantomData};

use aarch64_cpu::registers::*;
use tock_registers::interfaces::ReadWriteable;

use axerrno::AxResult;
use axvcpu::{AxArchPerCpu, AxVCpuHal};
use tock_registers::interfaces::ReadWriteable;

/// Per-CPU data. A pointer to this struct is loaded into TP when a CPU starts. This structure
#[repr(C)]
Expand Down Expand Up @@ -64,6 +63,19 @@ impl<H: AxVCpuHal> AxArchPerCpu for Aarch64PerCpu<H> {
+ HCR_EL2::TSC::EnableTrapEl1SmcToEl2,
);

// Note that `ICH_HCR_EL2` is not the same as `HCR_EL2`.
//
// `ICH_HCR_EL2[0]` controls the virtual CPU interface operation.
//
// We leave it for the virtual GIC implementations to decide whether to enable it or not.
//
// unsafe {
// core::arch::asm! {
// "msr ich_hcr_el2, {value:x}",
// value = in(reg) 0,
// }
// }

Ok(())
}

Expand Down
Loading