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 /* Same as pt_regs but has vbr in place of syscall_nr */
22 struct kgdb_regs {
23         unsigned long regs[16];
24         unsigned long pc;
25         unsigned long pr;
26         unsigned long sr;
27         unsigned long gbr;
28         unsigned long mach;
29         unsigned long macl;
30         unsigned long vbr;
31 };
32 
33 /* State info */
34 extern char kgdb_in_gdb_mode;
35 extern int kgdb_done_init;
36 extern int kgdb_enabled;
37 extern int kgdb_nofault;	/* Ignore bus errors (in gdb mem access) */
38 extern int kgdb_halt;		/* Execute initial breakpoint at startup */
39 extern char in_nmi;		/* Debounce flag to prevent NMI reentry*/
40 
41 /* SCI */
42 extern int kgdb_portnum;
43 extern int kgdb_baud;
44 extern char kgdb_parity;
45 extern char kgdb_bits;
46 extern int kgdb_cflag;
47 extern int kgdb_sci_setup(void);
48 
49 /* Init and interface stuff */
50 extern int kgdb_init(void);
51 extern int (*kgdb_serial_setup)(void);
52 extern int (*kgdb_getchar)(void);
53 extern void (*kgdb_putchar)(int);
54 
55 struct kgdb_sermap {
56 	char *name;
57 	int namelen;
58 	int (*setup_fn)(void);
59 	struct kgdb_sermap *next;
60 };
61 extern void kgdb_register_sermap(struct kgdb_sermap *map);
62 extern struct kgdb_sermap *kgdb_porttype;
63 
64 /* Trap functions */
65 typedef void (kgdb_debug_hook_t)(struct pt_regs *regs);
66 typedef void (kgdb_bus_error_hook_t)(void);
67 extern kgdb_debug_hook_t  *kgdb_debug_hook;
68 extern kgdb_bus_error_hook_t *kgdb_bus_err_hook;
69 
70 extern void breakpoint(void);
71 
72 /* Console */
73 struct console;
74 void kgdb_console_write(struct console *co, const char *s, unsigned count);
75 void kgdb_console_init(void);
76 
77 /* Prototypes for jmp fns */
78 #define _JBLEN 9
79 typedef        int jmp_buf[_JBLEN];
80 extern void    kgdb_longjmp(jmp_buf __jmpb, int __retval);
81 extern int     kgdb_setjmp(jmp_buf __jmpb);
82 
83 /* Variadic macro to print our own message to the console */
84 #define KGDB_PRINTK(...) printk("KGDB: " __VA_ARGS__)
85 
86 /* Forced breakpoint */
87 #define BREAKPOINT() do {                                     \
88   if (kgdb_enabled) {                                         \
89     asm volatile("trapa   #0xff");                            \
90   }                                                           \
91 } while (0)
92 
93 /* KGDB should be able to flush all kernel text space */
94 #if defined(__sh3__)
95 #define kgdb_flush_icache_range(start, end)	do { } while (0)
96 #elif defined(__SH4__)
97 #define kgdb_flush_icache_range(start, end) \
98 {									       \
99 	extern void __flush_purge_region(void *, int);			       \
100 	__flush_purge_region((void*)(start), (int)(end) - (int)(start));       \
101 	flush_icache_range((start), (end));				       \
102 }
103 #endif
104 
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 
131 #endif
132