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