Linux Audio

Check our new training course

Loading...
v4.10.11
  1/* kgdb.c: KGDB support for 32-bit sparc.
  2 *
  3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  4 */
  5
  6#include <linux/kgdb.h>
  7#include <linux/kdebug.h>
  8#include <linux/sched.h>
  9
 10#include <asm/kdebug.h>
 11#include <asm/ptrace.h>
 12#include <asm/irq.h>
 13#include <asm/cacheflush.h>
 14
 15#include "kernel.h"
 16#include "entry.h"
 17
 18void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
 19{
 20	struct reg_window32 *win;
 21	int i;
 22
 23	gdb_regs[GDB_G0] = 0;
 24	for (i = 0; i < 15; i++)
 25		gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i];
 26
 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];
 32
 33	for (i = GDB_F0; i <= GDB_F31; i++)
 34		gdb_regs[i] = 0;
 35
 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;
 44}
 45
 46void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
 47{
 48	struct thread_info *t = task_thread_info(p);
 49	struct reg_window32 *win;
 50	int i;
 51
 52	for (i = GDB_G0; i < GDB_G6; i++)
 53		gdb_regs[i] = 0;
 54	gdb_regs[GDB_G6] = (unsigned long) t;
 55	gdb_regs[GDB_G7] = 0;
 56	for (i = GDB_O0; i < GDB_SP; i++)
 57		gdb_regs[i] = 0;
 58	gdb_regs[GDB_SP] = t->ksp;
 59	gdb_regs[GDB_O7] = 0;
 60
 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];
 66
 67	for (i = GDB_F0; i <= GDB_F31; i++)
 68		gdb_regs[i] = 0;
 69
 70	gdb_regs[GDB_Y] = 0;
 71
 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;
 79}
 80
 81void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
 82{
 83	struct reg_window32 *win;
 84	int i;
 85
 86	for (i = 0; i < 15; i++)
 87		regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
 88
 89	/* If the PSR register is changing, we have to preserve
 90	 * the CWP field, otherwise window save/restore explodes.
 91	 */
 92	if (regs->psr != gdb_regs[GDB_PSR]) {
 93		unsigned long cwp = regs->psr & PSR_CWP;
 94
 95		regs->psr = (gdb_regs[GDB_PSR] & ~PSR_CWP) | cwp;
 96	}
 97
 98	regs->pc = gdb_regs[GDB_PC];
 99	regs->npc = gdb_regs[GDB_NPC];
100	regs->y = gdb_regs[GDB_Y];
101
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];
107}
108
109int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
110			       char *remcomInBuffer, char *remcomOutBuffer,
111			       struct pt_regs *linux_regs)
112{
113	unsigned long addr;
114	char *ptr;
115
116	switch (remcomInBuffer[0]) {
117	case 'c':
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;
123		}
124		/* fallthru */
125
126	case 'D':
127	case 'k':
128		if (linux_regs->pc == (unsigned long) arch_kgdb_breakpoint) {
129			linux_regs->pc = linux_regs->npc;
130			linux_regs->npc += 4;
131		}
132		return 0;
133	}
134	return -1;
135}
136
137asmlinkage void kgdb_trap(unsigned long trap_level, struct pt_regs *regs)
 
 
138{
139	unsigned long flags;
140
141	if (user_mode(regs)) {
142		do_hw_interrupt(regs, trap_level);
143		return;
144	}
145
146	flushw_all();
147
148	local_irq_save(flags);
149	kgdb_handle_exception(trap_level, SIGTRAP, 0, regs);
150	local_irq_restore(flags);
151}
152
153int kgdb_arch_init(void)
154{
155	return 0;
156}
157
158void kgdb_arch_exit(void)
159{
160}
161
162void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
163{
164	regs->pc = ip;
165	regs->npc = regs->pc + 4;
166}
167
168struct kgdb_arch arch_kgdb_ops = {
169	/* Breakpoint instruction: ta 0x7d */
170	.gdb_bpt_instr		= { 0x91, 0xd0, 0x20, 0x7d },
171};
v4.6
  1/* kgdb.c: KGDB support for 32-bit sparc.
  2 *
  3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  4 */
  5
  6#include <linux/kgdb.h>
  7#include <linux/kdebug.h>
  8#include <linux/sched.h>
  9
 10#include <asm/kdebug.h>
 11#include <asm/ptrace.h>
 12#include <asm/irq.h>
 13#include <asm/cacheflush.h>
 14
 15extern unsigned long trapbase;
 
 16
 17void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
 18{
 19	struct reg_window32 *win;
 20	int i;
 21
 22	gdb_regs[GDB_G0] = 0;
 23	for (i = 0; i < 15; i++)
 24		gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i];
 25
 26	win = (struct reg_window32 *) regs->u_regs[UREG_FP];
 27	for (i = 0; i < 8; i++)
 28		gdb_regs[GDB_L0 + i] = win->locals[i];
 29	for (i = 0; i < 8; i++)
 30		gdb_regs[GDB_I0 + i] = win->ins[i];
 31
 32	for (i = GDB_F0; i <= GDB_F31; i++)
 33		gdb_regs[i] = 0;
 34
 35	gdb_regs[GDB_Y] = regs->y;
 36	gdb_regs[GDB_PSR] = regs->psr;
 37	gdb_regs[GDB_WIM] = 0;
 38	gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
 39	gdb_regs[GDB_PC] = regs->pc;
 40	gdb_regs[GDB_NPC] = regs->npc;
 41	gdb_regs[GDB_FSR] = 0;
 42	gdb_regs[GDB_CSR] = 0;
 43}
 44
 45void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
 46{
 47	struct thread_info *t = task_thread_info(p);
 48	struct reg_window32 *win;
 49	int i;
 50
 51	for (i = GDB_G0; i < GDB_G6; i++)
 52		gdb_regs[i] = 0;
 53	gdb_regs[GDB_G6] = (unsigned long) t;
 54	gdb_regs[GDB_G7] = 0;
 55	for (i = GDB_O0; i < GDB_SP; i++)
 56		gdb_regs[i] = 0;
 57	gdb_regs[GDB_SP] = t->ksp;
 58	gdb_regs[GDB_O7] = 0;
 59
 60	win = (struct reg_window32 *) t->ksp;
 61	for (i = 0; i < 8; i++)
 62		gdb_regs[GDB_L0 + i] = win->locals[i];
 63	for (i = 0; i < 8; i++)
 64		gdb_regs[GDB_I0 + i] = win->ins[i];
 65
 66	for (i = GDB_F0; i <= GDB_F31; i++)
 67		gdb_regs[i] = 0;
 68
 69	gdb_regs[GDB_Y] = 0;
 70
 71	gdb_regs[GDB_PSR] = t->kpsr;
 72	gdb_regs[GDB_WIM] = t->kwim;
 73	gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
 74	gdb_regs[GDB_PC] = t->kpc;
 75	gdb_regs[GDB_NPC] = t->kpc + 4;
 76	gdb_regs[GDB_FSR] = 0;
 77	gdb_regs[GDB_CSR] = 0;
 78}
 79
 80void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
 81{
 82	struct reg_window32 *win;
 83	int i;
 84
 85	for (i = 0; i < 15; i++)
 86		regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
 87
 88	/* If the PSR register is changing, we have to preserve
 89	 * the CWP field, otherwise window save/restore explodes.
 90	 */
 91	if (regs->psr != gdb_regs[GDB_PSR]) {
 92		unsigned long cwp = regs->psr & PSR_CWP;
 93
 94		regs->psr = (gdb_regs[GDB_PSR] & ~PSR_CWP) | cwp;
 95	}
 96
 97	regs->pc = gdb_regs[GDB_PC];
 98	regs->npc = gdb_regs[GDB_NPC];
 99	regs->y = gdb_regs[GDB_Y];
100
101	win = (struct reg_window32 *) regs->u_regs[UREG_FP];
102	for (i = 0; i < 8; i++)
103		win->locals[i] = gdb_regs[GDB_L0 + i];
104	for (i = 0; i < 8; i++)
105		win->ins[i] = gdb_regs[GDB_I0 + i];
106}
107
108int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
109			       char *remcomInBuffer, char *remcomOutBuffer,
110			       struct pt_regs *linux_regs)
111{
112	unsigned long addr;
113	char *ptr;
114
115	switch (remcomInBuffer[0]) {
116	case 'c':
117		/* try to read optional parameter, pc unchanged if no parm */
118		ptr = &remcomInBuffer[1];
119		if (kgdb_hex2long(&ptr, &addr)) {
120			linux_regs->pc = addr;
121			linux_regs->npc = addr + 4;
122		}
123		/* fallthru */
124
125	case 'D':
126	case 'k':
127		if (linux_regs->pc == (unsigned long) arch_kgdb_breakpoint) {
128			linux_regs->pc = linux_regs->npc;
129			linux_regs->npc += 4;
130		}
131		return 0;
132	}
133	return -1;
134}
135
136extern void do_hw_interrupt(struct pt_regs *regs, unsigned long type);
137
138asmlinkage void kgdb_trap(struct pt_regs *regs)
139{
140	unsigned long flags;
141
142	if (user_mode(regs)) {
143		do_hw_interrupt(regs, 0xfd);
144		return;
145	}
146
147	flushw_all();
148
149	local_irq_save(flags);
150	kgdb_handle_exception(0x172, SIGTRAP, 0, regs);
151	local_irq_restore(flags);
152}
153
154int kgdb_arch_init(void)
155{
156	return 0;
157}
158
159void kgdb_arch_exit(void)
160{
161}
162
163void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
164{
165	regs->pc = ip;
166	regs->npc = regs->pc + 4;
167}
168
169struct kgdb_arch arch_kgdb_ops = {
170	/* Breakpoint instruction: ta 0x7d */
171	.gdb_bpt_instr		= { 0x91, 0xd0, 0x20, 0x7d },
172};