Xyris  0.5
Panic.cpp
Go to the documentation of this file.
1 /**
2  * @file Panic.cpp
3  * @author Keeton Feavel ([email protected])
4  * @brief
5  * @version 0.1
6  * @date 2021-11-05
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2021
9  *
10  */
14 #include <Devices/Serial/rs232.hpp>
15 #include <Library/stdio.hpp>
16 #include <Panic.hpp>
17 #include <Stacktrace.hpp>
18 #include <Scheduler/tasks.hpp>
19 #include <x86gprintrin.h>
20 
21 #define PANIC_MAX_TRACE 64
22 #define PANIC_MOO_BUF_SZ 256
23 #define PANIC_MSG_BUF_SZ 256
24 #define PANIC_REG_BUG_SZ 512
25 #define PANIC_COLOR_FORE 0xFFFFFF
26 #define PANIC_COLOR_BACK 0x2D2D2D
27 
28 #define PANIC_REG_DUMP_MSG "Kernel exception - Dumping register state..."
29 
30 const char *funnyMessagesForMoo[] = {
31  "Oh, it’s you. It’s been a long time.\nHow have you been?",
32  "Sorry, I accidentally let the magic smoke out.",
33  "Not sure how we got here, but here we are.",
34  "Whatever you just did, don't do it again.",
35  "Something udderly terrible happened!",
36  "Still more stable than DOS!",
37  "Yeah, that's about right.",
38  "I'm Moo, the Xryis cow!",
39  "Guru meditation time!",
40  "Yahaha, you found me!",
41  "Minecraft crashed!",
42  "Get Dunked On!",
43 };
45 
46 static void printMoo()
47 {
51 
52  char cow[PANIC_MOO_BUF_SZ];
53  ksprintf(
54  cow,
55  "\n"
56  "%s\n\n"
57  " \\ ^__^\n"
58  " \\ (OO)\\_______\n"
59  " (__)\\ )\\/\\\n"
60  " U ||----w |\n"
61  " || ||\n\n",
63  log_all("%s", cow);
64 }
65 
66 [[noreturn]] static void panicInternal(const char* msg, struct registers *registers)
67 {
68  printMoo();
69  if (msg) {
70  log_all("%s\n\n", msg);
71  }
72  if (registers) {
73  char buf[PANIC_REG_BUG_SZ];
76  log_all("%s", buf);
77  }
80 }
81 
82 [[noreturn]] void panic(const char* msg)
83 {
84  panicInternal(msg, NULL);
85 }
86 
87 [[noreturn]] void panicf(const char* fmt, ...)
88 {
89  va_list args;
90  char buf[PANIC_MSG_BUF_SZ];
91  va_start(args, fmt);
92  kvsprintf(buf, fmt, args);
93  va_end(args);
94 
95  panic(buf);
96 }
97 
98 [[noreturn]] void panic(struct registers *registers)
99 {
100  panicInternal(PANIC_REG_DUMP_MSG, registers);
101 }
stdio.hpp
funnyMessagesForMooSize
const size_t funnyMessagesForMooSize
Definition: Panic.cpp:44
ksprintf
int ksprintf(char *buf, const char *fmt,...)
Sends formatted output to a string.
Definition: printf.cpp:342
kvsprintf
int kvsprintf(char *buf, const char *fmt, va_list args)
Sends formatted output to a string using an argument list.
Definition: printf.cpp:333
graphics.hpp
PANIC_REG_BUG_SZ
#define PANIC_REG_BUG_SZ
Definition: Panic.cpp:24
console.hpp
Framebuffer console.
Stack::printTrace
void printTrace(size_t max)
Definition: Stacktrace.cpp:24
framebuffer.hpp
PANIC_COLOR_FORE
#define PANIC_COLOR_FORE
Definition: Panic.cpp:25
tasks.hpp
Arch::registersToString
void registersToString(char *buf, struct registers *regs)
Write all register names and values as a string to a buffer. Provided buffer size must also take esca...
Definition: Arch.i686.cpp:51
registers
A structure definining values for all x86 registers. Cannot be namespaced due to C linkage and ASM in...
Definition: regs.hpp:19
Graphics::Framebuffer::getWidth
uint32_t getWidth()
Definition: framebuffer.hpp:34
log_all
#define log_all(fmt,...)
Prints a statement to serial debugger and the kernel framebuffer. Max message size is 1024 (including...
Definition: stdio.hpp:59
rs232.hpp
A simple, write-only driver for the RS232 serial device standard. Code mostly ported from Panix-Archi...
Panic.hpp
Kernel panic management.
panicf
void panicf(const char *fmt,...)
Halt the system and print the provided message and arguments on the panic screen.
Definition: Panic.cpp:87
Graphics::Framebuffer
Definition: framebuffer.hpp:21
Stacktrace.hpp
Arch::registersPrintInformation
void registersPrintInformation(struct registers *regs)
Print register information to all kernel terminals (serial, framebuffer, etc.). Used for panic and de...
Definition: Arch.i686.cpp:67
PANIC_MAX_TRACE
#define PANIC_MAX_TRACE
Definition: Panic.cpp:21
PANIC_MOO_BUF_SZ
#define PANIC_MOO_BUF_SZ
Definition: Panic.cpp:22
Arch::haltAndCatchFire
void haltAndCatchFire()
Disable interrupts and halts execution.
Definition: Arch.hpp:42
PANIC_COLOR_BACK
#define PANIC_COLOR_BACK
Definition: Panic.cpp:26
funnyMessagesForMoo
const char * funnyMessagesForMoo[]
Definition: Panic.cpp:30
Console::reset
void reset(uint32_t fore, uint32_t back)
Definition: console.cpp:287
Graphics::Framebuffer::getHeight
uint32_t getHeight()
Definition: framebuffer.hpp:35
panic
void panic(const char *msg)
Halt the system and print the provided message on the panic screen.
Definition: Panic.cpp:82
Graphics::getFramebuffer
Framebuffer * getFramebuffer()
Get a pointer to the active framebuffer.
Definition: framebuffer.cpp:81
PANIC_REG_DUMP_MSG
#define PANIC_REG_DUMP_MSG
Definition: Panic.cpp:28
Graphics::putrect
void putrect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Draws and fills a rectangle of a given width and height, and color at the provided coordinates.
Definition: graphics.cpp:71
PANIC_MSG_BUF_SZ
#define PANIC_MSG_BUF_SZ
Definition: Panic.cpp:23