initial darwin

This commit is contained in:
rsc 2005-01-07 21:47:30 +00:00
parent 1aa9c533e0
commit 50f7ec339a
5 changed files with 156 additions and 3 deletions

View file

@ -0,0 +1,83 @@
/* get FPR and VR use flags with sc 0x7FF3 */
/* get vsave with mfspr reg, 256 */
.text
.align 2
.globl __setlabel
__setlabel: /* xxx: instruction scheduling */
mflr r0
mfcr r5
mfctr r6
mfxer r7
stw r0, 0*4(r3)
stw r5, 1*4(r3)
stw r6, 2*4(r3)
stw r7, 3*4(r3)
stw r1, 4*4(r3)
stw r2, 5*4(r3)
li r5, 1 /* return value for gotolabel */
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)
li r3, 0 /* return */
blr
.globl __gotolabel
__gotolabel:
lwz r13, (0+7)*4(r3) /* callee-save GPRs */
lwz r14, (1+7)*4(r3) /* xxx: block move */
lwz r15, (2+7)*4(r3)
lwz r16, (3+7)*4(r3)
lwz r17, (4+7)*4(r3)
lwz r18, (5+7)*4(r3)
lwz r19, (6+7)*4(r3)
lwz r20, (7+7)*4(r3)
lwz r21, (8+7)*4(r3)
lwz r22, (9+7)*4(r3)
lwz r23, (10+7)*4(r3)
lwz r24, (11+7)*4(r3)
lwz r25, (12+7)*4(r3)
lwz r26, (13+7)*4(r3)
lwz r27, (14+7)*4(r3)
lwz r28, (15+7)*4(r3)
lwz r29, (16+7)*4(r3)
lwz r30, (17+7)*4(r3)
lwz r31, (18+7)*4(r3)
lwz r1, 4*4(r3)
lwz r2, 5*4(r3)
lwz r0, 0*4(r3)
mtlr r0
lwz r0, 1*4(r3)
mtcr r0 /* mtcrf 0xFF, r0 */
lwz r0, 2*4(r3)
mtctr r0
lwz r0, 3*4(r3)
mtxer r0
lwz r3, 6*4(r4)
blr

View file

@ -0,0 +1,37 @@
#include "threadimpl.h"
void
makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
{
ulong *sp, *tos;
va_list arg;
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;
va_start(arg, argc);
ucp->label.r3 = va_arg(arg, long);
va_end(arg);
}
void
getcontext(ucontext_t *uc)
{
return __setlabel(uc);
}
int
setcontext(ucontext_t *uc)
{
return __gotolabel(uc);
}
int
swapcontext(ucontext_t *oucp, ucontext_t *ucp)
{
if(getcontext(oucp) == 0)
setcontext(ucp);
return 0;
}

View file

@ -0,0 +1,24 @@
typedef struct ucontext ucontext_t;
struct ucontext
{
ulong pc; /* lr */
ulong cr; /* mfcr */
ulong ctr; /* mfcr */
ulong xer; /* mfcr */
ulong sp; /* callee saved: r1 */
ulong toc; /* callee saved: r2 */
ulong r3; /* first arg to function, return register: r3 */
ulong gpr[19]; /* callee saved: r13-r31 */
// XXX: currently do not save vector registers or floating-point state
// ulong pad;
// uvlong fpr[18]; /* callee saved: f14-f31 */
// ulong vr[4*12]; /* callee saved: v20-v31, 256-bits each */
};
void makecontext(ucontext_t*, void(*)(void), int, ...);
void getcontext(ucontext_t*);
int setcontext(ucontext_t*);
int swapcontext(ucontext_t*, ucontext_t*);
int __setlabel(ucontext_t*);
void __gotolabel(ucontext_t*);

View file

@ -1,6 +1,8 @@
#!/bin/sh #!/bin/sh
tag="${OBJTYPE:-`uname -m`}-${SYSNAME:-`uname`}-`uname -r`-${CC9:-cc}" OBJTYPE=${OBJTYPE:-`uname -m | sed 's/Power Macintosh/power/;s/i.86/386/'`}
SYSNAME=${SYSNAME:-`uname`}
tag="$OBJTYPE-$SYSNAME-`uname -r`-${CC9:-cc}"
case "$tag" in case "$tag" in
*-Linux-2.6.*) *-Linux-2.6.*)
echo pthread.o echo pthread.o
@ -9,11 +11,14 @@ case "$tag" in
echo pthread.o echo pthread.o
;; ;;
*-Linux-*) *-Linux-*)
echo `uname`.o `uname`asm.o # will have to fix this for linux power pc
echo $SYSNAME.o ${SYSNAME}asm.o
;; ;;
*-FreeBSD-*) *-FreeBSD-*)
echo `uname`.o `uname`asm.o echo $SYSNAME.o ${SYSNAME}asm.o
;; ;;
*-Darwin-*)
echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o pthread.o
*) *)
echo pthread.o echo pthread.o
esac esac

View file

@ -16,6 +16,10 @@ extern int swapcontext(ucontext_t*, ucontext_t*);
extern void makecontext(ucontext_t*, void(*)(), int, ...); extern void makecontext(ucontext_t*, void(*)(), int, ...);
#endif #endif
#if defined(__APPLE__)
# include "Darwin-ucontext.h"
#endif
typedef struct Context Context; typedef struct Context Context;
typedef struct Execjob Execjob; typedef struct Execjob Execjob;
typedef struct Proc Proc; typedef struct Proc Proc;