From 26685f5203bc38cfa082b96182a406f4f7e6435a Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 30 Dec 2019 14:36:31 +0100 Subject: implement getchar() and putchar() in terms of supervisor call --- PL0_test.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'PL0_test.c') diff --git a/PL0_test.c b/PL0_test.c index 2e008a2..f476eb7 100644 --- a/PL0_test.c +++ b/PL0_test.c @@ -1,34 +1,29 @@ -#include "uart.h" -#include "psr.h" +#include "PL0_utils.h" // entry point - must remain the only function in the file! void PL0_main(void) { - // If all went correct, Success! gets printed - uart_puts("Success!\n\r"); - - uart_puts("calling supervisor\n\r"); - - asm volatile("svc #0"); - - uart_puts("back from supervisor call\n\r"); + // If loading program to userspace and handling of svc are + // implemented correctly, this shall get printed + puts("Hello userspace!"); - // if we're indeed in PL0, we should crash now, when trying to access - // memory we're not allowed to + // if we're indeed in PL0, we should trigger the abort handler now, + // when trying to access memory we're not allowed to + puts("Attempting to meddle with kernel memory from userspace :d"); char first_kernel_byte[2]; - first_kernel_byte[0] = *(char*) ((uint32_t) 0x0); + first_kernel_byte[0] = *(char*) 0x0; first_kernel_byte[1] = '\0'; uart_puts(first_kernel_byte); while (1) { - char c = uart_getc(); + char c = getchar(); - uart_putc(c); + putchar(c); if (c == '\r') - uart_putc('\n'); + putchar('\n'); } } -- cgit v1.2.3