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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [test.c] - Blame information for rev 406

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

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

powered by: WebSVN 2.1.0

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