2 * qtest function wrappers
4 * Copyright Red Hat Inc., 2019
7 * Alexander Bulekov <alxndr@bu.edu>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include "hw/core/cpu.h"
16 #include "exec/ioport.h"
20 static bool serialize
= true;
22 #define WRAP(RET_TYPE, NAME_AND_ARGS)\
23 RET_TYPE __wrap_##NAME_AND_ARGS;\
24 RET_TYPE __real_##NAME_AND_ARGS;
26 WRAP(uint8_t , qtest_inb(QTestState
*s
, uint16_t addr
))
27 WRAP(uint16_t , qtest_inw(QTestState
*s
, uint16_t addr
))
28 WRAP(uint32_t , qtest_inl(QTestState
*s
, uint16_t addr
))
29 WRAP(void , qtest_outb(QTestState
*s
, uint16_t addr
, uint8_t value
))
30 WRAP(void , qtest_outw(QTestState
*s
, uint16_t addr
, uint16_t value
))
31 WRAP(void , qtest_outl(QTestState
*s
, uint16_t addr
, uint32_t value
))
32 WRAP(uint8_t , qtest_readb(QTestState
*s
, uint64_t addr
))
33 WRAP(uint16_t , qtest_readw(QTestState
*s
, uint64_t addr
))
34 WRAP(uint32_t , qtest_readl(QTestState
*s
, uint64_t addr
))
35 WRAP(uint64_t , qtest_readq(QTestState
*s
, uint64_t addr
))
36 WRAP(void , qtest_writeb(QTestState
*s
, uint64_t addr
, uint8_t value
))
37 WRAP(void , qtest_writew(QTestState
*s
, uint64_t addr
, uint16_t value
))
38 WRAP(void , qtest_writel(QTestState
*s
, uint64_t addr
, uint32_t value
))
39 WRAP(void , qtest_writeq(QTestState
*s
, uint64_t addr
, uint64_t value
))
40 WRAP(void , qtest_memread(QTestState
*s
, uint64_t addr
,
41 void *data
, size_t size
))
42 WRAP(void , qtest_bufread(QTestState
*s
, uint64_t addr
, void *data
,
44 WRAP(void , qtest_memwrite(QTestState
*s
, uint64_t addr
, const void *data
,
46 WRAP(void, qtest_bufwrite(QTestState
*s
, uint64_t addr
,
47 const void *data
, size_t size
))
48 WRAP(void, qtest_memset(QTestState
*s
, uint64_t addr
,
49 uint8_t patt
, size_t size
))
52 uint8_t __wrap_qtest_inb(QTestState
*s
, uint16_t addr
)
57 return __real_qtest_inb(s
, addr
);
61 uint16_t __wrap_qtest_inw(QTestState
*s
, uint16_t addr
)
66 return __real_qtest_inw(s
, addr
);
70 uint32_t __wrap_qtest_inl(QTestState
*s
, uint16_t addr
)
75 return __real_qtest_inl(s
, addr
);
79 void __wrap_qtest_outb(QTestState
*s
, uint16_t addr
, uint8_t value
)
82 cpu_outb(addr
, value
);
84 __real_qtest_outb(s
, addr
, value
);
88 void __wrap_qtest_outw(QTestState
*s
, uint16_t addr
, uint16_t value
)
91 cpu_outw(addr
, value
);
93 __real_qtest_outw(s
, addr
, value
);
97 void __wrap_qtest_outl(QTestState
*s
, uint16_t addr
, uint32_t value
)
100 cpu_outl(addr
, value
);
102 __real_qtest_outl(s
, addr
, value
);
106 uint8_t __wrap_qtest_readb(QTestState
*s
, uint64_t addr
)
110 address_space_read(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
114 return __real_qtest_readb(s
, addr
);
118 uint16_t __wrap_qtest_readw(QTestState
*s
, uint64_t addr
)
122 address_space_read(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
126 return __real_qtest_readw(s
, addr
);
130 uint32_t __wrap_qtest_readl(QTestState
*s
, uint64_t addr
)
134 address_space_read(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
138 return __real_qtest_readl(s
, addr
);
142 uint64_t __wrap_qtest_readq(QTestState
*s
, uint64_t addr
)
146 address_space_read(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
150 return __real_qtest_readq(s
, addr
);
154 void __wrap_qtest_writeb(QTestState
*s
, uint64_t addr
, uint8_t value
)
157 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
160 __real_qtest_writeb(s
, addr
, value
);
164 void __wrap_qtest_writew(QTestState
*s
, uint64_t addr
, uint16_t value
)
167 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
170 __real_qtest_writew(s
, addr
, value
);
174 void __wrap_qtest_writel(QTestState
*s
, uint64_t addr
, uint32_t value
)
177 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
180 __real_qtest_writel(s
, addr
, value
);
184 void __wrap_qtest_writeq(QTestState
*s
, uint64_t addr
, uint64_t value
)
187 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
190 __real_qtest_writeq(s
, addr
, value
);
194 void __wrap_qtest_memread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
)
197 address_space_read(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
, data
,
200 __real_qtest_memread(s
, addr
, data
, size
);
204 void __wrap_qtest_bufread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
)
207 address_space_read(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
, data
,
210 __real_qtest_bufread(s
, addr
, data
, size
);
214 void __wrap_qtest_memwrite(QTestState
*s
, uint64_t addr
, const void *data
,
218 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
221 __real_qtest_memwrite(s
, addr
, data
, size
);
225 void __wrap_qtest_bufwrite(QTestState
*s
, uint64_t addr
,
226 const void *data
, size_t size
)
229 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
232 __real_qtest_bufwrite(s
, addr
, data
, size
);
235 void __wrap_qtest_memset(QTestState
*s
, uint64_t addr
,
236 uint8_t patt
, size_t size
)
241 memset(data
, patt
, size
);
242 address_space_write(first_cpu
->as
, addr
, MEMTXATTRS_UNSPECIFIED
,
245 __real_qtest_memset(s
, addr
, patt
, size
);
249 void fuzz_qtest_set_serialize(bool option
)