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