Home | History | Annotate | Line # | Download | only in include
      1 /* $NetBSD: db_machdep.h,v 1.4 2018/08/05 18:42:48 reinoud Exp $ */
      2 
      3 #ifndef _USERMODE_DB_MACHDEP_H
      4 #define _USERMODE_DB_MACHDEP_H
      5 
      6 #include <sys/ucontext.h>
      7 #include <machine/trap.h>
      8 #include <machine/psl.h>
      9 #include <machine/ucontext.h>
     10 
     11 typedef long int db_expr_t;
     12 typedef vaddr_t db_addr_t;
     13 typedef ucontext_t db_regs_t;
     14 
     15 extern void breakpoint(void);
     16 extern void kgdb_kernel_trap(int signo,
     17 	vaddr_t pc, vaddr_t va, ucontext_t *ucp);
     18 extern int db_validate_address(vaddr_t addr);
     19 
     20 /* same as amd64 */
     21 #ifndef MULTIPROCESSOR
     22 extern db_regs_t ddb_regs;	/* register state */
     23 #define	DDB_REGS	(&ddb_regs)
     24 #else
     25 extern db_regs_t *ddb_regp;
     26 #define DDB_REGS	(ddb_regp)
     27 #define ddb_regs	(*ddb_regp)
     28 #endif
     29 
     30 /* copied here in verbatim to remove dependencies */
     31 #if defined(__i386__)
     32 
     33 #define BKPT_SIZE 1
     34 #define BKPT_INST 0xcc		/* breakpoint instruction */
     35 #define	BKPT_ADDR(addr)	(addr)
     36 #define BKPT_SET(inst, addr) (BKPT_INST)
     37 
     38 #define	db_clear_single_step(regs)	_UC_MACHINE_EFLAGS(regs) &= ~PSL_T
     39 #define	db_set_single_step(regs)	_UC_MACHINE_EFLAGS(regs) |= PSL_T
     40 
     41 #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BPTFLT)
     42 #define IS_WATCHPOINT_TRAP(type, code)	((type) == T_TRCTRAP && (code) & 15)
     43 
     44 #define	I_CALL		0xe8
     45 #define	I_CALLI		0xff
     46 #define	I_RET		0xc3
     47 #define	I_IRET		0xcf
     48 
     49 #define	inst_trap_return(ins)	(((ins)&0xff) == I_IRET)
     50 #define	inst_return(ins)	(((ins)&0xff) == I_RET)
     51 #define	inst_call(ins)		(((ins)&0xff) == I_CALL || \
     52 				 (((ins)&0xff) == I_CALLI && \
     53 				  ((ins)&0x3800) == 0x1000))
     54 #define inst_load(ins)		0
     55 #define inst_store(ins)		0
     56 
     57 typedef	int		kgdb_reg_t;
     58 #define	KGDB_NUMREGS	16
     59 #define	KGDB_BUFLEN	512
     60 
     61 /* copied here in verbatim to remove dependencies */
     62 #elif defined(__x86_64__)
     63 
     64 #define	DDB_EXPR_FMT	"l"	/* expression is long */
     65 #define BKPT_SIZE 1
     66 #define BKPT_INST 0xcc		/* breakpoint instruction */
     67 #define	BKPT_ADDR(addr)	(addr)
     68 #define BKPT_SET(inst, addr) (BKPT_INST)
     69 
     70 #define db_clear_single_step(regs) _UC_MACHINE_RFLAGS(regs) &= ~PSL_T
     71 #define db_set_single_step(regs)   _UC_MACHINE_RFLAGS(regs) |=  PSL_T
     72 #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT)
     73 #define IS_WATCHPOINT_TRAP(type, code) (0)
     74 
     75 #define	I_CALL		0xe8
     76 #define	I_CALLI		0xff
     77 #define	I_RET		0xc3
     78 #define	I_IRET		0xcf
     79 
     80 #define	inst_trap_return(ins)	(((ins)&0xff) == I_IRET)
     81 #define	inst_return(ins)	(((ins)&0xff) == I_RET)
     82 #define	inst_call(ins)		(((ins)&0xff) == I_CALL || \
     83 				 (((ins)&0xff) == I_CALLI && \
     84 				  ((ins)&0x3800) == 0x1000))
     85 #define inst_load(ins)		(__USE(ins), 0)
     86 #define inst_store(ins)		(__USE(ins), 0)
     87 
     88 typedef	long		kgdb_reg_t;
     89 #define	KGDB_NUMREGS	20
     90 #define	KGDB_BUFLEN	1024
     91 
     92 #elif defined(__arm__)
     93 #error port kgdb for arm
     94 #else
     95 #error port me
     96 #endif
     97 
     98 /* commonly #define'd in db_machdep.h */
     99 #define PC_REGS(regs)	(_UC_MACHINE_PC(regs))
    100 #define PC_ADVANCE(r)	(_UC_MACHINE_PC(r) += BKPT_SIZE)
    101 #define FIXUP_PC_AFTER_BREAK(r) (_UC_MACHINE_PC(r) -= BKPT_SIZE)
    102 
    103 #endif
    104