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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [tools/] [test.c] - Blame information for rev 137

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

Line No. Rev Author Line
1 2 rhoads
/*-------------------------------------------------------------------
2 43 rhoads
-- TITLE: Plasma CPU test code
3 2 rhoads
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 4/21/01
5
-- FILENAME: test.c
6 43 rhoads
-- PROJECT: Plasma CPU core
7 2 rhoads
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10
--   The executable image of this file is used as input to the VHDL.
11
--
12
--   This file must not contain any global or static data since
13
--   there isn't a loader to relocate the .data segment and since
14
--   having static data causes the opcodes to begin at a different
15
--   location in the resulting executable file.
16
--
17 33 rhoads
--   Save the opcodes in "code.txt".
18 7 rhoads
--
19
--   The interrupt vector is set to address 0x30.
20 2 rhoads
--------------------------------------------------------------------*/
21 137 rhoads
#ifndef WIN32
22 2 rhoads
#undef putchar
23 137 rhoads
#define putchar(C) *(volatile unsigned char*)0x20000000=(unsigned char)(C)
24 2 rhoads
#endif
25
 
26 43 rhoads
char text[]="Testing the Plasma core.\n";
27 33 rhoads
char buf[20];
28
int xyz=0xbadbeef;
29
int abc;
30
 
31 2 rhoads
char *strcpy2(char *s, const char *t)
32
{
33
   char *tmp=s;
34 21 rhoads
   while((int)(*s++=*t++)) ;
35 2 rhoads
   return(tmp);
36
}
37
 
38
static void itoa2(long n, char *s, int base, long *digits)
39
{
40
   long i,j,sign;
41
   unsigned long n2;
42
   char number[20];
43 21 rhoads
   for(i=0;i<15;++i) {
44
      number[i]=' ';
45
   }
46 2 rhoads
   number[15]=0;
47 21 rhoads
   if(n>=0||base!=10) {
48
      sign=1;
49
   } else {
50
      sign=-1;
51
   }
52 2 rhoads
   n2=n*sign;
53
   for(j=14;j>=0;--j) {
54
      i=n2%base;
55
      n2/=base;
56
      number[j]=i<10?'0'+i:'a'+i-10;
57
      if(n2==0&&15-j>=*digits) break;
58
   }
59
   if(sign==-1) {
60
      number[--j]='-';
61
   }
62
   if(*digits==0||*digits<15-j) {
63
      strcpy2(s,&number[j]);
64
      *digits=15-j;
65
   } else {
66
      strcpy2(s,&number[15-*digits]);
67
   }
68
}
69
 
70
void print(long num,long base,long digits)
71
{
72
   char *ptr,buffer[128];
73
   itoa2(num,buffer,base,&digits);
74
   ptr=buffer;
75
   while(*ptr) {
76
      putchar(*ptr++);          /* Put the character out */
77
      if(ptr[-1]=='\n') *--ptr='\r';
78
   }
79
}
80
 
81
void print_hex(unsigned long num)
82
{
83
   long i;
84
   unsigned long j;
85
   for(i=28;i>=0;i-=4) {
86
      j=((num>>i)&0xf);
87
      if(j<10) putchar('0'+j);
88
      else putchar('a'-10+j);
89
   }
90
}
91
 
92 21 rhoads
void print_string(char *p)
93
{
94
   int i;
95 33 rhoads
   for(i=0;p[i];++i) {
96 21 rhoads
      putchar(p[i]);
97
   }
98
}
99
 
100 2 rhoads
int prime()
101
{
102 33 rhoads
   int i,j;
103 2 rhoads
   //show all prime numbers less than 1000
104
   for(i=3;i<1000;i+=2) {
105
      for(j=3;j<i;j+=2) {
106
         if(i%j==0) {
107
            j=0;
108
            break;
109
         }
110
      }
111
      if(j) {
112
         print(i,10,0);
113
         putchar(' ');
114
      }
115
   }
116
   putchar('\n');
117
   return 0;
118
}
119
 
120 137 rhoads
int main(void)
121 2 rhoads
{
122 33 rhoads
   long i,j;
123 2 rhoads
   char char_buf[16];
124
   short short_buf[16];
125
   long long_buf[16];
126 21 rhoads
 
127 6 rhoads
#if 1 
128 2 rhoads
   //test shift
129
   j=0x12345678;
130
   for(i=0;i<32;++i) {
131
      print_hex(j>>i);
132
      putchar(' ');
133
   }
134
   putchar('\n');
135
   j=0x92345678;
136
   for(i=0;i<32;++i) {
137
      print_hex(j>>i);
138
      putchar(' ');
139
   }
140
   putchar('\n');
141
   j=0x12345678;
142
   for(i=0;i<32;++i) {
143
      print_hex(j<<i);
144
      putchar(' ');
145
   }
146
   putchar('\n');
147
   putchar('\n');
148 6 rhoads
#endif
149
 
150
#if 1 
151 2 rhoads
   //test multiply and divide
152
   j=7;
153
   for(i=0;i<=10;++i) {
154
      print(j*i,10,0);
155
      putchar(' ');
156
   }
157
   putchar('\n');
158
   j=0x321;
159
   for(i=0;i<=5;++i) {
160
      print_hex(j*(i+0x12345));
161
      putchar(' ');
162
   }
163
   putchar('\n');
164
   j=0x54321;
165
   for(i=0;i<=5;++i) {
166
      print_hex(j*(i+0x123));
167
      putchar(' ');
168
   }
169
   putchar('\n');
170
   j=0x12345;
171
   for(i=1;i<10;++i) {
172
      print_hex(j/i);
173
      putchar(' ');
174
   }
175
   putchar('\n');
176
   for(i=1;i<10;++i) {
177
      print_hex(j%i);
178
      putchar(' ');
179
   }
180
   putchar('\n');
181
   putchar('\n');
182 6 rhoads
#endif
183 2 rhoads
 
184 6 rhoads
#if 1
185 2 rhoads
   //test addition and subtraction
186
   j=0x1234;
187
   for(i=0;i<10;++i) {
188
      print_hex(j+i);
189
      putchar(' ');
190
   }
191
   putchar('\n');
192
   for(i=0;i<10;++i) {
193
      print_hex(j-i);
194
      putchar(' ');
195
   }
196
   putchar('\n');
197
   putchar('\n');
198 6 rhoads
#endif
199
 
200
#if 1 
201 2 rhoads
   //test bit operations
202
   i=0x1234;
203
   j=0x4321;
204
   print_hex(i&j);
205
   putchar(' ');
206
   print_hex(i|j);
207
   putchar(' ');
208
   print_hex(i^j);
209
   putchar(' ');
210
   print_hex(~i);
211
   putchar(' ');
212
   print_hex(i+0x12);
213
   putchar(' ');
214
   print_hex(i-0x12);
215
   putchar('\n');
216
   putchar('\n');
217 6 rhoads
#endif
218
 
219
#if 1 
220 2 rhoads
   //test memory access
221
   for(i=0;i<10;++i) {
222
      char_buf[i]=i;
223
      short_buf[i]=i;
224
      long_buf[i]=i;
225
   }
226
   for(i=0;i<10;++i) {
227
      j=char_buf[i];
228
      print(j,10,0);
229
      putchar(' ');
230
      j=short_buf[i];
231
      print(j,10,0);
232
      putchar(' ');
233
      j=long_buf[i];
234
      print(j,10,0);
235
      putchar('\n');
236
   }
237
   putchar('\n');
238 6 rhoads
#endif
239 2 rhoads
 
240
   prime();
241
 
242
   putchar('d'); putchar('o'); putchar('n'); putchar('e'); putchar('\n');
243 6 rhoads
 
244
   for(;;) ;
245 2 rhoads
}
246
 

powered by: WebSVN 2.1.0

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