vbos/amd64/kernel/proc.c
Michael Shaw 9fed595abc Makefile: add module support
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-20 16:43:00 -04:00

48 lines
1 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <arch/proc.h>
#include <arch/page.h>
#include <kernel/proc.h>
#include "arch/msr.h"
struct cpu_local *tls_get()
{
return (void *)rdmsr(IA32_GS_BASE);
}
struct thread *get_cur_thread()
{
struct cpu_local *l = tls_get();
if (!l)
return NULL;
if (!l->cur_thread)
return NULL;
return l->cur_thread;
}
struct proc *get_cur_proc()
{
struct thread *t = get_cur_thread();
if (!t)
return NULL;
return t->proc;
}
/* the thread that calls this will be lost, so it should only be called
* on the initial process, and while doing an exec
*/
void enter_userspace_init(struct thread *thread, uaddr_t entry)
{
struct cpu_local *tls = tls_get();
tls->cur_thread = thread;
void *kstack = kalloc(PAGE_SIZE, ALLOC_KERN);
tls->kernel_rsp = (vaddr_t)kstack + PAGE_SIZE;
pgd_load(thread->proc->pgd);
thread->state = PROC_STATE_RUNNING;
void _enter_userspace_init(uaddr_t entry, u64 flags, uaddr_t stack_top);
_enter_userspace_init(entry, 0x202, thread->stack_addr);
}