2005-01-07 21:47:30 +00:00
|
|
|
#include "threadimpl.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
|
|
|
|
{
|
|
|
|
ulong *sp, *tos;
|
|
|
|
va_list arg;
|
|
|
|
|
|
|
|
tos = (ulong*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(ulong);
|
|
|
|
sp = tos - 16;
|
2005-01-11 17:43:53 +00:00
|
|
|
ucp->mc.pc = (long)func;
|
|
|
|
ucp->mc.sp = (long)sp;
|
2005-01-07 21:47:30 +00:00
|
|
|
va_start(arg, argc);
|
2005-01-11 17:43:53 +00:00
|
|
|
ucp->mc.r3 = va_arg(arg, long);
|
2005-01-07 21:47:30 +00:00
|
|
|
va_end(arg);
|
|
|
|
}
|
|
|
|
|
2005-01-11 17:43:53 +00:00
|
|
|
int
|
2005-01-07 21:47:30 +00:00
|
|
|
getcontext(ucontext_t *uc)
|
|
|
|
{
|
2005-01-11 17:43:53 +00:00
|
|
|
return _getmcontext(&uc->mc);
|
2005-01-07 21:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setcontext(ucontext_t *uc)
|
|
|
|
{
|
2005-01-11 17:43:53 +00:00
|
|
|
_setmcontext(&uc->mc);
|
|
|
|
return 0;
|
2005-01-07 21:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
swapcontext(ucontext_t *oucp, ucontext_t *ucp)
|
|
|
|
{
|
|
|
|
if(getcontext(oucp) == 0)
|
|
|
|
setcontext(ucp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|