diff --git a/arch/x86_64/irq.c b/arch/x86_64/irq.c index a7a0810..592fd8b 100644 --- a/arch/x86_64/irq.c +++ b/arch/x86_64/irq.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #define MAX_ISR_HANDLERS 16 @@ -166,6 +167,12 @@ int idt_load(struct idt_ptr *ptr) void isr_dispatch(struct ml_cpu_context *regs) { + struct thread *thr = get_current_thread(); + if (thr) { + thr->tr_irqctx = regs; + put_current_thread(thr); + } + int_hook h = isr_handlers[regs->int_no]; if (h) { h(regs); @@ -188,6 +195,13 @@ void irq_dispatch(struct ml_cpu_context *regs) end_charge_period(); irq_ack(regs->int_no); + + struct thread *thr = get_current_thread(); + if (thr) { + thr->tr_irqctx = regs; + put_current_thread(thr); + } + struct queue *hooks = &irq_hooks[regs->int_no - IRQ0]; queue_foreach(struct irq_hook, hook, hooks, irq_entry) { diff --git a/include/kernel/thread.h b/include/kernel/thread.h index acdaf03..1d6969d 100644 --- a/include/kernel/thread.h +++ b/include/kernel/thread.h @@ -8,6 +8,8 @@ #define THREAD_KSTACK_ORDER VM_PAGE_4K +struct ml_cpu_context; + enum thread_state { THREAD_READY = 1, THREAD_SLEEPING = 2, @@ -39,6 +41,9 @@ struct thread { virt_addr_t tr_ip, tr_sp, tr_bp; virt_addr_t tr_cpu_user_sp, tr_cpu_kernel_sp; + /* only valid within an interrupt or syscall context */ + struct ml_cpu_context *tr_irqctx; + struct ml_thread tr_ml; struct runqueue *tr_rq;