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