From 63669bee8529bed20d11a62ca03033c88cb0eb24 Mon Sep 17 00:00:00 2001 From: radare Date: Fri, 31 Aug 2018 03:05:41 +0200 Subject: [PATCH] Add support for wired-to-ground registers for MIPS and V850 (#11320) --- libr/anal/p/anal_mips_cs.c | 2 +- libr/anal/p/anal_v850.c | 1 + libr/reg/profile.c | 6 +++++- libr/reg/reg.c | 1 - libr/reg/value.c | 35 +++++++++++++++-------------------- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libr/anal/p/anal_mips_cs.c b/libr/anal/p/anal_mips_cs.c index 8adc3b36ba..12baf9b87f 100644 --- a/libr/anal/p/anal_mips_cs.c +++ b/libr/anal/p/anal_mips_cs.c @@ -1022,7 +1022,7 @@ static char *get_reg_profile(RAnal *anal) { "=A3 a3\n" "=R0 v0\n" "=R1 v1\n" - "gpr zero .32 0 0\n" + "gpr zero .32 ? 0\n" "gpr at .32 4 0\n" "gpr v0 .32 8 0\n" "gpr v1 .32 12 0\n" diff --git a/libr/anal/p/anal_v850.c b/libr/anal/p/anal_v850.c index ef0157c134..b21aaed661 100644 --- a/libr/anal/p/anal_v850.c +++ b/libr/anal/p/anal_v850.c @@ -359,6 +359,7 @@ static char *get_reg_profile(RAnal *anal) { "=OF ov\n" "=CF cy\n" + "gpr zero .32 ? 0\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" diff --git a/libr/reg/profile.c b/libr/reg/profile.c index 176139309c..08ec4c6864 100644 --- a/libr/reg/profile.c +++ b/libr/reg/profile.c @@ -73,7 +73,11 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { r_reg_item_free (item); return "Invalid size"; } - item->offset = parse_size (tok[3], &end); + if (!strcmp (tok[3], "?")) { + item->offset = -1; + } else { + item->offset = parse_size (tok[3], &end); + } if (*end != '\0') { r_reg_item_free (item); return "Invalid offset"; diff --git a/libr/reg/reg.c b/libr/reg/reg.c index 327f2febac..4a99826ed7 100644 --- a/libr/reg/reg.c +++ b/libr/reg/reg.c @@ -62,7 +62,6 @@ R_API const char* r_reg_64_to_32(RReg* reg, const char* rreg64) { return NULL; } - R_API const char* r_reg_get_type(int idx) { return (idx >= 0 && idx < R_REG_TYPE_LAST)? types[idx]: NULL; } diff --git a/libr/reg/value.c b/libr/reg/value.c index 997e764bd9..77d22841fb 100644 --- a/libr/reg/value.c +++ b/libr/reg/value.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2016 - pancake */ +/* radare - LGPL - Copyright 2009-2018 - pancake */ #include #include @@ -59,14 +59,11 @@ R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val) { } R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item) { - RRegSet *regset; - int off; - ut64 ret = 0LL; - if (!reg || !item) { + if (!reg || !item || item->offset == -1) { return 0LL; } - off = BITS2BYTES (item->offset); - regset = ®->regset[item->arena]; + int off = BITS2BYTES (item->offset); + RRegSet *regset = ®->regset[item->arena]; switch (item->size) { case 1: { @@ -74,54 +71,52 @@ R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item) { if (offset + item->size >= regset->arena->size) { break; } - ret = (regset->arena->bytes[offset] & + return (regset->arena->bytes[offset] & (1 << (item->offset % 8))) ? 1 : 0; } break; case 4: if (regset->arena->size - off - 1 >= 0) { - ret = (r_read_at_ble8 (regset->arena->bytes, off)) & 0xF; + return (r_read_at_ble8 (regset->arena->bytes, off)) & 0xF; } break; case 8: if (regset->arena->size - off - 1 >= 0) { - ret = r_read_at_ble8 (regset->arena->bytes, off); + return r_read_at_ble8 (regset->arena->bytes, off); } break; case 16: if (regset->arena->size - off - 2 >= 0) { - ret = r_read_ble16 (regset->arena->bytes + off, reg->big_endian); + return r_read_ble16 (regset->arena->bytes + off, reg->big_endian); } break; case 27: if (off + 3 < regset->arena->size) { - ret = r_read_me27 (regset->arena->bytes + off, 0); + return r_read_me27 (regset->arena->bytes + off, 0); } break; case 32: if (off + 4 <= regset->arena->size) { - ret = r_read_ble32 (regset->arena->bytes + off, reg->big_endian); - } else { - eprintf ("r_reg_get_value: 32bit oob read %d\n", off); + return r_read_ble32 (regset->arena->bytes + off, reg->big_endian); } + eprintf ("r_reg_get_value: 32bit oob read %d\n", off); break; case 64: if (regset->arena->bytes && (off + 8 <= regset->arena->size)) { - ret = r_read_ble64 (regset->arena->bytes + off, reg->big_endian); - } else { - eprintf ("r_reg_get_value: null or oob arena for current regset\n"); + return r_read_ble64 (regset->arena->bytes + off, reg->big_endian); } + eprintf ("r_reg_get_value: null or oob arena for current regset\n"); break; case 80: // long double case 96: // long floating value // FIXME: It is a precision loss, please implement me properly! - ret = (ut64)r_reg_get_longdouble (reg, item); + return (ut64)r_reg_get_longdouble (reg, item); break; default: eprintf ("r_reg_get_value: Bit size %d not supported\n", item->size); break; } - return ret; + return 0LL; } R_API ut64 r_reg_get_value_by_role(RReg *reg, RRegisterId role) {