--- /dev/null
+#ifndef PANIC_H
+#define PANIC_H
+
+void halt()
+{
+ asm("cli":);
+loop:
+ asm("hlt":);
+ goto loop;
+}
+
+#define PANIC(msg) \
+ kprint("PANIC (", VGA_COLOR_BRIGHT_RED);\
+ kprint(msg, VGA_COLOR_BRIGHT_RED);\
+ kprint(") in ", VGA_COLOR_BRIGHT_RED);\
+ kprint(__FILE__, VGA_COLOR_BRIGHT_RED);\
+ kprintc(':', VGA_COLOR_BRIGHT_RED);\
+ kprintdec(__LINE__, VGA_COLOR_BRIGHT_RED);\
+ kprintc(':', VGA_COLOR_BRIGHT_RED);\
+ kprint(__func__, VGA_COLOR_BRIGHT_RED);\
+ kprint("()", VGA_COLOR_BRIGHT_RED);\
+ halt();
+
+#endif
extern void kprintw(const uint16_t word);
extern void kprintd(const uint32_t dword);
extern void kprintq(const uint64_t qword);
-extern int kprintdec(uint32_t num);
+extern int kprintdec(uint32_t num, uint8_t color);
#endif
#include <io.h>
#include <stdint.h>
#include <mm/paging.h>
+#include <panic.h>
typedef uint32_t uword_t;
int address;
struct pf_errcode errcode = frame->error_code;
asm ("mov %%cr2, %0": "=a" (address));
- kprint("A page fault occurred!\n", VGA_COLOR_DARK_RED);
+ kprint("A page fault occurred!\n", VGA_COLOR_BRIGHT_RED);
kprint("Faulting address: ", 0);
kprintd(address);
kprint("\n", 0);
if (errcode.id) {
kprint("Fault occurred while fetching instruction\n", 0);
}
- asm("cli");
-halt:
- asm("hlt");
- goto halt;
+ PANIC("page fault");
}
__attribute__((interrupt))
void double_fault(struct abort_frame *frame)
{
- *(volatile uint32_t *) (0xb8000) = 0xcf28cf3a;
-halt:
- asm volatile ("cli; hlt");
- goto halt;
+ PANIC("double fault");
}
kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
}
-int kprintdec(uint32_t num)
+int kprintdec(uint32_t num, uint8_t color)
{
char buffer[11];
int digits = 10;
}
}
- kprint(buffer, 0);
+ kprint(buffer, color);
return digits;
}
pic_unmask(1);
asm volatile ("sti");
kprint("All done\n", 0);
- kprintdec(12345);
- kprintc('\n');
- kprintdec(6789);
- kprintc('\n');
while(1);
}