Exemple #1
0
/*
 * return 0 - no update found
 * return 1 - found update
 */
int get_matching_sig(unsigned int csig, int cpf, void *mc, int rev)
{
	struct microcode_header_intel *mc_header = mc;
	struct extended_sigtable *ext_header;
	unsigned long total_size = get_totalsize(mc_header);
	int ext_sigcount, i;
	struct extended_signature *ext_sig;

	if (update_match_cpu(csig, cpf, mc_header->sig, mc_header->pf))
		return 1;

	/* Look for ext. headers: */
	if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE)
		return 0;

	ext_header = mc + get_datasize(mc_header) + MC_HEADER_SIZE;
	ext_sigcount = ext_header->count;
	ext_sig = (void *)ext_header + EXT_HEADER_SIZE;

	for (i = 0; i < ext_sigcount; i++) {
		if (update_match_cpu(csig, cpf, ext_sig->sig, ext_sig->pf))
			return 1;
		ext_sig++;
	}
	return 0;
}
Exemple #2
0
static MAPTYPE *get_maps_3dvol(const mxArray *ptr, int *n)
{
    int num_dims, jj, t, dtype = 0;
    const mwSize *dims;
    MAPTYPE *maps;
    unsigned char *dptr;

    if      (mxIsDouble(ptr)) dtype = SPM_DOUBLE;
    else if (mxIsSingle(ptr)) dtype = SPM_FLOAT;
    else if (mxIsInt32 (ptr)) dtype = SPM_SIGNED_INT;
    else if (mxIsUint32(ptr)) dtype = SPM_UNSIGNED_INT;
    else if (mxIsInt16 (ptr)) dtype = SPM_SIGNED_SHORT;
    else if (mxIsUint16(ptr)) dtype = SPM_UNSIGNED_SHORT;
    else if (mxIsInt8  (ptr)) dtype = SPM_SIGNED_CHAR;
    else if (mxIsUint8 (ptr)) dtype = SPM_UNSIGNED_CHAR;
    else mexErrMsgTxt("Unknown volume datatype.");

    maps = (MAPTYPE *)mxCalloc(1, sizeof(MAPTYPE));

    num_dims = mxGetNumberOfDimensions(ptr);
    if (num_dims > 3)
    {
        mexErrMsgTxt("Too many dimensions.");
    }

    dims     = mxGetDimensions(ptr);
    for(jj=0; jj<num_dims; jj++)
        maps->dim[jj]=dims[jj];
    for(jj=num_dims; jj<3; jj++)
        maps->dim[jj]=1;

    for(jj=0; jj<16; jj++)
        maps->mat[jj] = 0.0;
    for(jj=0; jj<4; jj++)
        maps->mat[jj + jj*4] = 1.0;

    maps->dtype  = dtype;

    maps->data   = (void  **)mxCalloc(maps->dim[2],sizeof(void *));
    maps->scale  = (double *)mxCalloc(maps->dim[2],sizeof(double));
    maps->offset = (double *)mxCalloc(maps->dim[2],sizeof(double));

    t     = maps->dim[0]*maps->dim[1]*get_datasize(maps->dtype)/8;
    dptr   = (unsigned char *)mxGetPr(ptr);

    for(jj=0; jj<maps->dim[2]; jj++)
    {
        maps->scale[jj]  = 1.0;
        maps->offset[jj] = 0.0;
        maps->data[jj]   = &(dptr[jj*t]);
    }

    maps->addr      = 0;
    maps->len       = 0;

    *n = 1;
    return(maps);
}
block_datastr *blkdev_write_block(UID id,char *data)		
{
	int size;
	char *copy_ptr;
	block_datastr *ret;
	block_datastr *bp;

	char *temp;

	int i=0;

	ret = bp = find_freeblock();	 // get free block pointer
	printf("%x\n", ret);

	size = get_datasize(data); // get size of data
	printf("%d\n", size);

	while(size > 0){
		if(bcb.blocksleft <= 0)
		{
			printf("No have empty block");
			return NULL;
		}
		bp->next = (unsigned int)(bp->next)|(0x1);	// check block to be used
		if(size > BLOCK_SIZE)
		{
			MemCpy(bp->data, data, BLOCK_SIZE);
			bp->next = (unsigned int)(bp->next)|(unsigned int)find_freeblock();
			bp = (unsigned int)(bp->next)&0xFFFFFFFE;
		}
		else
		{
			MemCpy(bp->data, data, size);
		}
		size = size - BLOCK_SIZE;
		bcb.blocksleft--;
	}


	return ret;
}
Exemple #4
0
static void get_map_dat(int i, const mxArray *ptr, MAPTYPE *maps)
{
    mxArray *tmp;
    double *pr;
    int num_dims, j, t, dtype = 0;
    const mwSize *dims;
    unsigned char *dptr;

    tmp=mxGetField(ptr,i,"dat");
    if (tmp == (mxArray *)0)
    {
        free_maps(maps,i);
        mexErrMsgTxt("Cant find dat.");
    }
    if      (mxIsDouble(tmp)) dtype = SPM_DOUBLE;
    else if (mxIsSingle(tmp)) dtype = SPM_FLOAT;
    else if (mxIsInt32 (tmp)) dtype = SPM_SIGNED_INT;
    else if (mxIsUint32(tmp)) dtype = SPM_UNSIGNED_INT;
    else if (mxIsInt16 (tmp)) dtype = SPM_SIGNED_SHORT;
    else if (mxIsUint16(tmp)) dtype = SPM_UNSIGNED_SHORT;
    else if (mxIsInt8  (tmp)) dtype = SPM_SIGNED_CHAR;
    else if (mxIsUint8 (tmp)) dtype = SPM_UNSIGNED_CHAR;
    else
    {
        free_maps(maps,i);
        mexErrMsgTxt("Unknown volume datatype.");
    }
    dptr  = (unsigned char *)mxGetPr(tmp);

    num_dims = mxGetNumberOfDimensions(tmp);
    if (num_dims > 3)
    {
        free_maps(maps,i);
        mexErrMsgTxt("Too many dimensions.");
    }
    dims     = mxGetDimensions(tmp);
    for(j=0; j<num_dims; j++)
        maps[i].dim[j]=dims[j];
    for(j=num_dims; j<3; j++)
        maps[i].dim[j]=1;
    tmp=mxGetField(ptr,i,"dim");
    if (tmp != (mxArray *)0)
    {
        if (mxGetM(tmp)*mxGetN(tmp) != 3)
        {
            free_maps(maps,i);
            mexErrMsgTxt("Wrong sized dim.");
        }
        pr = mxGetPr(tmp);
        if (maps[i].dim[0] != (mwSize)fabs(pr[0]) ||
            maps[i].dim[1] != (mwSize)fabs(pr[1]) ||
            maps[i].dim[2] != (mwSize)fabs(pr[2]))
        {
            free_maps(maps,i);
            mexErrMsgTxt("Incompatible volume dimensions in dim.");
        }
    }
    tmp=mxGetField(ptr,i,"dt");
    if (tmp != (mxArray *)0)
    {
        if (mxGetM(tmp)*mxGetN(tmp) != 1 && mxGetM(tmp)*mxGetN(tmp) != 2)
        {
            free_maps(maps,i);
            mexErrMsgTxt("Wrong sized dt.");
        }
        pr = mxGetPr(tmp);
        if (dtype != (int)fabs(pr[0]))
        {
            free_maps(maps,i);
            mexErrMsgTxt("Incompatible datatype in dt.");
        }
    }

    maps[i].addr      = 0;
    maps[i].len       = 0;
    maps[i].dtype  = dtype;
    maps[i].data   = (void  **)mxCalloc(maps[i].dim[2],sizeof(void *));
    maps[i].scale  = (double *)mxCalloc(maps[i].dim[2],sizeof(double));
    maps[i].offset = (double *)mxCalloc(maps[i].dim[2],sizeof(double));

    t   = maps[i].dim[0]*maps[i].dim[1]*get_datasize(maps[i].dtype)/8;
    tmp = mxGetField(ptr,i,"pinfo");
    if (tmp != (mxArray *)0)
    {
        if ((mxGetM(tmp) != 2 && mxGetM(tmp) != 3) || (mxGetN(tmp) != 1 && mxGetN(tmp) != maps[i].dim[2]))
        {
            free_maps(maps,i+1);
            mexErrMsgTxt("Wrong sized pinfo.");
        }
        if (mxGetM(tmp) == 3 && mxGetPr(tmp)[2] != 0)
        {
            free_maps(maps,i+1);
            mexErrMsgTxt("pinfo(3) must equal 0 to read dat field.");
        }
        pr = mxGetPr(tmp);
        if (mxGetN(tmp) == 1)
            for(j=0; j<maps[i].dim[2]; j++)
            {
                maps[i].scale[j]  = pr[0];
                maps[i].offset[j] = pr[1];
                maps[i].data[j]   = &(dptr[j*t]);
            }
        else
            for(j=0; j<maps[i].dim[2]; j++)
            {
                maps[i].scale[j]  = pr[0+j*2];
                maps[i].offset[j] = pr[1+j*2];
                maps[i].data[j]   = &(dptr[j*t]);
            }
    }
    else
        for(j=0; j<maps[i].dim[2]; j++)
        {
            maps[i].scale[j]  = 1.0;
            maps[i].offset[j] = 0.0;
            maps[i].data[j]   = &(dptr[j*t]);
        }
    tmp=mxGetField(ptr,i,"mat");
    if (tmp != (mxArray *)0)
    {
        if (mxGetM(tmp) != 4 || mxGetN(tmp) != 4)
        {
            free_maps(maps,i+1);
            mexErrMsgTxt("Wrong sized mat.");
        }
        pr = mxGetPr(tmp);
        for(j=0; j<16; j++)
            maps[i].mat[j] = pr[j];
    }
    else
    {
        for(j=0; j<16; j++)
            maps[i].mat[j] = 0.0;
        for(j=0; j<4; j++)
            maps[i].mat[j + j*4] = 1.0;
    }
}
Exemple #5
0
int microcode_sanity_check(void *mc, int print_err)
{
	unsigned long total_size, data_size, ext_table_size;
	struct microcode_header_intel *mc_header = mc;
	struct extended_sigtable *ext_header = NULL;
	int sum, orig_sum, ext_sigcount = 0, i;
	struct extended_signature *ext_sig;

	total_size = get_totalsize(mc_header);
	data_size = get_datasize(mc_header);

	if (data_size + MC_HEADER_SIZE > total_size) {
		if (print_err)
			pr_err("error! Bad data size in microcode data file\n");
		return -EINVAL;
	}

	if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
		if (print_err)
			pr_err("error! Unknown microcode update format\n");
		return -EINVAL;
	}
	ext_table_size = total_size - (MC_HEADER_SIZE + data_size);
	if (ext_table_size) {
		if ((ext_table_size < EXT_HEADER_SIZE)
		 || ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE)) {
			if (print_err)
				pr_err("error! Small exttable size in microcode data file\n");
			return -EINVAL;
		}
		ext_header = mc + MC_HEADER_SIZE + data_size;
		if (ext_table_size != exttable_size(ext_header)) {
			if (print_err)
				pr_err("error! Bad exttable size in microcode data file\n");
			return -EFAULT;
		}
		ext_sigcount = ext_header->count;
	}

	/* check extended table checksum */
	if (ext_table_size) {
		int ext_table_sum = 0;
		int *ext_tablep = (int *)ext_header;

		i = ext_table_size / DWSIZE;
		while (i--)
			ext_table_sum += ext_tablep[i];
		if (ext_table_sum) {
			if (print_err)
				pr_warn("aborting, bad extended signature table checksum\n");
			return -EINVAL;
		}
	}

	/* calculate the checksum */
	orig_sum = 0;
	i = (MC_HEADER_SIZE + data_size) / DWSIZE;
	while (i--)
		orig_sum += ((int *)mc)[i];
	if (orig_sum) {
		if (print_err)
			pr_err("aborting, bad checksum\n");
		return -EINVAL;
	}
	if (!ext_table_size)
		return 0;
	/* check extended signature checksum */
	for (i = 0; i < ext_sigcount; i++) {
		ext_sig = (void *)ext_header + EXT_HEADER_SIZE +
			  EXT_SIGNATURE_SIZE * i;
		sum = orig_sum
			- (mc_header->sig + mc_header->pf + mc_header->cksum)
			+ (ext_sig->sig + ext_sig->pf + ext_sig->cksum);
		if (sum) {
			if (print_err)
				pr_err("aborting, bad checksum\n");
			return -EINVAL;
		}
	}
	return 0;
}
Exemple #6
0
int main(int argc, char **argv)
{
	static char id[] = "$Revision: 1.5 $$Date: 2002/09/10 22:14:51 $";
    char    *invec, *outvec;   /* image vectors */
    int     timePt;
    short   rows = 0;
	short   cols = 0;
    int     slices;
    long    MultImSize;         /* size of one image */
	short   SmallX, SmallY; /* X and Y size of single image from multi-display */
    int     argp=EOF;
    char    *in_fname = NULL;
	char    *out_basename = NULL;
    char    out_fname[128], procfname[128];
    FILE    *imFile;
	FILE    *procFile;
    IMAGE   im;
	short   dSize;
	char    typeString[40];
	OSErr   error = noErr;

	while ( (argp=getopt(argc,argv,"o:i:r:c:h?")) != EOF ) {
		switch( argp )   {
			case 'o': out_basename = optarg; break;
			case 'i': in_fname = optarg; break;
			case 'c': cols = atoi( optarg ); break;
			case 'r': rows = atoi( optarg ); break;
			case 'h':
			case '?':
			default:
				print_usage( argv[0] );
				exit( -1 );
			break;
		}
	}

	if( !out_basename || !in_fname || !rows || !cols ) {
	   print_usage( argv[0] );
	   exit(-1);
	}

	error = UC_Readheader(in_fname, &im);
	if( error ) {
		ILError( error, "Reading Header" );
	}

	switch( im.file_type )
	{
		case BSHORT:
			dSize = get_datasize( T_USHORT );
			sprintf( typeString, "bshort" );
			break;
		case BUCHAR:
			dSize = get_datasize( T_UCHAR );
			sprintf( typeString, "buchar" );
			break;
		case BFLOAT:
			dSize = get_datasize( T_FLOAT );
			sprintf( typeString, "bfloat" );
			break;
		default:
			ILError( DATA_OUT_OF_RANGE, "unknown type" );
	}

/* Parse output file name and create proc file name */
	strcpy( procfname, out_basename );
	
	MultImSize= im.dim.x*im.dim.y;
	SmallX = im.dim.x / cols;
	SmallY = im.dim.y / rows;
	slices = rows * cols;

/*  Buffer allocation  */
	invec =  ( char *)ck_malloc( MultImSize * dSize,  "image vector" );
	outvec = ( char *)ck_malloc( SmallX * SmallY * slices * dSize, "output vector" );

	imFile = errfopen( in_fname, "rb" );

	error = OpenProcFile( argc, argv, procfname, id, &procFile );
	ILError( error, "Opening Proc file" );

	for( timePt = 0; timePt < im.dim.timePts; timePt++ ) {
		int theSlice = 0;

		error = UC_Readimage( imFile, &im, invec, theSlice, timePt );
		if( error ) {
			ILError( error, "Reading image" );
		}

// fool unmdisplay by treating all input as char
		error = unmdisplay( outvec, invec, SmallX * dSize, SmallY, slices, T_UCHAR );
		if( error ) {
			ILError( error, "unmdisplay" );
		}

		if( im.dim.timePts > 1 ) {
			sprintf( out_fname, "%s.%0.3d", out_basename, timePt+1 );
		} else {
			sprintf( out_fname, "%s", out_basename );
		}

		fprintf( procFile, "\tCreated %s.%s\n", out_fname, typeString );

		error = WriteMGHImage( outvec, out_fname, SmallX, SmallY, (short)slices, im.data_type );
		if( error ) {
			ILError( error, "Writing output image" );
		}
	}
	error = ck_fclose( imFile );
	if( error ) ILError( error, "input file" );

	error = ck_fclose( procFile );
	if( error ) ILError( error, "proc file" );

	free( outvec );
	free( invec );

  return 0;
}
Exemple #7
0
/**********************************    T2Fit     ************************************
*   This is where the work will be done
*************************************************************************************/
OSErr T2Fit( FILE *inFile, FILE *outFile )
{
	OSErr   error = noErr;
	long    theTimePt;
	int     i;
	float   *inData, *outData, *T2, *intercept, *chi2, *Smoother;
	long    VolSize, outVolBytes, inVolBytes;
	float	te[ u.inIm.dim.timePts ];
	unsigned char *theMask;
	short   rules;

	u.NumOutImages   = 0;
	VolSize          = u.inIm.dim.isoX * u.inIm.dim.isoY * u.inIm.dim.n_slices;
	inVolBytes       = VolSize * get_datasize( T_FLOAT );
	outVolBytes      = VolSize * get_datasize( u.outIm.data_type );
	T2               = (float *)ck_malloc( inVolBytes,  "Storage for R2" );
	intercept        = (float *)ck_malloc( inVolBytes,  "Storage for intercept" );
	chi2             = (float *)ck_malloc( inVolBytes,  "Storage for chi2"  );
	outData          = (float *)ck_malloc( outVolBytes, "Storage for output data" );
	inData           = (float *)ck_malloc( inVolBytes * u.inIm.dim.timePts,  "Storage for input data" );
	theMask          = (unsigned char*)ck_malloc( VolSize * sizeof( unsigned char ),  "Storage for theMask" );
	if( u.Smooth ) {
		Smoother = (float *)ck_malloc( inVolBytes * 2, "Storage for smoothing" );
	}

// load up te vector
	if( u.Verbose ) {
		printf( "TE: " );
	}
	for( i=0; i<u.inIm.dim.timePts; i++ ) {
		fscanf(u.TEFile ,"%f", &te[i]);
		if( u.Verbose ) {
			printf( "%0.3f ", te[i] );
		}
	}
	
// We will do everything in float
	SetImDatatype( &u.inIm, T_FLOAT );

//	Load all of the images into a single matrix
	for ( theTimePt = 0; theTimePt < u.inIm.dim.timePts; theTimePt++ ) {
		error = GetSelectedVolume( inFile, &u.inIm, inData+theTimePt*VolSize, theTimePt );
		RETURNONERROR;
		if( u.Smooth ) {
			vmov( inData+theTimePt*VolSize, 1, Smoother, 1, VolSize, T_FLOAT );
			error = gaussSmooth( &u.inIm, Smoother, inData+theTimePt*VolSize, &u.xSmooth, &u.ySmooth, &u.zSmooth );
			RETURNONERROR;

		}
		RETURNONERROR;
	}
	

// threshold on first images
	if( u.autoThresh ) {
		error = autoMask( inData, theMask, VolSize, &u.threshold, &u.nonNoise, T_FLOAT );
		RETURNONERROR;
	} else if( u.threshold != 0 ) {
		u.nonNoise = ThreshMask( inData,  theMask, VolSize, &u.threshold, T_FLOAT );
	} else {
		u.nonNoise = VolSize;
	}

	error = CalcT2( &u.inIm, inData, theMask, te, T2, intercept, chi2 ); RETURNONERROR;

	free( inData );

	error = type_convert( T2, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;

	error = type_convert( intercept, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;

	if( u.Smooth ) {
		free( Smoother );
	}

// Make R2 image
	for( i=0; i<VolSize; i++ ) {
		if( T2[i] !=0 ) {
			T2[i] = 1/T2[i];
		}
	}
	error = type_convert( T2, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;
	error = type_convert( chi2, T_FLOAT,
						  outData, u.outIm.data_type,
						  VolSize, &u.outIm.theMinf, &u.outIm.theMaxf, &rules );
	if( error && error != CONVERSION_ERROR ) return error;
	error = ck_fwrite( outData, 1, outVolBytes, outFile );
	u.NumOutImages++;
	RETURNONERROR;

	fprintf( u.ProcFile, "Output file contains maps of T2, M0, R2 and chi2\n" );
	fprintf( u.ProcFile, "TE's used: " );
	for( i=0; i<u.inIm.dim.timePts; i++ ) {
		fprintf( u.ProcFile,  "%0.3f ", te[i] );
	}
	fprintf( u.ProcFile, "\n" );
	fprintf( u.ProcFile, "Input data were intensity thresholded at %0.3f\n", u.threshold ); 
	fprintf( u.ProcFile, "Non-Noise Points:\t%ld\n", u.nonNoise );
	if( u.Smooth ) {
		fprintf( u.ProcFile, "Input images were smoothed with a width of %0.3f mm in x, %0.3f mm in y and %0.3f mm in z\n", 
			u.xSmooth, u.ySmooth, u.zSmooth );
	}
	fprintf( stderr, "Output file contains maps of T2, M0, R2 and chi2\n" );
	fprintf( stderr, "TE's used: " );
	for( i=0; i<u.inIm.dim.timePts; i++ ) {
		fprintf( stderr,  "%0.3f ", te[i] );
	}
	fprintf( stderr, "\n" );
	fprintf( stderr, "Input data were intensity thresholded at %0.3f\n", u.threshold ); 
	fprintf( stderr, "Non-Noise Points:\t%ld\n\n", u.nonNoise );
	if( u.Smooth ) {
		fprintf( stderr, "Input images were smoothed with a width of %0.3f mm in x, %0.3f mm in y and %0.3f mm in z\n", 
			u.xSmooth, u.ySmooth, u.zSmooth );
	}
	free( theMask );
	free( outData );
	free( chi2 );
	free( intercept );
	free( T2 );

	return error;
}