aboutsummaryrefslogtreecommitdiff
path: root/src/kern/panic.c
blob: 75ce52ac76fe69129130ab8ea14d54ca71a24071 (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
#include "kern/panic.h"

#include <stdarg.h>

#include "arch.h"
#include "arch/stm32l4xxx/peripherals/clock.h"
#include "kern/delay.h"
#include "kern/gpio/gpio_manager.h"
#include "kern/gpio/sysled.h"
#include "kern/init.h"
#include "kern/log.h"

#ifdef ARCH_STM32L4
_Noreturn void panic(const char* fmt, ...)
{
  uint32_t base[0];
  disable_all_interrupts();

  va_list l;
  va_start(l, fmt);

  kerr_logf("** Kernel Panic! **\n");
  kerr_vlogf(fmt, l);
  kerr_logf("** Stack:\n");

  int i = 0;
  for (; i < 20 && &base[i] != (void*)STACK_TOP; ++i) {
    kerr_logf(" (%p) %p\n", &base[i], base[i]);
  }

  set_system_clock_MHz(4); /* reduce power usage while we do nothing. */
  gpio_reserved_pin_t pin3 = get_sysled();

  for (;;) {
    set_gpio_pin_high(pin3);
    delay(100000);
    set_gpio_pin_low(pin3);
    delay(100000);
  }
}
#endif