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
+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;
}