aboutsummaryrefslogtreecommitdiff
path: root/src/kern/main.c
blob: 3af8bebd8e65d3888815da4993d0caf59613df84 (plain) (blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "arch.h"
#include "arch/arm/cortex-m4/mpu.h"
#include "arch/stm32l4xxx/peripherals/clock.h"
#include "arch/stm32l4xxx/peripherals/system.h"
#include "kern/init.h"
#include "kern/log.h"
#include "kern/mem.h"
#include "kern/mpu/mpu_manager.h"
#include "kern/panic.h"
#include "kern/priv.h"
#include "user/syscall.h"

void on_hard_fault()
{
  panic("Hard fault encountered!\n");
}

void on_systick() /* Overrides weak-symbol on_systick. */
{
  klogf("Systick\n");
}

void configure_mpu()
{
  configure_flash_region((void*)0x08000000, REGION_SIZE_256Kb, NOT_PRIVILEGED);
  configure_ram_region((void*)SRAM1_BASE, REGION_SIZE_64Kb, NOT_PRIVILEGED);
  configure_ram_region((void*)SRAM2_BASE, REGION_SIZE_16Kb, NOT_PRIVILEGED);
  configure_peripheral_region((void*)0x40000000, REGION_SIZE_512Mb, PRIVILEGED);
  mpu_set_enabled(1);
}

#ifdef ARCH_STM32L4

/* Main function. This gets executed from the interrupt vector defined above. */
int main()
{
  configure_mpu();

  klogf("Outside of usermode, I can still log stuff using klogf()\n");

  enter_user_mode();

  logs("Now that I'm in user mode, I have to log stuff using a system call\n");
  logs(
      "because I no longer have direct accss to USART2 and cannot use\n"
      "klogf()\n");


  for (;;)
    ;
}

#endif