/*-------------------------------------------------------------------
|
/*-------------------------------------------------------------------
|
-- TITLE: Plasma CPU test code
|
-- TITLE: Plasma CPU test code
|
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
|
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
|
-- DATE CREATED: 4/21/01
|
-- DATE CREATED: 4/21/01
|
-- FILENAME: test.c
|
-- FILENAME: test.c
|
-- PROJECT: Plasma CPU core
|
-- PROJECT: Plasma CPU core
|
-- COPYRIGHT: Software placed into the public domain by the author.
|
-- COPYRIGHT: Software placed into the public domain by the author.
|
-- Software 'as is' without warranty. Author liable for nothing.
|
-- Software 'as is' without warranty. Author liable for nothing.
|
-- DESCRIPTION:
|
-- DESCRIPTION:
|
-- The executable image of this file is used as input to the VHDL.
|
-- The executable image of this file is used as input to the VHDL.
|
--
|
--
|
-- This file must not contain any global or static data since
|
-- This file must not contain any global or static data since
|
-- there isn't a loader to relocate the .data segment and since
|
-- there isn't a loader to relocate the .data segment and since
|
-- having static data causes the opcodes to begin at a different
|
-- having static data causes the opcodes to begin at a different
|
-- location in the resulting executable file.
|
-- location in the resulting executable file.
|
--
|
--
|
-- Save the opcodes in "code.txt".
|
-- Save the opcodes in "code.txt".
|
--
|
--
|
-- The interrupt vector is set to address 0x30.
|
-- Testing subversion.
|
--------------------------------------------------------------------*/
|
--------------------------------------------------------------------*/
|
#ifndef WIN32
|
#ifndef WIN32
|
#undef putchar
|
#undef putchar
|
#define putchar(C) *(volatile unsigned char*)0x20000000=(unsigned char)(C)
|
#define putchar(C) *(volatile unsigned char*)0x20000000=(unsigned char)(C)
|
#endif
|
#endif
|
|
|
void print_hex(unsigned long num);
|
void print_hex(unsigned long num);
|
|
|
char text[]="Testing the Plasma core.\n";
|
char text[]="Testing the Plasma core.\n";
|
char buf[20];
|
char buf[20];
|
int xyz=0xbadbeef;
|
int xyz=0xbadbeef;
|
int abc;
|
int abc;
|
|
|
char *strcpy2(char *s, const char *t)
|
char *strcpy2(char *s, const char *t)
|
{
|
{
|
char *tmp=s;
|
char *tmp=s;
|
while((int)(*s++=*t++)) ;
|
while((int)(*s++=*t++)) ;
|
return(tmp);
|
return(tmp);
|
}
|
}
|
|
|
static void itoa2(long n, char *s, int base, long *digits)
|
static void itoa2(long n, char *s, int base, long *digits)
|
{
|
{
|
long i,j,sign;
|
long i,j,sign;
|
unsigned long n2;
|
unsigned long n2;
|
char number[20];
|
char number[20];
|
for(i=0;i<15;++i) {
|
for(i=0;i<15;++i) {
|
number[i]=' ';
|
number[i]=' ';
|
}
|
}
|
number[15]=0;
|
number[15]=0;
|
if(n>=0||base!=10) {
|
if(n>=0||base!=10) {
|
sign=1;
|
sign=1;
|
} else {
|
} else {
|
sign=-1;
|
sign=-1;
|
}
|
}
|
n2=n*sign;
|
n2=n*sign;
|
for(j=14;j>=0;--j) {
|
for(j=14;j>=0;--j) {
|
i=n2%base;
|
i=n2%base;
|
n2/=base;
|
n2/=base;
|
number[j]=i<10?'0'+i:'a'+i-10;
|
number[j]=i<10?'0'+i:'a'+i-10;
|
if(n2==0&&15-j>=*digits) break;
|
if(n2==0&&15-j>=*digits) break;
|
}
|
}
|
if(sign==-1) {
|
if(sign==-1) {
|
number[--j]='-';
|
number[--j]='-';
|
}
|
}
|
if(*digits==0||*digits<15-j) {
|
if(*digits==0||*digits<15-j) {
|
strcpy2(s,&number[j]);
|
strcpy2(s,&number[j]);
|
*digits=15-j;
|
*digits=15-j;
|
} else {
|
} else {
|
strcpy2(s,&number[15-*digits]);
|
strcpy2(s,&number[15-*digits]);
|
}
|
}
|
}
|
}
|
|
|
void print(long num,long base,long digits)
|
void print(long num,long base,long digits)
|
{
|
{
|
char *ptr,buffer[128];
|
char *ptr,buffer[128];
|
itoa2(num,buffer,base,&digits);
|
itoa2(num,buffer,base,&digits);
|
ptr=buffer;
|
ptr=buffer;
|
while(*ptr) {
|
while(*ptr) {
|
putchar(*ptr++); /* Put the character out */
|
putchar(*ptr++); /* Put the character out */
|
if(ptr[-1]=='\n') *--ptr='\r';
|
if(ptr[-1]=='\n') *--ptr='\r';
|
}
|
}
|
}
|
}
|
|
|
void print_string(char *p)
|
void print_string(char *p)
|
{
|
{
|
int i;
|
int i;
|
for(i=0;p[i];++i) {
|
for(i=0;p[i];++i) {
|
putchar(p[i]);
|
putchar(p[i]);
|
}
|
}
|
}
|
}
|
|
|
int prime()
|
int prime()
|
{
|
{
|
int i,j;
|
int i,j;
|
//show all prime numbers less than 1000
|
//show all prime numbers less than 1000
|
for(i=3;i<1000;i+=2) {
|
for(i=3;i<1000;i+=2) {
|
for(j=3;j<i;j+=2) {
|
for(j=3;j<i;j+=2) {
|
if(i%j==0) {
|
if(i%j==0) {
|
j=0;
|
j=0;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
if(j) {
|
if(j) {
|
print(i,10,0);
|
print(i,10,0);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
return 0;
|
return 0;
|
}
|
}
|
|
|
int main(void)
|
int main(void)
|
{
|
{
|
long i,j;
|
long i,j;
|
char char_buf[16];
|
char char_buf[16];
|
short short_buf[16];
|
short short_buf[16];
|
long long_buf[16];
|
long long_buf[16];
|
|
|
#if 1
|
#if 1
|
//test shift
|
//test shift
|
j=0x12345678;
|
j=0x12345678;
|
for(i=0;i<32;++i) {
|
for(i=0;i<32;++i) {
|
print_hex(j>>i);
|
print_hex(j>>i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
j=0x92345678;
|
j=0x92345678;
|
for(i=0;i<32;++i) {
|
for(i=0;i<32;++i) {
|
print_hex(j>>i);
|
print_hex(j>>i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
j=0x12345678;
|
j=0x12345678;
|
for(i=0;i<32;++i) {
|
for(i=0;i<32;++i) {
|
print_hex(j<<i);
|
print_hex(j<<i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
#endif
|
#endif
|
|
|
#if 1
|
#if 1
|
//test multiply and divide
|
//test multiply and divide
|
j=7;
|
j=7;
|
for(i=0;i<=10;++i) {
|
for(i=0;i<=10;++i) {
|
print(j*i,10,0);
|
print(j*i,10,0);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
j=0x321;
|
j=0x321;
|
for(i=0;i<=5;++i) {
|
for(i=0;i<=5;++i) {
|
print_hex(j*(i+0x12345));
|
print_hex(j*(i+0x12345));
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
j=0x54321;
|
j=0x54321;
|
for(i=0;i<=5;++i) {
|
for(i=0;i<=5;++i) {
|
print_hex(j*(i+0x123));
|
print_hex(j*(i+0x123));
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
j=0x12345;
|
j=0x12345;
|
for(i=1;i<10;++i) {
|
for(i=1;i<10;++i) {
|
print_hex(j/i);
|
print_hex(j/i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
for(i=1;i<10;++i) {
|
for(i=1;i<10;++i) {
|
print_hex(j%i);
|
print_hex(j%i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
#endif
|
#endif
|
|
|
#if 1
|
#if 1
|
//test addition and subtraction
|
//test addition and subtraction
|
j=0x1234;
|
j=0x1234;
|
for(i=0;i<10;++i) {
|
for(i=0;i<10;++i) {
|
print_hex(j+i);
|
print_hex(j+i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
for(i=0;i<10;++i) {
|
for(i=0;i<10;++i) {
|
print_hex(j-i);
|
print_hex(j-i);
|
putchar(' ');
|
putchar(' ');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
#endif
|
#endif
|
|
|
#if 1
|
#if 1
|
//test bit operations
|
//test bit operations
|
i=0x1234;
|
i=0x1234;
|
j=0x4321;
|
j=0x4321;
|
print_hex(i&j);
|
print_hex(i&j);
|
putchar(' ');
|
putchar(' ');
|
print_hex(i|j);
|
print_hex(i|j);
|
putchar(' ');
|
putchar(' ');
|
print_hex(i^j);
|
print_hex(i^j);
|
putchar(' ');
|
putchar(' ');
|
print_hex(~i);
|
print_hex(~i);
|
putchar(' ');
|
putchar(' ');
|
print_hex(i+0x12);
|
print_hex(i+0x12);
|
putchar(' ');
|
putchar(' ');
|
print_hex(i-0x12);
|
print_hex(i-0x12);
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
putchar('\n');
|
#endif
|
#endif
|
|
|
#if 1
|
#if 1
|
//test memory access
|
//test memory access
|
for(i=0;i<10;++i) {
|
for(i=0;i<10;++i) {
|
char_buf[i]=i;
|
char_buf[i]=i;
|
short_buf[i]=i;
|
short_buf[i]=i;
|
long_buf[i]=i;
|
long_buf[i]=i;
|
}
|
}
|
for(i=0;i<10;++i) {
|
for(i=0;i<10;++i) {
|
j=char_buf[i];
|
j=char_buf[i];
|
print(j,10,0);
|
print(j,10,0);
|
putchar(' ');
|
putchar(' ');
|
j=short_buf[i];
|
j=short_buf[i];
|
print(j,10,0);
|
print(j,10,0);
|
putchar(' ');
|
putchar(' ');
|
j=long_buf[i];
|
j=long_buf[i];
|
print(j,10,0);
|
print(j,10,0);
|
putchar('\n');
|
putchar('\n');
|
}
|
}
|
putchar('\n');
|
putchar('\n');
|
#endif
|
#endif
|
|
|
prime();
|
prime();
|
|
|
putchar('d'); putchar('o'); putchar('n'); putchar('e'); putchar('\n');
|
putchar('d'); putchar('o'); putchar('n'); putchar('e'); putchar('\n');
|
|
|
for(;;) ;
|
for(;;) ;
|
}
|
}
|
|
|
|
|