disas/nanomips: Remove NMD class

NMD class has been deleted. The following methods are now declared as
static functions:
- public NMD::Disassemble method
- private NMD::Disassemble method
- private NMD::extract_op_code_value helper method

Also, the implementation of the print_insn_nanomips function and
nanomips_dis function is moved to the end of the nanomips.cpp file,
right after the implementation of the Disassemble function.

Signed-off-by: Milica Lazarevic <milica.lazarevic@syrmia.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220912122635.74032-10-milica.lazarevic@syrmia.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Milica Lazarevic 2022-09-12 14:26:20 +02:00 committed by Philippe Mathieu-Daudé
parent a146549034
commit beebf65bec
2 changed files with 101 additions and 118 deletions

View file

@ -41,105 +41,6 @@
#define IMGASSERTONCE(test)
static int nanomips_dis(char *buf,
Dis_info *info,
unsigned short one,
unsigned short two,
unsigned short three)
{
std::string disasm;
uint16 bits[3] = {one, two, three};
TABLE_ENTRY_TYPE type;
NMD d;
int size = d.Disassemble(bits, disasm, type, info);
strcpy(buf, disasm.c_str());
return size;
}
int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info)
{
int status;
bfd_byte buffer[2];
uint16_t insn1 = 0, insn2 = 0, insn3 = 0;
char buf[200];
info->bytes_per_chunk = 2;
info->display_endian = info->endian;
info->insn_info_valid = 1;
info->branch_delay_insns = 0;
info->data_size = 0;
info->insn_type = dis_nonbranch;
info->target = 0;
info->target2 = 0;
Dis_info disassm_info;
disassm_info.m_pc = memaddr;
status = (*info->read_memory_func)(memaddr, buffer, 2, info);
if (status != 0) {
(*info->memory_error_func)(status, memaddr, info);
return -1;
}
if (info->endian == BFD_ENDIAN_BIG) {
insn1 = bfd_getb16(buffer);
} else {
insn1 = bfd_getl16(buffer);
}
(*info->fprintf_func)(info->stream, "%04x ", insn1);
/* Handle 32-bit opcodes. */
if ((insn1 & 0x1000) == 0) {
status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info);
if (status != 0) {
(*info->memory_error_func)(status, memaddr + 2, info);
return -1;
}
if (info->endian == BFD_ENDIAN_BIG) {
insn2 = bfd_getb16(buffer);
} else {
insn2 = bfd_getl16(buffer);
}
(*info->fprintf_func)(info->stream, "%04x ", insn2);
} else {
(*info->fprintf_func)(info->stream, " ");
}
/* Handle 48-bit opcodes. */
if ((insn1 >> 10) == 0x18) {
status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info);
if (status != 0) {
(*info->memory_error_func)(status, memaddr + 4, info);
return -1;
}
if (info->endian == BFD_ENDIAN_BIG) {
insn3 = bfd_getb16(buffer);
} else {
insn3 = bfd_getl16(buffer);
}
(*info->fprintf_func)(info->stream, "%04x ", insn3);
} else {
(*info->fprintf_func)(info->stream, " ");
}
int length = nanomips_dis(buf, &disassm_info, insn1, insn2, insn3);
/* FIXME: Should probably use a hash table on the major opcode here. */
(*info->fprintf_func) (info->stream, "%s", buf);
if (length > 0) {
return length / 8;
}
info->insn_type = dis_noninsn;
return insn3 ? 6 : insn2 ? 4 : 2;
}
std::string img_format(const char *format, ...)
{
char buffer[256];
@ -739,7 +640,7 @@ static std::string ADDRESS(uint64 value, int instruction_size, Dis_info *info)
}
uint64 NMD::extract_op_code_value(const uint16 * data, int size)
static uint64 extract_op_code_value(const uint16 *data, int size)
{
switch (size) {
case 16:
@ -765,7 +666,7 @@ uint64 NMD::extract_op_code_value(const uint16 * data, int size)
* instruction size - negative is error
* disassembly string - on error will constain error string
*/
int NMD::Disassemble(const uint16 * data, std::string & dis,
static int Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, const Pool *table,
int table_size, Dis_info *info)
{
@ -22348,8 +22249,105 @@ static const Pool MAJOR[2] = {
0x0 }, /* P16 */
};
int NMD::Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, Dis_info *info)
static int Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, Dis_info *info)
{
return Disassemble(data, dis, type, MAJOR, 2, info);
}
static int nanomips_dis(char *buf,
Dis_info *info,
unsigned short one,
unsigned short two,
unsigned short three)
{
std::string disasm;
uint16 bits[3] = {one, two, three};
TABLE_ENTRY_TYPE type;
int size = Disassemble(bits, disasm, type, info);
strcpy(buf, disasm.c_str());
return size;
}
int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info)
{
int status;
bfd_byte buffer[2];
uint16_t insn1 = 0, insn2 = 0, insn3 = 0;
char buf[200];
info->bytes_per_chunk = 2;
info->display_endian = info->endian;
info->insn_info_valid = 1;
info->branch_delay_insns = 0;
info->data_size = 0;
info->insn_type = dis_nonbranch;
info->target = 0;
info->target2 = 0;
Dis_info disassm_info;
disassm_info.m_pc = memaddr;
status = (*info->read_memory_func)(memaddr, buffer, 2, info);
if (status != 0) {
(*info->memory_error_func)(status, memaddr, info);
return -1;
}
if (info->endian == BFD_ENDIAN_BIG) {
insn1 = bfd_getb16(buffer);
} else {
insn1 = bfd_getl16(buffer);
}
(*info->fprintf_func)(info->stream, "%04x ", insn1);
/* Handle 32-bit opcodes. */
if ((insn1 & 0x1000) == 0) {
status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info);
if (status != 0) {
(*info->memory_error_func)(status, memaddr + 2, info);
return -1;
}
if (info->endian == BFD_ENDIAN_BIG) {
insn2 = bfd_getb16(buffer);
} else {
insn2 = bfd_getl16(buffer);
}
(*info->fprintf_func)(info->stream, "%04x ", insn2);
} else {
(*info->fprintf_func)(info->stream, " ");
}
/* Handle 48-bit opcodes. */
if ((insn1 >> 10) == 0x18) {
status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info);
if (status != 0) {
(*info->memory_error_func)(status, memaddr + 4, info);
return -1;
}
if (info->endian == BFD_ENDIAN_BIG) {
insn3 = bfd_getb16(buffer);
} else {
insn3 = bfd_getl16(buffer);
}
(*info->fprintf_func)(info->stream, "%04x ", insn3);
} else {
(*info->fprintf_func)(info->stream, " ");
}
int length = nanomips_dis(buf, &disassm_info, insn1, insn2, insn3);
/* FIXME: Should probably use a hash table on the major opcode here. */
(*info->fprintf_func) (info->stream, "%s", buf);
if (length > 0) {
return length / 8;
}
info->insn_type = dis_noninsn;
return insn3 ? 6 : insn2 ? 4 : 2;
}

View file

@ -80,19 +80,4 @@ typedef struct Pool {
uint64 attributes;
} Pool;
class NMD
{
public:
int Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, Dis_info *info);
private:
uint64 extract_op_code_value(const uint16 *data, int size);
int Disassemble(const uint16 *data, std::string & dis,
TABLE_ENTRY_TYPE & type, const Pool *table, int table_size,
Dis_info *info);
};
#endif