2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* process.c - manage lwp context switches be means of setjmp/longjmp. */
12 #include <afsconfig.h>
13 #include <afs/param.h>
24 #if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
25 extern int PRE_Block; /* used in lwp.c and process.s */
27 extern char PRE_Block; /* used in lwp.c and process.s */
30 #ifdef HAVE_UCONTEXT_H
33 savecontext(ep, savearea, newsp)
35 struct lwp_context *savearea;
38 #if defined(AFS_IA64_LINUX20_ENV)
39 register unsigned long sp __asm__("r12");
41 #error "You need to update stack pointer register for this platform"
47 getcontext(&savearea->ucontext);
48 savearea->topstack = sp;
49 switch (savearea->state)
57 thread.uc_stack.ss_sp = newsp - AFS_LWP_MINSTACKSIZE + sizeof(void *) + sizeof(void *);
58 thread.uc_stack.ss_size = AFS_LWP_MINSTACKSIZE - sizeof(void *);
59 makecontext(&thread, ep, 0);
73 struct lwp_context *savearea;
78 setcontext(&savearea->ucontext);
86 #if defined(AFS_SGI64_ENV)
92 #elif defined(AFS_HPUX_ENV)
94 #elif defined(AFS_LINUX20_ENV)
95 #if defined(AFS_PPC_LINUX20_ENV)
97 #elif defined(AFS_I386_LINUX20_ENV)
99 #elif defined(AFS_S390_LINUX20_ENV)
102 #elif defined(AFS_SPARC_LINUX20_ENV)
105 #elif defined(AFS_SPARC64_LINUX20_ENV) && defined(AFS_32BIT_USR_ENV)
108 #elif defined(AFS_ALPHA_LINUX20_ENV)
111 #elif defined(AFS_PARISC_LINUX24_ENV)
114 #error Unsupported linux LWP system type.
116 #elif defined(AFS_X86_FBSD_ENV)
118 #elif defined(AFS_DARWIN_ENV)
121 Need offset to SP in jmp_buf for this platform.
125 * On SGIs the type of the elements of the array passed to setjmp
126 * differs based on the ISA chosen. It is int for mips1 and mips2 and
127 * __uint64_t for mips3 and mips4
131 #if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4)
132 typedef __uint64_t jmp_buf_type;
135 #ifdef AFS_ALPHA_LINUX20_ENV
136 typedef long jmp_buf_type;
138 typedef int jmp_buf_type;
139 #endif /*AFS_ALPHA_LINUX20_ENV*/
142 static jmp_buf jmp_tmp;
145 static jmp_buf_type *jmpBuffer;
147 afs_int32 savecontext(ep, savearea, sp)
149 struct lwp_context *savearea;
157 code = setjmp(savearea->setjmp_buffer);
158 jmpBuffer = (jmp_buf_type *)savearea->setjmp_buffer;
159 savearea->topstack = (char*)jmpBuffer[LWP_SP];
163 int i, *ptr = (int*)savearea->setjmp_buffer;
164 printf("savecontext\n");
165 for ( i=0; i < 5; i++)
166 printf("(%d) 0x%x ",i, ptr[i]);
168 for ( i=5; i < 10; i++)
169 printf("(%d) 0x%x ",i, ptr[i]);
179 rc = setjmp(jmp_tmp);
182 case 0: jmpBuffer = (jmp_buf_type *)jmp_tmp;
183 jmpBuffer[LWP_SP] = (jmp_buf_type)sp;
184 #if defined(AFS_S390_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || (defined(AFS_SPARC64_LINUX20_ENV) && defined(AFS_32BIT_USR_ENV))
185 jmpBuffer[LWP_FP] = (jmp_buf_type)sp;
190 assert(0); /* never returns */
193 perror("Error in setjmp1\n");
198 case 2: /* restoring frame */
202 perror("Error in setjmp2 : restoring\n");
208 afs_int32 returnto(savearea)
209 struct lwp_context *savearea;
212 int i, *ptr = savearea->setjmp_buffer;
214 printf("Returning to \n");
215 for ( i=0; i < 5; i++)
216 printf("(%d) 0x%x ",i, ptr[i]);
218 for ( i=5; i < 10; i++)
219 printf("(%d) 0x%x ",i, ptr[i]);
223 longjmp(savearea->setjmp_buffer, 2);