os x changes

This commit is contained in:
rsc 2005-01-11 17:43:53 +00:00
parent 530d001641
commit b8f742db85
18 changed files with 92 additions and 44 deletions

View file

@ -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

View file

@ -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

View file

@ -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*);

View file

@ -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)();

View file

@ -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