Esempio n. 1
0
int read_qdppp_lattice_fermion_double(int latdims[], double  *LatticeFermion, char *fin)
{

    long int buff_size=latdims[0]*latdims[1]*latdims[2]*latdims[3]*4*3*2*8; /*size in bytes of a single precision lattice fermion*/
    int num_elem=buff_size/8;
    int check_reading;

    check_reading=read_qdppp_scidac_binary_data((void *)LatticeFermion, buff_size,fin);

    if(check_reading == EXIT_FAILURE)
    {
        fprintf(stderr,"Error reading SCIDAC binary data\n");
        exit(EXIT_FAILURE);
    }

    /*test the machine endianness*/
    int check_end=endianness();

    if(check_end == UNKNOWN_ENDIAN)
    {
       fprintf(stderr,"Error: machine endianess is unknown.\n");
       exit(EXIT_FAILURE);
    }

    if(check_end == BIG_ENDIAN)
      return;   /*no swapping is needed*/

    if(check_end == LITTLE_ENDIAN)
      bswap_double(num_elem,LatticeFermion);

    return;   
}
int main (void)
{
  FILE *fp;
  int i, j;
  LL data[4];
  Byte buf[128];
  fp = fopen ("test-out", "w");
  if (!fp) {
    printf ("could not open file test-out for writing\n");
    return 1;
  }
  fprintf (fp, "Does a mips-sgi-irix5 binary work on an x86?\n");
  fprintf (fp, "In spite of what libbfd docs say?\n");
  fprintf (fp, "Your host seems to be of type %s-endian\n", endianness ());
  printf ("Summation\n\n");
  i = 5;
  do {
    printf ("Int: ");
    j = sum (i);
    printf ("sum %d = %d\n", i, j);
    fprintf (fp, "sum[%d] = %d\n", i, j);
    i--;
  } while (i > 0);
  fclose (fp);
  return 0;
}
Esempio n. 3
0
uint64_t mrtd_bac_get_ssc(const uint8_t *remote_challenge, const uint8_t *rnd_ifd)
{
	char ssc[8];
	uint64_t ssc_long;

	memcpy(ssc,remote_challenge+4,4);
	memcpy(ssc+4,rnd_ifd+4,4);

	if(endianness()){
		*(((uint8_t*)(&ssc_long))+0) = ssc[0];
		*(((uint8_t*)(&ssc_long))+1) = ssc[1];
		*(((uint8_t*)(&ssc_long))+2) = ssc[2];
		*(((uint8_t*)(&ssc_long))+3) = ssc[3];
		*(((uint8_t*)(&ssc_long))+4) = ssc[4];
		*(((uint8_t*)(&ssc_long))+5) = ssc[5];
		*(((uint8_t*)(&ssc_long))+6) = ssc[6];
		*(((uint8_t*)(&ssc_long))+7) = ssc[7];
	}
	else {
		*(((uint8_t*)(&ssc_long))+7) = ssc[0];
		*(((uint8_t*)(&ssc_long))+6) = ssc[1];
		*(((uint8_t*)(&ssc_long))+5) = ssc[2];
		*(((uint8_t*)(&ssc_long))+4) = ssc[3];
		*(((uint8_t*)(&ssc_long))+3) = ssc[4];
		*(((uint8_t*)(&ssc_long))+2) = ssc[5];
		*(((uint8_t*)(&ssc_long))+1) = ssc[6];
		*(((uint8_t*)(&ssc_long))+0) = ssc[7];
	}

	return ssc_long;
}
Esempio n. 4
0
const char* nvb_reader_impl::ucode() const
{
    if ( 0 == image_ || 0 == ucode_size() )
	return 0;

    return ( image_ + convert_endianness( header_.ucode, endianness() ) );
}
Esempio n. 5
0
CGBIO_ERROR nvb_reader_impl::get_param_name( unsigned int index, const char **name, bool& is_referenced ) const
{
	if ( index >= number_of_params() )
		return CGBIO_ERROR_INDEX;

	if ( 0 == image_ )
		return CGBIO_ERROR_NO_ERROR;

	const CgBinaryParameter* params = reinterpret_cast<CgBinaryParameter*>( &image_[convert_endianness( header_.parameterArray, endianness_ )] );
	const CgBinaryParameter& pp = params[index];
    is_referenced = convert_endianness( pp.isReferenced, endianness() ) != 0;
	CgBinaryStringOffset nm_offset = convert_endianness( pp.name,endianness() );
	if ( nm_offset != 0 )
		*name = &image_[nm_offset];
	else
		*name = "";
	return CGBIO_ERROR_NO_ERROR;
}
 /**
  * Return the full, quoted datatype string
  */
 static std::string dtype()
 {
   std::string ans(5, '\0');
   ans[0] = '\'';
   ans[1] = endianness();
   ans[2] = type();
   ans[3] = size();
   ans[4] = '\'';
   return ans;
 }
Esempio n. 7
0
static int check_machine(void)
{
   int ie;
   
   error_root(sizeof(stdint_t)!=4,1,"check_machine [archive_ildg.c]",
              "Size of a stdint_t integer is not 4");
   error_root(sizeof(double)!=8,1,"check_machine [archive_ildg.c]",
              "Size of a double is not 8");   

   ie=endianness();
   error_root(ie==UNKNOWN_ENDIAN,1,"check_machine [archive_ildg.c]",
              "Unkown endianness");

   return ie;
}
Esempio n. 8
0
File: main.c Progetto: damora/ivr
//-----------------------------------------------------------------------------------------------------------------------//
// initvolattrs
//-----------------------------------------------------------------------------------------------------------------------//
void initvolattrs(CMDARGS args, int rank)
{

    int machendian;

    // determine endianess of machine
    // 1 if little endian, 0 if big endian
    machendian = endianness();

    // get the volume, allocate memory, calculate brick size,number, calculate tile size,number
    if (machendian != args.dataendian) volume.byteswap = 1;

    // get/set information about volume
    volume.globaldims.w = args.width;
    volume.globaldims.h = args.height;
    volume.globaldims.d = args.depth;

    // mapping
    volume.procdims.y = args.procdims[0];
    volume.procdims.x = args.procdims[1];
    volume.procdims.z = args.procdims[2];

    // compute geometry for decmposition based on global dimentions and mapping to ranks
    initvolbbox(rank);

    volume.celldims.x = 1.0f; // THIS WILL EVENTUALLY BE CONTAINED IN ARGS OR IN VOLUME DATA HEADER
    volume.celldims.y = 1.0f; // THIS WILL EVENTUALLY BE CONTAINED IN ARGS OR IN VOLUME DATA HEADER
    volume.celldims.z = 1.0f; // THIS WILL EVENTUALLY BE CONTAINED IN ARGS OR IN VOLUME DATA HEADER
    volume.fvoldims.x = (float) volume.localdims.w;
    volume.fvoldims.y = (float) volume.localdims.h;
    volume.fvoldims.z = (float) volume.localdims.d;
    volume.rfvoldims.x = 1.0f / volume.localdims.w;
    volume.rfvoldims.y = 1.0f / volume.localdims.h;
    volume.rfvoldims.z = 1.0f / volume.localdims.d;

    return;
}
Esempio n. 9
0
/********************************* FUNCTION DEFINITIONS ****************************/
void nrk_init_nw_stack()
{
	if(endianness() == ERROR_ENDIAN)
	{
		nrk_int_disable();
		nrk_led_set(RED_LED);
		while(1)
			nrk_kprintf(PSTR("Error in calculating endianness in init_nw_stack()"));
	}
	
	// initialise a random number generator 
	srand(NODE_ADDR);
	
	initialise_serial_communication();
	if(DEBUG_NWSC == 2)
		nrk_kprintf(PSTR("Serial communications initalized\r\n"));
		
	initialise_buffer_manager();
	if(DEBUG_NWSC == 2)
		nrk_kprintf(PSTR("Buffer manager initialised\r\n"));
	
	initialise_transport_layer_udp();
	if(DEBUG_NWSC == 2)
		nrk_kprintf(PSTR("Transport layer initialised\r\n"));
	
	//widom mac will be init in network rx task
	//bmac_task_config();
	//if(DEBUG_NWSC == 2)
	//	nrk_kprintf(PSTR("Link layer initialised\r\n"));
	
	initialise_network_layer();
	if(DEBUG_NWSC == 2)
		nrk_kprintf(PSTR("Network layer initialised\r\n"));
		
	return;
}
Esempio n. 10
0
unsigned int nvb_reader_impl::ucode_size() const
{
    return convert_endianness( header_.ucodeSize, endianness() );
}
Esempio n. 11
0
/* This function computes information about all unexpanded operands, placing
 * information needed to extract them into op.  It also determines appropriate
 * byte ordering information and modifies v's code to swap bytes when
 * appropriate.  Returns the number of words of operands.
 */
int
compute_operand_info (OperandInfo *op, const ParsedOpcodeInfo *p,
		      const CCVariant *v)
{
  PatternRange range;
  ExprInfo field_info[16];
  char decls[2048];
  int words_in = p->operand_words_to_skip;
  int i;

  /* Zero out everything by default. */
  memset (op, 0, sizeof *op);

  /* Start out with the endianness/size of all operands unknown. */
  memset (field_info, 0, sizeof field_info);

  /* Figure out whatever we can about various fields. */
  for (i = 1; pattern_range (p->opcode_bits, i, &range); i++)
    {
      /* Was this field expanded? */
      if (field_expanded (i, p->opcode_bits, v->bits_to_expand))
	{
	  /* Yep; it's going to expand to a constant number,
	   * so specify the byte order as NATIVE.
	   */
	  field_info[i].order = BO_NATIVE;
	  break;
	}
    }

  /* Loop through unexpanded fields and nail down their size + signedness. */
  for (i = 1; pattern_range (p->opcode_bits, i, &range); i++)
    {
      Token *dollartok;
  
      /* If this field was expanded, no need to save it as an operand. */
      if (field_expanded (i, p->opcode_bits, v->bits_to_expand))
	continue;

      /* See if this field was actually used as a numeric constant. */
      if ((dollartok = has_tok_dollar (v->code, TOK_DOLLAR_NUMBER, i)) != NULL)
	{
	  field_info[i].sgnd = dollartok->u.dollarinfo.sgnd;
	  field_info[i].size = dollartok->u.dollarinfo.size;
	}
      else if (has_tok_dollar_reg (v->code, i))
	{
	  /* Make register numbers be 32 bit uints, since this seems to
	   * make most compilers the happiest when doing array references.
	   */
	  field_info[i].sgnd  = FALSE;
	  field_info[i].size  = BS_LONG;
	  field_info[i].order = BO_NATIVE;
	}
    }

  /* Recursively set/determine the endianness of all expressions and
   * add in swap's where appropriate.
   */
  endianness (v->code, BO_UNKNOWN, BO_NATIVE, FALSE, field_info);

  /* For all of the fields that weren't expanded, create bitfield
   * information for them and create a declaration.
   */
  for (i = 1; pattern_range (p->opcode_bits, i, &range); i++)
    {
      BitfieldInfo *b;

      /* If this field was expanded, no need to save it as an operand. */
      if (field_expanded (i, p->opcode_bits, v->bits_to_expand))
	continue;

      /* See if this field was actually used as a numeric constant,
       * or as a register number...
       */
      if (has_tok_dollar (v->code, TOK_DOLLAR_NUMBER, i) == NULL
	  && !has_tok_dollar_reg (v->code, i))
	continue;

      /* If we just don't care about byte order for a numeric constant,
       * make it default to BO_NATIVE.
       */
      if (field_info[i].order == BO_UNKNOWN
	  && has_tok_dollar (v->code, TOK_DOLLAR_NUMBER, i) != NULL)
	field_info[i].order = BO_NATIVE;

      /* It wasn't expanded, so create a bitfield for it. */
      if (field_info[i].order == BO_UNKNOWN
	  || field_info[i].size == BS_UNKNOWN)
	{
	  parse_error (v->code, "Error: Unable to determine best byte order "
		       "or size of operand field %d.  "
		       "(order == %d, size == %d)\n", i, field_info[i].order,
		       field_info[i].size);
	  print_list (stderr, v->code);
	  putc ('\n', stderr);
	}
      else
	{
	  b = &op->bitfield[op->num_bitfields++];
	  b->rev_amode = (has_tok_dollar (v->code, TOK_DOLLAR_REVERSED_AMODE,i)
			  != NULL);
	  b->index = range.index;
	  b->length = range.length - 1;
	  b->sign_extend = field_info[i].sgnd;
	  b->make_native_endian = (field_info[i].order == BO_NATIVE
				   || field_info[i].size == BS_BYTE);

#if 0
	  /* We prefer to translate 16 bit operands to the synthetic
	   * instruction stream as 16 bit operands.  However, if the operand
	   * is to be sign- or zero-extended to 32 bits, and it is not to be
	   * native endian, we extend it at translation time.  The logic
	   * behind this is that extending a 16 bit number is a free
	   * operation on the 386 (movesx/movezx) and a cheap operation on
	   * other CPU's, but this will only work for operands in native
	   * format.  Also, since 32 bit operands force operand alignment for
	   * QUADALIGN machines, using 16 bit operands can avoid alignment
	   * NOPs.
	   */
	  if (b->make_native_endian && range.length <= 16)
	    b->words = 1 - 1;  /* 1 word. */
	  else
	    b->words = ((field_info[i].size == BS_LONG) ? 2 : 1) - 1;
#else
	  /* We now prefer to use BS_LONG operands.  These are generally
	   * faster on RISC chips, and on the Pentium movswl, etc. are
	   * apparently not pairable.
	   */
	  if (b->make_native_endian)
	    field_info[i].size = BS_LONG;
	  b->words = ((field_info[i].size == BS_LONG) ? 2 : 1) - 1;
#endif

	  if (b->index == MAGIC_END_INDEX && b->length == MAGIC_END_LENGTH)
	    fatal_error ("Illegal bitfield index/length (%d/%d).  This "
			 "combination is used as a magic value and shouldn't "
			 "show up in real code!", MAGIC_END_INDEX,
			 MAGIC_END_LENGTH);
	}
    }

  if (op->num_bitfields > MAX_BITFIELDS)
    fatal_error ("Too many operand bitfields (%d) for OpcodeMappingInfo "
		 "struct.\n", op->num_bitfields);

#if defined (SORT_OPERANDS)
  /* Sort operands by size and then by field number. */
  {
#ifdef GENERATE_NATIVE_CODE
    BitfieldInfo *save;
    int size = op->num_bitfields * sizeof op->bitfield[0];
    save = (BitfieldInfo *) alloca (size);
    memcpy (save, op->bitfield, size);
#endif
    qsort (op->bitfield, op->num_bitfields, sizeof op->bitfield[0],
	   compare_bitfields);
#ifdef GENERATE_NATIVE_CODE
    if (v->native_code_info != NULL && memcmp (save, op->bitfield, size))
      parse_error (v->code, "byteorder.c insists on reordering your operands!"
		   "  This is incompatible with native code generation.");
#endif
  }
#endif /* defined (SORT_OPERANDS) */

  /* Create decls string. */
  decls[0] = '\0';
  for (i = 0; i < op->num_bitfields; i++)
    {
      int field = field_with_index (p->opcode_bits, op->bitfield[i].index);

      /* Output declaration. */
#if	1 || !defined(TEMPS_AT_TOP)
      sprintf (decls + strlen (decls), "        %sint%d operand_%d = ",
	       op->bitfield[i].sign_extend ? "" : "u",
	       field_info[field].size * 8, field);
#else	/* defined(TEMPS_AT_TOP) */
      sprintf (decls + strlen (decls), "        operand_%s%d_%d = ",
	       op->bitfield[i].sign_extend ? "" : "u",
	       field_info[field].size * 8, field);
#endif	/* defined(TEMPS_AT_TOP) */

      /* Fetch initial value. */
      if (op->bitfield[i].words == 1 - 1  /* One 16 bit word. */ )
	{
	  if (op->bitfield[i].sign_extend)
	    strcat (decls, "(int16) ");
	  sprintf (decls + strlen (decls), "code[%d];", words_in);
	  /* We leave a gap here.  We used to pack all the 16 bit
	   * operands together, but they have largely been abandoned
	   * in favor of 32 bit operands.  They only crop up occasionally
	   * when we're doing byte swapping of immediate constants.
	   * We leave a gap here so everything stays aligned.
	   */
	  words_in += 2;
	}
      else  /* Two 16 bit words. */
	{
	  strcat (decls, "*((");
	  if (!op->bitfield[i].sign_extend)
	    strcat (decls, "u");
	  if (words_in != 0)
	    sprintf (decls + strlen (decls), "int32 *) (code + %d));",
		     words_in);
	  else
	    sprintf (decls + strlen (decls), "int32 *) code);");
	  words_in += 2;
	}

      /* Add comment indicating swappedness. */
      if (op->bitfield[i].make_native_endian)
	strcat (decls, "   /* Native endian */\n");
      else
	strcat (decls, "   /* Big endian */\n");
    }

  op->operand_decls = unique_string (decls);
  return words_in;
}
Esempio n. 12
0
CGprofile
nvb_reader_impl::profile() const
{
    return (CGprofile) convert_endianness( (unsigned int) header_.profile, endianness() );
}
Esempio n. 13
0
void mrtd_bac_protected_apdu(const uint8_t *input, uint8_t *output, const int length, int *outputlength, const uint8_t *ksenc, const uint8_t *ksmac, const uint64_t ssc_long)
{
	int datalength;
	char has_le;
	uint8_t *do87 = NULL;
	uint8_t do8e[10];
	uint8_t padded_command[8];
	uint8_t *A;
	int padded_data_length;
	int do87_length;
	uint8_t *do97 = NULL;
	int do97_length;
	uint8_t le;

	if(length > 5){
		datalength = (int)input[4];
	}
	else{
		datalength = 0;
	}
	if(datalength != 0 ? length > (5+datalength) : length == 5){
		le = input[length-1];
		has_le = 1;
	}
	else{
		le = 0;
		has_le = 0;
	}

	//printf("datalength: %d\n",datalength);
	//printf("hasle: %d\n",has_le);
	int i;

	if(datalength != 0){
		uint8_t *padded_data;
		padded_data = malloc(((datalength+8)/8)*8);
		mrtd_crypto_padding(input+5,padded_data,datalength,&padded_data_length);
		do87 = malloc(padded_data_length+3);
		mrtd_crypto_encrypt_3des(padded_data,do87+3,padded_data_length,ksenc);
		do87[0] = 0x87;
		do87[1] = 0x09;
		do87[2] = 0x01;
		do87_length = padded_data_length+3;

		free(padded_data);
	}
	else{
		do87_length = 0;
		padded_data_length = 0;
	}

	if(has_le){
		do97_length = 3;
		do97 = malloc(do97_length);
		do97[0] = 0x97;
		do97[1] = 0x01;
		do97[2] = le;
	}
	else{
		do97_length = 0;
	}

	int padded_command_length;
	mrtd_crypto_padding(input,padded_command,4,&padded_command_length);
	padded_command[0] = 0x0c;


	A = malloc(16+do87_length+do97_length);
	if(endianness()){
		A[0] = *(((uint8_t*)(&ssc_long))+0);
		A[1] = *(((uint8_t*)(&ssc_long))+1);
		A[2] = *(((uint8_t*)(&ssc_long))+2);
		A[3] = *(((uint8_t*)(&ssc_long))+3);
		A[4] = *(((uint8_t*)(&ssc_long))+4);
		A[5] = *(((uint8_t*)(&ssc_long))+5);
		A[6] = *(((uint8_t*)(&ssc_long))+6);
		A[7] = *(((uint8_t*)(&ssc_long))+7);
	}
	else {
		A[0] = *(((uint8_t*)(&ssc_long))+7);
		A[1] = *(((uint8_t*)(&ssc_long))+6);
		A[2] = *(((uint8_t*)(&ssc_long))+5);
		A[3] = *(((uint8_t*)(&ssc_long))+4);
		A[4] = *(((uint8_t*)(&ssc_long))+3);
		A[5] = *(((uint8_t*)(&ssc_long))+2);
		A[6] = *(((uint8_t*)(&ssc_long))+1);
		A[7] = *(((uint8_t*)(&ssc_long))+0);
	}
	memcpy(A+8,padded_command,8);
	if(do87 != NULL)
		memcpy(A+16,do87,do87_length);
	if(do97 != NULL)
		memcpy(A+16+do87_length,do97,do97_length);


	do8e[0] = 0x8e;
	do8e[1] = 0x08;

	mrtd_crypto_mac_padding(A,do8e+2,16+do87_length+do97_length,ksmac);

	(*outputlength) = 5+do87_length+do97_length+10+1;
	memcpy(output,padded_command,4);
	output[4] = (*outputlength)-6;
	if(do87 != NULL)
		memcpy(output+5,do87,do87_length);
	if(do97 != NULL)
		memcpy(output+5+do87_length,do97,do97_length);
	memcpy(output+5+do87_length+do97_length,do8e,10);
	output[(*outputlength)-1] = 0x00;

	//printf("tot_length: %d\n",*outputlength);

	free(A);
	if(do87 != NULL)
		free(do87);
	if(do97 != NULL)
		free(do97);

	return ;
}
Esempio n. 14
0
CGBIO_ERROR
nvb_reader_impl::get_param( unsigned int index,
			    	 CGtype& type,
			     CGresource& resource,
				 CGenum& variability,
				    int& resource_index,
				 const char ** name,
		     STL_NAMESPACE vector<float>& default_value,
	      STL_NAMESPACE vector<unsigned int>& embedded_constants,
				 const char ** semantic,
				    int& paramno,
				   bool& is_referenced,
				   bool& is_shared ) const
{
    if ( index >= number_of_params() )
	return CGBIO_ERROR_INDEX;

    if ( 0 == image_ )
	return CGBIO_ERROR_NO_ERROR;

    const CgBinaryParameter* params = reinterpret_cast<CgBinaryParameter*>( &image_[convert_endianness( header_.parameterArray, endianness_ )] );
    const CgBinaryParameter& pp = params[index];
    type		= static_cast<CGtype>(convert_endianness( static_cast<unsigned int>( pp.type ),	endianness() ) );
    resource		= static_cast<CGresource>(convert_endianness( static_cast<unsigned int>( pp.res ), endianness() ) );
    variability		= static_cast<CGenum>(convert_endianness( static_cast<unsigned int>( pp.var ),endianness() ) );
    resource_index	= convert_endianness( pp.resIndex,endianness() );
    paramno		= convert_endianness( pp.paramno, endianness() );
    is_referenced	= convert_endianness( pp.isReferenced,endianness() ) != 0;
    is_shared		= convert_endianness( pp.isShared,endianness() ) != 0;
    CgBinaryStringOffset		nm_offset =	convert_endianness( pp.name,endianness() );
    CgBinaryFloatOffset			dv_offset =	convert_endianness( pp.defaultValue,endianness() );
    CgBinaryEmbeddedConstantOffset	ec_offset =	convert_endianness( pp.embeddedConst,endianness() );
    CgBinaryStringOffset		sm_offset =	convert_endianness( pp.semantic,endianness() );
    if ( 0 != nm_offset )
    {
		*name = &image_[nm_offset];
    }
	else
		*name = "";

    if ( 0 != sm_offset )
    {
		*semantic = &image_[sm_offset];
    }
	else
		*semantic = "";
    if ( 0 != dv_offset )
    {
	char *vp = &image_[dv_offset];
	for (int ii = 0; ii < 4; ++ii)
	{
		int tmp;
		memcpy(&tmp,vp+4*ii,4);
		tmp = convert_endianness(tmp,endianness());
		float tmp2;
		memcpy(&tmp2,&tmp,4);
		default_value.push_back( tmp2 );
	}
    }
    if ( 0 != ec_offset )
    {
	void *vp = &image_[ec_offset];
	CgBinaryEmbeddedConstant& ec = *(static_cast<CgBinaryEmbeddedConstant*>( vp ));
	for (unsigned int ii = 0; ii < convert_endianness( ec.ucodeCount, endianness() ); ++ii)
	{
	    unsigned int offset = convert_endianness( ec.ucodeOffset[ii], endianness() );
	    embedded_constants.push_back( offset );
	}
    }
    return CGBIO_ERROR_NO_ERROR;
}
Esempio n. 15
0
unsigned int
nvb_reader_impl::revision() const
{
    return convert_endianness( header_.binaryFormatRevision, endianness() );
}
Esempio n. 16
0
unsigned int nvb_reader_impl::size() const
{
    return convert_endianness( header_.totalSize, endianness() );
}
Esempio n. 17
0
int main(int argc, char** argv) {
	printf("The endianness of this machine is: %d\n", endianness());
	printf("The endianness(cast) of this machine is: %d\n",
			endianness_with_cast());
	return 0;
}
Esempio n. 18
0
unsigned int nvb_reader_impl::number_of_params() const
{
    return convert_endianness( header_.parameterCount, endianness() );
}