1 /*- 2 * Copyright (c) 2015 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Semihalf under 6 * the sponsorship of the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 #include <sys/param.h> 33 #include <sys/proc.h> 34 #include <vm/vm.h> 35 #include <vm/pmap.h> 36 #include <vm/vm_map.h> 37 38 #ifdef KDB 39 #include <sys/kdb.h> 40 #endif 41 42 #include <ddb/ddb.h> 43 #include <ddb/db_variables.h> 44 45 #include <machine/cpu.h> 46 #include <machine/pcb.h> 47 #include <machine/stack.h> 48 #include <machine/vmparam.h> 49 50 static int 51 db_frame(struct db_variable *vp, db_expr_t *valuep, int op) 52 { 53 long *reg; 54 55 if (kdb_frame == NULL) 56 return (0); 57 58 reg = (long *)((uintptr_t)kdb_frame + (db_expr_t)vp->valuep); 59 if (op == DB_VAR_GET) 60 *valuep = *reg; 61 else 62 *reg = *valuep; 63 return (1); 64 } 65 66 #define DB_OFFSET(x) (db_expr_t *)offsetof(struct trapframe, x) 67 struct db_variable db_regs[] = { 68 { "spsr", DB_OFFSET(tf_spsr), db_frame }, 69 { "x0", DB_OFFSET(tf_x[0]), db_frame }, 70 { "x1", DB_OFFSET(tf_x[1]), db_frame }, 71 { "x2", DB_OFFSET(tf_x[2]), db_frame }, 72 { "x3", DB_OFFSET(tf_x[3]), db_frame }, 73 { "x4", DB_OFFSET(tf_x[4]), db_frame }, 74 { "x5", DB_OFFSET(tf_x[5]), db_frame }, 75 { "x6", DB_OFFSET(tf_x[6]), db_frame }, 76 { "x7", DB_OFFSET(tf_x[7]), db_frame }, 77 { "x8", DB_OFFSET(tf_x[8]), db_frame }, 78 { "x9", DB_OFFSET(tf_x[9]), db_frame }, 79 { "x10", DB_OFFSET(tf_x[10]), db_frame }, 80 { "x11", DB_OFFSET(tf_x[11]), db_frame }, 81 { "x12", DB_OFFSET(tf_x[12]), db_frame }, 82 { "x13", DB_OFFSET(tf_x[13]), db_frame }, 83 { "x14", DB_OFFSET(tf_x[14]), db_frame }, 84 { "x15", DB_OFFSET(tf_x[15]), db_frame }, 85 { "x16", DB_OFFSET(tf_x[16]), db_frame }, 86 { "x17", DB_OFFSET(tf_x[17]), db_frame }, 87 { "x18", DB_OFFSET(tf_x[18]), db_frame }, 88 { "x19", DB_OFFSET(tf_x[19]), db_frame }, 89 { "x20", DB_OFFSET(tf_x[20]), db_frame }, 90 { "x21", DB_OFFSET(tf_x[21]), db_frame }, 91 { "x22", DB_OFFSET(tf_x[22]), db_frame }, 92 { "x23", DB_OFFSET(tf_x[23]), db_frame }, 93 { "x24", DB_OFFSET(tf_x[24]), db_frame }, 94 { "x25", DB_OFFSET(tf_x[25]), db_frame }, 95 { "x26", DB_OFFSET(tf_x[26]), db_frame }, 96 { "x27", DB_OFFSET(tf_x[27]), db_frame }, 97 { "x28", DB_OFFSET(tf_x[28]), db_frame }, 98 { "x29", DB_OFFSET(tf_x[29]), db_frame }, 99 { "lr", DB_OFFSET(tf_lr), db_frame }, 100 { "elr", DB_OFFSET(tf_elr), db_frame }, 101 { "sp", DB_OFFSET(tf_sp), db_frame }, 102 }; 103 104 struct db_variable *db_eregs = db_regs + nitems(db_regs); 105 106 void 107 db_show_mdpcpu(struct pcpu *pc) 108 { 109 } 110 111 /* 112 * Read bytes from kernel address space for debugger. 113 */ 114 int 115 db_read_bytes(vm_offset_t addr, size_t size, char *data) 116 { 117 jmp_buf jb; 118 void *prev_jb; 119 const char *src; 120 int ret; 121 122 prev_jb = kdb_jmpbuf(jb); 123 ret = setjmp(jb); 124 125 if (ret == 0) { 126 src = (const char *)addr; 127 while (size-- > 0) 128 *data++ = *src++; 129 } 130 (void)kdb_jmpbuf(prev_jb); 131 132 return (ret); 133 } 134 135 /* 136 * Write bytes to kernel address space for debugger. 137 */ 138 int 139 db_write_bytes(vm_offset_t addr, size_t size, char *data) 140 { 141 jmp_buf jb; 142 void *prev_jb; 143 char *dst; 144 int ret; 145 146 prev_jb = kdb_jmpbuf(jb); 147 ret = setjmp(jb); 148 if (ret == 0) { 149 dst = (char *)addr; 150 while (size-- > 0) 151 *dst++ = *data++; 152 153 dsb(ish); 154 155 /* Clean D-cache and invalidate I-cache */ 156 cpu_dcache_wb_range(addr, (vm_size_t)size); 157 cpu_icache_sync_range(addr, (vm_size_t)size); 158 } 159 (void)kdb_jmpbuf(prev_jb); 160 161 return (ret); 162 } 163