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