1
0

mmu: Add initial implementation of identity mapping

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

View File

@ -5,5 +5,6 @@ KOBJS += $(KERNEL_PREFIX)/font.o
KOBJS += $(KERNEL_PREFIX)/framebuffer.o
KOBJS += $(KERNEL_PREFIX)/list.o
KOBJS += $(KERNEL_PREFIX)/mm.o
KOBJS += $(KERNEL_PREFIX)/mmu.o
KOBJS += $(KERNEL_PREFIX)/print.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 <print.h>
#include <devices/pl011.h>
@ -54,6 +55,10 @@ void test_memory() {
int main(void) {
char *lower;
//setup MMU
mmu_reinit();
print_init(&pl011_putc); //initialize the serial console
//setup memory