Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * May be copied or modified under the terms of the GNU General Public |
| 3 | * License. See linux/COPYING for more information. |
| 4 | * |
| 5 | * Based on original code by Glenn Engel, Jim Kingdon, |
| 6 | * David Grothe <dave@gcom.com>, Tigran Aivazian, <tigran@sco.com> and |
| 7 | * Amit S. Kale <akale@veritas.com> |
| 8 | * |
| 9 | * Super-H port based on sh-stub.c (Ben Lee and Steve Chamberlain) by |
| 10 | * Henry Bell <henry.bell@st.com> |
| 11 | * |
| 12 | * Header file for low-level support for remote debug using GDB. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #ifndef __KGDB_H |
| 17 | #define __KGDB_H |
| 18 | |
| 19 | #include <asm/ptrace.h> |
| 20 | |
| 21 | struct console; |
| 22 | |
| 23 | /* Same as pt_regs but has vbr in place of syscall_nr */ |
| 24 | struct kgdb_regs { |
| 25 | unsigned long regs[16]; |
| 26 | unsigned long pc; |
| 27 | unsigned long pr; |
| 28 | unsigned long sr; |
| 29 | unsigned long gbr; |
| 30 | unsigned long mach; |
| 31 | unsigned long macl; |
| 32 | unsigned long vbr; |
| 33 | }; |
| 34 | |
| 35 | /* State info */ |
| 36 | extern char kgdb_in_gdb_mode; |
| 37 | extern int kgdb_done_init; |
| 38 | extern int kgdb_enabled; |
| 39 | extern int kgdb_nofault; /* Ignore bus errors (in gdb mem access) */ |
| 40 | extern int kgdb_halt; /* Execute initial breakpoint at startup */ |
| 41 | extern char in_nmi; /* Debounce flag to prevent NMI reentry*/ |
| 42 | |
| 43 | /* SCI */ |
| 44 | extern int kgdb_portnum; |
| 45 | extern int kgdb_baud; |
| 46 | extern char kgdb_parity; |
| 47 | extern char kgdb_bits; |
| 48 | extern int kgdb_console_setup(struct console *, char *); |
| 49 | |
| 50 | /* Init and interface stuff */ |
| 51 | extern int kgdb_init(void); |
| 52 | extern int (*kgdb_serial_setup)(void); |
| 53 | extern int (*kgdb_getchar)(void); |
| 54 | extern void (*kgdb_putchar)(int); |
| 55 | |
| 56 | struct kgdb_sermap { |
| 57 | char *name; |
| 58 | int namelen; |
| 59 | int (*setup_fn)(struct console *, char *); |
| 60 | struct kgdb_sermap *next; |
| 61 | }; |
| 62 | extern void kgdb_register_sermap(struct kgdb_sermap *map); |
| 63 | extern struct kgdb_sermap *kgdb_porttype; |
| 64 | |
| 65 | /* Trap functions */ |
| 66 | typedef void (kgdb_debug_hook_t)(struct pt_regs *regs); |
| 67 | typedef void (kgdb_bus_error_hook_t)(void); |
| 68 | extern kgdb_debug_hook_t *kgdb_debug_hook; |
| 69 | extern kgdb_bus_error_hook_t *kgdb_bus_err_hook; |
| 70 | |
| 71 | extern void breakpoint(void); |
| 72 | |
| 73 | /* Console */ |
| 74 | struct console; |
| 75 | void kgdb_console_write(struct console *co, const char *s, unsigned count); |
| 76 | void kgdb_console_init(void); |
| 77 | |
| 78 | /* Prototypes for jmp fns */ |
| 79 | #define _JBLEN 9 |
| 80 | typedef int jmp_buf[_JBLEN]; |
| 81 | extern void longjmp(jmp_buf __jmpb, int __retval); |
| 82 | extern int setjmp(jmp_buf __jmpb); |
| 83 | |
| 84 | /* Variadic macro to print our own message to the console */ |
| 85 | #define KGDB_PRINTK(...) printk("KGDB: " __VA_ARGS__) |
| 86 | |
| 87 | /* Forced breakpoint */ |
Paul Mundt | f413d0d | 2006-12-13 17:40:05 +0900 | [diff] [blame] | 88 | #define BREAKPOINT() \ |
| 89 | do { \ |
| 90 | if (kgdb_enabled) \ |
| 91 | __asm__ __volatile__("trapa #0x3c"); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } while (0) |
| 93 | |
| 94 | /* KGDB should be able to flush all kernel text space */ |
| 95 | #if defined(CONFIG_CPU_SH4) |
| 96 | #define kgdb_flush_icache_range(start, end) \ |
| 97 | { \ |
| 98 | extern void __flush_purge_region(void *, int); \ |
| 99 | __flush_purge_region((void*)(start), (int)(end) - (int)(start));\ |
| 100 | flush_icache_range((start), (end)); \ |
| 101 | } |
| 102 | #else |
| 103 | #define kgdb_flush_icache_range(start, end) do { } while (0) |
| 104 | #endif |
| 105 | |
| 106 | /* Kernel assert macros */ |
| 107 | #ifdef CONFIG_KGDB_KERNEL_ASSERTS |
| 108 | |
| 109 | /* Predefined conditions */ |
| 110 | #define KA_VALID_ERRNO(errno) ((errno) > 0 && (errno) <= EMEDIUMTYPE) |
| 111 | #define KA_VALID_PTR_ERR(ptr) KA_VALID_ERRNO(-PTR_ERR(ptr)) |
| 112 | #define KA_VALID_KPTR(ptr) (!(ptr) || \ |
| 113 | ((void *)(ptr) >= (void *)PAGE_OFFSET && \ |
| 114 | (void *)(ptr) < ERR_PTR(-EMEDIUMTYPE))) |
| 115 | #define KA_VALID_PTRORERR(errptr) \ |
| 116 | (KA_VALID_KPTR(errptr) || KA_VALID_PTR_ERR(errptr)) |
| 117 | #define KA_HELD_GKL() (current->lock_depth >= 0) |
| 118 | |
| 119 | /* The actual assert */ |
| 120 | #define KGDB_ASSERT(condition, message) do { \ |
| 121 | if (!(condition) && (kgdb_enabled)) { \ |
| 122 | KGDB_PRINTK("Assertion failed at %s:%d: %s\n", \ |
| 123 | __FILE__, __LINE__, message);\ |
| 124 | BREAKPOINT(); \ |
| 125 | } \ |
| 126 | } while (0) |
| 127 | #else |
| 128 | #define KGDB_ASSERT(condition, message) |
| 129 | #endif |
| 130 | |
Paul Mundt | 56e8d7b | 2006-09-27 16:24:55 +0900 | [diff] [blame] | 131 | /* Taken from sh-stub.c of GDB 4.18 */ |
| 132 | static const char hexchars[] = "0123456789abcdef"; |
| 133 | |
| 134 | /* Get high hex bits */ |
| 135 | static inline char highhex(const int x) |
| 136 | { |
| 137 | return hexchars[(x >> 4) & 0xf]; |
| 138 | } |
| 139 | |
| 140 | /* Get low hex bits */ |
| 141 | static inline char lowhex(const int x) |
| 142 | { |
| 143 | return hexchars[x & 0xf]; |
| 144 | } |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | #endif |