⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memory.c

📁 ADS下的bios工程
💻 C
字号:
#include <bios/system.h>#include <bios/stdio.h>#include <bios/string.h>#undef DEBUG/* define function prototype */void dump_mem(unsigned long bottom, unsigned long top) ;int March10N32(unsigned int *addr,int unit,unsigned int pattern,int rwdelay) ;int MarchSub1(unsigned int *addr,int unit,unsigned int pattern,int dir,int d) ;/* ---------------------------------------------------- * test memory range */void diag_memory(void){	unsigned int 	*base, *end ;	unsigned int 	unit ;	char 		buff[64] ;	int 		flags = 0;  /* error flag for march error */	printf("\n\n") ;	printf("$ enter start memory address ? 0x") ;	memset(buff,'\0',64) ;	if (gets(buff) == 0)		 sprintf(buff,"0x0") ;        base = (unsigned int *)hexstrtohex(buff, strlen(buff)); 	printf("\n") ;	printf("$ enter end memory address   ? 0x") ;	memset(buff,'\0',64) ;	if (gets(buff) == 0) sprintf(buff,"0x50") ;        end = (unsigned int *)hexstrtohex(buff, strlen(buff)); 	printf("\n") ;	unit = end - base ;	printf("# testing memory ranges are %d word (0x%08x - 0x%08x)\n", unit, (int)base, (int)end) ;	if ( base >= end ) 	{		printf("wrong test memory range requested \n") ;		return ;	}	printf(" * pattern 0x00000000 test -> ") ;        if(March10N32(base,unit,0x00000000,0)) {			printf("Fail !\n") ; flags = 1; 	}	else printf("Ok !\n") ;	printf(" * pattern 0x0000ffff test -> ") ;        if(March10N32(base,unit,0x0000ffff,0)) {			printf("Fail !\n") ; flags = 1; 	}	else printf("Ok !\n") ;	printf(" * pattern 0x00ff00ff test -> ") ;        if(March10N32(base,unit,0x00ff00ff,0)) {			printf("Fail !\n") ; flags = 1; 	}	else printf("Ok !\n") ;	printf(" * pattern 0x0f0f0f0f test -> ") ;        if(March10N32(base,unit,0x0f0f0f0f,0)) {			printf("Fail !\n") ; flags = 1; 	}	else printf("Ok !\n") ;	printf(" * pattern 0x33333333 test -> ") ;        if(March10N32(base,unit,0x33333333,0)) {			printf("Fail !\n") ; flags = 1; 	}	else printf("Ok !\n") ;	printf(" * pattern 0x55555555 test -> ") ;        if(March10N32(base,unit,0x55555555,0)) {			printf("Fail !\n") ; flags = 1; 	}	else printf("Ok !\n") ;        if(flags) {		printf("\n[FAIL] Memory 0x%08x - 0x%08x march test !!!\n",						(int)base, (int)end) ;        }        else {		printf("\n[PASS] Memory 0x%08x - 0x%08x march test !!!\n",						(int)base, (int)end) ;	}}/* ---------------------------------------------------- * dump memory space */void memory_dump(void){	unsigned int	bottom, top ;	char 		buff[64] ;	printf("\n\n") ;	printf("$ enter start memory address ? 0x") ;	memset(buff,'\0',64) ;	if (gets(buff) == 0) sprintf(buff,"0x0") ;        bottom = hexstrtohex(buff, strlen(buff)); 	printf("\n") ;	printf("$ enter end memory address   ? 0x") ;	memset(buff,'\0',64) ;	if (gets(buff) == 0) sprintf(buff,"0x50") ;        top = hexstrtohex(buff, strlen(buff)); 	printf("\n") ;	printf("dump memory range 0x%08x - 0x%08x\n",bottom, top) ;	if ( bottom >= top ) 		printf("wrong memory range dump requested \n") ;	else		dump_mem(bottom, top);}/* ---------------------------------------------------- * Dump out the contents of some memory nicely... */void dump_mem(unsigned long bottom, unsigned long top){        unsigned long p = bottom & ~31;        int i, j=0 ;        for (p = bottom & ~31; p < top;) {                printf("%08lx: ", p);                for (i = 0; i < 8; i++, p += 4) {                        if (p < bottom || p >= top)                                printf("         ");                        else                                printf("%08lx ", *(unsigned long *)p);                        if (i == 3)                                printf(" ");                }                printf ("\n");		if (j++ > 24) 		{			printf("$ press any key for next dump ...\n") ;			getc() ;			j = 0 ;		}        }}/* ---------------------------------------------------- * fill special pattern to memory space */void memory_pattern_fill(void){	unsigned int	bottom, top ;	char 		buff[64] ;	unsigned int	*addr, size ;	printf("\n\n") ;	printf("$ enter start memory address ? 0x") ;	memset(buff,'\0',64) ;	if (gets(buff) == 0) sprintf(buff,"0x0") ;        bottom = hexstrtohex(buff, strlen(buff)); 	printf("\n") ;	printf("$ enter end memory address   ? 0x") ;	memset(buff,'\0',64) ;	if (gets(buff) == 0) sprintf(buff,"0x50") ;        top = hexstrtohex(buff, strlen(buff)); 	printf("\n") ;	size = (top - bottom)/4 ;	printf("fill memory range with address %d word (0x%08x - 0x%08x)\n",								size, bottom, top) ;	if ( bottom >= top ) 		printf("wrong memory range dump requested \n") ;	else	{		addr = (unsigned int *)bottom ;		while(size--)		{			*addr = (unsigned int)addr ;			if ( !((unsigned int)addr % (unsigned int)0x10000) )				printf("Address (%x) => Value (%x)\n",(int)addr,*addr) ;			addr++ ;		}	}}/* ---------------------------------------------------- * seacrh special pattern from memory space */void memory_pattern_search(void){	printf("* seacrh special pattern from memory space\n") ;}/* ---------------------------------------------------- *  Main 10N March Algorithm *  ~~~~~~~~~~~~~~~~~~~~~~~~ *  March10N32(base address, word size, pattern) */int March10N32(unsigned int *addr,int unit,unsigned int pattern,int rwdelay){    int i;    int flag4march = 0; /* error flag for march test */    unsigned int *tempAddr;        tempAddr = addr;         /* Write pattern on memory */    for(i=0;i<unit;i++)    {        *tempAddr++ = pattern;    }       /* Sub Algorithm for Read & Write compare in memory      * _MarchSub1(end or base address,memory word size,pattern,addr dir);      *1 means increment, -1 is decrement address      */     if(MarchSub1(addr,unit,~pattern,1,rwdelay)) flag4march = 1;     if(MarchSub1(addr,unit,pattern,1,rwdelay)) flag4march = 1;     if(MarchSub1(addr+unit-1,unit,~pattern,-1,rwdelay)) flag4march = 1;     if(MarchSub1(addr+unit-1,unit,pattern,-1,rwdelay)) flag4march = 1;               tempAddr = addr;    /* Read & test memory */    for(i=0;i<unit;i++)    {        if(*tempAddr != pattern){             printf("\n[ERROR 1] [0x%08x]=0x%08x:0x%08x",(int)tempAddr,*tempAddr,pattern);             flag4march = 1;        }        tempAddr++;    }    return(flag4march);  //return error code}/* ---------------------------------------------------- *  This function is parts of 10N march Algorithms *  Memory  read[pattern] & write[~pattern] or  *          read[~pattern] & write[~pattern]  *  on increment or decrement address. * *  MarchSub1(base or end address, word size, pattern, address direction) */int MarchSub1(unsigned int *addr,int unit,unsigned int pattern,int dir,int d){    unsigned int i;    unsigned int j =0;    unsigned int flag4march = 0;    unsigned int rdata;    unsigned int *tempAddr;    tempAddr = addr;    for(i=0;i<unit;i++)    {        j++;         j++;         rdata = *addr;     /* read memory data */        *addr = pattern;   /* write data pattern */                if(rdata!=(~pattern)) {             printf("\n[ERROR 2] [0x%08x]=0x%08x:0x%08x", (int)addr,*addr,~pattern);             flag4march =1; /*  set flag for error */        }        addr += dir;    }    return(flag4march); /*  return error code */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -