aboutsummaryrefslogtreecommitdiff
path: root/PL0_test.c
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-12-30 14:36:31 +0100
committerWojtek Kosior <kwojtus@protonmail.com>2019-12-30 14:36:31 +0100
commit26685f5203bc38cfa082b96182a406f4f7e6435a (patch)
tree5566b6812c7cc127da597a08a6824616b2aa5bb5 /PL0_test.c
parentee8668f9fcd952e4952706789bdde7fd223dacb5 (diff)
downloadrpi-MMU-example-26685f5203bc38cfa082b96182a406f4f7e6435a.tar.gz
rpi-MMU-example-26685f5203bc38cfa082b96182a406f4f7e6435a.zip
implement getchar() and putchar() in terms of supervisor call
Diffstat (limited to 'PL0_test.c')
-rw-r--r--PL0_test.c27
1 files changed, 11 insertions, 16 deletions
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');
}
}