ADS下bootloader之MMU研究
如下是ADS下的boot的MMU.c的MMU初始化代碼。在2440init.S中跳入Main,這個(gè)Main函數(shù)在U2440mom.c中實(shí)現(xiàn),這個(gè)Main函數(shù)包括了對(duì)端口,中斷服務(wù),MMU,VGA等的初始化函數(shù)的調(diào)用。MMU.c中進(jìn)行了MMU的初始化,其中調(diào)用了很多初始化函數(shù),使用匯編寫的,確切的說是用協(xié)處理指令寫的。這些函數(shù)的聲明部分在2440slib.h,實(shí)現(xiàn)在2440slib.c中。在MMU的初始化程序MMU_Init中,首先禁止了Dcache,Icache,清除了Dcache和Icache。禁止了MMU,TLB。然后對(duì)存儲(chǔ)系統(tǒng)進(jìn)行了虛擬地址到物理地址的映射。然后設(shè)置了轉(zhuǎn)化表的基地址,設(shè)置了域,開啟了MMU,Icache,Dcache。
void MMU_Init(void)
{
int i,j;
//========================== IMPORTANT NOTE =========================
//The current stack and code area can't be re-mapped in this routine.
//If you want memory map mapped freely, your own sophiscated MMU
//initialization code is needed.
//===================================================================
MMU_DisableDCache();
MMU_DisableICache();
//If write-back is used,the DCache should be cleared.
for(i=0;i<64;i++)
for(j=0;j<8;j++)
MMU_CleanInvalidateDCacheIndex((i<<26)|(j<<5));
MMU_InvalidateICache();
#if 0
//To complete MMU_Init() fast, Icache may be turned on here.
MMU_EnableICache();
#endif
MMU_DisableMMU();
MMU_InvalidateTLB();
//MMU_SetMTT(int vaddrStart,int vaddrEnd,int paddrStart,int attr)
//MMU_SetMTT(0x00000000,0x07f00000,0x00000000,RW_CNB); //bank0
if(rBWSCON&0x6)//nor啟動(dòng)
MMU_SetMTT(0x00000000,0x07f00000,0x00000000,RW_NCNB); //bank0
else//nand 啟動(dòng)
MMU_SetMTT(0x00000000,0x00001000,0/*(int)__ENTRY*/,RW_CB); //bank0
//MMU_SetMTT(0x04000000,0x07f00000,0,RW_NCNB); //bank0
MMU_SetMTT(0x08000000,0x0ff00000,0x08000000,RW_NCNB); //bank1
MMU_SetMTT(0x10000000,0x17f00000,0x10000000,RW_NCNB); //bank2
MMU_SetMTT(0x18000000,0x1ff00000,0x18000000,RW_NCNB); //bank3
//MMU_SetMTT(0x20000000,0x27f00000,0x20000000,RW_CB); //bank4
MMU_SetMTT(0x20000000,0x27f00000,0x20000000,RW_NCNB); //bank4 for STRATA Flash
MMU_SetMTT(0x28000000,0x2ff00000,0x28000000,RW_NCNB); //bank5
MMU_SetMTT(0x30000000,0x30100000,0x30000000,RW_CB); //bank6-1 1
MMU_SetMTT(0x30200000,0x33e00000,0x30200000,RW_NCNB); //bank6-2 60
//
MMU_SetMTT(0x33f00000,0x33f00000,0x33f00000,RW_CB); //bank6-3
MMU_SetMTT(0x38000000,0x3ff00000,0x38000000,RW_NCNB); //bank7
MMU_SetMTT(0x40000000,0x47f00000,0x40000000,RW_NCNB); //SFR 127
MMU_SetMTT(0x48000000,0x5af00000,0x48000000,RW_NCNB); //SFR 303
MMU_SetMTT(0x5b000000,0x5b000000,0x5b000000,RW_NCNB); //SFR
MMU_SetMTT(0x5b100000,0xfff00000,0x5b100000,RW_FAULT);//not used
MMU_SetTTBase(_MMUTT_STARTADDRESS);
MMU_SetDomain(0x55555550|DOMAIN1_ATTR|DOMAIN0_ATTR);
//DOMAIN1: no_access, DOMAIN0,2"15=client(AP is checked)
MMU_SetProcessId(0x0);
MMU_EnableAlignFault();
MMU_EnableMMU();
MMU_EnableICache();
MMU_EnableDCache(); //DCache should be turned on after MMU is turned on.
}
for(i=0;i<64;i++)
for(j=0;j<8;j++)
MMU_CleanInvalidateDCacheIndex((i<<26)|(j<<5));
MMU_InvalidateICache();
這里是因?yàn)锳RM920T有64路,每路有8個(gè)組。所以。。。為什么要i<<26,j<<5呢,看下圖便知
[!--empirenews.page--]
這是一個(gè)MMU的虛擬地址向物理地址映射的函數(shù)。通過上邊的調(diào)用可以看到物理地址和虛擬地址的地址是相同的,那為什么還要開MMU呢,不是多此一舉嗎,Dcache的開啟必須在MMU開啟后才能開啟,Icache不受MMU影響。開啟Cache對(duì)系統(tǒng)性能會(huì)有很大提升。所以,哈哈。這里_MMUTT_STARTADDRESS是轉(zhuǎn)換表的基址,因?yàn)闆]有使用復(fù)雜的操作系統(tǒng),所以只使用了一級(jí)頁表,每個(gè)頁表項(xiàng)對(duì)應(yīng)的是一個(gè)1MB的段。pTT=(U32 *)_MMUTT_STARTADDRESS+(vaddrStart>>20);相當(dāng)于獲得相應(yīng)的頁表項(xiàng)??匆幌孪聢D就會(huì)明白。nSec=(vaddrEnd>>20)-(vaddrStart>>20);這句是計(jì)算有幾個(gè)段。for(i=0;i<=nSec;i++)*pTT++=attr |(((paddrStart>>20)+i)<<20);分別映射每段。Attr是域。
void MMU_SetMTT(int vaddrStart,int vaddrEnd,int paddrStart,int attr)
{
volatile U32 *pTT;
volatile int i,nSec;
pTT=(U32 *)_MMUTT_STARTADDRESS+(vaddrStart>>20);
nSec=(vaddrEnd>>20)-(vaddrStart>>20);
for(i=0;i<=nSec;i++)*pTT++=attr |(((paddrStart>>20)+i)<<20);
}
這里就不列出那些被調(diào)用的匯編代碼,這個(gè)是飛凌的boot,網(wǎng)上好多人說沒開MMU,真是誤人子弟啊。