#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
// 1) Only the section table is used.
// 2) The cachable/non-cachable area can be changed by MMT_DEFAULT value.
// The section size is 1MB.
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();//關(guān)閉數(shù)據(jù)Cache
MMU_DisableICache();//關(guān)閉指令Cache
//If write-back is used,the DCache should be cleared.
for(i=0;i<64;i++)//16K的Cache由512條Cache Line組成
for(j=0;j<8;j++)//ARM920T的一個Cache Line是32字節(jié)
MMU_CleanInvalidateDCacheIndex((i<<26)|(j<<5));//清除無效的數(shù)據(jù)cache內(nèi)的列表
MMU_InvalidateICache(); //無效指令cache
#if 0
//To complete MMU_Init() fast, Icache may be turned on here.
MMU_EnableICache();
#endif
MMU_DisableMMU();//關(guān)閉MMU
MMU_InvalidateTLB();//無效整個TLB
//MMU_SetMTT(int vaddrStart,int vaddrEnd,int paddrStart,int attr) 虛擬地址與物理地址映射規(guī)則函數(shù)
MMU_SetMTT(0x00000000,0x07f00000,0x00000000,RW_CNB); //bank0//attr為訪問權(quán)限,頁緩沖等屬性配置
MMU_SetMTT(0x08000000,0x0ff00000,0x08000000,RW_CNB); //bank1//此處皆為平行相等映射
MMU_SetMTT(0x10000000,0x17f00000,0x10000000,RW_NCNB); //bank2
MMU_SetMTT(0x18000000,0x1ff00000,0x18000000,RW_NCNB); //bank3
MMU_SetMTT(0x20000000,0x27f00000,0x20000000,RW_NCNB); //bank4
MMU_SetMTT(0x28000000,0x2ff00000,0x28000000,RW_NCNB); //bank5
MMU_SetMTT(0x30000000,0x30f00000,0x30000000,RW_CB); //bank6-1
MMU_SetMTT(0x31000000,0x33e00000,0x31000000,RW_NCNB); //bank6-2
MMU_SetMTT(0x33f00000,0x33f00000,0x33f00000,RW_CB); //bank6-3
MMU_SetMTT(0x38000000,0x3ff00000,0x38000000,RW_NCNB); //bank7
MMU_SetMTT(0x40000000,0x5af00000,0x40000000,RW_NCNB);//SFR+StepSram
MMU_SetMTT(0x5b000000,0xfff00000,0x5b000000,RW_FAULT);//not used
MMU_SetTTBase(_MMUTT_STARTADDRESS);//設(shè)置基地址:C2用于保存頁表的在內(nèi)存中的基地址,
MMU_SetDomain(0x55555550|DOMAIN1_ATTR|DOMAIN0_ATTR);////MMU將整個存儲空間分成16個域
//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.
}
// attr=RW_CB,RW_CNB,RW_NCNB,RW_FAULT
void ChangeRomCacheStatus(int attr)
{
int i,j;
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();
MMU_DisableMMU();
MMU_InvalidateTLB();
MMU_SetMTT(0x00000000,0x07f00000,0x00000000,attr);//bank0
MMU_SetMTT(0x08000000,0x0ff00000,0x08000000,attr);//bank1
MMU_EnableMMU();
MMU_EnableICache();
MMU_EnableDCache();
}
//void MMU_SetMTT(虛擬地址首地址,虛擬地址末地址,物理地址首地址,相關(guān)屬性)
void MMU_SetMTT(int vaddrStart,int vaddrEnd,int paddrStart,int attr)
{
U32 *pTT;
int i,nSec;
pTT=(U32 *)_MMUTT_STARTADDRESS+(vaddrStart>>20);//基址加VA高12位得到該描述符在頁表中的地址
// 頁表中每一行對應(yīng)一個虛地址頁對應(yīng)的實(shí)地址頁的地址、該位的方位權(quán)限和該頁的緩沖特性
nSec=(vaddrEnd>>20)-(vaddrStart>>20);//段大小
for(i=0;i<=nSec;i++)*pTT++=attr |(((paddrStart>>20)+i)<<20);//映射規(guī)則:在映射頁表中條目中寫上相應(yīng)的要映射的物理地址及相關(guān)屬性。由虛擬地址可以找到在映射頁表中的相應(yīng)條目,再由條目中的內(nèi)容找到相應(yīng)的物理地址。注:條目中的內(nèi)容:高12為物理地址段基址,映射規(guī)則的根本之處;低12位為相應(yīng)的訪問屬性等
}