Rizin
unix-like reverse engineering framework and cli tools
double.c File Reference
#include <rz_reg.h>
#include <rz_util.h>

Go to the source code of this file.

Macros

#define CASTLDBL
 

Functions

RZ_API double rz_reg_get_double (RzReg *reg, RzRegItem *item)
 
RZ_API bool rz_reg_set_double (RzReg *reg, RzRegItem *item, double value)
 
RZ_API long double rz_reg_get_longdouble (RzReg *reg, RzRegItem *item)
 
RZ_API bool rz_reg_set_longdouble (RzReg *reg, RzRegItem *item, long double value)
 
RZ_API float rz_reg_get_float (RzReg *reg, RzRegItem *item)
 
RZ_API bool rz_reg_set_float (RzReg *reg, RzRegItem *item, float value)
 

Macro Definition Documentation

◆ CASTLDBL

#define CASTLDBL

Definition at line 10 of file double.c.

Function Documentation

◆ rz_reg_get_double()

RZ_API double rz_reg_get_double ( RzReg reg,
RzRegItem item 
)

Definition at line 16 of file double.c.

16  {
17  RzRegSet *regset;
18  double vld = 0.0f;
19  int off;
20  double ret = 0.0f;
21  if (!reg || !item) {
22  return 0LL;
23  }
24  off = BITS2BYTES(item->offset);
25  regset = &reg->regset[item->arena];
26  switch (item->size) {
27  case 64:
28  if (regset->arena->size - off - 1 >= 0) {
29  memcpy(&vld, regset->arena->bytes + off, sizeof(double));
30  ret = vld;
31  }
32  break;
33  default:
34  eprintf("rz_reg_set_double: Bit size %d not supported\n", item->size);
35  return 0.0f;
36  }
37  return ret;
38 }
#define reg(n)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int off
Definition: pal.c:13
#define eprintf(x, y...)
Definition: rlcc.c:7
#define BITS2BYTES(x)
Definition: rz_types.h:280
ut8 * bytes
Definition: rz_reg.h:131
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120
int arena
In which arena is this reg living. Usually equals type.
Definition: rz_reg.h:127
int offset
Offset into register profile in bits.
Definition: rz_reg.h:121
RzRegArena * arena
Definition: rz_reg.h:136

References rz_reg_item_t::arena, rz_reg_set_t::arena, BITS2BYTES, rz_reg_arena_t::bytes, eprintf, memcpy(), off, rz_reg_item_t::offset, reg, rz_reg_item_t::size, and rz_reg_arena_t::size.

◆ rz_reg_get_float()

RZ_API float rz_reg_get_float ( RzReg reg,
RzRegItem item 
)

Definition at line 124 of file double.c.

124  {
125  // TODO
126  return 0.0f;
127 }

◆ rz_reg_get_longdouble()

RZ_API long double rz_reg_get_longdouble ( RzReg reg,
RzRegItem item 
)

Definition at line 67 of file double.c.

67  {
68  RzRegSet *regset;
69  long double vld = 0.0f;
70  int off;
71  long double ret = 0.0f;
72  if (!reg || !item) {
73  return 0LL;
74  }
75  off = BITS2BYTES(item->offset);
76  regset = &reg->regset[item->arena];
77  switch (item->size) {
78  case 80:
79  case 96:
80  case 128:
81  case 256:
82  if (regset->arena->size - off - 1 >= 0) {
83  memcpy(&vld, regset->arena->bytes + off, sizeof(long double));
84  ret = vld;
85  }
86  break;
87  default:
88  eprintf("rz_reg_get_longdouble: Bit size %d not supported\n", item->size);
89  return 0.0f;
90  }
91  return ret;
92 }

References rz_reg_item_t::arena, rz_reg_set_t::arena, BITS2BYTES, rz_reg_arena_t::bytes, eprintf, memcpy(), off, rz_reg_item_t::offset, reg, rz_reg_item_t::size, and rz_reg_arena_t::size.

Referenced by rz_reg_get_value(), and rz_regs_fpu_handler().

◆ rz_reg_set_double()

RZ_API bool rz_reg_set_double ( RzReg reg,
RzRegItem item,
double  value 
)

Definition at line 40 of file double.c.

40  {
41  ut8 *src;
42 
43  if (!item) {
44  eprintf("rz_reg_set_value: item is NULL\n");
45  return false;
46  }
47  switch (item->size) {
48  case 64:
49  // FIXME: endian
50  src = (ut8 *)&value;
51  break;
52  default:
53  eprintf("rz_reg_set_double: Bit size %d not supported\n", item->size);
54  return false;
55  }
56  if (reg->regset[item->arena].arena->size - BITS2BYTES(item->offset) - BITS2BYTES(item->size) >= 0) {
57  rz_mem_copybits(reg->regset[item->arena].arena->bytes +
58  BITS2BYTES(item->offset),
59  src, item->size);
60  return true;
61  }
62  eprintf("rz_reg_set_value: Cannot set %s to %lf\n", item->name, value);
63  return false;
64 }
lzma_index * src
Definition: index.h:567
static int value
Definition: cmd_api.c:93
uint8_t ut8
Definition: lh5801.h:11
RZ_API void rz_mem_copybits(ut8 *dst, const ut8 *src, int bits)
Definition: mem.c:79
char * name
Definition: rz_reg.h:118

References rz_reg_item_t::arena, BITS2BYTES, eprintf, rz_reg_item_t::name, rz_reg_item_t::offset, reg, rz_mem_copybits(), rz_reg_item_t::size, src, and value.

Referenced by rz_regs_fpu_handler().

◆ rz_reg_set_float()

RZ_API bool rz_reg_set_float ( RzReg reg,
RzRegItem item,
float  value 
)

Definition at line 129 of file double.c.

129  {
130  return false;
131 }

◆ rz_reg_set_longdouble()

RZ_API bool rz_reg_set_longdouble ( RzReg reg,
RzRegItem item,
long double  value 
)

Definition at line 94 of file double.c.

94  {
95  ut8 *src = NULL;
96 
97  if (!item) {
98  eprintf("rz_reg_set_value: item is NULL\n");
99  return false;
100  }
101  switch (item->size) {
102  case 80:
103  case 96:
104  case 128:
105  // FIXME: endian
106  src = (ut8 *)&value;
107  break;
108  default:
109  eprintf("rz_reg_set_longdouble: Bit size %d not supported\n", item->size);
110  return false;
111  }
112  if (reg->regset[item->arena].arena->size - BITS2BYTES(item->offset) - BITS2BYTES(item->size) >= 0) {
113  rz_mem_copybits(reg->regset[item->arena].arena->bytes +
114  BITS2BYTES(item->offset),
115  src, item->size);
116  return true;
117  }
118 
119  eprintf("rz_reg_set_value: Cannot set %s to %" LDBLFMT "\n", item->name, CASTLDBL value);
120  return false;
121 }
#define NULL
Definition: cris-opc.c:27
#define CASTLDBL
Definition: double.c:10
#define LDBLFMT
Definition: rz_types.h:401

References rz_reg_item_t::arena, BITS2BYTES, CASTLDBL, eprintf, LDBLFMT, rz_reg_item_t::name, NULL, rz_reg_item_t::offset, reg, rz_mem_copybits(), rz_reg_item_t::size, src, and value.

Referenced by rz_reg_set_value().