root / tests / test-i386.c @ 564c8f99
History | View | Annotate | Download (23.2 kB)
1 | 4d1135e4 | bellard | #include <stdlib.h> |
---|---|---|---|
2 | 4d1135e4 | bellard | #include <stdio.h> |
3 | 6dbad63e | bellard | #include <inttypes.h> |
4 | 4d1135e4 | bellard | #include <math.h> |
5 | 4d1135e4 | bellard | |
6 | 5dd9488c | bellard | #define TEST_CMOV 0 |
7 | 5dd9488c | bellard | |
8 | 4d1135e4 | bellard | #define xglue(x, y) x ## y |
9 | 4d1135e4 | bellard | #define glue(x, y) xglue(x, y)
|
10 | 4d1135e4 | bellard | #define stringify(s) tostring(s)
|
11 | 4d1135e4 | bellard | #define tostring(s) #s |
12 | 4d1135e4 | bellard | |
13 | 4d1135e4 | bellard | #define CC_C 0x0001 |
14 | 4d1135e4 | bellard | #define CC_P 0x0004 |
15 | 4d1135e4 | bellard | #define CC_A 0x0010 |
16 | 4d1135e4 | bellard | #define CC_Z 0x0040 |
17 | 4d1135e4 | bellard | #define CC_S 0x0080 |
18 | 4d1135e4 | bellard | #define CC_O 0x0800 |
19 | 4d1135e4 | bellard | |
20 | 4d1135e4 | bellard | #define __init_call __attribute__ ((unused,__section__ (".initcall.init"))) |
21 | 4d1135e4 | bellard | |
22 | 4d1135e4 | bellard | static void *call_start __init_call = NULL; |
23 | 4d1135e4 | bellard | |
24 | 4b74fe1f | bellard | #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
|
25 | 4b74fe1f | bellard | |
26 | 4d1135e4 | bellard | #define OP add
|
27 | 4d1135e4 | bellard | #include "test-i386.h" |
28 | 4d1135e4 | bellard | |
29 | 4d1135e4 | bellard | #define OP sub
|
30 | 4d1135e4 | bellard | #include "test-i386.h" |
31 | 4d1135e4 | bellard | |
32 | 4d1135e4 | bellard | #define OP xor
|
33 | 4d1135e4 | bellard | #include "test-i386.h" |
34 | 4d1135e4 | bellard | |
35 | 4d1135e4 | bellard | #define OP and
|
36 | 4d1135e4 | bellard | #include "test-i386.h" |
37 | 4d1135e4 | bellard | |
38 | 4d1135e4 | bellard | #define OP or
|
39 | 4d1135e4 | bellard | #include "test-i386.h" |
40 | 4d1135e4 | bellard | |
41 | 4d1135e4 | bellard | #define OP cmp
|
42 | 4d1135e4 | bellard | #include "test-i386.h" |
43 | 4d1135e4 | bellard | |
44 | 4d1135e4 | bellard | #define OP adc
|
45 | 4d1135e4 | bellard | #define OP_CC
|
46 | 4d1135e4 | bellard | #include "test-i386.h" |
47 | 4d1135e4 | bellard | |
48 | 4d1135e4 | bellard | #define OP sbb
|
49 | 4d1135e4 | bellard | #define OP_CC
|
50 | 4d1135e4 | bellard | #include "test-i386.h" |
51 | 4d1135e4 | bellard | |
52 | 4d1135e4 | bellard | #define OP inc
|
53 | 4d1135e4 | bellard | #define OP_CC
|
54 | 4d1135e4 | bellard | #define OP1
|
55 | 4d1135e4 | bellard | #include "test-i386.h" |
56 | 4d1135e4 | bellard | |
57 | 4d1135e4 | bellard | #define OP dec
|
58 | 4d1135e4 | bellard | #define OP_CC
|
59 | 4d1135e4 | bellard | #define OP1
|
60 | 4d1135e4 | bellard | #include "test-i386.h" |
61 | 4d1135e4 | bellard | |
62 | 4d1135e4 | bellard | #define OP neg
|
63 | 4d1135e4 | bellard | #define OP_CC
|
64 | 4d1135e4 | bellard | #define OP1
|
65 | 4d1135e4 | bellard | #include "test-i386.h" |
66 | 4d1135e4 | bellard | |
67 | 4d1135e4 | bellard | #define OP not
|
68 | 4d1135e4 | bellard | #define OP_CC
|
69 | 4d1135e4 | bellard | #define OP1
|
70 | 4d1135e4 | bellard | #include "test-i386.h" |
71 | 4d1135e4 | bellard | |
72 | 4b74fe1f | bellard | #undef CC_MASK
|
73 | 4b74fe1f | bellard | #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
|
74 | 4b74fe1f | bellard | |
75 | 379ca80d | bellard | #define OP shl
|
76 | 379ca80d | bellard | #include "test-i386-shift.h" |
77 | 379ca80d | bellard | |
78 | 379ca80d | bellard | #define OP shr
|
79 | 379ca80d | bellard | #include "test-i386-shift.h" |
80 | 379ca80d | bellard | |
81 | 379ca80d | bellard | #define OP sar
|
82 | 379ca80d | bellard | #include "test-i386-shift.h" |
83 | 379ca80d | bellard | |
84 | 379ca80d | bellard | #define OP rol
|
85 | 379ca80d | bellard | #include "test-i386-shift.h" |
86 | 379ca80d | bellard | |
87 | 379ca80d | bellard | #define OP ror
|
88 | 379ca80d | bellard | #include "test-i386-shift.h" |
89 | 379ca80d | bellard | |
90 | 379ca80d | bellard | #define OP rcr
|
91 | 379ca80d | bellard | #define OP_CC
|
92 | 379ca80d | bellard | #include "test-i386-shift.h" |
93 | 379ca80d | bellard | |
94 | 379ca80d | bellard | #define OP rcl
|
95 | 379ca80d | bellard | #define OP_CC
|
96 | 379ca80d | bellard | #include "test-i386-shift.h" |
97 | 379ca80d | bellard | |
98 | d57c4e01 | bellard | #define OP shld
|
99 | d57c4e01 | bellard | #define OP_SHIFTD
|
100 | d57c4e01 | bellard | #define OP_NOBYTE
|
101 | d57c4e01 | bellard | #include "test-i386-shift.h" |
102 | d57c4e01 | bellard | |
103 | d57c4e01 | bellard | #define OP shrd
|
104 | d57c4e01 | bellard | #define OP_SHIFTD
|
105 | d57c4e01 | bellard | #define OP_NOBYTE
|
106 | d57c4e01 | bellard | #include "test-i386-shift.h" |
107 | d57c4e01 | bellard | |
108 | d57c4e01 | bellard | /* XXX: should be more precise ? */
|
109 | d57c4e01 | bellard | #undef CC_MASK
|
110 | d57c4e01 | bellard | #define CC_MASK (CC_C)
|
111 | d57c4e01 | bellard | |
112 | d57c4e01 | bellard | #define OP bt
|
113 | d57c4e01 | bellard | #define OP_NOBYTE
|
114 | d57c4e01 | bellard | #include "test-i386-shift.h" |
115 | d57c4e01 | bellard | |
116 | d57c4e01 | bellard | #define OP bts
|
117 | d57c4e01 | bellard | #define OP_NOBYTE
|
118 | d57c4e01 | bellard | #include "test-i386-shift.h" |
119 | d57c4e01 | bellard | |
120 | d57c4e01 | bellard | #define OP btr
|
121 | d57c4e01 | bellard | #define OP_NOBYTE
|
122 | d57c4e01 | bellard | #include "test-i386-shift.h" |
123 | d57c4e01 | bellard | |
124 | d57c4e01 | bellard | #define OP btc
|
125 | d57c4e01 | bellard | #define OP_NOBYTE
|
126 | d57c4e01 | bellard | #include "test-i386-shift.h" |
127 | 379ca80d | bellard | |
128 | 4d1135e4 | bellard | /* lea test (modrm support) */
|
129 | 4d1135e4 | bellard | #define TEST_LEA(STR)\
|
130 | 4d1135e4 | bellard | {\ |
131 | 4d1135e4 | bellard | asm("leal " STR ", %0"\ |
132 | 4d1135e4 | bellard | : "=r" (res)\
|
133 | 4d1135e4 | bellard | : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\ |
134 | 4d1135e4 | bellard | printf("lea %s = %08x\n", STR, res);\
|
135 | 4d1135e4 | bellard | } |
136 | 4d1135e4 | bellard | |
137 | 4d1135e4 | bellard | #define TEST_LEA16(STR)\
|
138 | 4d1135e4 | bellard | {\ |
139 | 4d1135e4 | bellard | asm(".code16 ; .byte 0x67 ; leal " STR ", %0 ; .code32"\ |
140 | 4d1135e4 | bellard | : "=wq" (res)\
|
141 | 4d1135e4 | bellard | : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\ |
142 | 4d1135e4 | bellard | printf("lea %s = %08x\n", STR, res);\
|
143 | 4d1135e4 | bellard | } |
144 | 4d1135e4 | bellard | |
145 | 4d1135e4 | bellard | |
146 | 4d1135e4 | bellard | void test_lea(void) |
147 | 4d1135e4 | bellard | { |
148 | 4d1135e4 | bellard | int eax, ebx, ecx, edx, esi, edi, res;
|
149 | 4d1135e4 | bellard | eax = 0x0001;
|
150 | 4d1135e4 | bellard | ebx = 0x0002;
|
151 | 4d1135e4 | bellard | ecx = 0x0004;
|
152 | 4d1135e4 | bellard | edx = 0x0008;
|
153 | 4d1135e4 | bellard | esi = 0x0010;
|
154 | 4d1135e4 | bellard | edi = 0x0020;
|
155 | 4d1135e4 | bellard | |
156 | 4d1135e4 | bellard | TEST_LEA("0x4000");
|
157 | 4d1135e4 | bellard | |
158 | 4d1135e4 | bellard | TEST_LEA("(%%eax)");
|
159 | 4d1135e4 | bellard | TEST_LEA("(%%ebx)");
|
160 | 4d1135e4 | bellard | TEST_LEA("(%%ecx)");
|
161 | 4d1135e4 | bellard | TEST_LEA("(%%edx)");
|
162 | 4d1135e4 | bellard | TEST_LEA("(%%esi)");
|
163 | 4d1135e4 | bellard | TEST_LEA("(%%edi)");
|
164 | 4d1135e4 | bellard | |
165 | 4d1135e4 | bellard | TEST_LEA("0x40(%%eax)");
|
166 | 4d1135e4 | bellard | TEST_LEA("0x40(%%ebx)");
|
167 | 4d1135e4 | bellard | TEST_LEA("0x40(%%ecx)");
|
168 | 4d1135e4 | bellard | TEST_LEA("0x40(%%edx)");
|
169 | 4d1135e4 | bellard | TEST_LEA("0x40(%%esi)");
|
170 | 4d1135e4 | bellard | TEST_LEA("0x40(%%edi)");
|
171 | 4d1135e4 | bellard | |
172 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%eax)");
|
173 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%ebx)");
|
174 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%ecx)");
|
175 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%edx)");
|
176 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%esi)");
|
177 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%edi)");
|
178 | 4d1135e4 | bellard | |
179 | 4d1135e4 | bellard | TEST_LEA("(%%eax, %%ecx)");
|
180 | 4d1135e4 | bellard | TEST_LEA("(%%ebx, %%edx)");
|
181 | 4d1135e4 | bellard | TEST_LEA("(%%ecx, %%ecx)");
|
182 | 4d1135e4 | bellard | TEST_LEA("(%%edx, %%ecx)");
|
183 | 4d1135e4 | bellard | TEST_LEA("(%%esi, %%ecx)");
|
184 | 4d1135e4 | bellard | TEST_LEA("(%%edi, %%ecx)");
|
185 | 4d1135e4 | bellard | |
186 | 4d1135e4 | bellard | TEST_LEA("0x40(%%eax, %%ecx)");
|
187 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%ebx, %%edx)");
|
188 | 4d1135e4 | bellard | |
189 | 4d1135e4 | bellard | TEST_LEA("(%%ecx, %%ecx, 2)");
|
190 | 4d1135e4 | bellard | TEST_LEA("(%%edx, %%ecx, 4)");
|
191 | 4d1135e4 | bellard | TEST_LEA("(%%esi, %%ecx, 8)");
|
192 | 4d1135e4 | bellard | |
193 | 4d1135e4 | bellard | TEST_LEA("(,%%eax, 2)");
|
194 | 4d1135e4 | bellard | TEST_LEA("(,%%ebx, 4)");
|
195 | 4d1135e4 | bellard | TEST_LEA("(,%%ecx, 8)");
|
196 | 4d1135e4 | bellard | |
197 | 4d1135e4 | bellard | TEST_LEA("0x40(,%%eax, 2)");
|
198 | 4d1135e4 | bellard | TEST_LEA("0x40(,%%ebx, 4)");
|
199 | 4d1135e4 | bellard | TEST_LEA("0x40(,%%ecx, 8)");
|
200 | 4d1135e4 | bellard | |
201 | 4d1135e4 | bellard | |
202 | 4d1135e4 | bellard | TEST_LEA("-10(%%ecx, %%ecx, 2)");
|
203 | 4d1135e4 | bellard | TEST_LEA("-10(%%edx, %%ecx, 4)");
|
204 | 4d1135e4 | bellard | TEST_LEA("-10(%%esi, %%ecx, 8)");
|
205 | 4d1135e4 | bellard | |
206 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%ecx, %%ecx, 2)");
|
207 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%edx, %%ecx, 4)");
|
208 | 4d1135e4 | bellard | TEST_LEA("0x4000(%%esi, %%ecx, 8)");
|
209 | 4d1135e4 | bellard | |
210 | 4d1135e4 | bellard | /* limited 16 bit addressing test */
|
211 | 4d1135e4 | bellard | TEST_LEA16("0x4000");
|
212 | 4d1135e4 | bellard | TEST_LEA16("(%%bx)");
|
213 | 4d1135e4 | bellard | TEST_LEA16("(%%si)");
|
214 | 4d1135e4 | bellard | TEST_LEA16("(%%di)");
|
215 | 4d1135e4 | bellard | TEST_LEA16("0x40(%%bx)");
|
216 | 4d1135e4 | bellard | TEST_LEA16("0x40(%%si)");
|
217 | 4d1135e4 | bellard | TEST_LEA16("0x40(%%di)");
|
218 | 4d1135e4 | bellard | TEST_LEA16("0x4000(%%bx)");
|
219 | 4d1135e4 | bellard | TEST_LEA16("0x4000(%%si)");
|
220 | 4d1135e4 | bellard | TEST_LEA16("(%%bx,%%si)");
|
221 | 4d1135e4 | bellard | TEST_LEA16("(%%bx,%%di)");
|
222 | 4d1135e4 | bellard | TEST_LEA16("0x40(%%bx,%%si)");
|
223 | 4d1135e4 | bellard | TEST_LEA16("0x40(%%bx,%%di)");
|
224 | 4d1135e4 | bellard | TEST_LEA16("0x4000(%%bx,%%si)");
|
225 | 4d1135e4 | bellard | TEST_LEA16("0x4000(%%bx,%%di)");
|
226 | 4d1135e4 | bellard | } |
227 | 4d1135e4 | bellard | |
228 | 4d1135e4 | bellard | #define TEST_JCC(JCC, v1, v2)\
|
229 | 4d1135e4 | bellard | {\ |
230 | 5dd9488c | bellard | int res;\
|
231 | 4d1135e4 | bellard | asm("movl $1, %0\n\t"\ |
232 | 4d1135e4 | bellard | "cmpl %2, %1\n\t"\
|
233 | 5dd9488c | bellard | "j" JCC " 1f\n\t"\ |
234 | 4d1135e4 | bellard | "movl $0, %0\n\t"\
|
235 | 4d1135e4 | bellard | "1:\n\t"\
|
236 | 4d1135e4 | bellard | : "=r" (res)\
|
237 | 4d1135e4 | bellard | : "r" (v1), "r" (v2));\ |
238 | 5dd9488c | bellard | printf("%-10s %d\n", "j" JCC, res);\ |
239 | 5dd9488c | bellard | \ |
240 | 5dd9488c | bellard | asm("movl $0, %0\n\t"\ |
241 | 5dd9488c | bellard | "cmpl %2, %1\n\t"\
|
242 | 5dd9488c | bellard | "set" JCC " %b0\n\t"\ |
243 | 5dd9488c | bellard | : "=r" (res)\
|
244 | 5dd9488c | bellard | : "r" (v1), "r" (v2));\ |
245 | 5dd9488c | bellard | printf("%-10s %d\n", "set" JCC, res);\ |
246 | 5dd9488c | bellard | if (TEST_CMOV) {\
|
247 | 5dd9488c | bellard | asm("movl $0x12345678, %0\n\t"\ |
248 | 5dd9488c | bellard | "cmpl %2, %1\n\t"\
|
249 | 5dd9488c | bellard | "cmov" JCC "l %3, %0\n\t"\ |
250 | 5dd9488c | bellard | : "=r" (res)\
|
251 | 5dd9488c | bellard | : "r" (v1), "r" (v2), "m" (1));\ |
252 | 5dd9488c | bellard | printf("%-10s R=0x%08x\n", "cmov" JCC "l", res);\ |
253 | 5dd9488c | bellard | asm("movl $0x12345678, %0\n\t"\ |
254 | 5dd9488c | bellard | "cmpl %2, %1\n\t"\
|
255 | 5dd9488c | bellard | "cmov" JCC "w %w3, %w0\n\t"\ |
256 | 5dd9488c | bellard | : "=r" (res)\
|
257 | 5dd9488c | bellard | : "r" (v1), "r" (v2), "r" (1));\ |
258 | 5dd9488c | bellard | printf("%-10s R=0x%08x\n", "cmov" JCC "w", res);\ |
259 | 5dd9488c | bellard | } \ |
260 | 4d1135e4 | bellard | } |
261 | 4d1135e4 | bellard | |
262 | 4d1135e4 | bellard | /* various jump tests */
|
263 | 4d1135e4 | bellard | void test_jcc(void) |
264 | 4d1135e4 | bellard | { |
265 | 5dd9488c | bellard | TEST_JCC("ne", 1, 1); |
266 | 5dd9488c | bellard | TEST_JCC("ne", 1, 0); |
267 | 4d1135e4 | bellard | |
268 | 5dd9488c | bellard | TEST_JCC("e", 1, 1); |
269 | 5dd9488c | bellard | TEST_JCC("e", 1, 0); |
270 | 4d1135e4 | bellard | |
271 | 5dd9488c | bellard | TEST_JCC("l", 1, 1); |
272 | 5dd9488c | bellard | TEST_JCC("l", 1, 0); |
273 | 5dd9488c | bellard | TEST_JCC("l", 1, -1); |
274 | 4d1135e4 | bellard | |
275 | 5dd9488c | bellard | TEST_JCC("le", 1, 1); |
276 | 5dd9488c | bellard | TEST_JCC("le", 1, 0); |
277 | 5dd9488c | bellard | TEST_JCC("le", 1, -1); |
278 | 4d1135e4 | bellard | |
279 | 5dd9488c | bellard | TEST_JCC("ge", 1, 1); |
280 | 5dd9488c | bellard | TEST_JCC("ge", 1, 0); |
281 | 5dd9488c | bellard | TEST_JCC("ge", -1, 1); |
282 | 4d1135e4 | bellard | |
283 | 5dd9488c | bellard | TEST_JCC("g", 1, 1); |
284 | 5dd9488c | bellard | TEST_JCC("g", 1, 0); |
285 | 5dd9488c | bellard | TEST_JCC("g", 1, -1); |
286 | 4d1135e4 | bellard | |
287 | 5dd9488c | bellard | TEST_JCC("b", 1, 1); |
288 | 5dd9488c | bellard | TEST_JCC("b", 1, 0); |
289 | 5dd9488c | bellard | TEST_JCC("b", 1, -1); |
290 | 4d1135e4 | bellard | |
291 | 5dd9488c | bellard | TEST_JCC("be", 1, 1); |
292 | 5dd9488c | bellard | TEST_JCC("be", 1, 0); |
293 | 5dd9488c | bellard | TEST_JCC("be", 1, -1); |
294 | 4d1135e4 | bellard | |
295 | 5dd9488c | bellard | TEST_JCC("ae", 1, 1); |
296 | 5dd9488c | bellard | TEST_JCC("ae", 1, 0); |
297 | 5dd9488c | bellard | TEST_JCC("ae", 1, -1); |
298 | 4d1135e4 | bellard | |
299 | 5dd9488c | bellard | TEST_JCC("a", 1, 1); |
300 | 5dd9488c | bellard | TEST_JCC("a", 1, 0); |
301 | 5dd9488c | bellard | TEST_JCC("a", 1, -1); |
302 | 4d1135e4 | bellard | |
303 | 4d1135e4 | bellard | |
304 | 5dd9488c | bellard | TEST_JCC("p", 1, 1); |
305 | 5dd9488c | bellard | TEST_JCC("p", 1, 0); |
306 | 4d1135e4 | bellard | |
307 | 5dd9488c | bellard | TEST_JCC("np", 1, 1); |
308 | 5dd9488c | bellard | TEST_JCC("np", 1, 0); |
309 | 4d1135e4 | bellard | |
310 | 5dd9488c | bellard | TEST_JCC("o", 0x7fffffff, 0); |
311 | 5dd9488c | bellard | TEST_JCC("o", 0x7fffffff, -1); |
312 | 4d1135e4 | bellard | |
313 | 5dd9488c | bellard | TEST_JCC("no", 0x7fffffff, 0); |
314 | 5dd9488c | bellard | TEST_JCC("no", 0x7fffffff, -1); |
315 | 4d1135e4 | bellard | |
316 | 5dd9488c | bellard | TEST_JCC("s", 0, 1); |
317 | 5dd9488c | bellard | TEST_JCC("s", 0, -1); |
318 | 5dd9488c | bellard | TEST_JCC("s", 0, 0); |
319 | 4d1135e4 | bellard | |
320 | 5dd9488c | bellard | TEST_JCC("ns", 0, 1); |
321 | 5dd9488c | bellard | TEST_JCC("ns", 0, -1); |
322 | 5dd9488c | bellard | TEST_JCC("ns", 0, 0); |
323 | 4d1135e4 | bellard | } |
324 | 4d1135e4 | bellard | |
325 | 4b74fe1f | bellard | #undef CC_MASK
|
326 | 4b74fe1f | bellard | #define CC_MASK (CC_O | CC_C)
|
327 | 4b74fe1f | bellard | |
328 | 4b74fe1f | bellard | #define OP mul
|
329 | 4b74fe1f | bellard | #include "test-i386-muldiv.h" |
330 | 4b74fe1f | bellard | |
331 | 4b74fe1f | bellard | #define OP imul
|
332 | 4b74fe1f | bellard | #include "test-i386-muldiv.h" |
333 | 4b74fe1f | bellard | |
334 | 4b74fe1f | bellard | #undef CC_MASK
|
335 | 4b74fe1f | bellard | #define CC_MASK (0) |
336 | 4b74fe1f | bellard | |
337 | 4b74fe1f | bellard | #define OP div
|
338 | 4b74fe1f | bellard | #include "test-i386-muldiv.h" |
339 | 4b74fe1f | bellard | |
340 | 4b74fe1f | bellard | #define OP idiv
|
341 | 4b74fe1f | bellard | #include "test-i386-muldiv.h" |
342 | 4b74fe1f | bellard | |
343 | 4b74fe1f | bellard | void test_imulw2(int op0, int op1) |
344 | 4b74fe1f | bellard | { |
345 | 4b74fe1f | bellard | int res, s1, s0, flags;
|
346 | 4b74fe1f | bellard | s0 = op0; |
347 | 4b74fe1f | bellard | s1 = op1; |
348 | 4b74fe1f | bellard | res = s0; |
349 | 4b74fe1f | bellard | flags = 0;
|
350 | 4b74fe1f | bellard | asm ("push %4\n\t" |
351 | 4b74fe1f | bellard | "popf\n\t"
|
352 | 4b74fe1f | bellard | "imulw %w2, %w0\n\t"
|
353 | 4b74fe1f | bellard | "pushf\n\t"
|
354 | 4b74fe1f | bellard | "popl %1\n\t"
|
355 | 4b74fe1f | bellard | : "=q" (res), "=g" (flags) |
356 | 4b74fe1f | bellard | : "q" (s1), "0" (res), "1" (flags)); |
357 | 4b74fe1f | bellard | printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
|
358 | 4b74fe1f | bellard | "imulw", s0, s1, res, flags & CC_MASK);
|
359 | 4b74fe1f | bellard | } |
360 | 4b74fe1f | bellard | |
361 | 4b74fe1f | bellard | void test_imull2(int op0, int op1) |
362 | 4b74fe1f | bellard | { |
363 | 4b74fe1f | bellard | int res, s1, s0, flags;
|
364 | 4b74fe1f | bellard | s0 = op0; |
365 | 4b74fe1f | bellard | s1 = op1; |
366 | 4b74fe1f | bellard | res = s0; |
367 | 4b74fe1f | bellard | flags = 0;
|
368 | 4b74fe1f | bellard | asm ("push %4\n\t" |
369 | 4b74fe1f | bellard | "popf\n\t"
|
370 | 4b74fe1f | bellard | "imull %2, %0\n\t"
|
371 | 4b74fe1f | bellard | "pushf\n\t"
|
372 | 4b74fe1f | bellard | "popl %1\n\t"
|
373 | 4b74fe1f | bellard | : "=q" (res), "=g" (flags) |
374 | 4b74fe1f | bellard | : "q" (s1), "0" (res), "1" (flags)); |
375 | 4b74fe1f | bellard | printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
|
376 | 4b74fe1f | bellard | "imull", s0, s1, res, flags & CC_MASK);
|
377 | 4b74fe1f | bellard | } |
378 | 4b74fe1f | bellard | |
379 | 4b74fe1f | bellard | void test_mul(void) |
380 | 4b74fe1f | bellard | { |
381 | 4b74fe1f | bellard | test_imulb(0x1234561d, 4); |
382 | 4b74fe1f | bellard | test_imulb(3, -4); |
383 | 4b74fe1f | bellard | test_imulb(0x80, 0x80); |
384 | 4b74fe1f | bellard | test_imulb(0x10, 0x10); |
385 | 4b74fe1f | bellard | |
386 | 4b74fe1f | bellard | test_imulw(0, 0x1234001d, 45); |
387 | 4b74fe1f | bellard | test_imulw(0, 23, -45); |
388 | 4b74fe1f | bellard | test_imulw(0, 0x8000, 0x8000); |
389 | 4b74fe1f | bellard | test_imulw(0, 0x100, 0x100); |
390 | 4b74fe1f | bellard | |
391 | 4b74fe1f | bellard | test_imull(0, 0x1234001d, 45); |
392 | 4b74fe1f | bellard | test_imull(0, 23, -45); |
393 | 4b74fe1f | bellard | test_imull(0, 0x80000000, 0x80000000); |
394 | 4b74fe1f | bellard | test_imull(0, 0x10000, 0x10000); |
395 | 4b74fe1f | bellard | |
396 | 4b74fe1f | bellard | test_mulb(0x1234561d, 4); |
397 | 4b74fe1f | bellard | test_mulb(3, -4); |
398 | 4b74fe1f | bellard | test_mulb(0x80, 0x80); |
399 | 4b74fe1f | bellard | test_mulb(0x10, 0x10); |
400 | 4b74fe1f | bellard | |
401 | 4b74fe1f | bellard | test_mulw(0, 0x1234001d, 45); |
402 | 4b74fe1f | bellard | test_mulw(0, 23, -45); |
403 | 4b74fe1f | bellard | test_mulw(0, 0x8000, 0x8000); |
404 | 4b74fe1f | bellard | test_mulw(0, 0x100, 0x100); |
405 | 4b74fe1f | bellard | |
406 | 4b74fe1f | bellard | test_mull(0, 0x1234001d, 45); |
407 | 4b74fe1f | bellard | test_mull(0, 23, -45); |
408 | 4b74fe1f | bellard | test_mull(0, 0x80000000, 0x80000000); |
409 | 4b74fe1f | bellard | test_mull(0, 0x10000, 0x10000); |
410 | 4b74fe1f | bellard | |
411 | 4b74fe1f | bellard | test_imulw2(0x1234001d, 45); |
412 | 4b74fe1f | bellard | test_imulw2(23, -45); |
413 | 4b74fe1f | bellard | test_imulw2(0x8000, 0x8000); |
414 | 4b74fe1f | bellard | test_imulw2(0x100, 0x100); |
415 | 4b74fe1f | bellard | |
416 | 4b74fe1f | bellard | test_imull2(0x1234001d, 45); |
417 | 4b74fe1f | bellard | test_imull2(23, -45); |
418 | 4b74fe1f | bellard | test_imull2(0x80000000, 0x80000000); |
419 | 4b74fe1f | bellard | test_imull2(0x10000, 0x10000); |
420 | 4b74fe1f | bellard | |
421 | 4b74fe1f | bellard | test_idivb(0x12341678, 0x127e); |
422 | 4b74fe1f | bellard | test_idivb(0x43210123, -5); |
423 | 4b74fe1f | bellard | test_idivb(0x12340004, -1); |
424 | 4b74fe1f | bellard | |
425 | 4b74fe1f | bellard | test_idivw(0, 0x12345678, 12347); |
426 | 4b74fe1f | bellard | test_idivw(0, -23223, -45); |
427 | 4b74fe1f | bellard | test_idivw(0, 0x12348000, -1); |
428 | 4b74fe1f | bellard | test_idivw(0x12343, 0x12345678, 0x81238567); |
429 | 4b74fe1f | bellard | |
430 | 4b74fe1f | bellard | test_idivl(0, 0x12345678, 12347); |
431 | 4b74fe1f | bellard | test_idivl(0, -233223, -45); |
432 | 4b74fe1f | bellard | test_idivl(0, 0x80000000, -1); |
433 | 4b74fe1f | bellard | test_idivl(0x12343, 0x12345678, 0x81234567); |
434 | 4b74fe1f | bellard | |
435 | 4b74fe1f | bellard | test_divb(0x12341678, 0x127e); |
436 | 4b74fe1f | bellard | test_divb(0x43210123, -5); |
437 | 4b74fe1f | bellard | test_divb(0x12340004, -1); |
438 | 4b74fe1f | bellard | |
439 | 4b74fe1f | bellard | test_divw(0, 0x12345678, 12347); |
440 | 4b74fe1f | bellard | test_divw(0, -23223, -45); |
441 | 4b74fe1f | bellard | test_divw(0, 0x12348000, -1); |
442 | 4b74fe1f | bellard | test_divw(0x12343, 0x12345678, 0x81238567); |
443 | 4b74fe1f | bellard | |
444 | 4b74fe1f | bellard | test_divl(0, 0x12345678, 12347); |
445 | 4b74fe1f | bellard | test_divl(0, -233223, -45); |
446 | 4b74fe1f | bellard | test_divl(0, 0x80000000, -1); |
447 | 4b74fe1f | bellard | test_divl(0x12343, 0x12345678, 0x81234567); |
448 | 4b74fe1f | bellard | } |
449 | 4b74fe1f | bellard | |
450 | 9d8e9c09 | bellard | #define TEST_BSX(op, size, op0)\
|
451 | 9d8e9c09 | bellard | {\ |
452 | 9d8e9c09 | bellard | int res, val, resz;\
|
453 | 9d8e9c09 | bellard | val = op0;\ |
454 | 9d8e9c09 | bellard | asm("xorl %1, %1 ; " #op " %" size "2, %" size "0 ; setz %b1" \ |
455 | 9d8e9c09 | bellard | : "=r" (res), "=q" (resz)\ |
456 | 9d8e9c09 | bellard | : "g" (val));\
|
457 | 9d8e9c09 | bellard | printf("%-10s A=%08x R=%08x %d\n", #op, val, resz ? 0 : res, resz);\ |
458 | 9d8e9c09 | bellard | } |
459 | 9d8e9c09 | bellard | |
460 | 9d8e9c09 | bellard | void test_bsx(void) |
461 | 9d8e9c09 | bellard | { |
462 | 9d8e9c09 | bellard | TEST_BSX(bsrw, "w", 0); |
463 | 9d8e9c09 | bellard | TEST_BSX(bsrw, "w", 0x12340128); |
464 | 9d8e9c09 | bellard | TEST_BSX(bsrl, "", 0); |
465 | 9d8e9c09 | bellard | TEST_BSX(bsrl, "", 0x00340128); |
466 | 9d8e9c09 | bellard | TEST_BSX(bsfw, "w", 0); |
467 | 9d8e9c09 | bellard | TEST_BSX(bsfw, "w", 0x12340128); |
468 | 9d8e9c09 | bellard | TEST_BSX(bsfl, "", 0); |
469 | 9d8e9c09 | bellard | TEST_BSX(bsfl, "", 0x00340128); |
470 | 9d8e9c09 | bellard | } |
471 | 9d8e9c09 | bellard | |
472 | 55480af8 | bellard | /**********************************************/
|
473 | 55480af8 | bellard | |
474 | 9d8e9c09 | bellard | void test_fops(double a, double b) |
475 | 9d8e9c09 | bellard | { |
476 | 9d8e9c09 | bellard | printf("a=%f b=%f a+b=%f\n", a, b, a + b);
|
477 | 9d8e9c09 | bellard | printf("a=%f b=%f a-b=%f\n", a, b, a - b);
|
478 | 9d8e9c09 | bellard | printf("a=%f b=%f a*b=%f\n", a, b, a * b);
|
479 | 9d8e9c09 | bellard | printf("a=%f b=%f a/b=%f\n", a, b, a / b);
|
480 | 9d8e9c09 | bellard | printf("a=%f b=%f fmod(a, b)=%f\n", a, b, fmod(a, b));
|
481 | 9d8e9c09 | bellard | printf("a=%f sqrt(a)=%f\n", a, sqrt(a));
|
482 | 9d8e9c09 | bellard | printf("a=%f sin(a)=%f\n", a, sin(a));
|
483 | 9d8e9c09 | bellard | printf("a=%f cos(a)=%f\n", a, cos(a));
|
484 | 9d8e9c09 | bellard | printf("a=%f tan(a)=%f\n", a, tan(a));
|
485 | 9d8e9c09 | bellard | printf("a=%f log(a)=%f\n", a, log(a));
|
486 | 9d8e9c09 | bellard | printf("a=%f exp(a)=%f\n", a, exp(a));
|
487 | 9d8e9c09 | bellard | printf("a=%f b=%f atan2(a, b)=%f\n", a, b, atan2(a, b));
|
488 | 9d8e9c09 | bellard | /* just to test some op combining */
|
489 | 9d8e9c09 | bellard | printf("a=%f asin(sin(a))=%f\n", a, asin(sin(a)));
|
490 | 9d8e9c09 | bellard | printf("a=%f acos(cos(a))=%f\n", a, acos(cos(a)));
|
491 | 9d8e9c09 | bellard | printf("a=%f atan(tan(a))=%f\n", a, atan(tan(a)));
|
492 | 9d8e9c09 | bellard | |
493 | 9d8e9c09 | bellard | } |
494 | 9d8e9c09 | bellard | |
495 | 9d8e9c09 | bellard | void test_fcmp(double a, double b) |
496 | 9d8e9c09 | bellard | { |
497 | 9d8e9c09 | bellard | printf("(%f<%f)=%d\n",
|
498 | 9d8e9c09 | bellard | a, b, a < b); |
499 | 9d8e9c09 | bellard | printf("(%f<=%f)=%d\n",
|
500 | 9d8e9c09 | bellard | a, b, a <= b); |
501 | 9d8e9c09 | bellard | printf("(%f==%f)=%d\n",
|
502 | 9d8e9c09 | bellard | a, b, a == b); |
503 | 9d8e9c09 | bellard | printf("(%f>%f)=%d\n",
|
504 | 9d8e9c09 | bellard | a, b, a > b); |
505 | 9d8e9c09 | bellard | printf("(%f<=%f)=%d\n",
|
506 | 9d8e9c09 | bellard | a, b, a >= b); |
507 | 9d8e9c09 | bellard | } |
508 | 9d8e9c09 | bellard | |
509 | 9d8e9c09 | bellard | void test_fcvt(double a) |
510 | 9d8e9c09 | bellard | { |
511 | 9d8e9c09 | bellard | float fa;
|
512 | 9d8e9c09 | bellard | long double la; |
513 | 9d8e9c09 | bellard | |
514 | 9d8e9c09 | bellard | fa = a; |
515 | 9d8e9c09 | bellard | la = a; |
516 | 9d8e9c09 | bellard | printf("(float)%f = %f\n", a, fa);
|
517 | 9d8e9c09 | bellard | printf("(long double)%f = %Lf\n", a, la);
|
518 | c5e9815d | bellard | printf("a=%016Lx\n", *(long long *)&a); |
519 | c5e9815d | bellard | printf("la=%016Lx %04x\n", *(long long *)&la, |
520 | c5e9815d | bellard | *(unsigned short *)((char *)(&la) + 8)); |
521 | 9d8e9c09 | bellard | printf("a=%f floor(a)=%f\n", a, floor(a));
|
522 | 9d8e9c09 | bellard | printf("a=%f ceil(a)=%f\n", a, ceil(a));
|
523 | 9d8e9c09 | bellard | printf("a=%f rint(a)=%f\n", a, rint(a));
|
524 | 9d8e9c09 | bellard | } |
525 | 9d8e9c09 | bellard | |
526 | 9d8e9c09 | bellard | #define TEST(N) \
|
527 | 9d8e9c09 | bellard | asm("fld" #N : "=t" (a)); \ |
528 | 9d8e9c09 | bellard | printf("fld" #N "= %f\n", a); |
529 | 9d8e9c09 | bellard | |
530 | 9d8e9c09 | bellard | void test_fconst(void) |
531 | 9d8e9c09 | bellard | { |
532 | 9d8e9c09 | bellard | double a;
|
533 | 9d8e9c09 | bellard | TEST(1);
|
534 | 9d8e9c09 | bellard | TEST(l2t); |
535 | 9d8e9c09 | bellard | TEST(l2e); |
536 | 9d8e9c09 | bellard | TEST(pi); |
537 | 9d8e9c09 | bellard | TEST(lg2); |
538 | 9d8e9c09 | bellard | TEST(ln2); |
539 | 9d8e9c09 | bellard | TEST(z); |
540 | 9d8e9c09 | bellard | } |
541 | 9d8e9c09 | bellard | |
542 | c5e9815d | bellard | void test_fbcd(double a) |
543 | c5e9815d | bellard | { |
544 | c5e9815d | bellard | unsigned short bcd[5]; |
545 | c5e9815d | bellard | double b;
|
546 | c5e9815d | bellard | |
547 | c5e9815d | bellard | asm("fbstp %0" : "=m" (bcd[0]) : "t" (a) : "st"); |
548 | c5e9815d | bellard | asm("fbld %1" : "=t" (b) : "m" (bcd[0])); |
549 | c5e9815d | bellard | printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n",
|
550 | c5e9815d | bellard | a, bcd[4], bcd[3], bcd[2], bcd[1], bcd[0], b); |
551 | c5e9815d | bellard | } |
552 | c5e9815d | bellard | |
553 | 9d8e9c09 | bellard | void test_floats(void) |
554 | 9d8e9c09 | bellard | { |
555 | 9d8e9c09 | bellard | test_fops(2, 3); |
556 | 9d8e9c09 | bellard | test_fops(1.4, -5); |
557 | 9d8e9c09 | bellard | test_fcmp(2, -1); |
558 | 9d8e9c09 | bellard | test_fcmp(2, 2); |
559 | 9d8e9c09 | bellard | test_fcmp(2, 3); |
560 | 9d8e9c09 | bellard | test_fcvt(1.0/7.0); |
561 | 9d8e9c09 | bellard | test_fcvt(-1.0/9.0); |
562 | 9d8e9c09 | bellard | test_fcvt(1e30);
|
563 | 9d8e9c09 | bellard | test_fconst(); |
564 | c5e9815d | bellard | test_fbcd(1234567890123456);
|
565 | c5e9815d | bellard | test_fbcd(-123451234567890);
|
566 | 9d8e9c09 | bellard | } |
567 | 4b74fe1f | bellard | |
568 | 55480af8 | bellard | /**********************************************/
|
569 | 55480af8 | bellard | |
570 | 55480af8 | bellard | #define TEST_BCD(op, op0, cc_in, cc_mask)\
|
571 | 55480af8 | bellard | {\ |
572 | 55480af8 | bellard | int res, flags;\
|
573 | 55480af8 | bellard | res = op0;\ |
574 | 55480af8 | bellard | flags = cc_in;\ |
575 | 55480af8 | bellard | asm ("push %3\n\t"\ |
576 | 55480af8 | bellard | "popf\n\t"\
|
577 | 55480af8 | bellard | #op "\n\t"\ |
578 | 55480af8 | bellard | "pushf\n\t"\
|
579 | 55480af8 | bellard | "popl %1\n\t"\
|
580 | 55480af8 | bellard | : "=a" (res), "=g" (flags)\ |
581 | 55480af8 | bellard | : "0" (res), "1" (flags));\ |
582 | 55480af8 | bellard | printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",\
|
583 | 55480af8 | bellard | #op, op0, res, cc_in, flags & cc_mask);\
|
584 | 55480af8 | bellard | } |
585 | 55480af8 | bellard | |
586 | 55480af8 | bellard | void test_bcd(void) |
587 | 55480af8 | bellard | { |
588 | 55480af8 | bellard | TEST_BCD(daa, 0x12340503, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
589 | 55480af8 | bellard | TEST_BCD(daa, 0x12340506, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
590 | 55480af8 | bellard | TEST_BCD(daa, 0x12340507, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
591 | 55480af8 | bellard | TEST_BCD(daa, 0x12340559, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
592 | 55480af8 | bellard | TEST_BCD(daa, 0x12340560, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
593 | 55480af8 | bellard | TEST_BCD(daa, 0x1234059f, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
594 | 55480af8 | bellard | TEST_BCD(daa, 0x123405a0, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
595 | 55480af8 | bellard | TEST_BCD(daa, 0x12340503, 0, (CC_C | CC_P | CC_Z | CC_S | CC_A)); |
596 | 55480af8 | bellard | TEST_BCD(daa, 0x12340506, 0, (CC_C | CC_P | CC_Z | CC_S | CC_A)); |
597 | 55480af8 | bellard | TEST_BCD(daa, 0x12340503, CC_C, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
598 | 55480af8 | bellard | TEST_BCD(daa, 0x12340506, CC_C, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
599 | 55480af8 | bellard | TEST_BCD(daa, 0x12340503, CC_C | CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
600 | 55480af8 | bellard | TEST_BCD(daa, 0x12340506, CC_C | CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
601 | 55480af8 | bellard | |
602 | 55480af8 | bellard | TEST_BCD(das, 0x12340503, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
603 | 55480af8 | bellard | TEST_BCD(das, 0x12340506, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
604 | 55480af8 | bellard | TEST_BCD(das, 0x12340507, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
605 | 55480af8 | bellard | TEST_BCD(das, 0x12340559, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
606 | 55480af8 | bellard | TEST_BCD(das, 0x12340560, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
607 | 55480af8 | bellard | TEST_BCD(das, 0x1234059f, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
608 | 55480af8 | bellard | TEST_BCD(das, 0x123405a0, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
609 | 55480af8 | bellard | TEST_BCD(das, 0x12340503, 0, (CC_C | CC_P | CC_Z | CC_S | CC_A)); |
610 | 55480af8 | bellard | TEST_BCD(das, 0x12340506, 0, (CC_C | CC_P | CC_Z | CC_S | CC_A)); |
611 | 55480af8 | bellard | TEST_BCD(das, 0x12340503, CC_C, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
612 | 55480af8 | bellard | TEST_BCD(das, 0x12340506, CC_C, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
613 | 55480af8 | bellard | TEST_BCD(das, 0x12340503, CC_C | CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
614 | 55480af8 | bellard | TEST_BCD(das, 0x12340506, CC_C | CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_A));
|
615 | 55480af8 | bellard | |
616 | 55480af8 | bellard | TEST_BCD(aaa, 0x12340205, CC_A, (CC_C | CC_A));
|
617 | 55480af8 | bellard | TEST_BCD(aaa, 0x12340306, CC_A, (CC_C | CC_A));
|
618 | 55480af8 | bellard | TEST_BCD(aaa, 0x1234040a, CC_A, (CC_C | CC_A));
|
619 | 55480af8 | bellard | TEST_BCD(aaa, 0x123405fa, CC_A, (CC_C | CC_A));
|
620 | 55480af8 | bellard | TEST_BCD(aaa, 0x12340205, 0, (CC_C | CC_A)); |
621 | 55480af8 | bellard | TEST_BCD(aaa, 0x12340306, 0, (CC_C | CC_A)); |
622 | 55480af8 | bellard | TEST_BCD(aaa, 0x1234040a, 0, (CC_C | CC_A)); |
623 | 55480af8 | bellard | TEST_BCD(aaa, 0x123405fa, 0, (CC_C | CC_A)); |
624 | 55480af8 | bellard | |
625 | 55480af8 | bellard | TEST_BCD(aas, 0x12340205, CC_A, (CC_C | CC_A));
|
626 | 55480af8 | bellard | TEST_BCD(aas, 0x12340306, CC_A, (CC_C | CC_A));
|
627 | 55480af8 | bellard | TEST_BCD(aas, 0x1234040a, CC_A, (CC_C | CC_A));
|
628 | 55480af8 | bellard | TEST_BCD(aas, 0x123405fa, CC_A, (CC_C | CC_A));
|
629 | 55480af8 | bellard | TEST_BCD(aas, 0x12340205, 0, (CC_C | CC_A)); |
630 | 55480af8 | bellard | TEST_BCD(aas, 0x12340306, 0, (CC_C | CC_A)); |
631 | 55480af8 | bellard | TEST_BCD(aas, 0x1234040a, 0, (CC_C | CC_A)); |
632 | 55480af8 | bellard | TEST_BCD(aas, 0x123405fa, 0, (CC_C | CC_A)); |
633 | 55480af8 | bellard | |
634 | 55480af8 | bellard | TEST_BCD(aam, 0x12340547, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A));
|
635 | 55480af8 | bellard | TEST_BCD(aad, 0x12340407, CC_A, (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A));
|
636 | 55480af8 | bellard | } |
637 | 55480af8 | bellard | |
638 | e5918247 | bellard | #define TEST_XCHG(op, size, opconst)\
|
639 | e5918247 | bellard | {\ |
640 | e5918247 | bellard | int op0, op1;\
|
641 | e5918247 | bellard | op0 = 0x12345678;\
|
642 | e5918247 | bellard | op1 = 0xfbca7654;\
|
643 | e5918247 | bellard | asm(#op " %" size "0, %" size "1" \ |
644 | e5918247 | bellard | : "=q" (op0), opconst (op1) \
|
645 | e5918247 | bellard | : "0" (op0), "1" (op1));\ |
646 | e5918247 | bellard | printf("%-10s A=%08x B=%08x\n",\
|
647 | e5918247 | bellard | #op, op0, op1);\
|
648 | e5918247 | bellard | } |
649 | e5918247 | bellard | |
650 | e5918247 | bellard | #define TEST_CMPXCHG(op, size, opconst, eax)\
|
651 | e5918247 | bellard | {\ |
652 | e5918247 | bellard | int op0, op1;\
|
653 | e5918247 | bellard | op0 = 0x12345678;\
|
654 | e5918247 | bellard | op1 = 0xfbca7654;\
|
655 | e5918247 | bellard | asm(#op " %" size "0, %" size "1" \ |
656 | e5918247 | bellard | : "=q" (op0), opconst (op1) \
|
657 | e5918247 | bellard | : "0" (op0), "1" (op1), "a" (eax));\ |
658 | e5918247 | bellard | printf("%-10s EAX=%08x A=%08x C=%08x\n",\
|
659 | e5918247 | bellard | #op, eax, op0, op1);\
|
660 | e5918247 | bellard | } |
661 | e5918247 | bellard | |
662 | e5918247 | bellard | void test_xchg(void) |
663 | e5918247 | bellard | { |
664 | e5918247 | bellard | TEST_XCHG(xchgl, "", "=q"); |
665 | e5918247 | bellard | TEST_XCHG(xchgw, "w", "=q"); |
666 | e5918247 | bellard | TEST_XCHG(xchgb, "b", "=q"); |
667 | e5918247 | bellard | |
668 | e5918247 | bellard | TEST_XCHG(xchgl, "", "=m"); |
669 | e5918247 | bellard | TEST_XCHG(xchgw, "w", "=m"); |
670 | e5918247 | bellard | TEST_XCHG(xchgb, "b", "=m"); |
671 | e5918247 | bellard | |
672 | e5918247 | bellard | TEST_XCHG(xaddl, "", "=q"); |
673 | e5918247 | bellard | TEST_XCHG(xaddw, "w", "=q"); |
674 | e5918247 | bellard | TEST_XCHG(xaddb, "b", "=q"); |
675 | e5918247 | bellard | |
676 | e5918247 | bellard | TEST_XCHG(xaddl, "", "=m"); |
677 | e5918247 | bellard | TEST_XCHG(xaddw, "w", "=m"); |
678 | e5918247 | bellard | TEST_XCHG(xaddb, "b", "=m"); |
679 | e5918247 | bellard | |
680 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgl, "", "=q", 0xfbca7654); |
681 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgw, "w", "=q", 0xfbca7654); |
682 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgb, "b", "=q", 0xfbca7654); |
683 | e5918247 | bellard | |
684 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgl, "", "=q", 0xfffefdfc); |
685 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgw, "w", "=q", 0xfffefdfc); |
686 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgb, "b", "=q", 0xfffefdfc); |
687 | e5918247 | bellard | |
688 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgl, "", "=m", 0xfbca7654); |
689 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgw, "w", "=m", 0xfbca7654); |
690 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgb, "b", "=m", 0xfbca7654); |
691 | e5918247 | bellard | |
692 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgl, "", "=m", 0xfffefdfc); |
693 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgw, "w", "=m", 0xfffefdfc); |
694 | e5918247 | bellard | TEST_CMPXCHG(cmpxchgb, "b", "=m", 0xfffefdfc); |
695 | e5918247 | bellard | } |
696 | e5918247 | bellard | |
697 | 6dbad63e | bellard | /**********************************************/
|
698 | 6dbad63e | bellard | /* segmentation tests */
|
699 | 6dbad63e | bellard | |
700 | 6dbad63e | bellard | #include <asm/ldt.h> |
701 | 6dbad63e | bellard | #include <linux/unistd.h> |
702 | 6dbad63e | bellard | |
703 | 6dbad63e | bellard | _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount) |
704 | 6dbad63e | bellard | |
705 | 6dbad63e | bellard | uint8_t seg_data1[4096];
|
706 | 6dbad63e | bellard | uint8_t seg_data2[4096];
|
707 | 6dbad63e | bellard | |
708 | e5918247 | bellard | #define MK_SEL(n) (((n) << 3) | 7) |
709 | 6dbad63e | bellard | |
710 | 6dbad63e | bellard | /* NOTE: we use Linux modify_ldt syscall */
|
711 | 6dbad63e | bellard | void test_segs(void) |
712 | 6dbad63e | bellard | { |
713 | 6dbad63e | bellard | struct modify_ldt_ldt_s ldt;
|
714 | 6dbad63e | bellard | long long ldt_table[3]; |
715 | 04369ff2 | bellard | int res, res2;
|
716 | 6dbad63e | bellard | char tmp;
|
717 | e1d4294a | bellard | struct {
|
718 | e1d4294a | bellard | uint32_t offset; |
719 | e1d4294a | bellard | uint16_t seg; |
720 | e1d4294a | bellard | } __attribute__((packed)) segoff; |
721 | 6dbad63e | bellard | |
722 | 6dbad63e | bellard | ldt.entry_number = 1;
|
723 | 6dbad63e | bellard | ldt.base_addr = (unsigned long)&seg_data1; |
724 | 6dbad63e | bellard | ldt.limit = (sizeof(seg_data1) + 0xfff) >> 12; |
725 | 6dbad63e | bellard | ldt.seg_32bit = 1;
|
726 | 6dbad63e | bellard | ldt.contents = MODIFY_LDT_CONTENTS_DATA; |
727 | 6dbad63e | bellard | ldt.read_exec_only = 0;
|
728 | 6dbad63e | bellard | ldt.limit_in_pages = 1;
|
729 | 6dbad63e | bellard | ldt.seg_not_present = 0;
|
730 | 6dbad63e | bellard | ldt.useable = 1;
|
731 | 6dbad63e | bellard | modify_ldt(1, &ldt, sizeof(ldt)); /* write ldt entry */ |
732 | 6dbad63e | bellard | |
733 | 6dbad63e | bellard | ldt.entry_number = 2;
|
734 | 6dbad63e | bellard | ldt.base_addr = (unsigned long)&seg_data2; |
735 | 6dbad63e | bellard | ldt.limit = (sizeof(seg_data2) + 0xfff) >> 12; |
736 | 6dbad63e | bellard | ldt.seg_32bit = 1;
|
737 | 6dbad63e | bellard | ldt.contents = MODIFY_LDT_CONTENTS_DATA; |
738 | 6dbad63e | bellard | ldt.read_exec_only = 0;
|
739 | 6dbad63e | bellard | ldt.limit_in_pages = 1;
|
740 | 6dbad63e | bellard | ldt.seg_not_present = 0;
|
741 | 6dbad63e | bellard | ldt.useable = 1;
|
742 | 6dbad63e | bellard | modify_ldt(1, &ldt, sizeof(ldt)); /* write ldt entry */ |
743 | 6dbad63e | bellard | |
744 | 6dbad63e | bellard | modify_ldt(0, &ldt_table, sizeof(ldt_table)); /* read ldt entries */ |
745 | 04369ff2 | bellard | #if 0
|
746 | 04369ff2 | bellard | {
|
747 | 04369ff2 | bellard | int i;
|
748 | 04369ff2 | bellard | for(i=0;i<3;i++)
|
749 | 04369ff2 | bellard | printf("%d: %016Lx\n", i, ldt_table[i]);
|
750 | 04369ff2 | bellard | }
|
751 | 04369ff2 | bellard | #endif
|
752 | 6dbad63e | bellard | /* do some tests with fs or gs */
|
753 | 6dbad63e | bellard | asm volatile ("movl %0, %%fs" : : "r" (MK_SEL(1))); |
754 | 6dbad63e | bellard | asm volatile ("movl %0, %%gs" : : "r" (MK_SEL(2))); |
755 | 6dbad63e | bellard | |
756 | 6dbad63e | bellard | seg_data1[1] = 0xaa; |
757 | 6dbad63e | bellard | seg_data2[1] = 0x55; |
758 | 6dbad63e | bellard | |
759 | 6dbad63e | bellard | asm volatile ("fs movzbl 0x1, %0" : "=r" (res)); |
760 | 6dbad63e | bellard | printf("FS[1] = %02x\n", res);
|
761 | 6dbad63e | bellard | |
762 | 6dbad63e | bellard | asm volatile ("gs movzbl 0x1, %0" : "=r" (res)); |
763 | 6dbad63e | bellard | printf("GS[1] = %02x\n", res);
|
764 | 6dbad63e | bellard | |
765 | 6dbad63e | bellard | /* tests with ds/ss (implicit segment case) */
|
766 | 6dbad63e | bellard | tmp = 0xa5;
|
767 | 6dbad63e | bellard | asm volatile ("pushl %%ebp\n\t" |
768 | 6dbad63e | bellard | "pushl %%ds\n\t"
|
769 | 6dbad63e | bellard | "movl %2, %%ds\n\t"
|
770 | 6dbad63e | bellard | "movl %3, %%ebp\n\t"
|
771 | 6dbad63e | bellard | "movzbl 0x1, %0\n\t"
|
772 | 6dbad63e | bellard | "movzbl (%%ebp), %1\n\t"
|
773 | 6dbad63e | bellard | "popl %%ds\n\t"
|
774 | 6dbad63e | bellard | "popl %%ebp\n\t"
|
775 | 6dbad63e | bellard | : "=r" (res), "=r" (res2) |
776 | 6dbad63e | bellard | : "r" (MK_SEL(1)), "r" (&tmp)); |
777 | 6dbad63e | bellard | printf("DS[1] = %02x\n", res);
|
778 | 6dbad63e | bellard | printf("SS[tmp] = %02x\n", res2);
|
779 | e1d4294a | bellard | |
780 | e1d4294a | bellard | segoff.seg = MK_SEL(2);
|
781 | e1d4294a | bellard | segoff.offset = 0xabcdef12;
|
782 | e1d4294a | bellard | asm volatile("lfs %2, %0\n\t" |
783 | e1d4294a | bellard | "movl %%fs, %1\n\t"
|
784 | e1d4294a | bellard | : "=r" (res), "=g" (res2) |
785 | e1d4294a | bellard | : "m" (segoff));
|
786 | e1d4294a | bellard | printf("FS:reg = %04x:%08x\n", res2, res);
|
787 | 6dbad63e | bellard | } |
788 | 55480af8 | bellard | |
789 | e5918247 | bellard | /* 16 bit code test */
|
790 | e5918247 | bellard | extern char code16_start, code16_end; |
791 | e5918247 | bellard | extern char code16_func1; |
792 | e5918247 | bellard | extern char code16_func2; |
793 | e5918247 | bellard | extern char code16_func3; |
794 | a300e691 | bellard | |
795 | e5918247 | bellard | void test_code16(void) |
796 | 1a9353d2 | bellard | { |
797 | e5918247 | bellard | struct modify_ldt_ldt_s ldt;
|
798 | e5918247 | bellard | int res, res2;
|
799 | a300e691 | bellard | |
800 | e5918247 | bellard | /* build a code segment */
|
801 | e5918247 | bellard | ldt.entry_number = 1;
|
802 | e5918247 | bellard | ldt.base_addr = (unsigned long)&code16_start; |
803 | e5918247 | bellard | ldt.limit = &code16_end - &code16_start; |
804 | e5918247 | bellard | ldt.seg_32bit = 0;
|
805 | e5918247 | bellard | ldt.contents = MODIFY_LDT_CONTENTS_CODE; |
806 | e5918247 | bellard | ldt.read_exec_only = 0;
|
807 | e5918247 | bellard | ldt.limit_in_pages = 0;
|
808 | e5918247 | bellard | ldt.seg_not_present = 0;
|
809 | e5918247 | bellard | ldt.useable = 1;
|
810 | e5918247 | bellard | modify_ldt(1, &ldt, sizeof(ldt)); /* write ldt entry */ |
811 | a300e691 | bellard | |
812 | e5918247 | bellard | /* call the first function */
|
813 | e5918247 | bellard | asm volatile ("lcall %1, %2" |
814 | e5918247 | bellard | : "=a" (res)
|
815 | e5918247 | bellard | : "i" (MK_SEL(1)), "i" (&code16_func1): "memory", "cc"); |
816 | e5918247 | bellard | printf("func1() = 0x%08x\n", res);
|
817 | e5918247 | bellard | asm volatile ("lcall %2, %3" |
818 | e5918247 | bellard | : "=a" (res), "=c" (res2) |
819 | e5918247 | bellard | : "i" (MK_SEL(1)), "i" (&code16_func2): "memory", "cc"); |
820 | e5918247 | bellard | printf("func2() = 0x%08x spdec=%d\n", res, res2);
|
821 | e5918247 | bellard | asm volatile ("lcall %1, %2" |
822 | e5918247 | bellard | : "=a" (res)
|
823 | e5918247 | bellard | : "i" (MK_SEL(1)), "i" (&code16_func3): "memory", "cc"); |
824 | e5918247 | bellard | printf("func3() = 0x%08x\n", res);
|
825 | 1a9353d2 | bellard | } |
826 | 1a9353d2 | bellard | |
827 | e1d4294a | bellard | void test_misc(void) |
828 | e1d4294a | bellard | { |
829 | e1d4294a | bellard | char table[256]; |
830 | e1d4294a | bellard | int res, i;
|
831 | e1d4294a | bellard | |
832 | e1d4294a | bellard | for(i=0;i<256;i++) table[i] = 256 - i; |
833 | e1d4294a | bellard | res = 0x12345678;
|
834 | e1d4294a | bellard | asm ("xlat" : "=a" (res) : "b" (table), "0" (res)); |
835 | e1d4294a | bellard | printf("xlat: EAX=%08x\n", res);
|
836 | e1d4294a | bellard | } |
837 | e1d4294a | bellard | |
838 | e1d4294a | bellard | uint8_t str_buffer[4096];
|
839 | e1d4294a | bellard | |
840 | e1d4294a | bellard | #define TEST_STRING1(OP, size, DF, REP)\
|
841 | e1d4294a | bellard | {\ |
842 | e1d4294a | bellard | int esi, edi, eax, ecx, eflags;\
|
843 | e1d4294a | bellard | \ |
844 | e1d4294a | bellard | esi = (long)(str_buffer + sizeof(str_buffer) / 2);\ |
845 | e1d4294a | bellard | edi = (long)(str_buffer + sizeof(str_buffer) / 2) + 16;\ |
846 | e1d4294a | bellard | eax = 0x12345678;\
|
847 | e1d4294a | bellard | ecx = 17;\
|
848 | e1d4294a | bellard | \ |
849 | e1d4294a | bellard | asm volatile ("pushl $0\n\t"\ |
850 | e1d4294a | bellard | "popf\n\t"\
|
851 | e1d4294a | bellard | DF "\n\t"\
|
852 | e1d4294a | bellard | REP #OP size "\n\t"\ |
853 | e1d4294a | bellard | "cld\n\t"\
|
854 | e1d4294a | bellard | "pushf\n\t"\
|
855 | e1d4294a | bellard | "popl %4\n\t"\
|
856 | e1d4294a | bellard | : "=S" (esi), "=D" (edi), "=a" (eax), "=c" (ecx), "=g" (eflags)\ |
857 | e1d4294a | bellard | : "0" (esi), "1" (edi), "2" (eax), "3" (ecx));\ |
858 | e1d4294a | bellard | printf("%-10s ESI=%08x EDI=%08x EAX=%08x ECX=%08x EFL=%04x\n",\
|
859 | e1d4294a | bellard | REP #OP size, esi, edi, eax, ecx,\
|
860 | e1d4294a | bellard | eflags & (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A));\ |
861 | e1d4294a | bellard | } |
862 | e1d4294a | bellard | |
863 | e1d4294a | bellard | #define TEST_STRING(OP, REP)\
|
864 | e1d4294a | bellard | TEST_STRING1(OP, "b", "", REP);\ |
865 | e1d4294a | bellard | TEST_STRING1(OP, "w", "", REP);\ |
866 | e1d4294a | bellard | TEST_STRING1(OP, "l", "", REP);\ |
867 | e1d4294a | bellard | TEST_STRING1(OP, "b", "std", REP);\ |
868 | e1d4294a | bellard | TEST_STRING1(OP, "w", "std", REP);\ |
869 | e1d4294a | bellard | TEST_STRING1(OP, "l", "std", REP) |
870 | e1d4294a | bellard | |
871 | e1d4294a | bellard | void test_string(void) |
872 | e1d4294a | bellard | { |
873 | e1d4294a | bellard | int i;
|
874 | e1d4294a | bellard | for(i = 0;i < sizeof(str_buffer); i++) |
875 | e1d4294a | bellard | str_buffer[i] = i + 0x56;
|
876 | e1d4294a | bellard | TEST_STRING(stos, "");
|
877 | e1d4294a | bellard | TEST_STRING(stos, "rep ");
|
878 | e1d4294a | bellard | TEST_STRING(lods, ""); /* to verify stos */ |
879 | e1d4294a | bellard | TEST_STRING(lods, "rep ");
|
880 | e1d4294a | bellard | TEST_STRING(movs, "");
|
881 | e1d4294a | bellard | TEST_STRING(movs, "rep ");
|
882 | e1d4294a | bellard | TEST_STRING(lods, ""); /* to verify stos */ |
883 | e1d4294a | bellard | |
884 | e1d4294a | bellard | /* XXX: better tests */
|
885 | e1d4294a | bellard | TEST_STRING(scas, "");
|
886 | e1d4294a | bellard | TEST_STRING(scas, "repz ");
|
887 | e1d4294a | bellard | TEST_STRING(scas, "repnz ");
|
888 | e1d4294a | bellard | TEST_STRING(cmps, "");
|
889 | e1d4294a | bellard | TEST_STRING(cmps, "repz ");
|
890 | e1d4294a | bellard | TEST_STRING(cmps, "repnz ");
|
891 | e1d4294a | bellard | } |
892 | e5918247 | bellard | |
893 | 4d1135e4 | bellard | static void *call_end __init_call = NULL; |
894 | 4d1135e4 | bellard | |
895 | 4d1135e4 | bellard | int main(int argc, char **argv) |
896 | 4d1135e4 | bellard | { |
897 | 4d1135e4 | bellard | void **ptr;
|
898 | 4d1135e4 | bellard | void (*func)(void); |
899 | 4b74fe1f | bellard | |
900 | 4d1135e4 | bellard | ptr = &call_start + 1;
|
901 | 4d1135e4 | bellard | while (*ptr != NULL) { |
902 | 4d1135e4 | bellard | func = *ptr++; |
903 | 4d1135e4 | bellard | func(); |
904 | 4d1135e4 | bellard | } |
905 | 9d8e9c09 | bellard | test_bsx(); |
906 | d57c4e01 | bellard | test_mul(); |
907 | 4d1135e4 | bellard | test_jcc(); |
908 | 9d8e9c09 | bellard | test_floats(); |
909 | 55480af8 | bellard | test_bcd(); |
910 | 1a9353d2 | bellard | test_xchg(); |
911 | e1d4294a | bellard | test_string(); |
912 | e1d4294a | bellard | test_misc(); |
913 | 6dbad63e | bellard | test_lea(); |
914 | 6dbad63e | bellard | test_segs(); |
915 | e5918247 | bellard | test_code16(); |
916 | 4d1135e4 | bellard | return 0; |
917 | 4d1135e4 | bellard | } |