1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#ifndef KQEMU_H
25#define KQEMU_H
26
27#if defined(__i386__)
28#define KQEMU_PAD32(x) x
29#else
30#define KQEMU_PAD32(x)
31#endif
32
33#define KQEMU_VERSION 0x010400
34
35struct kqemu_segment_cache {
36 uint16_t selector;
37 uint16_t padding1;
38 uint32_t flags;
39 uint64_t base;
40 uint32_t limit;
41 uint32_t padding2;
42};
43
44struct kqemu_cpu_state {
45 uint64_t regs[16];
46 uint64_t eip;
47 uint64_t eflags;
48
49 struct kqemu_segment_cache segs[6];
50 struct kqemu_segment_cache ldt;
51 struct kqemu_segment_cache tr;
52 struct kqemu_segment_cache gdt;
53 struct kqemu_segment_cache idt;
54
55 uint64_t cr0;
56 uint64_t cr2;
57 uint64_t cr3;
58 uint64_t cr4;
59 uint64_t a20_mask;
60
61
62 uint64_t sysenter_cs;
63 uint64_t sysenter_esp;
64 uint64_t sysenter_eip;
65 uint64_t efer;
66 uint64_t star;
67
68 uint64_t lstar;
69 uint64_t cstar;
70 uint64_t fmask;
71 uint64_t kernelgsbase;
72
73 uint64_t tsc_offset;
74
75 uint64_t dr0;
76 uint64_t dr1;
77 uint64_t dr2;
78 uint64_t dr3;
79 uint64_t dr6;
80 uint64_t dr7;
81
82 uint8_t cpl;
83 uint8_t user_only;
84 uint16_t padding1;
85
86 uint32_t error_code;
87 uint64_t next_eip;
88 uint32_t nb_pages_to_flush;
89
90#define KQEMU_MAX_PAGES_TO_FLUSH 512
91#define KQEMU_FLUSH_ALL (KQEMU_MAX_PAGES_TO_FLUSH + 1)
92
93 int32_t retval;
94
95
96 uint32_t nb_ram_pages_to_update;
97#define KQEMU_MAX_RAM_PAGES_TO_UPDATE 512
98#define KQEMU_RAM_PAGES_UPDATE_ALL (KQEMU_MAX_RAM_PAGES_TO_UPDATE + 1)
99
100#define KQEMU_MAX_MODIFIED_RAM_PAGES 512
101 uint32_t nb_modified_ram_pages;
102};
103
104struct kqemu_init {
105 uint8_t *ram_base;
106 KQEMU_PAD32(uint32_t padding1;)
107 uint64_t ram_size;
108 uint8_t *ram_dirty;
109 KQEMU_PAD32(uint32_t padding2;)
110 uint64_t *pages_to_flush;
111 KQEMU_PAD32(uint32_t padding4;)
112 uint64_t *ram_pages_to_update;
113 KQEMU_PAD32(uint32_t padding5;)
114 uint64_t *modified_ram_pages;
115 KQEMU_PAD32(uint32_t padding6;)
116};
117
118#define KQEMU_IO_MEM_RAM 0
119#define KQEMU_IO_MEM_ROM 1
120#define KQEMU_IO_MEM_COMM 2
121#define KQEMU_IO_MEM_UNASSIGNED 3
122
123struct kqemu_phys_mem {
124 uint64_t phys_addr;
125
126 uint64_t size;
127 uint64_t ram_addr;
128 uint32_t io_index;
129 uint32_t padding1;
130};
131
132#define KQEMU_RET_ABORT (-1)
133#define KQEMU_RET_EXCEPTION 0x0000
134#define KQEMU_RET_INT 0x0100
135#define KQEMU_RET_SOFTMMU 0x0200
136
137#define KQEMU_RET_INTR 0x0201
138#define KQEMU_RET_SYSCALL 0x0300
139
140#ifdef _WIN32
141#define KQEMU_EXEC CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
142#define KQEMU_INIT CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
143#define KQEMU_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 3, METHOD_BUFFERED, FILE_READ_ACCESS)
144#define KQEMU_MODIFY_RAM_PAGES CTL_CODE(FILE_DEVICE_UNKNOWN, 4, METHOD_BUFFERED, FILE_WRITE_ACCESS)
145#define KQEMU_SET_PHYS_MEM CTL_CODE(FILE_DEVICE_UNKNOWN, 5, METHOD_BUFFERED, FILE_WRITE_ACCESS)
146#else
147#define KQEMU_EXEC _IOWR('q', 1, struct kqemu_cpu_state)
148#define KQEMU_INIT _IOW('q', 2, struct kqemu_init)
149#define KQEMU_GET_VERSION _IOR('q', 3, int)
150#define KQEMU_MODIFY_RAM_PAGES _IOW('q', 4, int)
151#define KQEMU_SET_PHYS_MEM _IOW('q', 5, struct kqemu_phys_mem)
152#endif
153
154#endif
155