73 lines
2.0 KiB
C
73 lines
2.0 KiB
C
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include <sys/kassert.h>
|
|
#include <sys/kconfig.h>
|
|
#include <sys/kdebug.h>
|
|
#include <sys/mp.h>
|
|
|
|
#include <machine/amd64.h>
|
|
#include <machine/amd64op.h>
|
|
#include <machine/trap.h>
|
|
|
|
TrapFrame *frames[MAX_CPUS];
|
|
|
|
void
|
|
Debug_Breakpoint(TrapFrame *tf)
|
|
{
|
|
frames[CPU()] = tf;
|
|
|
|
// Stop all processors
|
|
|
|
Debug_Prompt();
|
|
|
|
// Resume all processors
|
|
}
|
|
|
|
void
|
|
Debug_Registers(int argc, const char *argv[])
|
|
{
|
|
TrapFrame *tf = frames[CPU()];
|
|
|
|
kprintf("Interrupt %d Error Code: %016llx\n",
|
|
tf->vector, tf->errcode);
|
|
kprintf("cr0: %016llx cr2: %016llx\n",
|
|
read_cr0(), read_cr2());
|
|
kprintf("cr3: %016llx cr4: %016llx\n",
|
|
read_cr3(), read_cr4());
|
|
kprintf("dr0: %016llx dr1: %016llx dr2: %016llx\n",
|
|
read_dr0(), read_dr1(), read_dr2());
|
|
kprintf("dr3: %016llx dr6: %016llx dr7: %016llx\n",
|
|
read_dr3(), read_dr6(), read_dr7());
|
|
kprintf("rip: %04x:%016llx rsp: %04x:%016llx\n",
|
|
tf->cs, tf->rip, tf->ss, tf->rsp);
|
|
kprintf("rflags: %016llx ds: %04x es: %04x fs: %04x gs: %04x\n",
|
|
tf->rflags, read_ds(), read_es(), read_fs(), read_gs());
|
|
kprintf("rax: %016llx rbx: %016llx rcx: %016llx\n",
|
|
tf->rax, tf->rbx, tf->rcx);
|
|
kprintf("rdx: %016llx rsi: %016llx rdi: %016llx\n",
|
|
tf->rdx, tf->rsi, tf->rdi);
|
|
kprintf("rbp: %016llx r8: %016llx r9: %016llx\n",
|
|
tf->rbp, tf->r8, tf->r9);
|
|
kprintf("r10: %016llx r11: %016llx r12: %016llx\n",
|
|
tf->r10, tf->r11, tf->r12);
|
|
kprintf("r13: %016llx r14: %016llx r15: %016llx\n",
|
|
tf->r13, tf->r14, tf->r15);
|
|
}
|
|
|
|
REGISTER_DBGCMD(registers, "Show CPU registers", Debug_Registers);
|
|
|
|
void
|
|
Debug_Reboot(int argc, const char *argv[])
|
|
{
|
|
/*
|
|
* Triple fault the core by loading a non-canonical address into CR3. We
|
|
* should use ACPI, or even the keyboard controller if it exists.
|
|
*/
|
|
write_cr3(0x8000000000000000ULL);
|
|
}
|
|
|
|
REGISTER_DBGCMD(reboot, "Reboot computer", Debug_Reboot);
|
|
|