1
0
aedrix-kernel/kernel/mmu.c

30 lines
1020 B
C

#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++;
}
}