aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2016-07-18 17:32:54 -0700
committerGeoff Levand <geoff@infradead.org>2016-12-02 10:08:45 -0800
commitafd057a48beece978c71ef36030fe94fb8aa2650 (patch)
treec1c3aa4e70a7f023b6598605090cffa4ad93c1c9
parenta4e1331a7d0e68ff99c08f5318a90b95b002a230 (diff)
downloadlinux-kexec-afd057a48beece978c71ef36030fe94fb8aa2650.tar.gz
debugging: Add hacks.h
-rw-r--r--include/linux/hacks.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/include/linux/hacks.h b/include/linux/hacks.h
new file mode 100644
index 0000000000000..76bcf290308c9
--- /dev/null
+++ b/include/linux/hacks.h
@@ -0,0 +1,130 @@
+#if !defined(LINUX_HACKS_H)
+#define LINUX_HACKS_H
+
+/*
+ * putc - output a char to the UART at ARM64_DEBUG_PORT.
+ * model_brk - Hard breakpoint for the Fast Model debugger.
+ * c_out - output a char using Model Semi-hosting.
+ * s_out - output a string using Model Semi-hosting.
+ */
+
+#define ARM64_DEBUG_PORT 0x1c090000
+
+#if defined(__ASSEMBLY__)
+
+.macro putc c:req
+ mov x21, #ARM64_DEBUG_PORT
+ mov x22, \c
+ str x22, [x21]
+.endm
+
+.macro model_brk
+ mov x0, #0x18; /* angel_SWIreason_ReportException */
+ mov x1, #0x20000;
+ add x1, x1, #0x20; /* ADP_Stopped_BreakPoint */
+ hlt #0xf000 /* A64 semihosting */
+.endm
+
+.macro model_brk_2, r1=x21, r2=x22
+ mov \r1, x0
+ mov \r2, x1
+ mov x0, #0x18; /* angel_SWIreason_ReportException */
+ mov x1, #0x20000;
+ add x1, x1, #0x20; /* ADP_Stopped_BreakPoint */
+ hlt #0xf000 /* A64 semihosting */
+ mov x0, \r1
+ mov x1, \r2
+.endm
+
+.macro c_out, a
+ adr x1, .debug_str
+ mov w2, \a
+ strb w2, [x1]
+ mov x0, #3
+ hlt #0xf000
+.endm
+
+.macro s_out, a
+ adr x1, \a
+ mov x0, #4 /* SYS_WRITE0 */
+ hlt #0xf000 /* A64 semihosting */
+.endm
+
+.macro mmu_check, a
+ c_out #(\a + '0')
+ mrs x1, sctlr_el1
+ tbz x1, #0, 1f
+ s_out .debug_y
+ b 2f
+1:
+ s_out .debug_n
+2:
+.endm
+
+.macro out_data
+
+ .align 3
+
+ .debug_y:
+ .string " debug_y\n"
+ .debug_n:
+ .string " debug_n\n"
+
+ .align 3, 0
+ .debug_str:
+ .quad 0
+ .quad 0
+ .quad 0
+ .quad 0
+.endm
+
+#else
+
+#include <linux/kernel.h>
+#include <asm/compiler.h>
+
+static inline void model_brk(int line)
+{
+ asm volatile(
+ "mov x0, #0x18;" /* angel_SWIreason_ReportException */
+ "mov x1, #0x20000;"
+ "add x1, x1, #0x20;" /* ADP_Stopped_BreakPoint */
+ "hlt #0xf000\n" /* A64 semihosting */
+ :
+ : "r" (line)
+ : "x0", "x1");
+}
+
+static inline void c_out(char c)
+{
+ asm volatile("mov x1, %0\n"
+ "mov x0, #3\n"
+ "hlt 0xf000\n"
+ : : "r" (&c) : "x0", "x1", "memory");
+}
+
+static inline void s_out(const char *s)
+{
+ asm volatile("mov x1, %0\n"
+ "mov x0, #4\n"
+ "hlt 0xf000\n"
+ : : "r" (s) : "x0", "x1", "memory");
+}
+
+#define S(x) #x
+#define S_(x) S(x)
+
+#define line_out(_s) s_out(__func__); s_out(":" S_(__LINE__) ": " _s)
+
+#define print_sctlr_el1() _print_sctlr_el1(__func__, __LINE__)
+static inline void _print_sctlr_el1(const char *func, int line)
+{
+ u32 val;
+
+ asm volatile("mrs %0, sctlr_el1" : "=r" (val));
+
+ printk("%s:%d: sctlr_el1: %x - %s\n", func, line, val, (val & 1) ? "y" : "n");
+}
+
+#endif
+#endif /* LINUX_HACKS_H */