Example #1
0
uint64_t
aarch64_get_stack_start (sim_cpu *cpu)
{
  if (aarch64_get_heap_start (cpu) >= STACK_TOP)
    mem_error (cpu, "executable is too big", aarch64_get_heap_start (cpu));
  return STACK_TOP;
}
Example #2
0
void *mem_resize(void *ptr, size_t size, const char *func_name)
{
	assert(ptr);
	assert(size > 0);
	ptr = realloc(ptr, size);
	if (ptr == NULL) {
		mem_error(size, __func__, func_name);
	}
	return ptr;
}
Example #3
0
void* mem_calloc(size_t count, size_t size, const char *func_name)
{
	void *ptr;
	assert(count > 0);
	assert(size > 0);
	ptr = calloc(count, size);
	if (ptr == NULL) {
		mem_error(count, __func__, func_name);
	}
	return ptr;
}
Example #4
0
void *my_try_alloc(size_t size)
{
	void *ptr = malloc(size);
	
	if (ptr == NULL)
	{
		mem_error("malloc mem(size = %d) failed\n", size);
	}
	
	return ptr;
}
Example #5
0
void* mem_alloc(size_t size, const char*func_name)
{
	char* cp = NULL;

	if (func_name == NULL)
		logerr ("%s() Warning: No calling function name provided.", __func__);

	cp = (char*) malloc (size);
	if (cp == NULL)
		mem_error(size, __func__, func_name);

	return cp;
}
Example #6
0
const char *
aarch64_get_mem_ptr (sim_cpu *cpu, uint64_t address)
{
  char *addr = sim_core_trans_addr (CPU_STATE (cpu), cpu, read_map, address);

  if (addr == NULL)
    {
      mem_error (cpu, "request for non-existant mem addr of", address);
      sim_engine_halt (CPU_STATE (cpu), cpu, NULL, aarch64_get_PC (cpu),
		       sim_stopped, SIM_SIGBUS);
    }

  return addr;
}
Example #7
0
void
aarch64_get_mem_blk (sim_cpu *  cpu,
		     uint64_t   address,
		     char *     buffer,
		     unsigned   length)
{
  unsigned len;

  len = sim_core_read_buffer (CPU_STATE (cpu), cpu, read_map,
			      buffer, address, length);
  if (len == length)
    return;

  memset (buffer, 0, length);
  if (cpu)
    mem_error (cpu, "read of non-existant mem block at", address);

  sim_engine_halt (CPU_STATE (cpu), cpu, NULL, aarch64_get_PC (cpu),
		   sim_stopped, SIM_SIGBUS);
}
Example #8
0
/*
 * Convert a binary number (string) to a series of characters
 */
int number_to_string( char *string )
{
    int sLen = strlen( string );    //  Length of original string
    int ch = 0;                     //  Integer to receive character value
    int stringMoved = 0;            //  Number of times string was incremeneted
    int counter;                    //  Generic counter


    /*  Create our bin string */
    char *binStr = malloc( (BIN_STR_LENGTH) );
    if( binStr == NULL )
    {
        mem_error("In:  number_to_string");
        return(1);
    }

    /*  A mutable copy of the original string */
    char fromStringStack[ sLen ];
    char *fromString = fromStringStack;

    /*  Null out strings */
    memset( binStr, '\0', (BIN_STR_LENGTH) );
    memset( fromString, '\0', ( sLen + 1 ));

    /*  Strip whitespace */
    strip_whitespace( fromString, string );


    /*
     * Go through the string, grabbing 8-bit (or fewer) chunks of it and
     * converting said 'chunks' to ASCII character values, printing each
     * along the way.
     */
    while( 1 )
    {
        /*  Check if we're only working with one character */
        if( sLen <= (BIN_STR_LENGTH) + 1)
        {
            ch = (int)binary_to_decimal( fromString );

            if( ch != 0 )
            {
                text_mode_printer( ch, fromString );

                if( lineSpacing == 1 && totalConversions < 2 )
                    printf("\n");
            }

            break;
        }
        else
        {
            for( counter = 0; counter <= (BIN_STR_LENGTH) ; ++counter )
            {
                binStr[counter] = fromString[counter];
            }

            fromString += counter;
            stringMoved += counter;
            sLen -= counter;


            ch = (int)binary_to_decimal( binStr );

            text_mode_printer( ch, binStr );
            memset( binStr, '\0', (BIN_STR_LENGTH) );

            if( lineSpacing == 1 )
                printf("\n");
            else if( verbose == 1 )
                printf("\t");
        }


    }

    if( lineSpacing == 0 )
        printf("\n");

    /*  Reset the original string */
    fromString -= stringMoved;

    /*  Free / null binStr */
    free( binStr );
    binStr = NULL;

    return(0);
}
Example #9
0
/*
 * Herein we compile a string of text to be printed, based on various factors
 * such as whether or not verbosity is switched on, which conversions were
 * called for, etc.
 */
void text_mode_printer( int ch, char *string )
{
    char *line = malloc( 32 );
    if( line == NULL )
    {
        mem_error("In:  text_mode_printer");
        exit(1);
    }

    if( verbose == 1 )
    {
        if( bin2bin == 1 )
        {
            sprintf( line, "%c  BIN    %s", ch, string );
            text_mode_printer_finish( line );
            printf("%s", line);

            memset( line, '\0', 32 );
        }

        if( bin2oct == 1 )
        {
            sprintf( line, "%c  OCT    %o", ch, ch );
            text_mode_printer_finish( line );
            printf("%s", line);

            memset( line, '\0', 32 );
        }

        if( bin2dec == 1 )
        {
            sprintf( line, "%c  DEC    %d", ch, ch );
            text_mode_printer_finish( line );
            printf("%s", line);

            memset( line, '\0', 32 );
        }

        if( bin2hex == 1 )
        {
            sprintf( line, "%c  HEX    %x", ch, ch );
            text_mode_printer_finish( line );
            printf("%s", line);

            memset( line, '\0', 32 );
        }

        if( hexCaps == 1 )
        {
            sprintf( line, "%c  HEX    %X", ch, ch );
            text_mode_printer_finish( line );
            printf("%s", line);

            memset( line, '\0', 32 );
        }
    }

    else
    {
        sprintf( line, "%c", ch );
        text_mode_printer_finish( line );
        printf("%s", line );
    }


    free( line );
    line = NULL;

}
Example #10
0
/*
 * Master output decider function thingy
 */
int string_printer( double *decimalResult )
{
    /*  Create a string pointer, allocate memory to it */
    char *s = NULL;
    s = malloc( MAX_STRING_LENGTH );
    if( s == NULL )
    {
        mem_error( "string_printer:  Cannot allocate memory for string" );
        return(1);
    }

    /*  Print the result */
    if( bin2dec == 1 )  //  Decimal
    {
        if( verbose == 1 )
            printf( "DEC\t");

        sprintf( s, "%s%0.lf", s, *decimalResult );
        print_number_string( s );
        memset( s, '\0', MAX_STRING_LENGTH );
    }

    if( bin2oct == 1 )  //  Octal
    {
        if( verbose == 1 )
            printf("OCT\t");

        sprintf( s, "%s%o", s, (unsigned int)*decimalResult );
        print_number_string( s );
        memset( s, '\0', MAX_STRING_LENGTH );
    }

    if( bin2hex == 1 )  //  Hex
    {
        if( verbose == 1 )
            printf("HEX\t");

        sprintf( s, "%s%x", s, (unsigned int)*decimalResult );

        print_number_string( s );
        memset( s, '\0', MAX_STRING_LENGTH );
    }

    if( hexCaps == 1 )  //  Hex (with caps)
    {
        if( verbose == 1 )
            printf("HEX\t");

        sprintf( s, "%s%X", s, (unsigned int)*decimalResult );
        print_number_string( s );
        memset( s, '\0', MAX_STRING_LENGTH );

    }

    if( bin2phex == 1 ) //  SUPER HEX
    {
        if( verbose == 1 )
            printf("0xHEX\t");

        sections = 0;   //  Need to do this, otherwise stuff gets ugly

        sprintf( s, "%s%a", s, *decimalResult );
        print_number_string( s );
        memset( s, '\0', MAX_STRING_LENGTH );
    }

    if( phexCaps == 1 ) //  SUPER HEX (with caps)
    {
        if( verbose == 1 )
            printf("0xHEX\t");

        sections = 0;   //  Need to do this, otherwise stuff gets ugly

        sprintf( s, "%s%A", s, *decimalResult );
        print_number_string( s );
        memset( s, '\0', MAX_STRING_LENGTH );

    }

    /*  free our string buffer */
    free( s );
    s = NULL;

    return(0);
}
Example #11
0
int
write_MemFile(const char *path, DbfLocale * tbl, DbfData * arr, char **names, int acount, char *errbuf, int errbuflen)
{
   int r = 0, i, line;

   FILE *file;

   MemHeader mh;

   DbfData *dp;

   file = fopen(path, "wb");
   if (!file)
      return mem_error(errbuf, errbuflen, __LINE__, "cannot open file '%s': %s", path, strerror(errno));

   for (i = 0; i < acount; ++i)
   {
      dp = arr + i;

      memset(&mh, 0, sizeof(mh));
      strncpy((char *) mh.name, names[i], 10);

      switch (dp->type)
      {
      case 'C':
	 {
	    int len;

	    len = dp->u.c.len + 1;
	    mh.type = 0xC3;
	    mh.len = len & 0xff;
	    mh.dec = (len >> 8) & 0xff;
	 }
	 break;
      case 'L':
	 mh.type = 0xCC;
	 mh.len = 1;
	 break;
      case 'N':
	 mh.type = 0xCE;
	 mh.len = dp->len;
	 mh.dec = dp->dec;
	 break;
      case 'D':
	 mh.type = 0xC4;
	 mh.len = 1;
	 break;
      default:
	 continue;
      }

      if (fwrite(&mh, sizeof(mh), 1, file) != 1)
      {
	 line = __LINE__;
       writerr:
	 r = mem_error(errbuf, errbuflen, line, "file '%s' write error: %s", strerror(errno));
	 goto ret;
      }

      switch (mh.type)
      {
      case 0xC3:		/* string */
	 {
	    char *sp;

	    int len;

	    int j;

	    len = dp->u.c.len + 1;
	    sp = dp->u.c.str;

	    for (j = 0; j < len; ++j, ++sp)
	    {
	       int s = *(unsigned char *) sp;

	       if (tbl && s > 127)
		  s = tbl->write[s - 128];
	       if (fputc(s, file) == EOF)
	       {
		  line = __LINE__;
		  goto writerr;
	       }
	    }
	 }
	 break;
      case 0xCC:		/* logic */
	 {
	    char ch;

	    ch = dp->u.l;
	    if (fputc(ch, file) == EOF)
	    {
	       line = __LINE__;
	       goto writerr;
	    }
	 }
	 break;
      case 0xCE:		/* numeric */
	 {
	    double d;

	    unsigned char buf[8];

	    int j;

	    d = dp->u.n;
	    for (j = 0; j < 8; ++j)
	       buf[j] = ((unsigned char *) &d)[j];
	    if (fwrite(buf, 8, 1, file) != 1)
	    {
	       line = __LINE__;
	       goto writerr;
	    }
	 }
	 break;
      case 0xC4:		/* date */
	 {
	    double d;

	    unsigned char buf[8];

	    int j;

	    d = dp->u.d;
	    for (j = 0; j < 8; ++j)
	       buf[j] = ((unsigned char *) &d)[j];
	    if (fwrite(buf, 8, 1, file) != 1)
	    {
	       line = __LINE__;
	       goto writerr;
	    }
	 }
	 break;
      }
   }

 ret:
   fclose(file);

   return r;
}