OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [sim/] [or1200-cbasic.c] - Blame information for rev 504

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 475 julius
/* Test basic c functionality, and BSS section clearing.  */
2 393 julius
#include "cpu-utils.h"
3
#include "lib-utils.h"
4 349 julius
 
5
signed long test_cond(int i)
6
{
7
        switch(i) {
8
                case 1:
9
                        i += 1;
10
                        break;
11
                case -1:
12
                        i -= 10;
13
                        break;
14
                default:
15
                        return i;
16
        }
17
 
18
        if (i == 2)             /* normaly i == 2 */
19
                i += 1;
20
        else
21
                i -= 10;
22
 
23
        if (i > 2)              /* normaly i == 3 */
24
                i += 1;
25
        else
26
                i -=10;
27
 
28
        if (i >= 4)             /* normaly i == 4 */
29
                i += 1;
30
        else
31
                i -= 10;
32
 
33
        if (i <= 5)             /* normaly i == 5 */
34
                i += 1;
35
        else
36
                i -= 10;
37
 
38
        if (i < 7)              /* normaly i == 6 */
39
                i += 1;
40
        else
41
                i -= 10;
42
 
43
        if (i != 666)           /* normaly i == 7 */
44
                i += 1;
45
        else
46
                i -= 10;
47
 
48
        return i;               /* with initial i == 1 return 8 */
49
}
50
 
51
signed long test_loops(int i)
52
{
53
        int j = 0;
54
 
55
        for(; i < 10; i++)
56
                j += 2;
57
 
58
        do {
59
                i -= 3;
60
        } while (j--);
61
 
62
        return i;
63
}
64
 
65
signed long test_arith(int i)
66
{
67
        int mul = 0, div = 0;
68
        int j;
69
 
70
        for(j = i; j < 40; j++) {
71
 
72
                mul += j*j*i;
73
#if 0
74
                report(mul);
75
#endif
76
                div += mul + (j+5);
77
#if 0
78
                report(div);
79
#endif
80
        }
81
 
82
        report (mul+div);
83
        return (mul + div);
84
}
85
 
86
signed long test_bitop(int i)
87
{
88
        int shl = 0, shr = 0, bit = 0;
89
        int j;
90
 
91
        for(j = i; j < 35; j++) {
92
                shl += 1 << j;
93
#if 0
94
                printf("%u. shl:%.8lx", j, shl);
95
                report(shl);
96
#endif
97
                shr += 0x80000000 >> j;
98
#if 0
99
                printf("  shr:%.8lx", shr);
100
                report(shr);
101
#endif
102
                bit += (~j ^ 0x11223344) & 0x33557788 + j | 0x11223344;
103
#if 0
104
                printf("  bit:%.8lx\n", bit);
105
                report(bit);
106
#endif
107
        }
108
 
109
        return (shl + shr + bit);
110
}
111
 
112
signed long test_types(int i)
113
{
114
        unsigned char uc;
115
        signed char sc;
116
        unsigned short us;
117
        signed short ss;
118
        unsigned long ul;
119
        signed long sl;
120
 
121
        int j;
122
 
123
        i ^= 0x10203040;
124
 
125
        for(j = 0; j < 10; j++) {
126
                uc = i;
127
                sc = i;
128
                us = i;
129
                ss = i;
130
                ul = i;
131
                sl = i;
132
                i = uc + sc + us + ss + ul + sl;
133
        }
134
 
135
        return i;
136
}
137
 
138
signed long test_array(int i)
139
{
140
  char a1[] = "This test string MUST NOT be modified...";
141
  char a2[100];
142
 
143
  report(a1[5]);
144
  memcpy(a2, a1, 40);
145
  report(a1[5]);
146
  report(a2[5]);
147
  report(i);
148
  /* register reload test */
149
  i += a2[0] + a2[1] + a2[2] + a2[3] + a2[4] + a2[5] + a2[6] + a2[7]
150
    + a2[8] + a2[9] + a2[10] + a2[11] + a2[12] + a2[13] + a2[14] + a2[15]
151
    + a2[16] + a2[17] + a2[18] + a2[19] + a2[20] + a2[21] + a2[22] + a2[23]
152
    + a2[24] + a2[25] + a2[26] + a2[27] + a2[28] + a2[29] + a2[30] + a2[31]
153
    + a2[32] + a2[33] + a2[34] + a2[35] + a2[36] + a2[37] + a2[38] + a2[39];
154
 
155
  report(i);
156
 
157
  return i;
158
}
159
 
160 475 julius
 
161
/* Test of BSS section being cleared at initialisation. */
162
/* BSS testing requires correct linker symbols in script*/
163
 
164
static char testchar = 0;
165
static short testshort = 0;
166
static int testint = 0;
167
static long long int testlonglong = 0;
168
 
169
#define BSS_BEGINNING _bss_start
170
#define BSS_END _bss_end
171
 
172
/* Variables that will be determined by linker script */
173
extern unsigned int BSS_BEGINNING;
174
extern unsigned int BSS_END;
175
 
176
void
177
test_bss(void)
178
{
179
  unsigned long * bss_start_pointer;
180
  unsigned long * bss_end_pointer;
181
 
182
  char * test_char_ptr;
183
  short * test_short_ptr;
184
  int * test_int_ptr;
185
  long long int * test_long_ptr;
186
 
187
  bss_start_pointer = (unsigned long*) &BSS_BEGINNING;
188
  bss_end_pointer = (unsigned long*) &BSS_END;
189
 
190
  report ((unsigned long) bss_start_pointer);
191
  report ((unsigned long) bss_end_pointer);
192
 
193
  test_char_ptr = (char*) &testchar;
194
  test_short_ptr = (short*) &testshort;
195
  test_int_ptr = (int*) &testint;
196
  test_long_ptr = (long long int*) &testlonglong;
197
 
198
  report ((unsigned long) test_char_ptr);
199
  report ((unsigned long)testchar & 0xff);
200
  if (testchar & 0xff)
201
    exit(1);
202
 
203
  report ((unsigned long) test_short_ptr);
204
  report ((unsigned long) testshort & 0xffff);
205
  if (testshort & 0xffff)
206
    exit(2);
207
 
208
  report ((unsigned long) test_int_ptr);
209
  report ((unsigned long) testint);
210
  if (testint)
211
    exit(3);
212
 
213
  report ((unsigned long) test_long_ptr);
214
  report ((unsigned long) testlonglong & 0xffffffff);
215
  report ((unsigned long) (testlonglong >> 32) & 0xffffffff);
216
  if (testlonglong & 0xffffffff)
217
    exit(4);
218
  if ((testlonglong >> 32) & 0xffffffff)
219
    exit(5);
220
 
221
  /* This should be junk (maybe Xs in RTL sim) */
222
  int uninited_int;
223
  report ((unsigned long) &uninited_int);
224
  report ((unsigned long) uninited_int);
225
 
226
  return;
227
}
228
 
229 349 julius
int main()
230
{
231
        signed long result1 = 0;
232
        signed long result2 = 0;
233
        signed long result3 = 0;
234 475 julius
        unsigned long final_result;
235 349 julius
 
236 475 julius
        test_bss();
237
 
238 349 julius
        result1 = test_cond(1);
239
        result2 = test_cond(-1);
240
        result3 -= result1 + result2;
241
        report(result2);
242
 
243
        result1 = test_loops(1);
244
        result2 = test_loops(-1);
245
        result3 -= result1 + result2;
246
        report(result2);
247
 
248
        result1 = test_arith(1);
249
        result2 = test_arith(-1);
250
        result3 -= result1 + result2;
251
        report(result2);
252
 
253
        result1 = test_bitop(1);
254
        result2 = test_bitop(-1);
255
        result3 -= result1 + result2;
256
        report(result2);
257
 
258
        result1 = test_types(1);
259
        result2 = test_types(-1);
260
        result3 -= result1 + result2;
261
        report(result2);
262
 
263
        result1 = test_array(1);
264
        result2 = test_array(-1);
265
        result3 -= result1 + result2;
266 475 julius
        report(result2);
267 349 julius
 
268 475 julius
        // Check final result
269
        final_result = (unsigned long)result3;
270
 
271
        // Should give us 0x8000000d (Gooooood)
272
        final_result += 0x3474E142;
273
 
274
        report(final_result);
275
 
276
        if (final_result == 0x8000000d)
277
          return 0;
278 425 julius
        else
279 475 julius
          return 1;
280 349 julius
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.