diff options
| author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
|---|---|---|
| committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
| commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
| tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libgcc/config/s390 | |
| parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
| download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip | |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libgcc/config/s390')
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/_fixdfdi.c | 113 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/_fixsfdi.c | 107 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/_fixtfdi.c | 122 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/_fixunsdfdi.c | 120 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/_fixunssfdi.c | 114 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/_fixunstfdi.c | 125 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/32/t-floattodi | 5 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/gthr-tpf.h | 234 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/libgcc-glibc.ver | 116 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/linux-unwind.h | 132 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/t-crtstuff | 5 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/t-linux | 7 | ||||
| -rw-r--r-- | gcc-4.9/libgcc/config/s390/tpf-unwind.h | 252 |
13 files changed, 1452 insertions, 0 deletions
diff --git a/gcc-4.9/libgcc/config/s390/32/_fixdfdi.c b/gcc-4.9/libgcc/config/s390/32/_fixdfdi.c new file mode 100644 index 000000000..e6dd4d114 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/_fixdfdi.c @@ -0,0 +1,113 @@ +/* Definitions of target machine for GNU compiler, for IBM S/390 + Copyright (C) 1999-2014 Free Software Foundation, Inc. + Contributed by Hartmut Penner (hpenner@de.ibm.com) and + Ulrich Weigand (uweigand@de.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __s390x__ + +#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) +#define EXPONENT_BIAS 1023 +#define MANTISSA_BITS 52 +#define PRECISION (MANTISSA_BITS + 1) +#define SIGNBIT 0x80000000 +#define SIGN(fp) ((fp.l.upper) & SIGNBIT) +#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) +#define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1)) +#define HIDDEND_LL ((UDItype_x)1 << MANTISSA_BITS) +#define LLONG_MAX 9223372036854775807LL +#define LLONG_MIN (-LLONG_MAX - 1LL) + +typedef int DItype_x __attribute__ ((mode (DI))); +typedef unsigned int UDItype_x __attribute__ ((mode (DI))); +typedef int SItype_x __attribute__ ((mode (SI))); +typedef unsigned int USItype_x __attribute__ ((mode (SI))); + +union double_long { + double d; + struct { + SItype_x upper; + USItype_x lower; + } l; + UDItype_x ll; +}; + +static __inline__ void +fexceptdiv (float d, float e) +{ + __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); +} + +DItype_x __fixdfdi (double a1); + +/* convert double to int */ +DItype_x +__fixdfdi (double a1) +{ + register union double_long dl1; + register int exp; + register DItype_x l; + + dl1.d = a1; + + /* +/- 0, denormalized */ + if (!EXPD (dl1)) + return 0; + + /* The exponent - considered the binary point at the right end of + the mantissa. */ + exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; + + /* number < 1 */ + if (exp <= -PRECISION) + return 0; + + /* NaN */ + + if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */ + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0x8000000000000000ULL; + } + + /* Number big number & +/- inf */ + if (exp >= 11) { + /* Don't throw an exception for -1p+63 */ + if (!SIGN (dl1) || exp > 11 || FRACD_LL (dl1) != 0) + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return SIGN (dl1) ? LLONG_MIN : LLONG_MAX; + } + + l = MANTD_LL(dl1); + + /* shift down until exp < 12 or l = 0 */ + if (exp > 0) + l <<= exp; + else + l >>= -exp; + + return (SIGN (dl1) ? -l : l); +} +#endif /* !__s390x__ */ diff --git a/gcc-4.9/libgcc/config/s390/32/_fixsfdi.c b/gcc-4.9/libgcc/config/s390/32/_fixsfdi.c new file mode 100644 index 000000000..99f91a705 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/_fixsfdi.c @@ -0,0 +1,107 @@ +/* Definitions of target machine for GNU compiler, for IBM S/390 + Copyright (C) 1999-2014 Free Software Foundation, Inc. + Contributed by Hartmut Penner (hpenner@de.ibm.com) and + Ulrich Weigand (uweigand@de.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __s390x__ + +#define EXPONENT_BIAS 127 +#define MANTISSA_BITS 23 +#define EXP(fp) (((fp.l) >> MANTISSA_BITS) & 0xFF) +#define PRECISION (MANTISSA_BITS + 1) +#define SIGNBIT 0x80000000 +#define SIGN(fp) ((fp.l) & SIGNBIT) +#define HIDDEN (1 << MANTISSA_BITS) +#define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN) +#define FRAC(fp) ((fp.l) & 0x7FFFFF) +#define LLONG_MAX 9223372036854775807LL +#define LLONG_MIN (-LLONG_MAX - 1LL) + +typedef int DItype_x __attribute__ ((mode (DI))); +typedef unsigned int UDItype_x __attribute__ ((mode (DI))); +typedef int SItype_x __attribute__ ((mode (SI))); +typedef unsigned int USItype_x __attribute__ ((mode (SI))); + +union float_long + { + float f; + USItype_x l; + }; + +static __inline__ void +fexceptdiv (float d, float e) +{ + __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); +} + +DItype_x __fixsfdi (float a1); + +/* convert double to int */ +DItype_x +__fixsfdi (float a1) +{ + register union float_long fl1; + register int exp; + register DItype_x l; + + fl1.f = a1; + + /* +/- 0, denormalized */ + if (!EXP (fl1)) + return 0; + + exp = EXP (fl1) - EXPONENT_BIAS - MANTISSA_BITS; + + /* number < 1 */ + if (exp <= -PRECISION) + return 0; + + /* NaN */ + + if ((EXP (fl1) == 0xff) && (FRAC (fl1) != 0)) /* NaN */ + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0x8000000000000000ULL; + } + + /* Number big number & +/- inf */ + if (exp >= 40) { + /* Don't throw an exception for -1p+63 */ + if (!SIGN (fl1) || exp > 40 || FRAC (fl1) != 0) + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return SIGN (fl1) ? LLONG_MIN : LLONG_MAX; + } + + l = MANT (fl1); + + if (exp > 0) + l <<= exp; + else + l >>= -exp; + + return (SIGN (fl1) ? -l : l); +} +#endif /* !__s390x__ */ diff --git a/gcc-4.9/libgcc/config/s390/32/_fixtfdi.c b/gcc-4.9/libgcc/config/s390/32/_fixtfdi.c new file mode 100644 index 000000000..de84972a2 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/_fixtfdi.c @@ -0,0 +1,122 @@ +/* Definitions of target machine for GNU compiler, for IBM S/390 + Copyright (C) 1999-2014 Free Software Foundation, Inc. + Contributed by Hartmut Penner (hpenner@de.ibm.com) and + Ulrich Weigand (uweigand@de.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __s390x__ + +#define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) +#define EXPONENT_BIAS 16383 +#define MANTISSA_BITS 112 +#define PRECISION (MANTISSA_BITS + 1) +#define SIGNBIT 0x80000000 +#define SIGN(fp) ((fp.l.i[0]) & SIGNBIT) +#define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) +#define MANTD_LOW_LL(fp) (fp.ll[1]) +#define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) +#define HIGH_LL_FRAC_BITS 48 +#define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) +#define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) +#define LLONG_MAX 9223372036854775807LL +#define LLONG_MIN (-LLONG_MAX - 1LL) + +typedef int DItype_x __attribute__ ((mode (DI))); +typedef unsigned int UDItype_x __attribute__ ((mode (DI))); +typedef int SItype_x __attribute__ ((mode (SI))); +typedef unsigned int USItype_x __attribute__ ((mode (SI))); + +union double_long { + long double d; + struct { + SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ + } l; + UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ +}; + +static __inline__ void +fexceptdiv (float d, float e) +{ + __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); +} + +DItype_x __fixtfdi (long double a1); + +/* convert double to unsigned int */ +DItype_x +__fixtfdi (long double a1) +{ + register union double_long dl1; + register int exp; + register UDItype_x l; + + dl1.d = a1; + + /* +/- 0, denormalized */ + if (!EXPD (dl1)) + return 0; + + /* The exponent - considered the binary point at the right end of + the mantissa. */ + exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; + + /* number < 1: If the mantissa would need to be right-shifted more bits than + its size the result would be zero. */ + if (exp <= -PRECISION) + return 0; + + /* NaN: All exponent bits set and a nonzero fraction. */ + if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0x8000000000000000ULL; + } + + /* One extra bit is needed for the unit bit which is appended by + MANTD_HIGH_LL on the left of the matissa. */ + exp += HIGH_LL_FRAC_BITS + 1; + + /* If the result would still need a left shift it will be too large + to be represented. Compared to the unsigned variant we have to + take care that there is still space for the sign bit to be + applied. So we can only go on if there is a right-shift by one + or more. */ + if (exp >= 0) + { + /* Don't throw an exception for -1p+63 */ + if (!SIGN (dl1) + || exp > 0 + || MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) + || (dl1.ll[0] & HIGH_LL_FRAC_MASK)) + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return SIGN (dl1) ? LLONG_MIN : LLONG_MAX; + } + + l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) + | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); + + return SIGN (dl1) ? -(l >> -exp) : l >> -exp; +} +#endif /* !__s390x__ */ diff --git a/gcc-4.9/libgcc/config/s390/32/_fixunsdfdi.c b/gcc-4.9/libgcc/config/s390/32/_fixunsdfdi.c new file mode 100644 index 000000000..0a249611a --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/_fixunsdfdi.c @@ -0,0 +1,120 @@ +/* Definitions of target machine for GNU compiler, for IBM S/390 + Copyright (C) 1999-2014 Free Software Foundation, Inc. + Contributed by Hartmut Penner (hpenner@de.ibm.com) and + Ulrich Weigand (uweigand@de.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __s390x__ + +#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) +#define EXPONENT_BIAS 1023 +#define MANTISSA_BITS 52 +#define PRECISION (MANTISSA_BITS + 1) +#define SIGNBIT 0x80000000 +#define SIGN(fp) ((fp.l.upper) & SIGNBIT) +#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) +#define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1)) +#define HIDDEND_LL ((UDItype_x)1 << 52) + +typedef int DItype_x __attribute__ ((mode (DI))); +typedef unsigned int UDItype_x __attribute__ ((mode (DI))); +typedef int SItype_x __attribute__ ((mode (SI))); +typedef unsigned int USItype_x __attribute__ ((mode (SI))); + +union double_long { + double d; + struct { + SItype_x upper; + USItype_x lower; + } l; + UDItype_x ll; +}; + +static __inline__ void +fexceptdiv (float d, float e) +{ + __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); +} + +UDItype_x __fixunsdfdi (double a1); + +/* convert double to unsigned int */ +UDItype_x +__fixunsdfdi (double a1) +{ + register union double_long dl1; + register int exp; + register UDItype_x l; + + dl1.d = a1; + + /* +/- 0, denormalized */ + if (!EXPD (dl1)) + return 0; + + /* Negative. */ + if (SIGN (dl1)) + { + /* Value is <= -1.0 + C99 Annex F.4 requires an "invalid" exception to be thrown. */ + if (EXPD (dl1) >= EXPONENT_BIAS) + fexceptdiv (0.0, 0.0); + return 0; + } + + exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; + + /* number < 1 */ + + if (exp < -PRECISION) + return 0; + + /* NaN */ + + if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */ + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0x0ULL; + } + + /* Number big number & + inf */ + + if (exp >= 12) + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0xFFFFFFFFFFFFFFFFULL; + } + + l = MANTD_LL(dl1); + + /* shift down until exp < 12 or l = 0 */ + if (exp > 0) + l <<= exp; + else + l >>= -exp; + + return l; +} +#endif /* !__s390x__ */ diff --git a/gcc-4.9/libgcc/config/s390/32/_fixunssfdi.c b/gcc-4.9/libgcc/config/s390/32/_fixunssfdi.c new file mode 100644 index 000000000..7aeed28a0 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/_fixunssfdi.c @@ -0,0 +1,114 @@ +/* Definitions of target machine for GNU compiler, for IBM S/390 + Copyright (C) 1999-2014 Free Software Foundation, Inc. + Contributed by Hartmut Penner (hpenner@de.ibm.com) and + Ulrich Weigand (uweigand@de.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __s390x__ + +#define EXPONENT_BIAS 127 +#define MANTISSA_BITS 23 +#define EXP(fp) (((fp.l) >> MANTISSA_BITS) & 0xFF) +#define SIGNBIT 0x80000000 +#define SIGN(fp) ((fp.l) & SIGNBIT) +#define HIDDEN (1 << MANTISSA_BITS) +#define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN) +#define FRAC(fp) ((fp.l) & 0x7FFFFF) + +typedef int DItype_x __attribute__ ((mode (DI))); +typedef unsigned int UDItype_x __attribute__ ((mode (DI))); +typedef int SItype_x __attribute__ ((mode (SI))); +typedef unsigned int USItype_x __attribute__ ((mode (SI))); + +union float_long + { + float f; + USItype_x l; + }; + +static __inline__ void +fexceptdiv (float d, float e) +{ + __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); +} + +UDItype_x __fixunssfdi (float a1); + +/* convert float to unsigned int */ +UDItype_x +__fixunssfdi (float a1) +{ + register union float_long fl1; + register int exp; + register UDItype_x l; + + fl1.f = a1; + + /* +/- 0, denormalized */ + if (!EXP (fl1)) + return 0; + + /* Negative. */ + if (SIGN (fl1)) + { + /* Value is <= -1.0 + C99 Annex F.4 requires an "invalid" exception to be thrown. */ + if (EXP (fl1) >= EXPONENT_BIAS) + fexceptdiv (0.0, 0.0); + return 0; + } + + exp = EXP (fl1) - EXPONENT_BIAS - MANTISSA_BITS; + + /* number < 1 */ + if (exp < -24) + return 0; + + /* NaN */ + + if ((EXP (fl1) == 0xff) && (FRAC (fl1) != 0)) /* NaN */ + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0x0ULL; + } + + /* Number big number & + inf */ + + if (exp >= 41) + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0xFFFFFFFFFFFFFFFFULL; + } + + l = MANT (fl1); + + if (exp > 0) + l <<= exp; + else + l >>= -exp; + + return l; +} +#endif /* !__s390x__ */ diff --git a/gcc-4.9/libgcc/config/s390/32/_fixunstfdi.c b/gcc-4.9/libgcc/config/s390/32/_fixunstfdi.c new file mode 100644 index 000000000..2f90a5f2f --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/_fixunstfdi.c @@ -0,0 +1,125 @@ +/* Definitions of target machine for GNU compiler, for IBM S/390 + Copyright (C) 1999-2014 Free Software Foundation, Inc. + Contributed by Hartmut Penner (hpenner@de.ibm.com) and + Ulrich Weigand (uweigand@de.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#ifndef __s390x__ + +#define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) +#define EXPONENT_BIAS 16383 +#define MANTISSA_BITS 112 +#define PRECISION (MANTISSA_BITS + 1) +#define SIGNBIT 0x80000000 +#define SIGND(fp) ((fp.l.i[0]) & SIGNBIT) +#define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) +#define MANTD_LOW_LL(fp) (fp.ll[1]) +#define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) +#define HIGH_LL_FRAC_BITS 48 +#define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) +#define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) + +typedef int DItype_x __attribute__ ((mode (DI))); +typedef unsigned int UDItype_x __attribute__ ((mode (DI))); +typedef int SItype_x __attribute__ ((mode (SI))); +typedef unsigned int USItype_x __attribute__ ((mode (SI))); + +union double_long { + long double d; + struct { + SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ + } l; + UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ +}; + +static __inline__ void +fexceptdiv (float d, float e) +{ + __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); +} + +UDItype_x __fixunstfdi (long double a1); + +/* convert double to unsigned int */ +UDItype_x +__fixunstfdi (long double a1) +{ + register union double_long dl1; + register int exp; + register UDItype_x l; + + dl1.d = a1; + + /* +/- 0, denormalized */ + if (!EXPD (dl1)) + return 0; + + /* Negative. */ + if (SIGND (dl1)) + { + /* Value is <= -1.0 + C99 Annex F.4 requires an "invalid" exception to be thrown. */ + if (EXPD (dl1) >= EXPONENT_BIAS) + fexceptdiv (0.0, 0.0); + return 0; + } + + /* The exponent - considered the binary point at the right end of + the mantissa. */ + exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; + + /* number < 1: If the mantissa would need to be right-shifted more bits than + its size (plus the implied one bit on the left) the result would be + zero. */ + if (exp <= -PRECISION) + return 0; + + /* NaN: All exponent bits set and a nonzero fraction. */ + if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0; + } + + /* One extra bit is needed for the unit bit which is appended by + MANTD_HIGH_LL on the left of the matissa. */ + exp += HIGH_LL_FRAC_BITS + 1; + + /* If the result would still need a left shift it will be too + large to be represented. Infinities have all exponent bits set + and will end up here as well. */ + if (exp > 0) + { + /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ + fexceptdiv (0.0, 0.0); + return 0xFFFFFFFFFFFFFFFFULL; + } + + l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) + | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); + + return l >> -exp; +} + +#endif /* !__s390x__ */ diff --git a/gcc-4.9/libgcc/config/s390/32/t-floattodi b/gcc-4.9/libgcc/config/s390/32/t-floattodi new file mode 100644 index 000000000..4bd87b1f8 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/32/t-floattodi @@ -0,0 +1,5 @@ +floattodi-functions = _fixsfdi _fixdfdi _fixtfdi _fixunssfdi _fixunsdfdi _fixunstfdi +LIB2FUNCS_EXCLUDE += $(floattodi-functions) + +floattodi-src = $(addsuffix .c, $(floattodi-functions)) +LIB2ADD = $(addprefix $(srcdir)/config/s390/32/, $(floattodi-src)) diff --git a/gcc-4.9/libgcc/config/s390/gthr-tpf.h b/gcc-4.9/libgcc/config/s390/gthr-tpf.h new file mode 100644 index 000000000..95d87db34 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/gthr-tpf.h @@ -0,0 +1,234 @@ +/* Threads compatibility routines for libgcc2 and libobjc. + Compile this one with gcc. + Copyright (C) 2004-2014 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +/* TPF needs its own version of gthr-*.h because TPF always links to + the thread library. However, for performance reasons we still do not + want to issue thread api calls unless a check is made to see that we + are running as a thread. */ + +#ifndef GCC_GTHR_TPF_H +#define GCC_GTHR_TPF_H + +/* POSIX threads specific definitions. + Easy, since the interface is just one-to-one mapping. */ + +#define __GTHREADS 1 + +/* Some implementations of <pthread.h> require this to be defined. */ +#ifndef _REENTRANT +#define _REENTRANT 1 +#endif + +#include <pthread.h> +#include <unistd.h> + +typedef pthread_key_t __gthread_key_t; +typedef pthread_once_t __gthread_once_t; +typedef pthread_mutex_t __gthread_mutex_t; +typedef pthread_mutex_t __gthread_recursive_mutex_t; + +#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) +#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER +#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) +#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#endif + +#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT +#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function + +#define NOTATHREAD 00 +#define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u +#define ECBPG2PTR ECBBASEPTR + 0x1000 +#define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16)) +#define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD) + +#if SUPPORTS_WEAK && GTHREAD_USE_WEAK +# define __gthrw(name) \ + static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name))); +# define __gthrw_(name) __gthrw_ ## name +#else +# define __gthrw(name) +# define __gthrw_(name) name +#endif + +__gthrw(pthread_once) +__gthrw(pthread_key_create) +__gthrw(pthread_key_delete) +__gthrw(pthread_getspecific) +__gthrw(pthread_setspecific) +__gthrw(pthread_create) + +__gthrw(pthread_mutex_lock) +__gthrw(pthread_mutex_trylock) +__gthrw(pthread_mutex_unlock) +__gthrw(pthread_mutexattr_init) +__gthrw(pthread_mutexattr_settype) +__gthrw(pthread_mutexattr_destroy) +__gthrw(pthread_mutex_init) +__gthrw(pthread_mutex_destroy) + +static inline int +__gthread_active_p (void) +{ + return 1; +} + +static inline int +__gthread_once (__gthread_once_t *__once, void (*__func) (void)) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_once) (__once, __func); + else + return -1; +} + +static inline int +__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_key_create) (__key, __dtor); + else + return -1; +} + +static inline int +__gthread_key_delete (__gthread_key_t __key) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_key_delete) (__key); + else + return -1; +} + +static inline void * +__gthread_getspecific (__gthread_key_t __key) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_getspecific) (__key); + else + return NULL; +} + +static inline int +__gthread_setspecific (__gthread_key_t __key, const void *__ptr) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_setspecific) (__key, __ptr); + else + return -1; +} + +static inline int +__gthread_mutex_destroy (__gthread_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_mutex_destroy) (__mutex); + else + return 0; +} + +static inline int +__gthread_mutex_lock (__gthread_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_mutex_lock) (__mutex); + else + return 0; +} + +static inline int +__gthread_mutex_trylock (__gthread_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_mutex_trylock) (__mutex); + else + return 0; +} + +static inline int +__gthread_mutex_unlock (__gthread_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthrw_(pthread_mutex_unlock) (__mutex); + else + return 0; +} + +static inline int +__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthread_mutex_lock (__mutex); + else + return 0; +} + +static inline int +__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthread_mutex_trylock (__mutex); + else + return 0; +} + +static inline int +__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + return __gthread_mutex_unlock (__mutex); + else + return 0; +} + +static inline int +__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex) +{ + if (__tpf_pthread_active ()) + { + pthread_mutexattr_t __attr; + int __r; + + __r = __gthrw_(pthread_mutexattr_init) (&__attr); + if (!__r) + __r = __gthrw_(pthread_mutexattr_settype) (&__attr, + PTHREAD_MUTEX_RECURSIVE); + if (!__r) + __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr); + if (!__r) + __r = __gthrw_(pthread_mutexattr_destroy) (&__attr); + return __r; + } + return 0; +} + +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy (__mutex); +} + +#endif /* ! GCC_GTHR_TPF_H */ diff --git a/gcc-4.9/libgcc/config/s390/libgcc-glibc.ver b/gcc-4.9/libgcc/config/s390/libgcc-glibc.ver new file mode 100644 index 000000000..a03d2bd69 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/libgcc-glibc.ver @@ -0,0 +1,116 @@ +# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# In order to work around the very problems that force us to now generally +# create a libgcc.so, glibc reexported a number of routines from libgcc.a. +# By now choosing the same version tags for these specific routines, we +# maintain enough binary compatibility to allow future versions of glibc +# to defer implementation of these routines to libgcc.so via DT_AUXILIARY. + +# Note that we cannot use the default libgcc-glibc.ver file on s390x, +# because GLIBC_2.0 does not exist on this architecture, as the first +# ever glibc release on the platform was GLIBC_2.2. + +%ifndef __s390x__ +%exclude { + __divdi3 + __moddi3 + __udivdi3 + __umoddi3 + __register_frame + __register_frame_table + __deregister_frame + __register_frame_info + __deregister_frame_info + __frame_state_for + __register_frame_info_table +} + +%inherit GCC_3.0 GLIBC_2.0 +GLIBC_2.0 { + __divdi3 + __moddi3 + __udivdi3 + __umoddi3 + + __register_frame + __register_frame_table + __deregister_frame + __register_frame_info + __deregister_frame_info + __frame_state_for + __register_frame_info_table +} +%endif + +%ifdef __s390x__ +%exclude { + __register_frame + __register_frame_table + __deregister_frame + __register_frame_info + __deregister_frame_info + __frame_state_for + __register_frame_info_table +} + +%inherit GCC_3.0 GLIBC_2.2 +GLIBC_2.2 { + __register_frame + __register_frame_table + __deregister_frame + __register_frame_info + __deregister_frame_info + __frame_state_for + __register_frame_info_table +} +%endif + +# With GCC 4.1.0 long double 128 bit support was introduced. The +# following symbols coming from libgcc are enabled when -mlong-double-128 +# is specified. These lines make the symbols to get a @@GCC_4.1.0 attached. + +%exclude { + __divtc3 + __multc3 + __powitf2 + __fixtfti + __fixunstfti + __floattitf + + __fixtfdi + __fixunstfdi + __floatditf +} + +GCC_4.1.0 { + __divtc3 + __multc3 + __powitf2 + +%ifdef __s390x__ + __fixtfti + __fixunstfti + __floattitf + +%else + __fixtfdi + __fixunstfdi + __floatditf +%endif +} diff --git a/gcc-4.9/libgcc/config/s390/linux-unwind.h b/gcc-4.9/libgcc/config/s390/linux-unwind.h new file mode 100644 index 000000000..d78754f75 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/linux-unwind.h @@ -0,0 +1,132 @@ +/* DWARF2 EH unwinding support for S/390 Linux. + Copyright (C) 2004-2014 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +/* Do code reading to identify a signal frame, and set the frame + state data appropriately. See unwind-dw2.c for the structs. */ + +#define MD_FALLBACK_FRAME_STATE_FOR s390_fallback_frame_state + +static _Unwind_Reason_Code +s390_fallback_frame_state (struct _Unwind_Context *context, + _Unwind_FrameState *fs) +{ + static const unsigned char dwarf_to_fpr_map[16] = + { 0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15 }; + unsigned char *pc = context->ra; + long new_cfa; + int i; + + typedef struct + { + unsigned long psw_mask; + unsigned long psw_addr; + unsigned long gprs[16]; + unsigned int acrs[16]; + unsigned int fpc; + unsigned int __pad; + double fprs[16]; + } __attribute__ ((__aligned__ (8))) sigregs_; + + sigregs_ *regs; + int *signo; + + /* svc $__NR_sigreturn or svc $__NR_rt_sigreturn */ + if (pc[0] != 0x0a || (pc[1] != 119 && pc[1] != 173)) + return _URC_END_OF_STACK; + + /* Legacy frames: + old signal mask (8 bytes) + pointer to sigregs (8 bytes) - points always to next location + sigregs + retcode + This frame layout was used on kernels < 2.6.9 for non-RT frames, + and on kernels < 2.4.13 for RT frames as well. Note that we need + to look at RA to detect this layout -- this means that if you use + sa_restorer to install a different signal restorer on a legacy + kernel, unwinding from signal frames will not work. */ + if (context->ra == context->cfa + 16 + sizeof (sigregs_)) + { + regs = (sigregs_ *)(context->cfa + 16); + signo = NULL; + } + + /* New-style RT frame: + retcode + alignment (8 bytes) + siginfo (128 bytes) + ucontext (contains sigregs) */ + else if (pc[1] == 173 /* __NR_rt_sigreturn */) + { + struct ucontext_ + { + unsigned long uc_flags; + struct ucontext_ *uc_link; + unsigned long uc_stack[3]; + sigregs_ uc_mcontext; + } *uc = context->cfa + 8 + 128; + + regs = &uc->uc_mcontext; + signo = context->cfa + sizeof(long); + } + + /* New-style non-RT frame: + old signal mask (8 bytes) + pointer to sigregs (followed by signal number) */ + else + { + regs = *(sigregs_ **)(context->cfa + 8); + signo = (int *)(regs + 1); + } + + new_cfa = regs->gprs[15] + 16*sizeof(long) + 32; + fs->regs.cfa_how = CFA_REG_OFFSET; + fs->regs.cfa_reg = 15; + fs->regs.cfa_offset = + new_cfa - (long) context->cfa + 16*sizeof(long) + 32; + + for (i = 0; i < 16; i++) + { + fs->regs.reg[i].how = REG_SAVED_OFFSET; + fs->regs.reg[i].loc.offset = + (long)®s->gprs[i] - new_cfa; + } + for (i = 0; i < 16; i++) + { + fs->regs.reg[16+i].how = REG_SAVED_OFFSET; + fs->regs.reg[16+i].loc.offset = + (long)®s->fprs[dwarf_to_fpr_map[i]] - new_cfa; + } + + /* Load return addr from PSW into dummy register 32. */ + + fs->regs.reg[32].how = REG_SAVED_OFFSET; + fs->regs.reg[32].loc.offset = (long)®s->psw_addr - new_cfa; + fs->retaddr_column = 32; + /* SIGILL, SIGFPE and SIGTRAP are delivered with psw_addr + after the faulting instruction rather than before it. + Don't set FS->signal_frame in that case. */ + if (!signo || (*signo != 4 && *signo != 5 && *signo != 8)) + fs->signal_frame = 1; + + return _URC_NO_REASON; +} diff --git a/gcc-4.9/libgcc/config/s390/t-crtstuff b/gcc-4.9/libgcc/config/s390/t-crtstuff new file mode 100644 index 000000000..d738673fe --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/t-crtstuff @@ -0,0 +1,5 @@ +# crtend*.o cannot be compiled without -fno-asynchronous-unwind-tables, +# because then __FRAME_END__ might not be the last thing in .eh_frame +# section. +CRTSTUFF_T_CFLAGS += -fno-asynchronous-unwind-tables +CRTSTUFF_T_CFLAGS_S += -fno-asynchronous-unwind-tables diff --git a/gcc-4.9/libgcc/config/s390/t-linux b/gcc-4.9/libgcc/config/s390/t-linux new file mode 100644 index 000000000..b7670828d --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/t-linux @@ -0,0 +1,7 @@ +DFP_ENABLE = true + +# Override t-slibgcc-elf-ver to export some libgcc symbols with +# the symbol versions that glibc used. +SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/s390/libgcc-glibc.ver + +HOST_LIBGCC2_CFLAGS += -mlong-double-128
\ No newline at end of file diff --git a/gcc-4.9/libgcc/config/s390/tpf-unwind.h b/gcc-4.9/libgcc/config/s390/tpf-unwind.h new file mode 100644 index 000000000..5fa177b50 --- /dev/null +++ b/gcc-4.9/libgcc/config/s390/tpf-unwind.h @@ -0,0 +1,252 @@ +/* DWARF2 EH unwinding support for TPF OS. + Copyright (C) 2004-2014 Free Software Foundation, Inc. + Contributed by P.J. Darcy (darcypj@us.ibm.com). + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#include <dlfcn.h> + +/* Function Name: __isPATrange + Parameters passed into it: address to check + Return Value: A 1 if address is in pat code "range", 0 if not + Description: This function simply checks to see if the address + passed to it is in the CP pat code range. */ + +#define MIN_PATRANGE 0x10000 +#define MAX_PATRANGE 0x800000 + +static inline unsigned int +__isPATrange (void *addr) +{ + if (addr > (void *)MIN_PATRANGE && addr < (void *)MAX_PATRANGE) + return 1; + else + return 0; +} + +/* TPF return address offset from start of stack frame. */ +#define TPFRA_OFFSET 168 + +/* Exceptions macro defined for TPF so that functions without + dwarf frame information can be used with exceptions. */ +#define MD_FALLBACK_FRAME_STATE_FOR s390_fallback_frame_state + +static _Unwind_Reason_Code +s390_fallback_frame_state (struct _Unwind_Context *context, + _Unwind_FrameState *fs) +{ + unsigned long int regs; + unsigned long int new_cfa; + int i; + + regs = *((unsigned long int *) + (((unsigned long int) context->cfa) - STACK_POINTER_OFFSET)); + + /* Are we going through special linkage code? */ + if (__isPATrange (context->ra)) + { + + /* Our return register isn't zero for end of stack, so + check backward stackpointer to see if it is zero. */ + if (regs == NULL) + return _URC_END_OF_STACK; + + /* No stack frame. */ + fs->regs.cfa_how = CFA_REG_OFFSET; + fs->regs.cfa_reg = 15; + fs->regs.cfa_offset = STACK_POINTER_OFFSET; + + /* All registers remain unchanged ... */ + for (i = 0; i < 32; i++) + { + fs->regs.reg[i].how = REG_SAVED_REG; + fs->regs.reg[i].loc.reg = i; + } + + /* ... except for %r14, which is stored at CFA-112 + and used as return address. */ + fs->regs.reg[14].how = REG_SAVED_OFFSET; + fs->regs.reg[14].loc.offset = TPFRA_OFFSET - STACK_POINTER_OFFSET; + fs->retaddr_column = 14; + + return _URC_NO_REASON; + } + + regs = *((unsigned long int *) + (((unsigned long int) context->cfa) - STACK_POINTER_OFFSET)); + new_cfa = regs + STACK_POINTER_OFFSET; + + fs->regs.cfa_how = CFA_REG_OFFSET; + fs->regs.cfa_reg = 15; + fs->regs.cfa_offset = new_cfa - + (unsigned long int) context->cfa + STACK_POINTER_OFFSET; + + for (i = 0; i < 16; i++) + { + fs->regs.reg[i].how = REG_SAVED_OFFSET; + fs->regs.reg[i].loc.offset = regs + i*8 - new_cfa; + } + + for (i = 0; i < 4; i++) + { + fs->regs.reg[16 + i].how = REG_SAVED_OFFSET; + fs->regs.reg[16 + i].loc.offset = regs + 16*8 + i*8 - new_cfa; + } + + fs->retaddr_column = 14; + + return _URC_NO_REASON; +} + +/* Function Name: __tpf_eh_return + Parameters passed into it: Destination address to jump to. + Return Value: Converted Destination address if a Pat Stub exists. + Description: This function swaps the unwinding return address + with the cp stub code. The original target return address is + then stored into the tpf return address field. The cp stub + code is searched for by climbing back up the stack and + comparing the tpf stored return address object address to + that of the targets object address. */ + +#define CURRENT_STACK_PTR() \ + ({ register unsigned long int *stack_ptr asm ("%r15"); stack_ptr; }) + +#define PREVIOUS_STACK_PTR() \ + ((unsigned long int *)(*(CURRENT_STACK_PTR()))) + +#define RA_OFFSET 112 +#define R15_OFFSET 120 +#define TPFAREA_OFFSET 160 +#define TPFAREA_SIZE STACK_POINTER_OFFSET-TPFAREA_OFFSET +#define INVALID_RETURN 0 + +void * __tpf_eh_return (void *target); + +void * +__tpf_eh_return (void *target) +{ + Dl_info targetcodeInfo, currentcodeInfo; + int retval; + void *current, *stackptr, *destination_frame; + unsigned long int shifter, is_a_stub; + + is_a_stub = 0; + + /* Get code info for target return's address. */ + retval = dladdr (target, &targetcodeInfo); + + /* Ensure the code info is valid (for target). */ + if (retval != INVALID_RETURN) + { + + /* Get the stack pointer of the stack frame to be modified by + the exception unwinder. So that we can begin our climb + there. */ + stackptr = (void *) *((unsigned long int *) (*(PREVIOUS_STACK_PTR()))); + + /* Begin looping through stack frames. Stop if invalid + code information is retrieved or if a match between the + current stack frame iteration shared object's address + matches that of the target, calculated above. */ + do + { + /* Get return address based on our stackptr iterator. */ + current = (void *) *((unsigned long int *) + (stackptr+RA_OFFSET)); + + /* Is it a Pat Stub? */ + if (__isPATrange (current)) + { + /* Yes it was, get real return address + in TPF stack area. */ + current = (void *) *((unsigned long int *) + (stackptr+TPFRA_OFFSET)); + is_a_stub = 1; + } + + /* Get codeinfo on RA so that we can figure out + the module address. */ + retval = dladdr (current, ¤tcodeInfo); + + /* Check that codeinfo for current stack frame is valid. + Then compare the module address of current stack frame + to target stack frame to determine if we have the pat + stub address we want. Also ensure we are dealing + with a module crossing, stub return address. */ + if (is_a_stub && retval != INVALID_RETURN + && targetcodeInfo.dli_fbase == currentcodeInfo.dli_fbase) + { + /* Yes! They are in the same module. + Force copy of TPF private stack area to + destination stack frame TPF private area. */ + destination_frame = (void *) *((unsigned long int *) + (*PREVIOUS_STACK_PTR() + R15_OFFSET)); + + /* Copy TPF linkage area from current frame to + destination frame. */ + memcpy((void *) (destination_frame + TPFAREA_OFFSET), + (void *) (stackptr + TPFAREA_OFFSET), TPFAREA_SIZE); + + /* Now overlay the + real target address into the TPF stack area of + the target frame we are jumping to. */ + *((unsigned long int *) (destination_frame + + TPFRA_OFFSET)) = (unsigned long int) target; + + /* Before returning the desired pat stub address to + the exception handling unwinder so that it can + actually do the "leap" shift out the low order + bit designated to determine if we are in 64BIT mode. + This is necessary for CTOA stubs. + Otherwise we leap one byte past where we want to + go to in the TPF pat stub linkage code. */ + shifter = *((unsigned long int *) + (stackptr + RA_OFFSET)); + + shifter &= ~1ul; + + /* Store Pat Stub Address in destination Stack Frame. */ + *((unsigned long int *) (destination_frame + + RA_OFFSET)) = shifter; + + /* Re-adjust pat stub address to go to correct place + in linkage. */ + shifter = shifter - 4; + + return (void *) shifter; + } + + /* Desired module pat stub not found ... + Bump stack frame iterator. */ + stackptr = (void *) *(unsigned long int *) stackptr; + + is_a_stub = 0; + + } while (stackptr && retval != INVALID_RETURN + && targetcodeInfo.dli_fbase != currentcodeInfo.dli_fbase); + } + + /* No pat stub found, could be a problem? Simply return unmodified + target address. */ + return target; +} + |
