diff options
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/core/main.cpp | 0 | ||||
-rw-r--r-- | src/kernel/mem/paging.cpp | 24 | ||||
-rw-r--r-- | src/kernel/task/idt.cpp | 2 | ||||
-rw-r--r-- | src/kernel/task/task.cpp | 32 | ||||
-rw-r--r-- | src/kernel/ui/vt.cpp | 2 |
5 files changed, 42 insertions, 18 deletions
diff --git a/src/kernel/core/main.cpp b/src/kernel/core/main.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/kernel/core/main.cpp diff --git a/src/kernel/mem/paging.cpp b/src/kernel/mem/paging.cpp index 2ac190f..5c5a929 100644 --- a/src/kernel/mem/paging.cpp +++ b/src/kernel/mem/paging.cpp @@ -136,14 +136,22 @@ uint32_t paging_fault(registers *regs) { } if (seg == 0) { - NL; WHERE; *ke_vt << "Unhandled Page Fault (PID " << current_thread->process->pid << ")\t"; - *ke_vt << "cr2:" << addr; - NL; TAB; - if (regs->err_code & 0x1) *ke_vt << "present"; TAB; - if (regs->err_code & 0x2) *ke_vt << "write"; TAB; - if (regs->err_code & 0x4) *ke_vt << "user"; TAB; - if (regs->err_code & 0x8) *ke_vt << "rsvd"; TAB; - if (regs->err_code & 0x10) *ke_vt << "opfetch"; + node *n = current_thread->process->fd.at(0); + vt *vt = (n && n->as_vt() ? n->as_vt() : ke_vt); + + vt->writeStr("\n"); + vt->writeStr("[ke:"); vt->writeStr(__FILE__); vt->writeStr(":"); + vt->writeDec(__LINE__); vt->writeStr("] "); + vt->writeStr("Unhandled Page Fault"); + + *vt << "\n\tPID: " << (int)current_thread->process->pid; + *vt << "\n\tcr2: " << addr; + *vt << "\n\tflags: "; + if (regs->err_code & 0x1) *vt << "present "; + if (regs->err_code & 0x2) *vt << "write "; + if (regs->err_code & 0x4) *vt << "user "; + if (regs->err_code & 0x8) *vt << "rsvd "; + if (regs->err_code & 0x10) *vt << "opfetch "; return 1; } return 0; diff --git a/src/kernel/task/idt.cpp b/src/kernel/task/idt.cpp index e56a51b..94a31b7 100644 --- a/src/kernel/task/idt.cpp +++ b/src/kernel/task/idt.cpp @@ -78,7 +78,7 @@ static struct irq_waiter { /* Called in idt_.asm when an exception fires (interrupt 0 to 31). Tries to handle the exception, panics if fails. */ extern "C" void idt_isrHandler(registers regs) { - if ((regs.int_no == 14 && paging_fault(®s) != 0) || regs.int_no != 14) { + if (regs.int_no != 14 || paging_fault(®s)) { if (tasking_handleException(®s) == 0) { *ke_vt << "\nREALLY BAD THIS TIME\t\tUnhandled exception\t#"; *ke_vt << regs.int_no; diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp index 91f802d..2af0441 100644 --- a/src/kernel/task/task.cpp +++ b/src/kernel/task/task.cpp @@ -104,24 +104,40 @@ void schedule() { /* Called when an exception happens. Provides a stack trace if it was in kernel land. Ends the thread for most exceptions, ends the whole process for page faults. */ uint32_t tasking_handleException(registers *regs) { + node *n = current_thread->process->fd.at(0); + vt *vt = (n && n->as_vt() ? n->as_vt() : ke_vt); + if (current_thread == 0) return 0; //No tasking yet - NL; WHERE; ke_vt->writeStr("Exception: `"); + + vt->writeStr("\n"); + vt->writeStr("[ke:"); vt->writeStr(__FILE__); vt->writeStr(":"); + vt->writeDec(__LINE__); vt->writeStr("] "); + vt->writeStr("Exception: "); + char *exception_messages[] = {"Division By Zero","Debug","Non Maskable Interrupt","Breakpoint", "Into Detected Overflow","Out of Bounds","Invalid Opcode","No Coprocessor", "Double Fault", "Coprocessor Segment Overrun","Bad TSS","Segment Not Present","Stack Fault","General Protection Fault", "Page Fault","Unknown Interrupt","Coprocessor Fault","Alignment Check","Machine Check"}; - *ke_vt << exception_messages[regs->int_no]; - *ke_vt << "'\teip:" << regs->eip; + *vt << exception_messages[regs->int_no];; + *vt << "\n\tPID: " << (int)current_thread->process->pid; + *vt << "\n\teip: " << regs->eip; + if (regs->eip >= K_HIGHHALF_ADDR) { - *ke_vt << "\nException in kernel. Stack trace:\n"; - stack_trace(regs->ebp); + *vt << "\n\tException in kernel."; + stack_trace(regs->ebp); // useless + } + *vt << "\n\tTrace:"; + uint32_t *stack = (uint32_t*)regs->ebp, i; + for (i = 0; i < 7 && (size_t)stack < (regs->ebp + 0x4000) && (size_t) stack >= regs->ebp; i++) { + *vt << "\n\t " << (size_t)stack << " next: " << stack[0] << " ret: " << stack[1]; + stack = (uint32_t*)stack[0]; } - *ke_vt << "\n (PID " << current_thread->process->pid << ") "; + if (regs->int_no == 14) { - *ke_vt << ">>> Process exiting.\n"; + *vt << "\n\tKilling process.\n"; thread_exit_stackJmp(EX_PAGEFAULT); } else { - *ke_vt << ">>> Thread exiting.\n"; + *vt << "\n\tKilling thread.\n"; thread_exit_stackJmp(EX_EXCEPTION); } PANIC("This should never have happened. Please report this."); diff --git a/src/kernel/ui/vt.cpp b/src/kernel/ui/vt.cpp index 6876806..ec18808 100644 --- a/src/kernel/ui/vt.cpp +++ b/src/kernel/ui/vt.cpp @@ -310,7 +310,7 @@ int vt::write(size_t offset, size_t len, char* buffer) { fgcolor &= TC_MAKE_DARK; } else if (n >= 30 && n <= 37) { fgcolor = (fgcolor & TC_MAKE_LIGHT) | (n - 30); - } else if (n >= 40 && n <= 47) { + } else if (n >= 40 && n <= 55) { bgcolor = (n - 40); } else { // others to do. |