📄 dis.c
字号:
/************************************************************************
*
* dis.c
*
* Monitor command for disassembling an address range
*
* dis [-m] <address> [<count>]
*
* NOTE: The current version does not support 64-bit instructions!
* NOTE: The current version does not support MIPS16 instructions!
*
*
* ######################################################################
*
* Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved.
*
* Unpublished rights reserved under the Copyright Laws of the United States of
* America.
*
* This document contains information that is proprietary to MIPS Technologies,
* Inc. ("MIPS Technologies"). Any copying, modifying or use of this information
* (in whole or in part) which is not expressly permitted in writing by MIPS
* Technologies or a contractually-authorized third party is strictly
* prohibited. At a minimum, this information is protected under unfair
* competition laws and the expression of the information contained herein is
* protected under federal copyright laws. Violations thereof may result in
* criminal penalties and fines.
* MIPS Technologies or any contractually-authorized third party reserves the
* right to change the information contained in this document to improve
* function, design or otherwise. MIPS Technologies does not assume any
* liability arising out of the application or use of this information. Any
* license under patent rights or any other intellectual property rights owned
* by MIPS Technologies or third parties shall be conveyed by MIPS Technologies
* or any contractually-authorized third party in a separate license agreement
* between the parties.
* The information contained in this document constitutes one or more of the
* following: commercial computer software, commercial computer software
* documentation or other commercial items. If the user of this information, or
* any related documentation of any kind, including related technical data or
* manuals, is an agency, department, or other entity of the United States
* government ("Government"), the use, duplication, reproduction, release,
* modification, disclosure, or transfer of this information, or any related
* documentation of any kind, is restricted in accordance with Federal
* Acquisition Regulation 12.212 for civilian agencies and Defense Federal
* Acquisition Regulation Supplement 227.7202 for military agencies. The use of
* this information by the Government is further restricted in accordance with
* the terms of the license agreement(s) and/or applicable contract terms and
* conditions covering this information from MIPS Technologies or any
* contractually-authorized third party.
*
************************************************************************/
/************************************************************************
* Include files
************************************************************************/
#include <sysdefs.h>
#include <sys_api.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <shell_api.h>
#include "shell.h"
/************************************************************************
* Definitions
************************************************************************/
#define DIS_DEFAULT_COUNT 16
/************************************************************************
* Public variables
************************************************************************/
/************************************************************************
* Static variables
************************************************************************/
/* OPTIONS */
static t_cmd_option options[] =
{
#define OPTION_MORE 0
{ "m", "Prompt user for keypress after each screen of data" },
};
#define OPTION_COUNT (sizeof(options)/sizeof(t_cmd_option))
/* Options */
static bool more;
static UINT32 address, count;
static bool address_valid = FALSE;
/************************************************************************
* Static variables - Opcode and register tables
************************************************************************/
static const char *opcode[64] = { /* Disassembler opcodes */
"special","bcond", "tj", "tjal", "bbeq", "bbne", "bblez", "bbgtz",
"iaddi", "iaddiu", "islti", "isltiu", "iandi", "iori", "ixori", "Ilui",
"ccop0", "ccop1", "ccop2", "ccop3", "bbeql", "bbnel", "bblezl", "bbgtzl",
"", "", "", "", "spec2", "", "", "",
"olb", "olh", "olwl", "olw", "olbu", "olhu", "olwr", "",
"osb", "osh", "oswl", "osw", "", "", "oswr", "ocache",
"olwc0", "olwc1", "olwc2", "olwc3", "", "", "", "",
"oswc0", "oswc1", "oswc2", "oswc3", "", "", "", ""
};
static const char *special[64] = { /* Special opcodes */
"ssll", "", "ssrl", "ssra", "vsllv", "", "vsrlv", "vsrav",
"Sjr", "jjalr", "", "", " syscall","Bbreak","", "",
"Dmfhi", "Smthi", "Dmflo", "Smtlo", "", "", "", "",
"mmult", "mmultu", "mdiv", "mdivu", "", "", "", "",
"radd", "raddu", "rsub", "rsubu", "rand", "ror", "rxor", "rnor",
"", "", "rslt", "rsltu", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", ""
};
static const char *spec2[64] = { /* SPEC2 opcodes */
"mmadd", "mmaddu", "mmul", "", "mmsub", "mmsubu", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"mclz", "mclo", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", " sdbbp"
};
static const char *bcond[32] = { /* Branch conditionals */
"Cbltz", "Cbgez", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"Cbltzal","Cbgezal","", "", "", "", "", "",
"", "", "", "", "", "", "", ""
};
static const char *cop0[16] = { /* coprocessor 0 opcodes when rs < 8 */
"0mfc0", "", "0cfc0", "", "0mtc0", "", "0ctc0", "",
"", "", "", "", "", "", "", ""
};
static const char *cop0co[64] = { /* coprocessor 0 opcodes, when rs=16 (CO) */
"", " tlbr", " tlbwi", "", "", "", " tlbwr", "",
" tlbp", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
" eret", "", "", "", "", "", "", " deret",
" wait", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", ""
};
static const char *cop1[16] = { /* coprocessor 1 opcodes when rs < 16 */
"1mfc1", "", "1cfc1", "", "1mtc1", "", "1ctc1", "",
"1bc1", "", "", "", "", "", "", "",
};
static const char *cop1s[64] = { /* coprocessor 1 opcodes, when rs=16 (S) */
"2add", "2sub", "2mul", "2div", "2sqrt", "2abs", "2mov", "2neg",
"", "", "", "", "2round.w","2trunc.w","2ceil.w","2floor.w",
"", "2movfc", "2movz", "2movn", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "2cvt.d", "", "", "2cvt.w", "", "", "",
"", "", "", "", "", "", "", "",
"2c.f", "2c.un", "2c.eq", "2c.ueq", "2c.olt", "2c.ult", "2c.ole", "2c.ule",
"2c.sf", "2c.ngle", "2c.seq", "2c.ngl", "2c.lt", "2c.nge", "2c.le", "2c.ngt"
};
static const char *cop1d[64] = { /* coprocessor 1 opcodes, when rs=17 (D) */
"2add", "2sub", "2mul", "2div", "2sqrt", "2abs", "2mov", "2neg",
"", "", "", "", "2round.w","2trunc.w","2ceil.w","2floor.w",
"", "2movfc", "2movz", "2movn", "", "", "", "",
"", "", "", "", "", "", "", "",
"2cvt.s", "", "", "", "2cvt.w", "", "", "",
"", "", "", "", "", "", "", "",
"2c.f", "2c.un", "2c.eq", "2c.ueq", "2c.olt", "2c.ult", "2c.ole", "2c.ule",
"2c.sf", "2c.ngle", "2c.seq", "2c.ngl", "2c.lt", "2c.nge", "2c.le", "2c.ngt"
};
static const char *cop1w[64] = { /* coprocessor 1 opcodes, when rs=20 (W) */
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"2cvt.s", "2cvt.d", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", ""
};
const char *regs[32] = { /* Register names */
"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"
};
static const char *cp0regs[32] = { /* CP0 Register names */
"index", "random", "entrylo0", "entrylo1", "context", "pagemask", "wired", "#7",
"badvaddr", "count", "entryhi", "compare", "psr", "cause", "epc", "prid",
"config", "lladdr", "watchlo", "watchhi", "xcontext","#21", "#22", "debug",
"#24", "#25", "ecc", "cacheerr", "taglo", "taghi", "errorepc","#31"
};
static const char *fpregs[32] = { /* FPU Register names */
"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"
};
/************************************************************************
* Static function prototypes
************************************************************************/
static UINT32
get_options(
UINT32 argc,
char **argv,
bool *more,
UINT32 *address,
UINT32 *count );
static void
do_dis( void );
static int
disassemble(
char *dest, /* line address */
UINT32 addr, /* virtual address */
UINT32 inst); /* instruction */
/************************************************************************
* Implementation : Static functions
************************************************************************/
/************************************************************************
* dis
************************************************************************/
static MON_FUNC(dis)
{
UINT32 rc;
rc = get_options( argc, argv, &more, &address, &count );
if( rc != OK )
return rc;
else
{
do_dis();
address_valid = TRUE;
return OK;
}
}
/************************************************************************
* dis_dot
************************************************************************/
static MON_FUNC(dis_dot)
{
if( address_valid )
do_dis();
return OK;
}
/************************************************************************
* get_options
************************************************************************/
static UINT32
get_options(
UINT32 argc,
char **argv,
bool *more,
UINT32 *address,
UINT32 *count )
{
t_shell_option decode;
UINT32 type;
UINT32 arg;
bool address_valid = FALSE;
bool count_valid = FALSE;
bool ok = TRUE;
UINT32 i;
UINT32 error = SHELL_ERROR_SYNTAX;
/* Setup defaults */
*more = FALSE;
*count = DIS_DEFAULT_COUNT;
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -