commit - 6b11fe88cb3dd3a8181f56c24a33e065067d2170
commit + 110c707dda7d14af657a0cc184e60eb42af30c88
blob - /dev/null
blob + 46c96e94c5e55b7e16379bb25a0f1f476cf42586 (mode 644)
--- /dev/null
+++ src/libthread/Darwin-386-asm.s
+.globl _tas
+_tas:
+ movl $0xCAFEBABE, %eax
+ movl 4(%esp), %ecx
+ xchgl %eax, 0(%ecx)
+ ret
+
+.globl _getmcontext
+_getmcontext:
+ movl 4(%esp), %eax
+
+ movl %fs, 8(%eax)
+ movl %es, 12(%eax)
+ movl %ds, 16(%eax)
+ movl %ss, 76(%eax)
+ movl %edi, 20(%eax)
+ movl %esi, 24(%eax)
+ movl %ebp, 28(%eax)
+ movl %ebx, 36(%eax)
+ movl %edx, 40(%eax)
+ movl %ecx, 44(%eax)
+
+ movl $1, 48(%eax) /* %eax */
+ movl (%esp), %ecx /* %eip */
+ movl %ecx, 60(%eax)
+ leal 4(%esp), %ecx /* %esp */
+ movl %ecx, 72(%eax)
+
+ movl 44(%eax), %ecx /* restore %ecx */
+ movl $0, %eax
+ ret
+
+.globl _setmcontext
+_setmcontext:
+ movl 4(%esp), %eax
+
+ movl 8(%eax), %fs
+ movl 12(%eax), %es
+ movl 16(%eax), %ds
+ movl 76(%eax), %ss
+ movl 20(%eax), %edi
+ movl 24(%eax), %esi
+ movl 28(%eax), %ebp
+ movl 36(%eax), %ebx
+ movl 40(%eax), %edx
+ movl 44(%eax), %ecx
+
+ movl 72(%eax), %esp
+ pushl 60(%eax) /* new %eip */
+ movl 48(%eax), %eax
+ ret
+
blob - /dev/null
blob + 3725f264a4ef4f7b132095d58194cc55820437c3 (mode 644)
--- /dev/null
+++ src/libthread/Darwin-386.c
+#include "threadimpl.h"
+
+void
+makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+{
+ int *sp;
+
+ sp = (int*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/4;
+ sp -= argc;
+ memmove(sp, &argc+1, argc*sizeof(int));
+ *--sp = 0; /* return address */
+ ucp->uc_mcontext.mc_eip = (long)func;
+ ucp->uc_mcontext.mc_esp = (int)sp;
+}
+
+int
+swapcontext(ucontext_t *oucp, ucontext_t *ucp)
+{
+ if(getcontext(oucp) == 0)
+ setcontext(ucp);
+ return 0;
+}
+
blob - /dev/null
blob + fa58e0639da561433251899d5ebc70ebe7c2af0c (mode 644)
--- /dev/null
+++ src/libthread/test/tcontext.c
+#include "../threadimpl.h"
+#undef exits
+
+
+ucontext_t c0, c1;
+char stack[65536];
+
+void
+go(void *v)
+{
+ print("hello, world\n");
+ setcontext(&c0);
+}
+
+void
+main(void)
+{
+// print("in main\n");
+ getcontext(&c1);
+ c1.uc_stack.ss_sp = stack;
+ c1.uc_stack.ss_size = sizeof stack;
+ makecontext(&c1, go, 1, 0);
+ if(getcontext(&c0) == 0)
+ setcontext(&c1);
+ print("back in main\n");
+ exits(0);
+}
blob - /dev/null
blob + c5732165cd9ed7d1e8bd4d491d9b0327e877029d (mode 644)
--- /dev/null
+++ src/libthread/test/thello.c
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+
+void
+threadmain(int argc, char **argv)
+{
+ print("hello, world\n");
+}
+
blob - d89a30b9497abae789bcd8e5e32d189b0c456ace
blob + 93f5ac1729259554e878588cc012a91d4e475486
--- src/libthread/thread.c
+++ src/libthread/thread.c
argv0 = argv[0];
+ write(1, "", 0);
if(getenv("NOLIBTHREADDAEMONIZE") == nil)
_threadsetupdaemonize();
_threadsetproc(p);
if(mainstacksize == 0)
mainstacksize = 256*1024;
- atnotify(threadinfo, 1);
+// atnotify(threadinfo, 1);
_threadcreate(p, threadmainstart, nil, mainstacksize);
procscheduler(p);
sysfatal("procscheduler returned in threadmain!");
blob - d1f3e9383dc3091aeed3b2ba3c792a1b1ad45ee9
blob + 12b8a9988078af36ad1c9080784f51c1eda9be2a
--- src/libthread/threadimpl.h
+++ src/libthread/threadimpl.h
# define mcontext_t libthread_mcontext_t
# define ucontext libthread_ucontext
# define ucontext_t libthread_ucontext_t
-# include "power-ucontext.h"
+# if defined(__i386__)
+# include "386-ucontext.h"
+# else
+# include "power-ucontext.h"
+# endif
#endif
#if defined(__OpenBSD__)