Home | History | Annotate | Line # | Download | only in m68k
      1 /*	$NetBSD: kgdb_m68k.c,v 1.8 2026/03/28 04:08:40 thorpej 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.8 2026/03/28 04:08:40 thorpej 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
     61 kgdb_signal(int type)
     62 {
     63 	int sigval;
     64 
     65 	switch (type) {
     66 
     67 	case T_ASTFLT:
     68 		sigval = SIGINT;
     69 		break;
     70 
     71 	case T_ILLINST:
     72 	case T_PRIVINST:
     73 	case T_FMTERR:
     74 		sigval = SIGILL;
     75 		break;
     76 
     77 	case T_TRACE:
     78 	case T_TRAP15:
     79 		sigval = SIGTRAP;
     80 		break;
     81 
     82 	case T_ZERODIV:
     83 	case T_CHKINST:
     84 	case T_TRAPVINST:
     85 	case T_FPERR:
     86 	case T_COPERR:
     87 		sigval = SIGFPE;
     88 		break;
     89 
     90 	case T_BUSERR:
     91 	case T_ADDRERR:
     92 		sigval = SIGBUS;
     93 		break;
     94 
     95 	case T_MMUFLT:
     96 		sigval = SIGSEGV;
     97 		break;
     98 
     99 	default:
    100 		sigval = SIGEMT;
    101 		break;
    102 	}
    103 	return sigval;
    104 }
    105 
    106 /*
    107  * Definitions exported from gdb.
    108  */
    109 /* KGDB_NUMREGS == 18 */
    110 
    111 #define GDB_SR 16
    112 #define GDB_PC 17
    113 
    114 
    115 /*
    116  * Translate the values stored in the kernel regs struct to/from
    117  * the format understood by gdb.
    118  *
    119  * There is a short pad word between SP (A7) and SR which keeps the
    120  * kernel stack long word aligned (note that this is in addition to
    121  * the stack adjust short that we treat as the upper half of the SR
    122  * (always zero).  We must skip this when copying to/from gdb regs.
    123  */
    124 
    125 void
    126 kgdb_getregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
    127 {
    128 	int i;
    129 
    130 	for (i = 0; i < 16; i++)
    131 		gdb_regs[i]  = regs->tf_regs[i];
    132 	gdb_regs[GDB_SR] = regs->tf_sr;
    133 	gdb_regs[GDB_PC] = regs->tf_pc;
    134 }
    135 
    136 void
    137 kgdb_setregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
    138 {
    139 	int i;
    140 
    141 	for (i = 0; i < 16; i++)
    142 		regs->tf_regs[i] = gdb_regs[i];
    143 	regs->tf_sr = gdb_regs[GDB_SR] | (regs->tf_sr & PSL_T);
    144 	regs->tf_pc = gdb_regs[GDB_PC];
    145 }
    146