Add support for CellularRAM on Nexys2.
[firearm.git] / tests / testbench.c
1 extern void putc(unsigned char c);
2
3 int serial_getc (void)
4 {
5         int c;
6         do
7                 asm volatile("mrc 5, 0, %0, c1, c1, 1" : "=r"(c));
8         while (!(c & 0x100));
9         return c & 0xFF;
10 }
11
12 void puts(unsigned char *s)
13 {
14         while (*s)
15                 putc(*(s++));
16 }
17
18 void puthex(unsigned int x)
19 {
20         unsigned char *hex = "0123456789ABCDEF";
21         int i;
22         
23         for (i = 7; i >= 0; i--)
24                 putc(hex[(x >> (i * 4)) & 0xF]);
25 }
26
27 #define putchar putc
28 #include "ack.c"
29 #include "j4cbo.c"
30 #include "corecurse.c"
31 #include "miniblarg.c"
32
33 int fact(int n)
34 {
35         if (n == 0)
36                 return 1;
37         else
38                 return n * fact(n-1);
39 }
40
41 void facttest()
42 {
43         if (fact(10) != 3628800)
44                 puts("FAIL\n");
45         else
46                 puts("PASS\n");
47 }
48
49 struct tests {
50         char *name;
51         void (*test)();
52 };
53
54 extern int ldm_bonehead();
55
56 #ifndef X86
57 int shnasto()
58 {
59 __asm__ volatile(
60 ".globl ldm_bonehead\n"
61 "ldm_bonehead:;"
62 "mov r3, lr;"
63 "bl 1f;"
64 "nop;"
65 "nop;"
66 "nop;"
67 "nop;"
68 "nop;"
69 "nop;"
70 "nop;"
71 "nop;"
72 "nop;"
73 "mov pc, r3\n;"
74 "1:\n"
75 "mov r2, #0x00002F00;"
76 "orr r2, r2, #0x000000E0;"
77 "mov r1, #0x0000004C;"
78 "mov ip, sp;"
79 "stmdb sp!, {fp, ip, lr, pc};"
80 "mov r0, #0x00880000;"
81 "ldmia sp, {fp, sp, pc};"
82 "mul r0, r1, r2;"
83 "nop;"
84 "nop;\n"
85 );
86 }
87 #endif
88
89 void ldm_tester()
90 {
91 #ifdef X86
92         int x = 0x00880000;
93 #else
94         int x = ldm_bonehead();
95 #endif
96         if (x != 0x00880000)
97         {
98                 puts("FAIL: result was ");
99                 puthex(x);
100                 puts("\n");
101         } else
102                 puts("PASS\n");
103 }
104
105 void cellularram()
106 {
107         volatile int *p = 0x80010000;
108         
109         puts("[writing] ");
110         p[0] = 0x12345678;
111         p[1] = 0x87654321;
112         p[2] = 0xAAAA5555;
113         p[3] = 0x5555AAAA;
114         puts("[cache flush] ");
115         p[0x1000] = 0x00000000;
116         puts("[reading: ");
117         puthex(p[0]);
118         puthex(p[1]);
119         puthex(p[2]);
120         puthex(p[3]);
121         puts("]\n");
122 }
123
124 struct tests tlist[] = {
125         {"ldm pc/mul", ldm_tester},
126         {"fact", facttest},
127         {"j4cbo", j4cbo},
128         {"cellularram", cellularram},
129         {"ack", acktest},
130         {"miniblarg", testmain},
131         {"corecurse", corecurse},
132         {0, 0}};
133
134 int main()
135 {
136         struct tests *t;
137         
138         puts("Testbench running\n");
139         
140         for (t = tlist; t->name; t++)
141         {
142                 puts("Running ");
143                 puts(t->name);
144                 puts(": ");
145                 t->test();
146         }
147         puts("Done! Echoing characters.\n");
148         
149         while (1)
150                 putc(serial_getc());
151         return 0;
152 }
This page took 0.027738 seconds and 4 git commands to generate.