Exemple #1
0
void MetadataSectionHeader::Load(u8* in)
{
	memcpy(&data_offset, in, 8);
	memcpy(&data_size, in + 8, 8);
	memcpy(&type, in + 16, 4);
	memcpy(&program_idx, in + 20, 4);
	memcpy(&hashed, in + 24, 4);
	memcpy(&sha1_idx, in + 28, 4);
	memcpy(&encrypted, in + 32, 4);
	memcpy(&key_idx, in + 36, 4);
	memcpy(&iv_idx, in + 40, 4);
	memcpy(&compressed, in + 44, 4);

	// Endian swap.
	data_offset = swap64(data_offset);
	data_size = swap64(data_size);
	type = swap32(type);
	program_idx = swap32(program_idx);
	hashed = swap32(hashed);
	sha1_idx = swap32(sha1_idx);
	encrypted = swap32(encrypted);
	key_idx = swap32(key_idx);
	iv_idx = swap32(iv_idx);
	compressed = swap32(compressed);
}
Exemple #2
0
void test_macros()
{
    assert(swap16(0) == 0);
    assert(swap16(0x0102) == 0x0201);
    assert(swap32(0) == 0);
    assert(swap32(0x01020304) == 0x04030201);
    assert(swap64(0) == 0);
    assert(swap64(0x0102030405060708ULL) == 0x0807060504030201ULL);
}
Exemple #3
0
void adjust_v2_header_byteorder(cencrypted_v2_pwheader *pwhdr) {
  swap32(pwhdr->blocksize);
  swap64(pwhdr->datasize);
  swap64(pwhdr->dataoffset);
  pwhdr->kdf_algorithm = htonl(pwhdr->kdf_algorithm);
  pwhdr->kdf_prng_algorithm = htonl(pwhdr->kdf_prng_algorithm);
  pwhdr->kdf_iteration_count = htonl(pwhdr->kdf_iteration_count);
  pwhdr->kdf_salt_len = htonl(pwhdr->kdf_salt_len);
  pwhdr->blob_enc_iv_size = htonl(pwhdr->blob_enc_iv_size);
  pwhdr->blob_enc_key_bits = htonl(pwhdr->blob_enc_key_bits);
  pwhdr->blob_enc_algorithm = htonl(pwhdr->blob_enc_algorithm);
  pwhdr->blob_enc_padding = htonl(pwhdr->blob_enc_padding);
  pwhdr->blob_enc_mode = htonl(pwhdr->blob_enc_mode);
  pwhdr->encrypted_keyblob_size = htonl(pwhdr->encrypted_keyblob_size);
}
Exemple #4
0
FXbool InputPlugin::read_int64_be(FXlong & value) {
  if (read(&value,8)==8) {
    value = swap64(value);
    return true;
    }
  return false;
  }
Exemple #5
0
void
bchanset(                   /* output binary channel n */
int  n,
double  v
)
{
	static char	zerobuf[sizeof(double)];
	float	fval = v;

	while (++colpos < n)
		fwrite(zerobuf,
			tolower(otype)=='d' ? sizeof(double) : sizeof(float),
			1, stdout);
	switch (otype) {
	case 'D':
		swap64((char *)&v, 1);
		/* fall through */
	case 'd':
		fwrite(&v, sizeof(double), 1, stdout);
		break;
	case 'F':
		swap32((char *)&fval, 1);
		/* fall through */
	case 'f':
		fwrite(&fval, sizeof(float), 1, stdout);
		break;
	}
}
void PortableFile::write64(uint64 value)
{
    if (system_big_endian != big_endian_) {
        value = swap64(value);
    }
    f_.write((const char *)&value, 8);
}
Exemple #7
0
// EDAT/SDAT functions.
std::tuple<u64, s32, s32> dec_section(unsigned char* metadata)
{
	std::array<u8, 0x10> dec;
	dec[0x00] = (metadata[0xC] ^ metadata[0x8] ^ metadata[0x10]);
	dec[0x01] = (metadata[0xD] ^ metadata[0x9] ^ metadata[0x11]);
	dec[0x02] = (metadata[0xE] ^ metadata[0xA] ^ metadata[0x12]);
	dec[0x03] = (metadata[0xF] ^ metadata[0xB] ^ metadata[0x13]);
	dec[0x04] = (metadata[0x4] ^ metadata[0x8] ^ metadata[0x14]);
	dec[0x05] = (metadata[0x5] ^ metadata[0x9] ^ metadata[0x15]);
	dec[0x06] = (metadata[0x6] ^ metadata[0xA] ^ metadata[0x16]);
	dec[0x07] = (metadata[0x7] ^ metadata[0xB] ^ metadata[0x17]);
	dec[0x08] = (metadata[0xC] ^ metadata[0x0] ^ metadata[0x18]);
	dec[0x09] = (metadata[0xD] ^ metadata[0x1] ^ metadata[0x19]);
	dec[0x0A] = (metadata[0xE] ^ metadata[0x2] ^ metadata[0x1A]);
	dec[0x0B] = (metadata[0xF] ^ metadata[0x3] ^ metadata[0x1B]);
	dec[0x0C] = (metadata[0x4] ^ metadata[0x0] ^ metadata[0x1C]);
	dec[0x0D] = (metadata[0x5] ^ metadata[0x1] ^ metadata[0x1D]);
	dec[0x0E] = (metadata[0x6] ^ metadata[0x2] ^ metadata[0x1E]);
	dec[0x0F] = (metadata[0x7] ^ metadata[0x3] ^ metadata[0x1F]);

	u64 offset = swap64(*(u64*)&dec[0]);
	s32 length = swap32(*(s32*)&dec[8]);
	s32 compression_end = swap32(*(s32*)&dec[12]);

	return std::make_tuple(offset, length, compression_end);
}
Exemple #8
0
void WvOut :: writeData( unsigned long frames )
{
  if ( dataType == STK_SINT8 ) {
    if ( fileType == WVOUT_WAV ) { // 8-bit WAV data is unsigned!
      unsigned char sample;
      for ( unsigned long k=0; k<frames*channels; k++ ) {
        sample = (unsigned char) (data[k] * 127.0 + 128.0);
        if ( fwrite(&sample, 1, 1, fd) != 1 ) goto error;
      }
    }
    else {
      signed char sample;
      for ( unsigned long k=0; k<frames*channels; k++ ) {
        sample = (signed char) (data[k] * 127.0);
        //sample = ((signed char) (( data[k] + 1.0 ) * 127.5 + 0.5)) - 128;
        if ( fwrite(&sample, 1, 1, fd) != 1 ) goto error;
      }
    }
  }
  else if ( dataType == STK_SINT16 ) {
    SINT16 sample;
    for ( unsigned long k=0; k<frames*channels; k++ ) {
      sample = (SINT16) (data[k] * 32767.0);
      //sample = ((SINT16) (( data[k] + 1.0 ) * 32767.5 + 0.5)) - 32768;
      if ( byteswap ) swap16( (unsigned char *)&sample );
      if ( fwrite(&sample, 2, 1, fd) != 1 ) goto error;
    }
  }
  else if ( dataType == STK_SINT32 ) {
    SINT32 sample;
    for ( unsigned long k=0; k<frames*channels; k++ ) {
      sample = (SINT32) (data[k] * 2147483647.0);
      //sample = ((SINT32) (( data[k] + 1.0 ) * 2147483647.5 + 0.5)) - 2147483648;
      if ( byteswap ) swap32( (unsigned char *)&sample );
      if ( fwrite(&sample, 4, 1, fd) != 1 ) goto error;
    }
  }
  else if ( dataType == MY_FLOAT32 ) {
    FLOAT32 sample;
    for ( unsigned long k=0; k<frames*channels; k++ ) {
      sample = (FLOAT32) (data[k]);
      if ( byteswap ) swap32( (unsigned char *)&sample );
      if ( fwrite(&sample, 4, 1, fd) != 1 ) goto error;
    }
  }
  else if ( dataType == MY_FLOAT64 ) {
    FLOAT64 sample;
    for ( unsigned long k=0; k<frames*channels; k++ ) {
      sample = (FLOAT64) (data[k]);
      if ( byteswap ) swap64( (unsigned char *)&sample );
      if ( fwrite(&sample, 8, 1, fd) != 1 ) goto error;
    }
  }
  return;

 error:
  sprintf(msg, "WvOut: Error writing data to file.");
  handleError(msg, StkError::FILE_ERROR);
}
Exemple #9
0
int svc_editSymbol(char* symbol, Svc_Elf_Info_T* elfInfo ) {
  
  char* name = symbol;
  char* type;
  char* value;

  /*
   * p contains a string of the format "name=value".  Find the "=" sign
   * to split into name and value:
   */

  while ( (*symbol) != 0  && (*symbol != '=') ) {
    symbol++;
  }

  *symbol++ = 0;
  type = symbol;

  /*
   * The value is of the form type:val
   */

  while ( (*symbol) != 0  && (*symbol != ':') ) {
    symbol++;
  }

  *symbol++ = 0;
  value = symbol;

  unsigned long vaddr = 0, size = 0, fpos = 0;

  int rc = svc_getElfSymbolByName( elfInfo, name, &vaddr, &size, &fpos );

  if (verbose) {
    printf("(I) Editing symbol \"%s\" of type %s value=%s address(0x%lX,0x%lX)\n", name, type, value, vaddr, fpos);
  }

  if ( rc == 0 ) {
    
    if (strcmp(type, "i32") == 0 ) {
      uint32_t  v = strtoul( value, 0, 0 );
      uint32_t* ptr = (uint32_t*)(elfInfo->mappedAddress + fpos);
      *ptr = swap32(v);
    }
    else if (strcmp(type, "i64") == 0 ) {
      uint64_t  v = strtoull( value, 0, 0 );
      uint64_t* ptr = (uint64_t*)(elfInfo->mappedAddress + fpos);
      *ptr = swap64(v);
    }
    else {
      fprintf(stderr, "(E) unknown symbol type \"%s\" (must be one of {i32, i64, s}\n", type);
      rc = -1;
    }
  }


  return rc;

}
Exemple #10
0
uint64_t
dwarf_fix64(struct dwarf_nebula *dn, uint64_t a64)
{
	if (dn->elfdata == ELF_TARG_DATA)
		return a64;

	return swap64(a64);
}
Exemple #11
0
static void endianadjust_ehdr64(Elf64_Ehdr *eh)
{
    if ( !big_endian )
        return;
    eh->e_type      = swap16(eh->e_type);
    eh->e_machine   = swap16(eh->e_machine);
    eh->e_version   = swap32(eh->e_version);
    eh->e_entry     = swap64(eh->e_entry);
    eh->e_phoff     = swap64(eh->e_phoff);
    eh->e_shoff     = swap64(eh->e_shoff);
    eh->e_flags     = swap32(eh->e_flags);
    eh->e_ehsize    = swap16(eh->e_ehsize);
    eh->e_phentsize = swap16(eh->e_phentsize);
    eh->e_phnum     = swap16(eh->e_phnum);
    eh->e_shentsize = swap16(eh->e_shentsize);
    eh->e_shnum     = swap16(eh->e_shnum);
    eh->e_shstrndx  = swap16(eh->e_shstrndx);
}
uint64 PortableFile::read64()
{
    uint64 value = 0;
    f_.read((char *)&value, 8);
    if (system_big_endian != big_endian_) {
        value = swap64(value);
    }
    return value;
}
Exemple #13
0
void elf_read_elf_header(const void *elf_data,ELF *elf_hdr)
{
	memcpy(elf_hdr,elf_data,sizeof(ELF));

	elf_hdr->type = swap16 (elf_hdr->type);
	elf_hdr->machine = swap16 (elf_hdr->machine);
	elf_hdr->version = swap32 (elf_hdr->version);
	elf_hdr->entry_point = swap64 (elf_hdr->entry_point);
	elf_hdr->phdr_offset = swap64 (elf_hdr->phdr_offset);
	elf_hdr->shdr_offset = swap64 (elf_hdr->shdr_offset);
	elf_hdr->flags = swap16 (elf_hdr->flags);
	elf_hdr->header_size = swap32 (elf_hdr->header_size);
	elf_hdr->phent_size = swap16 (elf_hdr->phent_size);
	elf_hdr->phnum = swap16 (elf_hdr->phnum);
	elf_hdr->shent_size = swap16 (elf_hdr->shent_size);
	elf_hdr->shnum = swap16 (elf_hdr->shnum);
	elf_hdr->shstrndx = swap16 (elf_hdr->shstrndx);
}
Exemple #14
0
int64_t fibTwoSwap(int n) {
  if (n == 1 || n == 2) {return 1;}
  int64_t fibLower = 1;
  int64_t fibHigher = 1;
  for (int i=2; i<n; i++) {
    swap64(fibLower, fibHigher);
    fibHigher = fibHigher + fibLower;
  }
  return fibHigher;
}
Exemple #15
0
void elf_write_elf_header(void *elf_data,ELF *elf_hdr)
{
	ELF *out = (ELF*)elf_data;

	memcpy(out->ident,elf_hdr->ident,sizeof(elf_hdr->ident));
	out->type = swap16(elf_hdr->type);
	out->machine = swap16(elf_hdr->machine);
	out->version = swap32(elf_hdr->version);
	out->entry_point = swap64(elf_hdr->entry_point);
	out->phdr_offset = swap64(elf_hdr->phdr_offset);
	out->shdr_offset = swap64(elf_hdr->shdr_offset);
	out->flags = swap16(elf_hdr->flags);
	out->header_size = swap32(elf_hdr->header_size);
	out->phent_size = swap16(elf_hdr->phent_size);
	out->phnum = swap16(elf_hdr->phnum);
	out->shent_size = swap16(elf_hdr->shent_size);
	out->shnum = swap16(elf_hdr->shnum);
	out->shstrndx = swap16(elf_hdr->shstrndx);
}
Exemple #16
0
bool CheckDebugSelf(const std::string& self, const std::string& elf)
{
	// Open the SELF file.
	fs::file s(self);

	if (!s)
	{
		LOG_ERROR(LOADER, "Could not open SELF file! (%s)", self.c_str());
		return false;
	}

	// Get the key version.
	CHECK_ASSERTION(s.seek(0x08) != -1);

	u16 key_version;
	s.read(&key_version, sizeof(key_version));

	// Check for DEBUG version.
	if (swap16(key_version) == 0x8000)
	{
		LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header...");

		// Get the real elf offset.
		CHECK_ASSERTION(s.seek(0x10) != -1);

		u64 elf_offset;
		s.read(&elf_offset, sizeof(elf_offset));

		// Start at the real elf offset.
		elf_offset = swap64(elf_offset);

		CHECK_ASSERTION(s.seek(elf_offset) != -1);

		// Write the real ELF file back.
		fs::file e(elf, fom::rewrite);
		if (!e)
		{
			LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str());
			return false;
		}

		// Copy the data.
		char buf[2048];
		while (ssize_t size = s.read(buf, 2048))
		{
			e.write(buf, size);
		}

		return true;
	}

	// Leave the file untouched.
	return false;
}
Exemple #17
0
void
imc_eisa_write_raw_8(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o,
    const uint8_t *buf, bus_size_t len)
{
	volatile uint64_t *addr = (volatile uint64_t *)(h + o);
	len >>= 3;
	while (len-- != 0) {
		*addr = swap64(*(uint64_t *)buf);
		buf += 8;
	}
}
Exemple #18
0
static void read_dyninfo(size_t offset, size_t size, dyninfo_t *dyninfo)
{
  if ( size == 0 )
    return;

  qlseek(li, offset);
  const int entsize = elf64 ? sizeof(Elf64_Dyn) : sizeof(Elf32_Dyn);
  for ( int i=0; i < size; i+=entsize )
  {
    Elf64_Dyn d;
    if ( elf64 )
    {
      if ( qlread(li, &d, sizeof(d)) != sizeof(d) )
        errstruct();
      if ( mf )
      {
        d.d_tag = swap64(d.d_tag);
        d.d_un  = swap64(d.d_un);
      }
    }
    else
    {
      Elf32_Dyn d32;
      if ( qlread(li, &d32, sizeof(d32)) != sizeof(d32) )
        errstruct();
      if ( mf )
      {
        d.d_tag = swap32(d32.d_tag);
        d.d_un  = swap32(d32.d_un.d_val);
      }
      else
      {
        d.d_tag = d32.d_tag;
        d.d_un  = d32.d_un.d_val;
      }
    }
    dyninfo->push_back(d);
    if ( d.d_tag == DT_NULL )
      break;
  }
}
Exemple #19
0
bool CheckDebugSelf(const std::string& self, const std::string& elf)
{
	// Open the SELF file.
	wxFile s(fmt::FromUTF8(self));

	if(!s.IsOpened())
	{
		ConLog.Error("Could not open SELF file! (%s)", self.c_str());
		return false;
	}

	// Get the key version.
	s.Seek(0x08);
	u16 key_version;
	s.Read(&key_version, sizeof(key_version));

	// Check for DEBUG version.
	if(swap16(key_version) == 0x8000)
	{
		ConLog.Warning("Debug SELF detected! Removing fake header...");

		// Get the real elf offset.
		s.Seek(0x10);
		u64 elf_offset;
		s.Read(&elf_offset, sizeof(elf_offset));

		// Start at the real elf offset.
		elf_offset = swap64(elf_offset);
		s.Seek(elf_offset);

		// Write the real ELF file back.
		wxFile e(fmt::FromUTF8(elf), wxFile::write);
		if(!e.IsOpened())
		{
			ConLog.Error("Could not create ELF file! (%s)", elf.c_str());
			return false;
		}

		// Copy the data.
		char buf[2048];
		while (ssize_t size = s.Read(buf, 2048))
			e.Write(buf, size);

		e.Close();
		return true;
	}
	else
	{
		// Leave the file untouched.
		s.Seek(0);
		return false;
	}
}
Exemple #20
0
uint8_t DataUnpack::getS64(int64_t *val)
{
    if (*inBuf != 0xd3)
        return 1;
    if (inBufLen < 9)
        return 1;
    inBuf++;
    *val = swap64(*((uint64_t*)inBuf));
    inBufLen -= 9;
    inBuf += 8;
    return 0;
}
Exemple #21
0
void read_npd_edat_header(const fs::file* input, NPD_HEADER& NPD, EDAT_HEADER& EDAT)
{
	char npd_header[0x80];
	char edat_header[0x10];
	input->read(npd_header, sizeof(npd_header));
	input->read(edat_header, sizeof(edat_header));

	memcpy(&NPD.magic, npd_header, 4);
	NPD.version = swap32(*(int*)&npd_header[4]);
	NPD.license = swap32(*(int*)&npd_header[8]);
	NPD.type = swap32(*(int*)&npd_header[12]);
	memcpy(NPD.content_id, (unsigned char*)&npd_header[16], 0x30);
	memcpy(NPD.digest, (unsigned char*)&npd_header[64], 0x10);
	memcpy(NPD.title_hash, (unsigned char*)&npd_header[80], 0x10);
	memcpy(NPD.dev_hash, (unsigned char*)&npd_header[96], 0x10);
	NPD.unk1 = swap64(*(u64*)&npd_header[112]);
	NPD.unk2 = swap64(*(u64*)&npd_header[120]);

	EDAT.flags = swap32(*(int*)&edat_header[0]);
	EDAT.block_size = swap32(*(int*)&edat_header[4]);
	EDAT.file_size = swap64(*(u64*)&edat_header[8]);
}
Exemple #22
0
static void
swap_header(struct s_spcl *s)
{
	s->c_type = swap32(s->c_type);
	s->c_old_date = swap32(s->c_old_date);
	s->c_old_ddate = swap32(s->c_old_ddate);
	s->c_volume = swap32(s->c_volume);
	s->c_old_tapea = swap32(s->c_old_tapea);
	s->c_inumber = swap32(s->c_inumber);
	s->c_magic = swap32(s->c_magic);
	s->c_checksum = swap32(s->c_checksum);

	s->c_mode = swap16(s->c_mode);
	s->c_size = swap64(s->c_size);
	s->c_old_atime = swap32(s->c_old_atime);
	s->c_atimensec = swap32(s->c_atimensec);
	s->c_old_mtime = swap32(s->c_old_mtime);
	s->c_mtimensec = swap32(s->c_mtimensec);
	s->c_rdev = swap32(s->c_rdev);
	s->c_birthtimensec = swap32(s->c_birthtimensec);
	s->c_birthtime = swap64(s->c_birthtime);
	s->c_atime = swap64(s->c_atime);
	s->c_mtime = swap64(s->c_mtime);
	s->c_file_flags = swap32(s->c_file_flags);
	s->c_uid = swap32(s->c_uid);
	s->c_gid = swap32(s->c_gid);

	s->c_count = swap32(s->c_count);
	s->c_level = swap32(s->c_level);
	s->c_flags = swap32(s->c_flags);
	s->c_old_firstrec = swap32(s->c_old_firstrec);

	s->c_date = swap64(s->c_date);
	s->c_ddate = swap64(s->c_ddate);
	s->c_tapea = swap64(s->c_tapea);
	s->c_firstrec = swap64(s->c_firstrec);

	/*
	 * These are ouid and ogid.
	 */
	s->c_spare1[1] = swap16(s->c_spare1[1]);
	s->c_spare1[2] = swap16(s->c_spare1[2]);
}
Exemple #23
0
static void endianadjust_phdr64(Elf64_Phdr *ph)
{
    if ( !big_endian )
        return;
    ph->p_type      = swap32(ph->p_type);
    ph->p_flags     = swap32(ph->p_flags);
    ph->p_offset    = swap64(ph->p_offset);
    ph->p_vaddr     = swap64(ph->p_vaddr);
    ph->p_paddr     = swap64(ph->p_paddr);
    ph->p_filesz    = swap64(ph->p_filesz);
    ph->p_memsz     = swap64(ph->p_memsz);
    ph->p_align     = swap64(ph->p_align);
}
Exemple #24
0
static void att_signed_write_handle_cmac_result(uint8_t hash[8]){
    
    if (att_server_state != ATT_SERVER_W4_SIGNED_WRITE_VALIDATION) return;

    uint8_t hash_flipped[8];
    swap64(hash, hash_flipped);
    if (memcmp(hash_flipped, &att_request_buffer[att_request_size-8], 8)){
        log_info("ATT Signed Write, invalid signature");
        att_server_state = ATT_SERVER_IDLE;
        return;
    }
    log_info("ATT Signed Write, valid signature");

    // update sequence number
    uint32_t counter_packet = READ_BT_32(att_request_buffer, att_request_size-12);
    le_device_db_remote_counter_set(att_ir_le_device_db_index, counter_packet+1);
    att_server_state = ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED;
    att_run();
}
Exemple #25
0
void MetadataHeader::Load(u8* in)
{
	memcpy(&signature_input_length, in, 8);
	memcpy(&unknown1, in + 8, 4);
	memcpy(&section_count, in + 12, 4);
	memcpy(&key_count, in + 16, 4);
	memcpy(&opt_header_size, in + 20, 4);
	memcpy(&unknown2, in + 24, 4);
	memcpy(&unknown3, in + 28, 4);

	// Endian swap.
	signature_input_length = swap64(signature_input_length);
	unknown1 = swap32(unknown1);
	section_count = swap32(section_count);
	key_count = swap32(key_count);
	opt_header_size = swap32(opt_header_size);
	unknown2 = swap32(unknown2);
	unknown3 = swap32(unknown3);
}
Exemple #26
0
static void sha1_final(sha1_context_t *ctx, void *out)
{
	const uint8_t pad[64] = { 0x80, };
	uint64_t msglen = swap64(ctx->len << 3);
	uint32_t *data = out;
	int len, i;

	/* check how much padding is required */
	len = 56 - (ctx->len & 63);
	/* enough space in current chunk? */
	if (len < 1)
		len += 64;

	sha1_update(ctx, pad, len);

	sha1_update(ctx, &msglen, 8);

	for (i = 0; i < 5; i++)
		data[i] = swap32(ctx->h[i]);
}
Exemple #27
0
void elf_write_phdr_header(void *elf_data,ELF *elf_hdr,ELF_PHDR *phdr)
{
	uint16_t i;
	ELF_PHDR *elf_phdr = (ELF_PHDR*)elf_data;

	for(i=0;i<elf_hdr->phnum;i++) {
		elf_phdr[i].type = swap32(phdr[i].type);
		elf_phdr[i].flags = swap32(phdr[i].flags);
		elf_phdr[i].offset_in_file = swap64(phdr[i].offset_in_file);
		elf_phdr[i].vitual_addr = swap64(phdr[i].vitual_addr);
		elf_phdr[i].phys_addr = swap64(phdr[i].phys_addr);
		elf_phdr[i].segment_size = swap64(phdr[i].segment_size);
		elf_phdr[i].segment_mem_size = swap64(phdr[i].segment_mem_size);
		elf_phdr[i].alignment = swap64(phdr[i].alignment);
	}
}
	Encoding *RegisterAllocator::movq(OperandMMREG r64i, OperandMMREG r64j)
	{
		if(r64i == r64j) return 0;

		// Register overwritten, when not used, eliminate load instruction
		if(MMX[r64i.reg].loadInstruction && loadElimination)
		{
			MMX[r64i.reg].loadInstruction->reserve();
			MMX[r64i.reg].loadInstruction = 0;
		}

		// Register overwritten, when not used, eliminate copy instruction
		if(MMX[r64i.reg].copyInstruction && copyPropagation)
		{
			MMX[r64i.reg].copyInstruction->reserve();
			MMX[r64i.reg].copyInstruction = 0;
		}

		Encoding *spillInstruction = MMX[r64i.reg].spillInstruction;
		AllocationData spillAllocation = MMX[r64i.reg].spill;

		Encoding *movq = Assembler::movq(r64i, r64j);
		
		if(MMX[r64i.reg].reference == 0 || MMX[r64j.reg].reference == 0)   // Return if not in allocation table
		{
			return movq;
		}

		// Attempt copy propagation
		if(movq && copyPropagation)
		{
			swap64(r64i.reg, r64j.reg);
			MMX[r64i.reg].copyInstruction = movq;
		}

		MMX[r64i.reg].spillInstruction = spillInstruction;
		MMX[r64i.reg].spill = spillAllocation;
		
		return movq;
	}
Exemple #29
0
Fichier : swap.c Projet : kuro/gas
/**
 * @brief Unconditional array swapping routine.
 *
 * @param buf array buffer to swap bytes
 * @param stride byte stride, 2 or 4 (short and long, respectively)
 * @param bufsize the total data length of the buffer
 *
 * @retval 0 success, otherwise failure
 */
GASresult gas_swap (GASvoid *buf, GASunum stride, GASunum bufsize)
{
    GASunum count = bufsize / stride;
    GASunum i;

    if ((bufsize % stride) != 0) {
        return GAS_ERR_INVALID_PARAM;
    }

    switch (stride) {
    case 2: {
        uint16_t *buf16 = (uint16_t*)buf;
        for (i = 0; i < count; i++) {
            buf16[i] = swap16(buf16[i]);
        }
        break;
    }
    case 4: {
        uint32_t *buf32 = (uint32_t*)buf;
        for (i = 0; i < count; i++) {
            buf32[i] = swap32(buf32[i]);
        }
        break;
    }
#if GAS_SIZEOF_VOID_P >= 8
    case 8: {
        uint64_t *buf64 = (uint64_t*)buf;
        for (i = 0; i < count; i++) {
            buf64[i] = swap64(buf64[i]);
        }
        break;
    }
#endif
    default:
        return GAS_ERR_INVALID_PARAM;
    }
    return GAS_OK;
}
Exemple #30
0
static int
getinputrec(		/* get next input record */
FILE  *fp
)
{
	if (inpfmt != NULL)
		return(getrec());
	if (tolower(itype) == 'd') {
		if (fread(inpbuf, sizeof(double), nbicols, fp) != nbicols)
			return(0);
		if (itype == 'D')
			swap64(inpbuf, nbicols);
		return(1);
	}
	if (tolower(itype) == 'f') {
		if (fread(inpbuf, sizeof(float), nbicols, fp) != nbicols)
			return(0);
		if (itype == 'F')
			swap32(inpbuf, nbicols);
		return(1);
	}
	return(fgets(inpbuf, INBSIZ, fp) != NULL);
}