| #ifndef __PGTABLE_TEST_H |
| #define __PGTABLE_TEST_H |
| |
| #include <linux/kvm.h> |
| |
| #define PTRS_PER_PTE 512UL |
| #define PAGE_SIZE 0x1000UL |
| #define PMD_SIZE (PTRS_PER_PTE * PAGE_SIZE) |
| #define PUD_SIZE (PTRS_PER_PTE * PMD_SIZE) |
| |
| #define ARM64_INST_SIZE 4 |
| |
| /* Register ids */ |
| #define REG_X(number) (0x6030000000100000ULL + (number) * 2UL) |
| #define REG_PC 0x6030000000100040ULL |
| |
| #define KVM_IOCTL(fd, ioctl_id, ...) \ |
| ({ \ |
| int ret = ioctl(fd, ioctl_id, __VA_ARGS__); \ |
| if (ret < 0) \ |
| err(ret, #ioctl_id ); \ |
| ret; \ |
| }) |
| |
| /* XXX */ |
| typedef enum { |
| false = 0, |
| true = 1, |
| } bool; |
| |
| int get_kvm(void); |
| int create_vm(int kvm); |
| int create_vcpu(int kvm, int vmfd, struct kvm_run **run, bool debug); |
| void vm_add_mmio_page(int vmfd, int slot, uint64_t addr); |
| void set_one_reg(int vcpufd, uint64_t reg_id, uint64_t val); |
| int vcpu_run(int vcpufd, struct kvm_run *run); |
| |
| /* XXX - Move the bitmap stuff elsewhere */ |
| #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) |
| |
| #define BITMAP_SIZE(mem) (ALIGN((mem) / PAGE_SIZE, 64) / 8) |
| #define OFFSET_IDX(offset) (offset / PAGE_SIZE / 8) |
| #define OFFSET_BIT(offset) (1 << ((offset / PAGE_SIZE) % 8)) |
| |
| static inline bool bitmap_equal(uint8_t *bm_a, uint8_t *bm_b, uint64_t len) |
| { |
| for (uint64_t i = 0; i < len; i++) { |
| if (bm_a[i] != bm_b[i]) |
| return false; |
| } |
| |
| return true; |
| } |
| #endif /* __PGTABLE_TEST_H */ |