Permalink
Browse files

Fix 'cmp' in ARM assembler

- gnu dis is confusing:
  cmp r3, 1, 30 -> cmp r3, 1<<(32-30)
  • Loading branch information...
1 parent da33633 commit 3e5dc60379a63c7a298f5841eade4631d117ea43 @radare committed Dec 29, 2013
Showing with 34 additions and 9 deletions.
  1. +1 −0 Makefile
  2. +30 −6 libr/asm/arch/arm/armass.c
  3. +3 −3 libr/asm/p/asm_x86.c
View
@@ -162,6 +162,7 @@ purge-dev:
purge: purge-doc purge-dev
for a in ${R2BINS} ; do rm -f ${DESTDIR}/${BINDIR}/$$a ; done
rm -f ${DESTDIR}/${BINDIR}/ragg2-cc
+ rm -f ${DESTDIR}/${BINDIR}/r2
rm -f ${DESTDIR}/${LIBDIR}/libr_*
rm -rf ${DESTDIR}/${LIBDIR}/radare2
rm -rf ${DESTDIR}/${INCLUDEDIR}/libr
@@ -538,6 +538,22 @@ static int thumb_assemble(ArmOpcode *ao, const char *str) {
return 1;
}
+static int findyz(int x, int *y, int *z) {
+ int i, j;
+ for (i=0;i<0xff; i++) {
+ for (j=0;j<0xf;j++) {
+ int v = i<<j;
+ if (v>x) continue;
+ if (v==x) {
+ *y = i;
+ *z = 16-(j/2);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
static int arm_assemble(ArmOpcode *ao, const char *str) {
int i, j, ret, reg, a, b;
for (i=0; ops[i].name; i++) {
@@ -640,15 +656,23 @@ static int arm_assemble(ArmOpcode *ao, const char *str) {
a = getreg (ao->a[0]);
b = getreg (ao->a[1]);
if (b == -1) {
+ ut16 numshift;
+ int y, z;
b = getnum (ao->a[1]);
- if (b<0|| b>255) {
- eprintf ("Parameter out of range (0-255)\n");
+ if (b>=0 && b<=0xff) {
+ ao->o = 0x50e3;
+ // TODO: if (b>255) -> automatic multiplier
+ ao->o |= (a<<8);
+ ao->o |= ((b&0xff)<<24);
+ } else
+ if (findyz (b, &y, &z)) {
+ ao->o = 0x50e3;
+ ao->o |= (y<<24);
+ ao->o |= (z<<16);
+ } else {
+ eprintf ("Parameter %d out of range (0-255)\n", (int)b);
return 0;
}
- ao->o = 0x50e3;
- // TODO: if (b>255) -> automatic multiplier
- ao->o |= (a<<8);
- ao->o |= ((b&0xff)<<24);
} else {
ao->o |= (a<<8);
ao->o |= (b<<24);
@@ -52,10 +52,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
ud_set_input_buffer (&d, (uint8_t*) buf, len);
ud_set_pc (&d, a->pc);
ud_set_mode (&d, a->bits);
- op->size = ud_disassemble (&d);
+ opsize = ud_disassemble (&d);
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s", ud_insn_asm (&d));
- opsize = op->size;
- if (op->size<1 || strstr (op->buf_asm, "invalid"))
+ op->size = opsize;
+ if (opsize<1 || strstr (op->buf_asm, "invalid"))
opsize = -1;
return opsize;
}

0 comments on commit 3e5dc60

Please sign in to comment.