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