Beispiel #1
0
/*
 * Read parameter block header
 */
void psnd_pargtm(int file_type, float *parms, int *nt0par, int *ntnpar, 
                          int *iaqdir, int *nextdr)
{
    PARDEF_HEADER *ph;
    ENDI endi;

    ph = (PARDEF_HEADER *) parms;
    *ntnpar = ph->ntnpar;
    *nt0par = ph->nt0par;
    *iaqdir = ph->iaqdir;
    *nextdr = ph->nextdr;
    /*
     * If old style OLD3D file, params have been swapped in the
     * iora layer, so return
     */
    if (file_type == FILE_TYPE_OLD3D) {
        ph->type = FILE_TYPE_OLD3D;
        return;
    }
    ph->type = FILE_TYPE_ND;
    endi.i   = ph->endi;
    ph->swapit  = (os_big_endian() != endi.byte[3]);
    if (ph->swapit) {
        swap4(ntnpar);
        swap4(nt0par);
        swap4(iaqdir);
        swap4(nextdr);
    }
    *ntnpar /= sizeof(float);
    *nt0par /= sizeof(float);
}
Beispiel #2
0
 //***************************************************************************
 //***************************************************************************
 int 
 WriteHTKFeature(FILE * pOutFp, FLOAT * pOut, size_t feaLen, bool swap) 
 {
   size_t    i;
   size_t    cc = 0;
   
 #if !DOUBLEPRECISION
   if (swap) 
     for (i = 0; i < feaLen; i++) 
       swap4(pOut[i]);
   
   cc = fwrite(pOut, sizeof(FLOAT_32), feaLen, pOutFp);
   
   if (swap) 
     for (i = 0; i < feaLen; i++) 
       swap4(pOut[i]);
 #else
   FLOAT_32 f;
 
   for (i = 0; i < feaLen; i++) 
   {
     f = pOut[i];
     if (swap) 
       swap4(f);
     cc += fwrite(&f, sizeof(FLOAT_32), 1, pOutFp);
   }
 #endif
   return cc == feaLen ? 0 : -1;
 }
void Consumer::copyImageData(void* dst, const void* src)
	{
	if (connection.videoDevice.getRequestedPalette() == connection.videoDevice.getDevicePalette())
		{
		switch (connection.videoDevice.getDevicePalette())
			{
			case paletteGrey:
				copy(dst, src, 1);
				break;

			case paletteRGB:
			case paletteBGR:
				copy(dst, src, 3);
				break;

			case paletteRGBA:
			case paletteABGR:
				copy(dst, src, 4);
				break;

			default:
				throw Miro::Exception("can't copy image: illegal image palette");
			}
		}
	else
		{
		switch (connection.videoDevice.getDevicePalette())
			{
			case paletteRGB:
				if (connection.videoDevice.getRequestedPalette() == paletteBGR)
					swap3(dst, src);
				else
					throw Miro::Exception("can't copy image: incompatible image palette");
				break;

			case paletteBGR:
				if (connection.videoDevice.getRequestedPalette() == paletteRGB)
					swap3(dst, src);
				else
					throw Miro::Exception("can't copy image: incompatible image palette");
				break;

			case paletteRGBA:
				if (connection.videoDevice.getRequestedPalette() == paletteABGR)
					swap4(dst, src);
				else
					throw Miro::Exception("can't copy image: incompatible image palette");
				break;

			case paletteABGR:
				if (connection.videoDevice.getRequestedPalette() == paletteRGBA)
					swap4(dst, src);
				else
					throw Miro::Exception("can't copy image: incompatible image palette");
				break;
			default:
				throw Miro::Exception("can't copy image: incompatible image palette");
			}
		}
	}
Beispiel #4
0
/*
 * Get a parameter form the parameter-record 'par'
 * and store it in the PARDEF record 'pd', together
 * with its name, size, and type
 *
 * On success return the next (unused) PARDEF record,
 * on failure return this PARDEF record.
 */
static PARDEF *setpar(PARDEF *pd, int type, char *name, int offset, 
                      PBLOCK *par, int swapit)
{
    int *ip;
    float *fp;

    if (offset == 0) 
        return pd;
    pd->size = (unsigned char) sizeof(PARDEF);
    pd->type = (char) type;
    memset(pd->name, 0, PARNAMESIZE);
    strncpy(pd->name, name, PARNAMESIZE);
    if (pd->type == 'F') {
        fp = (float*) par;
        pd->value.f = fp[offset];
        if (swapit)
            swap4(&(pd->value.f));
    }
    else if (pd->type == 'I') {
        ip = (int*) par;
        pd->value.i = ip[offset];
        if (swapit)
            swap4(&(pd->value.i));
    }
    return (PARDEF*) (((char*)pd) + pd->size);
}
Beispiel #5
0
/*
 * Searches for the variable with 'pd->name' in the array
 * 'old123d_par'. On success, print the variable 
 * to the 'label' text record, from the corresponding position
 * in the parameter block 'pd'
 *
 * Return 1 on success, 0 otherwise
 */
static int findpar_text(PARDEF *pd, char *label, int swapit)
{
    int   ip;
    float fp;
    int i;

    if (pd == NULL)
        return 0;
    for (i=0;old123d_par[i].type;i++) {
        if (strncmp(old123d_par[i].name, pd->name, PARNAMESIZE)==0) {
            if (pd->type == 'F') {
                fp = pd->value.f;
                if (swapit)
                    swap4((void*)&fp);
                sprintf(label, "%-10s F %f\n",pd->name, fp);
            }
            else if (pd->type == 'I') {
                ip = pd->value.i;
                if (swapit)
                    swap4((void*)&ip);
                sprintf(label,"%-10s I %d\n",pd->name, ip);
            }
            else
                return 0;
            return 1;
        }
    }
    return 0;
}
Beispiel #6
0
/*
 * Store parameter from parameter block par onto
 * packed-parameter-block xpar.
 * idir is the direction corresponding to the par record
 * if create is true, a new xpar record is created, that is,
 * a record with all the new parameters on it
 */
void psnd_parstt(float *xpar, int idir, PBLOCK *par, int create)
{
    int i,ioff,dim,par_size,header_size;
    float *xp;
    PARDEF_HEADER *ph;
    PARDEF *pd;

    ph = (PARDEF_HEADER *) xpar;
    if (ph->type == FILE_TYPE_OLD3D) {
        old123d_parstt(xpar,idir,par);
        return;
    }
    dim         = ph->iaqdir;
    par_size    = ph->ntnpar;
    header_size = ph->nt0par;
    if (ph->swapit) {
        swap4(&dim);
        swap4(&par_size);
        swap4(&header_size);
    }
    if (idir > dim)
        return;
    ioff   = (idir-1) * par_size + header_size;
    xp     = xpar + ioff/sizeof(float);
    init_par_offsets(par);
    /*
     * Create a new xpar
     */
    if (create) {
        for (i=0;old123d_par[i].type;i++) 
            xp = (float*) setpar((PARDEF*) xp, 
                             old123d_par[i].type, 
                             old123d_par[i].name, 
                             old123d_par[i].offset,
                             par,
                             ph->swapit);
        return;
    }
    /*
     * Update xpar
     */
    pd = (PARDEF*) xp;
    while (pd->type) {
        for (i=0;old123d_par[i].type;i++) {
            if (!old123d_par[i].offset)
                continue;
            if (strcmp(pd->name, old123d_par[i].name) == 0) {
                xp = (float*) pd;
                setpar((PARDEF*) xp, 
                             old123d_par[i].type, 
                             old123d_par[i].name, 
                             old123d_par[i].offset,
                             par,
                             ph->swapit);
                break;
            }
        }
        pd += 1;
    }
}
Beispiel #7
0
/*
 * Packed-parameter-record in text format ,label, is translated
 * and stored on packed-parameter-record xpar
 */
int psnd_parstt_text(float *xpar, char *label)
{
    int i,ioff,dim,par_size,header_size,idir;
    float *xp;
    PARDEF_HEADER *ph;
    PARDEF *pd;
    char *p, delim[] = "\r\n";

    ph = (PARDEF_HEADER *) xpar;
    if (ph->type == FILE_TYPE_OLD3D) {
        return 0;
    }
    dim         = ph->iaqdir;
    par_size    = ph->ntnpar;
    header_size = ph->nt0par;
    if (ph->swapit) {
        swap4(&dim);
        swap4(&par_size);
        swap4(&header_size);
    }
    p = strtok(label, delim);
    idir = 0;
    while (p) {
        char name[100], type;
        
        if (strncmp(p,"Direction",9) == 0) {
            sscanf(p, "Direction:%d", &idir);
            ioff   = (idir-1) * par_size + header_size;
            xp     = xpar + ioff/sizeof(float);
            pd     = (PARDEF*) xp;
        }
        else if (idir > 0 && idir <= dim) {
            name[0] = '\0';
            type    = 0;
            sscanf(p, "%s %c", name, &type);
            
            for (i=0;(pd+i)->type;i++) {
                if (strcmp(name, (pd+i)->name)==0) {
                    if (type == 'F') {
                        float f = 0.0;
                        sscanf(p, "%s %c %f", name, &type, &f);
                        if (ph->swapit)
                            swap4(&f);
                        (pd+i)->value.f = f;
                    }
                    else if (type == 'I') {
                        int j = 0;
                        sscanf(p, "%s %c %d", name, &type, &j);
                        if (ph->swapit)
                            swap4(&j);
                        (pd+i)->value.i = j;
                    }
                }
            }
        }
        p = strtok(NULL, delim);
    }
    return 1;
}
Beispiel #8
0
int
pciCfgWrite(int interface,int bus,int device,int func,int regno,ulong value)
{
	*(ulong *)PCICFGADR = swap4(pciCfgAddress(bus,device,0,regno));
    *(ulong *)(PCICFGDATA | (regno << 2)) = swap4(value);

	return(0);
}
Beispiel #9
0
 //***************************************************************************
 //***************************************************************************
 int 
 ReadHTKFeature(
     FILE *    pInFp, 
     FLOAT *   pIn, 
     size_t    feaLen, 
     bool      swap,
     bool      decompress, 
     FLOAT *   pScale, 
     FLOAT *   pBias)
 {
   size_t i;
   
   if (decompress) 
   {
     INT_16 s;
 //    FLOAT pScale = (xmax - xmin) / (2*32767);
 //    FLOAT pBias  = (xmax + xmin) / 2;
 
     for (i = 0; i < feaLen; i++) 
     {
       if (fread(&s, sizeof(INT_16), 1, pInFp) != 1) 
         return -1;
       
       if (swap) swap2(s);
       pIn[i] = (s + pBias[i]) / pScale[i];
     }
     
     return 0;
   }
 
 #if !DOUBLEPRECISION
   if (fread(pIn, sizeof(FLOAT_32), feaLen, pInFp) != feaLen) 
     return -1;
   
   if (swap) 
     for (i = 0; i < feaLen; i++) 
       swap4(pIn[i]);
 #else
   FLOAT_32 f;
 
   for (i = 0; i < feaLen; i++) 
   {
     if (fread(&f, sizeof(FLOAT_32), 1, pInFp) != 1)
       return -1;
     
     if (swap) 
       swap4(f);
       
     pIn[i] = f;
   }
 #endif
   return 0;
 }  // int ReadHTKFeature
Beispiel #10
0
/*
 * Get parameters from packed-parameter-block xpar, starting
 * with direction idir_start and ending with direction idir_stop.
 * The parameters are printed on a text(ASCII) buffer, that is
 * allocated here and returned. The calling routine must free
 * this record after use. For old-i/o-type OLD3D files, NULL 
 * is returned.
 */
char *psnd_pargtt_text(float *xpar, int idir_start, int idir_stop)
{
    int ioff,dim,par_size,header_size,id = 1;
    PARDEF *pd;
    float *xp;
    PARDEF_HEADER *ph;
    char *par=NULL;
    int parlen=0,parsize=0,idir;

    ph = (PARDEF_HEADER *) xpar;
    if (ph->type == FILE_TYPE_OLD3D) {
        return NULL;
    }
    else {
        dim         = ph->iaqdir;
        par_size    = ph->ntnpar;
        header_size = ph->nt0par;
        if (ph->swapit) {
            swap4(&dim);
            swap4(&par_size);
            swap4(&header_size);
        }
        for (idir=idir_start;idir<=idir_stop;idir++) {
            char label[200];
            if (idir > dim)
                return par;
            ioff   = (idir-1) * par_size + header_size;
            xp     = xpar + ioff/sizeof(float);
            pd     = (PARDEF*) xp;
            sprintf(label,"Direction:%d\n", idir);
            while (pd) {
                if (parlen + (int)strlen(label) >= parsize) {
                    if (parsize == 0) {
                        parsize = 100;
                        par = (char*)calloc(parsize,sizeof(char));
                    }
                    else {
                        parsize *= 2;
                        par = (char*)realloc(par,parsize*sizeof(char));
                    }
                }
                parlen += strlen(label);
                strcat(par,label);
                id = findpar_text(pd, label, ph->swapit);
                if (!id)
                    break;
                pd = getnextpar(pd);
            }
        }
    }
    return par;
}
Beispiel #11
0
/*
 * byteswap a single magic entry
 */
static void bs1(struct r_magic *m) {
	m->cont_level = swap2(m->cont_level);
	m->offset = swap4((ut32)m->offset);
	m->in_offset = swap4((ut32)m->in_offset);
	m->lineno = swap4((ut32)m->lineno);
	if (MAGIC_IS_STRING (m->type)) {
		m->str_range = swap4(m->str_range);
		m->str_flags = swap4(m->str_flags);
	} else {
		m->value.q = swap8(m->value.q);
		m->num_mask = swap8(m->num_mask);
	}
}
Beispiel #12
0
// This function reorders the individual bytes (that we care about) 
// in each header struct entry. This is a hack to support the limited 
// xilsd_fread() functionality.
void bmpReorder(bmp_file_info *bmp) {

  // Swap the bmp_header values
  swap4(&bmp->h2.bmp_offset);


  // Swap the dib_header values
  swap4(&bmp->h3.header_sz);
  swap4(&bmp->h3.width);
  swap4(&bmp->h3.height);
  swap2(&bmp->h3.bitspp);

}
//
// Split function result into result (0/-1) and errno (-result)
//
static void setErrnoAndResult(
    vmiProcessorP processor,
    vmiosObjectP  object,
    Int32         result,
    const char   *context
) {
    if(!object->impurePtrDomain) {

        vmiMessage("P", "OR1K_ICF_NEWLIB",
            "Interception of '%s' failed - %s not found "
            "(application does not appear to be compiled with newlib "
            "or has no symbols)",
            context, ERRNO_REF
        );

        vmirtFinish(-1);

    } else if(result<0) {

        memDomainP domain     = object->impurePtrDomain;
        memEndian  endian     = vmirtGetProcessorDataEndian(processor);
        Int32      errnoValue = -result;
        Uns32      impurePtrAddr;

        result = -1;

        // swap errno endianness if required
        if(endian != ENDIAN_NATIVE) {
            errnoValue = swap4(errnoValue);
        }

        // read __impure_ptr value
        vmirtReadNByteDomain(
            domain, object->impurePtrAddr, &impurePtrAddr,
            sizeof(impurePtrAddr), 0, False
        );

        // swap errno address endianness if required
        if(endian != ENDIAN_NATIVE) {
            impurePtrAddr = swap4(impurePtrAddr);
        }

        // write back errno
        vmirtWriteNByteDomain(
            domain, impurePtrAddr+OR1K_ERRNO_OFFSET, &errnoValue,
            sizeof(errnoValue), 0, True
        );
    }

    vmiosRegWrite(processor, object->result, &result);
}
Beispiel #14
0
int
swap_sac (SAC * sachdr)
{
    float           x;
    int             intel;
    x = sachdr->delta;
    if (x == SAC_NULL_FLOAT
            || (x > 1e-8 && x < 1e3)) {
        /* no swap */

#ifndef WORDS_BIGENDIAN
        intel = 1;
#else
        intel = 0;
#endif
    } else {
        /* swap */
        char           *s;
        s = (char *) sachdr;
        swap4 (s, s, 110);

#ifdef WORDS_BIGENDIAN
        intel = 1;
#else
        intel = 0;
#endif
    }
    return intel;
}
Beispiel #15
0
/*
 * Get parameters from packed-parameter-block xpar
 * and put those in parameter block par.
 * idir is the direction, that is, the number of the parameter block
 */
void psnd_pargtt(float *xpar, int idir, PBLOCK *par)
{
    int ioff,dim,par_size,header_size,id = 1;
    PARDEF *pd;
    float *xp;
    PARDEF_HEADER *ph;

    ph = (PARDEF_HEADER *) xpar;
    if (ph->type == FILE_TYPE_OLD3D) {
        old123d_pargtt(xpar,idir,par);
    }
    else {
        dim         = ph->iaqdir;
        par_size    = ph->ntnpar;
        header_size = ph->nt0par;
        if (ph->swapit) {
            swap4(&dim);
            swap4(&par_size);
            swap4(&header_size);
        }
        if (idir > dim)
            return;
        ioff   = (idir-1) * par_size + header_size;
        xp     = xpar + ioff/sizeof(float);
        pd     = (PARDEF*) xp;
        init_par_offsets(par);
        while (pd) {
            id = findpar(pd, par, ph->swapit);
            pd = getnextpar(pd);
        }
    }
    /*
     * Set some newer parameters to acceptable defaults,
     * when not defined
     */
    if (par->aref <= 0) {
        par->aref = 1.0;
        par->bref = 1.0;
    }
    if (par->td <= 0) {
        par->td = par->nsiz;
    }
    if (par->iopt <= 0) {
        par->iopt = 3;
    }
}
Beispiel #16
0
/*
 * Searches for the variable with 'pd->name' in the array
 * 'old123d_par'. On success, copy the variable 
 * to the 'par' record, from the corresponding position
 * in the parameter block 'pd'
 *
 * Return 1 on success, 0 otherwise
 */
static int findpar(PARDEF *pd, PBLOCK *par, int swapit)
{
    int *ip;
    float *fp;
    int i;

    if (pd == NULL)
        return 0;
    for (i=0;old123d_par[i].type;i++) {
        if (old123d_par[i].offset==0)
            continue;
        if (strncmp(old123d_par[i].name, pd->name, PARNAMESIZE)==0) {
            if (old123d_par[i].type == 'F') {
                fp = (float*) par;
                /*
                 * if type of parameter is different in 'pd' and 'par',
                 * do a cast
                 */
                if (pd->type == 'I')
                    fp[old123d_par[i].offset]=(float)pd->value.i;
                else
                    fp[old123d_par[i].offset]=pd->value.f;
                if (swapit)
                    swap4((void*)(fp+old123d_par[i].offset));
            }
            else if (old123d_par[i].type == 'I') {
                ip = (int*) par;
                /*
                 * if type of parameter is different in 'pd' and 'par',
                 * do a cast
                 */
                if (pd->type == 'F')
                    ip[old123d_par[i].offset]=(int)pd->value.f;
                else
                    ip[old123d_par[i].offset]=pd->value.i;
                if (swapit)
                    swap4((void*)(ip+old123d_par[i].offset));
            }
            else
                return 0;
            return 1;
        }
    }
    return 0;
}
Beispiel #17
0
void
read_descriptrace( FILE *fp, Suds_tag header, Suds_descriptrace *d, int swap, long **data, int *bufsiz ) {

	fread( &d->dt_name.network, sizeof( char ), 4, fp );
	fread( &d->dt_name.st_name, sizeof( char ), 5, fp );
	fread( &d->dt_name.component, sizeof( char ), 1, fp );
	fread( &d->dt_name.inst_type, sizeof( short ), 1, fp );
	fread( &d->begintime, sizeof( double ), 1, fp );
	fread( &d->localtime, sizeof( short ), 1, fp );
	fread( &d->datatype, sizeof( char ), 1, fp );
	fread( &d->descriptor, sizeof( char ), 1, fp );
	fread( &d->digi_by, sizeof( short ), 1, fp );
	fread( &d->processed, sizeof( short ), 1, fp );
	fread( &d->length, sizeof( long ), 1, fp );
	fread( &d->rate, sizeof( float ), 1, fp );
	fread( &d->mindata, sizeof( float ), 1, fp );
	fread( &d->maxdata, sizeof( float ), 1, fp );
	fread( &d->avenoise, sizeof( float ), 1, fp );
	fread( &d->numclip, sizeof( long ), 1, fp );
	fread( &d->time_correct, sizeof( double ), 1, fp );
	fread( &d->rate_correct, sizeof( float ), 1, fp );

	if( swap ) {
		swap2( &d->dt_name.inst_type, &d->dt_name.inst_type, 1 );
		swap8( &d->begintime, &d->begintime, 1 );
		swap2( &d->localtime, &d->localtime, 1 );
		swap2( &d->digi_by, &d->digi_by, 1 );
		swap2( &d->processed, &d->processed, 1 );
		swap4( &d->length, &d->length, 1 );
		swap4( &d->rate, &d->rate, 1 );
		swap4( &d->mindata, &d->mindata, 1 );
		swap4( &d->maxdata, &d->maxdata, 1 );
		swap4( &d->avenoise, &d->avenoise, 1 );
		swap4( &d->numclip, &d->numclip, 1 );
		swap8( &d->time_correct, &d->time_correct, 1 );
		swap4( &d->rate_correct, &d->rate_correct, 1 );
	}

	if( d->datatype != '2' ) {

		complain( 1, "Datatype %s not understood--skipping\n", d->datatype );
		fseek( fp, header.data_length_bytes, SEEK_CUR );

	} else {
		if( *bufsiz < header.data_length_bytes ) {
			reallot( long *, *data, d->length ); 
			*bufsiz = d->length * sizeof( long );
		}

		fread( *data, sizeof( long ), d->length, fp );

		if( swap ) {
			swap4( *data, *data, d->length );
		}
	}
//
// Write data in the stat buffer 'buf' back to simulation space at address
// 'bufAddr'
//
static void transcribeStatData(
    vmiProcessorP processor,
    Uns32         bufAddr,
    vmiosStatBufP buf
) {
    memDomainP domain = vmirtGetProcessorDataDomain(processor);
    memEndian  endian = vmirtGetProcessorDataEndian(processor);

    // or1k/newlib stat structure
    struct {
        Uns32 _u1;      //  0:
        Uns32 mode;     //  4: mode
        Uns32 _u2;      //  8:
        Uns32 _u3;      // 12:
        Uns32 size;     // 16: size
        Uns32 atime;    // 20: atime
        Uns32 _u4;      // 24:
        Uns32 mtime;    // 28: mtime
        Uns32 _u5;      // 32:
        Uns32 ctime;    // 36: ctime
        Uns32 _u6;      // 40:
        Uns32 blksize;  // 44: blksize
        Uns32 blocks;   // 48: blocks
    } simStatStruct = {0};

    // convert from host mode to OR1K mode
    // - host S_IFDIR converts to or1k OR1K_NEWLIB_S_IFDIR
    // - host S_IFREG converts to or1k OR1K_NEWLIB_S_IFREG
    simStatStruct.mode = (
        (buf->mode & 0x1ff) |
        ((buf->mode & VMIOS_S_IFDIR) ? OR1K_NEWLIB_S_IFDIR : 0) |
        ((buf->mode & VMIOS_S_IFREG) ? OR1K_NEWLIB_S_IFREG : 0)
    );

    // extract remaining basic fields
    simStatStruct.size    = (Uns32)buf->size;
    simStatStruct.atime   = buf->atime;
    simStatStruct.ctime   = buf->ctime;
    simStatStruct.mtime   = buf->mtime;
    simStatStruct.blocks  = buf->blocks;
    simStatStruct.blksize = buf->blksize;

    // swap endianness if required
    if(endian != ENDIAN_NATIVE) {
        simStatStruct.mode    = swap4(simStatStruct.mode);
        simStatStruct.size    = swap4(simStatStruct.size);
        simStatStruct.blocks  = swap4(simStatStruct.blocks);
        simStatStruct.blksize = swap4(simStatStruct.blksize);
        simStatStruct.atime   = swap4(simStatStruct.atime);
        simStatStruct.ctime   = swap4(simStatStruct.ctime);
        simStatStruct.mtime   = swap4(simStatStruct.mtime);
    }

    // write stat struct into OR1K data domain
    vmirtWriteNByteDomain(
        domain, bufAddr, &simStatStruct, sizeof(simStatStruct), 0, True
    );
}
//
// Write data in the time buffer 'buf' back to simulation space at address
// 'bufAddr'
//
static void transcribeTimeData(
    vmiProcessorP processor,
    Uns32         bufAddr,
    vmiosTimeBufP buf
) {
    memDomainP domain = vmirtGetProcessorDataDomain(processor);
    memEndian  endian = vmirtGetProcessorDataEndian(processor);

    // swap endianness if required
    if(endian != ENDIAN_NATIVE) {
        buf->sec  = swap4(buf->sec);
        buf->usec = swap4(buf->usec);
    }

    // write values into OR1K data domain
    vmirtWriteNByteDomain(
        domain, bufAddr, buf, sizeof(*buf), 0, True
    );
}
Beispiel #20
0
int main (int argc ,char * * argv)
{
  int u;
  int t;
  u = 17;
  t = -96;
  printf ("before swap4: u = %d , t = %d \n" , u , t);
  swap4 (& u , & t);
  printf ("after  swap4: u = %d , t = %d \n" , u , t);
  return EXIT_SUCCESS;
}
//
// Intercept open - note that this appears NOT to use the standard ABI!
//
static VMIOS_INTERCEPT_FN(openInt) {

    Uns32 pathnameAddr;
    Int32 flags;
    Int32 mode;
    Uns32 sp;

    // obtain function arguments
    getArg(processor, object, 0, &pathnameAddr);
    vmiosRegRead(processor, object->sp,   &sp);

    // get file name from data domain
    memDomainP  domain   = vmirtGetProcessorDataDomain(processor);
    memEndian   endian   = vmirtGetProcessorDataEndian(processor);
    const char *pathname = vmirtGetString(domain, pathnameAddr);

    // get flags & mode from data domain
    vmirtReadNByteDomain(domain, sp,   &flags, sizeof(flags), 0, True);
    vmirtReadNByteDomain(domain, sp+4, &mode,  sizeof(mode),  0, True);

    // swap endianness if required
    if(endian != ENDIAN_NATIVE) {
        flags = swap4(flags);
        mode  = swap4(mode);
    }

    // implement open
    Int32 result = vmiosOpen(processor, pathname, flags, mode);

    // save file descriptor in simulated descriptor table if successful
    if(result>=0) {
        Int32 fdMap = newFileDescriptor(object, context);
        object->fileDescriptors[fdMap] = result;
        result = fdMap;
    }

    // return result
    setErrnoAndResult(processor, object, result, context);
}
Beispiel #22
0
int
read_header( FILE *fp, Suds_tag *header ) {

	int	swap;

	fread( &header->sync, sizeof( char ), 1, fp );
	fread( &header->machine, sizeof( char ), 1, fp );

	fread( &header->struct_type, sizeof( short ), 1, fp );
	fread( &header->struct_length_bytes, sizeof( long ), 1, fp );
	fread( &header->data_length_bytes, sizeof( long ), 1, fp );

#ifdef _BIG_ENDIAN 

	if( header->machine == '6' ) {
		swap = 1;
	} else {
		swap = 0;
	}

#else /* Assume little-endian */

	if( header->machine == '6' ) { 	
		swap = 0;
	} else {
		swap = 1;		/* Assume big-endian order */
	}

#endif

	if( swap ) {
		swap2( &header->struct_type, &header->struct_type, 1 );
		swap4( &header->struct_length_bytes, &header->struct_length_bytes, 1 );
		swap4( &header->data_length_bytes, &header->data_length_bytes, 1 );
	}

	return swap;
}
Beispiel #23
0
void 
read_stationcomp( FILE *fp, Suds_tag header, Suds_stationcomp *s, int swap ) {
	
	fread( &s->sc_name.network, sizeof( char ), 4, fp );
	fread( &s->sc_name.st_name, sizeof( char ), 5, fp );
	fread( &s->sc_name.component, sizeof( char ), 1, fp );
	fread( &s->sc_name.inst_type, sizeof( short ), 1, fp );
	fread( &s->azim, sizeof( short ), 1, fp );
	fread( &s->incid, sizeof( short ), 1, fp );
	fread( &s->st_lat, sizeof( double ), 1, fp );
	fread( &s->st_long, sizeof( double ), 1, fp );
	fread( &s->elev, sizeof( float ), 1, fp );
	fread( &s->enclosure, sizeof( char ), 1, fp );
	fread( &s->annotation, sizeof( char ), 1, fp );
	fread( &s->recorder, sizeof( char ), 1, fp );
	fread( &s->rockclass, sizeof( char ), 1, fp );
	fread( &s->rocktype, sizeof( short ), 1, fp );
	fread( &s->sitecondition, sizeof( char ), 1, fp );
	fread( &s->sensor_type, sizeof( char ), 1, fp );
	fread( &s->data_type, sizeof( char ), 1, fp );
	fread( &s->data_units, sizeof( char ), 1, fp );
	fread( &s->polarity, sizeof( char ), 1, fp );
	fread( &s->st_status, sizeof( char ), 1, fp );
	fread( &s->max_gain, sizeof( float ), 1, fp );
	fread( &s->clip_value, sizeof( float ), 1, fp );
	fread( &s->con_mvolts, sizeof( float ), 1, fp );
	fread( &s->channel, sizeof( short ), 1, fp );
	fread( &s->atod_gain, sizeof( short ), 1, fp );
	fread( &s->effective, sizeof( long ), 1, fp );
	fread( &s->clock_correct, sizeof( float ), 1, fp );
	fread( &s->station_delay, sizeof( float ), 1, fp );

	if( swap ) {
		swap2( &s->sc_name.inst_type, &s->sc_name.inst_type, 1 );
		swap2( &s->azim, &s->azim, 1 );
		swap2( &s->incid, &s->incid, 1 );
		swap8( &s->st_lat, &s->st_lat, 1 );
		swap8( &s->st_long, &s->st_long, 1 );
		swap4( &s->elev, &s->elev, 1 );
		swap2( &s->rocktype, &s->rocktype, 1 );
		swap4( &s->max_gain, &s->max_gain, 1 );
		swap4( &s->clip_value, &s->clip_value, 1 );
		swap4( &s->con_mvolts, &s->con_mvolts, 1 );
		swap2( &s->channel, &s->channel, 1 );
		swap2( &s->atod_gain, &s->atod_gain, 1 );
		swap4( &s->effective, &s->effective, 1 );
		swap4( &s->clock_correct, &s->clock_correct, 1 );
		swap4( &s->station_delay, &s->station_delay, 1 );
	}

	fseek( fp, header.data_length_bytes, SEEK_CUR );
}
Beispiel #24
0
 //***************************************************************************
 //***************************************************************************
 int 
 WriteHTKHeader (FILE * pOutFp, HtkHeader header, bool swap)
 {
   int cc;
 
   if (swap) {
     swap4(header.mNSamples);
     swap4(header.mSamplePeriod);
     swap2(header.mSampleSize);
     swap2(header.mSampleKind);
   }
 
   fseek (pOutFp, 0L, SEEK_SET);
   cc = fwrite(&header, sizeof(HtkHeader), 1, pOutFp);
 
   if (swap) {
     swap4(header.mNSamples);
     swap4(header.mSamplePeriod);
     swap2(header.mSampleSize);
     swap2(header.mSampleKind);
   }
 
   return cc == 1 ? 0 : -1;
 }
Beispiel #25
0
 //***************************************************************************
 //***************************************************************************
 int 
 ReadHTKHeader (FILE * pInFp, HtkHeader * pHeader, bool swap)
 {
   if (!fread(&pHeader->mNSamples,     sizeof(INT_32),  1, pInFp)) return -1;
   if (!fread(&pHeader->mSamplePeriod, sizeof(INT_32),  1, pInFp)) return -1;
   if (!fread(&pHeader->mSampleSize,   sizeof(INT_16),  1, pInFp)) return -1;
   if (!fread(&pHeader->mSampleKind,   sizeof(UINT_16), 1, pInFp)) return -1;
 
   if (swap) 
   {
     swap4(pHeader->mNSamples);
     swap4(pHeader->mSamplePeriod);
     swap2(pHeader->mSampleSize);
     swap2(pHeader->mSampleKind);
   }
 
   if (pHeader->mSamplePeriod < 0 || pHeader->mSamplePeriod > 100000 ||
       pHeader->mNSamples     < 0 || pHeader->mSampleSize   < 0) 
   {
     return -1;
   }
 
   return 0;
 }
Beispiel #26
0
int main(void) {

	//check_reference_and_ptr();
	
	int a = 5;
	int b = 10;

	printf("1). before swap, a:	%d, addr:	%p\n", a, &a);
	printf("1). before swap, b:	%d, addr:	%p\n", b, &b);
	swap(a, b);

	printf("1). after swap, a:	%d, addr:	%p\n", a, &a);
	printf("1). after swap, b:	%d, addr:	%p\n", b, &b);


	a = 5;
	b = 10;
	printf("2). before swap, a:	%d, addr:	%p\n", a, &a);
	printf("2). before swap, b:	%d, addr:	%p\n", b, &b);
	swap(&a, &b);

	printf("2). after swap, a:	%d, addr:	%p\n", a, &a);
	printf("2). after swap, b:	%d, addr:	%p\n", b, &b);


	a = 5;
	b = 10;

	printf("3). before swap, a:	%d, addr:	%p\n", a, &a);
	printf("3). before swap, b:	%d, addr:	%p\n", b, &b);
	swap3(&a, &b);

	printf("3). after swap, a:	%d, addr:	%p\n", a, &a);
	printf("3). after swap, b:	%d, addr:	%p\n", b, &b);

	a = 5;
	b = 10;

	printf("4). before swap, a:	%d, addr:	%p\n", a, &a);
	printf("4). before swap, b:	%d, addr:	%p\n", b, &b);
	swap4(a, b);

	printf("4). after swap, a:	%d, addr:	%p\n", a, &a);
	printf("4). after swap, b:	%d, addr:	%p\n", b, &b);

	return 0;

}
Beispiel #27
0
static int 
utPortableFWrite(FILE *f, const void *src, int numelem, int elemsize)
{
    int 	 size = numelem*elemsize;	    
    char	*buf = utGetBuffer(size);
    int		 i, retval;

    ut_2byte	*src2byte, *dest2byte;
    ut_4byte	*src4byte, *dest4byte;
    ut_8byte	*src8byte, *dest8byte;

    switch(elemsize)
    {
	case 1:
	    retval = fwrite(src, elemsize, numelem, f);
	    break;

	case 2:
	    src2byte = (ut_2byte *)src;
	    dest2byte = (ut_2byte *)buf;
	    if (!buf) return fwrite(src, elemsize, numelem, f);
	    for (i = 0; i < numelem; i++)
		dest2byte[i] = swap2(src2byte[i]);
	    retval = fwrite(buf, elemsize, numelem, f);	
	    break;

	case 4:
	    src4byte = (ut_4byte *)src;
	    dest4byte = (ut_4byte *)buf;
	    if (!buf) return fwrite(src, elemsize, numelem, f);
	    for (i = 0; i < numelem; i++)
		dest4byte[i] = swap4(src4byte[i]);
	    retval = fwrite(buf, elemsize, numelem, f);	
	    break;

	case 8:
	    src8byte = (ut_8byte *)src;
	    dest8byte = (ut_8byte *)buf;
	    if (!buf) return fwrite(src, elemsize, numelem, f);
	    for (i = 0; i < numelem; i++)
		dest8byte[i] = swap8(src8byte[i]);
	    retval = fwrite(buf, elemsize, numelem, f);	
	    break;
    }

    return retval;
}
Beispiel #28
0
static ostream &
utPortableWrite(ostream &os, const char *src, int numelem, int elemsize)
{
    int 	 size = numelem*elemsize;	    
    char	*buf = utGetBuffer(size);
    int		 i;

    ut_2byte	*src2byte, *dest2byte;
    ut_4byte	*src4byte, *dest4byte;
    ut_8byte	*src8byte, *dest8byte;

    switch(elemsize)
    {
	case 1:
	    os.write(src, numelem);
	    break;

	case 2:
	    src2byte = (ut_2byte *)src;
	    dest2byte = (ut_2byte *)buf;
	    if (!buf) return os.write(src, size);
	    for (i = 0; i < numelem; i++)
		dest2byte[i] = swap2(src2byte[i]);
	    os.write(buf, size);
	    break;

	case 4:
	    src4byte = (ut_4byte *)src;
	    dest4byte = (ut_4byte *)buf;
	    if (!buf) return os.write(src, size);
	    for (i = 0; i < numelem; i++)
		dest4byte[i] = swap4(src4byte[i]);
	    os.write(buf, size);
	    break;

	case 8:
	    src8byte = (ut_8byte *)src;
	    dest8byte = (ut_8byte *)buf;
	    if (!buf) return os.write(src, size);
	    for (i = 0; i < numelem; i++)
		dest8byte[i] = swap8(src8byte[i]);
	    os.write(buf, size);
	    break;
    }

    return os;
}
Beispiel #29
0
static istream &
utPortableRead(istream &is, char *dest, int numelem, int elemsize)
{
    int 	 size = numelem*elemsize;	    
    char	*buf = utGetBuffer(size);
    int		 i;

    ut_2byte	*src2byte, *dest2byte;
    ut_4byte	*src4byte, *dest4byte;
    ut_8byte	*src8byte, *dest8byte;

    switch(elemsize)
    {
	case 1:
	    is.read(dest, numelem);
	    break;

	case 2:
	    src2byte = (ut_2byte *)buf;
	    dest2byte = (ut_2byte *)dest;
	    if (!buf) return is.read(dest, size);
	    is.read(buf, size);
	    for (i = 0; i < numelem; i++)
		dest2byte[i] = swap2(src2byte[i]);
	    break;

	case 4:
	    src4byte = (ut_4byte *)buf;
	    dest4byte = (ut_4byte *)dest;
	    if (!buf) return is.read(dest, size);
	    is.read(buf, size);
	    for (i = 0; i < numelem; i++)
		dest4byte[i] = swap4(src4byte[i]);
	    break;

	case 8:
	    src8byte = (ut_8byte *)buf;
	    dest8byte = (ut_8byte *)dest;
	    if (!buf) return is.read(dest, size);
	    is.read(buf, size);
	    for (i = 0; i < numelem; i++)
		dest8byte[i] = swap8(src8byte[i]);
	    break;
    }

    return is;
}
Beispiel #30
0
ambix_err_t
_ambix_matrix_fill_data_byteswapped(ambix_matrix_t*mtx, const number32_t*data) {
  float32_t**matrix=mtx->data;
  uint32_t rows=mtx->rows;
  uint32_t cols=mtx->cols;
  uint32_t r;
  for(r=0; r<rows; r++) {
    uint32_t c;
    for(c=0; c<cols; c++) {
      number32_t v;
      number32_t d = *data++;
      v.i=swap4(d.i);
      matrix[r][c]=v.f;
    }
  }
  return AMBIX_ERR_SUCCESS;
}