1 /* $OpenBSD: db_disasm.c,v 1.1 1998/03/16 09:03:24 pefo Exp $ */
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * from: @(#)kadb.c 8.1 (Berkeley) 6/10/93
38 * Id: db_disasm.c,v 1.1 1998/03/16 09:03:24 pefo Exp
39 * JNPR: db_disasm.c,v 1.1 2006/08/07 05:38:57 katta
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
45 #include <sys/param.h>
46 #include <vm/vm_param.h>
49 #include <sys/systm.h>
51 #include <machine/mips_opcode.h>
52 #include <machine/db_machdep.h>
54 #include <ddb/db_output.h>
56 static char *op_name[64] = {
57 /* 0 */ "spec", "bcond","j", "jal", "beq", "bne", "blez", "bgtz",
58 /* 8 */ "addi", "addiu","slti", "sltiu","andi", "ori", "xori", "lui",
59 /*16 */ "cop0", "cop1", "cop2", "cop3", "beql", "bnel", "blezl","bgtzl",
60 /*24 */ "daddi","daddiu","ldl", "ldr", "op34", "op35", "op36", "op37",
61 /*32 */ "lb", "lh", "lwl", "lw", "lbu", "lhu", "lwr", "lwu",
62 /*40 */ "sb", "sh", "swl", "sw", "sdl", "sdr", "swr", "cache",
63 /*48 */ "ll", "lwc1", "lwc2", "lwc3", "lld", "ldc1", "ldc2", "ld",
64 /*56 */ "sc", "swc1", "swc2", "swc3", "scd", "sdc1", "sdc2", "sd"
67 static char *spec_name[64] = {
68 /* 0 */ "sll", "spec01","srl", "sra", "sllv", "spec05","srlv","srav",
69 /* 8 */ "jr", "jalr", "spec12","spec13","syscall","break","spec16","sync",
70 /*16 */ "mfhi", "mthi", "mflo", "mtlo", "dsllv","spec25","dsrlv","dsrav",
71 /*24 */ "mult", "multu","div", "divu", "dmult","dmultu","ddiv","ddivu",
72 /*32 */ "add", "addu", "sub", "subu", "and", "or", "xor", "nor",
73 /*40 */ "spec50","spec51","slt","sltu", "dadd","daddu","dsub","dsubu",
74 /*48 */ "tge","tgeu","tlt","tltu","teq","spec65","tne","spec67",
75 /*56 */ "dsll","spec71","dsrl","dsra","dsll32","spec75","dsrl32","dsra32"
78 static char *bcond_name[32] = {
79 /* 0 */ "bltz", "bgez", "bltzl", "bgezl", "?", "?", "?", "?",
80 /* 8 */ "tgei", "tgeiu", "tlti", "tltiu", "teqi", "?", "tnei", "?",
81 /*16 */ "bltzal", "bgezal", "bltzall", "bgezall", "?", "?", "?", "?",
82 /*24 */ "?", "?", "?", "?", "?", "?", "?", "?",
85 static char *cop1_name[64] = {
86 /* 0 */ "fadd", "fsub", "fmpy", "fdiv", "fsqrt","fabs", "fmov", "fneg",
87 /* 8 */ "fop08","fop09","fop0a","fop0b","fop0c","fop0d","fop0e","fop0f",
88 /*16 */ "fop10","fop11","fop12","fop13","fop14","fop15","fop16","fop17",
89 /*24 */ "fop18","fop19","fop1a","fop1b","fop1c","fop1d","fop1e","fop1f",
90 /*32 */ "fcvts","fcvtd","fcvte","fop23","fcvtw","fop25","fop26","fop27",
91 /*40 */ "fop28","fop29","fop2a","fop2b","fop2c","fop2d","fop2e","fop2f",
92 /*48 */ "fcmp.f","fcmp.un","fcmp.eq","fcmp.ueq","fcmp.olt","fcmp.ult",
93 "fcmp.ole","fcmp.ule",
94 /*56 */ "fcmp.sf","fcmp.ngle","fcmp.seq","fcmp.ngl","fcmp.lt","fcmp.nge",
98 static char *fmt_name[16] = {
99 "s", "d", "e", "fmt3",
100 "w", "fmt5", "fmt6", "fmt7",
101 "fmt8", "fmt9", "fmta", "fmtb",
102 "fmtc", "fmtd", "fmte", "fmtf"
105 static char *reg_name[32] = {
106 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
107 #if defined(__mips_n32) || defined(__mips_n64)
108 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
110 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
112 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
113 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
116 static char *c0_opname[64] = {
117 "c0op00","tlbr", "tlbwi", "c0op03","c0op04","c0op05","tlbwr", "c0op07",
118 "tlbp", "c0op11","c0op12","c0op13","c0op14","c0op15","c0op16","c0op17",
119 "rfe", "c0op21","c0op22","c0op23","c0op24","c0op25","c0op26","c0op27",
120 "eret","c0op31","c0op32","c0op33","c0op34","c0op35","c0op36","c0op37",
121 "c0op40","c0op41","c0op42","c0op43","c0op44","c0op45","c0op46","c0op47",
122 "c0op50","c0op51","c0op52","c0op53","c0op54","c0op55","c0op56","c0op57",
123 "c0op60","c0op61","c0op62","c0op63","c0op64","c0op65","c0op66","c0op67",
124 "c0op70","c0op71","c0op72","c0op73","c0op74","c0op75","c0op77","c0op77",
127 static char *c0_reg[32] = {
128 "index","random","tlblo0","tlblo1","context","tlbmask","wired","c0r7",
129 "badvaddr","count","tlbhi","c0r11","sr","cause","epc", "prid",
130 "config","lladr","watchlo","watchhi","xcontext","c0r21","c0r22","c0r23",
131 "c0r24","c0r25","ecc","cacheerr","taglo","taghi","errepc","c0r31"
134 static int md_printins(int ins, int mdbdot);
137 db_disasm(db_addr_t loc, bool altfmt)
142 if (vtophys((vm_offset_t)loc)) {
143 db_read_bytes((vm_offset_t)loc, (size_t)sizeof(int),
145 md_printins(ins, loc);
148 return (loc + sizeof(int));
153 md_printins(int ins, int mdbdot)
160 switch (i.JType.op) {
166 if (i.RType.func == OP_ADDU && i.RType.rt == 0) {
167 db_printf("move\t%s,%s",
168 reg_name[i.RType.rd], reg_name[i.RType.rs]);
171 db_printf("%s", spec_name[i.RType.func]);
172 switch (i.RType.func) {
182 db_printf("\t%s,%s,%d", reg_name[i.RType.rd],
183 reg_name[i.RType.rt], i.RType.shamt);
192 db_printf("\t%s,%s,%s", reg_name[i.RType.rd],
193 reg_name[i.RType.rt], reg_name[i.RType.rs]);
198 db_printf("\t%s", reg_name[i.RType.rd]);
207 db_printf("\t%s", reg_name[i.RType.rs]);
219 reg_name[i.RType.rs], reg_name[i.RType.rt]);
227 db_printf("\t%d", (i.RType.rs << 5) | i.RType.rt);
231 db_printf("\t%s,%s,%s", reg_name[i.RType.rd],
232 reg_name[i.RType.rs], reg_name[i.RType.rt]);
237 db_printf("%s\t%s,", bcond_name[i.IType.rt],
238 reg_name[i.IType.rs]);
245 db_printf("%s\t%s,", op_name[i.IType.op],
246 reg_name[i.IType.rs]);
251 if (i.IType.rs == 0 && i.IType.rt == 0) {
258 db_printf("%s\t%s,%s,", op_name[i.IType.op],
259 reg_name[i.IType.rs], reg_name[i.IType.rt]);
262 db_printf("0x%08x", mdbdot + 4 + ((short)i.IType.imm << 2));
266 switch (i.RType.rs) {
270 "ft"[i.RType.rt & COPz_BC_TF_MASK]);
274 db_printf("mtc0\t%s,%s",
275 reg_name[i.RType.rt], c0_reg[i.RType.rd]);
279 db_printf("dmtc0\t%s,%s",
280 reg_name[i.RType.rt], c0_reg[i.RType.rd]);
284 db_printf("mfc0\t%s,%s",
285 reg_name[i.RType.rt], c0_reg[i.RType.rd]);
289 db_printf("dmfc0\t%s,%s",
290 reg_name[i.RType.rt], c0_reg[i.RType.rd]);
294 db_printf("%s", c0_opname[i.FRType.func]);
299 switch (i.RType.rs) {
303 "ft"[i.RType.rt & COPz_BC_TF_MASK]);
307 db_printf("mtc1\t%s,f%d",
308 reg_name[i.RType.rt], i.RType.rd);
312 db_printf("mfc1\t%s,f%d",
313 reg_name[i.RType.rt], i.RType.rd);
317 db_printf("ctc1\t%s,f%d",
318 reg_name[i.RType.rt], i.RType.rd);
322 db_printf("cfc1\t%s,f%d",
323 reg_name[i.RType.rt], i.RType.rd);
327 db_printf("%s.%s\tf%d,f%d,f%d",
328 cop1_name[i.FRType.func], fmt_name[i.FRType.fmt],
329 i.FRType.fd, i.FRType.fs, i.FRType.ft);
335 db_printf("%s\t", op_name[i.JType.op]);
336 db_printf("0x%8x",(mdbdot & 0xF0000000) | (i.JType.target << 2));
342 db_printf("%s\tf%d,", op_name[i.IType.op], i.IType.rt);
356 db_printf("%s\t%s,", op_name[i.IType.op],
357 reg_name[i.IType.rt]);
359 db_printf("%d(%s)", (short)i.IType.imm, reg_name[i.IType.rs]);
364 if (i.IType.rs == 0) {
365 db_printf("li\t%s,0x%x",
366 reg_name[i.IType.rt], i.IType.imm);
371 db_printf("%s\t%s,%s,0x%x", op_name[i.IType.op],
372 reg_name[i.IType.rt], reg_name[i.IType.rs], i.IType.imm);
376 db_printf("%s\t%s,0x%x", op_name[i.IType.op],
377 reg_name[i.IType.rt], i.IType.imm);
384 if (i.IType.rs == 0) {
385 db_printf("li\t%s,%d", reg_name[i.IType.rt],
391 db_printf("%s\t%s,%s,%d", op_name[i.IType.op],
392 reg_name[i.IType.rt], reg_name[i.IType.rs],