diff options
Diffstat (limited to 'lib')
26 files changed, 176 insertions, 942 deletions
diff --git a/lib/libc_r/arch/alpha/uthread_machdep.h b/lib/libc_r/arch/alpha/uthread_machdep.h index 9a7c52da977..3c159c84b99 100644 --- a/lib/libc_r/arch/alpha/uthread_machdep.h +++ b/lib/libc_r/arch/alpha/uthread_machdep.h @@ -1,68 +1,6 @@ -/* - * OpenBSD/alpha machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.5 1999/11/25 07:01:27 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.6 2000/10/04 05:55:33 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ -do { \ - __asm__( \ - "stt $f8, ( 0 * 8) + %0\n\tstt $f9, ( 1 * 8) + %0\n\t" \ - "stt $f10, ( 2 * 8) + %0\n\tstt $f11, ( 3 * 8) + %0\n\t" \ - "stt $f12, ( 4 * 8) + %0\n\tstt $f13, ( 5 * 8) + %0\n\t" \ - "stt $f14, ( 6 * 8) + %0\n\tstt $f15, ( 7 * 8) + %0\n\t" \ - "stt $f16, ( 8 * 8) + %0\n\tstt $f17, ( 9 * 8) + %0\n\t" \ - "stt $f18, (10 * 8) + %0\n\tstt $f19, (11 * 8) + %0\n\t" \ - "stt $f20, (12 * 8) + %0\n\tstt $f21, (13 * 8) + %0\n\t" \ - "stt $f22, (14 * 8) + %0\n\tstt $f23, (15 * 8) + %0\n\t" \ - "stt $f24, (16 * 8) + %0\n\tstt $f25, (17 * 8) + %0\n\t" \ - "stt $f26, (18 * 8) + %0\n\tstt $f27, (19 * 8) + %0\n\t" \ - "stt $f28, (20 * 8) + %0\n\tstt $f29, (21 * 8) + %0\n\t" \ - "stt $f30, (22 * 8) + %0" \ - : : "o" ((thr)->_machdep.saved_fp) : "memory"); \ -} while(0) - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ -do { \ - __asm__( \ - "ldt $f8, ( 0 * 8) + %0\n\tldt $f9, ( 1 * 8) + %0\n\t" \ - "ldt $f10, ( 2 * 8) + %0\n\tldt $f11, ( 3 * 8) + %0\n\t" \ - "ldt $f12, ( 4 * 8) + %0\n\tldt $f13, ( 5 * 8) + %0\n\t" \ - "ldt $f14, ( 6 * 8) + %0\n\tldt $f15, ( 7 * 8) + %0\n\t" \ - "ldt $f16, ( 8 * 8) + %0\n\tldt $f17, ( 9 * 8) + %0\n\t" \ - "ldt $f18, (10 * 8) + %0\n\tldt $f19, (11 * 8) + %0\n\t" \ - "ldt $f20, (12 * 8) + %0\n\tldt $f21, (13 * 8) + %0\n\t" \ - "ldt $f22, (14 * 8) + %0\n\tldt $f23, (15 * 8) + %0\n\t" \ - "ldt $f24, (16 * 8) + %0\n\tldt $f25, (17 * 8) + %0\n\t" \ - "ldt $f26, (18 * 8) + %0\n\tldt $f27, (19 * 8) + %0\n\t" \ - "ldt $f28, (20 * 8) + %0\n\tldt $f29, (21 * 8) + %0\n\t" \ - "ldt $f30, (22 * 8) + %0\n\t" \ - : : "o" (thr->_machdep.saved_fp) : \ - "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", \ - "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", \ - "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30"); \ -} while(0) - -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[2] = (long) entry; \ - (thr)->saved_jmp_buf[4 + R_RA] = 0; \ - (thr)->saved_jmp_buf[4 + R_T12] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[4 + R_SP] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - char saved_fp[23 * 8]; +struct _machdep_state { + int fp; }; diff --git a/lib/libc_r/arch/hppa/uthread_machdep.h b/lib/libc_r/arch/hppa/uthread_machdep.h index 0d80d718ded..a1d8eeb4913 100644 --- a/lib/libc_r/arch/hppa/uthread_machdep.h +++ b/lib/libc_r/arch/hppa/uthread_machdep.h @@ -1,40 +1 @@ -/* - * OpenBSD/hppa machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.3 1999/11/25 07:01:27 d Exp $$ - */ - -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* fsave privileged instr */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* frestore privileged instr */ \ - } - -/* initialise the jmpbuf stack frame so it continues from entry */ - -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[5] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[2] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* char saved_fp[108]; */ - int dummy; -}; - +/* $OpenBSD: uthread_machdep.h,v 1.4 2000/10/04 05:55:33 d Exp $ */ diff --git a/lib/libc_r/arch/i386/uthread_machdep.h b/lib/libc_r/arch/i386/uthread_machdep.h index dab5c413932..22d48624d0d 100644 --- a/lib/libc_r/arch/i386/uthread_machdep.h +++ b/lib/libc_r/arch/i386/uthread_machdep.h @@ -1,89 +1,10 @@ -/* - * OpenBSD/i386 machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.6 1999/11/25 07:01:28 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.7 2000/10/04 05:55:34 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ #include <machine/reg.h> -/* - * We need to extend jmp_buf to hold extended segment registers - * for WINE. - */ -typedef struct _machdep_jmp_buf { - union { - jmp_buf jb; - struct { - int eip; - int ebx; - int esp; - int ebp; - int esi; - int edi; - } jbs; - } u; -#define mjb_eip u.jbs.eip -#define mjb_ebx u.jbs.ebx -#define mjb_esp u.jbs.esp -#define mjb_ebp u.jbs.ebp -#define mjb_esi u.jbs.esi -#define mjb_edi u.jbs.edi - int mjb_ds; /* informational only - not restored */ - int mjb_es; /* informational only - not restored */ - int mjb_fs; - int mjb_gs; -} _machdep_jmp_buf; - -/* Extra machine-dependent information */ -struct _machdep_struct { - struct fpreg saved_fp; /* only saved with on signals */ +struct _machdep_state { + int esp; + struct fpreg fpreg; }; -/* Save the floating point state of a thread: */ -#define _thread_machdep_save_float_state(thr) \ - { \ - char *fdata = (char*)(&(thr)->_machdep.saved_fp); \ - __asm__("fsave %0"::"m" (*fdata)); \ - } - -/* Restore the floating point state of a thread: */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - char *fdata = (char*)(&(thr)->_machdep.saved_fp); \ - __asm__("frstor %0"::"m" (*fdata)); \ - } - -/* Initialise the jmpbuf stack frame so it continues from entry: */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf.mjb_eip = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf.mjb_esp = \ - (long) (thr)->stack->base + \ - (thr)->stack->size \ - - sizeof(double); \ - } - -static __inline int -_thread_machdep_setjmp_helper(a) - _machdep_jmp_buf *a; -{ - int v; - - __asm__("mov %%ds, %0\n" : "=m" (a->mjb_ds) ); - __asm__("mov %%es, %0\n" : "=m" (a->mjb_es) ); - __asm__("mov %%fs, %0\n" : "=m" (a->mjb_fs) ); - __asm__("mov %%gs, %0\n" : "=m" (a->mjb_gs) ); - v = _setjmp(a->u.jb); - if (v) { - __asm__("mov %0, %%gs\n" :: "m" (a->mjb_gs) ); - __asm__("mov %0, %%fs\n" :: "m" (a->mjb_fs) ); - /* __asm__("mov %0, %%es\n" :: "m" (a->mjb_es) ); */ - /* __asm__("mov %0, %%ds\n" :: "m" (a->mjb_ds) ); */ - } - return (v); -} - -#define _thread_machdep_longjmp(a,v) _longjmp((a).u.jb,v) -#define _thread_machdep_setjmp(a) _thread_machdep_setjmp_helper(&(a)) diff --git a/lib/libc_r/arch/m68k/uthread_machdep.h b/lib/libc_r/arch/m68k/uthread_machdep.h index 8bda374924d..d9bb9935ca6 100644 --- a/lib/libc_r/arch/m68k/uthread_machdep.h +++ b/lib/libc_r/arch/m68k/uthread_machdep.h @@ -1,40 +1,6 @@ -/* - * OpenBSD/m68k machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.3 1999/11/25 07:01:28 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.4 2000/10/04 05:55:34 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* fsave privileged instr */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* frestore privileged instr */ \ - } - -/* initialise the jmpbuf stack frame so it continues from entry */ - -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[5] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[2] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* char saved_fp[108]; */ - int dummy; +struct _machdep_state { + int sp; }; - diff --git a/lib/libc_r/arch/m88k/uthread_machdep.h b/lib/libc_r/arch/m88k/uthread_machdep.h index 0fcad5cf0ae..586210e0deb 100644 --- a/lib/libc_r/arch/m88k/uthread_machdep.h +++ b/lib/libc_r/arch/m88k/uthread_machdep.h @@ -1,40 +1 @@ -/* - * OpenBSD/m88k machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.2 1999/11/25 07:01:28 d Exp $ - */ - -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* fsave privileged instr */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* frestore privileged instr */ \ - } - -/* initialise the jmpbuf stack frame so it continues from entry */ - -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[5] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[2] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* char saved_fp[108]; */ - int dummy; -}; - +/* $OpenBSD: uthread_machdep.h,v 1.3 2000/10/04 05:55:34 d Exp $ */ diff --git a/lib/libc_r/arch/mips/uthread_machdep.h b/lib/libc_r/arch/mips/uthread_machdep.h index 89fb399d629..113a83dc815 100644 --- a/lib/libc_r/arch/mips/uthread_machdep.h +++ b/lib/libc_r/arch/mips/uthread_machdep.h @@ -1,38 +1,6 @@ -/* - * OpenBSD/mips machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.4 1999/11/25 07:01:28 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:34 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -#include <machine/regnum.h> -#include <machine/signal.h> - -/* floating point state is saved by setjmp/longjmp */ - -#define _thread_machdep_save_float_state(thr) /* no need */ -#define _thread_machdep_restore_float_state(thr) /* no need */ - -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - struct sigcontext *j = &(thr)->saved_jmp_buf; \ - \ - /* initialise to sane values */ \ - _thread_machdep_setjmp(j); \ - /* entry */ \ - j->sc_regs[RA] = j->sc_pc; /* for gdb */ \ - j->sc_pc = (int)entry; \ - /* stack */ \ - j->sc_regs[SP] = (int) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) longjmp(a,v) -#define _thread_machdep_setjmp(a) setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* nothing needed */ +struct _machdep_state { + int frame; }; diff --git a/lib/libc_r/arch/powerpc/uthread_machdep.h b/lib/libc_r/arch/powerpc/uthread_machdep.h index 6041279d95e..54c864e71a4 100644 --- a/lib/libc_r/arch/powerpc/uthread_machdep.h +++ b/lib/libc_r/arch/powerpc/uthread_machdep.h @@ -1,45 +1,7 @@ -/* - * OpenBSD/powerpc machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.4 1999/11/25 07:01:29 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:35 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* rahnds to fill in */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* rahnds to fill in */ \ - } - -#define JMP_r1 (0x04/4) -#define JMP_lr (0x50/4) -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - (thr)->saved_jmp_buf[JMP_lr] = \ - (unsigned int) entry; \ - (thr)->saved_jmp_buf[JMP_r1] = \ - ((unsigned int) (thr)->stack->base \ - + (thr)->stack->size \ - - 0x4) & ~0xf; \ - { \ - unsigned int *pbacklink = \ - (thr)->saved_jmp_buf[JMP_r1]; \ - *pbacklink = 0; \ - } \ - } - -#define _thread_machdep_longjmp(a,v) longjmp(a,v) -#define _thread_machdep_setjmp(a) setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - char xxx; +struct _machdep_state { + int frame; }; diff --git a/lib/libc_r/arch/sparc/uthread_machdep.S b/lib/libc_r/arch/sparc/uthread_machdep.S deleted file mode 100644 index c24fff66c07..00000000000 --- a/lib/libc_r/arch/sparc/uthread_machdep.S +++ /dev/null @@ -1,35 +0,0 @@ -/* $OpenBSD: uthread_machdep.S,v 1.1 2000/01/06 07:04:36 d Exp $ */ - -#include <machine/asm.h> -#include <machine/trap.h> - -ENTRY(_thread_machdep_create) - st %o2, [%o0] /* store the new stack pointer */ - sub %o1, 8, %o1 /* the return adress is o7 + 8 ! */ - st %o1, [%o0+4] /* store the new pc */ - - retl - nop - -ENTRY(_thread_machdep_setjmp) - t ST_FLUSHWIN /* flush register windows */ - st %sp, [%o0] /* store sp */ - st %o7, [%o0+4] /* store pc */ - retl - clr %o0 /* return 0 */ - -ENTRY(_thread_machdep_longjmp) - t ST_FLUSHWIN /* flush register windows */ - sub %sp, 64, %sp /* foo? */ - - ld [%o0+4], %o7 /* restore pc */ - ld [%o0], %fp /* restore fp, the restore ins below will - * cause it to become sp */ - /* i?i:1 - Do we need to care? it's always called with 1 */ - tst %o1 - be,a 0f - mov 1, %o1 -0: - retl - restore %o1, 0, %o0 - diff --git a/lib/libc_r/arch/sparc/uthread_machdep.h b/lib/libc_r/arch/sparc/uthread_machdep.h index 53ad543f77a..cb43f3a0463 100644 --- a/lib/libc_r/arch/sparc/uthread_machdep.h +++ b/lib/libc_r/arch/sparc/uthread_machdep.h @@ -1,39 +1,7 @@ -/* - * OpenBSD/sparc machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.4 2000/01/06 07:04:54 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:35 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -#include <sys/signal.h> - -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* XXX tdb */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* XXX tdb */ \ - } - -typedef long _machdep_jmp_buf[2]; - -int _thread_machdep_setjmp __P((_machdep_jmp_buf)); -void _thread_machdep_longjmp __P((_machdep_jmp_buf, int)); - -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - long stack = (long)(thr)->stack->base + \ - (thr)->stack->size - 64; \ - (thr)->saved_jmp_buf[0] = (long)stack; \ - (thr)->saved_jmp_buf[1] = (long)entry - 8; \ - } - -struct _machdep_struct { - /* char saved_fp[???]; */ - int dummy; +struct _machdep_state { + int fp; /* frame pointer */ + int pc; /* program counter */ }; - diff --git a/lib/libc_r/sys/Makefile.inc b/lib/libc_r/sys/Makefile.inc index 91c5982d309..85598b38d38 100644 --- a/lib/libc_r/sys/Makefile.inc +++ b/lib/libc_r/sys/Makefile.inc @@ -1,12 +1,16 @@ -# $Id: Makefile.inc,v 1.5 2000/01/06 07:11:41 d Exp $ -# $OpenBSD: Makefile.inc,v 1.5 2000/01/06 07:11:41 d Exp $ +# $Id: Makefile.inc,v 1.6 2000/10/04 05:55:35 d Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2000/10/04 05:55:35 d Exp $ .PATH: ${LIBC_RSRCDIR}/sys ${LIBC_RSRCDIR}/arch/${MACHINE_ARCH} -SRCS+= uthread_error.c _atomic_lock.c slow_atomic_lock.c +SRCS+= uthread_error.c +SRCS+= _atomic_lock.c slow_atomic_lock.c -.if exists(${LIBC_RSRCDIR}/arch/${MACHINE_ARCH}/uthread_machdep.S) -SRCS+= uthread_machdep.S +.if exists(${LIBC_RSRCDIR}/arch/${MACHINE_ARCH}/uthread_machdep_asm.S) +SRCS+= uthread_machdep_asm.S +.endif +.if exists(${LIBC_RSRCDIR}/arch/${MACHINE_ARCH}/uthread_machdep.c) +SRCS+= uthread_machdep.c .endif .if (${LIB} == "c_r") diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index 1d2cf83b02c..9cfcffd5ca2 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread_private.h,v 1.19 2000/01/06 07:13:56 d Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.20 2000/10/04 05:55:35 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -41,7 +41,6 @@ /* * Include files. */ -#include <setjmp.h> #include <signal.h> #include <sys/queue.h> #include <sys/types.h> @@ -513,16 +512,10 @@ struct pthread { */ struct sigcontext saved_sigcontext; - /* - * Saved jump buffer used in call to longjmp by _thread_kern_sched - * if sig_saved is FALSE. - */ - _machdep_jmp_buf saved_jmp_buf; - /* - * Further machine-dependent context, valid if sig_saved is FALSE. + * Machine-dependent context, valid if sig_saved is FALSE. */ - struct _machdep_struct _machdep; + struct _machdep_state _machdep; /* * TRUE if the last state saved was a signal context. FALSE if the @@ -690,6 +683,16 @@ struct pthread { }; /* + * Flags and prototypes for the machine dependent layer + */ +void _thread_machdep_switch(struct _machdep_state *newstate, + struct _machdep_state *savestate); +void _thread_machdep_init(struct _machdep_state *state, void *stackbase, + int stacksize, void (*entry)(void)); +void _thread_machdep_save_float_state(struct _machdep_state* statep); +void _thread_machdep_restore_float_state(struct _machdep_state* statep); + +/* * Global variables for the uthread kernel. */ @@ -848,6 +851,7 @@ int _thread_slow_atomic_is_locked(volatile _spinlock_lock_t *); struct stack * _thread_stack_alloc(void *, size_t); void _thread_stack_free(struct stack *); + /* #include <signal.h> */ #ifdef _USER_SIGNAL_H int _thread_sys_kill(pid_t, int); diff --git a/lib/libc_r/uthread/uthread_create.c b/lib/libc_r/uthread/uthread_create.c index 3a9499d0a1c..a1981e90f3c 100644 --- a/lib/libc_r/uthread/uthread_create.c +++ b/lib/libc_r/uthread/uthread_create.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_create.c,v 1.13 2000/01/06 07:15:05 d Exp $ */ +/* $OpenBSD: uthread_create.c,v 1.14 2000/10/04 05:55:35 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -104,16 +104,13 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr, /* Initialise the thread for signals: */ new_thread->sigmask = _thread_run->sigmask; - /* Initialise the jump buffer: */ - _thread_machdep_setjmp(new_thread->saved_jmp_buf); - /* - * Set up new stack frame so that it looks like it - * returned from a longjmp() to the beginning of - * _thread_start(). + * Set up new stack frame so that it 'returns' to + * the beginning of _thread_start() after it is + * switched to: */ - _thread_machdep_thread_create(new_thread, _thread_start, - pattr); + _thread_machdep_init(&new_thread->_machdep, + stack->base, stack->size, _thread_start); /* Copy the thread attributes: */ memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr)); diff --git a/lib/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c index 56d6c7a3999..716c64f63cb 100644 --- a/lib/libc_r/uthread/uthread_kern.c +++ b/lib/libc_r/uthread/uthread_kern.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_kern.c,v 1.9 1999/11/25 07:01:37 d Exp $ */ +/* $OpenBSD: uthread_kern.c,v 1.10 2000/10/04 05:55:35 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -39,7 +39,6 @@ #include <string.h> #include <poll.h> #include <unistd.h> -#include <setjmp.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> @@ -77,6 +76,7 @@ void _thread_kern_sched(struct sigcontext * scp) { pthread_t pthread, pthread_h = NULL; + pthread_t old_thread_run; struct itimerval itimer; struct timespec ts, ts1; struct timeval tv, tv1; @@ -100,29 +100,10 @@ _thread_kern_sched(struct sigcontext * scp) /* * Save floating point state. */ - _thread_machdep_save_float_state(_thread_run); + _thread_machdep_save_float_state(&_thread_run->_machdep); /* Flag the signal context as the last state saved: */ _thread_run->sig_saved = 1; - } - /* Save the state of the current thread: */ - else if (_thread_machdep_setjmp(_thread_run->saved_jmp_buf) != 0) { - /* - * This point is reached when a longjmp() is called to - * restore the state of a thread. - * - * This is the normal way out of the scheduler. - */ - _thread_kern_in_sched = 0; - - if (_sched_switch_hook != NULL) { - /* Run the installed switch hook: */ - thread_run_switch_hook(_last_user_thread, _thread_run); - } - - _thread_check_cancel(); - - return; } else /* Flag the jump buffer was the last state saved: */ _thread_run->sig_saved = 0; @@ -134,12 +115,15 @@ _thread_kern_sched(struct sigcontext * scp) /* Save errno. */ _thread_run->error = errno; + /* Save the current thread to switch from */ + old_thread_run = _thread_run; + /* * Enter a scheduling loop that finds the next thread that is * ready to run. This loop completes when there are no more threads * in the global list or when a thread has its state restored by * either a sigreturn (if the state was saved as a sigcontext) or a - * longjmp (if the state was saved by a setjmp). + * switch. */ while (!(TAILQ_EMPTY(&_thread_list))) { /* Get the current time of day: */ @@ -541,7 +525,7 @@ _thread_kern_sched(struct sigcontext * scp) /* * Restore floating point state. */ - _thread_machdep_restore_float_state(_thread_run); + _thread_machdep_restore_float_state(&_thread_run->_machdep); /* * Do a sigreturn to restart the thread that @@ -561,15 +545,33 @@ _thread_kern_sched(struct sigcontext * scp) _thread_sys_sigreturn(&_thread_run->saved_sigcontext); } else { /* - * Do a longjmp to restart the thread that - * was context switched out (by a longjmp to - * a different thread): + * This is the normal way out of the scheduler. + */ + _thread_kern_in_sched = 0; + + if (_sched_switch_hook != NULL) { + /* Run the installed switch hook: */ + thread_run_switch_hook(_last_user_thread, + _thread_run); + } + + _thread_check_cancel(); + + /* + * Resume thread _thread_run. */ - _thread_machdep_longjmp(_thread_run->saved_jmp_buf, 1); + _thread_machdep_switch(&_thread_run->_machdep, + &old_thread_run->_machdep); + /* + * This thread is now the new _thread_run + * again. + */ + return; + } /* This point should not be reached. */ - PANIC("Thread has returned from sigreturn or longjmp"); + PANIC("Thread has returned from sigreturn or switch"); } } diff --git a/lib/libpthread/arch/alpha/uthread_machdep.h b/lib/libpthread/arch/alpha/uthread_machdep.h index 9a7c52da977..3c159c84b99 100644 --- a/lib/libpthread/arch/alpha/uthread_machdep.h +++ b/lib/libpthread/arch/alpha/uthread_machdep.h @@ -1,68 +1,6 @@ -/* - * OpenBSD/alpha machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.5 1999/11/25 07:01:27 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.6 2000/10/04 05:55:33 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ -do { \ - __asm__( \ - "stt $f8, ( 0 * 8) + %0\n\tstt $f9, ( 1 * 8) + %0\n\t" \ - "stt $f10, ( 2 * 8) + %0\n\tstt $f11, ( 3 * 8) + %0\n\t" \ - "stt $f12, ( 4 * 8) + %0\n\tstt $f13, ( 5 * 8) + %0\n\t" \ - "stt $f14, ( 6 * 8) + %0\n\tstt $f15, ( 7 * 8) + %0\n\t" \ - "stt $f16, ( 8 * 8) + %0\n\tstt $f17, ( 9 * 8) + %0\n\t" \ - "stt $f18, (10 * 8) + %0\n\tstt $f19, (11 * 8) + %0\n\t" \ - "stt $f20, (12 * 8) + %0\n\tstt $f21, (13 * 8) + %0\n\t" \ - "stt $f22, (14 * 8) + %0\n\tstt $f23, (15 * 8) + %0\n\t" \ - "stt $f24, (16 * 8) + %0\n\tstt $f25, (17 * 8) + %0\n\t" \ - "stt $f26, (18 * 8) + %0\n\tstt $f27, (19 * 8) + %0\n\t" \ - "stt $f28, (20 * 8) + %0\n\tstt $f29, (21 * 8) + %0\n\t" \ - "stt $f30, (22 * 8) + %0" \ - : : "o" ((thr)->_machdep.saved_fp) : "memory"); \ -} while(0) - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ -do { \ - __asm__( \ - "ldt $f8, ( 0 * 8) + %0\n\tldt $f9, ( 1 * 8) + %0\n\t" \ - "ldt $f10, ( 2 * 8) + %0\n\tldt $f11, ( 3 * 8) + %0\n\t" \ - "ldt $f12, ( 4 * 8) + %0\n\tldt $f13, ( 5 * 8) + %0\n\t" \ - "ldt $f14, ( 6 * 8) + %0\n\tldt $f15, ( 7 * 8) + %0\n\t" \ - "ldt $f16, ( 8 * 8) + %0\n\tldt $f17, ( 9 * 8) + %0\n\t" \ - "ldt $f18, (10 * 8) + %0\n\tldt $f19, (11 * 8) + %0\n\t" \ - "ldt $f20, (12 * 8) + %0\n\tldt $f21, (13 * 8) + %0\n\t" \ - "ldt $f22, (14 * 8) + %0\n\tldt $f23, (15 * 8) + %0\n\t" \ - "ldt $f24, (16 * 8) + %0\n\tldt $f25, (17 * 8) + %0\n\t" \ - "ldt $f26, (18 * 8) + %0\n\tldt $f27, (19 * 8) + %0\n\t" \ - "ldt $f28, (20 * 8) + %0\n\tldt $f29, (21 * 8) + %0\n\t" \ - "ldt $f30, (22 * 8) + %0\n\t" \ - : : "o" (thr->_machdep.saved_fp) : \ - "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", \ - "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", \ - "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30"); \ -} while(0) - -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[2] = (long) entry; \ - (thr)->saved_jmp_buf[4 + R_RA] = 0; \ - (thr)->saved_jmp_buf[4 + R_T12] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[4 + R_SP] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - char saved_fp[23 * 8]; +struct _machdep_state { + int fp; }; diff --git a/lib/libpthread/arch/hppa/uthread_machdep.h b/lib/libpthread/arch/hppa/uthread_machdep.h index 0d80d718ded..a1d8eeb4913 100644 --- a/lib/libpthread/arch/hppa/uthread_machdep.h +++ b/lib/libpthread/arch/hppa/uthread_machdep.h @@ -1,40 +1 @@ -/* - * OpenBSD/hppa machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.3 1999/11/25 07:01:27 d Exp $$ - */ - -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* fsave privileged instr */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* frestore privileged instr */ \ - } - -/* initialise the jmpbuf stack frame so it continues from entry */ - -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[5] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[2] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* char saved_fp[108]; */ - int dummy; -}; - +/* $OpenBSD: uthread_machdep.h,v 1.4 2000/10/04 05:55:33 d Exp $ */ diff --git a/lib/libpthread/arch/i386/uthread_machdep.h b/lib/libpthread/arch/i386/uthread_machdep.h index dab5c413932..22d48624d0d 100644 --- a/lib/libpthread/arch/i386/uthread_machdep.h +++ b/lib/libpthread/arch/i386/uthread_machdep.h @@ -1,89 +1,10 @@ -/* - * OpenBSD/i386 machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.6 1999/11/25 07:01:28 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.7 2000/10/04 05:55:34 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ #include <machine/reg.h> -/* - * We need to extend jmp_buf to hold extended segment registers - * for WINE. - */ -typedef struct _machdep_jmp_buf { - union { - jmp_buf jb; - struct { - int eip; - int ebx; - int esp; - int ebp; - int esi; - int edi; - } jbs; - } u; -#define mjb_eip u.jbs.eip -#define mjb_ebx u.jbs.ebx -#define mjb_esp u.jbs.esp -#define mjb_ebp u.jbs.ebp -#define mjb_esi u.jbs.esi -#define mjb_edi u.jbs.edi - int mjb_ds; /* informational only - not restored */ - int mjb_es; /* informational only - not restored */ - int mjb_fs; - int mjb_gs; -} _machdep_jmp_buf; - -/* Extra machine-dependent information */ -struct _machdep_struct { - struct fpreg saved_fp; /* only saved with on signals */ +struct _machdep_state { + int esp; + struct fpreg fpreg; }; -/* Save the floating point state of a thread: */ -#define _thread_machdep_save_float_state(thr) \ - { \ - char *fdata = (char*)(&(thr)->_machdep.saved_fp); \ - __asm__("fsave %0"::"m" (*fdata)); \ - } - -/* Restore the floating point state of a thread: */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - char *fdata = (char*)(&(thr)->_machdep.saved_fp); \ - __asm__("frstor %0"::"m" (*fdata)); \ - } - -/* Initialise the jmpbuf stack frame so it continues from entry: */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf.mjb_eip = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf.mjb_esp = \ - (long) (thr)->stack->base + \ - (thr)->stack->size \ - - sizeof(double); \ - } - -static __inline int -_thread_machdep_setjmp_helper(a) - _machdep_jmp_buf *a; -{ - int v; - - __asm__("mov %%ds, %0\n" : "=m" (a->mjb_ds) ); - __asm__("mov %%es, %0\n" : "=m" (a->mjb_es) ); - __asm__("mov %%fs, %0\n" : "=m" (a->mjb_fs) ); - __asm__("mov %%gs, %0\n" : "=m" (a->mjb_gs) ); - v = _setjmp(a->u.jb); - if (v) { - __asm__("mov %0, %%gs\n" :: "m" (a->mjb_gs) ); - __asm__("mov %0, %%fs\n" :: "m" (a->mjb_fs) ); - /* __asm__("mov %0, %%es\n" :: "m" (a->mjb_es) ); */ - /* __asm__("mov %0, %%ds\n" :: "m" (a->mjb_ds) ); */ - } - return (v); -} - -#define _thread_machdep_longjmp(a,v) _longjmp((a).u.jb,v) -#define _thread_machdep_setjmp(a) _thread_machdep_setjmp_helper(&(a)) diff --git a/lib/libpthread/arch/m68k/uthread_machdep.h b/lib/libpthread/arch/m68k/uthread_machdep.h index 8bda374924d..d9bb9935ca6 100644 --- a/lib/libpthread/arch/m68k/uthread_machdep.h +++ b/lib/libpthread/arch/m68k/uthread_machdep.h @@ -1,40 +1,6 @@ -/* - * OpenBSD/m68k machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.3 1999/11/25 07:01:28 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.4 2000/10/04 05:55:34 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* fsave privileged instr */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* frestore privileged instr */ \ - } - -/* initialise the jmpbuf stack frame so it continues from entry */ - -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[5] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[2] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* char saved_fp[108]; */ - int dummy; +struct _machdep_state { + int sp; }; - diff --git a/lib/libpthread/arch/m88k/uthread_machdep.h b/lib/libpthread/arch/m88k/uthread_machdep.h index 0fcad5cf0ae..586210e0deb 100644 --- a/lib/libpthread/arch/m88k/uthread_machdep.h +++ b/lib/libpthread/arch/m88k/uthread_machdep.h @@ -1,40 +1 @@ -/* - * OpenBSD/m88k machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.2 1999/11/25 07:01:28 d Exp $ - */ - -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* fsave privileged instr */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* frestore privileged instr */ \ - } - -/* initialise the jmpbuf stack frame so it continues from entry */ - -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - /* entry */ \ - (thr)->saved_jmp_buf[5] = (long) entry; \ - /* stack */ \ - (thr)->saved_jmp_buf[2] = (long) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) _longjmp(a,v) -#define _thread_machdep_setjmp(a) _setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* char saved_fp[108]; */ - int dummy; -}; - +/* $OpenBSD: uthread_machdep.h,v 1.3 2000/10/04 05:55:34 d Exp $ */ diff --git a/lib/libpthread/arch/mips/uthread_machdep.h b/lib/libpthread/arch/mips/uthread_machdep.h index 89fb399d629..113a83dc815 100644 --- a/lib/libpthread/arch/mips/uthread_machdep.h +++ b/lib/libpthread/arch/mips/uthread_machdep.h @@ -1,38 +1,6 @@ -/* - * OpenBSD/mips machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.4 1999/11/25 07:01:28 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:34 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -#include <machine/regnum.h> -#include <machine/signal.h> - -/* floating point state is saved by setjmp/longjmp */ - -#define _thread_machdep_save_float_state(thr) /* no need */ -#define _thread_machdep_restore_float_state(thr) /* no need */ - -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - struct sigcontext *j = &(thr)->saved_jmp_buf; \ - \ - /* initialise to sane values */ \ - _thread_machdep_setjmp(j); \ - /* entry */ \ - j->sc_regs[RA] = j->sc_pc; /* for gdb */ \ - j->sc_pc = (int)entry; \ - /* stack */ \ - j->sc_regs[SP] = (int) (thr)->stack->base \ - + (thr)->stack->size \ - - sizeof(double); \ - } - -#define _thread_machdep_longjmp(a,v) longjmp(a,v) -#define _thread_machdep_setjmp(a) setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - /* nothing needed */ +struct _machdep_state { + int frame; }; diff --git a/lib/libpthread/arch/powerpc/uthread_machdep.h b/lib/libpthread/arch/powerpc/uthread_machdep.h index 6041279d95e..54c864e71a4 100644 --- a/lib/libpthread/arch/powerpc/uthread_machdep.h +++ b/lib/libpthread/arch/powerpc/uthread_machdep.h @@ -1,45 +1,7 @@ -/* - * OpenBSD/powerpc machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.4 1999/11/25 07:01:29 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:35 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* rahnds to fill in */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* rahnds to fill in */ \ - } - -#define JMP_r1 (0x04/4) -#define JMP_lr (0x50/4) -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - (thr)->saved_jmp_buf[JMP_lr] = \ - (unsigned int) entry; \ - (thr)->saved_jmp_buf[JMP_r1] = \ - ((unsigned int) (thr)->stack->base \ - + (thr)->stack->size \ - - 0x4) & ~0xf; \ - { \ - unsigned int *pbacklink = \ - (thr)->saved_jmp_buf[JMP_r1]; \ - *pbacklink = 0; \ - } \ - } - -#define _thread_machdep_longjmp(a,v) longjmp(a,v) -#define _thread_machdep_setjmp(a) setjmp(a) - -typedef jmp_buf _machdep_jmp_buf; - -struct _machdep_struct { - char xxx; +struct _machdep_state { + int frame; }; diff --git a/lib/libpthread/arch/sparc/uthread_machdep.S b/lib/libpthread/arch/sparc/uthread_machdep.S deleted file mode 100644 index c24fff66c07..00000000000 --- a/lib/libpthread/arch/sparc/uthread_machdep.S +++ /dev/null @@ -1,35 +0,0 @@ -/* $OpenBSD: uthread_machdep.S,v 1.1 2000/01/06 07:04:36 d Exp $ */ - -#include <machine/asm.h> -#include <machine/trap.h> - -ENTRY(_thread_machdep_create) - st %o2, [%o0] /* store the new stack pointer */ - sub %o1, 8, %o1 /* the return adress is o7 + 8 ! */ - st %o1, [%o0+4] /* store the new pc */ - - retl - nop - -ENTRY(_thread_machdep_setjmp) - t ST_FLUSHWIN /* flush register windows */ - st %sp, [%o0] /* store sp */ - st %o7, [%o0+4] /* store pc */ - retl - clr %o0 /* return 0 */ - -ENTRY(_thread_machdep_longjmp) - t ST_FLUSHWIN /* flush register windows */ - sub %sp, 64, %sp /* foo? */ - - ld [%o0+4], %o7 /* restore pc */ - ld [%o0], %fp /* restore fp, the restore ins below will - * cause it to become sp */ - /* i?i:1 - Do we need to care? it's always called with 1 */ - tst %o1 - be,a 0f - mov 1, %o1 -0: - retl - restore %o1, 0, %o0 - diff --git a/lib/libpthread/arch/sparc/uthread_machdep.h b/lib/libpthread/arch/sparc/uthread_machdep.h index 53ad543f77a..cb43f3a0463 100644 --- a/lib/libpthread/arch/sparc/uthread_machdep.h +++ b/lib/libpthread/arch/sparc/uthread_machdep.h @@ -1,39 +1,7 @@ -/* - * OpenBSD/sparc machine-dependent thread macros - * - * $OpenBSD: uthread_machdep.h,v 1.4 2000/01/06 07:04:54 d Exp $ - */ +/* $OpenBSD: uthread_machdep.h,v 1.5 2000/10/04 05:55:35 d Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ -#include <sys/signal.h> - -/* save the floating point state of a thread */ -#define _thread_machdep_save_float_state(thr) \ - { \ - /* XXX tdb */ \ - } - -/* restore the floating point state of a thread */ -#define _thread_machdep_restore_float_state(thr) \ - { \ - /* XXX tdb */ \ - } - -typedef long _machdep_jmp_buf[2]; - -int _thread_machdep_setjmp __P((_machdep_jmp_buf)); -void _thread_machdep_longjmp __P((_machdep_jmp_buf, int)); - -/* initialise the jmpbuf stack frame so it continues from entry */ -#define _thread_machdep_thread_create(thr, entry, pattr) \ - { \ - long stack = (long)(thr)->stack->base + \ - (thr)->stack->size - 64; \ - (thr)->saved_jmp_buf[0] = (long)stack; \ - (thr)->saved_jmp_buf[1] = (long)entry - 8; \ - } - -struct _machdep_struct { - /* char saved_fp[???]; */ - int dummy; +struct _machdep_state { + int fp; /* frame pointer */ + int pc; /* program counter */ }; - diff --git a/lib/libpthread/sys/Makefile.inc b/lib/libpthread/sys/Makefile.inc index 91c5982d309..85598b38d38 100644 --- a/lib/libpthread/sys/Makefile.inc +++ b/lib/libpthread/sys/Makefile.inc @@ -1,12 +1,16 @@ -# $Id: Makefile.inc,v 1.5 2000/01/06 07:11:41 d Exp $ -# $OpenBSD: Makefile.inc,v 1.5 2000/01/06 07:11:41 d Exp $ +# $Id: Makefile.inc,v 1.6 2000/10/04 05:55:35 d Exp $ +# $OpenBSD: Makefile.inc,v 1.6 2000/10/04 05:55:35 d Exp $ .PATH: ${LIBC_RSRCDIR}/sys ${LIBC_RSRCDIR}/arch/${MACHINE_ARCH} -SRCS+= uthread_error.c _atomic_lock.c slow_atomic_lock.c +SRCS+= uthread_error.c +SRCS+= _atomic_lock.c slow_atomic_lock.c -.if exists(${LIBC_RSRCDIR}/arch/${MACHINE_ARCH}/uthread_machdep.S) -SRCS+= uthread_machdep.S +.if exists(${LIBC_RSRCDIR}/arch/${MACHINE_ARCH}/uthread_machdep_asm.S) +SRCS+= uthread_machdep_asm.S +.endif +.if exists(${LIBC_RSRCDIR}/arch/${MACHINE_ARCH}/uthread_machdep.c) +SRCS+= uthread_machdep.c .endif .if (${LIB} == "c_r") diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index 1d2cf83b02c..9cfcffd5ca2 100644 --- a/lib/libpthread/uthread/pthread_private.h +++ b/lib/libpthread/uthread/pthread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread_private.h,v 1.19 2000/01/06 07:13:56 d Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.20 2000/10/04 05:55:35 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -41,7 +41,6 @@ /* * Include files. */ -#include <setjmp.h> #include <signal.h> #include <sys/queue.h> #include <sys/types.h> @@ -513,16 +512,10 @@ struct pthread { */ struct sigcontext saved_sigcontext; - /* - * Saved jump buffer used in call to longjmp by _thread_kern_sched - * if sig_saved is FALSE. - */ - _machdep_jmp_buf saved_jmp_buf; - /* - * Further machine-dependent context, valid if sig_saved is FALSE. + * Machine-dependent context, valid if sig_saved is FALSE. */ - struct _machdep_struct _machdep; + struct _machdep_state _machdep; /* * TRUE if the last state saved was a signal context. FALSE if the @@ -690,6 +683,16 @@ struct pthread { }; /* + * Flags and prototypes for the machine dependent layer + */ +void _thread_machdep_switch(struct _machdep_state *newstate, + struct _machdep_state *savestate); +void _thread_machdep_init(struct _machdep_state *state, void *stackbase, + int stacksize, void (*entry)(void)); +void _thread_machdep_save_float_state(struct _machdep_state* statep); +void _thread_machdep_restore_float_state(struct _machdep_state* statep); + +/* * Global variables for the uthread kernel. */ @@ -848,6 +851,7 @@ int _thread_slow_atomic_is_locked(volatile _spinlock_lock_t *); struct stack * _thread_stack_alloc(void *, size_t); void _thread_stack_free(struct stack *); + /* #include <signal.h> */ #ifdef _USER_SIGNAL_H int _thread_sys_kill(pid_t, int); diff --git a/lib/libpthread/uthread/uthread_create.c b/lib/libpthread/uthread/uthread_create.c index 3a9499d0a1c..a1981e90f3c 100644 --- a/lib/libpthread/uthread/uthread_create.c +++ b/lib/libpthread/uthread/uthread_create.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_create.c,v 1.13 2000/01/06 07:15:05 d Exp $ */ +/* $OpenBSD: uthread_create.c,v 1.14 2000/10/04 05:55:35 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -104,16 +104,13 @@ pthread_create(pthread_t * thread, const pthread_attr_t * attr, /* Initialise the thread for signals: */ new_thread->sigmask = _thread_run->sigmask; - /* Initialise the jump buffer: */ - _thread_machdep_setjmp(new_thread->saved_jmp_buf); - /* - * Set up new stack frame so that it looks like it - * returned from a longjmp() to the beginning of - * _thread_start(). + * Set up new stack frame so that it 'returns' to + * the beginning of _thread_start() after it is + * switched to: */ - _thread_machdep_thread_create(new_thread, _thread_start, - pattr); + _thread_machdep_init(&new_thread->_machdep, + stack->base, stack->size, _thread_start); /* Copy the thread attributes: */ memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr)); diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c index 56d6c7a3999..716c64f63cb 100644 --- a/lib/libpthread/uthread/uthread_kern.c +++ b/lib/libpthread/uthread/uthread_kern.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_kern.c,v 1.9 1999/11/25 07:01:37 d Exp $ */ +/* $OpenBSD: uthread_kern.c,v 1.10 2000/10/04 05:55:35 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -39,7 +39,6 @@ #include <string.h> #include <poll.h> #include <unistd.h> -#include <setjmp.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> @@ -77,6 +76,7 @@ void _thread_kern_sched(struct sigcontext * scp) { pthread_t pthread, pthread_h = NULL; + pthread_t old_thread_run; struct itimerval itimer; struct timespec ts, ts1; struct timeval tv, tv1; @@ -100,29 +100,10 @@ _thread_kern_sched(struct sigcontext * scp) /* * Save floating point state. */ - _thread_machdep_save_float_state(_thread_run); + _thread_machdep_save_float_state(&_thread_run->_machdep); /* Flag the signal context as the last state saved: */ _thread_run->sig_saved = 1; - } - /* Save the state of the current thread: */ - else if (_thread_machdep_setjmp(_thread_run->saved_jmp_buf) != 0) { - /* - * This point is reached when a longjmp() is called to - * restore the state of a thread. - * - * This is the normal way out of the scheduler. - */ - _thread_kern_in_sched = 0; - - if (_sched_switch_hook != NULL) { - /* Run the installed switch hook: */ - thread_run_switch_hook(_last_user_thread, _thread_run); - } - - _thread_check_cancel(); - - return; } else /* Flag the jump buffer was the last state saved: */ _thread_run->sig_saved = 0; @@ -134,12 +115,15 @@ _thread_kern_sched(struct sigcontext * scp) /* Save errno. */ _thread_run->error = errno; + /* Save the current thread to switch from */ + old_thread_run = _thread_run; + /* * Enter a scheduling loop that finds the next thread that is * ready to run. This loop completes when there are no more threads * in the global list or when a thread has its state restored by * either a sigreturn (if the state was saved as a sigcontext) or a - * longjmp (if the state was saved by a setjmp). + * switch. */ while (!(TAILQ_EMPTY(&_thread_list))) { /* Get the current time of day: */ @@ -541,7 +525,7 @@ _thread_kern_sched(struct sigcontext * scp) /* * Restore floating point state. */ - _thread_machdep_restore_float_state(_thread_run); + _thread_machdep_restore_float_state(&_thread_run->_machdep); /* * Do a sigreturn to restart the thread that @@ -561,15 +545,33 @@ _thread_kern_sched(struct sigcontext * scp) _thread_sys_sigreturn(&_thread_run->saved_sigcontext); } else { /* - * Do a longjmp to restart the thread that - * was context switched out (by a longjmp to - * a different thread): + * This is the normal way out of the scheduler. + */ + _thread_kern_in_sched = 0; + + if (_sched_switch_hook != NULL) { + /* Run the installed switch hook: */ + thread_run_switch_hook(_last_user_thread, + _thread_run); + } + + _thread_check_cancel(); + + /* + * Resume thread _thread_run. */ - _thread_machdep_longjmp(_thread_run->saved_jmp_buf, 1); + _thread_machdep_switch(&_thread_run->_machdep, + &old_thread_run->_machdep); + /* + * This thread is now the new _thread_run + * again. + */ + return; + } /* This point should not be reached. */ - PANIC("Thread has returned from sigreturn or longjmp"); + PANIC("Thread has returned from sigreturn or switch"); } } |