tests/miniblarg: Make the ROM easier to read.
[firearm.git] / tests / testbench.c
CommitLineData
392d1bec
JW
1extern void putc(unsigned char c);
2
3void puts(unsigned char *s)
4{
5 while (*s)
6 putc(*(s++));
7}
8
9void puthex(unsigned int x)
10{
11 unsigned char *hex = "0123456789ABCDEF";
12 int i;
13
14 for (i = 7; i >= 0; i--)
15 putc(hex[(x >> (i * 4)) & 0xF]);
16}
17
18#define putchar putc
19#include "ack.c"
20#include "j4cbo.c"
21#include "corecurse.c"
35c31084 22#include "miniblarg.c"
392d1bec
JW
23
24int fact(int n)
25{
26 if (n == 0)
27 return 1;
28 else
29 return n * fact(n-1);
30}
31
32void facttest()
33{
34 if (fact(10) != 3628800)
35 puts("FAIL\n");
36 else
37 puts("PASS\n");
38}
39
40struct tests {
41 char *name;
42 void (*test)();
43};
44
45extern int ldm_bonehead();
35c31084 46
4ad5ab91 47#ifndef X86
35c31084
JW
48int shnasto()
49{
50__asm__ volatile(
392d1bec
JW
51".globl ldm_bonehead\n"
52"ldm_bonehead:;"
53"mov r3, lr;"
54"bl 1f;"
55"nop;"
56"nop;"
57"nop;"
58"nop;"
59"nop;"
60"nop;"
61"nop;"
62"nop;"
63"nop;"
64"mov pc, r3\n;"
65"1:\n"
35c31084
JW
66"mov r2, #0x00002F00;"
67"orr r2, r2, #0x000000E0;"
68"mov r1, #0x0000004C;"
392d1bec
JW
69"mov ip, sp;"
70"stmdb sp!, {fp, ip, lr, pc};"
71"mov r0, #0x00880000;"
72"ldmia sp, {fp, sp, pc};"
73"mul r0, r1, r2;"
74"nop;"
75"nop;\n"
76);
35c31084 77}
4ad5ab91 78#endif
35c31084 79
392d1bec
JW
80void ldm_tester()
81{
4ad5ab91
JW
82#ifdef X86
83 int x = 0x00880000;
84#else
392d1bec 85 int x = ldm_bonehead();
4ad5ab91 86#endif
392d1bec
JW
87 if (x != 0x00880000)
88 {
89 puts("FAIL: result was ");
90 puthex(x);
91 puts("\n");
92 } else
93 puts("PASS\n");
94}
95
96struct tests tlist[] = {
97 {"ldm pc/mul", ldm_tester},
98 {"fact", facttest},
99 {"j4cbo", j4cbo},
100 {"ack", acktest},
35c31084 101 {"miniblarg", testmain},
392d1bec
JW
102 {"corecurse", corecurse},
103 {0, 0}};
104
105int main()
106{
107 struct tests *t;
108
109 puts("Testbench running\n");
110
111 for (t = tlist; t->name; t++)
112 {
113 puts("Running ");
114 puts(t->name);
115 puts(": ");
116 t->test();
117 }
118 puts("Done!\n");
119
120 return 0;
121}
This page took 0.066205 seconds and 4 git commands to generate.