summaryrefslogtreecommitdiff
path: root/arch/arm64/disassembler/decode.c
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2024-03-05 19:50:13 -0500
committerRusty Wagner <rusty.wagner@gmail.com>2024-03-05 20:34:34 -0500
commite093c21ed880ac3eb72119be15093ee04f8ce299 (patch)
tree9f720ebdc0ae415734b1199ed341668c69710a94 /arch/arm64/disassembler/decode.c
parent0609276712622908254065546102381466033141 (diff)
Move architecture modules into the API repo
Diffstat (limited to 'arch/arm64/disassembler/decode.c')
-rw-r--r--arch/arm64/disassembler/decode.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/arch/arm64/disassembler/decode.c b/arch/arm64/disassembler/decode.c
new file mode 100644
index 00000000..b444bbcd
--- /dev/null
+++ b/arch/arm64/disassembler/decode.c
@@ -0,0 +1,39 @@
+#include "decode.h"
+#include "feature_flags.h"
+
+int decode_spec(context* ctx, Instruction* dec); // from decode0.cpp
+int decode_scratchpad(context* ctx, Instruction* dec); // from decode_scratchpad.c
+
+int aarch64_decompose(uint32_t instructionValue, Instruction* instr, uint64_t address)
+{
+ context ctx = {0};
+ ctx.halted = 1; // enable disassembly of exception instructions like DCPS1
+ ctx.insword = instructionValue;
+ ctx.address = address;
+ ctx.features0 = ARCH_FEATURES_ALL;
+ ctx.features1 = ARCH_FEATURES_ALL;
+ ctx.EDSCR_HDE = 1;
+
+ /* have the spec-generated code populate all the pcode variables */
+ int rc = decode_spec(&ctx, instr);
+
+ if (rc != DECODE_STATUS_OK)
+ {
+ /* exceptional cases where we accept a non-OK decode status */
+ if (rc == DECODE_STATUS_END_OF_INSTRUCTION && instr->encoding == ENC_HINT_HM_HINTS)
+ {
+ while (0)
+ ;
+ }
+ /* no exception! fail! */
+ else
+ return rc;
+ }
+
+ /* if UDF encoding, return undefined */
+ // if(instr->encoding == ENC_UDF_ONLY_PERM_UNDEF)
+ // return DECODE_STATUS_UNDEFINED;
+
+ /* convert the pcode variables to list of operands, etc. */
+ return decode_scratchpad(&ctx, instr);
+}