From 1fa64fccbf404d51cd3044a2f834d74c44805799 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 4 Mar 2018 17:23:16 -0800 Subject: [PATCH] Add pre-defined panic utilities --- exosphere/src/panic_color.h | 21 +++++++++++++++++++++ exosphere/src/utils.c | 5 +++++ exosphere/src/utils.h | 3 +++ 3 files changed, 29 insertions(+) create mode 100644 exosphere/src/panic_color.h diff --git a/exosphere/src/panic_color.h b/exosphere/src/panic_color.h new file mode 100644 index 000000000..ba42f8713 --- /dev/null +++ b/exosphere/src/panic_color.h @@ -0,0 +1,21 @@ +#ifndef EXOSPHERE_PANIC_COLOR_H +#define EXOSPHERE_PANIC_COLOR_H + +#define COLOR_0 0x00F00003 +#define COLOR_1 0x0F000003 +#define COLOR_2 0xF0000003 +#define COLOR_3 0x0FF00003 +#define COLOR_4 0xF0F00003 +#define COLOR_5 0xFF000003 +#define COLOR_6 0xFFF00003 +#define COLOR_7 0xAAF00003 +#define COLOR_8 0xAFA00003 +#define COLOR_9 0xFAA00003 +#define COLOR_A 0x33300003 +#define COLOR_B 0x06F00003 +#define COLOR_C 0x14800003 +#define COLOR_D 0x00300003 +#define COLOR_E 0x03000003 +#define COLOR_F 0xB6000003 + +#endif \ No newline at end of file diff --git a/exosphere/src/utils.c b/exosphere/src/utils.c index 375d20f02..9a59d579d 100644 --- a/exosphere/src/utils.c +++ b/exosphere/src/utils.c @@ -23,6 +23,11 @@ __attribute__ ((noreturn)) void generic_panic(void) { panic(0xFF000006); } +__attribute__ ((noreturn)) void panic_predefined(uint32_t which) { + static const uint32_t codes[0x10] = {COLOR_0, COLOR_1, COLOR_2, COLOR_3, COLOR_4, COLOR_5, COLOR_6, COLOR_7, COLOR_8, COLOR_9, COLOR_A, COLOR_B, COLOR_C, COLOR_D, COLOR_E, COLOR_F}; + panic(codes[which & 0xF]); +} + __attribute__((noinline)) bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be) { if(as <= bs && bs <= ae) diff --git a/exosphere/src/utils.h b/exosphere/src/utils.h index 2919c88c9..ff494351b 100644 --- a/exosphere/src/utils.h +++ b/exosphere/src/utils.h @@ -5,6 +5,8 @@ #include #include +#include "panic_color.h" + #define BIT(n) (1u << (n)) #define BITL(n) (1ull << (n)) #define MASK(n) (BIT(n) - 1) @@ -52,6 +54,7 @@ typedef struct { __attribute__ ((noreturn)) void panic(uint32_t code); __attribute__ ((noreturn)) void generic_panic(void); +__attribute__ ((noreturn)) void panic_predefined(uint32_t which); bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be); static inline uintptr_t get_physical_address(const void *vaddr) {