darwin 386 start
This commit is contained in:
parent
6b11fe88cb
commit
110c707dda
6 changed files with 119 additions and 2 deletions
52
src/libthread/Darwin-386-asm.s
Normal file
52
src/libthread/Darwin-386-asm.s
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
.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
|
||||||
|
|
||||||
23
src/libthread/Darwin-386.c
Normal file
23
src/libthread/Darwin-386.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
27
src/libthread/test/tcontext.c
Normal file
27
src/libthread/test/tcontext.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
10
src/libthread/test/thello.c
Normal file
10
src/libthread/test/thello.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#include <thread.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
threadmain(int argc, char **argv)
|
||||||
|
{
|
||||||
|
print("hello, world\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -624,6 +624,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
argv0 = argv[0];
|
argv0 = argv[0];
|
||||||
|
|
||||||
|
write(1, "", 0);
|
||||||
if(getenv("NOLIBTHREADDAEMONIZE") == nil)
|
if(getenv("NOLIBTHREADDAEMONIZE") == nil)
|
||||||
_threadsetupdaemonize();
|
_threadsetupdaemonize();
|
||||||
|
|
||||||
|
|
@ -651,7 +652,7 @@ main(int argc, char **argv)
|
||||||
_threadsetproc(p);
|
_threadsetproc(p);
|
||||||
if(mainstacksize == 0)
|
if(mainstacksize == 0)
|
||||||
mainstacksize = 256*1024;
|
mainstacksize = 256*1024;
|
||||||
atnotify(threadinfo, 1);
|
// atnotify(threadinfo, 1);
|
||||||
_threadcreate(p, threadmainstart, nil, mainstacksize);
|
_threadcreate(p, threadmainstart, nil, mainstacksize);
|
||||||
procscheduler(p);
|
procscheduler(p);
|
||||||
sysfatal("procscheduler returned in threadmain!");
|
sysfatal("procscheduler returned in threadmain!");
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,11 @@ extern void makecontext(ucontext_t*, void(*)(), int, ...);
|
||||||
# define mcontext_t libthread_mcontext_t
|
# define mcontext_t libthread_mcontext_t
|
||||||
# define ucontext libthread_ucontext
|
# define ucontext libthread_ucontext
|
||||||
# define ucontext_t libthread_ucontext_t
|
# define ucontext_t libthread_ucontext_t
|
||||||
|
# if defined(__i386__)
|
||||||
|
# include "386-ucontext.h"
|
||||||
|
# else
|
||||||
# include "power-ucontext.h"
|
# include "power-ucontext.h"
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue