From a029f0de5d447e38f8432875a0eb30925c1a333b Mon Sep 17 00:00:00 2001 From: Chloe M Date: Tue, 14 Jul 2026 16:40:06 -0400 Subject: [PATCH] ptos/amd64: ps: Add context switching stub Signed-off-by: Chloe M --- service/ptos/arch/amd64/ps/context.c | 16 ++++++++++++++++ service/ptos/arch/amd64/ps/thread.c | 7 +++++++ service/ptos/head/hal/context.h | 22 ++++++++++++++++++++++ service/ptos/head/hal/thread.h | 7 +++++++ service/ptos/head/ke/sched.h | 3 +++ service/ptos/ke/init.c | 10 ++++++++++ 6 files changed, 65 insertions(+) create mode 100644 service/ptos/arch/amd64/ps/context.c create mode 100644 service/ptos/head/hal/context.h diff --git a/service/ptos/arch/amd64/ps/context.c b/service/ptos/arch/amd64/ps/context.c new file mode 100644 index 0000000..2919d75 --- /dev/null +++ b/service/ptos/arch/amd64/ps/context.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: MD context management + * Author: Chloe M. + */ + +#include +#include + +VOID +HalContextSwitch(TRAP_FRAME *Frame) +{ + TRACE("CONTEXT SWITCHING IS A TODO\n"); +} diff --git a/service/ptos/arch/amd64/ps/thread.c b/service/ptos/arch/amd64/ps/thread.c index affb1f1..449aec2 100644 --- a/service/ptos/arch/amd64/ps/thread.c +++ b/service/ptos/arch/amd64/ps/thread.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -79,3 +80,9 @@ HalThreadInit(THREAD *Thread, ULONG Flags, UPTR Ip) ThreadInitTcb(Thread, Tcb, Ip); return STATUS_SUCCESS; } + +VOID +HalPrimeThreadTimer(ULONG Usec) +{ + MdLapicTimerOneshotUs(Usec); +} diff --git a/service/ptos/head/hal/context.h b/service/ptos/head/hal/context.h new file mode 100644 index 0000000..2f7a56d --- /dev/null +++ b/service/ptos/head/hal/context.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: HAL context management + * Author: Chloe M. + */ + +#ifndef _HAL_CONTEXT_H_ +#define _HAL_CONTEXT_H_ 1 + +#include +#include + +/* + * Perform a context switch from one thread to another + * + * @Frame: Current processor context + */ +VOID HalContextSwitch(TRAP_FRAME *Frame); + +#endif /* !_HAL_CONTEXT_H_ */ diff --git a/service/ptos/head/hal/thread.h b/service/ptos/head/hal/thread.h index 3121451..ce90b39 100644 --- a/service/ptos/head/hal/thread.h +++ b/service/ptos/head/hal/thread.h @@ -22,4 +22,11 @@ */ PT_STATUS HalThreadInit(THREAD *Thread, ULONG Flags, UPTR Ip); +/* + * Prime the scheduler timer + * + * @Usec: Number of microseconds to prime for + */ +VOID HalPrimeThreadTimer(ULONG Usec); + #endif /* !_HAL_THREAD_H_ */ diff --git a/service/ptos/head/ke/sched.h b/service/ptos/head/ke/sched.h index a9f54f3..176badc 100644 --- a/service/ptos/head/ke/sched.h +++ b/service/ptos/head/ke/sched.h @@ -14,6 +14,9 @@ #include #include +/* Minimum scheduler quantum in microseconds */ +#define SCHED_MIN_QUANTUM 900 + /* * Represents a scheduler queue that threads can be pulled * from and added to. diff --git a/service/ptos/ke/init.c b/service/ptos/ke/init.c index 7b31a0d..43c1b58 100644 --- a/service/ptos/ke/init.c +++ b/service/ptos/ke/init.c @@ -9,11 +9,14 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -95,4 +98,11 @@ KiKernelInit(VOID) /* Initialize the root process */ InitializeRootProcess(); + + /* Prime the scheduler timer */ + HalPrimeThreadTimer(SCHED_MIN_QUANTUM); + + for (;;) { + HalCpuSpinWait(); + } }