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>
8 #include <linux/sched.h>
10 #include <asm/kdebug.h>
11 #include <asm/ptrace.h>
13 #include <asm/cacheflush.h>
18 void pt_regs_to_gdb_regs(unsigned long *gdb_regs
, struct pt_regs
*regs
)
20 struct reg_window32
*win
;
24 for (i
= 0; i
< 15; i
++)
25 gdb_regs
[GDB_G1
+ i
] = regs
->u_regs
[UREG_G1
+ i
];
27 win
= (struct reg_window32
*) regs
->u_regs
[UREG_FP
];
28 for (i
= 0; i
< 8; i
++)
29 gdb_regs
[GDB_L0
+ i
] = win
->locals
[i
];
30 for (i
= 0; i
< 8; i
++)
31 gdb_regs
[GDB_I0
+ i
] = win
->ins
[i
];
33 for (i
= GDB_F0
; i
<= GDB_F31
; i
++)
36 gdb_regs
[GDB_Y
] = regs
->y
;
37 gdb_regs
[GDB_PSR
] = regs
->psr
;
38 gdb_regs
[GDB_WIM
] = 0;
39 gdb_regs
[GDB_TBR
] = (unsigned long) &trapbase
;
40 gdb_regs
[GDB_PC
] = regs
->pc
;
41 gdb_regs
[GDB_NPC
] = regs
->npc
;
42 gdb_regs
[GDB_FSR
] = 0;
43 gdb_regs
[GDB_CSR
] = 0;
46 void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs
, struct task_struct
*p
)
48 struct thread_info
*t
= task_thread_info(p
);
49 struct reg_window32
*win
;
52 for (i
= GDB_G0
; i
< GDB_G6
; i
++)
54 gdb_regs
[GDB_G6
] = (unsigned long) t
;
56 for (i
= GDB_O0
; i
< GDB_SP
; i
++)
58 gdb_regs
[GDB_SP
] = t
->ksp
;
61 win
= (struct reg_window32
*) t
->ksp
;
62 for (i
= 0; i
< 8; i
++)
63 gdb_regs
[GDB_L0
+ i
] = win
->locals
[i
];
64 for (i
= 0; i
< 8; i
++)
65 gdb_regs
[GDB_I0
+ i
] = win
->ins
[i
];
67 for (i
= GDB_F0
; i
<= GDB_F31
; i
++)
72 gdb_regs
[GDB_PSR
] = t
->kpsr
;
73 gdb_regs
[GDB_WIM
] = t
->kwim
;
74 gdb_regs
[GDB_TBR
] = (unsigned long) &trapbase
;
75 gdb_regs
[GDB_PC
] = t
->kpc
;
76 gdb_regs
[GDB_NPC
] = t
->kpc
+ 4;
77 gdb_regs
[GDB_FSR
] = 0;
78 gdb_regs
[GDB_CSR
] = 0;
81 void gdb_regs_to_pt_regs(unsigned long *gdb_regs
, struct pt_regs
*regs
)
83 struct reg_window32
*win
;
86 for (i
= 0; i
< 15; i
++)
87 regs
->u_regs
[UREG_G1
+ i
] = gdb_regs
[GDB_G1
+ i
];
89 /* If the PSR register is changing, we have to preserve
90 * the CWP field, otherwise window save/restore explodes.
92 if (regs
->psr
!= gdb_regs
[GDB_PSR
]) {
93 unsigned long cwp
= regs
->psr
& PSR_CWP
;
95 regs
->psr
= (gdb_regs
[GDB_PSR
] & ~PSR_CWP
) | cwp
;
98 regs
->pc
= gdb_regs
[GDB_PC
];
99 regs
->npc
= gdb_regs
[GDB_NPC
];
100 regs
->y
= gdb_regs
[GDB_Y
];
102 win
= (struct reg_window32
*) regs
->u_regs
[UREG_FP
];
103 for (i
= 0; i
< 8; i
++)
104 win
->locals
[i
] = gdb_regs
[GDB_L0
+ i
];
105 for (i
= 0; i
< 8; i
++)
106 win
->ins
[i
] = gdb_regs
[GDB_I0
+ i
];
109 int kgdb_arch_handle_exception(int e_vector
, int signo
, int err_code
,
110 char *remcomInBuffer
, char *remcomOutBuffer
,
111 struct pt_regs
*linux_regs
)
116 switch (remcomInBuffer
[0]) {
118 /* try to read optional parameter, pc unchanged if no parm */
119 ptr
= &remcomInBuffer
[1];
120 if (kgdb_hex2long(&ptr
, &addr
)) {
121 linux_regs
->pc
= addr
;
122 linux_regs
->npc
= addr
+ 4;
128 if (linux_regs
->pc
== (unsigned long) arch_kgdb_breakpoint
) {
129 linux_regs
->pc
= linux_regs
->npc
;
130 linux_regs
->npc
+= 4;
137 asmlinkage
void kgdb_trap(unsigned long trap_level
, struct pt_regs
*regs
)
141 if (user_mode(regs
)) {
142 do_hw_interrupt(regs
, trap_level
);
148 local_irq_save(flags
);
149 kgdb_handle_exception(trap_level
, SIGTRAP
, 0, regs
);
150 local_irq_restore(flags
);
153 int kgdb_arch_init(void)
158 void kgdb_arch_exit(void)
162 void kgdb_arch_set_pc(struct pt_regs
*regs
, unsigned long ip
)
165 regs
->npc
= regs
->pc
+ 4;
168 struct kgdb_arch arch_kgdb_ops
= {
169 /* Breakpoint instruction: ta 0x7d */
170 .gdb_bpt_instr
= { 0x91, 0xd0, 0x20, 0x7d },