]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/mips/mips/gdb_machdep.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.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  == PCPU_GET(curthread)) {
120                 switch (regnum) {
121                 /*
122                 * XXX: May need to add more registers 
123                 */
124                 case 2: return (&kdb_frame->v0);
125                 case 3: return (&kdb_frame->v1);
126                 }
127         }
128         switch (regnum) {
129         case 16: return (&kdb_thrctx->pcb_context.val[0]);
130         case 17: return (&kdb_thrctx->pcb_context.val[1]);
131         case 18: return (&kdb_thrctx->pcb_context.val[2]);
132         case 19: return (&kdb_thrctx->pcb_context.val[3]);
133         case 20: return (&kdb_thrctx->pcb_context.val[4]);
134         case 21: return (&kdb_thrctx->pcb_context.val[5]);
135         case 22: return (&kdb_thrctx->pcb_context.val[6]);
136         case 23: return (&kdb_thrctx->pcb_context.val[7]);
137         case 29: return (&kdb_thrctx->pcb_context.val[8]);
138         case 30: return (&kdb_thrctx->pcb_context.val[9]);
139         case 31: return (&kdb_thrctx->pcb_context.val[10]);
140         }
141         return (NULL);
142 }
143
144 void
145 gdb_cpu_setreg(int regnum, void *val)
146 {
147         switch (regnum) {
148         case GDB_REG_PC:
149                 kdb_thrctx->pcb_context.val[10] = *(register_t *)val;
150                 if (kdb_thread  == PCPU_GET(curthread))
151                         kdb_frame->pc = *(register_t *)val;
152         }
153 }
154
155 int
156 gdb_cpu_signal(int entry, int code)
157 {
158         switch (entry) {
159         case T_TLB_MOD:
160         case T_TLB_MOD+T_USER:
161         case T_TLB_LD_MISS:
162         case T_TLB_ST_MISS:
163         case T_TLB_LD_MISS+T_USER:
164         case T_TLB_ST_MISS+T_USER:
165         case T_ADDR_ERR_LD:             /* misaligned access */
166         case T_ADDR_ERR_ST:             /* misaligned access */
167         case T_BUS_ERR_LD_ST:           /* BERR asserted to CPU */
168         case T_ADDR_ERR_LD+T_USER:      /* misaligned or kseg access */
169         case T_ADDR_ERR_ST+T_USER:      /* misaligned or kseg access */
170         case T_BUS_ERR_IFETCH+T_USER:   /* BERR asserted to CPU */
171         case T_BUS_ERR_LD_ST+T_USER:    /* BERR asserted to CPU */
172                 return (SIGSEGV);
173
174         case T_BREAK:
175         case T_BREAK+T_USER:
176                 return (SIGTRAP);
177
178         case T_RES_INST+T_USER:
179         case T_COP_UNUSABLE+T_USER:
180                 return (SIGILL);
181
182         case T_FPE+T_USER:
183         case T_OVFLOW+T_USER:
184                 return (SIGFPE);
185
186         default:
187                 return (SIGEMT);
188         }
189 }