tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
err.c
Go to the documentation of this file.
1//err.c - err handling and so on
2#include "err.h"
3#include "types.h"
4
5//note: raw vga used incase prt was comprimised, minimal dependencys
6
7/**
8 * @brief panic halts the system with a kernel panic message
9 *
10 * panic is a function that clears the screen to red, displays a
11 * kernel panic banner with the provided message, and halts forever
12 * @param txt, the error message to display
13 *
14 * when panic is called the system becomes unrecoverable, it will
15 * always halt, so use it only for fatal unrecoverable errors
16 *
17 * using panic is done with
18 * @code{.c}
19 * #include "../lib/err.h" //or just err.h
20 * panic("something went wrong");
21 * @endcode
22 *
23 * @see assert()
24 */
25NORETURN void __panic(const char* txt) {
26 uint16_t* vga = (uint16_t*)0xB8000;
27 //clear screen
28 for (int i = 0; i < 2000; i++) {
29 vga[i] = (uint16_t)(0x0C << 8) | ' '; //red background, space character aka empty
30 }
31
32 //prt KERNEL PANIC
33 const char* kmsg = "KERNEL PANIC";
34 int i = 0;
35 while (kmsg[i] != 0) {
36 vga[i] = (uint16_t)((0x0C << 8) | kmsg[i]); //red text for error-ness
37 i++;
38 }
39
40 //prt err on row 2
41 i = 0;
42 while (txt[i] != 0) {
43 vga[2 * 80 + i] = (uint16_t)((0x0C << 8) | txt[i]);
44 i++;
45 }
46
47 //prt "system halted" on row 4
48 const char* hmsg = "system halted";
49 i = 0;
50 while (hmsg[i] != 0) {
51 vga[4 * 80 + i] = (uint16_t)((0x0C << 8) | hmsg[i]);
52 i++;
53 }
54
55 //halt forever
56 while(1);
57}
void __panic(const char *txt)
panic halts the system with a kernel panic message
Definition err.c:25
unsigned short uint16_t
Definition types.h:29
#define NORETURN
Definition types.h:40
uint16_t * vga
the vga framebuffer pointer
Definition vga.c:18