summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/interrupts/isr.c
diff options
context:
space:
mode:
authordzwdz2024-08-02 15:44:24 +0200
committerdzwdz2024-08-02 15:44:24 +0200
commit974c2581c9524aa7546f5863ecc26065e328cd54 (patch)
tree3cec6690bb1642d380cdee8749742ada926ce4d4 /src/kernel/arch/amd64/interrupts/isr.c
parente818cab3f1fc4a3d4d0b8e2c9424fb2e7b1dff70 (diff)
kernel/interrupts: use UserRegs in the isr handler
Diffstat (limited to 'src/kernel/arch/amd64/interrupts/isr.c')
-rw-r--r--src/kernel/arch/amd64/interrupts/isr.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/kernel/arch/amd64/interrupts/isr.c b/src/kernel/arch/amd64/interrupts/isr.c
index bf84c5c..15993b2 100644
--- a/src/kernel/arch/amd64/interrupts/isr.c
+++ b/src/kernel/arch/amd64/interrupts/isr.c
@@ -19,6 +19,13 @@ typedef struct {
uint64_t sp, ss;
} IretFrame;
+typedef struct IsrFrame {
+ UserRegs regs; /* doesn't include ip, flags, sp */
+ uint64_t _retaddr;
+ uint64_t errcode;
+ IretFrame iret;
+} __attribute__((packed)) IsrFrame;
+
void (*irq_fn[16])(void) = {0};
static uint64_t
@@ -30,12 +37,11 @@ getcr2(void)
}
static void
-log_interrupt(uint8_t inr, void *stackframe)
+log_interrupt(uint8_t inr, IsrFrame *sf)
{
- IretFrame *iret = stackframe;
- uint64_t *errcode = ((uint64_t*)stackframe) - 1;
+ IretFrame *iret = &sf->iret;
kprintf("interrupt %d, rip = k/%08x, cs 0x%x, code 0x%x\n",
- inr, iret->ip, iret->cs, *errcode);
+ inr, iret->ip, iret->cs, sf->errcode);
if ((iret->cs & 0x3) == 0) { /* ring 0? */
uint64_t *stack = (void*)iret->sp;
kprintf("kernel rsp = %p, *rsp = %p\n", stack, *stack);
@@ -46,9 +52,9 @@ log_interrupt(uint8_t inr, void *stackframe)
}
void
-isr_stage3(uint8_t inr, void *stackframe)
+isr_stage3(uint8_t inr, IsrFrame *sf)
{
- IretFrame *iret = stackframe;
+ IretFrame *iret = &sf->iret;
uint8_t irqn = inr - IRQ_IBASE;
if (irqn < 16) {
if (irq_fn[irqn]) {
@@ -59,13 +65,13 @@ isr_stage3(uint8_t inr, void *stackframe)
}
if (inr == Nmi) { /* print some debugging information */
- log_interrupt(inr, stackframe);
+ log_interrupt(inr, sf);
mem_debugprint();
return;
}
if ((iret->cs & 0x3) == 0) { /* ring 0? */
- log_interrupt(inr, stackframe);
+ log_interrupt(inr, sf);
cpu_halt();
} else { /* in user */
proc_kill(proc_cur, inr);