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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [test.c] - Rev 33

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

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

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

powered by: WebSVN 2.1.0

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