4 * Copyright (c) 2003 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #include <sys/ucontext.h>
32 /* Setting this to 1 creates a very comprehensive test of
33 integer condition codes. */
34 #define TEST_INTEGER_VERBOSE 1
37 //#define LINUX_VM86_IOPL_FIX
38 //#define TEST_P4_FLAGS
40 #define xglue(x, y) x ## y
41 #define glue(x, y) xglue(x, y)
42 #define stringify(s) tostring(s)
43 #define tostring(s) #s
52 #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
54 static void *call_start __init_call
= NULL
;
56 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
59 #include "test-i386.h"
62 #include "test-i386.h"
65 #include "test-i386.h"
68 #include "test-i386.h"
71 #include "test-i386.h"
74 #include "test-i386.h"
78 #include "test-i386.h"
82 #include "test-i386.h"
87 #include "test-i386.h"
92 #include "test-i386.h"
97 #include "test-i386.h"
102 #include "test-i386.h"
105 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
108 #include "test-i386-shift.h"
111 #include "test-i386-shift.h"
114 #include "test-i386-shift.h"
117 #include "test-i386-shift.h"
120 #include "test-i386-shift.h"
124 #include "test-i386-shift.h"
128 #include "test-i386-shift.h"
133 #include "test-i386-shift.h"
138 #include "test-i386-shift.h"
141 /* XXX: should be more precise ? */
143 #define CC_MASK (CC_C)
147 #include "test-i386-shift.h"
151 #include "test-i386-shift.h"
155 #include "test-i386-shift.h"
159 #include "test-i386-shift.h"
162 /* lea test (modrm support) */
163 #define TEST_LEA(STR)\
165 asm("leal " STR ", %0"\
167 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
168 printf("lea %s = %08x\n", STR, res);\
171 #define TEST_LEA16(STR)\
173 asm(".code16 ; .byte 0x67 ; leal " STR ", %0 ; .code32"\
175 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
176 printf("lea %s = %08x\n", STR, res);\
182 int eax
, ebx
, ecx
, edx
, esi
, edi
, res
;
199 TEST_LEA("0x40(%%eax)");
200 TEST_LEA("0x40(%%ebx)");
201 TEST_LEA("0x40(%%ecx)");
202 TEST_LEA("0x40(%%edx)");
203 TEST_LEA("0x40(%%esi)");
204 TEST_LEA("0x40(%%edi)");
206 TEST_LEA("0x4000(%%eax)");
207 TEST_LEA("0x4000(%%ebx)");
208 TEST_LEA("0x4000(%%ecx)");
209 TEST_LEA("0x4000(%%edx)");
210 TEST_LEA("0x4000(%%esi)");
211 TEST_LEA("0x4000(%%edi)");
213 TEST_LEA("(%%eax, %%ecx)");
214 TEST_LEA("(%%ebx, %%edx)");
215 TEST_LEA("(%%ecx, %%ecx)");
216 TEST_LEA("(%%edx, %%ecx)");
217 TEST_LEA("(%%esi, %%ecx)");
218 TEST_LEA("(%%edi, %%ecx)");
220 TEST_LEA("0x40(%%eax, %%ecx)");
221 TEST_LEA("0x4000(%%ebx, %%edx)");
223 TEST_LEA("(%%ecx, %%ecx, 2)");
224 TEST_LEA("(%%edx, %%ecx, 4)");
225 TEST_LEA("(%%esi, %%ecx, 8)");
227 TEST_LEA("(,%%eax, 2)");
228 TEST_LEA("(,%%ebx, 4)");
229 TEST_LEA("(,%%ecx, 8)");
231 TEST_LEA("0x40(,%%eax, 2)");
232 TEST_LEA("0x40(,%%ebx, 4)");
233 TEST_LEA("0x40(,%%ecx, 8)");
236 TEST_LEA("-10(%%ecx, %%ecx, 2)");
237 TEST_LEA("-10(%%edx, %%ecx, 4)");
238 TEST_LEA("-10(%%esi, %%ecx, 8)");
240 TEST_LEA("0x4000(%%ecx, %%ecx, 2)");
241 TEST_LEA("0x4000(%%edx, %%ecx, 4)");
242 TEST_LEA("0x4000(%%esi, %%ecx, 8)");
245 #define TEST_JCC(JCC, v1, v2)\
248 asm("movl $1, %0\n\t"\
254 : "r" (v1), "r" (v2));\
255 printf("%-10s %d\n", "j" JCC, res);\
257 asm("movl $0, %0\n\t"\
259 "set" JCC " %b0\n\t"\
261 : "r" (v1), "r" (v2));\
262 printf("%-10s %d\n", "set" JCC, res);\
264 asm("movl $0x12345678, %0\n\t"\
266 "cmov" JCC "l %3, %0\n\t"\
268 : "r" (v1), "r" (v2), "m" (one));\
269 printf("%-10s R=0x%08x\n", "cmov" JCC "l", res);\
270 asm("movl $0x12345678, %0\n\t"\
272 "cmov" JCC "w %w3, %w0\n\t"\
274 : "r" (v1), "r" (v2), "r" (1));\
275 printf("%-10s R=0x%08x\n", "cmov" JCC "w", res);\
279 /* various jump tests */
282 TEST_JCC("ne", 1, 1);
283 TEST_JCC("ne", 1, 0);
290 TEST_JCC("l", 1, -1);
292 TEST_JCC("le", 1, 1);
293 TEST_JCC("le", 1, 0);
294 TEST_JCC("le", 1, -1);
296 TEST_JCC("ge", 1, 1);
297 TEST_JCC("ge", 1, 0);
298 TEST_JCC("ge", -1, 1);
302 TEST_JCC("g", 1, -1);
306 TEST_JCC("b", 1, -1);
308 TEST_JCC("be", 1, 1);
309 TEST_JCC("be", 1, 0);
310 TEST_JCC("be", 1, -1);
312 TEST_JCC("ae", 1, 1);
313 TEST_JCC("ae", 1, 0);
314 TEST_JCC("ae", 1, -1);
318 TEST_JCC("a", 1, -1);
324 TEST_JCC("np", 1, 1);
325 TEST_JCC("np", 1, 0);
327 TEST_JCC("o", 0x7fffffff, 0);
328 TEST_JCC("o", 0x7fffffff, -1);
330 TEST_JCC("no", 0x7fffffff, 0);
331 TEST_JCC("no", 0x7fffffff, -1);
334 TEST_JCC("s", 0, -1);
337 TEST_JCC("ns", 0, 1);
338 TEST_JCC("ns", 0, -1);
339 TEST_JCC("ns", 0, 0);
344 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
346 #define CC_MASK (CC_O | CC_C)
350 #include "test-i386-muldiv.h"
353 #include "test-i386-muldiv.h"
355 void test_imulw2(int op0
, int op1
)
357 int res
, s1
, s0
, flags
;
367 : "=q" (res
), "=g" (flags
)
368 : "q" (s1
), "0" (res
), "1" (flags
));
369 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
370 "imulw", s0
, s1
, res
, flags
& CC_MASK
);
373 void test_imull2(int op0
, int op1
)
375 int res
, s1
, s0
, flags
;
385 : "=q" (res
), "=g" (flags
)
386 : "q" (s1
), "0" (res
), "1" (flags
));
387 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
388 "imull", s0
, s1
, res
, flags
& CC_MASK
);
391 #define TEST_IMUL_IM(size, size1, op0, op1)\
398 "imul" size " $" #op0 ", %" size1 "2, %" size1 "0\n\t" \
401 : "=r" (res), "=g" (flags)\
402 : "r" (op1), "1" (flags), "0" (res));\
403 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",\
404 "imul" size, op0, op1, res, flags & CC_MASK);\
412 #include "test-i386-muldiv.h"
415 #include "test-i386-muldiv.h"
419 test_imulb(0x1234561d, 4);
421 test_imulb(0x80, 0x80);
422 test_imulb(0x10, 0x10);
425 test_imulw(0, 0xFF, 0xFF);
426 test_imulw(0, 0xFF, 0x100);
427 test_imulw(0, 0x1234001d, 45);
428 test_imulw(0, 23, -45);
429 test_imulw(0, 0x8000, 0x8000);
430 test_imulw(0, 0x100, 0x100);
433 test_imull(0, 0xFFFF, 0xFFFF);
434 test_imull(0, 0xFFFF, 0x10000);
435 test_imull(0, 0x1234001d, 45);
436 test_imull(0, 23, -45);
437 test_imull(0, 0x80000000, 0x80000000);
438 test_imull(0, 0x10000, 0x10000);
440 test_mulb(0x1234561d, 4);
442 test_mulb(0x80, 0x80);
443 test_mulb(0x10, 0x10);
445 test_mulw(0, 0x1234001d, 45);
446 test_mulw(0, 23, -45);
447 test_mulw(0, 0x8000, 0x8000);
448 test_mulw(0, 0x100, 0x100);
450 test_mull(0, 0x1234001d, 45);
451 test_mull(0, 23, -45);
452 test_mull(0, 0x80000000, 0x80000000);
453 test_mull(0, 0x10000, 0x10000);
455 test_imulw2(0x1234001d, 45);
456 test_imulw2(23, -45);
457 test_imulw2(0x8000, 0x8000);
458 test_imulw2(0x100, 0x100);
460 test_imull2(0x1234001d, 45);
461 test_imull2(23, -45);
462 test_imull2(0x80000000, 0x80000000);
463 test_imull2(0x10000, 0x10000);
465 TEST_IMUL_IM("w", "w", 45, 0x1234);
466 TEST_IMUL_IM("w", "w", -45, 23);
467 TEST_IMUL_IM("w", "w", 0x8000, 0x80000000);
468 TEST_IMUL_IM("w", "w", 0x7fff, 0x1000);
470 TEST_IMUL_IM("l", "", 45, 0x1234);
471 TEST_IMUL_IM("l", "", -45, 23);
472 TEST_IMUL_IM("l", "", 0x8000, 0x80000000);
473 TEST_IMUL_IM("l", "", 0x7fff, 0x1000);
475 test_idivb(0x12341678, 0x127e);
476 test_idivb(0x43210123, -5);
477 test_idivb(0x12340004, -1);
479 test_idivw(0, 0x12345678, 12347);
480 test_idivw(0, -23223, -45);
481 test_idivw(0, 0x12348000, -1);
482 test_idivw(0x12343, 0x12345678, 0x81238567);
484 test_idivl(0, 0x12345678, 12347);
485 test_idivl(0, -233223, -45);
486 test_idivl(0, 0x80000000, -1);
487 test_idivl(0x12343, 0x12345678, 0x81234567);
489 test_divb(0x12341678, 0x127e);
490 test_divb(0x43210123, -5);
491 test_divb(0x12340004, -1);
493 test_divw(0, 0x12345678, 12347);
494 test_divw(0, -23223, -45);
495 test_divw(0, 0x12348000, -1);
496 test_divw(0x12343, 0x12345678, 0x81238567);
498 test_divl(0, 0x12345678, 12347);
499 test_divl(0, -233223, -45);
500 test_divl(0, 0x80000000, -1);
501 test_divl(0x12343, 0x12345678, 0x81234567);
504 #define TEST_BSX(op, size, op0)\
508 asm("xorl %1, %1\n\t"\
509 "movl $0x12345678, %0\n\t"\
510 #op " %" size "2, %" size "0\n\t" \
512 : "=r" (res), "=q" (resz)\
514 printf("%-10s A=%08x R=%08x %d\n", #op, val, res, resz);\
519 TEST_BSX(bsrw
, "w", 0);
520 TEST_BSX(bsrw
, "w", 0x12340128);
521 TEST_BSX(bsrl
, "", 0);
522 TEST_BSX(bsrl
, "", 0x00340128);
523 TEST_BSX(bsfw
, "w", 0);
524 TEST_BSX(bsfw
, "w", 0x12340128);
525 TEST_BSX(bsfl
, "", 0);
526 TEST_BSX(bsfl
, "", 0x00340128);
529 /**********************************************/
531 void test_fops(double a
, double b
)
533 printf("a=%f b=%f a+b=%f\n", a
, b
, a
+ b
);
534 printf("a=%f b=%f a-b=%f\n", a
, b
, a
- b
);
535 printf("a=%f b=%f a*b=%f\n", a
, b
, a
* b
);
536 printf("a=%f b=%f a/b=%f\n", a
, b
, a
/ b
);
537 printf("a=%f b=%f fmod(a, b)=%f\n", a
, b
, fmod(a
, b
));
538 printf("a=%f sqrt(a)=%f\n", a
, sqrt(a
));
539 printf("a=%f sin(a)=%f\n", a
, sin(a
));
540 printf("a=%f cos(a)=%f\n", a
, cos(a
));
541 printf("a=%f tan(a)=%f\n", a
, tan(a
));
542 printf("a=%f log(a)=%f\n", a
, log(a
));
543 printf("a=%f exp(a)=%f\n", a
, exp(a
));
544 printf("a=%f b=%f atan2(a, b)=%f\n", a
, b
, atan2(a
, b
));
545 /* just to test some op combining */
546 printf("a=%f asin(sin(a))=%f\n", a
, asin(sin(a
)));
547 printf("a=%f acos(cos(a))=%f\n", a
, acos(cos(a
)));
548 printf("a=%f atan(tan(a))=%f\n", a
, atan(tan(a
)));
551 void test_fcmp(double a
, double b
)
553 printf("(%f<%f)=%d\n",
555 printf("(%f<=%f)=%d\n",
557 printf("(%f==%f)=%d\n",
559 printf("(%f>%f)=%d\n",
561 printf("(%f<=%f)=%d\n",
565 /* test f(u)comi instruction */
571 printf("fcomi(%f %f)=%08x\n", a
, b
, eflags
& (CC_Z
| CC_P
| CC_C
));
575 void test_fcvt(double a
)
588 printf("(float)%f = %f\n", a
, fa
);
589 printf("(long double)%f = %Lf\n", a
, la
);
590 printf("a=%016Lx\n", *(long long *)&a
);
591 printf("la=%016Lx %04x\n", *(long long *)&la
,
592 *(unsigned short *)((char *)(&la
) + 8));
594 /* test all roundings */
595 asm volatile ("fstcw %0" : "=m" (fpuc
));
597 int16_t tmp
= (fpuc
& ~0x0c00) | (i
<< 10);
598 asm volatile ("fldcw %0" : : "m" (tmp
));
599 asm volatile ("fist %0" : "=m" (wa
) : "t" (a
));
600 asm volatile ("fistl %0" : "=m" (ia
) : "t" (a
));
601 asm volatile ("fistpll %0" : "=m" (lla
) : "t" (a
) : "st");
602 asm volatile ("frndint ; fstl %0" : "=m" (ra
) : "t" (a
));
603 asm volatile ("fldcw %0" : : "m" (fpuc
));
604 printf("(short)a = %d\n", wa
);
605 printf("(int)a = %d\n", ia
);
606 printf("(int64_t)a = %Ld\n", lla
);
607 printf("rint(a) = %f\n", ra
);
612 asm("fld" #N : "=t" (a)); \
613 printf("fld" #N "= %f\n", a);
615 void test_fconst(void)
627 void test_fbcd(double a
)
629 unsigned short bcd
[5];
632 asm("fbstp %0" : "=m" (bcd
[0]) : "t" (a
) : "st");
633 asm("fbld %1" : "=t" (b
) : "m" (bcd
[0]));
634 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n",
635 a
, bcd
[4], bcd
[3], bcd
[2], bcd
[1], bcd
[0], b
);
638 #define TEST_ENV(env, save, restore)\
640 memset((env), 0xaa, sizeof(*(env)));\
642 asm volatile ("fldl %0" : : "m" (dtab[i]));\
643 asm(save " %0\n" : : "m" (*(env)));\
644 asm(restore " %0\n": : "m" (*(env)));\
646 asm volatile ("fstpl %0" : "=m" (rtab[i]));\
648 printf("res[%d]=%f\n", i, rtab[i]);\
649 printf("fpuc=%04x fpus=%04x fptag=%04x\n",\
651 (env)->fpus & 0xff00,\
657 struct __attribute__((packed
)) {
665 long double fpregs
[8];
667 struct __attribute__((packed
)) {
672 long double fpregs
[8];
681 TEST_ENV(&float_env16
, "data16 fnstenv", "data16 fldenv");
682 TEST_ENV(&float_env16
, "data16 fnsave", "data16 frstor");
683 TEST_ENV(&float_env32
, "fnstenv", "fldenv");
684 TEST_ENV(&float_env32
, "fnsave", "frstor");
688 asm volatile ("fldl %0" : : "m" (dtab
[i
]));
689 asm volatile("ffree %st(2)");
690 asm volatile ("fnstenv %0\n" : : "m" (float_env32
));
691 asm volatile ("fninit");
692 printf("fptag=%04x\n", float_env32
.fptag
);
696 #define TEST_FCMOV(a, b, eflags, CC)\
701 "fcmov" CC " %2, %0\n"\
703 : "0" (a), "u" (b), "g" (eflags));\
704 printf("fcmov%s eflags=0x%04x-> %f\n", \
708 void test_fcmov(void)
715 for(i
= 0; i
< 4; i
++) {
721 TEST_FCMOV(a
, b
, eflags
, "b");
722 TEST_FCMOV(a
, b
, eflags
, "e");
723 TEST_FCMOV(a
, b
, eflags
, "be");
724 TEST_FCMOV(a
, b
, eflags
, "nb");
725 TEST_FCMOV(a
, b
, eflags
, "ne");
726 TEST_FCMOV(a
, b
, eflags
, "nbe");
728 TEST_FCMOV(a
, b
, 0, "u");
729 TEST_FCMOV(a
, b
, CC_P
, "u");
730 TEST_FCMOV(a
, b
, 0, "nu");
731 TEST_FCMOV(a
, b
, CC_P
, "nu");
734 void test_floats(void)
748 // REINSTATE (maybe): test_fbcd(1234567890123456);
749 // REINSTATE (maybe): test_fbcd(-123451234567890);
750 // REINSTATE: test_fenv();
751 // REINSTATE: test_fcmov();
754 /**********************************************/
757 #define TEST_BCD(op, op0, cc_in, cc_mask)\
767 : "=a" (res), "=g" (flags)\
768 : "0" (res), "1" (flags));\
769 printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",\
770 #op, op0, res, cc_in, flags & cc_mask);\
775 TEST_BCD(daa
, 0x12340503, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
776 TEST_BCD(daa
, 0x12340506, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
777 TEST_BCD(daa
, 0x12340507, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
778 TEST_BCD(daa
, 0x12340559, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
779 TEST_BCD(daa
, 0x12340560, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
780 TEST_BCD(daa
, 0x1234059f, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
781 TEST_BCD(daa
, 0x123405a0, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
782 TEST_BCD(daa
, 0x12340503, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
783 TEST_BCD(daa
, 0x12340506, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
784 TEST_BCD(daa
, 0x12340503, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
785 TEST_BCD(daa
, 0x12340506, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
786 TEST_BCD(daa
, 0x12340503, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
787 TEST_BCD(daa
, 0x12340506, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
789 TEST_BCD(das
, 0x12340503, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
790 TEST_BCD(das
, 0x12340506, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
791 TEST_BCD(das
, 0x12340507, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
792 TEST_BCD(das
, 0x12340559, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
793 TEST_BCD(das
, 0x12340560, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
794 TEST_BCD(das
, 0x1234059f, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
795 TEST_BCD(das
, 0x123405a0, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
796 TEST_BCD(das
, 0x12340503, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
797 TEST_BCD(das
, 0x12340506, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
798 TEST_BCD(das
, 0x12340503, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
799 TEST_BCD(das
, 0x12340506, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
800 TEST_BCD(das
, 0x12340503, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
801 TEST_BCD(das
, 0x12340506, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
803 TEST_BCD(aaa
, 0x12340205, CC_A
, (CC_C
| CC_A
));
804 TEST_BCD(aaa
, 0x12340306, CC_A
, (CC_C
| CC_A
));
805 TEST_BCD(aaa
, 0x1234040a, CC_A
, (CC_C
| CC_A
));
806 TEST_BCD(aaa
, 0x123405fa, CC_A
, (CC_C
| CC_A
));
807 TEST_BCD(aaa
, 0x12340205, 0, (CC_C
| CC_A
));
808 TEST_BCD(aaa
, 0x12340306, 0, (CC_C
| CC_A
));
809 TEST_BCD(aaa
, 0x1234040a, 0, (CC_C
| CC_A
));
810 TEST_BCD(aaa
, 0x123405fa, 0, (CC_C
| CC_A
));
812 TEST_BCD(aas
, 0x12340205, CC_A
, (CC_C
| CC_A
));
813 TEST_BCD(aas
, 0x12340306, CC_A
, (CC_C
| CC_A
));
814 TEST_BCD(aas
, 0x1234040a, CC_A
, (CC_C
| CC_A
));
815 TEST_BCD(aas
, 0x123405fa, CC_A
, (CC_C
| CC_A
));
816 TEST_BCD(aas
, 0x12340205, 0, (CC_C
| CC_A
));
817 TEST_BCD(aas
, 0x12340306, 0, (CC_C
| CC_A
));
818 TEST_BCD(aas
, 0x1234040a, 0, (CC_C
| CC_A
));
819 TEST_BCD(aas
, 0x123405fa, 0, (CC_C
| CC_A
));
821 TEST_BCD(aam
, 0x12340547, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_O
| CC_A
));
822 TEST_BCD(aad
, 0x12340407, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_O
| CC_A
));
826 #define TEST_XCHG(op, size, opconst)\
831 asm(#op " %" size "0, %" size "1" \
832 : "=q" (op0), opconst (op1) \
833 : "0" (op0), "1" (op1));\
834 printf("%-10s A=%08x B=%08x\n",\
838 #define TEST_CMPXCHG(op, size, opconst, eax)\
843 asm(#op " %" size "0, %" size "1" \
844 : "=q" (op0), opconst (op1) \
845 : "0" (op0), "1" (op1), "a" (eax));\
846 printf("%-10s EAX=%08x A=%08x C=%08x\n",\
847 #op, eax, op0, op1);\
852 TEST_XCHG(xchgl
, "", "=q");
853 TEST_XCHG(xchgw
, "w", "=q");
854 TEST_XCHG(xchgb
, "b", "=q");
856 TEST_XCHG(xchgl
, "", "=m");
857 TEST_XCHG(xchgw
, "w", "=m");
858 TEST_XCHG(xchgb
, "b", "=m");
861 TEST_XCHG(xaddl
, "", "=q");
862 TEST_XCHG(xaddw
, "w", "=q");
863 TEST_XCHG(xaddb
, "b", "=q");
868 asm("xaddl %1, %0" : "=r" (res
) : "0" (res
));
869 printf("xaddl same res=%08x\n", res
);
872 TEST_XCHG(xaddl
, "", "=m");
873 TEST_XCHG(xaddw
, "w", "=m");
874 TEST_XCHG(xaddb
, "b", "=m");
876 TEST_CMPXCHG(cmpxchgl
, "", "=q", 0xfbca7654);
877 TEST_CMPXCHG(cmpxchgw
, "w", "=q", 0xfbca7654);
878 TEST_CMPXCHG(cmpxchgb
, "b", "=q", 0xfbca7654);
880 TEST_CMPXCHG(cmpxchgl
, "", "=q", 0xfffefdfc);
881 TEST_CMPXCHG(cmpxchgw
, "w", "=q", 0xfffefdfc);
882 TEST_CMPXCHG(cmpxchgb
, "b", "=q", 0xfffefdfc);
884 TEST_CMPXCHG(cmpxchgl
, "", "=m", 0xfbca7654);
885 TEST_CMPXCHG(cmpxchgw
, "w", "=m", 0xfbca7654);
886 TEST_CMPXCHG(cmpxchgb
, "b", "=m", 0xfbca7654);
888 TEST_CMPXCHG(cmpxchgl
, "", "=m", 0xfffefdfc);
889 TEST_CMPXCHG(cmpxchgw
, "w", "=m", 0xfffefdfc);
890 TEST_CMPXCHG(cmpxchgb
, "b", "=m", 0xfffefdfc);
893 uint64_t op0
, op1
, op2
;
896 for(i
= 0; i
< 2; i
++) {
897 op0
= 0x123456789abcd;
899 op1
= 0xfbca765423456;
902 op2
= 0x6532432432434;
906 : "=A" (op0
), "=m" (op1
), "=g" (eflags
)
907 : "0" (op0
), "m" (op1
), "b" ((int)op2
), "c" ((int)(op2
>> 32)));
908 printf("cmpxchg8b: op0=%016llx op1=%016llx CC=%02x\n",
909 op0
, op1
, eflags
& CC_Z
);
915 /**********************************************/
916 /* segmentation tests */
919 #include <linux/unistd.h>
920 #include <linux/version.h>
922 _syscall3(int, modify_ldt
, int, func
, void *, ptr
, unsigned long, bytecount
)
924 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 66)
925 #define modify_ldt_ldt_s user_desc
928 uint8_t seg_data1
[4096];
929 uint8_t seg_data2
[4096];
931 #define MK_SEL(n) (((n) << 3) | 7)
933 #define TEST_LR(op, size, seg, mask)\
937 asm (op " %" size "2, %" size "0\n" \
942 : "=r" (res), "=r" (res2) : "m" (seg), "0" (res));\
943 printf(op ": Z=%d %08x\n", res2, res & ~(mask));\
946 /* NOTE: we use Linux modify_ldt syscall */
949 struct modify_ldt_ldt_s ldt
;
950 long long ldt_table
[3];
956 } __attribute__((packed
)) segoff
;
958 ldt
.entry_number
= 1;
959 ldt
.base_addr
= (unsigned long)&seg_data1
;
960 ldt
.limit
= (sizeof(seg_data1
) + 0xfff) >> 12;
962 ldt
.contents
= MODIFY_LDT_CONTENTS_DATA
;
963 ldt
.read_exec_only
= 0;
964 ldt
.limit_in_pages
= 1;
965 ldt
.seg_not_present
= 0;
967 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
969 ldt
.entry_number
= 2;
970 ldt
.base_addr
= (unsigned long)&seg_data2
;
971 ldt
.limit
= (sizeof(seg_data2
) + 0xfff) >> 12;
973 ldt
.contents
= MODIFY_LDT_CONTENTS_DATA
;
974 ldt
.read_exec_only
= 0;
975 ldt
.limit_in_pages
= 1;
976 ldt
.seg_not_present
= 0;
978 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
980 modify_ldt(0, &ldt_table
, sizeof(ldt_table
)); /* read ldt entries */
985 printf("%d: %016Lx\n", i
, ldt_table
[i
]);
988 /* do some tests with fs or gs */
989 asm volatile ("movl %0, %%fs" : : "r" (MK_SEL(1)));
994 asm volatile ("fs movzbl 0x1, %0" : "=r" (res
));
995 printf("FS[1] = %02x\n", res
);
997 asm volatile ("pushl %%gs\n"
999 "gs movzbl 0x1, %0\n"
1003 printf("GS[1] = %02x\n", res
);
1005 /* tests with ds/ss (implicit segment case) */
1007 asm volatile ("pushl %%ebp\n\t"
1010 "movl %3, %%ebp\n\t"
1011 "movzbl 0x1, %0\n\t"
1012 "movzbl (%%ebp), %1\n\t"
1015 : "=r" (res
), "=r" (res2
)
1016 : "r" (MK_SEL(1)), "r" (&tmp
));
1017 printf("DS[1] = %02x\n", res
);
1018 printf("SS[tmp] = %02x\n", res2
);
1020 segoff
.seg
= MK_SEL(2);
1021 segoff
.offset
= 0xabcdef12;
1022 asm volatile("lfs %2, %0\n\t"
1024 : "=r" (res
), "=g" (res2
)
1026 printf("FS:reg = %04x:%08x\n", res2
, res
);
1028 TEST_LR("larw", "w", MK_SEL(2), 0x0100);
1029 TEST_LR("larl", "", MK_SEL(2), 0x0100);
1030 TEST_LR("lslw", "w", MK_SEL(2), 0);
1031 TEST_LR("lsll", "", MK_SEL(2), 0);
1033 TEST_LR("larw", "w", 0xfff8, 0);
1034 TEST_LR("larl", "", 0xfff8, 0);
1035 TEST_LR("lslw", "w", 0xfff8, 0);
1036 TEST_LR("lsll", "", 0xfff8, 0);
1041 /* 16 bit code test */
1042 extern char code16_start
, code16_end
;
1043 extern char code16_func1
;
1044 extern char code16_func2
;
1045 extern char code16_func3
;
1047 void test_code16(void)
1049 struct modify_ldt_ldt_s ldt
;
1052 /* build a code segment */
1053 ldt
.entry_number
= 1;
1054 ldt
.base_addr
= (unsigned long)&code16_start
;
1055 ldt
.limit
= &code16_end
- &code16_start
;
1057 ldt
.contents
= MODIFY_LDT_CONTENTS_CODE
;
1058 ldt
.read_exec_only
= 0;
1059 ldt
.limit_in_pages
= 0;
1060 ldt
.seg_not_present
= 0;
1062 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
1064 /* call the first function */
1065 asm volatile ("lcall %1, %2"
1067 : "i" (MK_SEL(1)), "i" (&code16_func1
): "memory", "cc");
1068 printf("func1() = 0x%08x\n", res
);
1069 asm volatile ("lcall %2, %3"
1070 : "=a" (res
), "=c" (res2
)
1071 : "i" (MK_SEL(1)), "i" (&code16_func2
): "memory", "cc");
1072 printf("func2() = 0x%08x spdec=%d\n", res
, res2
);
1073 asm volatile ("lcall %1, %2"
1075 : "i" (MK_SEL(1)), "i" (&code16_func3
): "memory", "cc");
1076 printf("func3() = 0x%08x\n", res
);
1080 extern char func_lret32
;
1081 extern char func_iret32
;
1083 void test_misc(void)
1090 for(i
=0;i
<256;i
++) table
[i
] = 256 - i
;
1092 asm ("xlat" : "=a" (res
) : "b" (table
), "0" (res
));
1093 printf("xlat: EAX=%08x\n", res
);
1097 asm volatile ("pushl %%cs ; call %1"
1099 : "m" (func_lret32
): "memory", "cc");
1100 printf("func_lret32=%x\n", res
);
1102 asm volatile ("pushfl ; pushl %%cs ; call %1"
1104 : "m" (func_iret32
): "memory", "cc");
1105 printf("func_iret32=%x\n", res
);
1107 /* specific popl test */
1108 asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popl (%%esp) ; popl %0"
1110 printf("popl esp=%x\n", res
);
1113 /* specific popw test */
1114 asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popw (%%esp) ; addl $2, %%esp ; popl %0"
1116 printf("popw esp=%x\n", res
);
1120 uint8_t str_buffer
[4096];
1122 #define TEST_STRING1(OP, size, DF, REP)\
1124 int esi, edi, eax, ecx, eflags;\
1126 esi = (long)(str_buffer + sizeof(str_buffer) / 2);\
1127 edi = (long)(str_buffer + sizeof(str_buffer) / 2) + 16;\
1131 asm volatile ("pushl $0\n\t"\
1134 REP #OP size "\n\t"\
1138 : "=S" (esi), "=D" (edi), "=a" (eax), "=c" (ecx), "=g" (eflags)\
1139 : "0" (esi), "1" (edi), "2" (eax), "3" (ecx));\
1140 printf("%-10s ESI=%08x EDI=%08x EAX=%08x ECX=%08x EFL=%04x\n",\
1141 REP #OP size, esi, edi, eax, ecx,\
1142 eflags & (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A));\
1145 #define TEST_STRING(OP, REP)\
1146 TEST_STRING1(OP, "b", "", REP);\
1147 TEST_STRING1(OP, "w", "", REP);\
1148 TEST_STRING1(OP, "l", "", REP);\
1149 TEST_STRING1(OP, "b", "std", REP);\
1150 TEST_STRING1(OP, "w", "std", REP);\
1151 TEST_STRING1(OP, "l", "std", REP)
1153 void test_string(void)
1156 for(i
= 0;i
< sizeof(str_buffer
); i
++)
1157 str_buffer
[i
] = i
+ 0x56;
1158 TEST_STRING(stos
, "");
1159 TEST_STRING(stos
, "rep ");
1160 // REINSTATE: TEST_STRING(lods, ""); /* to verify stos */
1161 // REINSTATE: TEST_STRING(lods, "rep ");
1162 TEST_STRING(movs
, "");
1163 TEST_STRING(movs
, "rep ");
1164 // REINSTATE: TEST_STRING(lods, ""); /* to verify stos */
1166 /* XXX: better tests */
1167 TEST_STRING(scas
, "");
1168 // REINSTATE: TEST_STRING(scas, "repz ");
1169 TEST_STRING(scas
, "repnz ");
1170 // REINSTATE: TEST_STRING(cmps, "");
1171 TEST_STRING(cmps
, "repz ");
1172 // REINSTATE: TEST_STRING(cmps, "repnz ");
1177 static inline void set_bit(uint8_t *a
, unsigned int bit
)
1179 a
[bit
/ 8] |= (1 << (bit
% 8));
1182 static inline uint8_t *seg_to_linear(unsigned int seg
, unsigned int reg
)
1184 return (uint8_t *)((seg
<< 4) + (reg
& 0xffff));
1187 static inline void pushw(struct vm86_regs
*r
, int val
)
1189 r
->esp
= (r
->esp
& ~0xffff) | ((r
->esp
- 2) & 0xffff);
1190 *(uint16_t *)seg_to_linear(r
->ss
, r
->esp
) = val
;
1193 #undef __syscall_return
1194 #define __syscall_return(type, res) \
1196 return (type) (res); \
1199 _syscall2(int, vm86
, int, func
, struct vm86plus_struct
*, v86
)
1201 extern char vm86_code_start
;
1202 extern char vm86_code_end
;
1204 #define VM86_CODE_CS 0x100
1205 #define VM86_CODE_IP 0x100
1207 void test_vm86(void)
1209 struct vm86plus_struct ctx
;
1210 struct vm86_regs
*r
;
1214 vm86_mem
= mmap((void *)0x00000000, 0x110000,
1215 PROT_WRITE
| PROT_READ
| PROT_EXEC
,
1216 MAP_FIXED
| MAP_ANON
| MAP_PRIVATE
, -1, 0);
1217 if (vm86_mem
== MAP_FAILED
) {
1218 printf("ERROR: could not map vm86 memory");
1221 memset(&ctx
, 0, sizeof(ctx
));
1223 /* init basic registers */
1225 r
->eip
= VM86_CODE_IP
;
1234 r
->eflags
= VIF_MASK
;
1236 /* move code to proper address. We use the same layout as a .com
1238 memcpy(vm86_mem
+ (VM86_CODE_CS
<< 4) + VM86_CODE_IP
,
1239 &vm86_code_start
, &vm86_code_end
- &vm86_code_start
);
1241 /* mark int 0x21 as being emulated */
1242 set_bit((uint8_t *)&ctx
.int_revectored
, 0x21);
1245 ret
= vm86(VM86_ENTER
, &ctx
);
1246 switch(VM86_TYPE(ret
)) {
1251 int_num
= VM86_ARG(ret
);
1252 if (int_num
!= 0x21)
1254 ah
= (r
->eax
>> 8) & 0xff;
1256 case 0x00: /* exit */
1258 case 0x02: /* write char */
1264 case 0x09: /* write string */
1267 ptr
= seg_to_linear(r
->ds
, r
->edx
);
1274 r
->eax
= (r
->eax
& ~0xff) | '$';
1277 case 0xff: /* extension: write eflags number in edx */
1279 #ifndef LINUX_VM86_IOPL_FIX
1282 printf("%08x\n", v
);
1286 printf("unsupported int 0x%02x\n", int_num
);
1292 /* a signal came, we just ignore that */
1297 printf("ERROR: unhandled vm86 return code (0x%x)\n", ret
);
1302 printf("VM86 end\n");
1303 munmap(vm86_mem
, 0x110000);
1307 /* exception tests */
1320 #define REG_TRAPNO TRAPNO
1328 void sig_handler(int sig
, siginfo_t
*info
, void *puc
)
1330 struct ucontext
*uc
= puc
;
1332 printf("si_signo=%d si_errno=%d si_code=%d",
1333 info
->si_signo
, info
->si_errno
, info
->si_code
);
1334 printf(" si_addr=0x%08lx",
1335 (unsigned long)info
->si_addr
);
1338 printf("trapno=0x%02x err=0x%08x",
1339 uc
->uc_mcontext
.gregs
[REG_TRAPNO
],
1340 uc
->uc_mcontext
.gregs
[REG_ERR
]);
1341 printf(" EIP=0x%08x", uc
->uc_mcontext
.gregs
[REG_EIP
]);
1343 longjmp(jmp_env
, 1);
1346 void test_exceptions(void)
1348 struct modify_ldt_ldt_s ldt
;
1349 struct sigaction act
;
1352 act
.sa_sigaction
= sig_handler
;
1353 sigemptyset(&act
.sa_mask
);
1354 act
.sa_flags
= SA_SIGINFO
;
1355 sigaction(SIGFPE
, &act
, NULL
);
1356 sigaction(SIGILL
, &act
, NULL
);
1357 sigaction(SIGSEGV
, &act
, NULL
);
1358 sigaction(SIGBUS
, &act
, NULL
);
1359 sigaction(SIGTRAP
, &act
, NULL
);
1361 /* test division by zero reporting */
1362 printf("DIVZ exception:\n");
1363 if (setjmp(jmp_env
) == 0) {
1364 /* now divide by zero */
1369 printf("BOUND exception:\n");
1370 if (setjmp(jmp_env
) == 0) {
1371 /* bound exception */
1374 asm volatile ("bound %0, %1" : : "r" (11), "m" (tab
));
1377 printf("segment exceptions:\n");
1378 if (setjmp(jmp_env
) == 0) {
1379 /* load an invalid segment */
1380 asm volatile ("movl %0, %%fs" : : "r" ((0x1234 << 3) | 1));
1382 if (setjmp(jmp_env
) == 0) {
1383 /* null data segment is valid */
1384 asm volatile ("movl %0, %%fs" : : "r" (3));
1385 /* null stack segment */
1386 asm volatile ("movl %0, %%ss" : : "r" (3));
1389 ldt
.entry_number
= 1;
1390 ldt
.base_addr
= (unsigned long)&seg_data1
;
1391 ldt
.limit
= (sizeof(seg_data1
) + 0xfff) >> 12;
1393 ldt
.contents
= MODIFY_LDT_CONTENTS_DATA
;
1394 ldt
.read_exec_only
= 0;
1395 ldt
.limit_in_pages
= 1;
1396 ldt
.seg_not_present
= 1;
1398 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
1400 if (setjmp(jmp_env
) == 0) {
1401 /* segment not present */
1402 asm volatile ("movl %0, %%fs" : : "r" (MK_SEL(1)));
1405 /* test SEGV reporting */
1406 printf("PF exception:\n");
1407 if (setjmp(jmp_env
) == 0) {
1409 /* we add a nop to test a weird PC retrieval case */
1410 asm volatile ("nop");
1411 /* now store in an invalid address */
1412 *(char *)0x1234 = 1;
1415 /* test SEGV reporting */
1416 printf("PF exception:\n");
1417 if (setjmp(jmp_env
) == 0) {
1419 /* read from an invalid address */
1420 v1
= *(char *)0x1234;
1423 /* test illegal instruction reporting */
1424 printf("UD2 exception:\n");
1425 if (setjmp(jmp_env
) == 0) {
1426 /* now execute an invalid instruction */
1427 asm volatile("ud2");
1429 printf("lock nop exception:\n");
1430 if (setjmp(jmp_env
) == 0) {
1431 /* now execute an invalid instruction */
1432 asm volatile("lock nop");
1435 printf("INT exception:\n");
1436 if (setjmp(jmp_env
) == 0) {
1437 asm volatile ("int $0xfd");
1439 if (setjmp(jmp_env
) == 0) {
1440 asm volatile ("int $0x01");
1442 if (setjmp(jmp_env
) == 0) {
1443 asm volatile (".byte 0xcd, 0x03");
1445 if (setjmp(jmp_env
) == 0) {
1446 asm volatile ("int $0x04");
1448 if (setjmp(jmp_env
) == 0) {
1449 asm volatile ("int $0x05");
1452 printf("INT3 exception:\n");
1453 if (setjmp(jmp_env
) == 0) {
1454 asm volatile ("int3");
1457 printf("CLI exception:\n");
1458 if (setjmp(jmp_env
) == 0) {
1459 asm volatile ("cli");
1462 printf("STI exception:\n");
1463 if (setjmp(jmp_env
) == 0) {
1464 asm volatile ("cli");
1467 printf("INTO exception:\n");
1468 if (setjmp(jmp_env
) == 0) {
1469 /* overflow exception */
1470 asm volatile ("addl $1, %0 ; into" : : "r" (0x7fffffff));
1473 printf("OUTB exception:\n");
1474 if (setjmp(jmp_env
) == 0) {
1475 asm volatile ("outb %%al, %%dx" : : "d" (0x4321), "a" (0));
1478 printf("INB exception:\n");
1479 if (setjmp(jmp_env
) == 0) {
1480 asm volatile ("inb %%dx, %%al" : "=a" (val
) : "d" (0x4321));
1483 printf("REP OUTSB exception:\n");
1484 if (setjmp(jmp_env
) == 0) {
1485 asm volatile ("rep outsb" : : "d" (0x4321), "S" (tab
), "c" (1));
1488 printf("REP INSB exception:\n");
1489 if (setjmp(jmp_env
) == 0) {
1490 asm volatile ("rep insb" : : "d" (0x4321), "D" (tab
), "c" (1));
1493 printf("HLT exception:\n");
1494 if (setjmp(jmp_env
) == 0) {
1495 asm volatile ("hlt");
1498 printf("single step exception:\n");
1500 if (setjmp(jmp_env
) == 0) {
1501 asm volatile ("pushf\n"
1502 "orl $0x00100, (%%esp)\n"
1504 "movl $0xabcd, %0\n"
1505 "movl $0x0, %0\n" : "=m" (val
) : : "cc", "memory");
1507 printf("val=0x%x\n", val
);
1510 /* specific precise single step test */
1511 void sig_trap_handler(int sig
, siginfo_t
*info
, void *puc
)
1513 struct ucontext
*uc
= puc
;
1514 printf("EIP=0x%08x\n", uc
->uc_mcontext
.gregs
[REG_EIP
]);
1517 const uint8_t sstep_buf1
[4] = { 1, 2, 3, 4};
1518 uint8_t sstep_buf2
[4];
1520 void test_single_step(void)
1522 struct sigaction act
;
1527 act
.sa_sigaction
= sig_trap_handler
;
1528 sigemptyset(&act
.sa_mask
);
1529 act
.sa_flags
= SA_SIGINFO
;
1530 sigaction(SIGTRAP
, &act
, NULL
);
1531 asm volatile ("pushf\n"
1532 "orl $0x00100, (%%esp)\n"
1534 "movl $0xabcd, %0\n"
1543 /* movsb: the single step should stop at each movsb iteration */
1544 "movl $sstep_buf1, %%esi\n"
1545 "movl $sstep_buf2, %%edi\n"
1553 /* cmpsb: the single step should stop at each cmpsb iteration */
1554 "movl $sstep_buf1, %%esi\n"
1555 "movl $sstep_buf2, %%edi\n"
1561 /* getpid() syscall: single step should skip one
1567 /* when modifying SS, trace is not done on the next
1569 "movl %%ss, %%ecx\n"
1570 "movl %%ecx, %%ss\n"
1573 "movl %%ecx, %%ss\n"
1584 "andl $~0x00100, (%%esp)\n"
1588 : "cc", "memory", "eax", "ecx", "esi", "edi");
1589 printf("val=%d\n", val
);
1590 for(i
= 0; i
< 4; i
++)
1591 printf("sstep_buf2[%d] = %d\n", i
, sstep_buf2
[i
]);
1594 /* self modifying code test */
1596 0xb8, 0x1, 0x00, 0x00, 0x00, /* movl $1, %eax */
1601 "movl 4(%esp), %eax\n"
1602 "movl %eax, smc_patch_addr2 + 1\n"
1611 "smc_patch_addr2:\n"
1615 typedef int FuncType(void);
1616 extern int smc_code2(int);
1617 void test_self_modifying_code(void)
1621 printf("self modifying code:\n");
1622 printf("func1 = 0x%x\n", ((FuncType
*)code
)());
1623 for(i
= 2; i
<= 4; i
++) {
1625 printf("func%d = 0x%x\n", i
, ((FuncType
*)code
)());
1628 /* more difficult test : the modified code is just after the
1629 modifying instruction. It is forbidden in Intel specs, but it
1630 is used by old DOS programs */
1631 for(i
= 2; i
<= 4; i
++) {
1632 printf("smc_code2(%d) = %d\n", i
, smc_code2(i
));
1636 static void *call_end __init_call
= NULL
;
1639 int main(int argc
, char **argv
)
1645 ptr
= &call_start
+ 1;
1646 while (*ptr
!= NULL
) {
1658 test_misc(); // REINSTATE
1663 //test_exceptions();
1664 //test_self_modifying_code();
1665 //test_single_step();