feature (kernel): Implemented cpu state dumping on panic

This commit is contained in:
antifallobst 2023-02-12 09:44:59 +01:00
parent 91ee003264
commit 2d9b9144e2
1 changed files with 46 additions and 1 deletions

View File

@ -17,9 +17,54 @@
#include "utils/logger.h"
#include "utils/core.h"
void panic_log_paging_info(cpu_state_T* state) {
log(LOG_NONE, "Paging Info:");
log(LOG_NONE, " Page Map: 0x%x\n", state->cr3);
}
void panic_log_eflags(cpu_state_T* state) {
if (state->flags) {
log(LOG_NONE, "CPU Flags:");
if (state->flags & (1 << CPU_FLAG_CARRY)) { log(LOG_NONE, " Carry"); }
if (state->flags & (1 << CPU_FLAG_PARITY)) { log(LOG_NONE, " Parity"); }
if (state->flags & (1 << CPU_FLAG_AUXILIARY)) { log(LOG_NONE, " Auxiliary"); }
if (state->flags & (1 << CPU_FLAG_ZERO)) { log(LOG_NONE, " Zero"); }
if (state->flags & (1 << CPU_FLAG_SIGN)) { log(LOG_NONE, " Sign"); }
if (state->flags & (1 << CPU_FLAG_TRAP)) { log(LOG_NONE, " Trap"); }
if (state->flags & (1 << CPU_FLAG_INTERRUPT_ENABLE)) { log(LOG_NONE, " Interrupt Enable"); }
if (state->flags & (1 << CPU_FLAG_DIRECTION)) { log(LOG_NONE, " Direction"); }
if (state->flags & (1 << CPU_FLAG_OVERFLOW)) { log(LOG_NONE, " Overflow"); }
if (state->flags & (1 << CPU_FLAG_IO_PRIVILEGE_0)) { log(LOG_NONE, " IO Privilege 0"); }
if (state->flags & (1 << CPU_FLAG_IO_PRIVILEGE_1)) { log(LOG_NONE, " IO Privilege 1"); }
if (state->flags & (1 << CPU_FLAG_NESTED_TASK)) { log(LOG_NONE, " Nested Task"); }
if (state->flags & (1 << CPU_FLAG_RESUME)) { log(LOG_NONE, " Resume"); }
if (state->flags & (1 << CPU_FLAG_VIRTUAL_8086)) { log(LOG_NONE, " Virtual 8086"); }
if (state->flags & (1 << CPU_FLAG_ALIGNMENT_CHECK)) { log(LOG_NONE, " Alignment Check"); }
if (state->flags & (1 << CPU_FLAG_VIRTUAL_INTERRUPT)) { log(LOG_NONE, " Virtual Interrupt"); }
if (state->flags & (1 << CPU_FLAG_VIRTUAL_INTERRUPT_PENDING)) { log(LOG_NONE, " Virtual Interrupt Pending"); }
if (state->flags & (1 << CPU_FLAG_CPUID)) { log(LOG_NONE, " CPUID"); }
log(LOG_NONE, ""); // newline
}
}
void panic_log_registers(cpu_state_T* state) {
log(LOG_NONE, "CPU Registers:");
log(LOG_NONE, " RIP: 0x%x RAX: 0x%x RBX: 0x%x", state->rip, state->rax, state->rbx);
log(LOG_NONE, " RCX: 0x%x RDX: 0x%x RSI: 0x%x", state->rcx, state->rdx, state->rsi);
log(LOG_NONE, " RDI: 0x%x RBP: 0x%x RSP: 0x%x\n", state->rdi, state->rbp, state->rsp);
}
void panic(cpu_state_T* state, string_t message) {
log(LOG_ERROR, "!=====[ KERNEL PANIC ]=====!");
log(LOG_ERROR, "Error Message:", message);
log(LOG_NONE, "Interrupt ID: 0x%xb", state->interrupt_id);
log(LOG_NONE, "Error Code: 0b%.32b", state->error_code);
log(LOG_NONE, "Error Message: %s\n", message);
panic_log_paging_info(state);
panic_log_eflags(state);
panic_log_registers(state);
CORE_HALT_FOREVER
}