Changeset 36140 in vbox for trunk/src/recompiler/tests
- Timestamp:
- Mar 3, 2011 1:48:16 PM (14 years ago)
- Location:
- trunk/src/recompiler/tests
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/recompiler/tests/Makefile
r2426 r36140 1 1 -include ../config-host.mak 2 VPATH=$(SRC_PATH)/tests 2 3 3 CFLAGS=-Wall -O2 -g 4 CFLAGS=-Wall -O2 -g -fno-strict-aliasing 4 5 #CFLAGS+=-msse2 5 6 LDFLAGS= 6 7 7 8 ifeq ($(ARCH),i386) 8 TESTS=linux-test testthread sha1-i386 test-i386 runcom9 TESTS=linux-test testthread sha1-i386 test-i386 9 10 endif 10 11 ifeq ($(ARCH),x86_64) … … 13 14 TESTS+=sha1# test_path 14 15 #TESTS+=test_path 16 #TESTS+=runcom 15 17 16 QEMU=../i386- user/qemu-i38618 QEMU=../i386-linux-user/qemu-i386 17 19 18 20 all: $(TESTS) … … 32 34 test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S \ 33 35 test-i386.h test-i386-shift.h test-i386-muldiv.h 34 $(CC) $(CFLAGS) $(LDFLAGS) -static -o $@ \35 test-i386.c test-i386-code16.Stest-i386-vm86.S -lm36 $(CC) -m32 $(CFLAGS) $(LDFLAGS) -static -o $@ \ 37 $(<D)/test-i386.c $(<D)/test-i386-code16.S $(<D)/test-i386-vm86.S -lm 36 38 37 39 test-x86_64: test-i386.c \ 38 40 test-i386.h test-i386-shift.h test-i386-muldiv.h 39 $(CC) $(CFLAGS) $(LDFLAGS) -static -o $@test-i386.c -lm41 $(CC) -m64 $(CFLAGS) $(LDFLAGS) -static -o $@ $(<D)/test-i386.c -lm 40 42 41 43 ifeq ($(ARCH),i386) … … 47 49 $(QEMU) test-i386 > test-i386.out 48 50 @if diff -u test-i386.ref test-i386.out ; then echo "Auto Test OK"; fi 49 ifeq ($(ARCH),i386) 50 $(QEMU) -no-code-copy test-i386 > test-i386.out 51 @if diff -u test-i386.ref test-i386.out ; then echo "Auto Test OK (no code copy)"; fi 52 endif 51 52 .PHONY: test-mmap 53 test-mmap: test-mmap.c 54 $(CC) $(CFLAGS) -Wall -static -O2 $(LDFLAGS) -o $@ $< 55 -./test-mmap 56 -$(QEMU) ./test-mmap 57 -$(QEMU) -p 8192 ./test-mmap 8192 58 -$(QEMU) -p 16384 ./test-mmap 16384 59 -$(QEMU) -p 32768 ./test-mmap 32768 53 60 54 61 # generic Linux and CPU test … … 83 90 arm-linux-gcc -Wall -g -O2 -c -o $@ $< 84 91 92 test-arm-iwmmxt: test-arm-iwmmxt.s 93 cpp < $< | arm-linux-gnu-gcc -Wall -static -march=iwmmxt -mabi=aapcs -x assembler - -o $@ 94 85 95 # MIPS test 86 96 hello-mips: hello-mips.c … … 90 100 mipsel-linux-gnu-gcc -nostdlib -static -mno-abicalls -fno-PIC -mabi=32 -Wall -Wextra -g -O2 -o $@ $< 91 101 92 # XXX: find a way to compile easily a test for each arch 93 test2: 94 @for arch in i386 arm armeb sparc ppc mips mipsel; do \ 95 ../$${arch}-user/qemu-$${arch} $${arch}/ls -l linux-test.c ; \ 96 done 102 # testsuite for the CRIS port. 103 test-cris: 104 $(MAKE) -C cris check 97 105 98 106 clean: -
trunk/src/recompiler/tests/qruncom.c
r33540 r36140 60 60 } 61 61 62 static void set_gate(void *ptr, unsigned int type, unsigned int dpl, 62 static void set_gate(void *ptr, unsigned int type, unsigned int dpl, 63 63 unsigned long addr, unsigned int sel) 64 64 { … … 142 142 } 143 143 144 static void host_segv_handler(int host_signum, siginfo_t *info, 144 static void host_segv_handler(int host_signum, siginfo_t *info, 145 145 void *puc) 146 146 { … … 161 161 usage(); 162 162 filename = argv[1]; 163 164 vm86_mem = mmap((void *)0x00000000, 0x110000, 165 PROT_WRITE | PROT_READ | PROT_EXEC, 163 164 vm86_mem = mmap((void *)0x00000000, 0x110000, 165 PROT_WRITE | PROT_READ | PROT_EXEC, 166 166 MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); 167 167 if (vm86_mem == MAP_FAILED) { … … 186 186 { 187 187 struct sigaction act; 188 188 189 189 sigfillset(&act.sa_mask); 190 190 act.sa_flags = SA_SIGINFO; … … 194 194 sigaction(SIGSEGV, &act, NULL); 195 195 sigaction(SIGBUS, &act, NULL); 196 #if defined (TARGET_I386) && defined(USE_CODE_COPY)197 sigaction(SIGFPE, &act, NULL);198 #endif199 196 } 200 197 201 198 // cpu_set_log(CPU_LOG_TB_IN_ASM | CPU_LOG_TB_OUT_ASM | CPU_LOG_EXEC); 202 199 203 env = cpu_init(); 204 205 /* disable code copy to simplify debugging */ 206 code_copy_enabled = 0; 200 env = cpu_init("qemu32"); 207 201 208 202 /* set user mode state (XXX: should be done automatically by … … 219 213 mode. We also activate the VM86 flag to run DOS code */ 220 214 env->eflags |= IF_MASK | VM_MASK; 221 215 222 216 /* init basic registers */ 223 217 env->eip = 0x100; … … 225 219 seg = (COM_BASE_ADDR - 0x100) >> 4; 226 220 227 cpu_x86_load_seg_cache(env, R_CS, seg, 228 (seg << 4), 0xffff, 0); 229 cpu_x86_load_seg_cache(env, R_SS, seg, 230 (seg << 4), 0xffff, 0); 231 cpu_x86_load_seg_cache(env, R_DS, seg, 232 (seg << 4), 0xffff, 0); 233 cpu_x86_load_seg_cache(env, R_ES, seg, 234 (seg << 4), 0xffff, 0); 235 cpu_x86_load_seg_cache(env, R_FS, seg, 236 (seg << 4), 0xffff, 0); 237 cpu_x86_load_seg_cache(env, R_GS, seg, 221 cpu_x86_load_seg_cache(env, R_CS, seg, 222 (seg << 4), 0xffff, 0); 223 cpu_x86_load_seg_cache(env, R_SS, seg, 224 (seg << 4), 0xffff, 0); 225 cpu_x86_load_seg_cache(env, R_DS, seg, 226 (seg << 4), 0xffff, 0); 227 cpu_x86_load_seg_cache(env, R_ES, seg, 228 (seg << 4), 0xffff, 0); 229 cpu_x86_load_seg_cache(env, R_FS, seg, 230 (seg << 4), 0xffff, 0); 231 cpu_x86_load_seg_cache(env, R_GS, seg, 238 232 (seg << 4), 0xffff, 0); 239 233 … … 261 255 set_idt(18, 0); 262 256 set_idt(19, 0); 263 257 264 258 /* put return code */ 265 259 *seg_to_linear(env->segs[R_CS].selector, 0) = 0xb4; /* mov ah, $0 */ … … 275 269 env->regs[R_EDI] = 0xfffe; 276 270 277 /* inform the emulator of the m apped memory */278 page_set_flags(0x00000000, 0x110000, 271 /* inform the emulator of the mmaped memory */ 272 page_set_flags(0x00000000, 0x110000, 279 273 PAGE_WRITE | PAGE_READ | PAGE_EXEC | PAGE_VALID); 280 274 -
trunk/src/recompiler/tests/test-i386-code16.S
r2426 r36140 8 8 9 9 .globl code16_func1 10 10 11 11 /* basic test */ 12 12 code16_func1 = . - code16_start … … 25 25 data32 lret 26 26 27 /* test various jmp opcodes */ 27 /* test various jmp opcodes */ 28 28 .globl code16_func3 29 29 code16_func3 = . - code16_start … … 37 37 add $2, %ax 38 38 2: 39 39 40 40 call myfunc 41 41 42 42 lcall $CS_SEG, $(myfunc2 - code16_start) 43 43 … … 45 45 myjmp1_next: 46 46 47 cs lcall myfunc2_addr - code16_start47 cs lcall *myfunc2_addr - code16_start 48 48 49 cs ljmp myjmp2_addr - code16_start49 cs ljmp *myjmp2_addr - code16_start 50 50 myjmp2_next: 51 51 52 52 data32 lret 53 53 54 54 myfunc2_addr: 55 55 .short myfunc2 - code16_start -
trunk/src/recompiler/tests/test-i386-shift.h
r2426 r36140 146 146 exec_opl(s2, s0, s1, 0); 147 147 #ifdef OP_SHIFTD 148 if (s1 <= 15) 149 exec_opw(s2, s0, s1, 0); 148 exec_opw(s2, s0, s1, 0); 150 149 #else 151 150 exec_opw(s2, s0, s1, 0); -
trunk/src/recompiler/tests/test-i386-vm86.S
r1 r36140 15 15 es movw $GET_OFFSET(int90_test), 0x90 * 4 16 16 es movw %cs, 0x90 * 4 + 2 17 17 18 18 /* launch int 0x90 */ 19 19 … … 25 25 int $0x21 26 26 27 pushf 27 pushf 28 28 popw %dx 29 29 movb $0xff, %ah … … 31 31 32 32 cli 33 pushf 33 pushf 34 34 popw %dx 35 35 movb $0xff, %ah 36 36 int $0x21 37 37 38 sti 39 pushfl 38 sti 39 pushfl 40 40 popl %edx 41 41 movb $0xff, %ah 42 42 int $0x21 43 43 44 44 #if 0 45 45 movw $GET_OFFSET(IF_msg1), %dx … … 55 55 #endif 56 56 57 pushf 57 pushf 58 58 popw %dx 59 59 movb $0xff, %ah 60 60 int $0x21 61 61 62 62 pushfl 63 63 movw %sp, %bx … … 74 74 75 75 int90_test: 76 pushf 76 pushf 77 77 pop %dx 78 78 movb $0xff, %ah … … 83 83 movb $0xff, %ah 84 84 int $0x21 85 85 86 86 movw $GET_OFFSET(int90_msg), %dx 87 87 movb $0x09, %ah 88 88 int $0x21 89 89 iret 90 90 91 91 int90_msg: 92 92 .string "INT90 started\n$" 93 93 94 94 hello_world: 95 95 .string "Hello VM86 world\n$" … … 102 102 103 103 vm86_code_end: 104 -
trunk/src/recompiler/tests/test-i386.c
r33656 r36140 1 1 /* 2 2 * x86 CPU test 3 * 3 * 4 4 * Copyright (c) 2003 Fabrice Bellard 5 5 * … … 41 41 42 42 #if !defined(__x86_64__) 43 #define TEST_VM8643 //#define TEST_VM86 44 44 #define TEST_SEGS 45 45 #endif 46 46 //#define LINUX_VM86_IOPL_FIX 47 47 //#define TEST_P4_FLAGS 48 #if defined(__x86_64__)48 #ifdef __SSE__ 49 49 #define TEST_SSE 50 50 #define TEST_CMOV 1 51 51 #define TEST_FCOMI 1 52 52 #else 53 //#defineTEST_SSE54 #define TEST_CMOV 055 #define TEST_FCOMI 053 #undef TEST_SSE 54 #define TEST_CMOV 1 55 #define TEST_FCOMI 1 56 56 #endif 57 57 … … 468 468 } 469 469 470 #define TEST_LOOP(insn) \ 471 {\ 472 for(i = 0; i < sizeof(ecx_vals) / sizeof(long); i++) {\ 473 ecx = ecx_vals[i];\ 474 for(zf = 0; zf < 2; zf++) {\ 475 asm("test %2, %2\n\t"\ 476 "movl $1, %0\n\t"\ 477 insn " 1f\n\t" \ 478 "movl $0, %0\n\t"\ 479 "1:\n\t"\ 480 : "=a" (res)\ 481 : "c" (ecx), "b" (!zf)); \ 482 printf("%-10s ECX=" FMTLX " ZF=%ld r=%d\n", insn, ecx, zf, res); \ 483 }\ 484 }\ 485 } 486 487 void test_loop(void) 488 { 489 long ecx, zf; 490 const long ecx_vals[] = { 491 0, 492 1, 493 0x10000, 494 0x10001, 495 #if defined(__x86_64__) 496 0x100000000L, 497 0x100000001L, 498 #endif 499 }; 500 int i, res; 501 502 #if !defined(__x86_64__) 503 TEST_LOOP("jcxz"); 504 TEST_LOOP("loopw"); 505 TEST_LOOP("loopzw"); 506 TEST_LOOP("loopnzw"); 507 #endif 508 509 TEST_LOOP("jecxz"); 510 TEST_LOOP("loopl"); 511 TEST_LOOP("loopzl"); 512 TEST_LOOP("loopnzl"); 513 } 514 470 515 #undef CC_MASK 471 516 #ifdef TEST_P4_FLAGS … … 481 526 #include "test-i386-muldiv.h" 482 527 483 void test_imulw2(long op0, long op1) 528 void test_imulw2(long op0, long op1) 484 529 { 485 530 long res, s1, s0, flags; … … 490 535 asm volatile ("push %4\n\t" 491 536 "popf\n\t" 492 "imulw %w2, %w0\n\t" 537 "imulw %w2, %w0\n\t" 493 538 "pushf\n\t" 494 539 "pop %1\n\t" … … 499 544 } 500 545 501 void test_imull2(long op0, long op1) 546 void test_imull2(long op0, long op1) 502 547 { 503 548 long res, s1, s0, flags; … … 508 553 asm volatile ("push %4\n\t" 509 554 "popf\n\t" 510 "imull %k2, %k0\n\t" 555 "imull %k2, %k0\n\t" 511 556 "pushf\n\t" 512 557 "pop %1\n\t" … … 518 563 519 564 #if defined(__x86_64__) 520 void test_imulq2(long op0, long op1) 565 void test_imulq2(long op0, long op1) 521 566 { 522 567 long res, s1, s0, flags; … … 527 572 asm volatile ("push %4\n\t" 528 573 "popf\n\t" 529 "imulq %2, %0\n\t" 574 "imulq %2, %0\n\t" 530 575 "pushf\n\t" 531 576 "pop %1\n\t" … … 684 729 "mov $0x12345678, %0\n"\ 685 730 #op " %" size "2, %" size "0 ; setz %b1" \ 686 : "= r" (res), "=q" (resz)\687 : " g" (val));\731 : "=&r" (res), "=&q" (resz)\ 732 : "r" (val));\ 688 733 printf("%-10s A=" FMTLX " R=" FMTLX " %ld\n", #op, val, res, resz);\ 689 734 } … … 714 759 }; 715 760 716 union float64u q_nan = { .l = 0xFFF8000000000000 };717 union float64u s_nan = { .l = 0xFFF0000000000000 };761 union float64u q_nan = { .l = 0xFFF8000000000000LL }; 762 union float64u s_nan = { .l = 0xFFF0000000000000LL }; 718 763 719 764 void test_fops(double a, double b) … … 750 795 long double fpregs[8]; 751 796 } float_env32; 752 797 753 798 asm volatile ("fnstenv %0\n" : : "m" (float_env32)); 754 799 float_env32.fpus &= ~0x7f; … … 769 814 : "=a" (fpus) 770 815 : "t" (a), "u" (b)); 771 printf("fcom(%f %f)=%04lx \n", 816 printf("fcom(%f %f)=%04lx \n", 772 817 a, b, fpus & (0x4500 | FPUS_EMASK)); 773 818 fpu_clear_exceptions(); … … 776 821 : "=a" (fpus) 777 822 : "t" (a), "u" (b)); 778 printf("fucom(%f %f)=%04lx\n", 823 printf("fucom(%f %f)=%04lx\n", 779 824 a, b, fpus & (0x4500 | FPUS_EMASK)); 780 825 if (TEST_FCOMI) { … … 787 832 : "=r" (eflags), "=a" (fpus) 788 833 : "t" (a), "u" (b)); 789 printf("fcomi(%f %f)=%04lx %02lx\n", 834 printf("fcomi(%f %f)=%04lx %02lx\n", 790 835 a, b, fpus & FPUS_EMASK, eflags & (CC_Z | CC_P | CC_C)); 791 836 fpu_clear_exceptions(); … … 796 841 : "=r" (eflags), "=a" (fpus) 797 842 : "t" (a), "u" (b)); 798 printf("fucomi(%f %f)=%04lx %02lx\n", 843 printf("fucomi(%f %f)=%04lx %02lx\n", 799 844 a, b, fpus & FPUS_EMASK, eflags & (CC_Z | CC_P | CC_C)); 800 845 } … … 824 869 printf("(long double)%f = %Lf\n", a, la); 825 870 printf("a=" FMT64X "\n", *(uint64_t *)&a); 826 printf("la=" FMT64X " %04x\n", *(uint64_t *)&la, 871 printf("la=" FMT64X " %04x\n", *(uint64_t *)&la, 827 872 *(unsigned short *)((char *)(&la) + 8)); 828 873 … … 830 875 asm volatile ("fstcw %0" : "=m" (fpuc)); 831 876 for(i=0;i<4;i++) { 832 asm volatile ("fldcw %0" : : "m" ((fpuc & ~0x0c00) | (i << 10))); 877 uint16_t val16; 878 val16 = (fpuc & ~0x0c00) | (i << 10); 879 asm volatile ("fldcw %0" : : "m" (val16)); 833 880 asm volatile ("fist %0" : "=m" (wa) : "t" (a)); 834 881 asm volatile ("fistl %0" : "=m" (ia) : "t" (a)); … … 866 913 asm("fbstp %0" : "=m" (bcd[0]) : "t" (a) : "st"); 867 914 asm("fbld %1" : "=t" (b) : "m" (bcd[0])); 868 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n", 915 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n", 869 916 a, bcd[4], bcd[3], bcd[2], bcd[1], bcd[0], b); 870 917 } … … 987 1034 test_fcvt(q_nan.d); 988 1035 test_fconst(); 989 test_fbcd(1234567890123456 );990 test_fbcd(-123451234567890 );1036 test_fbcd(1234567890123456.0); 1037 test_fbcd(-123451234567890.0); 991 1038 test_fenv(); 992 1039 if (TEST_CMOV) { … … 1052 1099 TEST_BCD(aaa, 0x1234040a, 0, (CC_C | CC_A)); 1053 1100 TEST_BCD(aaa, 0x123405fa, 0, (CC_C | CC_A)); 1054 1101 1055 1102 TEST_BCD(aas, 0x12340205, CC_A, (CC_C | CC_A)); 1056 1103 TEST_BCD(aas, 0x12340306, CC_A, (CC_C | CC_A)); … … 1074 1121 asm(#op " %" size "0, %" size "1" \ 1075 1122 : "=q" (op0), opconst (op1) \ 1076 : "0" (op0) , "1" (op1));\1123 : "0" (op0));\ 1077 1124 printf("%-10s A=" FMTLX " B=" FMTLX "\n",\ 1078 1125 #op, op0, op1);\ … … 1087 1134 asm(#op " %" size "0, %" size "1" \ 1088 1135 : "=q" (op0), opconst (op1) \ 1089 : "0" (op0), " 1" (op1), "a" (op2));\1136 : "0" (op0), "a" (op2));\ 1090 1137 printf("%-10s EAX=" FMTLX " A=" FMTLX " C=" FMTLX "\n",\ 1091 1138 #op, op2, op0, op1);\ … … 1095 1142 { 1096 1143 #if defined(__x86_64__) 1097 TEST_XCHG(xchgq, "", " =q");1098 #endif 1099 TEST_XCHG(xchgl, "k", " =q");1100 TEST_XCHG(xchgw, "w", " =q");1101 TEST_XCHG(xchgb, "b", " =q");1144 TEST_XCHG(xchgq, "", "+q"); 1145 #endif 1146 TEST_XCHG(xchgl, "k", "+q"); 1147 TEST_XCHG(xchgw, "w", "+q"); 1148 TEST_XCHG(xchgb, "b", "+q"); 1102 1149 1103 1150 #if defined(__x86_64__) 1104 1151 TEST_XCHG(xchgq, "", "=m"); 1105 1152 #endif 1106 TEST_XCHG(xchgl, "k", " =m");1107 TEST_XCHG(xchgw, "w", " =m");1108 TEST_XCHG(xchgb, "b", " =m");1153 TEST_XCHG(xchgl, "k", "+m"); 1154 TEST_XCHG(xchgw, "w", "+m"); 1155 TEST_XCHG(xchgb, "b", "+m"); 1109 1156 1110 1157 #if defined(__x86_64__) 1111 TEST_XCHG(xaddq, "", " =q");1112 #endif 1113 TEST_XCHG(xaddl, "k", " =q");1114 TEST_XCHG(xaddw, "w", " =q");1115 TEST_XCHG(xaddb, "b", " =q");1158 TEST_XCHG(xaddq, "", "+q"); 1159 #endif 1160 TEST_XCHG(xaddl, "k", "+q"); 1161 TEST_XCHG(xaddw, "w", "+q"); 1162 TEST_XCHG(xaddb, "b", "+q"); 1116 1163 1117 1164 { … … 1123 1170 1124 1171 #if defined(__x86_64__) 1125 TEST_XCHG(xaddq, "", " =m");1126 #endif 1127 TEST_XCHG(xaddl, "k", " =m");1128 TEST_XCHG(xaddw, "w", " =m");1129 TEST_XCHG(xaddb, "b", " =m");1172 TEST_XCHG(xaddq, "", "+m"); 1173 #endif 1174 TEST_XCHG(xaddl, "k", "+m"); 1175 TEST_XCHG(xaddw, "w", "+m"); 1176 TEST_XCHG(xaddb, "b", "+m"); 1130 1177 1131 1178 #if defined(__x86_64__) 1132 TEST_CMPXCHG(cmpxchgq, "", " =q", 0xfbca7654);1133 #endif 1134 TEST_CMPXCHG(cmpxchgl, "k", " =q", 0xfbca7654);1135 TEST_CMPXCHG(cmpxchgw, "w", " =q", 0xfbca7654);1136 TEST_CMPXCHG(cmpxchgb, "b", " =q", 0xfbca7654);1179 TEST_CMPXCHG(cmpxchgq, "", "+q", 0xfbca7654); 1180 #endif 1181 TEST_CMPXCHG(cmpxchgl, "k", "+q", 0xfbca7654); 1182 TEST_CMPXCHG(cmpxchgw, "w", "+q", 0xfbca7654); 1183 TEST_CMPXCHG(cmpxchgb, "b", "+q", 0xfbca7654); 1137 1184 1138 1185 #if defined(__x86_64__) 1139 TEST_CMPXCHG(cmpxchgq, "", " =q", 0xfffefdfc);1140 #endif 1141 TEST_CMPXCHG(cmpxchgl, "k", " =q", 0xfffefdfc);1142 TEST_CMPXCHG(cmpxchgw, "w", " =q", 0xfffefdfc);1143 TEST_CMPXCHG(cmpxchgb, "b", " =q", 0xfffefdfc);1186 TEST_CMPXCHG(cmpxchgq, "", "+q", 0xfffefdfc); 1187 #endif 1188 TEST_CMPXCHG(cmpxchgl, "k", "+q", 0xfffefdfc); 1189 TEST_CMPXCHG(cmpxchgw, "w", "+q", 0xfffefdfc); 1190 TEST_CMPXCHG(cmpxchgb, "b", "+q", 0xfffefdfc); 1144 1191 1145 1192 #if defined(__x86_64__) 1146 TEST_CMPXCHG(cmpxchgq, "", " =m", 0xfbca7654);1147 #endif 1148 TEST_CMPXCHG(cmpxchgl, "k", " =m", 0xfbca7654);1149 TEST_CMPXCHG(cmpxchgw, "w", " =m", 0xfbca7654);1150 TEST_CMPXCHG(cmpxchgb, "b", " =m", 0xfbca7654);1193 TEST_CMPXCHG(cmpxchgq, "", "+m", 0xfbca7654); 1194 #endif 1195 TEST_CMPXCHG(cmpxchgl, "k", "+m", 0xfbca7654); 1196 TEST_CMPXCHG(cmpxchgw, "w", "+m", 0xfbca7654); 1197 TEST_CMPXCHG(cmpxchgb, "b", "+m", 0xfbca7654); 1151 1198 1152 1199 #if defined(__x86_64__) 1153 TEST_CMPXCHG(cmpxchgq, "", " =m", 0xfffefdfc);1154 #endif 1155 TEST_CMPXCHG(cmpxchgl, "k", " =m", 0xfffefdfc);1156 TEST_CMPXCHG(cmpxchgw, "w", " =m", 0xfffefdfc);1157 TEST_CMPXCHG(cmpxchgb, "b", " =m", 0xfffefdfc);1200 TEST_CMPXCHG(cmpxchgq, "", "+m", 0xfffefdfc); 1201 #endif 1202 TEST_CMPXCHG(cmpxchgl, "k", "+m", 0xfffefdfc); 1203 TEST_CMPXCHG(cmpxchgw, "w", "+m", 0xfffefdfc); 1204 TEST_CMPXCHG(cmpxchgb, "b", "+m", 0xfffefdfc); 1158 1205 1159 1206 { 1160 1207 uint64_t op0, op1, op2; 1208 long eax, edx; 1161 1209 long i, eflags; 1162 1210 1163 1211 for(i = 0; i < 2; i++) { 1164 op0 = 0x123456789abcd; 1212 op0 = 0x123456789abcdLL; 1213 eax = i2l(op0 & 0xffffffff); 1214 edx = i2l(op0 >> 32); 1165 1215 if (i == 0) 1166 op1 = 0xfbca765423456 ;1216 op1 = 0xfbca765423456LL; 1167 1217 else 1168 1218 op1 = op0; 1169 op2 = 0x6532432432434 ;1170 asm("cmpxchg8b % 1\n"1219 op2 = 0x6532432432434LL; 1220 asm("cmpxchg8b %2\n" 1171 1221 "pushf\n" 1172 "pop % 2\n"1173 : "= A" (op0), "=m" (op1), "=g" (eflags)1174 : "0" ( op0), "m" (op1), "b" ((int)op2), "c" ((int)(op2 >> 32)));1175 printf("cmpxchg8b: op0=" FMT64X " op1=" FMT64X " CC=%02lx\n",1176 op0, op1, eflags & CC_Z);1222 "pop %3\n" 1223 : "=a" (eax), "=d" (edx), "=m" (op1), "=g" (eflags) 1224 : "0" (eax), "1" (edx), "m" (op1), "b" ((int)op2), "c" ((int)(op2 >> 32))); 1225 printf("cmpxchg8b: eax=" FMTLX " edx=" FMTLX " op1=" FMT64X " CC=%02lx\n", 1226 eax, edx, op1, eflags & CC_Z); 1177 1227 } 1178 1228 } … … 1183 1233 /* segmentation tests */ 1184 1234 1235 #include <sys/syscall.h> 1236 #include <unistd.h> 1185 1237 #include <asm/ldt.h> 1186 #include <linux/unistd.h>1187 1238 #include <linux/version.h> 1188 1239 1189 _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount) 1240 static inline int modify_ldt(int func, void * ptr, unsigned long bytecount) 1241 { 1242 return syscall(__NR_modify_ldt, func, ptr, bytecount); 1243 } 1190 1244 1191 1245 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 66) … … 1201 1255 {\ 1202 1256 int res, res2;\ 1257 uint16_t mseg = seg;\ 1203 1258 res = 0x12345678;\ 1204 1259 asm (op " %" size "2, %" size "0\n" \ … … 1207 1262 "movl $1, %1\n"\ 1208 1263 "1:\n"\ 1209 : "=r" (res), "=r" (res2) : "m" ( seg), "0" (res));\1264 : "=r" (res), "=r" (res2) : "m" (mseg), "0" (res));\ 1210 1265 printf(op ": Z=%d %08x\n", res2, res & ~(mask));\ 1266 } 1267 1268 #define TEST_ARPL(op, size, op1, op2)\ 1269 {\ 1270 long a, b, c; \ 1271 a = (op1); \ 1272 b = (op2); \ 1273 asm volatile(op " %" size "3, %" size "0\n"\ 1274 "movl $0,%1\n"\ 1275 "jnz 1f\n"\ 1276 "movl $1,%1\n"\ 1277 "1:\n"\ 1278 : "=r" (a), "=r" (c) : "0" (a), "r" (b)); \ 1279 printf(op size " A=" FMTLX " B=" FMTLX " R=" FMTLX " z=%ld\n",\ 1280 (long)(op1), (long)(op2), a, c);\ 1211 1281 } 1212 1282 … … 1287 1357 segoff.seg = MK_SEL(2); 1288 1358 segoff.offset = 0xabcdef12; 1289 asm volatile("lfs %2, %0\n\t" 1359 asm volatile("lfs %2, %0\n\t" 1290 1360 "movl %%fs, %1\n\t" 1291 : "=r" (res), "=g" (res2) 1361 : "=r" (res), "=g" (res2) 1292 1362 : "m" (segoff)); 1293 1363 printf("FS:reg = %04x:%08x\n", res2, res); … … 1302 1372 TEST_LR("lslw", "w", 0xfff8, 0); 1303 1373 TEST_LR("lsll", "", 0xfff8, 0); 1374 1375 TEST_ARPL("arpl", "w", 0x12345678 | 3, 0x762123c | 1); 1376 TEST_ARPL("arpl", "w", 0x12345678 | 1, 0x762123c | 3); 1377 TEST_ARPL("arpl", "w", 0x12345678 | 1, 0x762123c | 1); 1304 1378 } 1305 1379 … … 1328 1402 1329 1403 /* call the first function */ 1330 asm volatile ("lcall %1, %2" 1404 asm volatile ("lcall %1, %2" 1331 1405 : "=a" (res) 1332 1406 : "i" (MK_SEL(1)), "i" (&code16_func1): "memory", "cc"); 1333 1407 printf("func1() = 0x%08x\n", res); 1334 asm volatile ("lcall %2, %3" 1408 asm volatile ("lcall %2, %3" 1335 1409 : "=a" (res), "=c" (res2) 1336 1410 : "i" (MK_SEL(1)), "i" (&code16_func2): "memory", "cc"); 1337 1411 printf("func2() = 0x%08x spdec=%d\n", res, res2); 1338 asm volatile ("lcall %1, %2" 1412 asm volatile ("lcall %1, %2" 1339 1413 : "=a" (res) 1340 1414 : "i" (MK_SEL(1)), "i" (&code16_func3): "memory", "cc"); … … 1374 1448 1375 1449 #if defined(__x86_64__) 1450 #if 0 1376 1451 { 1452 /* XXX: see if Intel Core2 and AMD64 behavior really 1453 differ. Here we implemented the Intel way which is not 1454 compatible yet with QEMU. */ 1377 1455 static struct __attribute__((packed)) { 1378 uint 32_t offset;1456 uint64_t offset; 1379 1457 uint16_t seg; 1380 1458 } desc; … … 1384 1462 1385 1463 asm volatile ("push %1\n" 1386 "call func_lret\n" 1464 "call func_lret\n" 1387 1465 : "=a" (res) 1388 1466 : "r" (cs_sel) : "memory", "cc"); 1389 1467 printf("func_lret=" FMTLX "\n", res); 1390 1468 1391 /* NOTE: we assume that &func_lret < 4GB */1392 1469 desc.offset = (long)&func_lret; 1393 1470 desc.seg = cs_sel; 1394 1471 1395 1472 asm volatile ("xor %%rax, %%rax\n" 1396 "rex64 lcall %1\n"1473 "rex64 lcall *(%%rcx)\n" 1397 1474 : "=a" (res) 1398 : " m" (desc)1475 : "c" (&desc) 1399 1476 : "memory", "cc"); 1400 1477 printf("func_lret2=" FMTLX "\n", res); … … 1403 1480 "mov $ 1f, %%rax\n" 1404 1481 "push %%rax\n" 1405 " ljmp %1\n"1482 "rex64 ljmp *(%%rcx)\n" 1406 1483 "1:\n" 1407 1484 : "=a" (res) 1408 : " m" (desc), "b" (cs_sel)1485 : "c" (&desc), "b" (cs_sel) 1409 1486 : "memory", "cc"); 1410 1487 printf("func_lret3=" FMTLX "\n", res); 1411 1488 } 1489 #endif 1412 1490 #else 1413 asm volatile ("push %%cs ; call %1" 1491 asm volatile ("push %%cs ; call %1" 1414 1492 : "=a" (res) 1415 1493 : "m" (func_lret): "memory", "cc"); 1416 1494 printf("func_lret=" FMTLX "\n", res); 1417 1495 1418 asm volatile ("pushf ; push %%cs ; call %1" 1496 asm volatile ("pushf ; push %%cs ; call %1" 1419 1497 : "=a" (res) 1420 1498 : "m" (func_iret): "memory", "cc"); … … 1483 1561 TEST_STRING(stos, "rep "); 1484 1562 TEST_STRING(lods, ""); /* to verify stos */ 1485 TEST_STRING(lods, "rep "); 1563 TEST_STRING(lods, "rep "); 1486 1564 TEST_STRING(movs, ""); 1487 1565 TEST_STRING(movs, "rep "); … … 1516 1594 } 1517 1595 1518 #undef __syscall_return 1519 #define __syscall_return(type, res) \ 1520 do { \ 1521 return (type) (res); \ 1522 } while (0) 1523 1524 _syscall2(int, vm86, int, func, struct vm86plus_struct *, v86) 1596 static inline int vm86(int func, struct vm86plus_struct *v86) 1597 { 1598 return syscall(__NR_vm86, func, v86); 1599 } 1525 1600 1526 1601 extern char vm86_code_start; … … 1537 1612 int seg, ret; 1538 1613 1539 vm86_mem = mmap((void *)0x00000000, 0x110000, 1540 PROT_WRITE | PROT_READ | PROT_EXEC, 1614 vm86_mem = mmap((void *)0x00000000, 0x110000, 1615 PROT_WRITE | PROT_READ | PROT_EXEC, 1541 1616 MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); 1542 1617 if (vm86_mem == MAP_FAILED) { … … 1561 1636 /* move code to proper address. We use the same layout as a .com 1562 1637 dos program. */ 1563 memcpy(vm86_mem + (VM86_CODE_CS << 4) + VM86_CODE_IP, 1638 memcpy(vm86_mem + (VM86_CODE_CS << 4) + VM86_CODE_IP, 1564 1639 &vm86_code_start, &vm86_code_end - &vm86_code_start); 1565 1640 … … 1573 1648 { 1574 1649 int int_num, ah, v; 1575 1650 1576 1651 int_num = VM86_ARG(ret); 1577 1652 if (int_num != 0x21) … … 1676 1751 struct sigaction act; 1677 1752 volatile int val; 1678 1753 1679 1754 act.sa_sigaction = sig_handler; 1680 1755 sigemptyset(&act.sa_mask); … … 1729 1804 ldt.useable = 1; 1730 1805 modify_ldt(1, &ldt, sizeof(ldt)); /* write ldt entry */ 1731 1806 1732 1807 if (setjmp(jmp_env) == 0) { 1733 1808 /* segment not present */ … … 1754 1829 v1 = *(char *)0x1234; 1755 1830 } 1756 1831 1757 1832 /* test illegal instruction reporting */ 1758 1833 printf("UD2 exception:\n"); … … 1766 1841 asm volatile("lock nop"); 1767 1842 } 1768 1843 1769 1844 printf("INT exception:\n"); 1770 1845 if (setjmp(jmp_env) == 0) { … … 1838 1913 "orl $0x00100, (%%esp)\n" 1839 1914 "popf\n" 1840 "movl $0xabcd, %0\n" 1915 "movl $0xabcd, %0\n" 1841 1916 "movl $0x0, %0\n" : "=m" (val) : : "cc", "memory"); 1842 1917 } … … 1869 1944 "orl $0x00100, (%%esp)\n" 1870 1945 "popf\n" 1871 "movl $0xabcd, %0\n" 1946 "movl $0xabcd, %0\n" 1872 1947 1873 1948 /* jmp test */ … … 1895 1970 "movl $4, %%ecx\n" 1896 1971 "rep cmpsb\n" 1897 1972 1898 1973 /* getpid() syscall: single step should skip one 1899 1974 instruction */ … … 1901 1976 "int $0x80\n" 1902 1977 "movl $0, %%eax\n" 1903 1978 1904 1979 /* when modifying SS, trace is not done on the next 1905 1980 instruction */ … … 1917 1992 "addl $1, %0\n" 1918 1993 "movl $1, %%eax\n" 1919 1994 1920 1995 "pushf\n" 1921 1996 "andl $~0x00100, (%%esp)\n" 1922 1997 "popf\n" 1923 : "=m" (val) 1924 : 1998 : "=m" (val) 1999 : 1925 2000 : "cc", "memory", "eax", "ecx", "esi", "edi"); 1926 2001 printf("val=%d\n", val); … … 1935 2010 }; 1936 2011 1937 asm("smc_code2:\n" 2012 asm(".section \".data\"\n" 2013 "smc_code2:\n" 1938 2014 "movl 4(%esp), %eax\n" 1939 2015 "movl %eax, smc_patch_addr2 + 1\n" … … 1948 2024 "smc_patch_addr2:\n" 1949 2025 "movl $1, %eax\n" 1950 "ret\n"); 2026 "ret\n" 2027 ".previous\n" 2028 ); 1951 2029 1952 2030 typedef int FuncType(void); … … 1955 2033 { 1956 2034 int i; 1957 1958 2035 printf("self modifying code:\n"); 1959 2036 printf("func1 = 0x%x\n", ((FuncType *)code)()); … … 2037 2114 2038 2115 typedef int __m64 __attribute__ ((__mode__ (__V2SI__))); 2039 typedef int __m128 __attribute__ ((__mode__(__V4SF__)));2116 typedef float __m128 __attribute__ ((__mode__(__V4SF__))); 2040 2117 2041 2118 typedef union { … … 2211 2288 2212 2289 /* Force %xmm0 usage to avoid the case where both register index are 0 2213 to test in struction decoding more extensively */2290 to test intruction decoding more extensively */ 2214 2291 #define CVT_OP_XMM2MMX(op)\ 2215 2292 {\ 2216 2293 asm volatile (#op " %1, %0" : "=y" (r.q[0]) : "x" (a.dq) \ 2217 : "%xmm0");\ 2294 : "%xmm0"); \ 2295 asm volatile("emms\n"); \ 2218 2296 printf("%-9s: a=" FMT64X "" FMT64X " r=" FMT64X "\n",\ 2219 2297 #op,\ … … 2225 2303 {\ 2226 2304 asm volatile (#op " %1, %0" : "=x" (r.dq) : "y" (a.q[0]));\ 2305 asm volatile("emms\n"); \ 2227 2306 printf("%-9s: a=" FMT64X " r=" FMT64X "" FMT64X "\n",\ 2228 2307 #op,\ … … 2293 2372 " fxsave %1\n" 2294 2373 " fninit\n" 2295 : "=m" (*(uint32_t *)fp2), "=m" (*(uint32_t *)fp) 2374 : "=m" (*(uint32_t *)fp2), "=m" (*(uint32_t *)fp) 2296 2375 : "m" (a), "m" (b)); 2297 2376 printf("fpuc=%04x\n", fp->fpuc); … … 2300 2379 for(i = 0; i < 3; i++) { 2301 2380 printf("ST%d: " FMT64X " %04x\n", 2302 i, 2381 i, 2303 2382 *(uint64_t *)&fp->fpregs1[i * 16], 2304 2383 *(uint16_t *)&fp->fpregs1[i * 16 + 8]); … … 2312 2391 for(i = 0; i < nb_xmm; i++) { 2313 2392 printf("xmm%d: " FMT64X "" FMT64X "\n", 2314 i, 2393 i, 2315 2394 *(uint64_t *)&fp->xmm_regs[i * 16], 2316 2395 *(uint64_t *)&fp->xmm_regs[i * 16 + 8]); … … 2352 2431 MMX_OP2(pmulhuw); 2353 2432 MMX_OP2(pmulhw); 2354 2433 2355 2434 MMX_OP2(psubsb); 2356 2435 MMX_OP2(psubsw); … … 2391 2470 asm volatile ("pmovmskb %1, %0" : "=r" (r.l[0]) : "y" (a.q[0])); 2392 2471 printf("%-9s: r=%08x\n", "pmovmskb", r.l[0]); 2393 2472 2394 2473 asm volatile ("pmovmskb %1, %0" : "=r" (r.l[0]) : "x" (a.dq)); 2395 2474 printf("%-9s: r=%08x\n", "pmovmskb", r.l[0]); … … 2403 2482 b.q[0] = test_values[1][0]; 2404 2483 b.q[1] = test_values[1][1]; 2405 asm volatile("maskmovq %1, %0" : 2484 asm volatile("maskmovq %1, %0" : 2406 2485 : "y" (a.q[0]), "y" (b.q[0]), "D" (&r) 2407 : "memory"); 2408 printf("%-9s: r=" FMT64X " a=" FMT64X " b=" FMT64X "\n", 2409 "maskmov", 2410 r.q[0], 2411 a.q[0], 2486 : "memory"); 2487 printf("%-9s: r=" FMT64X " a=" FMT64X " b=" FMT64X "\n", 2488 "maskmov", 2489 r.q[0], 2490 a.q[0], 2412 2491 b.q[0]); 2413 asm volatile("maskmovdqu %1, %0" : 2492 asm volatile("maskmovdqu %1, %0" : 2414 2493 : "x" (a.dq), "x" (b.dq), "D" (&r) 2415 : "memory"); 2416 printf("%-9s: r=" FMT64X "" FMT64X " a=" FMT64X "" FMT64X " b=" FMT64X "" FMT64X "\n", 2417 "maskmov", 2418 r.q[1], r.q[0], 2419 a.q[1], a.q[0], 2494 : "memory"); 2495 printf("%-9s: r=" FMT64X "" FMT64X " a=" FMT64X "" FMT64X " b=" FMT64X "" FMT64X "\n", 2496 "maskmov", 2497 r.q[1], r.q[0], 2498 a.q[1], a.q[0], 2420 2499 b.q[1], b.q[0]); 2421 2500 } … … 2517 2596 SSE_OPS(cmpnle); 2518 2597 SSE_OPS(cmpord); 2519 2520 2598 2599 2521 2600 a.d[0] = 2.7; 2522 2601 a.d[1] = -3.4; … … 2594 2673 #endif 2595 2674 2675 #define TEST_CONV_RAX(op)\ 2676 {\ 2677 unsigned long a, r;\ 2678 a = i2l(0x8234a6f8);\ 2679 r = a;\ 2680 asm volatile(#op : "=a" (r) : "0" (r));\ 2681 printf("%-10s A=" FMTLX " R=" FMTLX "\n", #op, a, r);\ 2682 } 2683 2684 #define TEST_CONV_RAX_RDX(op)\ 2685 {\ 2686 unsigned long a, d, r, rh; \ 2687 a = i2l(0x8234a6f8);\ 2688 d = i2l(0x8345a1f2);\ 2689 r = a;\ 2690 rh = d;\ 2691 asm volatile(#op : "=a" (r), "=d" (rh) : "0" (r), "1" (rh)); \ 2692 printf("%-10s A=" FMTLX " R=" FMTLX ":" FMTLX "\n", #op, a, r, rh); \ 2693 } 2694 2695 void test_conv(void) 2696 { 2697 TEST_CONV_RAX(cbw); 2698 TEST_CONV_RAX(cwde); 2699 #if defined(__x86_64__) 2700 TEST_CONV_RAX(cdqe); 2701 #endif 2702 2703 TEST_CONV_RAX_RDX(cwd); 2704 TEST_CONV_RAX_RDX(cdq); 2705 #if defined(__x86_64__) 2706 TEST_CONV_RAX_RDX(cqo); 2707 #endif 2708 2709 { 2710 unsigned long a, r; 2711 a = i2l(0x12345678); 2712 asm volatile("bswapl %k0" : "=r" (r) : "0" (a)); 2713 printf("%-10s: A=" FMTLX " R=" FMTLX "\n", "bswapl", a, r); 2714 } 2715 #if defined(__x86_64__) 2716 { 2717 unsigned long a, r; 2718 a = i2l(0x12345678); 2719 asm volatile("bswapq %0" : "=r" (r) : "0" (a)); 2720 printf("%-10s: A=" FMTLX " R=" FMTLX "\n", "bswapq", a, r); 2721 } 2722 #endif 2723 } 2724 2596 2725 extern void *__start_initcall; 2597 2726 extern void *__stop_initcall; … … 2611 2740 test_mul(); 2612 2741 test_jcc(); 2742 test_loop(); 2613 2743 test_floats(); 2614 2744 #if !defined(__x86_64__) … … 2626 2756 test_vm86(); 2627 2757 #endif 2758 #if !defined(__x86_64__) 2628 2759 test_exceptions(); 2629 #if !defined(__x86_64__)2630 2760 test_self_modifying_code(); 2631 2761 test_single_step(); 2632 2762 #endif 2633 2763 test_enter(); 2764 test_conv(); 2634 2765 #ifdef TEST_SSE 2635 2766 test_sse(); -
trunk/src/recompiler/tests/test_path.c
r1 r36140 150 150 return 0; 151 151 } 152 152
Note:
See TracChangeset
for help on using the changeset viewer.