From abcf935ee6270da536d8b355b92e013963062d7e Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 7 Aug 2011 19:00:56 +0200 Subject: ARM mmu: use high vectors if possible Using high vectors allows us to map a faulting zero page to catch NULL pointer dereferences. Signed-off-by: Sascha Hauer --- arch/arm/cpu/mmu.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c index 2f754c8b8b..b6693495b6 100644 --- a/arch/arm/cpu/mmu.c +++ b/arch/arm/cpu/mmu.c @@ -4,6 +4,7 @@ #include #include #include +#include static unsigned long *ttb; @@ -161,22 +162,46 @@ static int arm_mmu_remap_sdram(struct arm_memory *mem) #define ARM_VECTORS_SIZE (sizeof(u32) * 8 * 2) /* - * Allocate a page, map it to the zero page and copy our exception - * vectors there. + * Map vectors and zero page */ static void vectors_init(void) { - u32 *exc; + u32 *exc, *zero = NULL; void *vectors; extern unsigned long exception_vectors; - - exc = arm_create_pte(0x0); + u32 cr; + + cr = get_cr(); + cr |= CR_V; + set_cr(cr); + cr = get_cr(); + + if (cr & CR_V) { + /* + * If we can use high vectors, create the second level + * page table for the high vectors and zero page + */ + exc = arm_create_pte(0xfff00000); + zero = arm_create_pte(0x0); + + /* Set the zero page to faulting */ + zero[0] = 0; + } else { + /* + * Otherwise map the vectors to the zero page. We have to + * live without being able to catch NULL pointer dereferences + */ + exc = arm_create_pte(0x0); + } vectors = xmemalign(PAGE_SIZE, PAGE_SIZE); memset(vectors, 0, PAGE_SIZE); memcpy(vectors, &exception_vectors, ARM_VECTORS_SIZE); - exc[0] = (u32)vectors | PTE_TYPE_SMALL | PTE_FLAGS_CACHED; + if (cr & CR_V) + exc[256 - 16] = (u32)vectors | PTE_TYPE_SMALL | PTE_FLAGS_CACHED; + else + exc[0] = (u32)vectors | PTE_TYPE_SMALL | PTE_FLAGS_CACHED; } /* -- cgit v1.2.3