📄 memory.c
字号:
while(hcnt--) { *DstAddr++ = *SrcAddr++; }// PrintRotSlash(hnum++); // print progress indicator if(kbd_hit()) { U8 it; it = get_byte(); if(it == KEY_ESC) { return(-1); // bcopy skiped } } }// return(1); }////////////////////////////////////////////////////////////////////////////////// Byte Compare Function ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int bcomp(void *src, void *dst, int words, int hash){ U8 * SrcAddr; U8 * DstAddr; int cnt; int hnum; // progress indicator SrcAddr = (U8 *) src; /* byte pointer to source */ DstAddr = (U8 *) dst; /* byte pointer to destination */ cnt = words * 4; /* byte count */ if(hash <= 0) {// no print progress indicator ///////////////////////////////////////////////// while(cnt--) { if(*DstAddr != *SrcAddr) { Print("\nMemory Byte Test Error") ; Print("\nSource Data is %02x at Addr %08x",*SrcAddr,SrcAddr); Print("\nDestin Data is %02x at Addr %08x",*DstAddr,DstAddr); return(0); } DstAddr++; SrcAddr++; }// return(1); } hnum = 0; while(cnt > 0) { int hcnt; // if(cnt > hash) { hcnt = hash; } else { hcnt = cnt; } cnt -= hcnt; // remain half word copy while(hcnt--) { if(*DstAddr != *SrcAddr) { Print("\nMemory Byte Test Error") ; Print("\nSource Data is %02x at Addr %08x",*SrcAddr,SrcAddr) ; Print("\nDestin Data is %02x at Addr %08x",*DstAddr,DstAddr) ; return(0); } DstAddr++; SrcAddr++; }// PrintRotSlash(hnum++); // print progress indicator if(kbd_hit()) { U8 it; it = get_byte(); if(it == KEY_ESC) { return(-1); // bcopy skiped } } } return(1);}////////////////////////////////////////////////////////////////////////////////// Half Word Compare Function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int scomp(void *src, void *dst, int words, int hash){ U16 *SrcAddr; U16 *DstAddr; int cnt; int hnum; SrcAddr = (U16 *)src; /* half word pointer to source */ DstAddr = (U16 *)dst; /* half word pointer to destination */ cnt = words * 2; /* half word count */ if(hash <= 0) {// no print prgress indicator ////////////////////////////////////////////////// while(cnt--) { if( *DstAddr != *SrcAddr ) { Print("\nMemory Short Test Error") ; Print("\nSource Data is %04x at Addr %08x",*SrcAddr,SrcAddr); Print("\nDestin Data is %04x at Addr %08x",*DstAddr,DstAddr); return(0); } DstAddr++; SrcAddr++; }// return(1); } hnum = 0; while(cnt > 0) { int hcnt; // if(cnt > hash) { hcnt = hash; } // else { hcnt = cnt; } // cnt -= hcnt; // remain half word copy while(hcnt--) { if( *DstAddr != *SrcAddr) { Print("\nMemory Short Test Error") ; Print("\nSource Data is %04x at Addr %08x",*SrcAddr,SrcAddr) ; Print("\nDestin Data is %04x at Addr %08x",*DstAddr,DstAddr) ; return(0); } DstAddr++; SrcAddr++; }// PrintRotSlash(hnum++); // print progress indicator if(kbd_hit()) { U8 it; it = get_byte(); if(it == KEY_ESC) { return(-1); // bcopy skiped } } } return(1);}////////////////////////////////////////////////////////////////////////////////// Word Compare Function ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int wcomp(void *src, void *dst, int words, int hash){ U32 *SrcAddr; U32 *DstAddr; int cnt ; int hnum; SrcAddr = (U32 *) src; /* word pointer to source */ DstAddr = (U32 *) dst; /* word pointer to destination */ cnt = words; /* word count */ if(hash == 0) {// no print progress indicator ///////////////////////////////////////////////// while(cnt--) { if ( *DstAddr != *SrcAddr ) { Print("\nMemory Long Test Error") ; Print("\nSource Data is %08x at Addr %08x",*SrcAddr, SrcAddr); Print("\nDestin Data is %08x at Addr %08x",*DstAddr, DstAddr); return(0); } DstAddr++; SrcAddr++; }// return(1); } hnum = 0; while(cnt) { int hcnt; // if(cnt > hash) { hcnt = hash; } else { hcnt = cnt; } cnt -= hcnt; // remain half word copy while(hcnt--) { if ( *DstAddr != *SrcAddr ) { Print("\nMemory Long Test Error") ; Print("\nSource Data is %08x at Addr %08x",*SrcAddr, SrcAddr) ; Print("\nDestin Data is %08x at Addr %08x",*DstAddr, DstAddr) ; return(0); } DstAddr++; SrcAddr++; }// PrintRotSlash(hnum++); // print progress indicator if(kbd_hit()) { U8 it; it = get_byte(); if(it == KEY_ESC) { return(-1); // bcopy skiped } } }// return(1);}int PatternGen(unsigned int seed){#ifdef NO_HAVE_RAND static int rand_todo = 0; if((seed%0x100) == 0) { rand_todo = seed; } seed = (((rand_todo << 11) | (rand_todo >> 21)) + seed); rand_todo = ~seed + 1; return(rand_todo); #else if((seed%0x100) == 0) { srand(seed); }// return(rand());#endif }#ifdef NO_HAVE_MEMCPYvoid memcpy(void * dst, void *src, int cnt) { int pos; for(pos = 0; pos < cnt; ++pos) { *((char *) dst + pos) = *((char *) src + pos); }}#endif /* Initialize Memory Test, Test Pattern Generation *//* src = source address *//* tsize = memory size in words */static int MemTestInit(U32 *src, int words, int hash){ U32 * addr; int cnt; int pat; int hnum; addr = src; /* source address */ cnt = words; /* source size in words */ pat = 0; /* start parameter for PatternGen */ if(hash <= 0) {// no pring progress indicator ///////////////////////////////////////////////// while(cnt--) { *addr++ = (U32) PatternGen(pat++); }// return(1); }// hnum = 0; while(cnt) { int hcnt; if(cnt > hash) { hcnt = hash; } // else { hcnt = cnt; } // cnt -= hcnt; // remain fill words while(hcnt--) { * addr++ = (U32) PatternGen(pat++); }// PrintRotSlash(hnum++); // print fill progress if(kbd_hit()) { U8 it; it = get_byte(); if(it == KEY_ESC) { return(-1); // bcopy skiped } } }// return(1); }////////////////////////////////////////////////////////////////////////////////// Print Memory Test Status ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void PrintRotSlash(int j){ static int i = -1; j &= 0x3; if(i != j) { i = j; if (j == 0) put_byte('/'); else if (j == 1) put_byte('-'); else if (j == 2) put_byte('\\'); else put_byte('|'); put_byte('\b'); }}////////////////////////////////////////////////////////////////////////////////// Memory word, halfword, byte copy & Compare test ////////////////////////////////////////////////////////////////////////////////////////////////////////////int MemTest(U32 * src, U32 * dst, int tsize, int lsize, int hash){ int rvl; int i; int j;/* Word Test */ Print("\n Memory Test (Long)...."); for(i = 0; i < lsize; ++i) /* loop */ { for(j = 0; j < 4; ++j) {// init source area //////////////////////////////////////////////////////////// if(MemTestInit(src, tsize, hash) == -1) { return(-1); // ESC pressed }// word copy /////////////////////////////////////////////////////////////////// if(wcopy(src, dst, tsize, hash) == -1) { // skipped test return(-1); // ESC pressed } // word compare //////////////////////////////////////////////////////////////// rvl = wcomp(src, dst, tsize, hash); if(rvl == -1) { // compare skipped return(-1); // ESC pressed } else if(rvl == 0) { Print("Fail."); /* word test failure */ return(0); }// if(hash > 0) { break; } else { PrintRotSlash(j++); } } } Print("Ok.") ;/* Half Word Test */ Print("\n Memory Test (Short) ..") ; for (i=0; i < lsize; i++) { for(j = 0; j < 4; ++j) {// init source area //////////////////////////////////////////////////////////// if(MemTestInit(src, tsize, hash) == -1) { // init source area return(-1); // skipped } // half word copy soure to destination ///////////////////////////////////////// if(scopy(src, dst, tsize, hash) == -1) { return(-1); // ESC pressed }// half word compare source and destination //////////////////////////////////// rvl = scomp(src, dst, tsize, hash); if(rvl == -1) { return(-1); // ESC pressed } else if(rvl == 0) { Print("Fail."); return(0); }// if(hash > 0) { break; } else { PrintRotSlash(j); } } } Print("Ok.");/* Byte Test */ Print("\n Memory Test (Byte) ...") ; for (i=0 ; i < lsize ; i++) { for(j = 0; j < 4; ++j) {// init source area //////////////////////////////////////////////////////////// if(MemTestInit(src, tsize, hash) == -1) { return(-1); } // byte copy source to destination ///////////////////////////////////////////// if(bcopy(src, dst, tsize, hash) == -1) { return(-1); } // byte compare source and destination ///////////////////////////////////////// rvl = bcomp(src, dst, tsize, hash); if(rvl == -1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -