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

📄 memory.c

📁 本source code 為s3c4510的bootloader
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    n++;  }   // *size = un;  return(1);}////////////////////////////////////////////////////////////////////////////////// check memory region ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// saddr    = start address// eaddr    = end address (first byte that not included int tested memory region) // dramonly = static int MemAddrCheck(U32 * saddr, U32 * eaddr, int dramonly) { U32 start;				// test region start address U32 end; 				// test region end address//  U32 base[10];				// ROM/RAM bank base address  U32 limit[10];				// ROM/RAM bank next address U32 src[10];				// base/limit source int cnt; int i; cnt = 10; if(MemRegions(base, limit, src, & cnt, dramonly) == 0)   {   return(0);  }//  start = (U32) (saddr);			// tested region start address end   = (U32) (eaddr); 		// tested region end address  for(i = 0; i < cnt; ++i)  {   if(start >= base[i] && end <= limit[i])    {// start & end address in continuous memory region /////////////////////////////     return(1);    }   } // Print  (  "\nMemory from 0x%08x to 0x%08x out of configured memory" ,     saddr,      eaddr  ); // print configured memory regions ///////////////////////////////////////////// for(i = 0; i < cnt; ++i)  {   Print("\n  0x%08x 0x%08x", base[i], limit[i]);   if((src[i] & MemAddrCheck_ROMCON0 ) != 0) { Print("  ROMCON0"); }   if((src[i] & MemAddrCheck_ROMCON1 ) != 0) { Print("  ROMCON1"); }   if((src[i] & MemAddrCheck_ROMCON2 ) != 0) { Print("  ROMCON2"); }   if((src[i] & MemAddrCheck_ROMCON3 ) != 0) { Print("  ROMCON3"); }   if((src[i] & MemAddrCheck_ROMCON4 ) != 0) { Print("  ROMCON4"); }   if((src[i] & MemAddrCheck_ROMCON5 ) != 0) { Print("  ROMCON5"); }   if((src[i] & MemAddrCheck_DRAMCON0) != 0) { Print(" DRAMCON0"); }   if((src[i] & MemAddrCheck_DRAMCON1) != 0) { Print(" DRAMCON1"); }   if((src[i] & MemAddrCheck_DRAMCON2) != 0) { Print(" DRAMCON2"); }   if((src[i] & MemAddrCheck_DRAMCON3) != 0) { Print(" DRAMCON3"); }  }//  Print("\n"); return(0); }////////////////////////////////////////////////////////////////////////////////// Memory dump program /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void MemDump(U32 * base, U32 * end){ int cnt;				// words count int row;				// current row  int i;					// start word in row  int j;					// word index in row //  cnt = end - base;			// words count  row = 0; 				// init current row  j = 0;					//  for(i=0; i < cnt + 4; i+= j)  {   if(row == 20)     {     U8 it;     Print("\nPress Any Key");      it = get_byte();     if(it == 'Q' || it == 'q')      {       return;      }      row = 0;    }   else     {      row++;         Print("\n%08x : ", base);     for(j = 0; j < 4 ; ++j)      {//        U8 * ptr;       int bn;       ptr = (U8 *) base;       for(bn = 0; bn < 4; ++bn)        {          Print("%02x", *ptr);         ptr++;        } //        Print(" ");       base++;      }    }  } }////////////////////////////////////////////////////////////////////////////////// Memory Dump top function ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void MemoryDump(void){ U32   dramcon0;			// Dram bank 0 address from DRAMCON0 U32   addr;				// dump memory address U32   size;				// dump memory size U32 * base;  				// Dump Memory base address U32 * end;   				// Dump Memory end address/* [19:10]  DRAM bank # base pointer 					      *//*          This value indicates the start address of DRAM bank #. 	      *//*          The start address is calculated as RAM bank # base pointer << 16  */ dramcon0 = ( (DRAMCON0 >> 10) & 0x3FF ) << 16;//     Print("\nInput Memory Dump Base Address (0x%08x) : 0x", dramcon0);	 addr = get_number(16,0); if(addr == 0)   {					/* default start dump address */     addr = dramcon0;  } Print("\nInput Memory Dump Size (0x100)              : 0x") ;	 size = get_number(16,0); if(size == 0)   {   size=0x100;  }//  base = (U32 *) addr;			// base address end  = (U32 *)(addr + size);		// end address if(MemAddrCheck(base,end,0) == 0)  {// memory Region out of configured memory //////////////////////////////////////   U8 ch;   Print("\nContinue dump [Y/N]_");   ch = get_upper();    if(ch != 'Y')    {      return;    }   } Print("\nMemory Dump from %x to %x",base, end) ; MemDump(base, end);}////////////////////////////////////////////////////////////////////////////////// Memory Pattern Fill /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static void MemPatternFill(void) { U32 * start;				// start address  U32 * end;				// end address U32 pat;				// pattern  int cnt;				// words count  U8 ch;	//  Print("\nMemory Pattern Fill"); Print("\nMemory Pattern Fill Start Address : 0x"); start = (U32 *) get_number(16,0);//   Print("\nMemory Pattern Fill End Address   : 0x"); end   = (U32 *) get_number(16,0);//   Print("\nMemor Fill Pattern (word)         : 0x"); pat   = get_number(16,0); cnt = (int)(end - start); if(cnt < 0)  {					// start address >   return;				// end address  }  if(MemAddrCheck(start,end,0) == 0)  {// memory Region out of configured memory //////////////////////////////////////   Print    (     "\nMemory region 0x%08x 0x%08x out of configured memory"	,       start	,			// start address        end				// end address    );  } Print  (   "\nMemory Fill %08x to %08x, Pattern : %08x [Y/N]_",//    start	, 			//    end		, 			//    pat					//   ); ch = get_upper(); if(ch == 'Y')  {   while( cnt-- )     {     *start++ = pat;    }  }}////////////////////////////////////////////////////////////////////////////////// Memory Pattern Search ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static void MemPatternSearch(void){ U32 * start; U32 * end; U32 pat; int cnt; Print("\nMemory Pattern Search"); Print("\nMemory Pattern Search Start Address : 0x");	 start = (U32 *)get_number(16,0);  Print("\nMemory Pattern Search End Address   : 0x");	 end = (U32 *)get_number(16,0);  Print("\nMemory Search Pattern (word)        : 0x");	 pat = get_number(16,0); cnt = (int)( end - start ); if(MemAddrCheck(start,end,0) == 0)  {   U8 ch;   Print("\nContinue Search [Y/N]_");   ch = get_upper();    if(ch != 'Y')    {     return;    }   } Print  (   "\nMemory Pattern Search 0x%08x to 0x%08x, Pattern : %08x\n",    start	,     end		,    pat  ); while(cnt--)   {   if( *start == pat )     {     Print      (       "\nPattern is Searched : 0x%08x (0x%08x)",         start	, 			// address         *start				// pattern       );//      if(kbd_hit())      {       U8 it;       it = get_byte();       if(it == KEY_ESC)        {         return;        }       }    }   start++;  }}////////////////////////////////////////////////////////////////////////////////// Byte Copy Function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int bcopy(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 ///////////////////////////////////////////////////////////   while(cnt--)    {     *DstAddr++ = *SrcAddr++ ;    }//   return(1);  }//  hnum = 0; while(cnt > 0)  {   int hcnt;   if(cnt > hash) { hcnt = hash; }   else           { hcnt = cnt;  }       cnt -= hcnt;				// remain copy bytes   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);}////////////////////////////////////////////////////////////////////////////////// Half Word Copy Function /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int scopy(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 half word copy progress ////////////////////////////////////////////   while(cnt--)    {     *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--)    {     *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 Copy Function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int wcopy(void *src, void *dst, int words, int hash){ U32 *SrcAddr;  U32 *DstAddr; int cnt; int hnum;				// progress indicator 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--)    {     *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

⌨️ 快捷键说明

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