rsc | cea1000 | 2005-05-01 18:38:12 +0000 | [diff] [blame] | 1 | #include "threadimpl.h" |
| 2 | |
| 3 | void |
| 4 | makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) |
| 5 | { |
| 6 | ulong *sp, *tos; |
| 7 | va_list arg; |
| 8 | |
| 9 | tos = (ulong*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(ulong); |
| 10 | sp = (ulong*)((ulong)(tos-16) & ~15); |
| 11 | ucp->mc.pc = (long)func; |
| 12 | ucp->mc.sp = (long)sp; |
| 13 | va_start(arg, argc); |
| 14 | ucp->mc.r3 = va_arg(arg, long); |
| 15 | va_end(arg); |
| 16 | } |
| 17 | |
| 18 | int |
| 19 | getcontext(ucontext_t *uc) |
| 20 | { |
| 21 | return _getmcontext(&uc->mc); |
| 22 | } |
| 23 | |
| 24 | int |
| 25 | setcontext(ucontext_t *uc) |
| 26 | { |
| 27 | _setmcontext(&uc->mc); |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | int |
| 32 | swapcontext(ucontext_t *oucp, ucontext_t *ucp) |
| 33 | { |
| 34 | if(getcontext(oucp) == 0) |
| 35 | setcontext(ucp); |
| 36 | return 0; |
| 37 | } |
| 38 | |