本文引用地址://m.amcfsurvey.com/article/201611/322695.htmvirtuladdr = 0xA0000000;
physicaladdr = 0x56000000;
*(mmu_tlb_base + (virtuladdr >> 20)) = (physicaladdr & 0xFFF00000) |
MMU_SECDESC;
virtuladdr = 0xB0000000;
physicaladdr = 0x30000000;
while (virtuladdr < 0xB4000000)
{
*(mmu_tlb_base + (virtuladdr >> 20)) = (physicaladdr & 0xFFF00000) |
MMU_SECDESC_WB;
virtuladdr += 0x100000;//右移20位就是1
physicaladdr += 0x100000;//右移20位就是1
}
}
void mmu_init(void)
{
unsigned long ttb = 0x30000000;
__asm__(
"movr0, #0"
"mcrp15, 0, r0, c7, c7, 0"
"mcrp15, 0, r0, c7, c10, 4"
"mcrp15, 0, r0, c8, c7, 0"
"movr4, %0"
"mcrp15, 0, r4, c2, c0, 0"
"mvnr0, #0"
"mcrp15, 0, r0, c3, c0, 0"
"mrcp15, 0, r0, c1, c0, 0"
"bicr0, r0, #0x3000"
"bicr0, r0, #0x0300"
"bicr0, r0, #0x0087"
"orrr0, r0, #0x0002"
"orrr0, r0, #0x0004"
"orrr0, r0, #0x1000"
"orrr0, r0, #0x0001"
"mcrp15, 0, r0, c1, c0, 0"
:
: "r" (ttb) );
}
#define GPBCON(*(volatile unsigned long *)0xA0000010)// 物理地址0x56000010
#define GPBDAT(*(volatile unsigned long *)0xA0000014)// 物理地址0x56000014
#define GPB5_out(1<<(5*2))
#define GPB6_out(1<<(6*2))
#define GPB7_out(1<<(7*2))
#define GPB8_out(1<<(8*2))
static inline void wait(unsigned long dly)
{
for(; dly > 0; dly--);
}
int main(void)
{
unsigned long i = 0;
// 将LED1-4对应的GPB5/6/7/8四个引脚设为输出
GPBCON = GPB5_out|GPB6_out|GPB7_out|GPB8_out;
while(1){
wait(30000);
GPBDAT = (~(i<<5));// 根据i的值,点亮LED1-4
if(++i == 16)
i = 0;
}
return 0;
}
最后是Makefile
objs := head.o init.o leds.o
mmu.bin : $(objs)
arm-linux-ld -Tmmu.lds -o mmu_elf $^
arm-linux-objcopy -O binary -S mmu_elf $@
arm-linux-objdump -D -m arm mmu_elf > mmu.dis
%.o:%.c
arm-linux-gcc -Wall -O2 -c -o $@ $<
%.o:%.S
arm-linux-gcc -Wall -O2 -c -o $@ $<
clean:
rm -f mmu.bin mmu_elf mmu.dis *.o
评论