123 lines
2.2 KiB
C
123 lines
2.2 KiB
C
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include <sys/kconfig.h>
|
|
#include <sys/kassert.h>
|
|
#include <sys/kdebug.h>
|
|
#include <sys/kmem.h>
|
|
#include <sys/ktime.h>
|
|
#include <sys/spinlock.h>
|
|
#include <sys/irq.h>
|
|
#include <sys/syscall.h>
|
|
#include <sys/mp.h>
|
|
|
|
#include <machine/cpu.h>
|
|
#include <machine/trap.h>
|
|
#include <machine/mp.h>
|
|
|
|
#if defined(_aarch64_)
|
|
#include <dev/arm64/uart.h>
|
|
#endif
|
|
|
|
#include <sys/thread.h>
|
|
|
|
extern uint64_t trap_table[T_MAX];
|
|
extern void trap_pop(TrapFrame *tf);
|
|
extern void Debug_Breakpoint(TrapFrame *tf);
|
|
extern void Debug_HaltIPI(TrapFrame *tf);
|
|
extern void KTimer_Process();
|
|
|
|
static uint64_t intStats[256];
|
|
|
|
void
|
|
Trap_Init()
|
|
{
|
|
int i;
|
|
|
|
kprintf("Initializing IDT... ");
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
intStats[i] = 0;
|
|
}
|
|
|
|
kprintf("Done!\n");
|
|
}
|
|
|
|
void
|
|
Trap_InitAP()
|
|
{
|
|
}
|
|
|
|
void
|
|
Trap_Dump(TrapFrame *tf)
|
|
{
|
|
kprintf("CPU %d\n", CPU());
|
|
kprintf("Interrupt %d Error Code: %016llx\n",
|
|
tf->vector, tf->errcode);
|
|
}
|
|
|
|
void
|
|
Trap_StackDump(TrapFrame *tf)
|
|
{
|
|
uint64_t rsp;
|
|
uint64_t *data;
|
|
|
|
// XXX: This should use safe copy
|
|
for (rsp = tf->rsp; (rsp & 0xFFF) != 0; rsp += 8) {
|
|
data = (uint64_t *)rsp;
|
|
kprintf("%016llx: %016llx\n", rsp, *data);
|
|
}
|
|
}
|
|
|
|
extern int copy_unsafe(void *to, void *from, uintptr_t len);
|
|
extern void copy_unsafe_done(void);
|
|
extern void copy_unsafe_fault(void);
|
|
|
|
extern int copystr_unsafe(void *to, void *from, uintptr_t len);
|
|
extern void copystr_unsafe_done(void);
|
|
extern void copystr_unsafe_fault(void);
|
|
|
|
void
|
|
trap_entry(void)
|
|
{
|
|
uint64_t id;
|
|
__asm__ volatile (
|
|
"mrs %x0, ICC_IAR1_EL1;"
|
|
: "=r" (id)
|
|
:
|
|
:
|
|
);
|
|
|
|
kprintf("Unhandled irq: 0x%x\n", id);
|
|
|
|
if (id == 30) {
|
|
__asm__ volatile (
|
|
"mrs x1, CNTFRQ_EL0;"
|
|
"msr CNTP_TVAL_EL0, x1;"
|
|
"msr ICC_EOIR1_EL1, %x0;"
|
|
"dsb sy;"
|
|
:
|
|
: "r" (id)
|
|
: "x1"
|
|
);
|
|
}
|
|
}
|
|
|
|
static void
|
|
Debug_Traps(int argc, const char *argv[])
|
|
{
|
|
int i;
|
|
|
|
kprintf("Trap Interrupts Trap Interrupts\n");
|
|
for (i = 0; i < T_MAX / 2; i++)
|
|
{
|
|
kprintf("%-4d %-12d %-4d %-12d\n",
|
|
i, intStats[i],
|
|
T_MAX / 2 + i, intStats[T_MAX / 2 + i]);
|
|
}
|
|
}
|
|
|
|
REGISTER_DBGCMD(traps, "Print trap statistics", Debug_Traps);
|
|
|