2 * QTest testcase for ISA endianness
4 * Copyright Red Hat, Inc. 2012
7 * Paolo Bonzini <pbonzini@redhat.com>
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.
21 #include "qemu/bswap.h"
23 typedef struct TestCase TestCase
;
32 static const TestCase test_cases
[] = {
34 { "mips", "magnum", 0x90000000, .bswap
= true },
35 { "mips", "pica61", 0x90000000, .bswap
= true },
36 { "mips", "mips", 0x14000000, .bswap
= true },
37 { "mips", "malta", 0x10000000, .bswap
= true },
38 { "mips64", "magnum", 0x90000000, .bswap
= true },
39 { "mips64", "pica61", 0x90000000, .bswap
= true },
40 { "mips64", "mips", 0x14000000, .bswap
= true },
41 { "mips64", "malta", 0x10000000, .bswap
= true },
42 { "mips64el", "fulong2e", 0x1fd00000 },
43 { "ppc", "g3beige", 0xfe000000, .bswap
= true, .superio
= "i82378" },
44 { "ppc", "prep", 0x80000000, .bswap
= true },
45 { "ppc", "bamboo", 0xe8000000, .bswap
= true, .superio
= "i82378" },
46 { "ppc64", "mac99", 0xf2000000, .bswap
= true, .superio
= "i82378" },
47 { "ppc64", "pseries", 0x10080000000, .bswap
= true, .superio
= "i82378" },
48 { "sh4", "r2d", 0xfe240000, .superio
= "i82378" },
49 { "sh4eb", "r2d", 0xfe240000, .bswap
= true, .superio
= "i82378" },
50 { "sparc64", "sun4u", 0x1fe02000000LL
, .bswap
= true },
51 { "x86_64", "pc", -1 },
55 static uint8_t isa_inb(const TestCase
*test
, uint16_t addr
)
58 if (test
->isa_base
== -1) {
61 value
= readb(test
->isa_base
+ addr
);
66 static uint16_t isa_inw(const TestCase
*test
, uint16_t addr
)
69 if (test
->isa_base
== -1) {
72 value
= readw(test
->isa_base
+ addr
);
74 return test
->bswap
? bswap16(value
) : value
;
77 static uint32_t isa_inl(const TestCase
*test
, uint16_t addr
)
80 if (test
->isa_base
== -1) {
83 value
= readl(test
->isa_base
+ addr
);
85 return test
->bswap
? bswap32(value
) : value
;
88 static void isa_outb(const TestCase
*test
, uint16_t addr
, uint8_t value
)
90 if (test
->isa_base
== -1) {
93 writeb(test
->isa_base
+ addr
, value
);
97 static void isa_outw(const TestCase
*test
, uint16_t addr
, uint16_t value
)
99 value
= test
->bswap
? bswap16(value
) : value
;
100 if (test
->isa_base
== -1) {
103 writew(test
->isa_base
+ addr
, value
);
107 static void isa_outl(const TestCase
*test
, uint16_t addr
, uint32_t value
)
109 value
= test
->bswap
? bswap32(value
) : value
;
110 if (test
->isa_base
== -1) {
113 writel(test
->isa_base
+ addr
, value
);
118 static void test_endianness(gconstpointer data
)
120 const TestCase
*test
= data
;
123 args
= g_strdup_printf("-display none -M %s%s%s -device pc-testdev",
125 test
->superio
? " -device " : "",
126 test
->superio
?: "");
128 isa_outl(test
, 0xe0, 0x87654321);
129 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654321);
130 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
131 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4321);
132 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x87);
133 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x65);
134 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x43);
135 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x21);
137 isa_outw(test
, 0xe2, 0x8866);
138 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x88664321);
139 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8866);
140 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4321);
141 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x88);
142 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x66);
143 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x43);
144 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x21);
146 isa_outw(test
, 0xe0, 0x4422);
147 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x88664422);
148 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8866);
149 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4422);
150 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x88);
151 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x66);
152 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x44);
153 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x22);
155 isa_outb(test
, 0xe3, 0x87);
156 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87664422);
157 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8766);
158 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x87);
159 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x66);
160 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x44);
161 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x22);
163 isa_outb(test
, 0xe2, 0x65);
164 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654422);
165 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
166 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4422);
167 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x87);
168 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x65);
169 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x44);
170 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x22);
172 isa_outb(test
, 0xe1, 0x43);
173 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654322);
174 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
175 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4322);
176 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x87);
177 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x65);
178 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x43);
179 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x22);
181 isa_outb(test
, 0xe0, 0x21);
182 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654321);
183 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
184 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4321);
185 g_assert_cmphex(isa_inb(test
, 0xe3), ==, 0x87);
186 g_assert_cmphex(isa_inb(test
, 0xe2), ==, 0x65);
187 g_assert_cmphex(isa_inb(test
, 0xe1), ==, 0x43);
188 g_assert_cmphex(isa_inb(test
, 0xe0), ==, 0x21);
189 qtest_quit(global_qtest
);
193 static void test_endianness_split(gconstpointer data
)
195 const TestCase
*test
= data
;
198 args
= g_strdup_printf("-display none -M %s%s%s -device pc-testdev",
200 test
->superio
? " -device " : "",
201 test
->superio
?: "");
203 isa_outl(test
, 0xe8, 0x87654321);
204 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654321);
205 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
206 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4321);
208 isa_outw(test
, 0xea, 0x8866);
209 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x88664321);
210 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8866);
211 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4321);
213 isa_outw(test
, 0xe8, 0x4422);
214 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x88664422);
215 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8866);
216 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4422);
218 isa_outb(test
, 0xeb, 0x87);
219 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87664422);
220 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8766);
222 isa_outb(test
, 0xea, 0x65);
223 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654422);
224 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
225 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4422);
227 isa_outb(test
, 0xe9, 0x43);
228 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654322);
229 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
230 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4322);
232 isa_outb(test
, 0xe8, 0x21);
233 g_assert_cmphex(isa_inl(test
, 0xe0), ==, 0x87654321);
234 g_assert_cmphex(isa_inw(test
, 0xe2), ==, 0x8765);
235 g_assert_cmphex(isa_inw(test
, 0xe0), ==, 0x4321);
236 qtest_quit(global_qtest
);
240 static void test_endianness_combine(gconstpointer data
)
242 const TestCase
*test
= data
;
245 args
= g_strdup_printf("-display none -M %s%s%s -device pc-testdev",
247 test
->superio
? " -device " : "",
248 test
->superio
?: "");
250 isa_outl(test
, 0xe0, 0x87654321);
251 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x87654321);
252 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8765);
253 g_assert_cmphex(isa_inw(test
, 0xe8), ==, 0x4321);
255 isa_outw(test
, 0xe2, 0x8866);
256 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x88664321);
257 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8866);
258 g_assert_cmphex(isa_inw(test
, 0xe8), ==, 0x4321);
260 isa_outw(test
, 0xe0, 0x4422);
261 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x88664422);
262 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8866);
263 g_assert_cmphex(isa_inw(test
, 0xe8), ==, 0x4422);
265 isa_outb(test
, 0xe3, 0x87);
266 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x87664422);
267 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8766);
269 isa_outb(test
, 0xe2, 0x65);
270 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x87654422);
271 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8765);
272 g_assert_cmphex(isa_inw(test
, 0xe8), ==, 0x4422);
274 isa_outb(test
, 0xe1, 0x43);
275 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x87654322);
276 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8765);
277 g_assert_cmphex(isa_inw(test
, 0xe8), ==, 0x4322);
279 isa_outb(test
, 0xe0, 0x21);
280 g_assert_cmphex(isa_inl(test
, 0xe8), ==, 0x87654321);
281 g_assert_cmphex(isa_inw(test
, 0xea), ==, 0x8765);
282 g_assert_cmphex(isa_inw(test
, 0xe8), ==, 0x4321);
283 qtest_quit(global_qtest
);
287 int main(int argc
, char **argv
)
289 const char *arch
= qtest_get_arch();
293 g_test_init(&argc
, &argv
, NULL
);
295 for (i
= 0; test_cases
[i
].arch
; i
++) {
297 if (strcmp(test_cases
[i
].arch
, arch
) != 0) {
300 path
= g_strdup_printf("/%s/endianness/%s",
301 arch
, test_cases
[i
].machine
);
302 g_test_add_data_func(path
, &test_cases
[i
], test_endianness
);
304 path
= g_strdup_printf("/%s/endianness/split/%s",
305 arch
, test_cases
[i
].machine
);
306 g_test_add_data_func(path
, &test_cases
[i
], test_endianness_split
);
308 path
= g_strdup_printf("/%s/endianness/combine/%s",
309 arch
, test_cases
[i
].machine
);
310 g_test_add_data_func(path
, &test_cases
[i
], test_endianness_combine
);