From 0a39fd12370e66df0253d19460850cc3cc158b7f Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Tue, 16 Jul 2013 16:52:22 +0000 Subject: [PATCH] pdp10-opcodes: add pdp10_instruction_from_high13() helper for decoding/disassembly --- include/pdp10-opcodes.h | 2 ++ lib/pdp10-opcodes.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/pdp10-opcodes.h b/include/pdp10-opcodes.h index 9097076..b51b8b8 100644 --- a/include/pdp10-opcodes.h +++ b/include/pdp10-opcodes.h @@ -130,4 +130,6 @@ extern const unsigned int pdp10_num_aliases; extern const struct pdp10_instruction pdp10_extended_instruction[]; extern const unsigned int pdp10_num_extended_instructions; +const struct pdp10_instruction *pdp10_instruction_from_high13(unsigned int high13); + #endif /* PDP10_OPCODES_H */ diff --git a/lib/pdp10-opcodes.c b/lib/pdp10-opcodes.c index 311af37..76128b2 100644 --- a/lib/pdp10-opcodes.c +++ b/lib/pdp10-opcodes.c @@ -957,3 +957,29 @@ const struct pdp10_instruction pdp10_extended_instruction[] = const unsigned int pdp10_num_extended_instructions = sizeof pdp10_extended_instruction / sizeof pdp10_extended_instruction[0]; + +static int pdp10_opcode_matches(unsigned int high13, const struct pdp10_instruction *insn) +{ + unsigned int opcode; + + if ((insn->type & PDP10_A_OPCODE) || (insn->type & PDP10_IO)) + opcode = high13 << 2; /* table entry has 5 octal digits == 15 bits */ + else + opcode = high13 >> 4; /* table entry has 3 octal digits == 9 bits */ + return opcode == insn->opcode; +} + +const struct pdp10_instruction *pdp10_instruction_from_high13(unsigned int high13) +{ + unsigned int i; + + for (i = 0; i < pdp10_num_aliases; ++i) + if (pdp10_opcode_matches(high13, &pdp10_alias[i])) + return &pdp10_alias[i]; + + for (i = 0; i < pdp10_num_instructions; ++i) + if (pdp10_opcode_matches(high13, &pdp10_instruction[i])) + return &pdp10_instruction[i]; + + return (void*)0; +}