ptos/amd64: ps: Add support for CPL 3 processes

Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
2026-07-15 01:10:39 -04:00
parent bda2c510cd
commit 85927ce8c1
4 changed files with 30 additions and 7 deletions
+10
View File
@@ -20,8 +20,12 @@ HalContextSwitch(TRAP_FRAME *Frame)
PROCESS *NextParent;
TCB *ThisTcb, *NextTcb;
KPCR *Kpcr;
MCB *Mcb;
TSS_ENTRY *Tss;
UPTR KStackTop;
Kpcr = HalKpcrCurrent();
Mcb = &Kpcr->Mcb;
ThisThread = Kpcr->CurrentThread;
NextThread = NULL;
@@ -54,6 +58,12 @@ HalContextSwitch(TRAP_FRAME *Frame)
NextParent = NextThread->Parent;
HalMmuWriteVas(&NextParent->Vas);
/* Update the task state segment with kstack */
KStackTop = NextTcb->KStackBase + NextTcb->KStackLength;
Tss = Mcb->Tss;
Tss->Rsp0Low = KStackTop & 0xFFFFFFFF;
Tss->Rsp0High = (KStackTop >> 32) & 0xFFFFFFFF;
/* Context switch here */
Kpcr->CurrentThread = NextThread;
NextTcb = &NextThread->Tcb;
+16 -2
View File
@@ -9,6 +9,7 @@
#include <hal/thread.h>
#include <hal/page.h>
#include <ps/thread.h>
#include <ps/process.h>
#include <machine/gdt.h>
#include <machine/lapic.h>
#include <mm/vm.h>
@@ -44,16 +45,25 @@ static PT_STATUS
ThreadInitTcb(THREAD *Thread, TCB *Tcb, UPTR Ip)
{
TRAP_FRAME *Frame;
PROCESS *Parent;
if (Thread == NULL || Tcb == NULL) {
return STATUS_INVALID_PARAM;
}
Parent = Thread->Parent;
Thread->StackBase = (UPTR)ThreadAllocKStack();
if (Thread->StackBase == 0) {
return STATUS_NO_MEMORY;
}
Tcb->KStackLength = PAGESIZE;
Tcb->KStackBase = (UPTR)ThreadAllocKStack();
if (Tcb->KStackBase == 0) {
/* TODO: Free Thread->StackBase */
return STATUS_NO_MEMORY;
}
/* Zero the whole frame */
Frame = &Tcb->FrameSnapshot;
RtlMemSet(Frame, 0, sizeof(*Frame));
@@ -62,8 +72,12 @@ ThreadInitTcb(THREAD *Thread, TCB *Tcb, UPTR Ip)
Frame->Rflags = 0x202;
Frame->Rsp = Thread->StackBase + PAGESIZE;
Frame->Rip = Ip;
Frame->CodeSeg = GDT_KCODE;
Frame->StackSeg = GDT_KDATA;
Frame->CodeSeg = ISSET(Parent->Flags, PS_USER)
? GDT_UCODE | 3
: GDT_KCODE;
Frame->StackSeg = ISSET(Parent->Flags, PS_USER)
? GDT_UDATA | 3
: GDT_KDATA;
return STATUS_SUCCESS;
}