1 /* $OpenBSD: db_machdep.h,v 1.16 2010/11/27 19:57:23 miod Exp $ */ 2 3 /* 4 * Copyright (c) 1998-2004 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef _MACHINE_DB_MACHDEP_H_ 30 #define _MACHINE_DB_MACHDEP_H_ 31 32 #include <uvm/uvm_extern.h> 33 34 #define DB_ELF_SYMBOLS 35 #define DB_ELFSIZE 32 36 37 /* types the generic ddb module needs */ 38 typedef vaddr_t db_addr_t; 39 typedef long db_expr_t; 40 41 typedef struct trapframe db_regs_t; 42 extern db_regs_t ddb_regs; 43 #define DDB_REGS (&ddb_regs) 44 45 #define PC_REGS(regs) ((db_addr_t)(regs)->tf_iioq_head) 46 #define SET_PC_REGS(regs, value) \ 47 do { \ 48 (regs)->tf_iioq_tail = 4 + \ 49 ((regs)->tf_iioq_head = (value)); \ 50 } while (0) 51 52 /* Breakpoint related definitions */ 53 #define BKPT_INST 0x00010000 /* break 0,8 */ 54 #define BKPT_SIZE sizeof(int) 55 #define BKPT_SET(inst) BKPT_INST 56 57 #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_IBREAK) 58 #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_DBREAK) 59 60 #define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_iioq_head -= sizeof(int)) 61 62 #define DB_VALID_BREAKPOINT(addr) db_valid_breakpoint(addr) 63 64 static __inline int inst_call(u_int ins) { 65 return (ins & 0xfc00e000) == 0xe8000000 || 66 (ins & 0xfc00e000) == 0xe8004000 || 67 (ins & 0xfc000000) == 0xe4000000; 68 } 69 static __inline int inst_branch(u_int ins) { 70 return (ins & 0xf0000000) == 0xe0000000 || 71 (ins & 0xf0000000) == 0xc0000000 || 72 (ins & 0xf0000000) == 0xa0000000 || 73 (ins & 0xf0000000) == 0x80000000; 74 } 75 static __inline int inst_return(u_int ins) { 76 return (ins & 0xfc00e000) == 0xe800c000 || 77 (ins & 0xfc000000) == 0xe0000000; 78 } 79 static __inline int inst_trap_return(u_int ins) { 80 return (ins & 0xfc001fc0) == 0x00000ca0; 81 } 82 83 #if 0 84 #define db_clear_single_step(r) ((r)->tf_flags &= ~(PSL_Z)) 85 #define db_set_single_step(r) ((r)->tf_flags |= (PSL_Z)) 86 #else 87 #define SOFTWARE_SSTEP 1 88 #define SOFTWARE_SSTEP_EMUL 1 89 90 static __inline db_addr_t 91 next_instr_address(db_addr_t addr, int b) { 92 return (addr + 4); 93 } 94 95 #define branch_taken(ins,pc,f,regs) branch_taken1(ins, pc, regs) 96 static __inline db_addr_t 97 branch_taken1(int ins, db_addr_t pc, db_regs_t *regs) { 98 return (pc); 99 } 100 101 #endif 102 103 int db_valid_breakpoint(db_addr_t); 104 int kdb_trap(int, int, db_regs_t *); 105 106 #endif /* _MACHINE_DB_MACHDEP_H_ */ 107