xref: /f-stack/freebsd/mips/mips/gdb_machdep.c (revision 22ce4aff)
1 /*	$NetBSD: kgdb_machdep.c,v 1.11 2005/12/24 22:45:35 perry Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-2-Clause-NetBSD
5  *
6  * Copyright (c) 2004 Marcel Moolenaar
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*-
31  * Copyright (c) 1997 The NetBSD Foundation, Inc.
32  * All rights reserved.
33  *
34  * This code is derived from software contributed to The NetBSD Foundation
35  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
36  * NASA Ames Research Center.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57  * POSSIBILITY OF SUCH DAMAGE.
58  */
59 
60 /*
61  * Copyright (c) 1996 Matthias Pfaller.
62  * All rights reserved.
63  *
64  * Redistribution and use in source and binary forms, with or without
65  * modification, are permitted provided that the following conditions
66  * are met:
67  * 1. Redistributions of source code must retain the above copyright
68  *    notice, this list of conditions and the following disclaimer.
69  * 2. Redistributions in binary form must reproduce the above copyright
70  *    notice, this list of conditions and the following disclaimer in the
71  *    documentation and/or other materials provided with the distribution.
72  * 3. All advertising materials mentioning features or use of this software
73  *    must display the following acknowledgement:
74  *	This product includes software developed by Matthias Pfaller.
75  * 4. The name of the author may not be used to endorse or promote products
76  *    derived from this software without specific prior written permission
77  *
78  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
79  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
80  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
82  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
83  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
87  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88  *
89  *	JNPR: gdb_machdep.c,v 1.1 2007/08/09 12:25:25 katta
90  * $FreeBSD$
91  */
92 
93 #include <sys/cdefs.h>
94 
95 #include <sys/param.h>
96 #include <sys/systm.h>
97 #include <sys/kdb.h>
98 #include <sys/kernel.h>
99 #include <sys/signal.h>
100 #include <sys/pcpu.h>
101 
102 #include <machine/gdb_machdep.h>
103 #include <machine/pcb.h>
104 #include <machine/reg.h>
105 #include <machine/trap.h>
106 
107 #include <gdb/gdb.h>
108 
109 void *
gdb_cpu_getreg(int regnum,size_t * regsz)110 gdb_cpu_getreg(int regnum, size_t *regsz)
111 {
112 
113  	*regsz = gdb_cpu_regsz(regnum);
114  	if (kdb_thread == curthread) {
115 		register_t *zero_ptr = &kdb_frame->zero;
116 		return zero_ptr + regnum;
117 	}
118 
119 	switch (regnum) {
120 	/*
121 	 * S0..S7
122 	 */
123 	case 16:
124 	case 17:
125 	case 18:
126 	case 19:
127 	case 20:
128 	case 21:
129 	case 22:
130 	case 23:
131  		return (&kdb_thrctx->pcb_context[PCB_REG_S0 + regnum - 16]);
132 	case 28:
133 		return (&kdb_thrctx->pcb_context[PCB_REG_GP]);
134 	case 29:
135 		return (&kdb_thrctx->pcb_context[PCB_REG_SP]);
136 	case 30:
137 		return (&kdb_thrctx->pcb_context[PCB_REG_S8]);
138 	case 31:
139 		return (&kdb_thrctx->pcb_context[PCB_REG_RA]);
140 	case 37:
141 		return (&kdb_thrctx->pcb_context[PCB_REG_PC]);
142 	}
143 	return (NULL);
144 }
145 
146 void
gdb_cpu_setreg(int regnum,void * val)147 gdb_cpu_setreg(int regnum, void *val)
148 {
149 	switch (regnum) {
150 	case GDB_REG_PC:
151 		kdb_thrctx->pcb_context[10] = *(register_t *)val;
152 		if (kdb_thread == curthread)
153 			kdb_frame->pc = *(register_t *)val;
154 	}
155 }
156 
157 int
gdb_cpu_signal(int entry,int code)158 gdb_cpu_signal(int entry, int code)
159 {
160 	switch (entry) {
161 	case T_TLB_MOD:
162 	case T_TLB_MOD+T_USER:
163 	case T_TLB_LD_MISS:
164 	case T_TLB_ST_MISS:
165 	case T_TLB_LD_MISS+T_USER:
166 	case T_TLB_ST_MISS+T_USER:
167 	case T_ADDR_ERR_LD:		/* misaligned access */
168 	case T_ADDR_ERR_ST:		/* misaligned access */
169 	case T_BUS_ERR_LD_ST:		/* BERR asserted to CPU */
170 	case T_ADDR_ERR_LD+T_USER:	/* misaligned or kseg access */
171 	case T_ADDR_ERR_ST+T_USER:	/* misaligned or kseg access */
172 	case T_BUS_ERR_IFETCH+T_USER:	/* BERR asserted to CPU */
173 	case T_BUS_ERR_LD_ST+T_USER:	/* BERR asserted to CPU */
174 		return (SIGSEGV);
175 
176 	case T_BREAK:
177 	case T_BREAK+T_USER:
178 		return (SIGTRAP);
179 
180 	case T_RES_INST+T_USER:
181 	case T_COP_UNUSABLE+T_USER:
182 		return (SIGILL);
183 
184 	case T_FPE+T_USER:
185 	case T_OVFLOW+T_USER:
186 		return (SIGFPE);
187 
188 	default:
189 		return (SIGEMT);
190 	}
191 }
192