xref: /plan9/sys/src/libthread/amd64.c (revision ab3dc52f122c98aa4bc2bd64bd2292bb7b80fba2)
1 #include <u.h>
2 #include <libc.h>
3 #include <thread.h>
4 #include "threadimpl.h"
5 
6 /* first argument goes in a register; simplest just to ignore it */
7 static void
launcheramd64(int,void (* f)(void * arg),void * arg)8 launcheramd64(int, void (*f)(void *arg), void *arg)
9 {
10 	(*f)(arg);
11 	threadexits(nil);
12 }
13 
14 void
_threadinitstack(Thread * t,void (* f)(void *),void * arg)15 _threadinitstack(Thread *t, void (*f)(void*), void *arg)
16 {
17 	uvlong *tos;
18 
19 	tos = (uvlong*)&t->stk[t->stksize&~7];
20 	*--tos = (uvlong)arg;
21 	*--tos = (uvlong)f;
22 	*--tos = 0;	/* first arg to launcheramd64 */
23 	t->sched[JMPBUFPC] = (uvlong)launcheramd64+JMPBUFDPC;
24 	t->sched[JMPBUFSP] = (uvlong)tos - 2*8;		/* old PC and new PC */
25 }
26 
27