Example #1
0
static void do_realloc( struct x86_function *p )
{
   if (p->store == p->error_overflow) {
      p->csr = p->store;
   }
   else if (p->size == 0) {
      p->size = 1024;
      p->store = rtasm_exec_malloc(p->size);
      p->csr = p->store;
   }
   else {
      uintptr_t used = pointer_to_uintptr( p->csr ) - pointer_to_uintptr( p->store );
      unsigned char *tmp = p->store;
      p->size *= 2;
      p->store = rtasm_exec_malloc(p->size);

      if (p->store) {
         memcpy(p->store, tmp, used);
         p->csr = p->store + used;
      }
      else {
         p->csr = p->store;
      }

      rtasm_exec_free(tmp);
   }

   if (p->store == NULL) {
      p->store = p->csr = p->error_overflow;
      p->size = sizeof(p->error_overflow);
   }
}
Example #2
0
/**
 * Append instruction to instruction buffer.  Grow buffer if out of room.
 */
static void
emit_instruction(struct ppc_function *p, uint32_t inst_bits)
{
   if (!p->store)
      return;  /* out of memory, drop the instruction */

   if (p->num_inst == p->max_inst) {
      /* allocate larger buffer */
      uint32_t *newbuf;
      p->max_inst *= 2;  /* 2x larger */
      newbuf = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE);
      if (newbuf) {
         memcpy(newbuf, p->store, p->num_inst * PPC_INST_SIZE);
      }
      rtasm_exec_free(p->store);
      p->store = newbuf;
      if (!p->store) {
         /* out of memory */
         p->num_inst = 0;
         return;
      }
   }

   p->store[p->num_inst++] = inst_bits;
}
Example #3
0
void x86_init_func_size( struct x86_function *p, unsigned code_size )
{
   p->size = code_size;
   p->store = rtasm_exec_malloc(code_size);
   if (p->store == NULL) {
      p->store = p->error_overflow;
   }
   p->csr = p->store;
   DUMP_START();
}
Example #4
0
void
ppc_init_func(struct ppc_function *p)
{
   uint i;

   memset(p, 0, sizeof(*p));

   p->num_inst = 0;
   p->max_inst = 100; /* first guess at buffer size */
   p->store = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE);
   p->reg_used = 0x0;
   p->fp_used = 0x0;
   p->vec_used = 0x0;

   p->print = FALSE;
   p->indent = 0;

   /* only allow using gp registers 3..12 for now */
   for (i = 0; i < 3; i++)
      ppc_reserve_register(p, i);
   for (i = 12; i < PPC_NUM_REGS; i++)
      ppc_reserve_register(p, i);
}