sched: thread: add cpu context pointer usable during interrupts and syscalls

This commit is contained in:
2026-04-01 18:22:23 +01:00
parent 7bcd1577be
commit 876f91d8be
2 changed files with 19 additions and 0 deletions
+14
View File
@@ -8,6 +8,7 @@
#include <kernel/panic.h>
#include <kernel/sched.h>
#include <kernel/syscall.h>
#include <kernel/thread.h>
#include <stddef.h>
#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)
{
+5
View File
@@ -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;