Home | History | Annotate | Line # | Download | only in i386
pthread_md.h revision 1.1.2.10
      1  1.1.2.10  thorpej /*	$NetBSD: pthread_md.h,v 1.1.2.10 2003/01/16 03:35:47 thorpej Exp $	*/
      2   1.1.2.1  nathanw 
      3   1.1.2.2  nathanw /*-
      4   1.1.2.2  nathanw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5   1.1.2.2  nathanw  * All rights reserved.
      6   1.1.2.2  nathanw  *
      7   1.1.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1.2.2  nathanw  * by Nathan J. Williams.
      9   1.1.2.2  nathanw  *
     10   1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11   1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     12   1.1.2.2  nathanw  * are met:
     13   1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14   1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15   1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18   1.1.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19   1.1.2.2  nathanw  *    must display the following acknowledgement:
     20   1.1.2.2  nathanw  *        This product includes software developed by the NetBSD
     21   1.1.2.2  nathanw  *        Foundation, Inc. and its contributors.
     22   1.1.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24   1.1.2.2  nathanw  *    from this software without specific prior written permission.
     25   1.1.2.2  nathanw  *
     26   1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1.2.2  nathanw  */
     38   1.1.2.1  nathanw 
     39   1.1.2.1  nathanw #ifndef _LIB_PTHREAD_I386_MD_H
     40   1.1.2.1  nathanw #define _LIB_PTHREAD_I386_MD_H
     41   1.1.2.1  nathanw 
     42   1.1.2.6  nathanw extern int (*_md_getcontext_u)(ucontext_t *);
     43   1.1.2.6  nathanw extern int (*_md_setcontext_u)(const ucontext_t *);
     44   1.1.2.6  nathanw extern int (*_md_swapcontext_u)(ucontext_t *, const ucontext_t *);
     45   1.1.2.6  nathanw 
     46   1.1.2.6  nathanw #define _getcontext_u(uc) (*_md_getcontext_u)((uc))
     47   1.1.2.6  nathanw #define _setcontext_u(uc) (*_md_setcontext_u)((uc))
     48   1.1.2.6  nathanw #define _swapcontext_u(ouc, nuc) (*_md_swapcontext_u)((ouc), (nuc))
     49   1.1.2.6  nathanw 
     50   1.1.2.6  nathanw int _getcontext_u_s87(ucontext_t *);
     51   1.1.2.6  nathanw int _setcontext_u_s87(const ucontext_t *);
     52   1.1.2.6  nathanw int _swapcontext_u_s87(ucontext_t *, const ucontext_t *);
     53   1.1.2.6  nathanw int _getcontext_u_xmm(ucontext_t *);
     54   1.1.2.6  nathanw int _setcontext_u_xmm(const ucontext_t *);
     55   1.1.2.6  nathanw int _swapcontext_u_xmm(ucontext_t *, const ucontext_t *);
     56   1.1.2.6  nathanw 
     57   1.1.2.6  nathanw void pthread__i386_init(void);
     58   1.1.2.6  nathanw 
     59   1.1.2.6  nathanw #define PTHREAD_MD_INIT pthread__i386_init();
     60   1.1.2.1  nathanw 
     61   1.1.2.1  nathanw static __inline long
     62   1.1.2.1  nathanw pthread__sp(void)
     63   1.1.2.1  nathanw {
     64   1.1.2.1  nathanw 	long ret;
     65   1.1.2.1  nathanw 	__asm("movl %%esp, %0" : "=g" (ret));
     66   1.1.2.1  nathanw 
     67   1.1.2.1  nathanw 	return ret;
     68   1.1.2.1  nathanw }
     69   1.1.2.1  nathanw 
     70   1.1.2.1  nathanw #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_UESP])
     71   1.1.2.4   briggs #define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_EIP])
     72   1.1.2.8  nathanw 
     73   1.1.2.8  nathanw /*
     74   1.1.2.8  nathanw  * Set initial, sane values for registers whose values aren't just
     75   1.1.2.8  nathanw  * "don't care".
     76   1.1.2.8  nathanw  * 0x2b is GSEL(GUDATA_SEL, SEL_UPL), and
     77   1.1.2.8  nathanw  * 0x23 is GSEL(GUCODE_SEL, SEL_UPL), from arch/i386/include/segments.h.
     78   1.1.2.8  nathanw  * 0x202 is PSL_USERSET from arch/i386/include/psl.h
     79   1.1.2.8  nathanw  */
     80   1.1.2.8  nathanw #define _INITCONTEXT_U_MD(ucp)						\
     81   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_GS] = 0x2b;			\
     82   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_FS] = 0x2b;			\
     83   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_ES] = 0x2b;			\
     84   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_DS] = 0x2b;			\
     85   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_CS] = 0x23;			\
     86   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_SS] = 0x2b;			\
     87   1.1.2.8  nathanw 	(ucp)->uc_mcontext.__gregs[_REG_EFL] = 0x202;
     88   1.1.2.3  nathanw 
     89   1.1.2.3  nathanw /*
     90   1.1.2.3  nathanw  * Usable stack space below the ucontext_t.
     91   1.1.2.3  nathanw  * See comment in pthread_switch.S about STACK_SWITCH.
     92   1.1.2.3  nathanw  */
     93   1.1.2.3  nathanw #define STACKSPACE	32	/* room for 8 integer values */
     94   1.1.2.5  nathanw 
     95   1.1.2.5  nathanw /*
     96   1.1.2.5  nathanw  * Conversions between struct reg and struct mcontext. Used by
     97   1.1.2.5  nathanw  * libpthread_dbg.
     98   1.1.2.5  nathanw  */
     99   1.1.2.5  nathanw 
    100   1.1.2.5  nathanw #define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {				\
    101   1.1.2.5  nathanw 	(reg)->r_gs  = (uc)->uc_mcontext.__gregs[_REG_GS];		\
    102   1.1.2.5  nathanw 	(reg)->r_fs  = (uc)->uc_mcontext.__gregs[_REG_FS];		\
    103   1.1.2.5  nathanw 	(reg)->r_es  = (uc)->uc_mcontext.__gregs[_REG_ES];		\
    104   1.1.2.5  nathanw 	(reg)->r_ds  = (uc)->uc_mcontext.__gregs[_REG_DS];		\
    105   1.1.2.5  nathanw 	(reg)->r_edi = (uc)->uc_mcontext.__gregs[_REG_EDI];		\
    106   1.1.2.5  nathanw 	(reg)->r_esi = (uc)->uc_mcontext.__gregs[_REG_ESI];		\
    107   1.1.2.5  nathanw 	(reg)->r_ebp = (uc)->uc_mcontext.__gregs[_REG_EBP];		\
    108   1.1.2.5  nathanw 	(reg)->r_ebx = (uc)->uc_mcontext.__gregs[_REG_EBX];		\
    109   1.1.2.5  nathanw 	(reg)->r_edx = (uc)->uc_mcontext.__gregs[_REG_EDX];		\
    110   1.1.2.5  nathanw 	(reg)->r_ecx = (uc)->uc_mcontext.__gregs[_REG_ECX];		\
    111   1.1.2.5  nathanw 	(reg)->r_eax = (uc)->uc_mcontext.__gregs[_REG_EAX];		\
    112   1.1.2.5  nathanw 	(reg)->r_eip = (uc)->uc_mcontext.__gregs[_REG_EIP];		\
    113   1.1.2.5  nathanw 	(reg)->r_cs  = (uc)->uc_mcontext.__gregs[_REG_CS];		\
    114   1.1.2.5  nathanw 	(reg)->r_eflags  = (uc)->uc_mcontext.__gregs[_REG_EFL];		\
    115   1.1.2.5  nathanw 	(reg)->r_esp = (uc)->uc_mcontext.__gregs[_REG_UESP];		\
    116   1.1.2.5  nathanw 	(reg)->r_ss  = (uc)->uc_mcontext.__gregs[_REG_SS];		\
    117   1.1.2.5  nathanw 	} while (/*CONSTCOND*/0)
    118   1.1.2.5  nathanw 
    119   1.1.2.5  nathanw #define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
    120   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_GS]  = (reg)->r_gs;		\
    121   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_FS]  = (reg)->r_fs; 		\
    122   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_ES]  = (reg)->r_es; 		\
    123   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_DS]  = (reg)->r_ds; 		\
    124   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EDI] = (reg)->r_edi; 		\
    125   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_ESI] = (reg)->r_esi; 		\
    126   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EBP] = (reg)->r_ebp; 		\
    127   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EBX] = (reg)->r_ebx; 		\
    128   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EDX] = (reg)->r_edx; 		\
    129   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_ECX] = (reg)->r_ecx; 		\
    130   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EAX] = (reg)->r_eax; 		\
    131   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EIP] = (reg)->r_eip; 		\
    132   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_CS]  = (reg)->r_cs; 		\
    133   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EFL] = (reg)->r_eflags; 		\
    134   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_UESP]= (reg)->r_esp;		\
    135   1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_SS]  = (reg)->r_ss; 		\
    136   1.1.2.5  nathanw 	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;       	\
    137   1.1.2.5  nathanw 	} while (/*CONSTCOND*/0)
    138   1.1.2.5  nathanw 
    139   1.1.2.5  nathanw #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)		       		\
    140   1.1.2.5  nathanw 	memcpy((freg)->__data,						\
    141   1.1.2.5  nathanw         (uc)->uc_mcontext.__fpregs.__fp_reg_set.__fpchip_state.__fp_state, \
    142   1.1.2.5  nathanw 	sizeof(struct fpreg))
    143   1.1.2.5  nathanw 
    144   1.1.2.5  nathanw #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {       	       		\
    145   1.1.2.5  nathanw 	memcpy(								\
    146   1.1.2.5  nathanw         (uc)->uc_mcontext.__fpregs.__fp_reg_set.__fpchip_state.__fp_state, \
    147   1.1.2.5  nathanw 	(freg)->__data, sizeof(struct fpreg));				\
    148   1.1.2.5  nathanw 	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
    149   1.1.2.5  nathanw 	} while (/*CONSTCOND*/0)
    150   1.1.2.1  nathanw 
    151   1.1.2.1  nathanw #endif /* _LIB_PTHREAD_I386_MD_H */
    152