1*0a6a1f1dSLionel Sambuc /* $NetBSD: db_machdep.h,v 1.30 2011/05/26 15:34:13 joerg Exp $ */ 2*0a6a1f1dSLionel Sambuc 3*0a6a1f1dSLionel Sambuc /* 4*0a6a1f1dSLionel Sambuc * Mach Operating System 5*0a6a1f1dSLionel Sambuc * Copyright (c) 1991,1990 Carnegie Mellon University 6*0a6a1f1dSLionel Sambuc * All Rights Reserved. 7*0a6a1f1dSLionel Sambuc * 8*0a6a1f1dSLionel Sambuc * Permission to use, copy, modify and distribute this software and its 9*0a6a1f1dSLionel Sambuc * documentation is hereby granted, provided that both the copyright 10*0a6a1f1dSLionel Sambuc * notice and this permission notice appear in all copies of the 11*0a6a1f1dSLionel Sambuc * software, derivative works or modified versions, and any portions 12*0a6a1f1dSLionel Sambuc * thereof, and that both notices appear in supporting documentation. 13*0a6a1f1dSLionel Sambuc * 14*0a6a1f1dSLionel Sambuc * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 15*0a6a1f1dSLionel Sambuc * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 16*0a6a1f1dSLionel Sambuc * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17*0a6a1f1dSLionel Sambuc * 18*0a6a1f1dSLionel Sambuc * Carnegie Mellon requests users of this software to return to 19*0a6a1f1dSLionel Sambuc * 20*0a6a1f1dSLionel Sambuc * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 21*0a6a1f1dSLionel Sambuc * School of Computer Science 22*0a6a1f1dSLionel Sambuc * Carnegie Mellon University 23*0a6a1f1dSLionel Sambuc * Pittsburgh PA 15213-3890 24*0a6a1f1dSLionel Sambuc * 25*0a6a1f1dSLionel Sambuc * any improvements or extensions that they make and grant Carnegie Mellon 26*0a6a1f1dSLionel Sambuc * the rights to redistribute these changes. 27*0a6a1f1dSLionel Sambuc */ 28*0a6a1f1dSLionel Sambuc 29*0a6a1f1dSLionel Sambuc #ifndef _I386_DB_MACHDEP_H_ 30*0a6a1f1dSLionel Sambuc #define _I386_DB_MACHDEP_H_ 31*0a6a1f1dSLionel Sambuc 32*0a6a1f1dSLionel Sambuc /* 33*0a6a1f1dSLionel Sambuc * Machine-dependent defines for new kernel debugger. 34*0a6a1f1dSLionel Sambuc */ 35*0a6a1f1dSLionel Sambuc 36*0a6a1f1dSLionel Sambuc #if defined(_KERNEL_OPT) 37*0a6a1f1dSLionel Sambuc #include "opt_multiprocessor.h" 38*0a6a1f1dSLionel Sambuc #endif 39*0a6a1f1dSLionel Sambuc #include <sys/param.h> 40*0a6a1f1dSLionel Sambuc #include <uvm/uvm_extern.h> 41*0a6a1f1dSLionel Sambuc #include <machine/trap.h> 42*0a6a1f1dSLionel Sambuc 43*0a6a1f1dSLionel Sambuc typedef vaddr_t db_addr_t; /* address - unsigned */ 44*0a6a1f1dSLionel Sambuc #define DDB_EXPR_FMT "l" /* expression is long */ 45*0a6a1f1dSLionel Sambuc typedef long db_expr_t; /* expression - signed */ 46*0a6a1f1dSLionel Sambuc 47*0a6a1f1dSLionel Sambuc typedef struct trapframe db_regs_t; 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc struct i386_frame { 50*0a6a1f1dSLionel Sambuc struct i386_frame *f_frame; 51*0a6a1f1dSLionel Sambuc int f_retaddr; 52*0a6a1f1dSLionel Sambuc int f_arg0; 53*0a6a1f1dSLionel Sambuc }; 54*0a6a1f1dSLionel Sambuc 55*0a6a1f1dSLionel Sambuc #ifndef MULTIPROCESSOR 56*0a6a1f1dSLionel Sambuc extern db_regs_t ddb_regs; /* register state */ 57*0a6a1f1dSLionel Sambuc #define DDB_REGS (&ddb_regs) 58*0a6a1f1dSLionel Sambuc #else 59*0a6a1f1dSLionel Sambuc extern db_regs_t *ddb_regp; 60*0a6a1f1dSLionel Sambuc #define DDB_REGS (ddb_regp) 61*0a6a1f1dSLionel Sambuc #define ddb_regs (*ddb_regp) 62*0a6a1f1dSLionel Sambuc #endif 63*0a6a1f1dSLionel Sambuc 64*0a6a1f1dSLionel Sambuc #define PC_REGS(regs) ((regs)->tf_eip) 65*0a6a1f1dSLionel Sambuc 66*0a6a1f1dSLionel Sambuc #define BKPT_ADDR(addr) (addr) /* breakpoint address */ 67*0a6a1f1dSLionel Sambuc #define BKPT_INST 0xcc /* breakpoint instruction */ 68*0a6a1f1dSLionel Sambuc #define BKPT_SIZE (1) /* size of breakpoint inst */ 69*0a6a1f1dSLionel Sambuc #define BKPT_SET(inst, addr) (BKPT_INST) 70*0a6a1f1dSLionel Sambuc 71*0a6a1f1dSLionel Sambuc #define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_eip -= BKPT_SIZE) 72*0a6a1f1dSLionel Sambuc 73*0a6a1f1dSLionel Sambuc #define db_clear_single_step(regs) ((regs)->tf_eflags &= ~PSL_T) 74*0a6a1f1dSLionel Sambuc #define db_set_single_step(regs) ((regs)->tf_eflags |= PSL_T) 75*0a6a1f1dSLionel Sambuc 76*0a6a1f1dSLionel Sambuc #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) 77*0a6a1f1dSLionel Sambuc #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) 78*0a6a1f1dSLionel Sambuc 79*0a6a1f1dSLionel Sambuc #define I_CALL 0xe8 80*0a6a1f1dSLionel Sambuc #define I_CALLI 0xff 81*0a6a1f1dSLionel Sambuc #define I_RET 0xc3 82*0a6a1f1dSLionel Sambuc #define I_IRET 0xcf 83*0a6a1f1dSLionel Sambuc 84*0a6a1f1dSLionel Sambuc #define inst_trap_return(ins) (((ins)&0xff) == I_IRET) 85*0a6a1f1dSLionel Sambuc #define inst_return(ins) (((ins)&0xff) == I_RET) 86*0a6a1f1dSLionel Sambuc #define inst_call(ins) (((ins)&0xff) == I_CALL || \ 87*0a6a1f1dSLionel Sambuc (((ins)&0xff) == I_CALLI && \ 88*0a6a1f1dSLionel Sambuc ((ins)&0x3800) == 0x1000)) 89*0a6a1f1dSLionel Sambuc #define inst_load(ins) 0 90*0a6a1f1dSLionel Sambuc #define inst_store(ins) 0 91*0a6a1f1dSLionel Sambuc 92*0a6a1f1dSLionel Sambuc /* access capability and access macros */ 93*0a6a1f1dSLionel Sambuc 94*0a6a1f1dSLionel Sambuc #define DB_ACCESS_LEVEL 2 /* access any space */ 95*0a6a1f1dSLionel Sambuc #define DB_CHECK_ACCESS(addr,size,task) \ 96*0a6a1f1dSLionel Sambuc db_check_access(addr,size,task) 97*0a6a1f1dSLionel Sambuc #define DB_PHYS_EQ(task1,addr1,task2,addr2) \ 98*0a6a1f1dSLionel Sambuc db_phys_eq(task1,addr1,task2,addr2) 99*0a6a1f1dSLionel Sambuc #define DB_VALID_KERN_ADDR(addr) \ 100*0a6a1f1dSLionel Sambuc ((addr) >= VM_MIN_KERNEL_ADDRESS && \ 101*0a6a1f1dSLionel Sambuc (addr) < VM_MAX_KERNEL_ADDRESS) 102*0a6a1f1dSLionel Sambuc #define DB_VALID_ADDRESS(addr,user) \ 103*0a6a1f1dSLionel Sambuc ((!(user) && DB_VALID_KERN_ADDR(addr)) || \ 104*0a6a1f1dSLionel Sambuc ((user) && (addr) < VM_MAX_ADDRESS)) 105*0a6a1f1dSLionel Sambuc 106*0a6a1f1dSLionel Sambuc #if 0 107*0a6a1f1dSLionel Sambuc bool db_check_access(vaddr_t, int, task_t); 108*0a6a1f1dSLionel Sambuc bool db_phys_eq(task_t, vaddr_t, task_t, vaddr_t); 109*0a6a1f1dSLionel Sambuc #endif 110*0a6a1f1dSLionel Sambuc 111*0a6a1f1dSLionel Sambuc /* macros for printing OS server dependent task name */ 112*0a6a1f1dSLionel Sambuc 113*0a6a1f1dSLionel Sambuc #define DB_TASK_NAME(task) db_task_name(task) 114*0a6a1f1dSLionel Sambuc #define DB_TASK_NAME_TITLE "COMMAND " 115*0a6a1f1dSLionel Sambuc #define DB_TASK_NAME_LEN 23 116*0a6a1f1dSLionel Sambuc #define DB_NULL_TASK_NAME "? " 117*0a6a1f1dSLionel Sambuc 118*0a6a1f1dSLionel Sambuc /* 119*0a6a1f1dSLionel Sambuc * Constants for KGDB. 120*0a6a1f1dSLionel Sambuc */ 121*0a6a1f1dSLionel Sambuc typedef long kgdb_reg_t; 122*0a6a1f1dSLionel Sambuc #define KGDB_NUMREGS 16 123*0a6a1f1dSLionel Sambuc #define KGDB_BUFLEN 512 124*0a6a1f1dSLionel Sambuc 125*0a6a1f1dSLionel Sambuc #if 0 126*0a6a1f1dSLionel Sambuc void db_task_name(/* task_t */); 127*0a6a1f1dSLionel Sambuc #endif 128*0a6a1f1dSLionel Sambuc 129*0a6a1f1dSLionel Sambuc /* macro for checking if a thread has used floating-point */ 130*0a6a1f1dSLionel Sambuc 131*0a6a1f1dSLionel Sambuc #define db_thread_fp_used(thread) ((thread)->pcb->ims.ifps != 0) 132*0a6a1f1dSLionel Sambuc 133*0a6a1f1dSLionel Sambuc int kdb_trap(int, int, db_regs_t *); 134*0a6a1f1dSLionel Sambuc 135*0a6a1f1dSLionel Sambuc /* 136*0a6a1f1dSLionel Sambuc * We define some of our own commands 137*0a6a1f1dSLionel Sambuc */ 138*0a6a1f1dSLionel Sambuc #ifdef _KERNEL 139*0a6a1f1dSLionel Sambuc #define DB_MACHINE_COMMANDS 140*0a6a1f1dSLionel Sambuc #endif 141*0a6a1f1dSLionel Sambuc 142*0a6a1f1dSLionel Sambuc /* 143*0a6a1f1dSLionel Sambuc * We use Elf32 symbols in DDB. 144*0a6a1f1dSLionel Sambuc */ 145*0a6a1f1dSLionel Sambuc #define DB_ELF_SYMBOLS 146*0a6a1f1dSLionel Sambuc #define DB_ELFSIZE 32 147*0a6a1f1dSLionel Sambuc 148*0a6a1f1dSLionel Sambuc extern void db_machine_init(void); 149*0a6a1f1dSLionel Sambuc 150*0a6a1f1dSLionel Sambuc extern void cpu_debug_dump(void); 151*0a6a1f1dSLionel Sambuc 152*0a6a1f1dSLionel Sambuc /* i386/db_machdep.c */ 153*0a6a1f1dSLionel Sambuc bool db_intrstack_p(const void *); 154*0a6a1f1dSLionel Sambuc 155*0a6a1f1dSLionel Sambuc #endif /* _I386_DB_MACHDEP_H_ */ 156