Skip to content

Commit d6421d5

Browse files
committed
feat(vcpu): add support for emulated system register access
- Add new exit reasons for system register read and write - Implement handling for emulated system register access - Update VM to use new emulated register functionality
1 parent 7a35c93 commit d6421d5

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/vcpu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cfg_if::cfg_if! {
2222
pub use arm_vcpu::Aarch64VCpu as AxArchVCpuImpl;
2323
pub use arm_vcpu::Aarch64PerCpu as AxVMArchPerCpuImpl;
2424
pub use arm_vcpu::Aarch64VCpuCreateConfig as AxVCpuCreateConfig;
25+
pub use arm_vcpu::Aarch64EmuRegs as AxArchEmuRegs;
2526
pub use arm_vcpu::has_hardware_support;
2627
}
2728
}

src/vm.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use alloc::sync::Arc;
44
use alloc::vec::Vec;
55
use core::sync::atomic::{AtomicBool, Ordering};
66

7-
use axerrno::{AxResult, ax_err, ax_err_type};
7+
use axerrno::{ax_err, ax_err_type, AxResult};
88
use spin::Mutex;
99

1010
use axaddrspace::{AddrSpace, GuestPhysAddr, HostPhysAddr, MappingFlags};
1111
use axdevice::{AxVmDeviceConfig, AxVmDevices};
1212
use axvcpu::{AxArchVCpu, AxVCpu, AxVCpuExitReason, AxVCpuHal};
1313

1414
use crate::config::{AxVMConfig, VmMemMappingType};
15-
use crate::vcpu::{AxArchVCpuImpl, AxVCpuCreateConfig};
16-
use crate::{AxVMHal, has_hardware_support};
15+
use crate::vcpu::{AxArchEmuRegs, AxArchVCpuImpl, AxVCpuCreateConfig};
16+
use crate::{has_hardware_support, AxVMHal};
1717

1818
const VM_ASPACE_BASE: usize = 0x0;
1919
const VM_ASPACE_SIZE: usize = 0x7fff_ffff_f000;
@@ -168,7 +168,7 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
168168
MappingFlags::DEVICE | MappingFlags::READ | MappingFlags::WRITE,
169169
)?;
170170
}
171-
171+
info!("skedfghkshdgfkd");
172172
let devices = axdevice::AxVmDevices::new(AxVmDeviceConfig {
173173
emu_configs: config.emu_devices().to_vec(),
174174
});
@@ -306,15 +306,21 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
306306
reg,
307307
reg_width: _,
308308
} => {
309-
let val = self
310-
.get_devices()
311-
.handle_mmio_read(*addr, (*width).into())?;
309+
let val = self.get_devices().handle_mmio_read(
310+
*addr,
311+
(*width).into(),
312+
vcpu.as_ref(),
313+
)?;
312314
vcpu.set_gpr(*reg, val);
313315
true
314316
}
315317
AxVCpuExitReason::MmioWrite { addr, width, data } => {
316-
self.get_devices()
317-
.handle_mmio_write(*addr, (*width).into(), *data as usize);
318+
self.get_devices().handle_mmio_write(
319+
*addr,
320+
(*width).into(),
321+
*data as usize,
322+
vcpu.as_ref(),
323+
);
318324
true
319325
}
320326
AxVCpuExitReason::IoRead { port: _, width: _ } => true,
@@ -323,6 +329,22 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
323329
width: _,
324330
data: _,
325331
} => true,
332+
AxVCpuExitReason::SysRegRead { addr, reg } => {
333+
AxArchEmuRegs::<U>::emu_register_handle_read(
334+
(*addr).into(),
335+
*reg,
336+
vcpu.clone(),
337+
);
338+
true
339+
}
340+
AxVCpuExitReason::SysRegWrite { addr, value } => {
341+
AxArchEmuRegs::<U>::emu_register_handle_write(
342+
(*addr).into(),
343+
*value,
344+
vcpu.clone(),
345+
);
346+
true
347+
}
326348
AxVCpuExitReason::NestedPageFault { addr, access_flags } => self
327349
.inner_mut
328350
.address_space

0 commit comments

Comments
 (0)