1
0

mmu: Add initial implementation of identity mapping

This commit is contained in:
Aaron Lindsay 2012-09-21 11:52:24 -04:00
parent ae45deb789
commit ab29c2c442
6 changed files with 82 additions and 7 deletions

View File

@ -9,9 +9,43 @@ interrupt_vector_table:
b . b .
.comm stack, 0x10000 @ Reserve 64k stack in the BSS .comm stack, 0x10000 @ Reserve 64k stack in the BSS
_start: .globl start
.globl _start
start:
ldr r0, tt_base
mcr p15, 0, r0, c2, c0, 0 /* TTBR0 */
/* Setup page table entries for the page table and kernel (domain 0) */
ldr r0, tt_tt_addr
ldr r1, tt_tt_val
str r1, [r0]
ldr r0, kernel_tt_addr
ldr r1, kernel_tt_val
str r1, [r0]
/* Set access permissions for domain 0 to "Manager" */
mov r0, #0x3
mcr p15, 0, r0, c3, c0, 0 /* DACR */
/* Enable the MMU */
mrc p15, 0, r0, c1, c0, 0 /* SCTLR */
orr r0, r0, #0x1
mcr p15, 0, r0, c1, c0, 0 /* SCTLR */
ldr sp, =stack+0x10000 @ Set up the stack ldr sp, =stack+0x10000 @ Set up the stack
bl main @ Jump to the main function bl main @ Jump to the main function
1: 1:
b 1b @ Halt b 1b @ Halt
tt_base:
.word 0x80000000
tt_tt_addr:
.word 0x80002000
tt_tt_val:
.word 0x80000c02 /* ...c02 means read/write at any priviledge level, and that it's a section w/o PXN bit set */
kernel_tt_addr:
.word 0x80002004
kernel_tt_val:
.word 0x80100c02

6
include/mmu.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef MMU_H
#define MMU_H
void mmu_reinit();
#endif /* MMU_H */

View File

@ -5,5 +5,6 @@ KOBJS += $(KERNEL_PREFIX)/font.o
KOBJS += $(KERNEL_PREFIX)/framebuffer.o KOBJS += $(KERNEL_PREFIX)/framebuffer.o
KOBJS += $(KERNEL_PREFIX)/list.o KOBJS += $(KERNEL_PREFIX)/list.o
KOBJS += $(KERNEL_PREFIX)/mm.o KOBJS += $(KERNEL_PREFIX)/mm.o
KOBJS += $(KERNEL_PREFIX)/mmu.o
KOBJS += $(KERNEL_PREFIX)/print.o KOBJS += $(KERNEL_PREFIX)/print.o
KOBJS += $(KERNEL_PREFIX)/start_kernel.o KOBJS += $(KERNEL_PREFIX)/start_kernel.o

29
kernel/mmu.c Normal file
View File

@ -0,0 +1,29 @@
#include <print.h>
#define SCTLR 15,0,1,0,0
#define TTBR0 15,0,2,0,0
#define TTBR1 15,0,2,0,1
#define TTBCR 15,0,2,0,2
#define _cp_read(var, cp, opc1, CRn, CRm, opc2) asm("mrc p" #cp ", " #opc1 ", %0, c" #CRn ", c" #CRm ", " #opc2 ";" : "=r"(var) : )
#define _cp_write(var, cp, opc1, CRn, CRm, opc2) asm("mcr p" #cp ", " #opc1 ", %0, c" #CRn ", c" #CRm ", " #opc2 ";" : : "r"(var) )
#define cp_read(var, ...) _cp_read(var, __VA_ARGS__)
#define cp_write(var, ...) _cp_write(var, __VA_ARGS__)
void mmu_reinit() {
unsigned int *curr_tt_entry;
unsigned int curr_addr;
//get the current translation table base address
cp_read(curr_tt_entry, TTBR0);
//do first loop iteration outside the loop, because we have to check against wrapping back around to know we're done
*curr_tt_entry = 0xc02;
curr_tt_entry++;
//create identity mapping for entire address space using sections
for (curr_addr = 0x00100000; curr_addr != 0; curr_addr += 0x00100000) {
*curr_tt_entry = curr_addr | 0xc02;
curr_tt_entry++;
}
}

View File

@ -1,3 +1,4 @@
#include <mmu.h>
#include <mm.h> #include <mm.h>
#include <print.h> #include <print.h>
#include <devices/pl011.h> #include <devices/pl011.h>
@ -54,6 +55,10 @@ void test_memory() {
int main(void) { int main(void) {
char *lower; char *lower;
//setup MMU
mmu_reinit();
print_init(&pl011_putc); //initialize the serial console print_init(&pl011_putc); //initialize the serial console
//setup memory //setup memory

View File

@ -1,8 +1,8 @@
ENTRY (_start) ENTRY (start)
SECTIONS SECTIONS
{ {
. = 0x80000000; . = 0x80100000;
.text : { *(.text*) *(.rodata*) } .text : { *(.text*) *(.rodata*) }
.data : { *(.data*) } .data : { *(.data*) }
.bss : { *(.bss*) *(COMMON*) } .bss : { *(.bss*) *(COMMON*) }