2015-08-23 01:58:49 +00:00
|
|
|
/* radare - LGPL - Copyright 2015 - pancake */
|
|
|
|
|
|
|
|
#include <r_reg.h>
|
|
|
|
#include <r_util.h>
|
|
|
|
|
2015-09-21 21:40:17 +00:00
|
|
|
// TODO: add support for 80bit floating point value
|
|
|
|
|
|
|
|
// long double = 128 bit
|
|
|
|
R_API double r_reg_get_double(RReg *reg, RRegItem *item) {
|
|
|
|
RRegSet *regset;
|
|
|
|
double vld = 0.0f;
|
|
|
|
int off;
|
|
|
|
double ret = 0.0f;
|
|
|
|
if (!reg || !item)
|
|
|
|
return 0LL;
|
|
|
|
off = BITS2BYTES (item->offset);
|
|
|
|
regset = ®->regset[item->type];
|
|
|
|
switch (item->size) {
|
|
|
|
case 64:
|
2015-12-08 22:55:23 +00:00
|
|
|
if (regset->arena->size - off - 1 >= 0) {
|
|
|
|
memcpy (&vld, regset->arena->bytes + off, sizeof (double));
|
2015-09-21 21:40:17 +00:00
|
|
|
ret = vld;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-08 22:55:23 +00:00
|
|
|
eprintf ("r_reg_set_double: Bit size %d not supported\n", item->size);
|
2015-09-21 21:40:17 +00:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_reg_set_double(RReg *reg, RRegItem *item, double value) {
|
|
|
|
double vld = 0.0f;
|
|
|
|
ut8 *src;
|
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
eprintf ("r_reg_set_value: item is NULL\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (item->size) {
|
|
|
|
case 64:
|
2015-12-08 22:55:23 +00:00
|
|
|
r_mem_copyendian ((ut8 *)&vld, (ut8 *)&value, 10, !reg->big_endian);
|
|
|
|
src = (ut8 *)&vld;
|
2015-09-21 21:40:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-12-08 22:55:23 +00:00
|
|
|
eprintf ("r_reg_set_double: Bit size %d not supported\n", item->size);
|
2015-09-21 21:40:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-08 22:55:23 +00:00
|
|
|
if (reg->regset[item->type].arena->size - BITS2BYTES (item->offset) - BITS2BYTES (item->size) >= 0) {
|
|
|
|
r_mem_copybits (reg->regset[item->type].arena->bytes +
|
|
|
|
BITS2BYTES (item->offset),
|
|
|
|
src, item->size);
|
2015-09-21 21:40:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
eprintf ("r_reg_set_value: Cannot set %s to %lf\n", item->name, value);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-23 01:58:49 +00:00
|
|
|
// long double = 80 bit
|
2015-09-21 21:40:17 +00:00
|
|
|
R_API long double r_reg_get_longdouble(RReg *reg, RRegItem *item) {
|
2015-08-23 01:58:49 +00:00
|
|
|
RRegSet *regset;
|
|
|
|
long double vld = 0.0f;
|
|
|
|
int off;
|
|
|
|
long double ret = 0.0f;
|
|
|
|
if (!reg || !item)
|
|
|
|
return 0LL;
|
|
|
|
off = BITS2BYTES (item->offset);
|
|
|
|
regset = ®->regset[item->type];
|
|
|
|
switch (item->size) {
|
2015-10-22 11:38:30 +00:00
|
|
|
case 80:
|
|
|
|
case 96:
|
2015-09-21 21:40:17 +00:00
|
|
|
case 128:
|
2015-12-08 22:55:23 +00:00
|
|
|
if (regset->arena->size - off - 1 >= 0) {
|
2015-10-22 11:38:30 +00:00
|
|
|
memcpy (&vld, regset->arena->bytes + off, sizeof (long double));
|
2015-08-23 01:58:49 +00:00
|
|
|
ret = vld;
|
|
|
|
}
|
|
|
|
break;
|
2015-09-21 21:40:17 +00:00
|
|
|
default:
|
2015-12-08 22:55:23 +00:00
|
|
|
eprintf ("r_reg_get_longdouble: Bit size %d not supported\n", item->size);
|
2015-09-21 21:40:17 +00:00
|
|
|
return 0.0f;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-21 21:40:17 +00:00
|
|
|
R_API bool r_reg_set_longdouble(RReg *reg, RRegItem *item, long double value) {
|
2015-08-23 01:58:49 +00:00
|
|
|
long double vld = 0.0f;
|
|
|
|
ut8 *src;
|
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
eprintf ("r_reg_set_value: item is NULL\n");
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|
|
|
|
switch (item->size) {
|
|
|
|
case 80:
|
2015-10-22 11:38:30 +00:00
|
|
|
case 96:
|
2015-09-21 21:40:17 +00:00
|
|
|
case 128:
|
2015-12-08 22:55:23 +00:00
|
|
|
r_mem_copyendian ((ut8 *)&vld, (ut8 *)&value, 10, !reg->big_endian);
|
|
|
|
src = (ut8 *)&vld;
|
2015-08-23 01:58:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-12-08 22:55:23 +00:00
|
|
|
eprintf ("r_reg_set_longdouble: Bit size %d not supported\n", item->size);
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|
2015-12-08 22:55:23 +00:00
|
|
|
if (reg->regset[item->type].arena->size - BITS2BYTES (item->offset) - BITS2BYTES (item->size) >= 0) {
|
|
|
|
r_mem_copybits (reg->regset[item->type].arena->bytes +
|
|
|
|
BITS2BYTES (item->offset),
|
|
|
|
src, item->size);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|
|
|
|
eprintf ("r_reg_set_value: Cannot set %s to %Lf\n", item->name, value);
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* floating point . deprecate maybe? */
|
|
|
|
R_API float r_reg_get_float(RReg *reg, RRegItem *item) {
|
|
|
|
// TODO
|
2015-09-21 21:40:17 +00:00
|
|
|
return 0.0f;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 21:40:17 +00:00
|
|
|
R_API bool r_reg_set_float(RReg *reg, RRegItem *item, float value) {
|
|
|
|
return false;
|
2015-08-23 01:58:49 +00:00
|
|
|
}
|