aboutsummaryrefslogtreecommitdiff
path: root/PL0_test.c
blob: fed62a272c8e7b044b58e8ceb58dee8d189c19cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "PL0_utils.h"

// entry point - must remain the only function in the file!
void PL0_main(void)
{
  // If loading program to userspace and handling of svc are
  // implemented correctly, this shall get printed
  puts("Hello userspace! Type 'f' if you want me to try accessing "
       "kernel memory!");


  asm volatile("mov r0, #17\n\rsvc #0" ::: "r0");
  while (1)
    {
      char c = getchar();
      
      if (c == '\r')
	putchar('\n');
      
      putchar(c);
      
      if (c == 'f')
	{
	  // 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 read kernel memory from userspace :d");
	  char first_kernel_byte[2];

	  first_kernel_byte[0] = *(char*) 0x0;
	  first_kernel_byte[1] = '\0';

	  puts(first_kernel_byte);
	}
    }
}