69 lines
1.3 KiB
C
69 lines
1.3 KiB
C
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#include <sys/kconfig.h>
|
|
#include <sys/kassert.h>
|
|
#include <sys/kmem.h>
|
|
#include <sys/mp.h>
|
|
#include <sys/thread.h>
|
|
|
|
#include <machine/cpu.h>
|
|
#include <machine/cpuop.h>
|
|
#include <machine/trap.h>
|
|
#include <machine/pmap.h>
|
|
|
|
extern void ThreadKThreadEntry(TrapFrame *tf);
|
|
extern void switchstack(uint64_t *oldrsp, uint64_t rsp);
|
|
|
|
void
|
|
Thread_InitArch(Thread *thr)
|
|
{
|
|
thr->arch.useFP = true;
|
|
}
|
|
|
|
void
|
|
Thread_SetupKThread(Thread *thr, UNUSED void (*f)(void *),
|
|
UNUSED uintptr_t arg1, UNUSED uintptr_t arg2, UNUSED uintptr_t arg3)
|
|
{
|
|
// Initialize stack
|
|
uint64_t stacktop = thr->kstack + PGSIZE;
|
|
ThreadArchStackFrame *sf;
|
|
TrapFrame *tf;
|
|
|
|
tf = (TrapFrame *)(stacktop - sizeof(*tf));
|
|
sf = (ThreadArchStackFrame *)(stacktop - sizeof(*tf) - sizeof(*sf));
|
|
|
|
memset(tf, 0, sizeof(*tf));
|
|
memset(sf, 0, sizeof(*sf));
|
|
|
|
// Setup thread exit function on stack
|
|
|
|
}
|
|
|
|
static void
|
|
ThreadEnterUserLevelCB(UNUSED void * unused)
|
|
{
|
|
TrapFrame tf;
|
|
|
|
memset(&tf, 0, sizeof(tf));
|
|
|
|
//Trap_Pop(&tf);
|
|
}
|
|
|
|
void
|
|
Thread_SetupUThread(Thread *thr, uintptr_t rip, uintptr_t arg)
|
|
{
|
|
Thread_SetupKThread(thr, ThreadEnterUserLevelCB, rip,
|
|
thr->ustack, arg);
|
|
}
|
|
|
|
void
|
|
Thread_SwitchArch(Thread *oldthr, Thread *newthr)
|
|
{
|
|
// Jump to trapframe
|
|
switchstack(&oldthr->arch.rsp, newthr->arch.rsp);
|
|
}
|
|
|