Home | History | Annotate | Line # | Download | only in m68k
      1 /*	$NetBSD: db_interface.c,v 1.36 2022/10/26 23:38:08 riastradh Exp $	*/
      2 
      3 /*
      4  * Mach Operating System
      5  * Copyright (c) 1992 Carnegie Mellon University
      6  * All Rights Reserved.
      7  *
      8  * Permission to use, copy, modify and distribute this software and its
      9  * documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie Mellon
     26  * the rights to redistribute these changes.
     27  */
     28 
     29 /*
     30  * Interface to the "ddb" kernel debugger.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.36 2022/10/26 23:38:08 riastradh Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/proc.h>
     38 #include <sys/reboot.h>
     39 #include <sys/systm.h> /* just for boothowto --eichin */
     40 
     41 #include <uvm/uvm_extern.h>
     42 
     43 #include <dev/cons.h>
     44 
     45 #include <machine/trap.h>
     46 #include <machine/db_machdep.h>
     47 
     48 #include <ddb/db_active.h>
     49 #include <ddb/db_command.h>
     50 #include <ddb/db_sym.h>
     51 #ifdef _KERNEL
     52 #include <ddb/db_extern.h>
     53 #endif
     54 
     55 int	db_active = 0;
     56 db_regs_t	ddb_regs;
     57 
     58 #ifdef _KERNEL
     59 static void kdbprinttrap(int, int);
     60 
     61 /*
     62  * Received keyboard interrupt sequence.
     63  */
     64 void
     65 kdb_kintr(db_regs_t *regs)
     66 {
     67 
     68 	if (db_active == 0 && (boothowto & RB_KDB)) {
     69 		printf("\n\nkernel: keyboard interrupt\n");
     70 		kdb_trap(-1, regs);
     71 	}
     72 }
     73 
     74 /*
     75  * kdb_trap - field a TRACE or BPT trap
     76  * Return non-zero if we "handled" the trap.
     77  */
     78 int
     79 kdb_trap(int type, db_regs_t *regs)
     80 {
     81 
     82 	switch (type) {
     83 	case T_TRACE:		/* single-step */
     84 	case T_BREAKPOINT:	/* breakpoint */
     85 /*      case T_WATCHPOINT:*/
     86 		break;
     87 	case -1:
     88 		break;
     89 	default:
     90 		kdbprinttrap(type, 0);
     91 		if (db_recover != 0) {
     92 			/* This will longjmp back to db_command_loop */
     93 			db_error("Caught exception in ddb.\n");
     94 			/*NOTREACHED*/
     95 		}
     96 		/*
     97 		 * Tell caller "We did NOT handle the trap."
     98 		 * Caller should panic or whatever.
     99 		 */
    100 		return 0;
    101 	}
    102 
    103 	/*
    104 	 * We'd like to be on a separate debug stack here, but
    105 	 * that's easier to do in locore.s before we get here.
    106 	 * See sun3/locore.s:T_TRACE for stack switch code.
    107 	 */
    108 
    109 	ddb_regs = *regs;
    110 
    111 	db_active++;
    112 	cnpollc(true);	/* set polling mode, unblank video */
    113 
    114 	db_trap(type, 0);	/* where the work happens */
    115 
    116 	cnpollc(false);	/* resume interrupt mode */
    117 	db_active--;
    118 
    119 	*regs = ddb_regs;
    120 
    121 	/*
    122 	 * Indicate that single_step is for KDB.
    123 	 * But lock out interrupts to prevent TRACE_KDB from setting the
    124 	 * trace bit in the current SR (and trapping while exiting KDB).
    125 	 */
    126 	(void)spl7();
    127 
    128 	/*
    129 	 * Tell caller "We HAVE handled the trap."
    130 	 * Caller will return to locore and rte.
    131 	 */
    132 	return 1;
    133 }
    134 
    135 extern char *trap_type[];
    136 extern int trap_types;
    137 
    138 /*
    139  * Print trap reason.
    140  */
    141 static void
    142 kdbprinttrap(int type, int code)
    143 {
    144 
    145 	printf("kernel: ");
    146 	if (type >= trap_types || type < 0)
    147 		printf("type %d", type);
    148 	else
    149 		printf("%s", trap_type[type]);
    150 	printf(" trap\n");
    151 }
    152 
    153 void
    154 cpu_Debugger(void)
    155 {
    156 
    157 	__asm ("trap #15");
    158 }
    159 #endif
    160