#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