1 /* $OpenBSD: db_machdep.c,v 1.2 1998/09/15 10:50:13 pefo Exp $ */
4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed under OpenBSD by
17 * Per Fogelstrom, Opsycon AB, Sweden.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * JNPR: db_interface.c,v 1.6.2.1 2007/08/29 12:24:49 girish
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/systm.h>
45 #include <vm/vm_object.h>
46 #include <vm/vm_page.h>
48 #include <vm/vm_map.h>
51 #include <sys/reboot.h>
53 #include <machine/cache.h>
54 #include <machine/db_machdep.h>
55 #include <machine/mips_opcode.h>
56 #include <machine/vmparam.h>
57 #include <machine/md_var.h>
58 #include <machine/setjmp.h>
61 #include <ddb/db_sym.h>
62 #include <ddb/db_access.h>
63 #include <ddb/db_output.h>
64 #include <ddb/db_variables.h>
67 static db_varfcn_t db_frame;
69 #define DB_OFFSET(x) (db_expr_t *)offsetof(struct trapframe, x)
70 struct db_variable db_regs[] = {
71 { "at", DB_OFFSET(ast), db_frame },
72 { "v0", DB_OFFSET(v0), db_frame },
73 { "v1", DB_OFFSET(v1), db_frame },
74 { "a0", DB_OFFSET(a0), db_frame },
75 { "a1", DB_OFFSET(a1), db_frame },
76 { "a2", DB_OFFSET(a2), db_frame },
77 { "a3", DB_OFFSET(a3), db_frame },
78 #if defined(__mips_n32) || defined(__mips_n64)
79 { "a4", DB_OFFSET(a4), db_frame },
80 { "a5", DB_OFFSET(a5), db_frame },
81 { "a6", DB_OFFSET(a6), db_frame },
82 { "a7", DB_OFFSET(a7), db_frame },
83 { "t0", DB_OFFSET(t0), db_frame },
84 { "t1", DB_OFFSET(t1), db_frame },
85 { "t2", DB_OFFSET(t2), db_frame },
86 { "t3", DB_OFFSET(t3), db_frame },
88 { "t0", DB_OFFSET(t0), db_frame },
89 { "t1", DB_OFFSET(t1), db_frame },
90 { "t2", DB_OFFSET(t2), db_frame },
91 { "t3", DB_OFFSET(t3), db_frame },
92 { "t4", DB_OFFSET(t4), db_frame },
93 { "t5", DB_OFFSET(t5), db_frame },
94 { "t6", DB_OFFSET(t6), db_frame },
95 { "t7", DB_OFFSET(t7), db_frame },
97 { "s0", DB_OFFSET(s0), db_frame },
98 { "s1", DB_OFFSET(s1), db_frame },
99 { "s2", DB_OFFSET(s2), db_frame },
100 { "s3", DB_OFFSET(s3), db_frame },
101 { "s4", DB_OFFSET(s4), db_frame },
102 { "s5", DB_OFFSET(s5), db_frame },
103 { "s6", DB_OFFSET(s6), db_frame },
104 { "s7", DB_OFFSET(s7), db_frame },
105 { "t8", DB_OFFSET(t8), db_frame },
106 { "t9", DB_OFFSET(t9), db_frame },
107 { "k0", DB_OFFSET(k0), db_frame },
108 { "k1", DB_OFFSET(k1), db_frame },
109 { "gp", DB_OFFSET(gp), db_frame },
110 { "sp", DB_OFFSET(sp), db_frame },
111 { "s8", DB_OFFSET(s8), db_frame },
112 { "ra", DB_OFFSET(ra), db_frame },
113 { "sr", DB_OFFSET(sr), db_frame },
114 { "lo", DB_OFFSET(mullo), db_frame },
115 { "hi", DB_OFFSET(mulhi), db_frame },
116 { "bad", DB_OFFSET(badvaddr), db_frame },
117 { "cs", DB_OFFSET(cause), db_frame },
118 { "pc", DB_OFFSET(pc), db_frame },
120 struct db_variable *db_eregs = db_regs + nitems(db_regs);
122 int (*do_db_log_stack_trace_cmd)(char *);
125 db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
129 if (kdb_frame == NULL)
132 reg = (register_t *)((uintptr_t)kdb_frame + (size_t)(intptr_t)vp->valuep);
133 if (op == DB_VAR_GET)
141 db_read_bytes(vm_offset_t addr, size_t size, char *data)
147 prev_jb = kdb_jmpbuf(jb);
151 * 'addr' could be a memory-mapped I/O address. Try to
152 * do atomic load/store in unit of size requested.
154 if ((size == 2 || size == 4 || size == 8) &&
155 ((addr & (size -1)) == 0) &&
156 (((vm_offset_t)data & (size -1)) == 0)) {
159 *(uint16_t *)data = *(uint16_t *)addr;
162 *(uint32_t *)data = *(uint32_t *)addr;
165 atomic_load_64((volatile u_int64_t *)addr,
178 (void)kdb_jmpbuf(prev_jb);
183 db_write_bytes(vm_offset_t addr, size_t size, char *data)
189 prev_jb = kdb_jmpbuf(jb);
194 * 'addr' could be a memory-mapped I/O address. Try to
195 * do atomic load/store in unit of size requested.
197 if ((size == 2 || size == 4 || size == 8) &&
198 ((addr & (size -1)) == 0) &&
199 (((vm_offset_t)data & (size -1)) == 0)) {
202 *(uint16_t *)addr = *(uint16_t *)data;
205 *(uint32_t *)addr = *(uint32_t *)data;
208 atomic_store_64((volatile u_int64_t *)addr,
221 mips_icache_sync_range((db_addr_t) addr, size);
222 mips_dcache_wbinv_range((db_addr_t) addr, size);
224 (void)kdb_jmpbuf(prev_jb);
229 * To do a single step ddb needs to know the next address
230 * that we will get to. It means that we need to find out
231 * both the address for a branch taken and for not taken, NOT! :-)
232 * MipsEmulateBranch will do the job to find out _exactly_ which
233 * address we will end up at so the 'dual bp' method is not
237 next_instr_address(db_addr_t pc, boolean_t bd)
241 next = (db_addr_t)MipsEmulateBranch(kdb_frame, pc, 0, 0);
247 * Decode instruction and figure out type.
250 db_inst_type(int ins)
256 switch ((int)inst.JType.op) {
258 switch ((int)inst.RType.func) {
270 switch ((int)inst.IType.rt) {
304 switch (inst.RType.rs) {
335 * Return the next pc if the given branch is taken.
336 * MachEmulateBranch() runs analysis for branch delay slot.
339 branch_taken(int inst, db_addr_t pc)
344 /* TBD: when is fsr set */
345 fpucsr = (curthread) ? curthread->td_pcb->pcb_regs.fsr : 0;
346 ra = (db_addr_t)MipsEmulateBranch(kdb_frame, pc, fpucsr, 0);