@@ -41,102 +41,6 @@
#define IMGASSERTONCE(test)
-static int nanomips_dis(char *buf,
- unsigned address,
- 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, address);
-
- 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;
-
- 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, memaddr, 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];
@@ -736,7 +640,7 @@ static std::string ADDRESS(uint64 value, int instruction_size, img_address m_pc)
}
-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:
@@ -762,9 +666,9 @@ 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,
- TABLE_ENTRY_TYPE & type, const Pool *table,
- int table_size, img_address m_pc)
+static int Disassemble(const uint16 *data, std::string & dis,
+ TABLE_ENTRY_TYPE & type, const Pool *table,
+ int table_size, img_address m_pc)
{
try
{
@@ -22354,8 +22258,102 @@ static struct Pool MAJOR[2] = {
0x0 }, /* P16 */
};
-int NMD::Disassemble(const uint16 * data, std::string & dis,
- TABLE_ENTRY_TYPE & type, img_address m_pc)
+static int Disassemble(const uint16 *data, std::string & dis,
+ TABLE_ENTRY_TYPE & type, img_address m_pc)
{
return Disassemble(data, dis, type, MAJOR, 2, m_pc);
}
+
+static int nanomips_dis(char *buf,
+ unsigned address,
+ 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, address);
+
+ 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;
+
+ 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, memaddr, 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;
+}
@@ -76,21 +76,4 @@ struct Pool {
uint64 attributes;
};
-
-class NMD
-{
-public:
-
- int Disassemble(const uint16 *data, std::string & dis,
- TABLE_ENTRY_TYPE & type, img_address m_pc);
-
-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, img_address m_pc);
-
-};
-
#endif
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> --- disas/nanomips.cpp | 202 ++++++++++++++++++++++----------------------- disas/nanomips.h | 17 ---- 2 files changed, 100 insertions(+), 119 deletions(-)