summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/shared/startup/panic.c
blob: bff7aeb8678167cada0bef6be9319aba96af1913 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <rtems.h>
#include <bsp.h>
#include <bsp/bootcard.h>
#include <bsp/uart.h>
#include <rtems/bspIo.h>
#include <rtems/error.h>
#include <libcpu/stackTrace.h>
#include <rtems/score/percpu.h>
#include <rtems/score/threaddispatch.h>

static void
rebootQuestion(void)
{
  printk("Press a key to reboot\n");
  BSP_poll_char_via_serial();
  bsp_reset();
}

void BSP_panic(char *s)
{
  printk("%s PANIC %s\n",_RTEMS_version, s);
  rebootQuestion();
}

#define THESRC _Internal_errors_What_happened.the_source
#define ISITNL _Internal_errors_What_happened.is_internal
#define THEERR _Internal_errors_What_happened.the_error

void _BSP_Fatal_error(unsigned int v)
{
  unsigned long flags;
  const char *err = 0;

  rtems_interrupt_disable(flags);
  (void) flags; /* avoid set but not used warning */

  printk("%s\n",_RTEMS_version);
  printk("FATAL ERROR:\n");
  printk("Internal error: %s\n", ISITNL? "Yes":"No");
  printk("Environment:");
  switch (THESRC) {
    case INTERNAL_ERROR_CORE:
      printk(" RTEMS Core\n");
      err = rtems_internal_error_text(THEERR);
    break;

      case INTERNAL_ERROR_RTEMS_API:
      printk(" RTEMS API\n");
      err = rtems_status_text(THEERR);
    break;

      case INTERNAL_ERROR_POSIX_API:
      printk(" POSIX API (errno)\n");
      /* could use strerror but I'd rather avoid using this here */
    break;

    default:
      printk("  UNKNOWN (0x%x)\n",THESRC);
  break;
  }
  if ( _Thread_Dispatch_is_enabled() )
    printk("enabled\n");
  else
    printk(
      "  Error occurred in a Thread Dispatching DISABLED context (level %i)\n",
      _Thread_Dispatch_get_disable_level());

  if ( _ISR_Nest_level ) {
    printk(
      "  Error occurred from ISR context (ISR nest level %i)\n",
      _ISR_Nest_level
    );
  }

  printk("Error %d",THEERR);
  if (err) {
    printk(": %s",err);
  }
  printk("\n");
  printk("Stack Trace:\n");
  CPU_print_stack();

  rebootQuestion();
}