Back to index

glibc  2.9
setjmp.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1992, 1994, 1997, 2001, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <setjmp.h>
00020 
00021 /* Save the current program position in ENV and return 0.  */
00022 int
00023 #if defined BSD_SETJMP
00024 # undef setjmp
00025 # define savemask 1
00026 setjmp (jmp_buf env)
00027 #elif defined BSD__SETJMP
00028 # undef _setjmp
00029 # define savemask 0
00030 _setjmp (jmp_buf env)
00031 #else
00032 __sigsetjmp (jmp_buf env, int savemask)
00033 #endif
00034 {
00035   /* Save data registers D1 through D7.  */
00036   asm volatile ("movem%.l %/d1-%/d7, %0"
00037               : : "m" (env[0].__jmpbuf[0].__dregs[0]));
00038 
00039   /* Save return address in place of register A0.  */
00040   env[0].__jmpbuf[0].__aregs[0] = __builtin_return_address (0);
00041 
00042   /* Save address registers A1 through A5.  */
00043   asm volatile ("movem%.l %/a1-%/a5, %0"
00044               : : "m" (env[0].__jmpbuf[0].__aregs[1]));
00045 
00046   /* Save caller's FP, not our own.  */
00047   env[0].__jmpbuf[0].__fp = *(int **) __builtin_frame_address (0);
00048 
00049   /* Save caller's SP, not our own.  */
00050   env[0].__jmpbuf[0].__sp = (int *) __builtin_frame_address (0) + 2;
00051 
00052 #if defined __HAVE_68881__ || defined __HAVE_FPU__
00053   /* Save floating-point (68881) registers FP0 through FP7.  */
00054   asm volatile ("fmovem%.x %/fp0-%/fp7, %0"
00055               : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
00056 #elif defined (__mcffpu__)
00057   asm volatile ("fmovem %/fp0-%/fp7, %0"
00058               : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
00059 #endif
00060 
00061 #if defined NOT_IN_libc && defined IS_IN_rtld
00062   /* In ld.so we never save the signal mask.  */
00063   return 0;
00064 #else
00065   /* Save the signal mask if requested.  */
00066   return __sigjmp_save (env, savemask);
00067 #endif
00068 }
00069 #if !defined BSD_SETJMP && !defined BSD__SETJMP
00070 libc_hidden_def (__sigsetjmp)
00071 #endif