/* * Depending on the size of the type being described, either a ctf_stype_t (for * types with size < CTF_LSTRUCT_THRESH) or a ctf_type_t (all others) will be * written. We isolate the determination here so the rest of the writer code * doesn't need to care. */ static void write_sized_type_rec(ctf_buf_t *b, ctf_type_t *ctt, size_t size) { if (size > CTF_MAX_SIZE) { ctt->ctt_size = CTF_LSIZE_SENT; ctt->ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size); ctt->ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size); if (target_requires_swap) { SWAP_32(ctt->ctt_name); SWAP_16(ctt->ctt_info); SWAP_16(ctt->ctt_size); SWAP_32(ctt->ctt_lsizehi); SWAP_32(ctt->ctt_lsizelo); } ctf_buf_write(b, ctt, sizeof (*ctt)); } else { ctf_stype_t *cts = (ctf_stype_t *)ctt; cts->ctt_size = (ushort_t)size; if (target_requires_swap) { SWAP_32(cts->ctt_name); SWAP_16(cts->ctt_info); SWAP_16(cts->ctt_size); } ctf_buf_write(b, cts, sizeof (*cts)); } }
static void testSwap_16(void) { volatile unsigned long t=TEST_VECT_32; unsigned long tt; LONG x; tt = t; tt = SWAP_16(tt); ASSERT( tt == SWAP_16(TEST_VECT_32)); /* swapping union with little register pressure */ { unsigned char c; x.l = t; c = x.c[0]; x.c[0]=x.c[2]; x.c[2]=c; c = x.c[1]; x.c[1]=x.c[3]; x.c[3]=c; ASSERT( x.l == SWAP_16(TEST_VECT_32)); } }
SampleFormat PcmDecoder::setHeader(msg::CodecHeader* chunk) { if (chunk->payloadSize < 44) throw SnapException("PCM header too small"); struct riff_wave_header riff_wave_header; struct chunk_header chunk_header; struct chunk_fmt chunk_fmt; chunk_fmt.sample_rate = SWAP_32(0); chunk_fmt.bits_per_sample = SWAP_16(0); chunk_fmt.num_channels = SWAP_16(0); size_t pos(0); memcpy(&riff_wave_header, chunk->payload + pos, sizeof(riff_wave_header)); pos += sizeof(riff_wave_header); if ((SWAP_32(riff_wave_header.riff_id) != ID_RIFF) || (SWAP_32(riff_wave_header.wave_id) != ID_WAVE)) throw SnapException("Not a riff/wave header"); bool moreChunks(true); do { if (pos + sizeof(chunk_header) > chunk->payloadSize) throw SnapException("riff/wave header incomplete"); memcpy(&chunk_header, chunk->payload + pos, sizeof(chunk_header)); pos += sizeof(chunk_header); switch (SWAP_32(chunk_header.id)) { case ID_FMT: if (pos + sizeof(chunk_fmt) > chunk->payloadSize) throw SnapException("riff/wave header incomplete"); memcpy(&chunk_fmt, chunk->payload + pos, sizeof(chunk_fmt)); pos += sizeof(chunk_fmt); /// If the format header is larger, skip the rest if (SWAP_32(chunk_header.sz) > sizeof(chunk_fmt)) pos += (SWAP_32(chunk_header.sz) - sizeof(chunk_fmt)); break; case ID_DATA: /// Stop looking for chunks moreChunks = false; break; default: /// Unknown chunk, skip bytes pos += SWAP_32(chunk_header.sz); } } while (moreChunks); if (SWAP_32(chunk_fmt.sample_rate) == 0) throw SnapException("Sample format not found"); SampleFormat sampleFormat( SWAP_32(chunk_fmt.sample_rate), SWAP_16(chunk_fmt.bits_per_sample), SWAP_16(chunk_fmt.num_channels)); return sampleFormat; }
static void write_unsized_type_rec(ctf_buf_t *b, ctf_type_t *ctt) { ctf_stype_t *cts = (ctf_stype_t *)ctt; if (target_requires_swap) { SWAP_32(cts->ctt_name); SWAP_16(cts->ctt_info); SWAP_16(cts->ctt_size); } ctf_buf_write(b, cts, sizeof (*cts)); }
static void write_functions(iidesc_t *idp, ctf_buf_t *b) { ushort_t fdata[2]; ushort_t id; int nargs; int i; if (!idp) { fdata[0] = 0; ctf_buf_write(b, &fdata[0], sizeof (fdata[0])); debug(3, "Wrote function (null)\n"); return; } nargs = idp->ii_nargs + (idp->ii_vargs != 0); if (nargs > CTF_MAX_VLEN) { terminate("function %s has too many args: %d > %d\n", idp->ii_name, nargs, CTF_MAX_VLEN); } fdata[0] = CTF_TYPE_INFO(CTF_K_FUNCTION, 1, nargs); fdata[1] = idp->ii_dtype->t_id; if (target_requires_swap) { SWAP_16(fdata[0]); SWAP_16(fdata[1]); } ctf_buf_write(b, fdata, sizeof (fdata)); for (i = 0; i < idp->ii_nargs; i++) { id = idp->ii_args[i]->t_id; if (target_requires_swap) { SWAP_16(id); } ctf_buf_write(b, &id, sizeof (id)); } if (idp->ii_vargs) { id = 0; ctf_buf_write(b, &id, sizeof (id)); } debug(3, "Wrote function %s (%d args)\n", idp->ii_name, nargs); }
/* now for something ugly */ static void testSwap_16_ptr(void) { #if defined (SDCC) #include <sdcc-lib.h> /* just to get _AUTOMEM or _STATMEM */ #if defined (SDCC_STACK_AUTO) #define MY_STATIC static #else #define MY_STATIC #endif MY_STATIC unsigned long _STATMEM tt=TEST_VECT_32; /* swapping with little register pressure */ { unsigned char c; /* uglyness += 1 */ c = *(0+(unsigned char _STATMEM *)&tt); *(0+(unsigned char _STATMEM *)&tt) = *(2+(unsigned char _STATMEM *)&tt); *(2+(unsigned char _STATMEM *)&tt) = c; c = *(1+(unsigned char _STATMEM *)&tt); *(1+(unsigned char _STATMEM *)&tt) = *(3+(unsigned char _STATMEM *)&tt); *(3+(unsigned char _STATMEM *)&tt) = c; /* uglyness -= 1 */ } ASSERT( tt == SWAP_16(TEST_VECT_32)); #endif }
extern unsigned_16 DWRVMReadWord( drmem_hdl hdl ) /***********************************************/ { page_entry *node; unsigned_16 off; virt_struct vm; vm.l = hdl; ACCESSPAGE( node, vm ); off = NODE_OFF(vm); if( off <= MAX_NODE_SIZE - 2 ) { // we can read both bytes now. // must not swap bytes in source buffer! off = *((unsigned_16 *)( node->mem + off )); } else { off = *(unsigned_8 *)( node->mem + off ); vm.l++; ACCESSPAGE( node, vm ); off |= ((unsigned_16)*node->mem) << 8; } if( DWRCurrNode->byte_swap ) { SWAP_16( off ); } return( off ); }
ScmObj Scm_ReadBinaryF16(ScmPort *iport, ScmSymbol *endian) { swap_f16_t v; CHECK_ENDIAN(endian); if (getbytes(v.buf, 2, iport) == EOF) return SCM_EOF; SWAP_16(endian, v); return Scm_MakeFlonum(Scm_HalfToDouble(v.val)); }
ScmObj Scm_GetBinaryS16(ScmUVector *uv, int off, ScmSymbol *endian) { swap_s16_t v; CHECK_ENDIAN(endian); extract(uv, v.buf, off, 2); SWAP_16(endian, v); return SCM_MAKE_INT(v.val); }
ScmObj Scm_GetBinaryF16(ScmUVector *uv, int off, ScmSymbol *endian) { swap_f16_t v; CHECK_ENDIAN(endian); extract(uv, v.buf, off, 2); SWAP_16(endian, v); return Scm_MakeFlonum(Scm_HalfToDouble(v.val)); }
void Scm_PutBinaryS16(ScmUVector *uv, int off, ScmObj val, ScmSymbol *e) { swap_s16_t v; CHECK_ENDIAN(e); v.val = Scm_GetInteger16Clamp(val, SCM_CLAMP_NONE, NULL); SWAP_16(e, v); inject(uv, v.buf, off, 2); }
void Scm_PutBinaryF16(ScmUVector *uv, int off, ScmObj val, ScmSymbol *e) { swap_f16_t v; CHECK_ENDIAN(e); v.val = Scm_DoubleToHalf(Scm_GetDouble(val)); SWAP_16(e, v); inject(uv, v.buf, off, 2); }
ScmObj Scm_ReadBinaryS16(ScmPort *iport, ScmSymbol *endian) { swap_s16_t v; CHECK_ENDIAN(endian); if (getbytes(v.buf, 2, iport) == EOF) return SCM_EOF; SWAP_16(endian, v); return SCM_MAKE_INT(v.val); }
void Scm_WriteBinaryS16(ScmObj sval, ScmPort *oport, ScmSymbol *endian) { swap_s16_t v; ENSURE_OPORT(oport); CHECK_ENDIAN(endian); v.val = Scm_GetInteger16Clamp(sval, SCM_CLAMP_NONE, NULL); SWAP_16(endian, v); Scm_Putz(v.buf, 2, oport); }
void Scm_WriteBinaryF16(ScmObj sval, ScmPort *oport, ScmSymbol *endian) { swap_f16_t v; ENSURE_OPORT(oport); CHECK_ENDIAN(endian); v.val = Scm_DoubleToHalf(Scm_GetDouble(sval)); SWAP_16(endian, v); Scm_Putz(v.buf, 2, oport); }
extern unsigned_16 DWRVMReadWord( dr_handle hdl ) /***********************************************/ { unsigned_16 word = *((unsigned_16 _WCUNALIGNED *)(hdl)); if( DWRCurrNode->byte_swap ) { SWAP_16( word ); } return( word ); }
unsigned short letoh16(unsigned short x) { unsigned short n = 0x1234; unsigned char* ch = (unsigned char*)&n; if (*ch == 0x34) { /* Little-endian */ return x; } else { return SWAP_16(x); } }
static void write_objects(iidesc_t *idp, ctf_buf_t *b) { ushort_t id = (idp ? idp->ii_dtype->t_id : 0); ctf_buf_write(b, &id, sizeof (id)); if (target_requires_swap) { SWAP_16(id); } debug(3, "Wrote object %s (%d)\n", (idp ? idp->ii_name : "(null)"), id); }
/* * Dump the ELF header, if any. */ bool Dmp_elf_header( unsigned long start ) /****************************************/ { Wread( &Elf_head, sizeof( Elf32_Ehdr ) ); if( memcmp( Elf_head.e_ident, ELF_SIGNATURE, ELF_SIGNATURE_LEN ) ) { return( 0 ); } Banner( "ELF Header" ); if( start != 0 ) { Wdputs( "File Offset:" ); Puthex( start, 8 ); Wdputslc( "\n" ); } Wdputs( "class (1==32-bit objects, 2==64-bit objs) = " ); Puthex( Elf_head.e_ident[EI_CLASS], 2 ); Wdputslc( "H\ndata (1==little-endian, 2==big-endian) = " ); Puthex( Elf_head.e_ident[EI_DATA], 2 ); Wdputslc( "H\nversion = " ); Puthex( Elf_head.e_ident[EI_VERSION], 2 ); Wdputslc( "H\nOS/ABI type (0==unspecified) = " ); Puthex( Elf_head.e_ident[EI_OSABI], 2 ); Wdputslc( "H\nABI version (0==unspecified) = " ); Puthex( Elf_head.e_ident[EI_ABIVERSION], 2 ); Wdputslc( "H\n" ); if( Elf_head.e_ident[EI_DATA] != NATIVE_ENDIAN ) { Byte_swap = TRUE; /* Byte swap ELF header */ SWAP_16( Elf_head.e_type ); SWAP_16( Elf_head.e_machine ); SWAP_32( Elf_head.e_version ); SWAP_32( Elf_head.e_entry ); SWAP_32( Elf_head.e_phoff ); SWAP_32( Elf_head.e_shoff ); SWAP_32( Elf_head.e_flags ); SWAP_16( Elf_head.e_ehsize ); SWAP_16( Elf_head.e_phentsize ); SWAP_16( Elf_head.e_phnum ); SWAP_16( Elf_head.e_shentsize ); SWAP_16( Elf_head.e_shnum ); SWAP_16( Elf_head.e_shstrndx ); } dmp_hdr_type( Elf_head.e_type ); Dump_header( &Elf_head.e_type, elf_exe_msg ); Wdputslc( "\n" ); dmp_prog_sec( start ); return( 1 ); }
static void label(ud_handle_t udh, uint32_t set_flags) { if (set_flags == 0) { if (udh->udfs.flags & VALID_MVDS) { print_info(&udh->udfs.mvds, "mvds", udh); } if (udh->udfs.flags & VALID_RVDS) { print_info(&udh->udfs.rvds, "rvds", udh); } return; } else { if (udh->udfs.flags & VALID_MVDS) { label_vds(&udh->udfs.mvds, set_flags, udh); } if (udh->udfs.flags & VALID_RVDS) { label_vds(&udh->udfs.rvds, set_flags, udh); } if (((set_flags & (SET_FSNAME | SET_VOLNAME)) == (SET_FSNAME | SET_VOLNAME)) && (udh->udfs.fsd_len != 0)) { struct file_set_desc *fsd; off = udh->udfs.fsd_loc * udh->udfs.lbsize; if (ud_read_dev(udh, off, buf, udh->udfs.fsd_len) != 0) { return; } /* LINTED */ fsd = (struct file_set_desc *)buf; set_dstring(fsd->fsd_lvid, volname, sizeof (fsd->fsd_lvid)); set_dstring(fsd->fsd_fsi, volname, sizeof (fsd->fsd_fsi)); ud_make_tag(udh, &fsd->fsd_tag, UD_FILE_SET_DESC, SWAP_32(fsd->fsd_tag.tag_loc), SWAP_16(fsd->fsd_tag.tag_crc_len)); (void) ud_write_dev(udh, off, buf, udh->udfs.fsd_len); } } }
/* Read ELF header and check if it's roughly what we're expecting */ int elf_read_hdr( int fd, Elf32_Ehdr *e_hdr ) { // Elf32_Phdr phdr; // size_t i; int result = FALSE; lseek( fd, 0, SEEK_SET ); if( read( fd, e_hdr, sizeof( *e_hdr ) ) >= sizeof( *e_hdr ) && memcmp( e_hdr->e_ident, ELF_SIGNATURE, 4 ) == 0 && e_hdr->e_ident[EI_CLASS] == ELFCLASS32) { #ifdef __BIG_ENDIAN__ if( e_hdr->e_ident[EI_DATA] == ELFDATA2LSB ) core_info.swap_bytes = TRUE; #else if( e_hdr->e_ident[EI_DATA] == ELFDATA2MSB ) core_info.swap_bytes = TRUE; #endif if( core_info.swap_bytes ) { SWAP_16( e_hdr->e_type ); SWAP_16( e_hdr->e_machine ); SWAP_32( e_hdr->e_version ); SWAP_32( e_hdr->e_entry ); SWAP_32( e_hdr->e_phoff ); SWAP_32( e_hdr->e_shoff ); SWAP_32( e_hdr->e_flags ); SWAP_16( e_hdr->e_ehsize ); SWAP_16( e_hdr->e_phentsize ); SWAP_16( e_hdr->e_phnum ); SWAP_16( e_hdr->e_shentsize ); SWAP_16( e_hdr->e_shnum ); SWAP_16( e_hdr->e_shstrndx ); } if( e_hdr->e_phoff != 0 && e_hdr->e_phentsize >= sizeof( Elf32_Phdr ) ) { result = TRUE; } } return( result ); }
UInt16 mlsConfigGetAckCheckTimeout() { return SWAP_16(gConfigData.settlementAckCheckTimeout); }
UInt16 mlsConfigGetAckCheckingInterval() { return SWAP_16(gConfigData.settlementAckCheckingInterval); }
UInt16 mlsConfigGetMdFileErrorAge() { return SWAP_16(gConfigData.mdFileErrorAge); }
UInt16 mlsConfigGetMdFileWarningAge() { return SWAP_16(gConfigData.mdFileWarningAge); }
UInt16 mlsConfigGetBatchClearanceDay() { return SWAP_16(gConfigData.batchClearanceDay); }
UInt16 mlsConfigGetNETSMdLimit() { return SWAP_16(gConfigData.netsMDLimit); }
UInt16 mlsConfigGetEZMdLimit() { return SWAP_16(gConfigData.ezMDLimit); }
#define CONFIG_DEBUG_HEADER "CFG_:" #define CONFIG_DEBUG_PRINTF(...) mlsDebugModPrintf(DEBUG_MODULE_ID_CONFIG, CONFIG_DEBUG_HEADER __VA_ARGS__) //#ifdef CONFIG_DEBUG //#define CONFIG_DEBUG_PRINTF mlsDebugPrintf //#else //#define CONFIG_DEBUG_PRINTF(...) //#endif #define CONFIGURATION_DATA_FORMAT_VERSION 0x0100 //#define SING_DEFAULT_CONFIG_VALUE ConfigFile gConfigData; const ConfigFile defaultConfig = { .formatVersion = SWAP_16(CONFIGURATION_DATA_FORMAT_VERSION), .effectiveDate = "20100101", .merchantChainID = "00000", .locationID = "00000", .deviceType = "0080", .deviceID = "CCTVending", .merchantID = "000000000000000", .merchantPOSID = "0000000000", .cardSerialNumber = "00000000", .netsTerminalSerialNumber = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, .netsMerchantIdentifier = "Z1Z", .gprsEnable = 1, .gprsRetryInterval = SWAP_16(1), #ifdef SING_DEFAULT_CONFIG_VALUE .gprsAPNserver = "sunsurf", .gprsAPNUserName = "",
/* * Search for the prn in the array * of partitions and translate * to the disk block number */ daddr_t ud_xlate_to_daddr(struct udf_vfs *udf_vfsp, uint16_t prn, uint32_t blkno, int32_t nblks, uint32_t *count) { int32_t i; struct ud_map *map; struct ud_part *ud_parts; uint32_t lblkno, retblkno = 0, *addr; uint32_t begin_req, end_req; uint32_t begin_bad, end_bad; ud_printf("ud_xlate_to_daddr\n"); /* Is prn valid */ if (prn < udf_vfsp->udf_nmaps) { map = &(udf_vfsp->udf_maps[prn]); if (map->udm_flags == UDM_MAP_VPM) { /* * Map is Virtual Parition Map * first check for the appropriate * table and then return the converted * block number */ for (i = 0; i < map->udm_nent; i++) { if (blkno < map->udm_count[i]) { addr = map->udm_addr[i]; lblkno = SWAP_32(addr[blkno]); *count = 1; break; } else { blkno -= map->udm_count[i]; } } } else if (map->udm_flags == UDM_MAP_SPM) { struct stbl *stbl; struct stbl_entry *te; int32_t entry_count; /* * Map type is Sparable Parition Map * if the block is in the map * return the translated block * other wise use the regular * partition stuff */ begin_req = blkno; end_req = begin_req + nblks; stbl = (struct stbl *)map->udm_spaddr[0]; te = (struct stbl_entry *)&stbl->stbl_entry; entry_count = SWAP_16(stbl->stbl_len); for (i = 0; i < entry_count; i++, te++) { begin_bad = SWAP_32(te->sent_ol); end_bad = begin_bad + map->udm_plen; /* * Either unmapped or reserved * or defective. need not consider */ if (begin_bad >= (uint32_t)0xFFFFFFF0) { continue; } if ((end_req < begin_bad) || (begin_req >= end_bad)) { continue; } if (begin_req < begin_bad) { ASSERT(end_req >= begin_bad); end_req = begin_bad; } else { retblkno = SWAP_32(te->sent_ml) + begin_req - begin_bad; if (end_req < end_bad) { *count = end_req - begin_req; } else { *count = end_bad - begin_req; } goto end; } } lblkno = blkno; *count = end_req - begin_req; } else { /* * regular partition */ lblkno = blkno; *count = nblks; } ud_parts = udf_vfsp->udf_parts; for (i = 0; i < udf_vfsp->udf_npart; i++) { if (map->udm_pn == ud_parts->udp_number) { /* * Check if the block is inside * the partition or not */ if (lblkno >= ud_parts->udp_length) { retblkno = 0; } else { retblkno = ud_parts->udp_start + lblkno; } goto end; } ud_parts ++; } } end: return (retblkno); }