arm9之mmu-九游会j9

单片机 > 单片机程序设计 > 详情

arm9之mmu_init()

发布时间:2025-07-16 发布时间:
|

#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();//关闭数据cache
    mmu_disableicache();//关闭指令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字节
         mmu_cleaninvalidatedcacheindex((i<<26)|(j<<5));//清除无效的数据cache内的列表
    mmu_invalidateicache();  //无效指令cache
    
    #if 0
    //to complete mmu_init() fast, icache may be turned on here.
    mmu_enableicache(); 
    #endif
    
    mmu_disablemmu();  //关闭mmu
    mmu_invalidatetlb();   //无效整个tlb

    //mmu_setmtt(int vaddrstart,int vaddrend,int paddrstart,int attr) 虚拟地址与物理地址映射规则函数
    mmu_setmtt(0x00000000,0x07f00000,0x00000000,rw_cnb);  //bank0 //attr为访问权限,页缓冲等属性配置
    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);   //设置基地址:c2用于保存页表的在内存中的基地址,
    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(虚拟地址首地址,虚拟地址末地址,物理地址首地址,相关属性)

void mmu_setmtt(int vaddrstart,int vaddrend,int paddrstart,int attr)
{
    u32 *ptt;
    int i,nsec;      
    ptt=(u32 *)_mmutt_startaddress (vaddrstart>>20);//基址加va高12位得到该描述符在页表中的地址
                                  // 页表中每一行对应一个虚地址页对应的实地址页的地址、该位的方位权限和该页的缓冲特性
    nsec=(vaddrend>>20)-(vaddrstart>>20);//段大小
    for(i=0;i<=nsec;i )*ptt =attr |(((paddrstart>>20) i)<<20);//映射规则:在映射页表中条目中写上相应的要映射的物理地址及相关属性。由虚拟地址可以找到在映射页表中的相应条目,再由条目中的内容找到相应的物理地址。注:条目中的内容:高12为物理地址段基址,映射规则的根本之处;低12位为相应的访问属性等
}


关键字:arm9  mmu

『本文转载自网络,九游会j9的版权归原作者所有,如有侵权请联系删除』

热门文章 更多
stm32cubemx新建工程 基本io配置过程
网站地图