1 /* $NetBSD: kgdb_m68k.c,v 1.7 2006/07/22 06:58:17 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
41 */
42
43 /*
44 * Machine-dependent (m68k) part of the KGDB remote "stub"
45 */
46
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: kgdb_m68k.c,v 1.7 2006/07/22 06:58:17 tsutsui Exp $");
49
50 #include <sys/param.h>
51 #include <sys/kgdb.h>
52
53 #include <machine/frame.h>
54 #include <machine/trap.h>
55
56 /*
57 * Translate a trap number into a unix compatible signal value.
58 * (gdb only understands unix signal numbers).
59 */
60 int
kgdb_signal(int type)61 kgdb_signal(int type)
62 {
63 int sigval;
64
65 switch (type) {
66
67 case T_ASTFLT:
68 case T_SSIR:
69 sigval = SIGINT;
70 break;
71
72 case T_ILLINST:
73 case T_PRIVINST:
74 case T_FMTERR:
75 sigval = SIGILL;
76 break;
77
78 case T_TRACE:
79 case T_TRAP15:
80 sigval = SIGTRAP;
81 break;
82
83 case T_ZERODIV:
84 case T_CHKINST:
85 case T_TRAPVINST:
86 case T_FPERR:
87 case T_COPERR:
88 sigval = SIGFPE;
89 break;
90
91 case T_BUSERR:
92 case T_ADDRERR:
93 sigval = SIGBUS;
94 break;
95
96 case T_MMUFLT:
97 sigval = SIGSEGV;
98 break;
99
100 default:
101 sigval = SIGEMT;
102 break;
103 }
104 return sigval;
105 }
106
107 /*
108 * Definitions exported from gdb.
109 */
110 /* KGDB_NUMREGS == 18 */
111
112 #define GDB_SR 16
113 #define GDB_PC 17
114
115
116 /*
117 * Translate the values stored in the kernel regs struct to/from
118 * the format understood by gdb.
119 *
120 * There is a short pad word between SP (A7) and SR which keeps the
121 * kernel stack long word aligned (note that this is in addition to
122 * the stack adjust short that we treat as the upper half of the SR
123 * (always zero). We must skip this when copying to/from gdb regs.
124 */
125
126 void
kgdb_getregs(db_regs_t * regs,kgdb_reg_t * gdb_regs)127 kgdb_getregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
128 {
129 int i;
130
131 for (i = 0; i < 16; i++)
132 gdb_regs[i] = regs->tf_regs[i];
133 gdb_regs[GDB_SR] = regs->tf_sr;
134 gdb_regs[GDB_PC] = regs->tf_pc;
135 }
136
137 void
kgdb_setregs(db_regs_t * regs,kgdb_reg_t * gdb_regs)138 kgdb_setregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
139 {
140 int i;
141
142 for (i = 0; i < 16; i++)
143 regs->tf_regs[i] = gdb_regs[i];
144 regs->tf_sr = gdb_regs[GDB_SR] | (regs->tf_sr & PSL_T);
145 regs->tf_pc = gdb_regs[GDB_PC];
146 }
147