runtime, interrupt: print to screen on errors, print CR2 on panic

CR2 is the last accessed address set on page exceptions
This commit is contained in:
Edgaru089 2021-11-11 16:18:47 +08:00
parent c0c2c12493
commit ec808e5e2e
4 changed files with 53 additions and 13 deletions

View File

@ -59,12 +59,16 @@ const char *interrupt_Descriptions[] = {
*/
SYSV_ABI void interrupt_Handler(int vec, int errcode, uint64_t rip, uint64_t rax, uint64_t rbx, uint64_t rcx, uint64_t rdx, uint64_t rsi, uint64_t rdi, uint64_t rbp, uint64_t rsp, uint64_t r8, uint64_t r9, uint64_t r10, uint64_t r11, uint64_t r12, uint64_t r13, uint64_t r14, uint64_t r15) {
io_Printf("Panic: INT %02xh: %s, err=%d(0x%02x), rip=%llx\n"
asm volatile("cli");
uint64_t cr2;
asm volatile("mov %%cr2, %0"
: "=r"(cr2));
io_Errorf("Panic: INT %02xh: %s, err=%d(0x%02x), RIP=%llx, CR2=%llx\n"
" RAX=%016llX, RBX=%016llX, RCX=%016llX, RDX=%016llX\n"
" RSI=%016llX, RDI=%016llX, RBP=%016llX, RSP=%016llX\n"
" R8=%016llX, R9=%016llX, R10=%016llX, R11=%016llX\n"
" R12=%016llX, R13=%016llX, R14=%016llX, R15=%016llX",
vec, interrupt_Descriptions[vec], errcode, errcode, rip, rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15);
vec, interrupt_Descriptions[vec], errcode, errcode, rip, cr2, rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15);
__Panic_HaltSystem();
}

View File

@ -27,17 +27,19 @@ noreturn void __Panic_HaltSystem();
// Panic() aborts the system after printing the message and some other information.
noreturn inline static void Panic(const char *message) {
io_Printf("Panic: %s\n", message);
asm volatile("cli");
io_Errorf("Panic: %s\n", message);
__Panic_HaltSystem();
}
// Panicf() aborts the system after printing the message using vsnprintf.
noreturn inline static void Panicf(const char *fmt, ...) {
asm volatile("cli");
va_list args;
va_start(args, fmt);
int ret = vsnprintf(Buffer, HELOS_BUFFER_SIZE, fmt, args);
va_end(args);
io_Printf("Panic: %s\n", Buffer);
io_Errorf("Panic: %s\n", Buffer);
__Panic_HaltSystem();
}

View File

@ -46,10 +46,7 @@ void __io_WriteConsole_ResizeBuffer(int size) {
}
}
void io_WriteConsole(const char *str) {
pic_serial_Write(&pic_serial_COM1, str, 0);
#ifndef HELOS_RUNTIME_QUIET
static inline void __io_WriteConsoleUTF8(const char *str) {
int size = 0; // don't include the \0 at the end here
int len = strlen(str); // left the \0 out here too
@ -71,13 +68,9 @@ void io_WriteConsole(const char *str) {
} else {
console_WriteUTF16(&HelosGraphics_Color_White, __io_WriteConsole_buffer, 0);
}
#endif
}
void io_WriteConsoleASCII(const char *str) {
pic_serial_Write(&pic_serial_COM1, str, 0);
#ifndef HELOS_RUNTIME_QUIET
static inline void __io_WriteConsoleASCII(const char *str) {
if (!graphics_Framebuffer) {
int len = strlen(str);
__io_WriteConsole_ResizeBuffer(len + 1);
@ -87,6 +80,19 @@ void io_WriteConsoleASCII(const char *str) {
} else {
console_WriteASCII(&HelosGraphics_Color_White, str, 0);
}
}
void io_WriteConsole(const char *str) {
pic_serial_Write(&pic_serial_COM1, str, 0);
#ifndef HELOS_RUNTIME_QUIET
__io_WriteConsoleUTF8(str);
#endif
}
void io_WriteConsoleASCII(const char *str) {
pic_serial_Write(&pic_serial_COM1, str, 0);
#ifndef HELOS_RUNTIME_QUIET
__io_WriteConsoleASCII(str);
#endif
}
@ -104,3 +110,26 @@ int io_Printf(const char *fmt, ...) {
INTERRUPT_RESTORE;
return ret;
}
void io_Error(const char *str) {
pic_serial_Write(&pic_serial_COM1, str, 0);
__io_WriteConsoleUTF8(str);
}
void io_ErrorASCII(const char *str) {
pic_serial_Write(&pic_serial_COM1, str, 0);
__io_WriteConsoleASCII(str);
}
int io_Errorf(const char *fmt, ...) {
INTERRUPT_DISABLE;
va_list args;
va_start(args, fmt);
int ret = vsnprintf(__io_Printf_buffer, sizeof(__io_Printf_buffer), fmt, args);
va_end(args);
io_Error(__io_Printf_buffer);
INTERRUPT_RESTORE;
return ret;
}

View File

@ -20,6 +20,11 @@ void io_WriteConsoleASCII(const char *str);
// io_Printf is a printf() replacement, printing to WriteConsole function.
int io_Printf(const char *format, ...);
// io_Error prints error information directly to the screen.
void io_Error(const char *str);
void io_ErrorASCII(const char *str);
int io_Errorf(const char *format, ...);
// Debugging printing marcos
#ifndef NDEBUG