这些天我只想写一些裸机代码来处理MMU,经过几天的努力,我仍然无法使其正常工作。由于我无法使用串行控制台对其进行调试,而且我没有像D-STREAM这样昂贵的调试器,我能做的就是在这里粘贴代码并寻求帮助。 我不想成为水蛭,但我真的不知道我能提供什么进一步的信息。
我的CPU是基于cortex-A8架构的S5PV210 我想做的只是做一个平面内存映射, 这只是意味着"虚拟地址==物理地址"
之后的代码 "ldr pc, =0x30000000\n"
只是闪光LED程序。如果在" enable_mmu"
中对此行发表评论"orr r0, r0, #0x0001\n" /* .... .... .... ...1 Enable MMU */
我的flash led程序运行良好,如果我取消注释,flash led停止工作。 这是整个计划
#define ttl_base 0x2F000000
#define MMU_DES_FULL_ACESS (3<<10)
#define MMU_DES_DOMAIN (0<<5)
#define MMU_DES_EXECUTE_NEVER (0<<4)
#define MMU_DES_CACHEABLE (1<<3)
#define MMU_DES_BUFFERABLE (1<<2)
#define MMU_DES_SECTION (2)
#define MMU_DES_ATTRIBUTE (MMU_DES_SECTION|MMU_DES_BUFFERABLE|MMU_DES_CACHEABLE|MMU_DES_EXECUTE_NEVER|MMU_DES_DOMAIN|MMU_DES_FULL_ACESS)
void init_mmu()
{
//Create Translation Table for a flat map (Vitual Address == Physical Address)
u32 virtualaddr,phyaddr;
u32 *mmu_tlb_base=(u32 *)ttl_base;
virtualaddr = 0x0;
phyaddr = 0x0;
while(1)
{
*(mmu_tlb_base + (virtualaddr>>20)) = (phyaddr & 0xFFF00000) | (MMU_DES_ATTRIBUTE); //map 0x0x30000000-0x30100000 to 0xB0000000-0xB0100000
virtualaddr+=0x100000;
phyaddr+=0x100000;
if (phyaddr==0x00000000)
{
break;
}
}
}
void enable_mmu()
{
__asm__(
"mrc p15, 0, r0, c1, c0, 0\n"
"bic r0, r0, #0x3000\n"
"mcr p15, 0, r0, c1, c0, 0\n" /* Disable Insturection cache */
"mov r0, #0\n"
"mcr p15, 0, r0, c7, c5, 0\n" /*Instruction cache invalidate all*/
"mcr p15, 0, r0, c7, c5, 6\n" /*branch predictor invalidate all*/
"mcr p15, 0, r0, c8, c7, 0\n" /* Invalidate data and instruction TLB */
/*Invalidate entire Data cache*/
/*Start*/
"MRC p15, 1, r0, c0, c0, 0\n" /* Read Cache Size ID */
"LDR r3, =0x1ff\n"
"AND r0, r3, r0, LSR #13\n" /* r0 = no. of sets - 1 */
"MOV r1, #0\n" /* r1 = way counter way_loop */
"way_loop:\n"
"MOV r3, #0\n" /* r3 = set counter set_loop */
"set_loop:\n"
"MOV r2, r1, LSL #30\n" /* */
"ORR r2, r3, LSL #5\n" /* r2 = set/way cache operation format */
"MCR p15, 0, r2, c7, c6, 2\n" /* Invalidate line described by r2 */
"ADD r3, r3, #1\n" /* Increment set counter */
"CMP r0, r3\n" /* Last set reached yet? */
"BGT set_loop\n" /* if not, iterate set_loop */
"ADD r1, r1, #1\n" /* else, next */
"CMP r1, #4\n" /* Last way reached yet? */
"BNE way_loop\n" /* if not, iterate way_loop */
/*End*/
/*Data and Instruction barrier*/
"dsb\n"
"isb\n"
"mov r0, #0\n"
"mcr p15, 0, r0, c2, c0, 2\n" /*Clear L2 Translation Table Entry*/
"mov r4, #0x2F000000\n"
"mcr p15, 0, r4, c2, c0, 0\n" /*Write L1 Translation Table Entry*/
"mvn r0, #0\n"
"mcr p15, 0, r0, c3, c0, 0\n" /*Write 0xFFFFFFFF to Domain Access Register, which means no permission check*/
"mrc p15, 0, r0, c1, c0, 0\n" /* Read SCTLR */
/* .RVI ..RS B... .CAM */
"bic r0, r0, #0x3000\n" /* ..11 .... .... .... Clear bit V、bit I */
"bic r0, r0, #0x0087\n" /* .... .... 1... .111 Clear bit B/C/A/M */
"orr r0, r0, #0x0002\n" /* .... .... .... ..1. Enable Aligment Check */
"orr r0, r0, #0x0004\n" /* .... .... .... .1.. Enable Data Caches */
"orr r0, r0, #0x1000\n" /* ...1 .... .... .... Enable Instruction Caches */
"orr r0, r0, #0x0800\n" /* .... 1... .... .... Enble brach prediction */
"orr r0, r0, #0x0001\n" /* .... .... .... ...1 Enable MMU */
"mcr p15, 0, r0, c1, c0, 0\n" /* Write back to SCTLR */
"ldr sp, =0x3F000000\n"
"ldr pc, =0x30000000\n"
"loop:\n"
"b loop\n"
);
}
答案 0 :(得分:0)
您的页表初始化代码似乎是正确的。但是你需要提供MMU_DES_ATTRIBUTE
。我认为这些属性有问题。