Home | History | Annotate | Line # | Download | only in hppa
      1 /*	$NetBSD: db_interface.c,v 1.30 2026/11/10 03:43:25 thorpej 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.30 2026/11/10 03:43:25 thorpej 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 void
     61 cpu_Debugger(void)
     62 {
     63 	__asm volatile ("break	%0, %1"
     64 			  :: "i" (HPPA_BREAK_KERNEL), "i" (HPPA_BREAK_KGDB));
     65 }
     66 
     67 /*
     68  * Print trap reason.
     69  */
     70 void
     71 kdbprinttrap(int type, int code)
     72 {
     73 	db_printf("kernel: ");
     74 	if (type >= trap_types || type < 0)
     75 		db_printf("type %d", type);
     76 	else
     77 		db_printf("%s", trap_type[type]);
     78 	db_printf(" trap, code=%x\n", code);
     79 }
     80 
     81 /*
     82  *  kdb_trap - field a BPT trap
     83  */
     84 int
     85 kdb_trap(int type, int code, db_regs_t *regs)
     86 {
     87 	int s;
     88 
     89 	switch (type) {
     90 	case T_RECOVERY:
     91 	case T_IBREAK:
     92 	case T_DBREAK:
     93 	case -1:
     94 		break;
     95 	default:
     96 		if (!db_onpanic && db_recover == 0)
     97 			return 0;
     98 
     99 		kdbprinttrap(type, code);
    100 		if (db_recover != 0) {
    101 			db_error("Caught exception in DDB; continuing...\n");
    102 			/* NOT REACHED */
    103 		}
    104 	}
    105 
    106 	/* XXX Should switch to kdb`s own stack here. */
    107 
    108 	ddb_regs = *regs;
    109 
    110 	s = splhigh();
    111 	db_active++;
    112 	cnpollc(true);
    113 	db_trap(type, code);
    114 	cnpollc(false);
    115 	db_active--;
    116 	splx(s);
    117 
    118 	*regs = ddb_regs;
    119 	return 1;
    120 }
    121 
    122 /*
    123  *  Validate an address for use as a breakpoint.
    124  *  Any address is allowed for now.
    125  */
    126 int
    127 db_valid_breakpoint(db_addr_t addr)
    128 {
    129 	return 1;
    130 }
    131