#include <9pm/windows.h>
#include <9pm/u.h>
#include <9pm/libc.h>
#include "dat.h"
#include "fns.h"

__declspec(naked)
static 
void
linkproc(void)
{
	up->kpfun(up->kparg);
}

void
kprocchild(Proc* p, void (*func)(void*), void* arg)
{
	/*
	 * gotolabel() needs a word on the stack in
	 * which to place the return PC used to jump
	 * to linkproc().
	 */
	p->sched.jb[JMPBUFPC] = (ulong)linkproc+JMPBUFDPC;
	p->sched.jb[JMPBUFSP] = (ulong)p->kstack+KSTACK-8;
	p->kpfun = func;
	p->kparg = arg;
}

