Blob


1 #include "threadimpl.h"
3 static void
4 launchersparc(uint o0, uint o1, uint o2, uint o3,
5 uint o4, uint o5, uint o6, uint o7,
6 void (*f)(void *arg), void *arg)
7 {
8 if(0) print("ls %x %x %x %x %x %x %x %x %x %x at %x\n",
9 o0, o1, o2, o3, o4, o5, o6, o7, f, arg, &o0);
10 (*f)(arg);
11 threadexits(nil);
12 }
14 void
15 _threadinitstack(Thread *t, void (*f)(void*), void *arg)
16 {
17 ulong *tos, *stk;
19 /*
20 * This is a bit more complicated than it should be,
21 * because we need to set things up so that gotolabel
22 * (which executes a return) gets us into launchersparc.
23 * So all the registers are going to be renamed before
24 * we get there. The input registers here become the
25 * output registers there, which is useless.
26 * The input registers there are inaccessible, so we
27 * have to give launchersparc enough arguments that
28 * everything ends up in the stack.
29 */
30 tos = (ulong*)&t->stk[t->stksize&~7];
31 stk = tos;
32 --stk;
33 *--stk = (ulong)arg;
34 *--stk = (ulong)f;
35 stk -= 25; /* would love to understand this */
36 t->sched.link = (ulong)launchersparc - 8;
37 t->sched.input[6] = 0;
38 t->sched.sp = (ulong)stk;
39 if(0) print("tis %x %x at %x\n", f, arg, t->sched.sp);
40 }