diff options
author | rsc <devnull@localhost> | 2005-01-11 17:43:53 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-01-11 17:43:53 +0000 |
commit | b8f742db850ffc99333a97ab54fc820c6de0fd98 (patch) | |
tree | 9096b9872c0e65a3f1f3cdd7b993c58411d20e5e /src/libthread | |
parent | 530d00164177fd68e2aeb403e7b9be31823e3168 (diff) | |
download | plan9port-b8f742db850ffc99333a97ab54fc820c6de0fd98.tar.gz plan9port-b8f742db850ffc99333a97ab54fc820c6de0fd98.tar.bz2 plan9port-b8f742db850ffc99333a97ab54fc820c6de0fd98.zip |
os x changes
Diffstat (limited to 'src/libthread')
-rw-r--r-- | src/libthread/Darwin-power-asm.s | 50 | ||||
-rw-r--r-- | src/libthread/Darwin-power.c | 13 | ||||
-rw-r--r-- | src/libthread/Darwin-ucontext.h | 19 | ||||
-rw-r--r-- | src/libthread/thread.c | 15 | ||||
-rw-r--r-- | src/libthread/threadimpl.h | 4 |
5 files changed, 64 insertions, 37 deletions
diff --git a/src/libthread/Darwin-power-asm.s b/src/libthread/Darwin-power-asm.s index 0776b1e3..a064b5ea 100644 --- a/src/libthread/Darwin-power-asm.s +++ b/src/libthread/Darwin-power-asm.s @@ -4,9 +4,9 @@ .text .align 2 -.globl __setlabel +.globl __getmcontext -__setlabel: /* xxx: instruction scheduling */ +__getmcontext: /* xxx: instruction scheduling */ mflr r0 mfcr r5 mfctr r6 @@ -18,35 +18,35 @@ __setlabel: /* xxx: instruction scheduling */ stw r1, 4*4(r3) stw r2, 5*4(r3) - li r5, 1 /* return value for gotolabel */ + li r5, 1 /* return value for setmcontext */ stw r5, 6*4(r3) - stw r13, (0+6)*4(r3) /* callee-save GPRs */ - stw r14, (1+6)*4(r3) /* xxx: block move */ - stw r15, (2+6)*4(r3) - stw r16, (3+6)*4(r3) - stw r17, (4+6)*4(r3) - stw r18, (5+6)*4(r3) - stw r19, (6+6)*4(r3) - stw r20, (7+6)*4(r3) - stw r21, (8+6)*4(r3) - stw r22, (9+6)*4(r3) - stw r23, (10+6)*4(r3) - stw r24, (11+6)*4(r3) - stw r25, (12+6)*4(r3) - stw r26, (13+6)*4(r3) - stw r27, (14+6)*4(r3) - stw r28, (15+6)*4(r3) - stw r29, (16+6)*4(r3) - stw r30, (17+6)*4(r3) - stw r31, (18+6)*4(r3) + stw r13, (0+7)*4(r3) /* callee-save GPRs */ + stw r14, (1+7)*4(r3) /* xxx: block move */ + stw r15, (2+7)*4(r3) + stw r16, (3+7)*4(r3) + stw r17, (4+7)*4(r3) + stw r18, (5+7)*4(r3) + stw r19, (6+7)*4(r3) + stw r20, (7+7)*4(r3) + stw r21, (8+7)*4(r3) + stw r22, (9+7)*4(r3) + stw r23, (10+7)*4(r3) + stw r24, (11+7)*4(r3) + stw r25, (12+7)*4(r3) + stw r26, (13+7)*4(r3) + stw r27, (14+7)*4(r3) + stw r28, (15+7)*4(r3) + stw r29, (16+7)*4(r3) + stw r30, (17+7)*4(r3) + stw r31, (18+7)*4(r3) li r3, 0 /* return */ blr -.globl __gotolabel +.globl __setmcontext -__gotolabel: +__setmcontext: lwz r13, (0+7)*4(r3) /* callee-save GPRs */ lwz r14, (1+7)*4(r3) /* xxx: block move */ lwz r15, (2+7)*4(r3) @@ -79,5 +79,5 @@ __gotolabel: lwz r0, 3*4(r3) mtxer r0 - lwz r3, 6*4(r4) + lwz r3, 6*4(r3) blr diff --git a/src/libthread/Darwin-power.c b/src/libthread/Darwin-power.c index 373cc623..e625626c 100644 --- a/src/libthread/Darwin-power.c +++ b/src/libthread/Darwin-power.c @@ -8,23 +8,24 @@ makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) tos = (ulong*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(ulong); sp = tos - 16; - ucp->label.pc = (long)func; - ucp->label.sp = (long)sp; + ucp->mc.pc = (long)func; + ucp->mc.sp = (long)sp; va_start(arg, argc); - ucp->label.r3 = va_arg(arg, long); + ucp->mc.r3 = va_arg(arg, long); va_end(arg); } -void +int getcontext(ucontext_t *uc) { - return __setlabel(uc); + return _getmcontext(&uc->mc); } int setcontext(ucontext_t *uc) { - return __gotolabel(uc); + _setmcontext(&uc->mc); + return 0; } int diff --git a/src/libthread/Darwin-ucontext.h b/src/libthread/Darwin-ucontext.h index c7915ff8..a39be28a 100644 --- a/src/libthread/Darwin-ucontext.h +++ b/src/libthread/Darwin-ucontext.h @@ -1,5 +1,6 @@ +typedef struct mcontext mcontext_t; typedef struct ucontext ucontext_t; -struct ucontext +struct mcontext { ulong pc; /* lr */ ulong cr; /* mfcr */ @@ -15,10 +16,20 @@ struct ucontext // ulong vr[4*12]; /* callee saved: v20-v31, 256-bits each */ }; +struct ucontext +{ + struct { + void *ss_sp; + uint ss_size; + } uc_stack; + sigset_t uc_sigmask; + mcontext_t mc; +}; + void makecontext(ucontext_t*, void(*)(void), int, ...); -void getcontext(ucontext_t*); +int getcontext(ucontext_t*); int setcontext(ucontext_t*); int swapcontext(ucontext_t*, ucontext_t*); -int __setlabel(ucontext_t*); -void __gotolabel(ucontext_t*); +int _getmcontext(mcontext_t*); +void _setmcontext(mcontext_t*); diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 120e6514..550cc056 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -27,6 +27,11 @@ _threaddebug(char *fmt, ...) static int fd = -1; return; + va_start(arg, fmt); + vfprint(1, fmt, arg); + va_end(arg); +return; + if(fd < 0){ p = strrchr(argv0, '/'); if(p) @@ -77,9 +82,11 @@ threadstart(void *v) _Thread *t; t = v; +//print("threadstart %p\n", v); t->startfn(t->startarg); - memset(&v, 0xff, 32); /* try to cut off stack traces */ +//print("threadexits %p\n", v); threadexits(nil); +//print("not reacehd\n"); } static _Thread* @@ -156,6 +163,7 @@ _threadswitch(void) Proc *p; p = proc(); +//print("threadswtch %p\n", p); contextswitch(&p->thread->context, &p->schedcontext); } @@ -217,7 +225,7 @@ scheduler(Proc *p) setproc(p); _threaddebug("scheduler enter"); - // print("s %p %d\n", p, gettid()); +// print("s %p\n", p); lock(&p->lock); for(;;){ while((t = p->runqueue.head) == nil){ @@ -234,11 +242,13 @@ scheduler(Proc *p) p->nswitch++; _threaddebug("run %d (%s)", t->id, t->name); contextswitch(&p->schedcontext, &t->context); +//print("back in scheduler\n"); p->thread = nil; lock(&p->lock); if(t->exiting){ delthreadinproc(p, t); p->nthread--; +//print("ntrhead %d\n", p->nthread); free(t); } } @@ -313,6 +323,7 @@ threadsetstate(char *fmt, ...) static int threadqlock(QLock *l, int block, ulong pc) { +//print("threadqlock %p\n", l); lock(&l->l); if(l->owner == nil){ l->owner = (*threadnow)(); diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h index 0334fe30..842b81d8 100644 --- a/src/libthread/threadimpl.h +++ b/src/libthread/threadimpl.h @@ -17,6 +17,10 @@ extern void makecontext(ucontext_t*, void(*)(), int, ...); #endif #if defined(__APPLE__) +# define mcontext libthread_mcontext +# define mcontext_t libthread_mcontext_t +# define ucontext libthread_ucontext +# define ucontext_t libthread_ucontext_t # include "Darwin-ucontext.h" #endif |