1 /* $NetBSD: db_machdep.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */ 2 3 /*- 4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matt Thomas of 3am Software Foundry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 #ifndef _RISCV_DB_MACHDEP_H_ 32 #define _RISCV_DB_MACHDEP_H_ 33 34 #include <riscv/locore.h> /* T_BREAK */ 35 36 #define DB_ELF_SYMBOLS 37 #ifndef DB_ELFSIZE 38 #define DB_ELFSIZE 32 39 #endif 40 41 typedef vaddr_t db_addr_t; /* address - unsigned */ 42 #define DDB_EXPR_FMT "l" /* expression is long */ 43 typedef long db_expr_t; /* expression - signed */ 44 45 typedef struct trapframe db_regs_t; 46 47 extern const uint32_t __cpu_Debugger_insn[1]; 48 #define DDB_REGS (curcpu()->ci_ddb_regs) 49 50 #define PC_REGS(tf) ((tf)->tf_pc) 51 52 #define PC_ADVANCE(tf) do { \ 53 if (db_get_value((tf)->tf_pc, sizeof(uint32_t), false) == BKPT_INST) \ 54 (tf)->tf_pc += BKPT_SIZE; \ 55 } while(0) 56 57 /* Similar to PC_ADVANCE(), except only advance on cpu_Debugger()'s bpt */ 58 #define PC_BREAK_ADVANCE(tf) do { \ 59 if ((tf)->tf_pc == (register_t) __cpu_Debugger_insn) \ 60 (tf)->tf_pc += BKPT_SIZE; \ 61 } while(0) 62 63 #define BKPT_ADDR(addr) (addr) /* breakpoint address */ 64 #define BKPT_INST 0x00100073 65 #define BKPT_SIZE (sizeof(uint32_t)) /* size of breakpoint inst */ 66 #define BKPT_SET(inst, addr) (BKPT_INST) 67 68 #define IS_BREAKPOINT_TRAP(type, code) ((type) == CAUSE_BREAKPOINT) 69 #define IS_WATCHPOINT_TRAP(type, code) (0) 70 71 /* 72 * Interface to disassembly 73 */ 74 db_addr_t db_disasm_insn(uint32_t insn, db_addr_t loc, bool altfmt); 75 76 77 /* 78 * Entrypoints to DDB for kernel, keyboard drivers, init hook 79 */ 80 void kdb_kbd_trap(db_regs_t *); 81 int kdb_trap(int type, struct trapframe *); 82 83 static inline void 84 db_set_ddb_regs(int type, struct trapframe *tf) 85 { 86 *curcpu()->ci_ddb_regs = *tf; 87 } 88 89 90 /* 91 * Constants for KGDB. 92 */ 93 typedef register_t kgdb_reg_t; 94 #define KGDB_NUMREGS 90 95 #define KGDB_BUFLEN 1024 96 97 /* 98 * RISCV cpus have no hardware single-step. 99 */ 100 #define SOFTWARE_SSTEP 101 102 #define inst_trap_return(ins) ((ins)&0) 103 104 bool inst_branch(uint32_t inst); 105 bool inst_call(uint32_t inst); 106 bool inst_return(uint32_t inst); 107 bool inst_load(uint32_t inst); 108 bool inst_store(uint32_t inst); 109 bool inst_unconditional_flow_transfer(uint32_t inst); 110 db_addr_t branch_taken(uint32_t inst, db_addr_t pc, db_regs_t *regs); 111 db_addr_t next_instr_address(db_addr_t pc, bool bd); 112 113 bool ddb_running_on_this_cpu_p(void); 114 bool ddb_running_on_any_cpu_p(void); 115 void db_resume_others(void); 116 117 #if 0 118 /* 119 * We have machine-dependent commands. 120 */ 121 #define DB_MACHINE_COMMANDS 122 #endif 123 124 #endif /* _RISCV_DB_MACHDEP_H_ */ 125