Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit f4e96e9

Browse files
RuoqingHerbradford
authored andcommitted
riscv64: Enable get_dirty_log doc test
Add assembly code which does dirty one page and forces MMIO exit on RISC-V 64-bit platform to complete `get_dirty_log` doc test. Signed-off-by: Ruoqing He <[email protected]>
1 parent 3a16618 commit f4e96e9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/ioctls/vm.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,13 @@ impl VmFd {
855855
/// 0x00, 0x00, 0x00,
856856
/// 0x14, /* b <this address>; shouldn't get here, but if so loop forever */
857857
/// ];
858+
/// #[cfg(target_arch = "riscv64")]
859+
/// let asm_code = [
860+
/// 0x17, 0x03, 0x00, 0x00, // auipc t1, 0; <this address> -> t1
861+
/// 0xa3, 0x23, 0x73, 0x00, // sw t2, t1 + 7; dirty current page
862+
/// 0x23, 0x20, 0x75, 0x00, // sw t2, a0; trigger MMIO exit
863+
/// 0x6f, 0x00, 0x00, 0x00, // j .;shouldn't get here, but if so loop forever
864+
/// ];
858865
///
859866
/// // Write the code in the guest memory. This will generate a dirty page.
860867
/// unsafe {
@@ -894,6 +901,14 @@ impl VmFd {
894901
/// vcpu_fd.set_one_reg(core_reg_base + 2 * 0, &mmio_addr.to_le_bytes()); // set X0
895902
/// }
896903
///
904+
/// #[cfg(target_arch = "riscv64")]
905+
/// {
906+
/// let core_reg_base: u64 = 0x8030_0000_0200_0000;
907+
/// let mmio_addr: u64 = guest_addr + mem_size as u64;
908+
/// vcpu_fd.set_one_reg(core_reg_base, &guest_addr.to_le_bytes()); // set PC
909+
/// vcpu_fd.set_one_reg(core_reg_base + 10, &mmio_addr.to_le_bytes()); // set A0
910+
/// }
911+
///
897912
/// loop {
898913
/// match vcpu_fd.run().expect("run failed") {
899914
/// VcpuExit::MmioWrite(addr, data) => {

0 commit comments

Comments
 (0)