tests: add armv7 debug test and a register dumper
authorGrazvydas Ignotas <notasas@gmail.com>
Wed, 18 Feb 2015 00:28:11 +0000 (02:28 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Wed, 18 Feb 2015 00:28:11 +0000 (02:28 +0200)
tests/regread_dump.c [new file with mode: 0644]
tests/test_a8debug.c [new file with mode: 0644]

diff --git a/tests/regread_dump.c b/tests/regread_dump.c
new file mode 100644 (file)
index 0000000..94e45ac
--- /dev/null
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+static volatile int fault;
+
+static void sigbus_sigaction(int num, siginfo_t *info, void *ctx)
+{
+       struct ucontext *context = ctx;
+       unsigned int *regs = (unsigned int *)&context->uc_mcontext.arm_r0;
+
+       //printf("\nsigbus %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
+       fault = 1;
+       regs[15] += 4;
+
+       usleep(1000);
+}
+
+int main(int argc, char *argv[])
+{
+       struct sigaction sigbus_action = {
+               .sa_sigaction = sigbus_sigaction,
+               .sa_flags = SA_SIGINFO,
+       };
+       unsigned int base = 0x5401d000;
+       volatile unsigned int *regs;
+       unsigned int val;
+       int i, fd;
+
+       fd = open("/dev/mem", O_RDONLY | O_SYNC);
+       if (fd == -1)
+       {
+               perror("open /dev/mem");
+               return 1;
+       }
+
+       regs = mmap(0, 0x1000, PROT_READ, MAP_SHARED, fd, base);
+       if (regs == MAP_FAILED) {
+               close(fd);
+               perror("mmap");
+               return 1;
+       }
+
+       sigemptyset(&sigbus_action.sa_mask);
+       sigaction(SIGBUS, &sigbus_action, NULL);
+
+       for (i = 0; i < 1024; i++) {
+               printf("%08x ", base + i * 4);
+
+               fault = 0;
+
+               val = regs[i];
+
+               if (!fault)
+                       printf("%08x\n", val);
+               else
+                       printf("fault\n");
+               fflush(stdout);
+       }
+
+       munmap((void *)regs, 0x1000);
+       close(fd);
+
+       return 0;
+}
diff --git a/tests/test_a8debug.c b/tests/test_a8debug.c
new file mode 100644 (file)
index 0000000..f028563
--- /dev/null
@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+static void handle_v4(void)
+{
+}
+
+static void handle_unknown(void)
+{
+}
+
+static void (*handlers[16])(void) = {
+       [4] = handle_v4,
+};
+
+// XXX: LPAE?
+static void dump_mem_registers(unsigned int address)
+{
+       unsigned int *regs;
+       int fd;
+
+       fd = open("/dev/mem", O_RDONLY | O_SYNC);
+       if (fd == -1) {
+               perror("open(/dev/mem)");
+               return;
+       }
+
+       regs = mmap(NULL, 0x1000, PROT_READ, MAP_SHARED, fd, address);
+       if (regs == MAP_FAILED) {
+               perror("mmap");
+               close(fd);
+               return;
+       }
+
+       printf("\nmemory mapped registers:\n");
+       printf("DIDR:       %08x\n", regs[0]);
+       printf("AUTHSTATUS: %08x\n", regs[1006]);
+       printf("DEVID:      %08x\n", regs[1010]);
+
+       munmap(regs, 0x1000);
+       close(fd);
+}
+
+int main(int argc, char *argv[])
+{
+       unsigned int didr = 0, drar = 0, dsar = 0, dscr = 0;
+       unsigned int i, arch_version;
+
+       asm ("mrc p14, 0, %0, c0, c0, 0" : "=r"(didr));
+       asm ("mrc p14, 0, %0, c1, c0, 0" : "=r"(drar));
+       asm ("mrc p14, 0, %0, c2, c0, 0" : "=r"(dsar));
+       asm ("mrc p14, 0, %0, c0, c1, 0" : "=r"(dscr));
+
+       for (i = 0; i < 16; i++)
+               if (handlers[i] == NULL)
+                       handlers[i] = handle_unknown;
+
+       printf("DIDR: %08x\n", didr);
+       arch_version = (didr >> 16) & 0x0f;
+       printf(" Revision: %d\n", didr & 0x0f);
+       printf(" Variant: %d\n", (didr >> 4) & 0x0f);
+       printf(" Debug arch version: %d\n", arch_version);
+
+       printf("DRAR: %08x\n", drar);
+       printf("DSAR: %08x\n", dsar);
+       printf("DSCR: %08x\n", dscr);
+
+       if ((drar & 3) != 3)
+               printf(" (debug ROM table not available)\n");
+       if ((dsar & 3) != 3)
+               printf(" (debug self address not available\n");
+       if ((drar & 3) == 3 && (dsar & 3) == 3 && argv[1] != NULL)
+               dump_mem_registers((drar & ~0xfff) + (dsar & ~0xfff));
+       if (argv[1] != NULL && !strcmp(argv[1], "pnd"))
+               dump_mem_registers(0x54011000);
+
+       handlers[arch_version]();
+
+       return 0;
+}