xref: /netbsd/sys/arch/m68k/m68k/db_interface.c (revision bf9ec67e)
1 /*	$NetBSD: db_interface.c,v 1.28 2002/05/13 20:30:08 matt 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@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 #include "opt_ddb.h"
33 
34 #include <sys/param.h>
35 #include <sys/proc.h>
36 #include <sys/reboot.h>
37 #include <sys/systm.h> /* just for boothowto --eichin */
38 
39 #include <uvm/uvm_extern.h>
40 
41 #include <dev/cons.h>
42 
43 #include <machine/trap.h>
44 #include <machine/db_machdep.h>
45 
46 #include <ddb/db_command.h>
47 #include <ddb/db_sym.h>
48 #include <ddb/db_extern.h>
49 
50 
51 int	db_active = 0;
52 db_regs_t	ddb_regs;
53 
54 static void kdbprinttrap __P((int, int));
55 
56 /*
57  * Received keyboard interrupt sequence.
58  */
59 void
60 kdb_kintr(regs)
61 	register db_regs_t *regs;
62 {
63 	if (db_active == 0 && (boothowto & RB_KDB)) {
64 		printf("\n\nkernel: keyboard interrupt\n");
65 		kdb_trap(-1, regs);
66 	}
67 }
68 
69 /*
70  * kdb_trap - field a TRACE or BPT trap
71  * Return non-zero if we "handled" the trap.
72  */
73 int
74 kdb_trap(type, regs)
75 	int	type;
76 	register db_regs_t *regs;
77 {
78 
79 	switch (type) {
80 	case T_TRACE:		/* single-step */
81 	case T_BREAKPOINT:	/* breakpoint */
82 /*      case T_WATCHPOINT:*/
83 		break;
84 	case -1:
85 		break;
86 	default:
87 		kdbprinttrap(type, 0);
88 		if (db_recover != 0) {
89 			/* This will longjmp back to db_command_loop */
90 			db_error("Caught exception in ddb.\n");
91 			/*NOTREACHED*/
92 		}
93 		/*
94 		 * Tell caller "We did NOT handle the trap."
95 		 * Caller should panic or whatever.
96 		 */
97 		return (0);
98 	}
99 
100 	/*
101 	 * We'd like to be on a separate debug stack here, but
102 	 * that's easier to do in locore.s before we get here.
103 	 * See sun3/locore.s:T_TRACE for stack switch code.
104 	 */
105 
106 	ddb_regs = *regs;
107 
108 	db_active++;
109 	cnpollc(TRUE);	/* set polling mode, unblank video */
110 
111 	db_trap(type, 0);	/* where the work happens */
112 
113 	cnpollc(FALSE);	/* resume interrupt mode */
114 	db_active--;
115 
116 	*regs = ddb_regs;
117 
118 	/*
119 	 * Indicate that single_step is for KDB.
120 	 * But lock out interrupts to prevent TRACE_KDB from setting the
121 	 * trace bit in the current SR (and trapping while exiting KDB).
122 	 */
123 	(void) spl7();
124 
125 	/*
126 	 * Tell caller "We HAVE handled the trap."
127 	 * Caller will return to locore and rte.
128 	 */
129 	return(1);
130 }
131 
132 extern char *trap_type[];
133 extern int trap_types;
134 
135 /*
136  * Print trap reason.
137  */
138 static void
139 kdbprinttrap(type, code)
140 	int	type, code;
141 {
142 	printf("kernel: ");
143 	if (type >= trap_types || type < 0)
144 		printf("type %d", type);
145 	else
146 		printf("%s", trap_type[type]);
147 	printf(" trap\n");
148 }
149 
150 void
151 cpu_Debugger()
152 {
153 	asm ("trap #15");
154 }
155 
156