From 11541f1d1eaaefebd6d01b42e92a65606e4bc382 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 12 Nov 2019 18:23:39 +0100 Subject: some ugly instructions (I wouldn't call this code), that switch to PL0 and check that MMU really works here - it's temporary, don't merge! (merge commit b4 PL0_test.c was added, if you really want) --- PL0_test.c | 18 +++++++++++++++++- kernel.c | 7 ++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/PL0_test.c b/PL0_test.c index 1a3d49d..7609294 100644 --- a/PL0_test.c +++ b/PL0_test.c @@ -1,9 +1,25 @@ #include "uart.h" +#include "psr.h" void PL0_main(void) { - uart_puts("hello PL0!\n\r"); + uart_puts("hello PL0! Switching to user mode!\n\r"); + asm("cps #0b10000\n\r" + "isb" ::: "memory"); + + // if all went correct, Success! gets printed + uart_puts("Success!\n\r"); + + // if we're indeed i PL0, we should crash now, when trying to access + // memory we're not allowed to + char first_kernel_byte[2]; + + first_kernel_byte[0] = *(char*) ((uint32_t) 0x8000); + first_kernel_byte[1] = '\0'; + + uart_puts(first_kernel_byte); + while (1) { char c; diff --git a/kernel.c b/kernel.c index bd4426d..5d4e6d7 100644 --- a/kernel.c +++ b/kernel.c @@ -229,7 +229,12 @@ void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) (&_binary_PL_0_test_img_start)[i]; // jump to that copied code (no switch to PL0 yet, just testing) - ((void(*)(void)) (((uint32_t) 0b101010101010) << 20))(); + asm volatile("mov r5, #0\n\r" + "movt r5, #0b1010101010101111\n\r" + "mov sp, r5\n\r" + "mov r5, #0\n\r" + "movt r5, #0b1010101010100000\n\r" + "blx r5\n\r"); while(1); -- cgit v1.2.3