📄 dis.c
字号:
{10, "c.lt.ps" }, {10, "c.nge.ps" }, {10, "c.le.ps" }, {10, "c.ngt.ps" }};/* MOVCF opcode (opcode field = 17) for rs = 16 (S) and function = 17. * Encoding of tf field (bit 16) */static t_opc movcfs[2] = { {34, "movf.s"}, {34, "movt.s"}};/* MOVCF opcode (opcode field = 17) for rs = 17 (D) and function = 17. * Encoding of tf field (bit 16) */static t_opc movcfd[2] = { {34, "movf.d"}, {34, "movt.d"}};/* MOVCF opcode (opcode field = 17) for rs = 22 (PS) and function = 17. * Encoding of tf field (bit 16) */static t_opc movcfps[2] = { {34, "movf.ps"}, {34, "movt.ps"}};/* COP2 opcode (opcode field = 18) * Encoding of rs field (25..21) */static t_opc cop2[32] = { {44, "mfc2"}, {0, ""}, {45, "cfc2"}, {44, "mfhc2"}, {44, "mtc2"}, {0, ""}, {45, "ctc2"}, {44, "mthc2"}, {0, "" }, {0, "" }, {0, "" }, {0, ""}, {0, "" }, {0, "" }, {0, "" }, {0, ""}, {0, "" }, {0, "" }, {0, "" }, {0, ""}, {0, "" }, {0, "" }, {0, "" }, {0, ""}, {0, "" }, {0, "" }, {0, "" }, {0, ""}, {0, "" }, {0, "" }, {0, "" }, {0, ""}};/* BC2 opcode (opcode field = 18) for rs = 8 * Encoding of rt field (17..16) */static t_opc bc2[4] = { {6, "bc2f" }, {6, "bc2t" }, {6, "bc2fl"}, {6, "bc2tl"}};/* SPECIAL3.BSHFL (opcode field = 31, function field=32). * Encoding of bshfl function field (10..6) */static t_opc bshfl[32] = { {0, "" }, {41, "wsbh"}, {0, ""}, {0, ""}, {0, "" }, {0, "" }, {0, ""}, {0, ""}, {0, "" }, {0, "" }, {0, ""}, {0, ""}, {0, "" }, {0, "" }, {0, ""}, {0, ""}, {41, "seb"}, {0, "" }, {0, ""}, {0, ""}, {0, "" }, {0, "" }, {0, ""}, {0, ""}, {41, "seh"}, {0, "" }, {0, ""}, {0, ""}, {0, "" }, {0, "" }, {0, ""}, {0, ""}};/* SLL instruction and special cases of this opcode */static t_opc opc_sll = {21, "sll" };static t_opc opc_nop = {18, "nop" };static t_opc opc_ssnop = {18, "ssnop"};static t_opc opc_ehb = {18, "ehb" };/* Register names */static char *regs[32] = { "zero","at", "v0", "v1", "a0", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"};/* CP0 Register names */static char *cp0regs[8][32] = { /* SEL = 0 */ { "Index", "Random", "EntryLo0","EntryLo1","Context", "PageMask","Wired", "HWREna", "BadVAddr","Count", "EntryHi", "Compare", "Status", "Cause", "EPC", "PRId", "Config", "LLAddr", "WatchLo", "WatchHi", "XContext","$21,0", "$22,0", "Debug", "DEPC", "PerfCnt","ErrCtl", "CacheErr","TagLo", "TagHi", "ErrorEPC","DESAVE" }, /* SEL = 1 */ { "$0,1", "$1,1", "$2,1", "$3,1", "ContextConfig","PageGrain","$6,1", "$7,1", "$8,1", "$9,1", "$10,1","$11,1","IntCtl", "$13,1", "$14,1","EBase", "Config1","$17,1","$18,1","$19,1","$20,1", "$21,1", "$22,1","TraceControl", "$24,1", "$25,1","$26,1","$27,1","DataLo", "DataHi", "$30,1","$31,1" }, /* SEL = 2 */ { "$0,2", "$1,2", "$2,2", "$3,2", "$4,2", "$5,2", "$6,2", "$7,2", "$8,2", "$9,2", "$10,2","$11,2","SRSCtl","$13,2","$14,2","$15,2", "Config2","$17,2","$18,2","$19,2","$20,2", "$21,2","$22,2","TraceControl2", "$24,2", "$25,2","$26,2","$27,2","$28,2", "$29,2","$30,2","$31,2" }, /* SEL = 3 */ { "$0,3", "$1,3", "$2,3", "$3,3", "$4,3", "$5,3", "$6,3", "$7,3", "$8,3", "$9,3", "$10,3","$11,3","SRSMap","$13,3","$14,3","$15,3", "Config3","$17,3","$18,3","$19,3","$20,3", "$21,3","$22,3","UserTraceData", "$24,3", "$25,3","$26,3","$27,3","$28,3", "$29,3","$30,3","$31,3" }, /* SEL = 4 */ { "$0,4", "$1,4", "$2,4", "$3,4", "$4,4", "$5,4", "$6,4", "$7,4", "$8,4", "$9,4", "$10,4","$11,4","$12,4","$13,4","$14,4","$15,4", "$16,4","$17,4","$18,4","$19,4","$20,4","$21,4","$22,4","TraceBPC", "$24,4","$25,4","$26,4","$27,4","$28,4","$29,4","$30,4","$31,4" }, /* SEL = 5 */ { "$0,5", "$1,5", "$2,5", "$3,5", "$4,5", "$5,5", "$6,5", "$7,5", "$8,5", "$9,5", "$10,5","$11,5","$12,5","$13,5","$14,5","$15,5", "$16,5","$17,5","$18,5","$19,5","$20,5","$21,5","$22,5","$23,5", "$24,5","$25,5","$26,5","$27,5","$28,5","$29,5","$30,5","$31,5" }, /* SEL = 6 */ { "$0,6", "$1,6", "$2,6", "$3,6", "$4,6", "$5,6", "$6,6", "$7,6", "$8,6", "$9,6", "$10,6","$11,6","$12,6","$13,6","$14,6","$15,6", "$16,6","$17,6","$18,6","$19,6","$20,6","$21,6","$22,6","$23,6", "$24,6","$25,6","$26,6","$27,6","$28,6","$29,6","$30,6","$31,6" }, /* SEL = 7 */ { "$0,7", "$1,7", "$2,7", "$3,7", "$4,7", "$5,7", "$6,7", "$7,7", "$8,7", "$9,7", "$10,7","$11,7","$12,7","$13,7","$14,7","$15,7", "$16,7","$17,7","$18,7","$19,7","$20,7","$21,7","$22,7","$23,7", "$24,7","$25,7","$26,7","$27,7","$28,7","$29,7","$30,7","$31,7" } };/* FPU Register names */static char *fpregs[32] = { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"};/************************************************************************ * MIPS16e ASE ************************************************************************/static t_opc opc16[32] = { { 1, "addiu" }, { 2, "addiu" }, { 3, "b" }, { 0xff, "" }, { 4, "beqz" }, { 4, "bnez" }, { 0xff, "" }, { 5, "ld" }, { 0xff, "" }, { 6, "addiu" }, { 7, "slti" }, { 7, "sltiu" }, { 0xff, "" }, { 8, "li" }, { 8, "cmpi" }, { 5, "sd" }, { 9, "lb" }, { 10, "lh" }, { 11, "lw" }, { 12, "lw" }, { 9, "lbu" }, { 10, "lhu" }, { 13, "lw" }, { 12, "lwu" }, { 9, "sb" }, { 10, "sh" }, { 11, "sw" }, { 12, "sw" }, { 0xff, "" }, { 0xff, "" }, { 0xff, "" }, { 0xff, "" }};static t_opc opc16_jalx[2] = { { 14, "jal" }, { 14, "jalx" }};static t_opc opc16_shift[4] = { { 15, "sll" }, { 15, "dsll" }, { 15, "srl" }, { 15, "sra" }};static t_opc opc16_rria[2] = { { 16, "addiu" }, { 16, "daddiu" }};static t_opc opc16_i8[8] = { { 17, "bteqz" }, { 17, "btnez" }, { 18, "sw" }, { 19, "addiu" }, { 0xff, "" }, { 20, "move" }, { 0xff, "" }, { 21, "move" }};static t_opc opc16_rrr[4] = { { 22, "daddu" }, { 22, "addu" }, { 22, "dsubu" }, { 22, "subu" }};static t_opc opc16_rr[32] = { { 0xff, "" }, { 23, "sdbbp" }, { 24, "slt" }, { 24, "sltu" }, { 25, "sllv" }, { 23, "break" }, { 25, "srlv" }, { 25, "srav" }, { 26, "dsrl" }, { 0xff, "" }, { 24, "cmp" }, { 24, "neg" }, { 24, "and" }, { 24, "or" }, { 24, "xor" }, { 24, "not" }, { 27, "mfhi" }, { 0xff, "" }, { 27, "mflo" }, { 26, "dsra" }, { 25, "dsllv" }, { 0xff, "" }, { 25, "dsrlv" }, { 25, "dsrav" }, { 24, "mult" }, { 24, "multu" }, { 24, "div" }, { 24, "divu" }, { 24, "dmult" }, { 24, "dmultu" }, { 24, "ddiv" }, { 24, "ddivu" }};static t_opc opc16_i64[8] = { { 28, "ld" }, { 28, "sd" }, { 29, "sd" }, { 19, "daddiu" }, { 30, "ld" }, { 31, "daddiu" }, { 32, "daddiu" }, { 33, "daddiu" }};static t_opc opc16_svrs[2] = { { 34, "restore" }, { 34, "save" }};static t_opc opc16_jalrc[8] = { { 27, "jr" }, { 35, "jr" }, { 36, "jalr" }, { 0xff, "" }, { 27, "jrc" }, { 35, "jrc" }, { 36, "jalrc" }, { 0xff, "" }};static t_opc opc16_cnvt[8] = { { 27, "zeb" }, { 27, "zeh" }, { 27, "zew" }, { 0xff, "" }, { 27, "seb" }, { 27, "seh" }, { 27, "sew" }, { 0xff, "" }};static t_opc opc16_asmacro = { 0, "asmacro" };static t_opc opc16_nop = { 0, "nop" };/* Register names */static char *regs16[8] = { "s0","s1", "v0", "v1", "a0", "a1", "a2", "a3" };/************************************************************************ * Static function prototypes ************************************************************************/static UINT32 get_options( UINT32 argc, char **argv );static voiddo_dis( void );static booldisassemble( char *dest, /* line address */ UINT32 *addr ); /* virtual address */static booldisassemble16( char *dest, /* line address */ UINT32 *addr ); /* virtual address *//************************************************************************ * Implementation : Static functions ************************************************************************//************************************************************************ * dis ************************************************************************/static MON_FUNC(dis){ UINT32 size; if( !shell_dot ) rc = get_options( argc, argv ); size = mips16e ? sizeof(UINT16) : sizeof(UINT32); if( rc == OK ) rc = sys_validate_range( address, count * size, size, FALSE ); if( rc == OK ) do_dis(); return rc;}/************************************************************************ * get_options ************************************************************************/static UINT32 get_options( UINT32 argc, char **argv ){ t_shell_option decode; UINT32 type; UINT32 arg; UINT32 i; bool address_valid = FALSE; bool count_valid = FALSE; bool ok = TRUE; UINT32 error = SHELL_ERROR_SYNTAX; /* Setup defaults */ more = FALSE; count = DIS_DEFAULT_COUNT; mips16e = FALSE; for( arg = 1; ok && (arg < argc) && shell_decode_token( argv[arg], &type, &decode ); arg++ ) { switch( type ) { case SHELL_TOKEN_OPTION : /* Find match */ for(i=0; (i<OPTION_COUNT) && (strcmp(decode.option, options[i].option) != 0); i++) ; switch(i) { case OPTION_MORE : more = TRUE; break; case OPTION_MIPS16E : mips16e = TRUE; break; default : error = SHELL_ERROR_OPTION; shell_error_data = argv[arg]; ok = FALSE; break; } break; case SHELL_TOKEN_NUMBER : if( !address_valid ) { address_valid = TRUE; address = decode.number; } else if( !count_valid ) { count_valid = TRUE; count = decode.number; } else ok = FALSE; break; default : ok = FALSE; break; } } if(!address_valid) ok = FALSE; return ok ? OK : error;}/************************************************************************ * do_dis ************************************************************************/static voiddo_dis( void ){ UINT32 i; char line[80]; // must be long enough to hold disassembled inst line bool rc = TRUE; if (SHELL_PUTC( '\n' )) return; if (!more) SHELL_DISABLE_MORE; for(i=0; (i<count) && rc; i++) { rc = mips16e ? disassemble16( line, &address ) : disassemble( line, &address ); if (SHELL_PUTS(line)) break; } SHELL_PUTC( '\n' );}/************************************************************************ * disassemble ************************************************************************/static booldisassemble( char *dest, /* destination line */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -