Home | History | Annotate | Download | only in mips32
      1 #include <stdio.h>
      2 
      3 unsigned int mem[] = {
      4    0x121f1e1f, 0, 3, -1,
      5    0x232f2e2f, 0x242c2b2b, 0x252a2e2b, 0x262d2d2a,
      6    0x3f343f3e, 0x3e353d3c, 0x363a3c3b, 0x3b373b3a,
      7    0x454f4e45, 0x4e464d46, 0x474d474c, 0x4a484a4c
      8 };
      9 
     10 unsigned int mem1[] = {
     11    0, 0, 0, 0,
     12    0, 0, 0, 0,
     13    0xffffffff, 0, 0, 0,
     14    0, 0, 0, 0
     15 };
     16 
     17 unsigned int mem2[] = {
     18 0x0000e680, 0x00010700, 0x0000e7dc, 0x0000b0d0,
     19 0x2ab05fd0, 0x0000b6a0, 0x0000be80, 0x0000de10,
     20 0x0000df20, 0x2ab05fe0, 0x0000dfd0, 0x00010300
     21 };
     22 
     23 // sb $t0, 0($t1)
     24 #define TESTINST1(instruction, RTval, offset, RT, RS) \
     25 { \
     26     unsigned int out; \
     27    __asm__ volatile( \
     28      "move $" #RS", %1\n\t" \
     29      "li $" #RT", " #RTval"\n\t" \
     30      instruction "\n\t" \
     31      "lw %0, "#offset"($"#RS")\n\t" \
     32      : "=&r" (out) \
     33 	 : "r" (mem1), "r" (RTval) \
     34 	 : #RT, "cc", "memory" \
     35 	 ); \
     36    printf("%s :: RTval: 0x%x, out: 0x%x\n", \
     37           instruction, RTval, out); \
     38    out = 0; \
     39    __asm__ volatile( \
     40      "move $" #RS", %1\n\t" \
     41      "li $" #RT", " #RTval"\n\t" \
     42      instruction "\n\t" \
     43      "lw %0, "#offset"($"#RS")\n\t" \
     44      : "=&r" (out) \
     45 	 : "r" (mem), "r" (RTval) \
     46 	 : #RT, "cc", "memory" \
     47 	 ); \
     48    printf("%s :: RTval: 0x%x, out: 0x%x\n", \
     49           instruction, RTval, out); \
     50 }
     51 
     52 // swl $t0, 3($t1)
     53 // swr $t0, 0($t1)
     54 #define TESTINSTsw(RTval, offset, RT, RS) \
     55 { \
     56     unsigned int out; \
     57    __asm__ volatile( \
     58      "move $" #RS", %1\n\t" \
     59      "addiu $"#RS", $"#RS", "#offset"\n\t" \
     60      "li $" #RT", " #RTval"\n\t" \
     61      "swl $t0, 3($t1) \n\t" \
     62      "swr $t0, 0($t1) \n\t" \
     63      "lw %0, 0($"#RS")\n\t" \
     64      : "=&r" (out) \
     65 	 : "r" (mem2), "r" (RTval) \
     66 	 : #RT, #RS, "cc", "memory" \
     67 	 ); \
     68    printf("swl $t0, 3($t1)\nswr $t0, 0($t1)\n :: RTval: 0x%x, out: 0x%x\n", \
     69           RTval, out); \
     70 }
     71 
     72 void ppMem(unsigned int* mem, int len)
     73 {
     74    int i;
     75    printf("MEM1:\n");
     76    for (i = 0; i < len; i=i+4)
     77    {
     78       printf("0x%x, 0x%x, 0x%x, 0x%x\n", mem[i], mem[i+1], mem[i+2], mem[i+3]);
     79       mem[i] = 0;
     80       mem[i+1] = 0;
     81       mem[i+2] = 0;
     82       mem[i+3] = 0;
     83       if (i == 2)
     84       {
     85          mem[i] = 0xffffffff;
     86          mem[i+1] = 0;
     87          mem[i+2] = 0;
     88          mem[i+3] = 0;
     89       }
     90    }
     91 }
     92 
     93 void ppMem1(unsigned int* mem, int len)
     94 {
     95    int i;
     96    printf("MEM:\n");
     97    for (i = 0; i < len; i=i+4)
     98    {
     99       printf("0x%x, 0x%x, 0x%x, 0x%x\n", mem[i], mem[i+1], mem[i+2], mem[i+3]);
    100    }
    101    mem[0] = 0x121f1e1f;
    102    mem[1] = 0;
    103    mem[2] = 3;
    104    mem[3] = -1;
    105    mem[4] = 0x232f2e2f;
    106    mem[5] = 0x242c2b2b;
    107    mem[6] = 0x252a2e2b;
    108    mem[7] = 0x262d2d2a;
    109    mem[8] = 0x3f343f3e;
    110    mem[9] = 0x3e353d3c;
    111    mem[10] = 0x363a3c3b;
    112    mem[11] = 0x3b373b3a;
    113    mem[12] = 0x454f4e45;
    114    mem[13] = 0x4e464d46;
    115    mem[14] = 0x474d474c;
    116    mem[15] = 0x4a484a4c;
    117 }
    118 
    119 void ppMem0(unsigned int* mem, int len)
    120 {
    121    int i;
    122    printf("MEM:\n");
    123    for (i = 0; i < len; i=i+4)
    124    {
    125       printf("0x%x, 0x%x, 0x%x, 0x%x\n", mem[i], mem[i+1], mem[i+2], mem[i+3]);
    126    }
    127 
    128    mem[0] = 0x0000e680;
    129    mem[1] = 0x00010700;
    130    mem[2] = 0x0000e7dc;
    131    mem[3] = 0x0000b0d0;
    132    mem[4] = 0x2ab05fd0;
    133    mem[5] = 0x0000b6a0;
    134    mem[6] = 0x0000be80;
    135    mem[7] = 0x0000de10;
    136    mem[8] = 0x0000df20;
    137    mem[9] = 0x2ab05fe0;
    138    mem[10] = 0x0000dfd0;
    139    mem[11] = 0x00010300;
    140 }
    141 
    142 int main()
    143 {
    144    printf("sb\n");
    145    TESTINST1("sb $t0, 3($t1)", 0, 3, t0, t1);
    146    TESTINST1("sb $t0, 5($t1)", 0x31415927, 5, t0, t1);
    147    TESTINST1("sb $t0, 7($t1)", 0x7fffffff, 7, t0, t1);
    148    TESTINST1("sb $t0, 1($t1)", 0x80000000, 1, t0, t1);
    149    TESTINST1("sb $t0, 2($t1)", 0x80000000, 2, t0, t1);
    150    TESTINST1("sb $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    151    TESTINST1("sb $t0, 11($t1)", 0x7fffffff, 11, t0, t1);
    152    TESTINST1("sb $t0, 8($t1)", -1, 8, t0, t1);
    153    TESTINST1("sb $t0, 0($t1)", 0x31415927, 0, t0, t1);
    154    TESTINST1("sb $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    155    TESTINST1("sb $t0, 0($t1)", 655, 0, t0, t1);
    156    TESTINST1("sb $t0, 0($t1)", -655, 0, t0, t1);
    157    TESTINST1("sb $t0, 0($t1)", 15, 0, t0, t1);
    158    TESTINST1("sb $t0, 0($t1)", 1, 0, t0, t1);
    159    TESTINST1("sb $t0, 0($t1)", 53, 0, t0, t1);
    160    TESTINST1("sb $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    161    TESTINST1("sb $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    162    TESTINST1("sb $t0, 31($t1)", 0xffffffff, 31, t0, t1);
    163    TESTINST1("sb $t0, 35($t1)", 0xffffffff, 35, t0, t1);
    164    TESTINST1("sb $t0, 41($t1)", 0x31415927, 41, t0, t1);
    165    TESTINST1("sb $t0, 42($t1)", 0x7fffffff, 42, t0, t1);
    166    TESTINST1("sb $t0, 45($t1)", 0x80000000, 45, t0, t1);
    167    TESTINST1("sb $t0, 51($t1)", 655, 51, t0, t1);
    168    ppMem(mem1, 16);
    169    ppMem1(mem, 16);
    170 
    171    printf("sh\n");
    172    TESTINST1("sh $t0, 1($t1)", 0, 1, t0, t1);
    173    TESTINST1("sh $t0, 3($t1)", 0x31415927, 3, t0, t1);
    174    TESTINST1("sh $t0, 5($t1)", 0x7fffffff, 5, t0, t1);
    175    TESTINST1("sh $t0, 7($t1)", 0x80000000, 7, t0, t1);
    176    TESTINST1("sh $t0, 9($t1)", 0x80000000, 9, t0, t1);
    177    TESTINST1("sh $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    178    TESTINST1("sh $t0, 11($t1)", 0x7fffffff, 11, t0, t1);
    179    TESTINST1("sh $t0, 8($t1)", -1, 8, t0, t1);
    180    TESTINST1("sh $t0, 0($t1)", 0x31415927, 0, t0, t1);
    181    TESTINST1("sh $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    182    TESTINST1("sh $t0, 0($t1)", 655, 0, t0, t1);
    183    TESTINST1("sh $t0, 0($t1)", -655, 0, t0, t1);
    184    TESTINST1("sh $t0, 0($t1)", 15, 0, t0, t1);
    185    TESTINST1("sh $t0, 0($t1)", 1, 0, t0, t1);
    186    TESTINST1("sh $t0, 0($t1)", 53, 0, t0, t1);
    187    TESTINST1("sh $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    188    TESTINST1("sh $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    189    TESTINST1("sh $t0, 31($t1)", 0xffffffff, 31, t0, t1);
    190    TESTINST1("sh $t0, 35($t1)", 0xffffffff, 35, t0, t1);
    191    TESTINST1("sh $t0, 41($t1)", 0x31415927, 41, t0, t1);
    192    TESTINST1("sh $t0, 47($t1)", 0x7fffffff, 47, t0, t1);
    193    TESTINST1("sh $t0, 49($t1)", 0x80000000, 49, t0, t1);
    194    TESTINST1("sh $t0, 51($t1)", 655, 51, t0, t1);
    195    ppMem(mem1, 16);
    196    ppMem1(mem, 16);
    197 
    198    printf("sw\n");
    199    TESTINST1("sw $t0, 1($t1)", 0, 1, t0, t1);
    200    TESTINST1("sw $t0, 3($t1)", 0x31415927, 3, t0, t1);
    201    TESTINST1("sw $t0, 5($t1)", 0x7fffffff, 5, t0, t1);
    202    TESTINST1("sw $t0, 7($t1)", 0x80000000, 7, t0, t1);
    203    TESTINST1("sw $t0, 9($t1)", 0x80000000, 9, t0, t1);
    204    TESTINST1("sw $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    205    TESTINST1("sw $t0, 15($t1)", 0x7fffffff, 11, t0, t1);
    206    TESTINST1("sw $t0, 8($t1)", -1, 8, t0, t1);
    207    TESTINST1("sw $t0, 0($t1)", 0x31415927, 0, t0, t1);
    208    TESTINST1("sw $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    209    TESTINST1("sw $t0, 0($t1)", 655, 0, t0, t1);
    210    TESTINST1("sw $t0, 0($t1)", -655, 0, t0, t1);
    211    TESTINST1("sw $t0, 0($t1)", 15, 0, t0, t1);
    212    TESTINST1("sw $t0, 0($t1)", 1, 0, t0, t1);
    213    TESTINST1("sw $t0, 0($t1)", 53, 0, t0, t1);
    214    TESTINST1("sw $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    215    TESTINST1("sw $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    216    TESTINST1("sw $t0, 31($t1)", 0xffffffff, 31, t0, t1);
    217    TESTINST1("sw $t0, 37($t1)", 0xffffffff, 37, t0, t1);
    218    TESTINST1("sw $t0, 49($t1)", 0x31415927, 49, t0, t1);
    219    TESTINST1("sw $t0, 41($t1)", 0x7fffffff, 41, t0, t1);
    220    TESTINST1("sw $t0, 43($t1)", 0x80000000, 43, t0, t1);
    221    TESTINST1("sw $t0, 51($t1)", 655, 51, t0, t1);
    222    ppMem(mem1, 16);
    223    ppMem1(mem, 16);
    224 
    225    printf("swl\n");
    226    TESTINST1("swl $t0, 1($t1)", 0, 1, t0, t1);
    227    TESTINST1("swl $t0, 3($t1)", 0x31415927, 3, t0, t1);
    228    TESTINST1("swl $t0, 5($t1)", 0x7fffffff, 5, t0, t1);
    229    TESTINST1("swl $t0, 7($t1)", 0x80000000, 7, t0, t1);
    230    TESTINST1("swl $t0, 9($t1)", 0x80000000, 9, t0, t1);
    231    TESTINST1("swl $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    232    TESTINST1("swl $t0, 11($t1)", 0x7fffffff, 11, t0, t1);
    233    TESTINST1("swl $t0, 8($t1)", -1, 8, t0, t1);
    234    TESTINST1("swl $t0, 0($t1)", 0x31415927, 0, t0, t1);
    235    TESTINST1("swl $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    236    TESTINST1("swl $t0, 0($t1)", 655, 0, t0, t1);
    237    TESTINST1("swl $t0, 0($t1)", -655, 0, t0, t1);
    238    TESTINST1("swl $t0, 0($t1)", 15, 0, t0, t1);
    239    TESTINST1("swl $t0, 0($t1)", 1, 0, t0, t1);
    240    TESTINST1("swl $t0, 0($t1)", 53, 0, t0, t1);
    241    TESTINST1("swl $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    242    TESTINST1("swl $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    243    TESTINST1("swl $t0, 33($t1)", 0xffffffff, 33, t0, t1);
    244    TESTINST1("swl $t0, 35($t1)", 0xffffffff, 35, t0, t1);
    245    TESTINST1("swl $t0, 41($t1)", 0x31415927, 41, t0, t1);
    246    TESTINST1("swl $t0, 45($t1)", 0x7fffffff, 45, t0, t1);
    247    TESTINST1("swl $t0, 49($t1)", 0x80000000, 49, t0, t1);
    248    TESTINST1("swl $t0, 51($t1)", 655, 51, t0, t1);
    249    ppMem(mem1, 16);
    250    ppMem1(mem, 16);
    251 
    252    printf("swr\n");
    253    TESTINST1("swr $t0, 1($t1)", 0, 1, t0, t1);
    254    TESTINST1("swr $t0, 3($t1)", 0x31415927, 3, t0, t1);
    255    TESTINST1("swr $t0, 5($t1)", 0x7fffffff, 5, t0, t1);
    256    TESTINST1("swr $t0, 7($t1)", 0x80000000, 7, t0, t1);
    257    TESTINST1("swr $t0, 9($t1)", 0x80000000, 9, t0, t1);
    258    TESTINST1("swr $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    259    TESTINST1("swr $t0, 11($t1)", 0x7fffffff, 11, t0, t1);
    260    TESTINST1("swr $t0, 8($t1)", -1, 8, t0, t1);
    261    TESTINST1("swr $t0, 0($t1)", 0x31415927, 0, t0, t1);
    262    TESTINST1("swr $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    263    TESTINST1("swr $t0, 0($t1)", 655, 0, t0, t1);
    264    TESTINST1("swr $t0, 0($t1)", -655, 0, t0, t1);
    265    TESTINST1("swr $t0, 0($t1)", 15, 0, t0, t1);
    266    TESTINST1("swr $t0, 0($t1)", 1, 0, t0, t1);
    267    TESTINST1("swr $t0, 0($t1)", 53, 0, t0, t1);
    268    TESTINST1("swr $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    269    TESTINST1("swr $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    270    TESTINST1("swr $t0, 31($t1)", 0xffffffff, 31, t0, t1);
    271    TESTINST1("swr $t0, 33($t1)", 0xffffffff, 33, t0, t1);
    272    TESTINST1("swr $t0, 45($t1)", 0x31415927, 45, t0, t1);
    273    TESTINST1("swr $t0, 47($t1)", 0x7fffffff, 47, t0, t1);
    274    TESTINST1("swr $t0, 49($t1)", 0x80000000, 49, t0, t1);
    275    TESTINST1("swr $t0, 51($t1)", 655, 51, t0, t1);
    276    ppMem(mem1, 16);
    277    ppMem1(mem, 16);
    278 
    279    printf("ulw\n");
    280    TESTINST1("ulw $t0, 0($t1)", 0, 0, t0, t1);
    281    TESTINST1("ulw $t0, 0($t1)", 0x31415927, 0, t0, t1);
    282    TESTINST1("ulw $t0, 0($t1)", 0x7fffffff, 0, t0, t1);
    283    TESTINST1("ulw $t0, 0($t1)", 0x80000000, 0, t0, t1);
    284    TESTINST1("ulw $t0, 2($t1)", 0x80000000, 2, t0, t1);
    285    TESTINST1("ulw $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    286    TESTINST1("ulw $t0, 10($t1)", 0x7fffffff, 10, t0, t1);
    287    TESTINST1("ulw $t0, 8($t1)", -1, 8, t0, t1);
    288    TESTINST1("ulw $t0, 0($t1)", 0x31415927, 0, t0, t1);
    289    TESTINST1("ulw $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    290    TESTINST1("ulw $t0, 0($t1)", 655, 0, t0, t1);
    291    TESTINST1("ulw $t0, 0($t1)", -655, 0, t0, t1);
    292    TESTINST1("ulw $t0, 0($t1)", 15, 0, t0, t1);
    293    TESTINST1("ulw $t0, 0($t1)", 1, 0, t0, t1);
    294    TESTINST1("ulw $t0, 0($t1)", 53, 0, t0, t1);
    295    TESTINST1("ulw $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    296    TESTINST1("ulw $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    297    TESTINST1("ulw $t0, 32($t1)", 0xffffffff, 32, t0, t1);
    298    TESTINST1("ulw $t0, 36($t1)", 0xffffffff, 36, t0, t1);
    299    TESTINST1("ulw $t0, 40($t1)", 0x31415927, 40, t0, t1);
    300    TESTINST1("ulw $t0, 44($t1)", 0x7fffffff, 44, t0, t1);
    301    TESTINST1("ulw $t0, 48($t1)", 0x80000000, 48, t0, t1);
    302    TESTINST1("ulw $t0, 52($t1)", 655, 52, t0, t1);
    303    ppMem(mem1, 16);
    304    ppMem1(mem, 16);
    305 
    306    printf("usw\n");
    307    TESTINST1("usw $t0, 0($t1)", 0, 0, t0, t1);
    308    TESTINST1("usw $t0, 0($t1)", 0x31415927, 0, t0, t1);
    309    TESTINST1("usw $t0, 0($t1)", 0x7fffffff, 0, t0, t1);
    310    TESTINST1("usw $t0, 0($t1)", 0x80000000, 0, t0, t1);
    311    TESTINST1("usw $t0, 2($t1)", 0x80000000, 2, t0, t1);
    312    TESTINST1("usw $t0, 6($t1)", 0x7fffffff, 6, t0, t1);
    313    TESTINST1("usw $t0, 10($t1)", 0x7fffffff, 10, t0, t1);
    314    TESTINST1("usw $t0, 8($t1)", -1, 8, t0, t1);
    315    TESTINST1("usw $t0, 0($t1)", 0x31415927, 0, t0, t1);
    316    TESTINST1("usw $t0, 0($t1)", 0x0dd00000, 0, t0, t1);
    317    TESTINST1("usw $t0, 0($t1)", 655, 0, t0, t1);
    318    TESTINST1("usw $t0, 0($t1)", -655, 0, t0, t1);
    319    TESTINST1("usw $t0, 0($t1)", 15, 0, t0, t1);
    320    TESTINST1("usw $t0, 0($t1)", 1, 0, t0, t1);
    321    TESTINST1("usw $t0, 0($t1)", 53, 0, t0, t1);
    322    TESTINST1("usw $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    323    TESTINST1("usw $t0, 2($t1)", 0xffffffff, 2, t0, t1);
    324    TESTINST1("usw $t0, 32($t1)", 0xffffffff, 32, t0, t1);
    325    TESTINST1("usw $t0, 36($t1)", 0xffffffff, 36, t0, t1);
    326    TESTINST1("usw $t0, 40($t1)", 0x31415927, 40, t0, t1);
    327    TESTINST1("usw $t0, 44($t1)", 0x7fffffff, 44, t0, t1);
    328    TESTINST1("usw $t0, 48($t1)", 0x80000000, 48, t0, t1);
    329    TESTINST1("usw $t0, 52($t1)", 655, 52, t0, t1);
    330    ppMem(mem1, 16);
    331    ppMem1(mem, 16);
    332 
    333    printf("swl $t0, 3($t0)\nswr $t0, 0($t0)\n");
    334    TESTINSTsw(0x4853000, 0, t0, t1);
    335    ppMem0(mem2, 12);
    336    TESTINSTsw(0x4853000, 4, t0, t1);
    337    ppMem0(mem2, 12);
    338    TESTINSTsw(0x4863700, 8, t0, t1);
    339    ppMem0(mem2, 12);
    340    TESTINSTsw(0x48aedd0, 12, t0, t1);
    341    ppMem0(mem2, 12);
    342    TESTINSTsw(0x2aaee700, 16, t0, t1);
    343    ppMem0(mem2, 12);
    344    TESTINSTsw(0x2aaee7ff, 20, t0, t1);
    345    ppMem0(mem2, 12);
    346    TESTINSTsw(0x2aaeffff, 24, t0, t1);
    347    ppMem0(mem2, 12);
    348    TESTINSTsw(0x4863700, 28, t0, t1);
    349    ppMem0(mem2, 12);
    350    TESTINSTsw(0x2aaee700, 32, t0, t1);
    351    ppMem0(mem2, 12);
    352    return 0;
    353 }
    354 
    355