diff --git a/examples/build/type18_test.dsp b/examples/build/type18_test.dsp new file mode 100644 index 0000000..172974a --- /dev/null +++ b/examples/build/type18_test.dsp @@ -0,0 +1,17 @@ +/* + * type18_test.dsp -- Verify Type 18 mode control encoding. + */ + .section/PM program0; + .global _start; +_start: + ena ar_sat; + dis ar_sat; + ena m_mode; + dis m_mode; + ena bit_rev; + dis bit_rev; + ena timer; + dis timer; + nop; +_halt: + jump _halt; diff --git a/r2plugin/asm_adsp219x.c b/r2plugin/asm_adsp219x.c index 3a83c5f..16ea33d 100644 --- a/r2plugin/asm_adsp219x.c +++ b/r2plugin/asm_adsp219x.c @@ -61,10 +61,11 @@ decode (RArchSession *as, RAnalOp *op, RAnalOpMask mask) { ut32 ins, ins2 = 0; const ut8 *b = op->bytes; - if (op->size < 3) return false; + int avail = op->size; + if (avail < 3) return false; ins = ((ut32) b[0] << 16) | ((ut32) b[1] << 8) | (ut32) b[2]; - if (op->size >= 6) + if (avail >= 6) ins2 = ((ut32) b[3] << 16) | ((ut32) b[4] << 8) | (ut32) b[5]; op->size = 3; op->type = R_ANAL_OP_TYPE_UNK; @@ -217,13 +218,22 @@ decode (RArchSession *as, RAnalOp *op, RAnalOpMask mask) return true; } - /* Constant YOP form: CC=bits7-6, BO=bits5-4 */ + /* Constant YOP form: YY=bits12-11, CC=bits7-6, BO=bits5-4. + Index = (YY<<2)|CC. BO=01: val = 1<> 11) & 0x3; ut32 cc = (ins >> 6) & 0x3; ut32 bo = (ins >> 4) & 0x3; - int val = (int) cc; - if (bo & 0x2) - val = -val; + ut32 idx = (yy << 2) | cc; + int32_t val; + if (idx == 15) + val = (bo & 0x2) ? 32767 : -32768; + else if (bo & 0x2) + val = -((int32_t)(1 << idx)) - 1; + else + val = (int32_t)(1 << idx); op->mnemonic = r_str_newf ("%s%s%s%s = %s(%s, %d)", cp, cs, sp, dst, f, x, val); return true; @@ -285,7 +295,7 @@ decode (RArchSession *as, RAnalOp *op, RAnalOpMask mask) /* Type 36: Long Jump/Call (2-word, bits 23-16 = 00000101) */ if ((ins >> 16) == 0x05) { - if (op->size < 6) + if (avail < 6) { op->mnemonic = r_str_newf ("trunc L%s 0x%06X", ((ins >> 12) & 1) ? "CALL" : "JUMP", ins); @@ -314,7 +324,7 @@ decode (RArchSession *as, RAnalOp *op, RAnalOpMask mask) /* Type 22: DM/PM = Data16 (2-word, bits 23-13 = 00000011110) */ if ((ins >> 13) == 0x1E && !((ins >> 12) & 1)) { - if (op->size < 6) + if (avail < 6) { op->mnemonic = r_str_newf ("trunc DM_IMM16 0x%06X", ins); @@ -336,7 +346,7 @@ decode (RArchSession *as, RAnalOp *op, RAnalOpMask mask) /* Type 22a: PM = Data24 (2-word, bits 23-13 = 00000011111) */ if ((ins >> 13) == 0x1F) { - if (op->size < 6) + if (avail < 6) { op->mnemonic = r_str_newf ("trunc PM_IMM24 0x%06X", ins); @@ -512,7 +522,7 @@ decode (RArchSession *as, RAnalOp *op, RAnalOpMask mask) for (i = 0; i < 8; i++) { ut32 v = (ins >> (i * 2)) & 0x3; - if (v == 1) + if (v == 2) pos += snprintf (buf + pos, sizeof (buf) - pos, "%sDIS %s", pos ? ", " : "", mbits[i]); diff --git a/r2plugin/asm_adsp219x.so b/r2plugin/asm_adsp219x.so index 967848e..8e1ced5 100755 Binary files a/r2plugin/asm_adsp219x.so and b/r2plugin/asm_adsp219x.so differ