summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-08-07 19:00:56 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2011-08-07 19:00:59 +0200
commitabcf935ee6270da536d8b355b92e013963062d7e (patch)
tree2f7ede8cf4ed3f3ce07e83c66e0d59765dc114ff
parent606bd7d9ced401f155534c70a834b45fd4075173 (diff)
downloadbarebox-abcf935ee6270da536d8b355b92e013963062d7e.tar.gz
barebox-abcf935ee6270da536d8b355b92e013963062d7e.tar.xz
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 <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/cpu/mmu.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 2f754c8b8..b6693495b 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -4,6 +4,7 @@
#include <errno.h>
#include <sizes.h>
#include <asm/memory.h>
+#include <asm/system.h>
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;
}
/*