Home | History | Annotate | Line # | Download | only in include
db_machdep.h revision 1.37.2.1
      1  1.37.2.1   thorpej /* $NetBSD: db_machdep.h,v 1.37.2.1 2021/06/17 04:46:22 thorpej Exp $ */
      2       1.1  jonathan 
      3       1.2  jonathan /*
      4       1.2  jonathan  * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
      5       1.2  jonathan  * All rights reserved.
      6       1.2  jonathan  *
      7       1.2  jonathan  * Redistribution and use in source and binary forms, with or without
      8       1.2  jonathan  * modification, are permitted provided that the following conditions
      9       1.2  jonathan  * are met:
     10       1.2  jonathan  * 1. Redistributions of source code must retain the above copyright
     11       1.2  jonathan  *    notice, this list of conditions and the following disclaimer.
     12       1.2  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.2  jonathan  *    notice, this list of conditions and the following disclaimer in the
     14       1.2  jonathan  *    documentation and/or other materials provided with the distribution.
     15       1.2  jonathan  * 3. All advertising materials mentioning features or use of this software
     16       1.2  jonathan  *    must display the following acknowledgement:
     17       1.2  jonathan  *      This product includes software developed by Jonathan Stone for
     18       1.2  jonathan  *      the NetBSD Project.
     19       1.2  jonathan  * 4. The name of the author may not be used to endorse or promote products
     20       1.2  jonathan  *    derived from this software without specific prior written permission.
     21       1.2  jonathan  *
     22       1.2  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
     23       1.2  jonathan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24       1.2  jonathan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25       1.2  jonathan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
     26       1.2  jonathan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27       1.2  jonathan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28       1.2  jonathan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.2  jonathan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30       1.2  jonathan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31       1.2  jonathan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.2  jonathan  * SUCH DAMAGE.
     33       1.2  jonathan  */
     34       1.1  jonathan #ifndef	_MIPS_DB_MACHDEP_H_
     35       1.1  jonathan #define	_MIPS_DB_MACHDEP_H_
     36       1.1  jonathan 
     37      1.33       mrg #include <sys/types.h>
     38      1.33       mrg #include <sys/stdbool.h>
     39      1.33       mrg 
     40       1.9       mrg #include <uvm/uvm_param.h>		/* XXX  boolean_t */
     41      1.33       mrg 
     42       1.1  jonathan #include <mips/trap.h>			/* T_BREAK */
     43       1.3  jonathan #include <mips/reg.h>			/* register state */
     44       1.3  jonathan #include <mips/regnum.h>		/* symbolic register indices */
     45      1.23     rmind #include <mips/pcb.h>
     46       1.1  jonathan 
     47      1.28      matt #define	DB_ELF_SYMBOLS
     48       1.1  jonathan 
     49       1.5  nisimura typedef	vaddr_t		db_addr_t;	/* address - unsigned */
     50      1.29      matt #ifdef __mips_n32
     51      1.29      matt #define	DDB_EXPR_FMT	"ll"		/* expression is long long */
     52      1.29      matt typedef	int64_t		db_expr_t;	/* expression - signed */
     53      1.29      matt #else
     54      1.27     joerg #define	DDB_EXPR_FMT	"l"		/* expression is long */
     55       1.1  jonathan typedef	long		db_expr_t;	/* expression - signed */
     56      1.29      matt #endif
     57       1.1  jonathan 
     58      1.24      matt typedef struct reg db_regs_t;
     59       1.1  jonathan 
     60      1.13    simonb extern db_regs_t	ddb_regs;	/* register state */
     61       1.1  jonathan #define	DDB_REGS	(&ddb_regs)
     62       1.1  jonathan 
     63      1.24      matt #define	PC_REGS(regs)	((regs)->r_regs[_R_PC])
     64       1.4    mhitch 
     65      1.32    simonb #define	PC_ADVANCE(regs) do {						\
     66      1.24      matt 	if ((db_get_value((regs)->r_regs[_R_PC], sizeof(int), false) &\
     67       1.4    mhitch 	     0xfc00003f) == 0xd)					\
     68      1.24      matt 		(regs)->r_regs[_R_PC] += BKPT_SIZE;			\
     69      1.10     jeffs } while(0)
     70       1.1  jonathan 
     71      1.10     jeffs /* Similar to PC_ADVANCE(), except only advance on cpu_Debugger()'s bpt */
     72      1.32    simonb #define	PC_BREAK_ADVANCE(regs) do {					 \
     73      1.24      matt 	if (db_get_value((regs)->r_regs[_R_PC], sizeof(int), false) == 0xd) \
     74      1.24      matt 		(regs)->r_regs[_R_PC] += BKPT_SIZE;			 \
     75      1.10     jeffs } while(0)
     76      1.10     jeffs 
     77      1.15       scw #define	BKPT_ADDR(addr)	(addr)		/* breakpoint address */
     78      1.32    simonb #define	BKPT_INST	0x0001000D
     79       1.1  jonathan #define	BKPT_SIZE	(4)		/* size of breakpoint inst */
     80      1.18    cherry #define	BKPT_SET(inst, addr)	(BKPT_INST)
     81       1.1  jonathan 
     82       1.1  jonathan #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BREAK)
     83      1.32    simonb #define	IS_WATCHPOINT_TRAP(type, code)	(0)	/* XXX mips3 watchpoint */
     84       1.1  jonathan 
     85       1.1  jonathan /*
     86      1.35    simonb  * Interface to disassembly (shared with mdb)
     87       1.1  jonathan  */
     88      1.21      matt db_addr_t	db_disasm_insn(int insn, db_addr_t loc, bool altfmt);
     89       1.1  jonathan 
     90       1.1  jonathan /*
     91       1.1  jonathan  * Entrypoints to DDB for kernel, keyboard drivers, init hook
     92       1.1  jonathan  */
     93      1.14    simonb void 	kdb_kbd_trap(db_regs_t *);
     94  1.37.2.1   thorpej int 	kdb_trap(int, struct reg *);
     95      1.24      matt 
     96      1.24      matt static inline void
     97      1.24      matt db_set_ddb_regs(int type, struct reg *regs)
     98      1.24      matt {
     99      1.24      matt 	ddb_regs = *regs;
    100      1.24      matt }
    101       1.1  jonathan 
    102      1.37    simonb /*
    103      1.37    simonb  * Helper functions for fetching 32-bit and 64-bit kernel memory.
    104      1.37    simonb  */
    105      1.37    simonb bool		kdbpeek(vaddr_t, unsigned *);
    106  1.37.2.1   thorpej mips_reg_t	kdbrpeek(vaddr_t, size_t);
    107      1.37    simonb 
    108       1.1  jonathan 
    109       1.1  jonathan /*
    110      1.10     jeffs  * Constants for KGDB.
    111      1.10     jeffs  */
    112      1.10     jeffs typedef	mips_reg_t	kgdb_reg_t;
    113      1.10     jeffs #define	KGDB_NUMREGS	90
    114      1.10     jeffs #define	KGDB_BUFLEN	1024
    115      1.10     jeffs 
    116      1.10     jeffs /*
    117       1.1  jonathan  * MIPS cpus have no hardware single-step.
    118       1.1  jonathan  */
    119      1.32    simonb #define	SOFTWARE_SSTEP
    120       1.1  jonathan 
    121      1.32    simonb #define	inst_trap_return(ins)	((ins)&0)
    122      1.10     jeffs 
    123      1.20   thorpej bool	inst_branch(int inst);
    124      1.20   thorpej bool	inst_call(int inst);
    125      1.20   thorpej bool	inst_return(int inst);
    126      1.20   thorpej bool	inst_load(int inst);
    127      1.20   thorpej bool	inst_store(int inst);
    128      1.20   thorpej bool	inst_unconditional_flow_transfer(int inst);
    129      1.14    simonb db_addr_t branch_taken(int inst, db_addr_t pc, db_regs_t *regs);
    130      1.20   thorpej db_addr_t next_instr_address(db_addr_t pc, bool bd);
    131       1.1  jonathan 
    132      1.25      matt bool ddb_running_on_this_cpu_p(void);
    133      1.25      matt bool ddb_running_on_any_cpu_p(void);
    134      1.24      matt void db_resume_others(void);
    135      1.34    simonb void db_mips_stack_trace(void *, void *, void (*pr)(const char *, ...));
    136      1.24      matt 
    137      1.36    simonb 
    138      1.36    simonb #ifdef _KERNEL
    139      1.36    simonb /*
    140      1.36    simonb  * Optional function to perform machine- or cpu-specific reset.
    141      1.36    simonb  * Called from ddb "machine reset".
    142      1.36    simonb  */
    143      1.31    simonb extern void (*cpu_reset_address)(void);
    144      1.31    simonb 
    145       1.1  jonathan /*
    146      1.10     jeffs  * We have machine-dependent commands.
    147       1.1  jonathan  */
    148      1.32    simonb #define	DB_MACHINE_COMMANDS
    149      1.33       mrg #endif
    150       1.1  jonathan 
    151      1.34    simonb #define	db_stacktrace_print(prfunc) \
    152      1.34    simonb     db_mips_stack_trace(__builtin_return_address(0), \
    153      1.34    simonb 	__builtin_frame_address(0), prfunc)
    154      1.34    simonb 
    155       1.1  jonathan #endif	/* _MIPS_DB_MACHDEP_H_ */
    156