~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to tests/test-i386.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-07 06:20:34 UTC
  • mfrom: (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090307062034-i3pead4mw653v2el
Tags: 0.10.0-1
[ Aurelien Jarno ]
* New upstream release:
  - Fix fr-be keyboard mapping (closes: bug#514462).
  - Fix stat64 structure on ppc-linux-user (closes: bug#470231).
  - Add a chroot option (closes: bug#415996).
  - Add evdev support (closes: bug#513210).
  - Fix loop on symlinks in user mode (closes: bug#297572).
  - Bump depends on openbios-sparc.
  - Depends on openbios-ppc.
  - Update 12_signal_powerpc_support.patch.
  - Update 21_net_soopts.patch.
  - Drop 44_socklen_t_check.patch (merged upstream).
  - Drop 49_null_check.patch (merged upstream).
  - Update 64_ppc_asm_constraints.patch.
  - Drop security/CVE-2008-0928-fedora.patch (merged upstream).
  - Drop security/CVE-2007-5730.patch (merged upstream).
* patches/80_stable-branch.patch: add patches from stable branch:
  - Fix race condition between signal handler/execution loop (closes:
    bug#474386, bug#501731).
* debian/copyright: update.
* Compile and install .dtb files:
  - debian/control: build-depends on device-tree-compiler.
  - debian/patches/81_compile_dtb.patch: new patch from upstream.
  - debian/rules: compile and install bamboo.dtb and mpc8544.dtb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 *  You should have received a copy of the GNU General Public License
17
17
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *  Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
 
19
 *  MA 02110-1301, USA.
19
20
 */
20
21
#define _GNU_SOURCE
21
22
#include <stdlib.h>
30
31
#include <sys/mman.h>
31
32
 
32
33
#if !defined(__x86_64__)
33
 
#define TEST_VM86
 
34
//#define TEST_VM86
34
35
#define TEST_SEGS
35
36
#endif
36
37
//#define LINUX_VM86_IOPL_FIX
37
38
//#define TEST_P4_FLAGS
38
 
#if defined(__x86_64__)
 
39
#ifdef __SSE__
39
40
#define TEST_SSE
40
41
#define TEST_CMOV  1
41
42
#define TEST_FCOMI 1
42
43
#else
43
 
//#define TEST_SSE
44
 
#define TEST_CMOV  0
45
 
#define TEST_FCOMI 0
 
44
#undef TEST_SSE
 
45
#define TEST_CMOV  1
 
46
#define TEST_FCOMI 1
46
47
#endif
47
48
 
48
49
#if defined(__x86_64__)
457
458
    TEST_JCC("ns", 0, 0);
458
459
}
459
460
 
 
461
#define TEST_LOOP(insn) \
 
462
{\
 
463
    for(i = 0; i < sizeof(ecx_vals) / sizeof(long); i++) {\
 
464
        ecx = ecx_vals[i];\
 
465
        for(zf = 0; zf < 2; zf++) {\
 
466
    asm("test %2, %2\n\t"\
 
467
        "movl $1, %0\n\t"\
 
468
          insn " 1f\n\t" \
 
469
        "movl $0, %0\n\t"\
 
470
        "1:\n\t"\
 
471
        : "=a" (res)\
 
472
        : "c" (ecx), "b" (!zf)); \
 
473
    printf("%-10s ECX=" FMTLX " ZF=%ld r=%d\n", insn, ecx, zf, res);      \
 
474
        }\
 
475
   }\
 
476
}
 
477
 
 
478
void test_loop(void)
 
479
{
 
480
    long ecx, zf;
 
481
    const long ecx_vals[] = {
 
482
        0,
 
483
        1,
 
484
        0x10000,
 
485
        0x10001,
 
486
#if defined(__x86_64__)
 
487
        0x100000000L,
 
488
        0x100000001L,
 
489
#endif
 
490
    };
 
491
    int i, res;
 
492
 
 
493
#if !defined(__x86_64__)
 
494
    TEST_LOOP("jcxz");
 
495
    TEST_LOOP("loopw");
 
496
    TEST_LOOP("loopzw");
 
497
    TEST_LOOP("loopnzw");
 
498
#endif
 
499
 
 
500
    TEST_LOOP("jecxz");
 
501
    TEST_LOOP("loopl");
 
502
    TEST_LOOP("loopzl");
 
503
    TEST_LOOP("loopnzl");
 
504
}
 
505
 
460
506
#undef CC_MASK
461
507
#ifdef TEST_P4_FLAGS
462
508
#define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
673
719
    asm("xor %1, %1\n"\
674
720
        "mov $0x12345678, %0\n"\
675
721
        #op " %" size "2, %" size "0 ; setz %b1" \
676
 
        : "=r" (res), "=q" (resz)\
677
 
        : "g" (val));\
 
722
        : "=&r" (res), "=&q" (resz)\
 
723
        : "r" (val));\
678
724
    printf("%-10s A=" FMTLX " R=" FMTLX " %ld\n", #op, val, res, resz);\
679
725
}
680
726
 
1065
1111
    op1 = i2l(0xfbca7654);\
1066
1112
    asm(#op " %" size "0, %" size "1" \
1067
1113
        : "=q" (op0), opconst (op1) \
1068
 
        : "0" (op0), "1" (op1));\
 
1114
        : "0" (op0));\
1069
1115
    printf("%-10s A=" FMTLX " B=" FMTLX "\n",\
1070
1116
           #op, op0, op1);\
1071
1117
}
1078
1124
    op2 = i2l(eax);\
1079
1125
    asm(#op " %" size "0, %" size "1" \
1080
1126
        : "=q" (op0), opconst (op1) \
1081
 
        : "0" (op0), "1" (op1), "a" (op2));\
 
1127
        : "0" (op0), "a" (op2));\
1082
1128
    printf("%-10s EAX=" FMTLX " A=" FMTLX " C=" FMTLX "\n",\
1083
1129
           #op, op2, op0, op1);\
1084
1130
}
1086
1132
void test_xchg(void)
1087
1133
{
1088
1134
#if defined(__x86_64__)
1089
 
    TEST_XCHG(xchgq, "", "=q");
 
1135
    TEST_XCHG(xchgq, "", "+q");
1090
1136
#endif
1091
 
    TEST_XCHG(xchgl, "k", "=q");
1092
 
    TEST_XCHG(xchgw, "w", "=q");
1093
 
    TEST_XCHG(xchgb, "b", "=q");
 
1137
    TEST_XCHG(xchgl, "k", "+q");
 
1138
    TEST_XCHG(xchgw, "w", "+q");
 
1139
    TEST_XCHG(xchgb, "b", "+q");
1094
1140
 
1095
1141
#if defined(__x86_64__)
1096
1142
    TEST_XCHG(xchgq, "", "=m");
1097
1143
#endif
1098
 
    TEST_XCHG(xchgl, "k", "=m");
1099
 
    TEST_XCHG(xchgw, "w", "=m");
1100
 
    TEST_XCHG(xchgb, "b", "=m");
 
1144
    TEST_XCHG(xchgl, "k", "+m");
 
1145
    TEST_XCHG(xchgw, "w", "+m");
 
1146
    TEST_XCHG(xchgb, "b", "+m");
1101
1147
 
1102
1148
#if defined(__x86_64__)
1103
 
    TEST_XCHG(xaddq, "", "=q");
 
1149
    TEST_XCHG(xaddq, "", "+q");
1104
1150
#endif
1105
 
    TEST_XCHG(xaddl, "k", "=q");
1106
 
    TEST_XCHG(xaddw, "w", "=q");
1107
 
    TEST_XCHG(xaddb, "b", "=q");
 
1151
    TEST_XCHG(xaddl, "k", "+q");
 
1152
    TEST_XCHG(xaddw, "w", "+q");
 
1153
    TEST_XCHG(xaddb, "b", "+q");
1108
1154
 
1109
1155
    {
1110
1156
        int res;
1114
1160
    }
1115
1161
 
1116
1162
#if defined(__x86_64__)
1117
 
    TEST_XCHG(xaddq, "", "=m");
1118
 
#endif
1119
 
    TEST_XCHG(xaddl, "k", "=m");
1120
 
    TEST_XCHG(xaddw, "w", "=m");
1121
 
    TEST_XCHG(xaddb, "b", "=m");
1122
 
 
1123
 
#if defined(__x86_64__)
1124
 
    TEST_CMPXCHG(cmpxchgq, "", "=q", 0xfbca7654);
1125
 
#endif
1126
 
    TEST_CMPXCHG(cmpxchgl, "k", "=q", 0xfbca7654);
1127
 
    TEST_CMPXCHG(cmpxchgw, "w", "=q", 0xfbca7654);
1128
 
    TEST_CMPXCHG(cmpxchgb, "b", "=q", 0xfbca7654);
1129
 
 
1130
 
#if defined(__x86_64__)
1131
 
    TEST_CMPXCHG(cmpxchgq, "", "=q", 0xfffefdfc);
1132
 
#endif
1133
 
    TEST_CMPXCHG(cmpxchgl, "k", "=q", 0xfffefdfc);
1134
 
    TEST_CMPXCHG(cmpxchgw, "w", "=q", 0xfffefdfc);
1135
 
    TEST_CMPXCHG(cmpxchgb, "b", "=q", 0xfffefdfc);
1136
 
 
1137
 
#if defined(__x86_64__)
1138
 
    TEST_CMPXCHG(cmpxchgq, "", "=m", 0xfbca7654);
1139
 
#endif
1140
 
    TEST_CMPXCHG(cmpxchgl, "k", "=m", 0xfbca7654);
1141
 
    TEST_CMPXCHG(cmpxchgw, "w", "=m", 0xfbca7654);
1142
 
    TEST_CMPXCHG(cmpxchgb, "b", "=m", 0xfbca7654);
1143
 
 
1144
 
#if defined(__x86_64__)
1145
 
    TEST_CMPXCHG(cmpxchgq, "", "=m", 0xfffefdfc);
1146
 
#endif
1147
 
    TEST_CMPXCHG(cmpxchgl, "k", "=m", 0xfffefdfc);
1148
 
    TEST_CMPXCHG(cmpxchgw, "w", "=m", 0xfffefdfc);
1149
 
    TEST_CMPXCHG(cmpxchgb, "b", "=m", 0xfffefdfc);
 
1163
    TEST_XCHG(xaddq, "", "+m");
 
1164
#endif
 
1165
    TEST_XCHG(xaddl, "k", "+m");
 
1166
    TEST_XCHG(xaddw, "w", "+m");
 
1167
    TEST_XCHG(xaddb, "b", "+m");
 
1168
 
 
1169
#if defined(__x86_64__)
 
1170
    TEST_CMPXCHG(cmpxchgq, "", "+q", 0xfbca7654);
 
1171
#endif
 
1172
    TEST_CMPXCHG(cmpxchgl, "k", "+q", 0xfbca7654);
 
1173
    TEST_CMPXCHG(cmpxchgw, "w", "+q", 0xfbca7654);
 
1174
    TEST_CMPXCHG(cmpxchgb, "b", "+q", 0xfbca7654);
 
1175
 
 
1176
#if defined(__x86_64__)
 
1177
    TEST_CMPXCHG(cmpxchgq, "", "+q", 0xfffefdfc);
 
1178
#endif
 
1179
    TEST_CMPXCHG(cmpxchgl, "k", "+q", 0xfffefdfc);
 
1180
    TEST_CMPXCHG(cmpxchgw, "w", "+q", 0xfffefdfc);
 
1181
    TEST_CMPXCHG(cmpxchgb, "b", "+q", 0xfffefdfc);
 
1182
 
 
1183
#if defined(__x86_64__)
 
1184
    TEST_CMPXCHG(cmpxchgq, "", "+m", 0xfbca7654);
 
1185
#endif
 
1186
    TEST_CMPXCHG(cmpxchgl, "k", "+m", 0xfbca7654);
 
1187
    TEST_CMPXCHG(cmpxchgw, "w", "+m", 0xfbca7654);
 
1188
    TEST_CMPXCHG(cmpxchgb, "b", "+m", 0xfbca7654);
 
1189
 
 
1190
#if defined(__x86_64__)
 
1191
    TEST_CMPXCHG(cmpxchgq, "", "+m", 0xfffefdfc);
 
1192
#endif
 
1193
    TEST_CMPXCHG(cmpxchgl, "k", "+m", 0xfffefdfc);
 
1194
    TEST_CMPXCHG(cmpxchgw, "w", "+m", 0xfffefdfc);
 
1195
    TEST_CMPXCHG(cmpxchgb, "b", "+m", 0xfffefdfc);
1150
1196
 
1151
1197
    {
1152
1198
        uint64_t op0, op1, op2;
 
1199
        long eax, edx;
1153
1200
        long i, eflags;
1154
1201
 
1155
1202
        for(i = 0; i < 2; i++) {
1156
1203
            op0 = 0x123456789abcdLL;
 
1204
            eax = i2l(op0 & 0xffffffff);
 
1205
            edx = i2l(op0 >> 32);
1157
1206
            if (i == 0)
1158
1207
                op1 = 0xfbca765423456LL;
1159
1208
            else
1160
1209
                op1 = op0;
1161
1210
            op2 = 0x6532432432434LL;
1162
 
            asm("cmpxchg8b %1\n"
 
1211
            asm("cmpxchg8b %2\n"
1163
1212
                "pushf\n"
1164
 
                "pop %2\n"
1165
 
                : "=A" (op0), "=m" (op1), "=g" (eflags)
1166
 
                : "0" (op0), "m" (op1), "b" ((int)op2), "c" ((int)(op2 >> 32)));
1167
 
            printf("cmpxchg8b: op0=" FMT64X " op1=" FMT64X " CC=%02lx\n",
1168
 
                    op0, op1, eflags & CC_Z);
 
1213
                "pop %3\n"
 
1214
                : "=a" (eax), "=d" (edx), "=m" (op1), "=g" (eflags)
 
1215
                : "0" (eax), "1" (edx), "m" (op1), "b" ((int)op2), "c" ((int)(op2 >> 32)));
 
1216
            printf("cmpxchg8b: eax=" FMTLX " edx=" FMTLX " op1=" FMT64X " CC=%02lx\n",
 
1217
                   eax, edx, op1, eflags & CC_Z);
1169
1218
        }
1170
1219
    }
1171
1220
}
1196
1245
#define TEST_LR(op, size, seg, mask)\
1197
1246
{\
1198
1247
    int res, res2;\
 
1248
    uint16_t mseg = seg;\
1199
1249
    res = 0x12345678;\
1200
1250
    asm (op " %" size "2, %" size "0\n" \
1201
1251
         "movl $0, %1\n"\
1202
1252
         "jnz 1f\n"\
1203
1253
         "movl $1, %1\n"\
1204
1254
         "1:\n"\
1205
 
         : "=r" (res), "=r" (res2) : "m" (seg), "0" (res));\
 
1255
         : "=r" (res), "=r" (res2) : "m" (mseg), "0" (res));\
1206
1256
    printf(op ": Z=%d %08x\n", res2, res & ~(mask));\
1207
1257
}
1208
1258
 
 
1259
#define TEST_ARPL(op, size, op1, op2)\
 
1260
{\
 
1261
    long a, b, c;                               \
 
1262
    a = (op1);                                  \
 
1263
    b = (op2);                                  \
 
1264
    asm volatile(op " %" size "3, %" size "0\n"\
 
1265
                 "movl $0,%1\n"\
 
1266
                 "jnz 1f\n"\
 
1267
                 "movl $1,%1\n"\
 
1268
                 "1:\n"\
 
1269
                 : "=r" (a), "=r" (c) : "0" (a), "r" (b));    \
 
1270
    printf(op size " A=" FMTLX " B=" FMTLX " R=" FMTLX " z=%ld\n",\
 
1271
           (long)(op1), (long)(op2), a, c);\
 
1272
}
 
1273
 
1209
1274
/* NOTE: we use Linux modify_ldt syscall */
1210
1275
void test_segs(void)
1211
1276
{
1297
1362
    TEST_LR("larl", "", 0xfff8, 0);
1298
1363
    TEST_LR("lslw", "w", 0xfff8, 0);
1299
1364
    TEST_LR("lsll", "", 0xfff8, 0);
 
1365
 
 
1366
    TEST_ARPL("arpl", "w", 0x12345678 | 3, 0x762123c | 1);
 
1367
    TEST_ARPL("arpl", "w", 0x12345678 | 1, 0x762123c | 3);
 
1368
    TEST_ARPL("arpl", "w", 0x12345678 | 1, 0x762123c | 1);
1300
1369
}
1301
1370
 
1302
1371
/* 16 bit code test */
1369
1438
    printf("xlat: EAX=" FMTLX "\n", res);
1370
1439
 
1371
1440
#if defined(__x86_64__)
 
1441
#if 0
1372
1442
    {
 
1443
        /* XXX: see if Intel Core2 and AMD64 behavior really
 
1444
           differ. Here we implemented the Intel way which is not
 
1445
           compatible yet with QEMU. */
1373
1446
        static struct __attribute__((packed)) {
1374
 
            uint32_t offset;
 
1447
            uint64_t offset;
1375
1448
            uint16_t seg;
1376
1449
        } desc;
1377
1450
        long cs_sel;
1384
1457
                      : "r" (cs_sel) : "memory", "cc");
1385
1458
        printf("func_lret=" FMTLX "\n", res);
1386
1459
 
1387
 
        /* NOTE: we assume that &func_lret < 4GB */
1388
1460
        desc.offset = (long)&func_lret;
1389
1461
        desc.seg = cs_sel;
1390
1462
 
1391
1463
        asm volatile ("xor %%rax, %%rax\n"
1392
 
                      "rex64 lcall %1\n"
 
1464
                      "rex64 lcall *(%%rcx)\n"
1393
1465
                      : "=a" (res)
1394
 
                      : "m" (desc)
 
1466
                      : "c" (&desc)
1395
1467
                      : "memory", "cc");
1396
1468
        printf("func_lret2=" FMTLX "\n", res);
1397
1469
 
1398
1470
        asm volatile ("push %2\n"
1399
1471
                      "mov $ 1f, %%rax\n"
1400
1472
                      "push %%rax\n"
1401
 
                      "ljmp %1\n"
 
1473
                      "rex64 ljmp *(%%rcx)\n"
1402
1474
                      "1:\n"
1403
1475
                      : "=a" (res)
1404
 
                      : "m" (desc), "b" (cs_sel)
 
1476
                      : "c" (&desc), "b" (cs_sel)
1405
1477
                      : "memory", "cc");
1406
1478
        printf("func_lret3=" FMTLX "\n", res);
1407
1479
    }
 
1480
#endif
1408
1481
#else
1409
1482
    asm volatile ("push %%cs ; call %1"
1410
1483
                  : "=a" (res)
1927
2000
    0xc3, /* ret */
1928
2001
};
1929
2002
 
1930
 
asm("smc_code2:\n"
 
2003
asm(".section \".data\"\n"
 
2004
    "smc_code2:\n"
1931
2005
    "movl 4(%esp), %eax\n"
1932
2006
    "movl %eax, smc_patch_addr2 + 1\n"
1933
2007
    "nop\n"
1940
2014
    "nop\n"
1941
2015
    "smc_patch_addr2:\n"
1942
2016
    "movl $1, %eax\n"
1943
 
    "ret\n");
 
2017
    "ret\n"
 
2018
    ".previous\n"
 
2019
    );
1944
2020
 
1945
2021
typedef int FuncType(void);
1946
2022
extern int smc_code2(int);
1947
2023
void test_self_modifying_code(void)
1948
2024
{
1949
2025
    int i;
1950
 
 
1951
2026
    printf("self modifying code:\n");
1952
2027
    printf("func1 = 0x%x\n", ((FuncType *)code)());
1953
2028
    for(i = 2; i <= 4; i++) {
2029
2104
#ifdef TEST_SSE
2030
2105
 
2031
2106
typedef int __m64 __attribute__ ((__mode__ (__V2SI__)));
2032
 
typedef int __m128 __attribute__ ((__mode__(__V4SF__)));
 
2107
typedef float __m128 __attribute__ ((__mode__(__V4SF__)));
2033
2108
 
2034
2109
typedef union {
2035
2110
    double d[2];
2207
2282
#define CVT_OP_XMM2MMX(op)\
2208
2283
{\
2209
2284
    asm volatile (#op " %1, %0" : "=y" (r.q[0]) : "x" (a.dq) \
2210
 
                  : "%xmm0");\
 
2285
                  : "%xmm0"); \
 
2286
    asm volatile("emms\n"); \
2211
2287
    printf("%-9s: a=" FMT64X "" FMT64X " r=" FMT64X "\n",\
2212
2288
           #op,\
2213
2289
           a.q[1], a.q[0],\
2217
2293
#define CVT_OP_MMX2XMM(op)\
2218
2294
{\
2219
2295
    asm volatile (#op " %1, %0" : "=x" (r.dq) : "y" (a.q[0]));\
 
2296
    asm volatile("emms\n"); \
2220
2297
    printf("%-9s: a=" FMT64X " r=" FMT64X "" FMT64X "\n",\
2221
2298
           #op,\
2222
2299
           a.q[0],\
2619
2696
#if defined(__x86_64__)
2620
2697
    TEST_CONV_RAX_RDX(cqo);
2621
2698
#endif
 
2699
 
 
2700
    {
 
2701
        unsigned long a, r;
 
2702
        a = i2l(0x12345678);
 
2703
        asm volatile("bswapl %k0" : "=r" (r) : "0" (a));
 
2704
        printf("%-10s: A=" FMTLX " R=" FMTLX "\n", "bswapl", a, r);
 
2705
    }
 
2706
#if defined(__x86_64__)
 
2707
    {
 
2708
        unsigned long a, r;
 
2709
        a = i2l(0x12345678);
 
2710
        asm volatile("bswapq %0" : "=r" (r) : "0" (a));
 
2711
        printf("%-10s: A=" FMTLX " R=" FMTLX "\n", "bswapq", a, r);
 
2712
    }
 
2713
#endif
2622
2714
}
2623
2715
 
2624
2716
extern void *__start_initcall;
2638
2730
    test_bsx();
2639
2731
    test_mul();
2640
2732
    test_jcc();
 
2733
    test_loop();
2641
2734
    test_floats();
2642
2735
#if !defined(__x86_64__)
2643
2736
    test_bcd();
2653
2746
#ifdef TEST_VM86
2654
2747
    test_vm86();
2655
2748
#endif
 
2749
#if !defined(__x86_64__)
2656
2750
    test_exceptions();
2657
 
#if !defined(__x86_64__)
2658
2751
    test_self_modifying_code();
2659
2752
    test_single_step();
2660
2753
#endif