1 /* kgdb.c: KGDB support for 32-bit sparc.
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
6 #include <linux/kgdb.h>
7 #include <linux/kdebug.h>
9 #include <asm/kdebug.h>
10 #include <asm/ptrace.h>
13 extern unsigned long trapbase;
15 void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
17 struct reg_window32 *win;
21 for (i = 0; i < 15; i++)
22 gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i];
24 win = (struct reg_window32 *) regs->u_regs[UREG_FP];
25 for (i = 0; i < 8; i++)
26 gdb_regs[GDB_L0 + i] = win->locals[i];
27 for (i = 0; i < 8; i++)
28 gdb_regs[GDB_I0 + i] = win->ins[i];
30 for (i = GDB_F0; i <= GDB_F31; i++)
33 gdb_regs[GDB_Y] = regs->y;
34 gdb_regs[GDB_PSR] = regs->psr;
35 gdb_regs[GDB_WIM] = 0;
36 gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
37 gdb_regs[GDB_PC] = regs->pc;
38 gdb_regs[GDB_NPC] = regs->npc;
39 gdb_regs[GDB_FSR] = 0;
40 gdb_regs[GDB_CSR] = 0;
43 void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
45 struct thread_info *t = task_thread_info(p);
46 struct reg_window32 *win;
49 for (i = GDB_G0; i < GDB_G6; i++)
51 gdb_regs[GDB_G6] = (unsigned long) t;
53 for (i = GDB_O0; i < GDB_SP; i++)
55 gdb_regs[GDB_SP] = t->ksp;
58 win = (struct reg_window32 *) t->ksp;
59 for (i = 0; i < 8; i++)
60 gdb_regs[GDB_L0 + i] = win->locals[i];
61 for (i = 0; i < 8; i++)
62 gdb_regs[GDB_I0 + i] = win->ins[i];
64 for (i = GDB_F0; i <= GDB_F31; i++)
69 gdb_regs[GDB_PSR] = t->kpsr;
70 gdb_regs[GDB_WIM] = t->kwim;
71 gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
72 gdb_regs[GDB_PC] = t->kpc;
73 gdb_regs[GDB_NPC] = t->kpc + 4;
74 gdb_regs[GDB_FSR] = 0;
75 gdb_regs[GDB_CSR] = 0;
78 void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
80 struct reg_window32 *win;
83 for (i = 0; i < 15; i++)
84 regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
86 /* If the PSR register is changing, we have to preserve
87 * the CWP field, otherwise window save/restore explodes.
89 if (regs->psr != gdb_regs[GDB_PSR]) {
90 unsigned long cwp = regs->psr & PSR_CWP;
92 regs->psr = (gdb_regs[GDB_PSR] & ~PSR_CWP) | cwp;
95 regs->pc = gdb_regs[GDB_PC];
96 regs->npc = gdb_regs[GDB_NPC];
97 regs->y = gdb_regs[GDB_Y];
99 win = (struct reg_window32 *) regs->u_regs[UREG_FP];
100 for (i = 0; i < 8; i++)
101 win->locals[i] = gdb_regs[GDB_L0 + i];
102 for (i = 0; i < 8; i++)
103 win->ins[i] = gdb_regs[GDB_I0 + i];
106 int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
107 char *remcomInBuffer, char *remcomOutBuffer,
108 struct pt_regs *linux_regs)
113 switch (remcomInBuffer[0]) {
115 /* try to read optional parameter, pc unchanged if no parm */
116 ptr = &remcomInBuffer[1];
117 if (kgdb_hex2long(&ptr, &addr)) {
118 linux_regs->pc = addr;
119 linux_regs->npc = addr + 4;
125 if (linux_regs->pc == (unsigned long) arch_kgdb_breakpoint) {
126 linux_regs->pc = linux_regs->npc;
127 linux_regs->npc += 4;
134 extern void do_hw_interrupt(struct pt_regs *regs, unsigned long type);
136 asmlinkage void kgdb_trap(struct pt_regs *regs)
140 if (user_mode(regs)) {
141 do_hw_interrupt(regs, 0xfd);
147 local_irq_save(flags);
148 kgdb_handle_exception(0x172, SIGTRAP, 0, regs);
149 local_irq_restore(flags);
152 int kgdb_arch_init(void)
157 void kgdb_arch_exit(void)
161 struct kgdb_arch arch_kgdb_ops = {
162 /* Breakpoint instruction: ta 0x7d */
163 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },