From 2b0dccb243593e459128b8b491c9f346a18a7ca9 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 11 Jul 2014 01:27:32 -0700 Subject: [PATCH] Fold direction into memory format --- src/arm/decoder-thumb.c | 17 ++++++++--------- src/arm/decoder.h | 22 ++++++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/arm/decoder-thumb.c b/src/arm/decoder-thumb.c index d0fdcedf5..21ba8ca9f 100644 --- a/src/arm/decoder-thumb.c +++ b/src/arm/decoder-thumb.c @@ -226,12 +226,11 @@ DEFINE_LOAD_STORE_WITH_REGISTER_THUMB(STRH2, STR, STORE_CYCLES, ARM_ACCESS_HALFW info->op1.immediate = (opcode & 0xFF) | ADDITIONAL_REG; \ info->branches = info->op1.immediate & (1 << ARM_PC); \ info->operandFormat = ARM_OPERAND_MEMORY_1; \ - info->memory.direction = DIRECTION; \ info->memory.format = ARM_MEMORY_REGISTER_BASE | \ - ARM_MEMORY_POST_INCREMENT;) + ARM_MEMORY_POST_INCREMENT | DIRECTION;) #define DEFINE_LOAD_STORE_MULTIPLE_THUMB(NAME) \ - COUNT_3(DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB, NAME ## IA_R, NAME, ARM_INCREMENT_AFTER, 0) + COUNT_3(DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB, NAME ## IA_R, NAME, ARM_MEMORY_INCREMENT_AFTER, 0) DEFINE_LOAD_STORE_MULTIPLE_THUMB(LDM) DEFINE_LOAD_STORE_MULTIPLE_THUMB(STM) @@ -270,10 +269,10 @@ DEFINE_CONDITIONAL_BRANCH_THUMB(LE) DEFINE_SP_MODIFY_THUMB(ADD7, ADD) DEFINE_SP_MODIFY_THUMB(SUB4, SUB) -DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(POP, ARM_SP, LDM, ARM_INCREMENT_AFTER, 0) -DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(POPR, ARM_SP, LDM, ARM_INCREMENT_AFTER, 1 << ARM_PC) -DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(PUSH, ARM_SP, STM, ARM_DECREMENT_BEFORE, 0) -DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(PUSHR, ARM_SP, STM, ARM_DECREMENT_BEFORE, 1 << ARM_LR) +DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(POP, ARM_SP, LDM, ARM_MEMORY_INCREMENT_AFTER, 0) +DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(POPR, ARM_SP, LDM, ARM_MEMORY_INCREMENT_AFTER, 1 << ARM_PC) +DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(PUSH, ARM_SP, STM, ARM_MEMORY_DECREMENT_BEFORE, 0) +DEFINE_LOAD_STORE_MULTIPLE_EX_THUMB(PUSHR, ARM_SP, STM, ARM_MEMORY_DECREMENT_BEFORE, 1 << ARM_LR) DEFINE_THUMB_DECODER(ILL, ILL, info->traps = 1;) DEFINE_THUMB_DECODER(BKPT, BKPT, info->traps = 1;) @@ -396,11 +395,11 @@ int ARMDisassembleThumb(uint16_t opcode, uint32_t pc, char* buffer, int blen) { switch (info.mnemonic) { case ARM_MN_LDM: case ARM_MN_STM: - flags = armDirectionStrings[info.memory.direction]; + flags = armDirectionStrings[MEMORY_FORMAT_TO_DIRECTION(info.memory.format)]; break; case ARM_MN_LDR: case ARM_MN_STR: - flags = armAccessTypeStrings[info.memory.direction]; + flags = armAccessTypeStrings[info.memory.width]; break; default: break; diff --git a/src/arm/decoder.h b/src/arm/decoder.h index eb552e728..84cf0ad40 100644 --- a/src/arm/decoder.h +++ b/src/arm/decoder.h @@ -43,9 +43,17 @@ enum ARMMemoryFormat { ARM_MEMORY_SHIFTED_OFFSET = 0x0008, ARM_MEMORY_PRE_INCREMENT = 0x0010, ARM_MEMORY_POST_INCREMENT = 0x0020, - ARM_MEMORY_OFFSET_SUBTRACT = 0x0040 + ARM_MEMORY_OFFSET_SUBTRACT = 0x0040, + + ARM_MEMORY_WRITEBACK = 0x0080, + ARM_MEMORY_DECREMENT_AFTER = 0x0000, + ARM_MEMORY_INCREMENT_AFTER = 0x0100, + ARM_MEMORY_DECREMENT_BEFORE = 0x0200, + ARM_MEMORY_INCREMENT_BEFORE = 0x0300, }; +#define MEMORY_FORMAT_TO_DIRECTION(F) (((F) >> 8) & 0x7) + enum ARMCondition { ARM_CONDITION_EQ = 0x0, ARM_CONDITION_NE = 0x1, @@ -77,13 +85,6 @@ union ARMOperand { int32_t immediate; }; -enum ARMMultipleDirection { - ARM_DECREMENT_AFTER = 0, - ARM_INCREMENT_AFTER = 1, - ARM_DECREMENT_BEFORE = 2, - ARM_INCREMENT_BEFORE = 3, -}; - enum ARMMemoryAccessType { ARM_ACCESS_WORD = 4, ARM_ACCESS_HALFWORD = 2, @@ -96,10 +97,7 @@ struct ARMMemoryAccess { uint8_t baseReg; uint16_t format; union ARMOperand offset; - union { - enum ARMMultipleDirection direction; - enum ARMMemoryAccessType width; - }; + enum ARMMemoryAccessType width; }; enum ARMMnemonic {