1 /* $OpenBSD: db_machdep.h,v 1.15 2016/09/04 09:22:28 mpi Exp $ */ 2 /* $NetBSD: db_machdep.h,v 1.2 2003/04/29 17:06:04 scw Exp $ */ 3 4 /* 5 * Mach Operating System 6 * Copyright (c) 1991,1990 Carnegie Mellon University 7 * All Rights Reserved. 8 * 9 * Permission to use, copy, modify and distribute this software and its 10 * documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie Mellon 27 * the rights to redistribute these changes. 28 */ 29 30 #ifndef _MACHINE_DB_MACHDEP_H_ 31 #define _MACHINE_DB_MACHDEP_H_ 32 33 /* 34 * Machine-dependent defines for new kernel debugger. 35 */ 36 37 #include <sys/param.h> 38 #include <uvm/uvm_extern.h> 39 #include <machine/trap.h> 40 #include <sys/mutex.h> 41 42 typedef vaddr_t db_addr_t; /* address - unsigned */ 43 typedef long db_expr_t; /* expression - signed */ 44 45 typedef struct trapframe db_regs_t; 46 47 extern db_regs_t ddb_regs; /* register state */ 48 49 #define PC_REGS(regs) ((db_addr_t)(regs)->tf_rip) 50 #define SET_PC_REGS(regs, value) (regs)->tf_rip = (int64_t)(value) 51 52 #define BKPT_ADDR(addr) (addr) /* breakpoint address */ 53 #define BKPT_INST 0xcc /* breakpoint instruction */ 54 #define BKPT_SIZE (1) /* size of breakpoint inst */ 55 #define BKPT_SET(inst) (BKPT_INST) 56 57 #define SSF_INST 0x55 58 #define SSF_SIZE (1) 59 60 #define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_rip -= BKPT_SIZE) 61 62 #define db_clear_single_step(regs) ((regs)->tf_rflags &= ~PSL_T) 63 #define db_set_single_step(regs) ((regs)->tf_rflags |= PSL_T) 64 65 #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) 66 #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) 67 68 #define I_CALL 0xe8 69 #define I_CALLI 0xff 70 #define I_RET 0xc3 71 #define I_IRET 0xcf 72 73 #define inst_trap_return(ins) (((ins)&0xff) == I_IRET) 74 #define inst_return(ins) (((ins)&0xff) == I_RET) 75 #define inst_call(ins) (((ins)&0xff) == I_CALL || \ 76 (((ins)&0xff) == I_CALLI && \ 77 ((ins)&0x3800) == 0x1000)) 78 79 /* 80 * Constants for KGDB. 81 */ 82 typedef long kgdb_reg_t; 83 #define KGDB_NUMREGS 20 84 #define KGDB_BUFLEN 512 85 86 #define KGDB_ENTER breakpoint() 87 88 /* macro for checking if a thread has used floating-point */ 89 90 int db_ktrap(int, int, db_regs_t *); 91 92 void db_machine_init(void); 93 int db_enter_ddb(void); 94 void db_startcpu(int); 95 void db_stopcpu(int); 96 void x86_ipi_db(struct cpu_info *); 97 98 extern struct mutex ddb_mp_mutex; 99 100 #define DDB_STATE_NOT_RUNNING 0 101 #define DDB_STATE_RUNNING 1 102 #define DDB_STATE_EXITING 2 103 104 /* 105 * We define some of our own commands 106 */ 107 #define DB_MACHINE_COMMANDS 108 109 extern void db_machine_init(void); 110 111 extern void cpu_debug_dump(void); 112 113 #endif /* _MACHINE_DB_MACHDEP_H_ */ 114