Add a test to read from all SPRs
[microwatt.git] / tests / spr_read / spr_read.c
1 #include <stddef.h>
2 #include <stdint.h>
3 #include <stdbool.h>
4
5 #include "console.h"
6
7 #define TEST "Test "
8 #define PASS "PASS\n"
9 #define FAIL "FAIL\n"
10
11 // i < 100
12 void print_test(char *str)
13 {
14 puts(TEST);
15 puts(str);
16 putchar(':');
17 }
18
19 #define SPR_XER 1
20 #define SPR_LR 8
21 #define SPR_CTR 9
22 #define SPR_TAR 815
23 #define SPR_DSISR 18
24 #define SPR_DAR 19
25 #define SPR_TB 268
26 #define SPR_TBU 269
27 #define SPR_DEC 22
28 #define SPR_SRR0 26
29 #define SPR_SRR1 27
30 #define SPR_CFAR 28
31 #define SPR_HSRR0 314
32 #define SPR_HSRR1 315
33 #define SPR_SPRG0 272
34 #define SPR_SPRG1 273
35 #define SPR_SPRG2 274
36 #define SPR_SPRG3 275
37 #define SPR_SPRG3U 259
38 #define SPR_HSPRG0 304
39 #define SPR_HSPRG1 305
40 #define SPR_PID 48
41 #define SPR_PRTBL 720
42 #define SPR_PVR 287
43
44 #define __stringify_1(x...) #x
45 #define __stringify(x...) __stringify_1(x)
46
47 int main(void)
48 {
49 unsigned long tmp;
50
51 console_init();
52
53 /*
54 * Read all SPRs. Rely on the register file raising an assertion if we
55 * write X state to a GPR.
56 */
57
58 #define DO_ONE(SPR) { \
59 print_test(#SPR); \
60 __asm__ __volatile__("mfspr %0," __stringify(SPR) : "=r" (tmp)); \
61 puts(PASS); \
62 }
63
64 DO_ONE(SPR_XER);
65 DO_ONE(SPR_LR);
66 DO_ONE(SPR_CTR);
67 DO_ONE(SPR_TAR);
68 DO_ONE(SPR_DSISR);
69 DO_ONE(SPR_DAR);
70 DO_ONE(SPR_TB);
71 DO_ONE(SPR_TBU);
72 DO_ONE(SPR_DEC);
73 DO_ONE(SPR_SRR0);
74 DO_ONE(SPR_SRR1);
75 DO_ONE(SPR_CFAR);
76 DO_ONE(SPR_HSRR0);
77 DO_ONE(SPR_HSRR1);
78 DO_ONE(SPR_SPRG0);
79 DO_ONE(SPR_SPRG1);
80 DO_ONE(SPR_SPRG2);
81 DO_ONE(SPR_SPRG3);
82 DO_ONE(SPR_SPRG3U);
83 DO_ONE(SPR_HSPRG0);
84 DO_ONE(SPR_HSPRG1);
85 DO_ONE(SPR_PID);
86 DO_ONE(SPR_PRTBL);
87 DO_ONE(SPR_PVR);
88
89 puts(PASS);
90
91 return 0;
92 }