add op_lidstate
[pandora-misc.git] / tests / test_a8debug.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <sys/mman.h>
7 #include <unistd.h>
8
9 static void handle_v4(void)
10 {
11 }
12
13 static void handle_unknown(void)
14 {
15 }
16
17 static void (*handlers[16])(void) = {
18         [4] = handle_v4,
19 };
20
21 // XXX: LPAE?
22 static void dump_mem_registers(unsigned int address)
23 {
24         unsigned int *regs;
25         int fd;
26
27         fd = open("/dev/mem", O_RDONLY | O_SYNC);
28         if (fd == -1) {
29                 perror("open(/dev/mem)");
30                 return;
31         }
32
33         regs = mmap(NULL, 0x1000, PROT_READ, MAP_SHARED, fd, address);
34         if (regs == MAP_FAILED) {
35                 perror("mmap");
36                 close(fd);
37                 return;
38         }
39
40         printf("\nmemory mapped registers:\n");
41         printf("DIDR:       %08x\n", regs[0]);
42         printf("AUTHSTATUS: %08x\n", regs[1006]);
43         printf("DEVID:      %08x\n", regs[1010]);
44
45         munmap(regs, 0x1000);
46         close(fd);
47 }
48
49 int main(int argc, char *argv[])
50 {
51         unsigned int didr = 0, drar = 0, dsar = 0, dscr = 0;
52         unsigned int i, arch_version;
53
54         asm ("mrc p14, 0, %0, c0, c0, 0" : "=r"(didr));
55         asm ("mrc p14, 0, %0, c1, c0, 0" : "=r"(drar));
56         asm ("mrc p14, 0, %0, c2, c0, 0" : "=r"(dsar));
57         asm ("mrc p14, 0, %0, c0, c1, 0" : "=r"(dscr));
58
59         for (i = 0; i < 16; i++)
60                 if (handlers[i] == NULL)
61                         handlers[i] = handle_unknown;
62
63         printf("DIDR: %08x\n", didr);
64         arch_version = (didr >> 16) & 0x0f;
65         printf(" Revision: %d\n", didr & 0x0f);
66         printf(" Variant: %d\n", (didr >> 4) & 0x0f);
67         printf(" Debug arch version: %d\n", arch_version);
68
69         printf("DRAR: %08x\n", drar);
70         printf("DSAR: %08x\n", dsar);
71         printf("DSCR: %08x\n", dscr);
72
73         if ((drar & 3) != 3)
74                 printf(" (debug ROM table not available)\n");
75         if ((dsar & 3) != 3)
76                 printf(" (debug self address not available\n");
77         if ((drar & 3) == 3 && (dsar & 3) == 3 && argv[1] != NULL)
78                 dump_mem_registers((drar & ~0xfff) + (dsar & ~0xfff));
79         if (argv[1] != NULL && !strcmp(argv[1], "pnd"))
80                 dump_mem_registers(0x54011000);
81
82         handlers[arch_version]();
83
84         return 0;
85 }