Home | History | Annotate | Line # | Download | only in hppa
      1 /*	$NetBSD: db_interface.c,v 1.28 2022/10/26 23:38:07 riastradh Exp $	*/
      2 
      3 /*	$OpenBSD: db_interface.c,v 1.16 2001/03/22 23:31:45 mickey Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1999-2003 Michael Shalayeff
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28  * THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.28 2022/10/26 23:38:07 riastradh Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/proc.h>
     37 
     38 #include <machine/db_machdep.h>
     39 #include <machine/frame.h>
     40 #include <machine/cpufunc.h>
     41 
     42 #include <ddb/db_access.h>
     43 #include <ddb/db_active.h>
     44 #include <ddb/db_command.h>
     45 #include <ddb/db_output.h>
     46 #include <ddb/db_run.h>
     47 #include <ddb/db_sym.h>
     48 #include <ddb/db_variables.h>
     49 #include <ddb/db_extern.h>
     50 #include <ddb/db_interface.h>
     51 #include <ddb/ddbvar.h>
     52 
     53 #include <dev/cons.h>
     54 
     55 void kdbprinttrap(int, int);
     56 
     57 extern const char *trap_type[];
     58 extern int trap_types;
     59 
     60 int db_active = 0;
     61 
     62 void
     63 cpu_Debugger(void)
     64 {
     65 	__asm volatile ("break	%0, %1"
     66 			  :: "i" (HPPA_BREAK_KERNEL), "i" (HPPA_BREAK_KGDB));
     67 }
     68 
     69 /*
     70  * Print trap reason.
     71  */
     72 void
     73 kdbprinttrap(int type, int code)
     74 {
     75 	db_printf("kernel: ");
     76 	if (type >= trap_types || type < 0)
     77 		db_printf("type %d", type);
     78 	else
     79 		db_printf("%s", trap_type[type]);
     80 	db_printf(" trap, code=%x\n", code);
     81 }
     82 
     83 /*
     84  *  kdb_trap - field a BPT trap
     85  */
     86 int
     87 kdb_trap(int type, int code, db_regs_t *regs)
     88 {
     89 	int s;
     90 
     91 	switch (type) {
     92 	case T_RECOVERY:
     93 	case T_IBREAK:
     94 	case T_DBREAK:
     95 	case -1:
     96 		break;
     97 	default:
     98 		if (!db_onpanic && db_recover == 0)
     99 			return 0;
    100 
    101 		kdbprinttrap(type, code);
    102 		if (db_recover != 0) {
    103 			db_error("Caught exception in DDB; continuing...\n");
    104 			/* NOT REACHED */
    105 		}
    106 	}
    107 
    108 	/* XXX Should switch to kdb`s own stack here. */
    109 
    110 	ddb_regs = *regs;
    111 
    112 	s = splhigh();
    113 	db_active++;
    114 	cnpollc(true);
    115 	db_trap(type, code);
    116 	cnpollc(false);
    117 	db_active--;
    118 	splx(s);
    119 
    120 	*regs = ddb_regs;
    121 	return 1;
    122 }
    123 
    124 /*
    125  *  Validate an address for use as a breakpoint.
    126  *  Any address is allowed for now.
    127  */
    128 int
    129 db_valid_breakpoint(db_addr_t addr)
    130 {
    131 	return 1;
    132 }
    133