testbench: Add a putc(getc()) loop.
[firearm.git] / tests / testbench.c
CommitLineData
392d1bec
JW
1extern void putc(unsigned char c);
2
121556d6
JW
3int 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
392d1bec
JW
12void puts(unsigned char *s)
13{
14 while (*s)
15 putc(*(s++));
16}
17
18void 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"
35c31084 31#include "miniblarg.c"
392d1bec
JW
32
33int fact(int n)
34{
35 if (n == 0)
36 return 1;
37 else
38 return n * fact(n-1);
39}
40
41void facttest()
42{
43 if (fact(10) != 3628800)
44 puts("FAIL\n");
45 else
46 puts("PASS\n");
47}
48
49struct tests {
50 char *name;
51 void (*test)();
52};
53
54extern int ldm_bonehead();
35c31084 55
4ad5ab91 56#ifndef X86
35c31084
JW
57int shnasto()
58{
59__asm__ volatile(
392d1bec
JW
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"
35c31084
JW
75"mov r2, #0x00002F00;"
76"orr r2, r2, #0x000000E0;"
77"mov r1, #0x0000004C;"
392d1bec
JW
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);
35c31084 86}
4ad5ab91 87#endif
35c31084 88
392d1bec
JW
89void ldm_tester()
90{
4ad5ab91
JW
91#ifdef X86
92 int x = 0x00880000;
93#else
392d1bec 94 int x = ldm_bonehead();
4ad5ab91 95#endif
392d1bec
JW
96 if (x != 0x00880000)
97 {
98 puts("FAIL: result was ");
99 puthex(x);
100 puts("\n");
101 } else
102 puts("PASS\n");
103}
104
105struct tests tlist[] = {
106 {"ldm pc/mul", ldm_tester},
107 {"fact", facttest},
108 {"j4cbo", j4cbo},
109 {"ack", acktest},
35c31084 110 {"miniblarg", testmain},
392d1bec
JW
111 {"corecurse", corecurse},
112 {0, 0}};
113
114int main()
115{
116 struct tests *t;
117
118 puts("Testbench running\n");
119
120 for (t = tlist; t->name; t++)
121 {
122 puts("Running ");
123 puts(t->name);
124 puts(": ");
125 t->test();
126 }
121556d6 127 puts("Done! Echoing characters.\n");
392d1bec 128
121556d6
JW
129 while (1)
130 putc(serial_getc());
392d1bec
JW
131 return 0;
132}
This page took 0.03172 seconds and 4 git commands to generate.