4 gcc -g -o test-amd64 test-amd64.c -lm
8 /* Contrary to what the next comment says, this is now an amd64 CPU
14 * Copyright (c) 2003 Fabrice Bellard
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
38 #include <sys/ucontext.h>
41 /* Setting this to 1 creates a very comprehensive test of
42 integer condition codes. */
43 #define TEST_INTEGER_VERBOSE 1
45 typedef long long int int64
;
47 //#define LINUX_VM86_IOPL_FIX
48 //#define TEST_P4_FLAGS
50 #define xglue(x, y) x ## y
51 #define glue(x, y) xglue(x, y)
52 #define stringify(s) tostring(s)
53 #define tostring(s) #s
62 #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
64 static void *call_start __init_call
= NULL
;
66 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
69 #include "test-amd64.h"
72 #include "test-amd64.h"
75 #include "test-amd64.h"
78 #include "test-amd64.h"
81 #include "test-amd64.h"
84 #include "test-amd64.h"
88 #include "test-amd64.h"
92 #include "test-amd64.h"
97 #include "test-amd64.h"
102 #include "test-amd64.h"
107 #include "test-amd64.h"
112 #include "test-amd64.h"
115 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
118 #include "test-amd64-shift.h"
121 #include "test-amd64-shift.h"
124 #include "test-amd64-shift.h"
127 #include "test-amd64-shift.h"
130 #include "test-amd64-shift.h"
134 #include "test-amd64-shift.h"
138 #include "test-amd64-shift.h"
144 #include "test-amd64-shift.h"
149 #include "test-amd64-shift.h"
152 /* XXX: should be more precise ? */
154 #define CC_MASK (CC_C)
159 #include "test-amd64-shift.h"
163 #include "test-amd64-shift.h"
167 #include "test-amd64-shift.h"
171 #include "test-amd64-shift.h"
174 /* lea test (modrm support) */
175 #define TEST_LEA(STR)\
177 asm("leaq " STR ", %0"\
179 : "a" (rax), "b" (rbx), "c" (rcx), "d" (rdx), "S" (rsi), "D" (rdi));\
180 printf("lea %s = %016llx\n", STR, res);\
183 #define TEST_LEA16(STR)\
185 asm(".code16 ; .byte 0x67 ; leal " STR ", %0 ; .code32"\
187 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
188 printf("lea %s = %08x\n", STR, res);\
194 int64 rax
, rbx
, rcx
, rdx
, rsi
, rdi
, res
;
211 TEST_LEA("0x40(%%rax)");
212 TEST_LEA("0x40(%%rbx)");
213 TEST_LEA("0x40(%%rcx)");
214 TEST_LEA("0x40(%%rdx)");
215 TEST_LEA("0x40(%%rsi)");
216 TEST_LEA("0x40(%%rdi)");
218 TEST_LEA("0x4000(%%rax)");
219 TEST_LEA("0x4000(%%rbx)");
220 TEST_LEA("0x4000(%%rcx)");
221 TEST_LEA("0x4000(%%rdx)");
222 TEST_LEA("0x4000(%%rsi)");
223 TEST_LEA("0x4000(%%rdi)");
225 TEST_LEA("(%%rax, %%rcx)");
226 TEST_LEA("(%%rbx, %%rdx)");
227 TEST_LEA("(%%rcx, %%rcx)");
228 TEST_LEA("(%%rdx, %%rcx)");
229 TEST_LEA("(%%rsi, %%rcx)");
230 TEST_LEA("(%%rdi, %%rcx)");
232 TEST_LEA("0x40(%%rax, %%rcx)");
233 TEST_LEA("0x4000(%%rbx, %%rdx)");
235 TEST_LEA("(%%rcx, %%rcx, 2)");
236 TEST_LEA("(%%rdx, %%rcx, 4)");
237 TEST_LEA("(%%rsi, %%rcx, 8)");
239 TEST_LEA("(,%%rax, 2)");
240 TEST_LEA("(,%%rbx, 4)");
241 TEST_LEA("(,%%rcx, 8)");
243 TEST_LEA("0x40(,%%rax, 2)");
244 TEST_LEA("0x40(,%%rbx, 4)");
245 TEST_LEA("0x40(,%%rcx, 8)");
248 TEST_LEA("-10(%%rcx, %%rcx, 2)");
249 TEST_LEA("-10(%%rdx, %%rcx, 4)");
250 TEST_LEA("-10(%%rsi, %%rcx, 8)");
252 TEST_LEA("0x4000(%%rcx, %%rcx, 2)");
253 TEST_LEA("0x4000(%%rdx, %%rcx, 4)");
254 TEST_LEA("0x4000(%%rsi, %%rcx, 8)");
257 #define TEST_JCC(JCC, v1, v2)\
260 asm("movl $1, %0\n\t"\
266 : "r" (v1), "r" (v2));\
267 printf("%-10s %d\n", "j" JCC, res);\
269 asm("movl $0, %0\n\t"\
271 "set" JCC " %b0\n\t"\
273 : "r" (v1), "r" (v2));\
274 printf("%-10s %d\n", "set" JCC, res);\
276 asm("movl $0x12345678, %0\n\t"\
278 "cmov" JCC "l %3, %0\n\t"\
280 : "r" (v1), "r" (v2), "m" (one));\
281 printf("%-10s R=0x%08x\n", "cmov" JCC "l", res);\
282 asm("movl $0x12345678, %0\n\t"\
284 "cmov" JCC "w %w3, %w0\n\t"\
286 : "r" (v1), "r" (v2), "r" (one));\
287 printf("%-10s R=0x%08x\n", "cmov" JCC "w", res);\
291 /* various jump tests */
294 TEST_JCC("ne", 1, 1);
295 TEST_JCC("ne", 1, 0);
302 TEST_JCC("l", 1, -1);
304 TEST_JCC("le", 1, 1);
305 TEST_JCC("le", 1, 0);
306 TEST_JCC("le", 1, -1);
308 TEST_JCC("ge", 1, 1);
309 TEST_JCC("ge", 1, 0);
310 TEST_JCC("ge", -1, 1);
314 TEST_JCC("g", 1, -1);
318 TEST_JCC("b", 1, -1);
320 TEST_JCC("be", 1, 1);
321 TEST_JCC("be", 1, 0);
322 TEST_JCC("be", 1, -1);
324 TEST_JCC("ae", 1, 1);
325 TEST_JCC("ae", 1, 0);
326 TEST_JCC("ae", 1, -1);
330 TEST_JCC("a", 1, -1);
336 TEST_JCC("np", 1, 1);
337 TEST_JCC("np", 1, 0);
339 TEST_JCC("o", 0x7fffffff, 0);
340 TEST_JCC("o", 0x7fffffff, -1);
342 TEST_JCC("no", 0x7fffffff, 0);
343 TEST_JCC("no", 0x7fffffff, -1);
346 TEST_JCC("s", 0, -1);
349 TEST_JCC("ns", 0, 1);
350 TEST_JCC("ns", 0, -1);
351 TEST_JCC("ns", 0, 0);
356 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
358 #define CC_MASK (CC_O | CC_C)
362 #include "test-amd64-muldiv.h"
365 #include "test-amd64-muldiv.h"
367 void test_imulw2(int64 op0
, int64 op1
)
369 int64 res
, s1
, s0
, flags
;
379 : "=q" (res
), "=g" (flags
)
380 : "q" (s1
), "0" (res
), "1" (flags
));
381 printf("%-10s A=%016llx B=%016llx R=%016llx CC=%04llx\n",
382 "imulw", s0
, s1
, res
, flags
& CC_MASK
);
385 void test_imull2(int64 op0
, int64 op1
)
398 : "=q" (res
), "=g" (flags
)
399 : "q" (s1
), "0" (res
), "1" (flags
));
400 printf("%-10s A=%016llx B=%08x R=%08x CC=%04llx\n",
401 "imull", s0
, s1
, res
, flags
& CC_MASK
);
404 #define TEST_IMUL_IM(size, size1, op0, op1)\
411 "imul" size " $" #op0 ", %" size1 "2, %" size1 "0\n\t" \
414 : "=r" (res), "=g" (flags)\
415 : "r" (op1), "1" (flags), "0" (res));\
416 printf("%-10s A=%08x B=%08x R=%016llx CC=%04llx\n",\
417 "imul" size, op0, op1, res, flags & CC_MASK);\
420 #define TEST_IMUL_IM_L(op0, op1)\
427 "imul $" #op0 ", %2, %0\n\t" \
430 : "=r" (res64), "=g" (flags)\
431 : "r" (op1), "1" (flags), "0" (res));\
432 printf("%-10s A=%08x B=%08x R=%08x CC=%04llx\n",\
433 "imull", op0, op1, res, flags & CC_MASK);\
441 #include "test-amd64-muldiv.h"
444 #include "test-amd64-muldiv.h"
448 test_imulb(0x1234561d, 4);
450 test_imulb(0x80, 0x80);
451 test_imulb(0x10, 0x10);
454 test_imulw(0, 0xFF, 0xFF);
455 test_imulw(0, 0xFF, 0x100);
456 test_imulw(0, 0x1234001d, 45);
457 test_imulw(0, 23, -45);
458 test_imulw(0, 0x8000, 0x8000);
459 test_imulw(0, 0x100, 0x100);
462 test_imull(0, 0xFFFF, 0xFFFF);
463 test_imull(0, 0xFFFF, 0x10000);
464 test_imull(0, 0x1234001d, 45);
465 test_imull(0, 23, -45);
466 test_imull(0, 0x80000000, 0x80000000);
467 test_imull(0, 0x10000, 0x10000);
469 test_mulb(0x1234561d, 4);
471 test_mulb(0x80, 0x80);
472 test_mulb(0x10, 0x10);
474 test_mulw(0, 0x1234001d, 45);
475 test_mulw(0, 23, -45);
476 test_mulw(0, 0x8000, 0x8000);
477 test_mulw(0, 0x100, 0x100);
479 test_mull(0, 0x1234001d, 45);
480 test_mull(0, 23, -45);
481 test_mull(0, 0x80000000, 0x80000000);
482 test_mull(0, 0x10000, 0x10000);
484 test_imulw2(0x1234001d, 45);
485 test_imulw2(23, -45);
486 test_imulw2(0x8000, 0x8000);
487 test_imulw2(0x100, 0x100);
489 test_imull2(0x1234001d, 45);
490 test_imull2(23, -45);
491 test_imull2(0x80000000, 0x80000000);
492 test_imull2(0x10000, 0x10000);
494 TEST_IMUL_IM("w", "w", 45, 0x1234);
495 TEST_IMUL_IM("w", "w", -45, 23);
496 TEST_IMUL_IM("w", "w", 0x8000, 0x80000000);
497 TEST_IMUL_IM("w", "w", 0x7fff, 0x1000);
499 TEST_IMUL_IM_L(45, 0x1234);
500 TEST_IMUL_IM_L(-45, 23);
501 TEST_IMUL_IM_L(0x8000, 0x80000000);
502 TEST_IMUL_IM_L(0x7fff, 0x1000);
504 test_idivb(0x12341678, 0x127e);
505 test_idivb(0x43210123, -5);
506 test_idivb(0x12340004, -1);
508 test_idivw(0, 0x12345678, 12347);
509 test_idivw(0, -23223, -45);
510 test_idivw(0, 0x12348000, -1);
511 test_idivw(0x12343, 0x12345678, 0x81238567);
513 test_idivl(0, 0x12345678, 12347);
514 test_idivl(0, -233223, -45);
515 test_idivl(0, 0x80000000, -1);
516 test_idivl(0x12343, 0x12345678, 0x81234567);
518 test_idivq(0, 0x12345678, 12347);
519 test_idivq(0, -233223, -45);
520 test_idivq(0, 0x80000000, -1);
521 test_idivq(0x12343, 0x12345678, 0x81234567);
523 test_divb(0x12341678, 0x127e);
524 test_divb(0x43210123, -5);
525 test_divb(0x12340004, -1);
527 test_divw(0, 0x12345678, 12347);
528 test_divw(0, -23223, -45);
529 test_divw(0, 0x12348000, -1);
530 test_divw(0x12343, 0x12345678, 0x81238567);
532 test_divl(0, 0x12345678, 12347);
533 test_divl(0, -233223, -45);
534 test_divl(0, 0x80000000, -1);
535 test_divl(0x12343, 0x12345678, 0x81234567);
537 test_divq(0, 0x12345678, 12347);
538 test_divq(0, -233223, -45);
539 test_divq(0, 0x80000000, -1);
540 test_divq(0x12343, 0x12345678, 0x81234567);
543 #define TEST_BSX(op, size, op0)\
548 "movl $0x12345678, %0\n"\
549 #op " %" size "2, %" size "0 ; setz %b1" \
550 : "=r" (res), "=q" (resz)\
552 printf("%-10s A=%08x R=%08x %d\n", #op, val, res, resz);\
557 TEST_BSX(bsrw
, "w", 0);
558 TEST_BSX(bsrw
, "w", 0x12340128);
559 TEST_BSX(bsrl
, "", 0);
560 TEST_BSX(bsrl
, "", 0x00340128);
561 TEST_BSX(bsfw
, "w", 0);
562 TEST_BSX(bsfw
, "w", 0x12340128);
563 TEST_BSX(bsfl
, "", 0);
564 TEST_BSX(bsfl
, "", 0x00340128);
567 /**********************************************/
569 void test_fops(double a
, double b
)
571 printf("a=%f b=%f a+b=%f\n", a
, b
, a
+ b
);
572 printf("a=%f b=%f a-b=%f\n", a
, b
, a
- b
);
573 printf("a=%f b=%f a*b=%f\n", a
, b
, a
* b
);
574 printf("a=%f b=%f a/b=%f\n", a
, b
, a
/ b
);
575 printf("a=%f b=%f fmod(a, b)=%f\n", a
, b
, fmod(a
, b
));
576 printf("a=%f sqrt(a)=%f\n", a
, sqrt(a
));
577 printf("a=%f sin(a)=%f\n", a
, sin(a
));
578 printf("a=%f cos(a)=%f\n", a
, cos(a
));
579 printf("a=%f tan(a)=%f\n", a
, tan(a
));
580 printf("a=%f log(a)=%f\n", a
, log(a
));
581 printf("a=%f exp(a)=%f\n", a
, exp(a
));
582 printf("a=%f b=%f atan2(a, b)=%f\n", a
, b
, atan2(a
, b
));
583 /* just to test some op combining */
584 printf("a=%f asin(sin(a))=%f\n", a
, asin(sin(a
)));
585 printf("a=%f acos(cos(a))=%f\n", a
, acos(cos(a
)));
586 printf("a=%f atan(tan(a))=%f\n", a
, atan(tan(a
)));
589 void test_fcmp(double a
, double b
)
591 printf("(%f<%f)=%d\n",
593 printf("(%f<=%f)=%d\n",
595 printf("(%f==%f)=%d\n",
597 printf("(%f>%f)=%d\n",
599 printf("(%f<=%f)=%d\n",
602 unsigned long long int rflags
;
603 /* test f(u)comi instruction */
609 printf("fcomi(%f %f)=%016llx\n", a
, b
, rflags
& (CC_Z
| CC_P
| CC_C
));
613 void test_fcvt(double a
)
626 printf("(float)%f = %f\n", a
, fa
);
627 printf("(long double)%f = %Lf\n", a
, la
);
628 printf("a=%016Lx\n", *(long long *)&a
);
629 printf("la=%016Lx %04x\n", *(long long *)&la
,
630 *(unsigned short *)((char *)(&la
) + 8));
632 /* test all roundings */
633 asm volatile ("fstcw %0" : "=m" (fpuc
));
635 short zz
= (fpuc
& ~0x0c00) | (i
<< 10);
636 asm volatile ("fldcw %0" : : "m" (zz
));
637 asm volatile ("fist %0" : "=m" (wa
) : "t" (a
));
638 asm volatile ("fistl %0" : "=m" (ia
) : "t" (a
));
639 asm volatile ("fistpll %0" : "=m" (lla
) : "t" (a
) : "st");
640 asm volatile ("frndint ; fstl %0" : "=m" (ra
) : "t" (a
));
641 asm volatile ("fldcw %0" : : "m" (fpuc
));
642 printf("(short)a = %d\n", wa
);
643 printf("(int)a = %d\n", ia
);
644 printf("(int64_t)a = %Ld\n", lla
);
645 printf("rint(a) = %f\n", ra
);
650 asm("fld" #N : "=t" (a)); \
651 printf("fld" #N "= %f\n", a);
653 void test_fconst(void)
665 void test_fbcd(double a
)
667 unsigned short bcd
[5];
670 asm("fbstp %0" : "=m" (bcd
[0]) : "t" (a
) : "st");
671 asm("fbld %1" : "=t" (b
) : "m" (bcd
[0]));
672 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n",
673 a
, bcd
[4], bcd
[3], bcd
[2], bcd
[1], bcd
[0], b
);
676 #define TEST_ENV(env, save, restore)\
678 memset((env), 0xaa, sizeof(*(env)));\
680 asm volatile ("fldl %0" : : "m" (dtab[i]));\
681 asm(save " %0\n" : : "m" (*(env)));\
682 asm(restore " %0\n": : "m" (*(env)));\
684 asm volatile ("fstpl %0" : "=m" (rtab[i]));\
686 printf("res[%d]=%f\n", i, rtab[i]);\
687 printf("fpuc=%04x fpus=%04x fptag=%04x\n",\
689 (env)->fpus & 0xff00,\
695 struct __attribute__((packed
)) {
703 long double fpregs
[8];
705 struct __attribute__((packed
)) {
710 long double fpregs
[8];
719 TEST_ENV(&float_env16
, "data16 fnstenv", "data16 fldenv");
720 TEST_ENV(&float_env16
, "data16 fnsave", "data16 frstor");
721 TEST_ENV(&float_env32
, "fnstenv", "fldenv");
722 TEST_ENV(&float_env32
, "fnsave", "frstor");
726 asm volatile ("fldl %0" : : "m" (dtab
[i
]));
727 asm volatile("ffree %st(2)");
728 asm volatile ("fnstenv %0\n" : : "m" (float_env32
));
729 asm volatile ("fninit");
730 printf("fptag=%04x\n", float_env32
.fptag
);
734 #define TEST_FCMOV(a, b, rflags, CC)\
739 "fcmov" CC " %2, %0\n"\
741 : "0" (a), "u" (b), "g" (rflags));\
742 printf("fcmov%s rflags=0x%04llx-> %f\n", \
746 void test_fcmov(void)
753 for(i
= 0; i
< 4; i
++) {
759 TEST_FCMOV(a
, b
, rflags
, "b");
760 TEST_FCMOV(a
, b
, rflags
, "e");
761 TEST_FCMOV(a
, b
, rflags
, "be");
762 TEST_FCMOV(a
, b
, rflags
, "nb");
763 TEST_FCMOV(a
, b
, rflags
, "ne");
764 TEST_FCMOV(a
, b
, rflags
, "nbe");
766 TEST_FCMOV(a
, b
, (int64
)0, "u");
767 TEST_FCMOV(a
, b
, (int64
)CC_P
, "u");
768 TEST_FCMOV(a
, b
, (int64
)0, "nu");
769 TEST_FCMOV(a
, b
, (int64
)CC_P
, "nu");
772 void test_floats(void)
786 // REINSTATE (maybe): test_fbcd(1234567890123456);
787 // REINSTATE (maybe): test_fbcd(-123451234567890);
788 // REINSTATE: test_fenv();
789 // REINSTATE: test_fcmov();
792 /**********************************************/
795 #define TEST_BCD(op, op0, cc_in, cc_mask)\
805 : "=a" (res), "=g" (flags)\
806 : "0" (res), "1" (flags));\
807 printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",\
808 #op, op0, res, cc_in, flags & cc_mask);\
813 TEST_BCD(daa
, 0x12340503, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
814 TEST_BCD(daa
, 0x12340506, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
815 TEST_BCD(daa
, 0x12340507, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
816 TEST_BCD(daa
, 0x12340559, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
817 TEST_BCD(daa
, 0x12340560, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
818 TEST_BCD(daa
, 0x1234059f, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
819 TEST_BCD(daa
, 0x123405a0, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
820 TEST_BCD(daa
, 0x12340503, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
821 TEST_BCD(daa
, 0x12340506, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
822 TEST_BCD(daa
, 0x12340503, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
823 TEST_BCD(daa
, 0x12340506, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
824 TEST_BCD(daa
, 0x12340503, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
825 TEST_BCD(daa
, 0x12340506, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
827 TEST_BCD(das
, 0x12340503, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
828 TEST_BCD(das
, 0x12340506, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
829 TEST_BCD(das
, 0x12340507, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
830 TEST_BCD(das
, 0x12340559, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
831 TEST_BCD(das
, 0x12340560, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
832 TEST_BCD(das
, 0x1234059f, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
833 TEST_BCD(das
, 0x123405a0, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
834 TEST_BCD(das
, 0x12340503, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
835 TEST_BCD(das
, 0x12340506, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
836 TEST_BCD(das
, 0x12340503, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
837 TEST_BCD(das
, 0x12340506, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
838 TEST_BCD(das
, 0x12340503, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
839 TEST_BCD(das
, 0x12340506, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
841 TEST_BCD(aaa
, 0x12340205, CC_A
, (CC_C
| CC_A
));
842 TEST_BCD(aaa
, 0x12340306, CC_A
, (CC_C
| CC_A
));
843 TEST_BCD(aaa
, 0x1234040a, CC_A
, (CC_C
| CC_A
));
844 TEST_BCD(aaa
, 0x123405fa, CC_A
, (CC_C
| CC_A
));
845 TEST_BCD(aaa
, 0x12340205, 0, (CC_C
| CC_A
));
846 TEST_BCD(aaa
, 0x12340306, 0, (CC_C
| CC_A
));
847 TEST_BCD(aaa
, 0x1234040a, 0, (CC_C
| CC_A
));
848 TEST_BCD(aaa
, 0x123405fa, 0, (CC_C
| CC_A
));
850 TEST_BCD(aas
, 0x12340205, CC_A
, (CC_C
| CC_A
));
851 TEST_BCD(aas
, 0x12340306, CC_A
, (CC_C
| CC_A
));
852 TEST_BCD(aas
, 0x1234040a, CC_A
, (CC_C
| CC_A
));
853 TEST_BCD(aas
, 0x123405fa, CC_A
, (CC_C
| CC_A
));
854 TEST_BCD(aas
, 0x12340205, 0, (CC_C
| CC_A
));
855 TEST_BCD(aas
, 0x12340306, 0, (CC_C
| CC_A
));
856 TEST_BCD(aas
, 0x1234040a, 0, (CC_C
| CC_A
));
857 TEST_BCD(aas
, 0x123405fa, 0, (CC_C
| CC_A
));
859 TEST_BCD(aam
, 0x12340547, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_O
| CC_A
));
860 TEST_BCD(aad
, 0x12340407, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_O
| CC_A
));
864 #define TEST_XCHG(op, size, opconst)\
869 asm(#op " %" size "0, %" size "1" \
870 : "=q" (op0), opconst (op1) \
871 : "0" (op0), "1" (op1));\
872 printf("%-10s A=%08x B=%08x\n",\
876 #define TEST_CMPXCHG(op, size, opconst, eax)\
881 asm(#op " %" size "0, %" size "1" \
882 : "=q" (op0), opconst (op1) \
883 : "0" (op0), "1" (op1), "a" (eax));\
884 printf("%-10s EAX=%08x A=%08x C=%08x\n",\
885 #op, eax, op0, op1);\
890 TEST_XCHG(xchgl
, "", "=q");
891 TEST_XCHG(xchgw
, "w", "=q");
892 TEST_XCHG(xchgb
, "b", "=q");
894 TEST_XCHG(xchgl
, "", "=m");
895 TEST_XCHG(xchgw
, "w", "=m");
896 TEST_XCHG(xchgb
, "b", "=m");
899 TEST_XCHG(xaddl
, "", "=q");
900 TEST_XCHG(xaddw
, "w", "=q");
901 TEST_XCHG(xaddb
, "b", "=q");
906 asm("xaddl %1, %0" : "=r" (res
) : "0" (res
));
907 printf("xaddl same res=%08x\n", res
);
910 TEST_XCHG(xaddl
, "", "=m");
911 TEST_XCHG(xaddw
, "w", "=m");
912 TEST_XCHG(xaddb
, "b", "=m");
914 TEST_CMPXCHG(cmpxchgl
, "", "=q", 0xfbca7654);
915 TEST_CMPXCHG(cmpxchgw
, "w", "=q", 0xfbca7654);
916 TEST_CMPXCHG(cmpxchgb
, "b", "=q", 0xfbca7654);
918 TEST_CMPXCHG(cmpxchgl
, "", "=q", 0xfffefdfc);
919 TEST_CMPXCHG(cmpxchgw
, "w", "=q", 0xfffefdfc);
920 TEST_CMPXCHG(cmpxchgb
, "b", "=q", 0xfffefdfc);
922 TEST_CMPXCHG(cmpxchgl
, "", "=m", 0xfbca7654);
923 TEST_CMPXCHG(cmpxchgw
, "w", "=m", 0xfbca7654);
924 TEST_CMPXCHG(cmpxchgb
, "b", "=m", 0xfbca7654);
926 TEST_CMPXCHG(cmpxchgl
, "", "=m", 0xfffefdfc);
927 TEST_CMPXCHG(cmpxchgw
, "w", "=m", 0xfffefdfc);
928 TEST_CMPXCHG(cmpxchgb
, "b", "=m", 0xfffefdfc);
931 uint64_t op0
, op1
, op2
;
934 for(i
= 0; i
< 2; i
++) {
935 op0
= 0x123456789abcd;
937 op1
= 0xfbca765423456;
940 op2
= 0x6532432432434;
944 : "=A" (op0
), "=m" (op1
), "=g" (eflags
)
945 : "0" (op0
), "m" (op1
), "b" ((int)op2
), "c" ((int)(op2
>> 32)));
946 printf("cmpxchg8b: op0=%016llx op1=%016llx CC=%02x\n",
947 op0
, op1
, eflags
& CC_Z
);
953 /**********************************************/
954 /* segmentation tests */
957 #include <linux/unistd.h>
958 #include <linux/version.h>
960 _syscall3(int, modify_ldt
, int, func
, void *, ptr
, unsigned long, bytecount
)
962 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 66)
963 #define modify_ldt_ldt_s user_desc
966 uint8_t seg_data1
[4096];
967 uint8_t seg_data2
[4096];
969 #define MK_SEL(n) (((n) << 3) | 7)
971 #define TEST_LR(op, size, seg, mask)\
975 asm (op " %" size "2, %" size "0\n" \
980 : "=r" (res), "=r" (res2) : "m" (seg), "0" (res));\
981 printf(op ": Z=%d %08x\n", res2, res & ~(mask));\
984 /* NOTE: we use Linux modify_ldt syscall */
987 struct modify_ldt_ldt_s ldt
;
988 long long ldt_table
[3];
994 } __attribute__((packed
)) segoff
;
996 ldt
.entry_number
= 1;
997 ldt
.base_addr
= (unsigned long)&seg_data1
;
998 ldt
.limit
= (sizeof(seg_data1
) + 0xfff) >> 12;
1000 ldt
.contents
= MODIFY_LDT_CONTENTS_DATA
;
1001 ldt
.read_exec_only
= 0;
1002 ldt
.limit_in_pages
= 1;
1003 ldt
.seg_not_present
= 0;
1005 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
1007 ldt
.entry_number
= 2;
1008 ldt
.base_addr
= (unsigned long)&seg_data2
;
1009 ldt
.limit
= (sizeof(seg_data2
) + 0xfff) >> 12;
1011 ldt
.contents
= MODIFY_LDT_CONTENTS_DATA
;
1012 ldt
.read_exec_only
= 0;
1013 ldt
.limit_in_pages
= 1;
1014 ldt
.seg_not_present
= 0;
1016 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
1018 modify_ldt(0, &ldt_table
, sizeof(ldt_table
)); /* read ldt entries */
1023 printf("%d: %016Lx\n", i
, ldt_table
[i
]);
1026 /* do some tests with fs or gs */
1027 asm volatile ("movl %0, %%fs" : : "r" (MK_SEL(1)));
1029 seg_data1
[1] = 0xaa;
1030 seg_data2
[1] = 0x55;
1032 asm volatile ("fs movzbl 0x1, %0" : "=r" (res
));
1033 printf("FS[1] = %02x\n", res
);
1035 asm volatile ("pushl %%gs\n"
1037 "gs movzbl 0x1, %0\n"
1041 printf("GS[1] = %02x\n", res
);
1043 /* tests with ds/ss (implicit segment case) */
1045 asm volatile ("pushl %%ebp\n\t"
1048 "movl %3, %%ebp\n\t"
1049 "movzbl 0x1, %0\n\t"
1050 "movzbl (%%ebp), %1\n\t"
1053 : "=r" (res
), "=r" (res2
)
1054 : "r" (MK_SEL(1)), "r" (&tmp
));
1055 printf("DS[1] = %02x\n", res
);
1056 printf("SS[tmp] = %02x\n", res2
);
1058 segoff
.seg
= MK_SEL(2);
1059 segoff
.offset
= 0xabcdef12;
1060 asm volatile("lfs %2, %0\n\t"
1062 : "=r" (res
), "=g" (res2
)
1064 printf("FS:reg = %04x:%08x\n", res2
, res
);
1066 TEST_LR("larw", "w", MK_SEL(2), 0x0100);
1067 TEST_LR("larl", "", MK_SEL(2), 0x0100);
1068 TEST_LR("lslw", "w", MK_SEL(2), 0);
1069 TEST_LR("lsll", "", MK_SEL(2), 0);
1071 TEST_LR("larw", "w", 0xfff8, 0);
1072 TEST_LR("larl", "", 0xfff8, 0);
1073 TEST_LR("lslw", "w", 0xfff8, 0);
1074 TEST_LR("lsll", "", 0xfff8, 0);
1079 /* 16 bit code test */
1080 extern char code16_start
, code16_end
;
1081 extern char code16_func1
;
1082 extern char code16_func2
;
1083 extern char code16_func3
;
1085 void test_code16(void)
1087 struct modify_ldt_ldt_s ldt
;
1090 /* build a code segment */
1091 ldt
.entry_number
= 1;
1092 ldt
.base_addr
= (unsigned long)&code16_start
;
1093 ldt
.limit
= &code16_end
- &code16_start
;
1095 ldt
.contents
= MODIFY_LDT_CONTENTS_CODE
;
1096 ldt
.read_exec_only
= 0;
1097 ldt
.limit_in_pages
= 0;
1098 ldt
.seg_not_present
= 0;
1100 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
1102 /* call the first function */
1103 asm volatile ("lcall %1, %2"
1105 : "i" (MK_SEL(1)), "i" (&code16_func1
): "memory", "cc");
1106 printf("func1() = 0x%08x\n", res
);
1107 asm volatile ("lcall %2, %3"
1108 : "=a" (res
), "=c" (res2
)
1109 : "i" (MK_SEL(1)), "i" (&code16_func2
): "memory", "cc");
1110 printf("func2() = 0x%08x spdec=%d\n", res
, res2
);
1111 asm volatile ("lcall %1, %2"
1113 : "i" (MK_SEL(1)), "i" (&code16_func3
): "memory", "cc");
1114 printf("func3() = 0x%08x\n", res
);
1118 extern char func_lret32
;
1119 extern char func_iret32
;
1121 void test_misc(void)
1128 for(i
=0;i
<256;i
++) table
[i
] = 256 - i
;
1130 asm ("xlat" : "=a" (res
) : "b" (table
), "0" (res
));
1131 printf("xlat: EAX=%08x\n", res
);
1135 asm volatile ("pushl %%cs ; call %1"
1137 : "m" (func_lret32
): "memory", "cc");
1138 printf("func_lret32=%x\n", res
);
1140 asm volatile ("pushfl ; pushl %%cs ; call %1"
1142 : "m" (func_iret32
): "memory", "cc");
1143 printf("func_iret32=%x\n", res
);
1146 /* specific popl test */
1147 asm volatile ("pushq $0x9abcdef12345678 ; popl (%%rsp) ; addq $4,%%rsp"
1149 printf("popl esp=%x\n", res
);
1153 /* specific popw test */
1154 asm volatile ("pushq $12345432 ; pushq $0x9abcdef ; popw (%%rsp) ; addl $2, %%rsp ; popq %0"
1156 printf("popw rsp=%x\n", res
);
1160 uint8_t str_buffer
[4096];
1162 #define TEST_STRING1(OP, size, DF, REP)\
1164 int64 rsi, rdi, rax, rcx, rflags;\
1166 rsi = (long)(str_buffer + sizeof(str_buffer) / 2);\
1167 rdi = (long)(str_buffer + sizeof(str_buffer) / 2) + 16;\
1171 asm volatile ("pushq $0\n\t"\
1174 REP #OP size "\n\t"\
1178 : "=S" (rsi), "=D" (rdi), "=a" (rax), "=c" (rcx), "=g" (rflags)\
1179 : "0" (rsi), "1" (rdi), "2" (rax), "3" (rcx));\
1180 printf("%-10s ESI=%016llx EDI=%016llx EAX=%016llx ECX=%016llx EFL=%04llx\n",\
1181 REP #OP size, rsi, rdi, rax, rcx,\
1182 rflags & (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A));\
1185 #define TEST_STRING(OP, REP)\
1186 TEST_STRING1(OP, "b", "", REP);\
1187 TEST_STRING1(OP, "w", "", REP);\
1188 TEST_STRING1(OP, "l", "", REP);\
1189 TEST_STRING1(OP, "b", "std", REP);\
1190 TEST_STRING1(OP, "w", "std", REP);\
1191 TEST_STRING1(OP, "l", "std", REP)
1193 void test_string(void)
1196 for(i
= 0;i
< sizeof(str_buffer
); i
++)
1197 str_buffer
[i
] = i
+ 0x56;
1198 TEST_STRING(stos
, "");
1199 TEST_STRING(stos
, "rep ");
1200 // REINSTATE: TEST_STRING(lods, ""); /* to verify stos */
1201 // REINSTATE: TEST_STRING(lods, "rep ");
1202 TEST_STRING(movs
, "");
1203 TEST_STRING(movs
, "rep ");
1204 // REINSTATE: TEST_STRING(lods, ""); /* to verify stos */
1206 /* XXX: better tests */
1207 TEST_STRING(scas
, "");
1208 // REINSTATE: TEST_STRING(scas, "repz ");
1209 TEST_STRING(scas
, "repnz ");
1210 // REINSTATE: TEST_STRING(cmps, "");
1211 TEST_STRING(cmps
, "repz ");
1212 // REINSTATE: TEST_STRING(cmps, "repnz ");
1217 static inline void set_bit(uint8_t *a
, unsigned int bit
)
1219 a
[bit
/ 8] |= (1 << (bit
% 8));
1222 static inline uint8_t *seg_to_linear(unsigned int seg
, unsigned int reg
)
1224 return (uint8_t *)((seg
<< 4) + (reg
& 0xffff));
1227 static inline void pushw(struct vm86_regs
*r
, int val
)
1229 r
->esp
= (r
->esp
& ~0xffff) | ((r
->esp
- 2) & 0xffff);
1230 *(uint16_t *)seg_to_linear(r
->ss
, r
->esp
) = val
;
1233 #undef __syscall_return
1234 #define __syscall_return(type, res) \
1236 return (type) (res); \
1239 _syscall2(int, vm86
, int, func
, struct vm86plus_struct
*, v86
)
1241 extern char vm86_code_start
;
1242 extern char vm86_code_end
;
1244 #define VM86_CODE_CS 0x100
1245 #define VM86_CODE_IP 0x100
1247 void test_vm86(void)
1249 struct vm86plus_struct ctx
;
1250 struct vm86_regs
*r
;
1254 vm86_mem
= mmap((void *)0x00000000, 0x110000,
1255 PROT_WRITE
| PROT_READ
| PROT_EXEC
,
1256 MAP_FIXED
| MAP_ANON
| MAP_PRIVATE
, -1, 0);
1257 if (vm86_mem
== MAP_FAILED
) {
1258 printf("ERROR: could not map vm86 memory");
1261 memset(&ctx
, 0, sizeof(ctx
));
1263 /* init basic registers */
1265 r
->eip
= VM86_CODE_IP
;
1274 r
->eflags
= VIF_MASK
;
1276 /* move code to proper address. We use the same layout as a .com
1278 memcpy(vm86_mem
+ (VM86_CODE_CS
<< 4) + VM86_CODE_IP
,
1279 &vm86_code_start
, &vm86_code_end
- &vm86_code_start
);
1281 /* mark int 0x21 as being emulated */
1282 set_bit((uint8_t *)&ctx
.int_revectored
, 0x21);
1285 ret
= vm86(VM86_ENTER
, &ctx
);
1286 switch(VM86_TYPE(ret
)) {
1291 int_num
= VM86_ARG(ret
);
1292 if (int_num
!= 0x21)
1294 ah
= (r
->eax
>> 8) & 0xff;
1296 case 0x00: /* exit */
1298 case 0x02: /* write char */
1304 case 0x09: /* write string */
1307 ptr
= seg_to_linear(r
->ds
, r
->edx
);
1314 r
->eax
= (r
->eax
& ~0xff) | '$';
1317 case 0xff: /* extension: write eflags number in edx */
1319 #ifndef LINUX_VM86_IOPL_FIX
1322 printf("%08x\n", v
);
1326 printf("unsupported int 0x%02x\n", int_num
);
1332 /* a signal came, we just ignore that */
1337 printf("ERROR: unhandled vm86 return code (0x%x)\n", ret
);
1342 printf("VM86 end\n");
1343 munmap(vm86_mem
, 0x110000);
1347 /* exception tests */
1360 #define REG_TRAPNO TRAPNO
1368 void sig_handler(int sig
, siginfo_t
*info
, void *puc
)
1370 struct ucontext
*uc
= puc
;
1372 printf("si_signo=%d si_errno=%d si_code=%d",
1373 info
->si_signo
, info
->si_errno
, info
->si_code
);
1374 printf(" si_addr=0x%08lx",
1375 (unsigned long)info
->si_addr
);
1378 printf("trapno=0x%02x err=0x%08x",
1379 uc
->uc_mcontext
.gregs
[REG_TRAPNO
],
1380 uc
->uc_mcontext
.gregs
[REG_ERR
]);
1381 printf(" EIP=0x%08x", uc
->uc_mcontext
.gregs
[REG_EIP
]);
1383 longjmp(jmp_env
, 1);
1386 void test_exceptions(void)
1388 struct modify_ldt_ldt_s ldt
;
1389 struct sigaction act
;
1392 act
.sa_sigaction
= sig_handler
;
1393 sigemptyset(&act
.sa_mask
);
1394 act
.sa_flags
= SA_SIGINFO
;
1395 sigaction(SIGFPE
, &act
, NULL
);
1396 sigaction(SIGILL
, &act
, NULL
);
1397 sigaction(SIGSEGV
, &act
, NULL
);
1398 sigaction(SIGBUS
, &act
, NULL
);
1399 sigaction(SIGTRAP
, &act
, NULL
);
1401 /* test division by zero reporting */
1402 printf("DIVZ exception:\n");
1403 if (setjmp(jmp_env
) == 0) {
1404 /* now divide by zero */
1409 printf("BOUND exception:\n");
1410 if (setjmp(jmp_env
) == 0) {
1411 /* bound exception */
1414 asm volatile ("bound %0, %1" : : "r" (11), "m" (tab
));
1417 printf("segment exceptions:\n");
1418 if (setjmp(jmp_env
) == 0) {
1419 /* load an invalid segment */
1420 asm volatile ("movl %0, %%fs" : : "r" ((0x1234 << 3) | 1));
1422 if (setjmp(jmp_env
) == 0) {
1423 /* null data segment is valid */
1424 asm volatile ("movl %0, %%fs" : : "r" (3));
1425 /* null stack segment */
1426 asm volatile ("movl %0, %%ss" : : "r" (3));
1429 ldt
.entry_number
= 1;
1430 ldt
.base_addr
= (unsigned long)&seg_data1
;
1431 ldt
.limit
= (sizeof(seg_data1
) + 0xfff) >> 12;
1433 ldt
.contents
= MODIFY_LDT_CONTENTS_DATA
;
1434 ldt
.read_exec_only
= 0;
1435 ldt
.limit_in_pages
= 1;
1436 ldt
.seg_not_present
= 1;
1438 modify_ldt(1, &ldt
, sizeof(ldt
)); /* write ldt entry */
1440 if (setjmp(jmp_env
) == 0) {
1441 /* segment not present */
1442 asm volatile ("movl %0, %%fs" : : "r" (MK_SEL(1)));
1445 /* test SEGV reporting */
1446 printf("PF exception:\n");
1447 if (setjmp(jmp_env
) == 0) {
1449 /* we add a nop to test a weird PC retrieval case */
1450 asm volatile ("nop");
1451 /* now store in an invalid address */
1452 *(char *)0x1234 = 1;
1455 /* test SEGV reporting */
1456 printf("PF exception:\n");
1457 if (setjmp(jmp_env
) == 0) {
1459 /* read from an invalid address */
1460 v1
= *(char *)0x1234;
1463 /* test illegal instruction reporting */
1464 printf("UD2 exception:\n");
1465 if (setjmp(jmp_env
) == 0) {
1466 /* now execute an invalid instruction */
1467 asm volatile("ud2");
1469 printf("lock nop exception:\n");
1470 if (setjmp(jmp_env
) == 0) {
1471 /* now execute an invalid instruction */
1472 asm volatile("lock nop");
1475 printf("INT exception:\n");
1476 if (setjmp(jmp_env
) == 0) {
1477 asm volatile ("int $0xfd");
1479 if (setjmp(jmp_env
) == 0) {
1480 asm volatile ("int $0x01");
1482 if (setjmp(jmp_env
) == 0) {
1483 asm volatile (".byte 0xcd, 0x03");
1485 if (setjmp(jmp_env
) == 0) {
1486 asm volatile ("int $0x04");
1488 if (setjmp(jmp_env
) == 0) {
1489 asm volatile ("int $0x05");
1492 printf("INT3 exception:\n");
1493 if (setjmp(jmp_env
) == 0) {
1494 asm volatile ("int3");
1497 printf("CLI exception:\n");
1498 if (setjmp(jmp_env
) == 0) {
1499 asm volatile ("cli");
1502 printf("STI exception:\n");
1503 if (setjmp(jmp_env
) == 0) {
1504 asm volatile ("cli");
1507 printf("INTO exception:\n");
1508 if (setjmp(jmp_env
) == 0) {
1509 /* overflow exception */
1510 asm volatile ("addl $1, %0 ; into" : : "r" (0x7fffffff));
1513 printf("OUTB exception:\n");
1514 if (setjmp(jmp_env
) == 0) {
1515 asm volatile ("outb %%al, %%dx" : : "d" (0x4321), "a" (0));
1518 printf("INB exception:\n");
1519 if (setjmp(jmp_env
) == 0) {
1520 asm volatile ("inb %%dx, %%al" : "=a" (val
) : "d" (0x4321));
1523 printf("REP OUTSB exception:\n");
1524 if (setjmp(jmp_env
) == 0) {
1525 asm volatile ("rep outsb" : : "d" (0x4321), "S" (tab
), "c" (1));
1528 printf("REP INSB exception:\n");
1529 if (setjmp(jmp_env
) == 0) {
1530 asm volatile ("rep insb" : : "d" (0x4321), "D" (tab
), "c" (1));
1533 printf("HLT exception:\n");
1534 if (setjmp(jmp_env
) == 0) {
1535 asm volatile ("hlt");
1538 printf("single step exception:\n");
1540 if (setjmp(jmp_env
) == 0) {
1541 asm volatile ("pushf\n"
1542 "orl $0x00100, (%%esp)\n"
1544 "movl $0xabcd, %0\n"
1545 "movl $0x0, %0\n" : "=m" (val
) : : "cc", "memory");
1547 printf("val=0x%x\n", val
);
1550 /* specific precise single step test */
1551 void sig_trap_handler(int sig
, siginfo_t
*info
, void *puc
)
1553 struct ucontext
*uc
= puc
;
1554 printf("EIP=0x%08x\n", uc
->uc_mcontext
.gregs
[REG_EIP
]);
1557 const uint8_t sstep_buf1
[4] = { 1, 2, 3, 4};
1558 uint8_t sstep_buf2
[4];
1560 void test_single_step(void)
1562 struct sigaction act
;
1567 act
.sa_sigaction
= sig_trap_handler
;
1568 sigemptyset(&act
.sa_mask
);
1569 act
.sa_flags
= SA_SIGINFO
;
1570 sigaction(SIGTRAP
, &act
, NULL
);
1571 asm volatile ("pushf\n"
1572 "orl $0x00100, (%%esp)\n"
1574 "movl $0xabcd, %0\n"
1583 /* movsb: the single step should stop at each movsb iteration */
1584 "movl $sstep_buf1, %%esi\n"
1585 "movl $sstep_buf2, %%edi\n"
1593 /* cmpsb: the single step should stop at each cmpsb iteration */
1594 "movl $sstep_buf1, %%esi\n"
1595 "movl $sstep_buf2, %%edi\n"
1601 /* getpid() syscall: single step should skip one
1607 /* when modifying SS, trace is not done on the next
1609 "movl %%ss, %%ecx\n"
1610 "movl %%ecx, %%ss\n"
1613 "movl %%ecx, %%ss\n"
1624 "andl $~0x00100, (%%esp)\n"
1628 : "cc", "memory", "eax", "ecx", "esi", "edi");
1629 printf("val=%d\n", val
);
1630 for(i
= 0; i
< 4; i
++)
1631 printf("sstep_buf2[%d] = %d\n", i
, sstep_buf2
[i
]);
1634 /* self modifying code test */
1636 0xb8, 0x1, 0x00, 0x00, 0x00, /* movl $1, %eax */
1641 "movl 4(%esp), %eax\n"
1642 "movl %eax, smc_patch_addr2 + 1\n"
1651 "smc_patch_addr2:\n"
1655 typedef int FuncType(void);
1656 extern int smc_code2(int);
1657 void test_self_modifying_code(void)
1661 printf("self modifying code:\n");
1662 printf("func1 = 0x%x\n", ((FuncType
*)code
)());
1663 for(i
= 2; i
<= 4; i
++) {
1665 printf("func%d = 0x%x\n", i
, ((FuncType
*)code
)());
1668 /* more difficult test : the modified code is just after the
1669 modifying instruction. It is forbidden in Intel specs, but it
1670 is used by old DOS programs */
1671 for(i
= 2; i
<= 4; i
++) {
1672 printf("smc_code2(%d) = %d\n", i
, smc_code2(i
));
1676 static void *call_end __init_call
= NULL
;
1679 int main(int argc
, char **argv
)
1685 ptr
= &call_start
+ 1;
1686 while (*ptr
!= NULL
) {
1691 test_bsx(); //REINSTATE64
1694 // test_floats(); REINSTATE64
1696 //test_xchg(); REINSTATE64
1698 //test_misc(); // REINSTATE
1703 //test_exceptions();
1704 //test_self_modifying_code();
1705 //test_single_step();