OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [arm/] [unwind-arm.c] - Diff between revs 154 and 816

Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* ARM EABI compliant unwinding routines.
/* ARM EABI compliant unwinding routines.
   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
   Contributed by Paul Brook
   Contributed by Paul Brook
 
 
   This file is free software; you can redistribute it and/or modify it
   This file is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   Free Software Foundation; either version 2, or (at your option) any
   later version.
   later version.
 
 
   In addition to the permissions in the GNU General Public License, the
   In addition to the permissions in the GNU General Public License, the
   Free Software Foundation gives you unlimited permission to link the
   Free Software Foundation gives you unlimited permission to link the
   compiled version of this file into combinations with other programs,
   compiled version of this file into combinations with other programs,
   and to distribute those combinations without any restriction coming
   and to distribute those combinations without any restriction coming
   from the use of this file.  (The General Public License restrictions
   from the use of this file.  (The General Public License restrictions
   do apply in other respects; for example, they cover modification of
   do apply in other respects; for example, they cover modification of
   the file, and distribution when not linked into a combine
   the file, and distribution when not linked into a combine
   executable.)
   executable.)
 
 
   This file is distributed in the hope that it will be useful, but
   This file is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
   General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, 51 Franklin Street, Fifth Floor,
   the Free Software Foundation, 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.  */
   Boston, MA 02110-1301, USA.  */
#include "unwind.h"
#include "unwind.h"
 
 
/* We add a prototype for abort here to avoid creating a dependency on
/* We add a prototype for abort here to avoid creating a dependency on
   target headers.  */
   target headers.  */
extern void abort (void);
extern void abort (void);
 
 
/* Definitions for C++ runtime support routines.  We make these weak
/* Definitions for C++ runtime support routines.  We make these weak
   declarations to avoid pulling in libsupc++ unnecessarily.  */
   declarations to avoid pulling in libsupc++ unnecessarily.  */
typedef unsigned char bool;
typedef unsigned char bool;
 
 
typedef struct _ZSt9type_info type_info; /* This names C++ type_info type */
typedef struct _ZSt9type_info type_info; /* This names C++ type_info type */
 
 
void __attribute__((weak)) __cxa_call_unexpected(_Unwind_Control_Block *ucbp);
void __attribute__((weak)) __cxa_call_unexpected(_Unwind_Control_Block *ucbp);
bool __attribute__((weak)) __cxa_begin_cleanup(_Unwind_Control_Block *ucbp);
bool __attribute__((weak)) __cxa_begin_cleanup(_Unwind_Control_Block *ucbp);
bool __attribute__((weak)) __cxa_type_match(_Unwind_Control_Block *ucbp,
bool __attribute__((weak)) __cxa_type_match(_Unwind_Control_Block *ucbp,
                                            const type_info *rttip,
                                            const type_info *rttip,
                                            void **matched_object);
                                            void **matched_object);
 
 
_Unwind_Ptr __attribute__((weak))
_Unwind_Ptr __attribute__((weak))
__gnu_Unwind_Find_exidx (_Unwind_Ptr, int *);
__gnu_Unwind_Find_exidx (_Unwind_Ptr, int *);
 
 
/* Misc constants.  */
/* Misc constants.  */
#define R_IP    12
#define R_IP    12
#define R_SP    13
#define R_SP    13
#define R_LR    14
#define R_LR    14
#define R_PC    15
#define R_PC    15
 
 
#define EXIDX_CANTUNWIND 1
#define EXIDX_CANTUNWIND 1
#define uint32_highbit (((_uw) 1) << 31)
#define uint32_highbit (((_uw) 1) << 31)
 
 
#define UCB_FORCED_STOP_FN(ucbp) ((ucbp)->unwinder_cache.reserved1)
#define UCB_FORCED_STOP_FN(ucbp) ((ucbp)->unwinder_cache.reserved1)
#define UCB_PR_ADDR(ucbp) ((ucbp)->unwinder_cache.reserved2)
#define UCB_PR_ADDR(ucbp) ((ucbp)->unwinder_cache.reserved2)
#define UCB_SAVED_CALLSITE_ADDR(ucbp) ((ucbp)->unwinder_cache.reserved3)
#define UCB_SAVED_CALLSITE_ADDR(ucbp) ((ucbp)->unwinder_cache.reserved3)
#define UCB_FORCED_STOP_ARG(ucbp) ((ucbp)->unwinder_cache.reserved4)
#define UCB_FORCED_STOP_ARG(ucbp) ((ucbp)->unwinder_cache.reserved4)
 
 
struct core_regs
struct core_regs
{
{
  _uw r[16];
  _uw r[16];
};
};
 
 
/* We use normal integer types here to avoid the compiler generating
/* We use normal integer types here to avoid the compiler generating
   coprocessor instructions.  */
   coprocessor instructions.  */
struct vfp_regs
struct vfp_regs
{
{
  _uw64 d[16];
  _uw64 d[16];
  _uw pad;
  _uw pad;
};
};
 
 
struct fpa_reg
struct fpa_reg
{
{
  _uw w[3];
  _uw w[3];
};
};
 
 
struct fpa_regs
struct fpa_regs
{
{
  struct fpa_reg f[8];
  struct fpa_reg f[8];
};
};
 
 
/* Unwind descriptors.  */
/* Unwind descriptors.  */
 
 
typedef struct
typedef struct
{
{
  _uw16 length;
  _uw16 length;
  _uw16 offset;
  _uw16 offset;
} EHT16;
} EHT16;
 
 
typedef struct
typedef struct
{
{
  _uw length;
  _uw length;
  _uw offset;
  _uw offset;
} EHT32;
} EHT32;
 
 
/* The ABI specifies that the unwind routines may only use core registers,
/* The ABI specifies that the unwind routines may only use core registers,
   except when actually manipulating coprocessor state.  This allows
   except when actually manipulating coprocessor state.  This allows
   us to write one implementation that works on all platforms by
   us to write one implementation that works on all platforms by
   demand-saving coprocessor registers.
   demand-saving coprocessor registers.
 
 
   During unwinding we hold the coprocessor state in the actual hardware
   During unwinding we hold the coprocessor state in the actual hardware
   registers and allocate demand-save areas for use during phase1
   registers and allocate demand-save areas for use during phase1
   unwinding.  */
   unwinding.  */
 
 
typedef struct
typedef struct
{
{
  /* The first fields must be the same as a phase2_vrs.  */
  /* The first fields must be the same as a phase2_vrs.  */
  _uw demand_save_flags;
  _uw demand_save_flags;
  struct core_regs core;
  struct core_regs core;
  _uw prev_sp; /* Only valid during forced unwinding.  */
  _uw prev_sp; /* Only valid during forced unwinding.  */
  struct vfp_regs vfp;
  struct vfp_regs vfp;
  struct fpa_regs fpa;
  struct fpa_regs fpa;
} phase1_vrs;
} phase1_vrs;
 
 
#define DEMAND_SAVE_VFP 1
#define DEMAND_SAVE_VFP 1
 
 
/* This must match the structure created by the assembly wrappers.  */
/* This must match the structure created by the assembly wrappers.  */
typedef struct
typedef struct
{
{
  _uw demand_save_flags;
  _uw demand_save_flags;
  struct core_regs core;
  struct core_regs core;
} phase2_vrs;
} phase2_vrs;
 
 
 
 
/* An exception index table entry.  */
/* An exception index table entry.  */
 
 
typedef struct __EIT_entry
typedef struct __EIT_entry
{
{
  _uw fnoffset;
  _uw fnoffset;
  _uw content;
  _uw content;
} __EIT_entry;
} __EIT_entry;
 
 
/* Assembly helper functions.  */
/* Assembly helper functions.  */
 
 
/* Restore core register state.  Never returns.  */
/* Restore core register state.  Never returns.  */
void __attribute__((noreturn)) restore_core_regs (struct core_regs *);
void __attribute__((noreturn)) restore_core_regs (struct core_regs *);
 
 
 
 
/* Coprocessor register state manipulation functions.  */
/* Coprocessor register state manipulation functions.  */
 
 
void __gnu_Unwind_Save_VFP (struct vfp_regs * p);
void __gnu_Unwind_Save_VFP (struct vfp_regs * p);
void __gnu_Unwind_Restore_VFP (struct vfp_regs * p);
void __gnu_Unwind_Restore_VFP (struct vfp_regs * p);
 
 
/* Restore coprocessor state after phase1 unwinding.  */
/* Restore coprocessor state after phase1 unwinding.  */
static void
static void
restore_non_core_regs (phase1_vrs * vrs)
restore_non_core_regs (phase1_vrs * vrs)
{
{
  if ((vrs->demand_save_flags & DEMAND_SAVE_VFP) == 0)
  if ((vrs->demand_save_flags & DEMAND_SAVE_VFP) == 0)
    __gnu_Unwind_Restore_VFP (&vrs->vfp);
    __gnu_Unwind_Restore_VFP (&vrs->vfp);
}
}
 
 
/* A better way to do this would probably be to compare the absolute address
/* A better way to do this would probably be to compare the absolute address
   with a segment relative relocation of the same symbol.  */
   with a segment relative relocation of the same symbol.  */
 
 
extern int __text_start;
extern int __text_start;
extern int __data_start;
extern int __data_start;
 
 
/* The exception index table location.  */
/* The exception index table location.  */
extern __EIT_entry __exidx_start;
extern __EIT_entry __exidx_start;
extern __EIT_entry __exidx_end;
extern __EIT_entry __exidx_end;
 
 
/* ABI defined personality routines.  */
/* ABI defined personality routines.  */
extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr0 (_Unwind_State,
extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr0 (_Unwind_State,
    _Unwind_Control_Block *, _Unwind_Context *);// __attribute__((weak));
    _Unwind_Control_Block *, _Unwind_Context *);// __attribute__((weak));
extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr1 (_Unwind_State,
extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr1 (_Unwind_State,
    _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
    _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr2 (_Unwind_State,
extern _Unwind_Reason_Code __aeabi_unwind_cpp_pr2 (_Unwind_State,
    _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
    _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak));
 
 
/* ABI defined routine to store a virtual register to memory.  */
/* ABI defined routine to store a virtual register to memory.  */
 
 
_Unwind_VRS_Result _Unwind_VRS_Get (_Unwind_Context *context,
_Unwind_VRS_Result _Unwind_VRS_Get (_Unwind_Context *context,
                                    _Unwind_VRS_RegClass regclass,
                                    _Unwind_VRS_RegClass regclass,
                                    _uw regno,
                                    _uw regno,
                                    _Unwind_VRS_DataRepresentation representation,
                                    _Unwind_VRS_DataRepresentation representation,
                                    void *valuep)
                                    void *valuep)
{
{
  phase1_vrs *vrs = (phase1_vrs *) context;
  phase1_vrs *vrs = (phase1_vrs *) context;
 
 
  switch (regclass)
  switch (regclass)
    {
    {
    case _UVRSC_CORE:
    case _UVRSC_CORE:
      if (representation != _UVRSD_UINT32
      if (representation != _UVRSD_UINT32
          || regno > 15)
          || regno > 15)
        return _UVRSR_FAILED;
        return _UVRSR_FAILED;
      *(_uw *) valuep = vrs->core.r[regno];
      *(_uw *) valuep = vrs->core.r[regno];
      return _UVRSR_OK;
      return _UVRSR_OK;
 
 
    case _UVRSC_VFP:
    case _UVRSC_VFP:
    case _UVRSC_FPA:
    case _UVRSC_FPA:
    case _UVRSC_WMMXD:
    case _UVRSC_WMMXD:
    case _UVRSC_WMMXC:
    case _UVRSC_WMMXC:
      return _UVRSR_NOT_IMPLEMENTED;
      return _UVRSR_NOT_IMPLEMENTED;
 
 
    default:
    default:
      return _UVRSR_FAILED;
      return _UVRSR_FAILED;
    }
    }
}
}
 
 
 
 
/* ABI defined function to load a virtual register from memory.  */
/* ABI defined function to load a virtual register from memory.  */
 
 
_Unwind_VRS_Result _Unwind_VRS_Set (_Unwind_Context *context,
_Unwind_VRS_Result _Unwind_VRS_Set (_Unwind_Context *context,
                                    _Unwind_VRS_RegClass regclass,
                                    _Unwind_VRS_RegClass regclass,
                                    _uw regno,
                                    _uw regno,
                                    _Unwind_VRS_DataRepresentation representation,
                                    _Unwind_VRS_DataRepresentation representation,
                                    void *valuep)
                                    void *valuep)
{
{
  phase1_vrs *vrs = (phase1_vrs *) context;
  phase1_vrs *vrs = (phase1_vrs *) context;
 
 
  switch (regclass)
  switch (regclass)
    {
    {
    case _UVRSC_CORE:
    case _UVRSC_CORE:
      if (representation != _UVRSD_UINT32
      if (representation != _UVRSD_UINT32
          || regno > 15)
          || regno > 15)
        return _UVRSR_FAILED;
        return _UVRSR_FAILED;
 
 
      vrs->core.r[regno] = *(_uw *) valuep;
      vrs->core.r[regno] = *(_uw *) valuep;
      return _UVRSR_OK;
      return _UVRSR_OK;
 
 
    case _UVRSC_VFP:
    case _UVRSC_VFP:
    case _UVRSC_FPA:
    case _UVRSC_FPA:
    case _UVRSC_WMMXD:
    case _UVRSC_WMMXD:
    case _UVRSC_WMMXC:
    case _UVRSC_WMMXC:
      return _UVRSR_NOT_IMPLEMENTED;
      return _UVRSR_NOT_IMPLEMENTED;
 
 
    default:
    default:
      return _UVRSR_FAILED;
      return _UVRSR_FAILED;
    }
    }
}
}
 
 
 
 
/* ABI defined function to pop registers off the stack.  */
/* ABI defined function to pop registers off the stack.  */
 
 
_Unwind_VRS_Result _Unwind_VRS_Pop (_Unwind_Context *context,
_Unwind_VRS_Result _Unwind_VRS_Pop (_Unwind_Context *context,
                                    _Unwind_VRS_RegClass regclass,
                                    _Unwind_VRS_RegClass regclass,
                                    _uw discriminator,
                                    _uw discriminator,
                                    _Unwind_VRS_DataRepresentation representation)
                                    _Unwind_VRS_DataRepresentation representation)
{
{
  phase1_vrs *vrs = (phase1_vrs *) context;
  phase1_vrs *vrs = (phase1_vrs *) context;
 
 
  switch (regclass)
  switch (regclass)
    {
    {
    case _UVRSC_CORE:
    case _UVRSC_CORE:
      {
      {
        _uw *ptr;
        _uw *ptr;
        _uw mask;
        _uw mask;
        int i;
        int i;
 
 
        if (representation != _UVRSD_UINT32)
        if (representation != _UVRSD_UINT32)
          return _UVRSR_FAILED;
          return _UVRSR_FAILED;
 
 
        mask = discriminator & 0xffff;
        mask = discriminator & 0xffff;
        ptr = (_uw *) vrs->core.r[R_SP];
        ptr = (_uw *) vrs->core.r[R_SP];
        /* Pop the requested registers.  */
        /* Pop the requested registers.  */
        for (i = 0; i < 16; i++)
        for (i = 0; i < 16; i++)
          {
          {
            if (mask & (1 << i))
            if (mask & (1 << i))
              vrs->core.r[i] = *(ptr++);
              vrs->core.r[i] = *(ptr++);
          }
          }
        /* Writeback the stack pointer value if it wasn't restored.  */
        /* Writeback the stack pointer value if it wasn't restored.  */
        if ((mask & (1 << R_SP)) == 0)
        if ((mask & (1 << R_SP)) == 0)
          vrs->core.r[R_SP] = (_uw) ptr;
          vrs->core.r[R_SP] = (_uw) ptr;
      }
      }
      return _UVRSR_OK;
      return _UVRSR_OK;
 
 
    case _UVRSC_VFP:
    case _UVRSC_VFP:
      {
      {
        _uw start = discriminator >> 16;
        _uw start = discriminator >> 16;
        _uw count = discriminator & 0xffff;
        _uw count = discriminator & 0xffff;
        struct vfp_regs tmp;
        struct vfp_regs tmp;
        _uw *sp;
        _uw *sp;
        _uw *dest;
        _uw *dest;
 
 
        if ((representation != _UVRSD_VFPX && representation != _UVRSD_DOUBLE)
        if ((representation != _UVRSD_VFPX && representation != _UVRSD_DOUBLE)
            || start + count > 16)
            || start + count > 16)
          return _UVRSR_FAILED;
          return _UVRSR_FAILED;
 
 
        if (vrs->demand_save_flags & DEMAND_SAVE_VFP)
        if (vrs->demand_save_flags & DEMAND_SAVE_VFP)
          {
          {
            /* Demand-save resisters for stage1.  */
            /* Demand-save resisters for stage1.  */
            vrs->demand_save_flags &= ~DEMAND_SAVE_VFP;
            vrs->demand_save_flags &= ~DEMAND_SAVE_VFP;
            __gnu_Unwind_Save_VFP (&vrs->vfp);
            __gnu_Unwind_Save_VFP (&vrs->vfp);
          }
          }
 
 
        /* Restore the registers from the stack.  Do this by saving the
        /* Restore the registers from the stack.  Do this by saving the
           current VFP registers to a memory area, moving the in-memory
           current VFP registers to a memory area, moving the in-memory
           values into that area, and restoring from the whole area.
           values into that area, and restoring from the whole area.
           For _UVRSD_VFPX we assume FSTMX standard format 1.  */
           For _UVRSD_VFPX we assume FSTMX standard format 1.  */
        __gnu_Unwind_Save_VFP (&tmp);
        __gnu_Unwind_Save_VFP (&tmp);
 
 
        /* The stack address is only guaranteed to be word aligned, so
        /* The stack address is only guaranteed to be word aligned, so
           we can't use doubleword copies.  */
           we can't use doubleword copies.  */
        sp = (_uw *) vrs->core.r[R_SP];
        sp = (_uw *) vrs->core.r[R_SP];
        dest = (_uw *) &tmp.d[start];
        dest = (_uw *) &tmp.d[start];
        count *= 2;
        count *= 2;
        while (count--)
        while (count--)
          *(dest++) = *(sp++);
          *(dest++) = *(sp++);
 
 
        /* Skip the pad word */
        /* Skip the pad word */
        if (representation == _UVRSD_VFPX)
        if (representation == _UVRSD_VFPX)
          sp++;
          sp++;
 
 
        /* Set the new stack pointer.  */
        /* Set the new stack pointer.  */
        vrs->core.r[R_SP] = (_uw) sp;
        vrs->core.r[R_SP] = (_uw) sp;
 
 
        /* Reload the registers.  */
        /* Reload the registers.  */
        __gnu_Unwind_Restore_VFP (&tmp);
        __gnu_Unwind_Restore_VFP (&tmp);
      }
      }
      return _UVRSR_OK;
      return _UVRSR_OK;
 
 
    case _UVRSC_FPA:
    case _UVRSC_FPA:
    case _UVRSC_WMMXD:
    case _UVRSC_WMMXD:
    case _UVRSC_WMMXC:
    case _UVRSC_WMMXC:
      return _UVRSR_NOT_IMPLEMENTED;
      return _UVRSR_NOT_IMPLEMENTED;
 
 
    default:
    default:
      return _UVRSR_FAILED;
      return _UVRSR_FAILED;
    }
    }
}
}
 
 
 
 
/* Core unwinding functions.  */
/* Core unwinding functions.  */
 
 
/* Calculate the address encoded by a 31-bit self-relative offset at address
/* Calculate the address encoded by a 31-bit self-relative offset at address
   P.  */
   P.  */
static inline _uw
static inline _uw
selfrel_offset31 (const _uw *p)
selfrel_offset31 (const _uw *p)
{
{
  _uw offset;
  _uw offset;
 
 
  offset = *p;
  offset = *p;
  /* Sign extend to 32 bits.  */
  /* Sign extend to 32 bits.  */
  if (offset & (1 << 30))
  if (offset & (1 << 30))
    offset |= 1u << 31;
    offset |= 1u << 31;
  else
  else
    offset &= ~(1u << 31);
    offset &= ~(1u << 31);
 
 
  return offset + (_uw) p;
  return offset + (_uw) p;
}
}
 
 
 
 
/* Perform a binary search for RETURN_ADDRESS in TABLE.  The table contains
/* Perform a binary search for RETURN_ADDRESS in TABLE.  The table contains
   NREC entries.  */
   NREC entries.  */
 
 
static const __EIT_entry *
static const __EIT_entry *
search_EIT_table (const __EIT_entry * table, int nrec, _uw return_address)
search_EIT_table (const __EIT_entry * table, int nrec, _uw return_address)
{
{
  _uw next_fn;
  _uw next_fn;
  _uw this_fn;
  _uw this_fn;
  int n, left, right;
  int n, left, right;
 
 
  if (nrec == 0)
  if (nrec == 0)
    return (__EIT_entry *) 0;
    return (__EIT_entry *) 0;
 
 
  left = 0;
  left = 0;
  right = nrec - 1;
  right = nrec - 1;
 
 
  while (1)
  while (1)
    {
    {
      n = (left + right) / 2;
      n = (left + right) / 2;
      this_fn = selfrel_offset31 (&table[n].fnoffset);
      this_fn = selfrel_offset31 (&table[n].fnoffset);
      if (n != nrec - 1)
      if (n != nrec - 1)
        next_fn = selfrel_offset31 (&table[n + 1].fnoffset) - 1;
        next_fn = selfrel_offset31 (&table[n + 1].fnoffset) - 1;
      else
      else
        next_fn = (_uw)0 - 1;
        next_fn = (_uw)0 - 1;
 
 
      if (return_address < this_fn)
      if (return_address < this_fn)
        {
        {
          if (n == left)
          if (n == left)
            return (__EIT_entry *) 0;
            return (__EIT_entry *) 0;
          right = n - 1;
          right = n - 1;
        }
        }
      else if (return_address <= next_fn)
      else if (return_address <= next_fn)
        return &table[n];
        return &table[n];
      else
      else
        left = n + 1;
        left = n + 1;
    }
    }
}
}
 
 
/* Find the exception index table eintry for the given address.
/* Find the exception index table eintry for the given address.
   Fill in the relevant fields of the UCB.
   Fill in the relevant fields of the UCB.
   Returns _URC_FAILURE if an error occurred, _URC_OK on success.  */
   Returns _URC_FAILURE if an error occurred, _URC_OK on success.  */
 
 
static _Unwind_Reason_Code
static _Unwind_Reason_Code
get_eit_entry (_Unwind_Control_Block *ucbp, _uw return_address)
get_eit_entry (_Unwind_Control_Block *ucbp, _uw return_address)
{
{
  const __EIT_entry * eitp;
  const __EIT_entry * eitp;
  int nrec;
  int nrec;
 
 
  /* The return address is the address of the instruction following the
  /* The return address is the address of the instruction following the
     call instruction (plus one in thumb mode).  If this was the last
     call instruction (plus one in thumb mode).  If this was the last
     instruction in the function the address will lie in the following
     instruction in the function the address will lie in the following
     function.  Subtract 2 from the address so that it points within the call
     function.  Subtract 2 from the address so that it points within the call
     instruction itself.  */
     instruction itself.  */
  return_address -= 2;
  return_address -= 2;
 
 
  if (__gnu_Unwind_Find_exidx)
  if (__gnu_Unwind_Find_exidx)
    {
    {
      eitp = (const __EIT_entry *) __gnu_Unwind_Find_exidx (return_address,
      eitp = (const __EIT_entry *) __gnu_Unwind_Find_exidx (return_address,
                                                            &nrec);
                                                            &nrec);
      if (!eitp)
      if (!eitp)
        {
        {
          UCB_PR_ADDR (ucbp) = 0;
          UCB_PR_ADDR (ucbp) = 0;
          return _URC_FAILURE;
          return _URC_FAILURE;
        }
        }
    }
    }
  else
  else
    {
    {
      eitp = &__exidx_start;
      eitp = &__exidx_start;
      nrec = &__exidx_end - &__exidx_start;
      nrec = &__exidx_end - &__exidx_start;
    }
    }
 
 
  eitp = search_EIT_table (eitp, nrec, return_address);
  eitp = search_EIT_table (eitp, nrec, return_address);
 
 
  if (!eitp)
  if (!eitp)
    {
    {
      UCB_PR_ADDR (ucbp) = 0;
      UCB_PR_ADDR (ucbp) = 0;
      return _URC_FAILURE;
      return _URC_FAILURE;
    }
    }
  ucbp->pr_cache.fnstart = selfrel_offset31 (&eitp->fnoffset);
  ucbp->pr_cache.fnstart = selfrel_offset31 (&eitp->fnoffset);
 
 
  /* Can this frame be unwound at all?  */
  /* Can this frame be unwound at all?  */
  if (eitp->content == EXIDX_CANTUNWIND)
  if (eitp->content == EXIDX_CANTUNWIND)
    {
    {
      UCB_PR_ADDR (ucbp) = 0;
      UCB_PR_ADDR (ucbp) = 0;
      return _URC_END_OF_STACK;
      return _URC_END_OF_STACK;
    }
    }
 
 
  /* Obtain the address of the "real" __EHT_Header word.  */
  /* Obtain the address of the "real" __EHT_Header word.  */
 
 
  if (eitp->content & uint32_highbit)
  if (eitp->content & uint32_highbit)
    {
    {
      /* It is immediate data.  */
      /* It is immediate data.  */
      ucbp->pr_cache.ehtp = (_Unwind_EHT_Header *)&eitp->content;
      ucbp->pr_cache.ehtp = (_Unwind_EHT_Header *)&eitp->content;
      ucbp->pr_cache.additional = 1;
      ucbp->pr_cache.additional = 1;
    }
    }
  else
  else
    {
    {
      /* The low 31 bits of the content field are a self-relative
      /* The low 31 bits of the content field are a self-relative
         offset to an _Unwind_EHT_Entry structure.  */
         offset to an _Unwind_EHT_Entry structure.  */
      ucbp->pr_cache.ehtp =
      ucbp->pr_cache.ehtp =
        (_Unwind_EHT_Header *) selfrel_offset31 (&eitp->content);
        (_Unwind_EHT_Header *) selfrel_offset31 (&eitp->content);
      ucbp->pr_cache.additional = 0;
      ucbp->pr_cache.additional = 0;
    }
    }
 
 
  /* Discover the personality routine address.  */
  /* Discover the personality routine address.  */
  if (*ucbp->pr_cache.ehtp & (1u << 31))
  if (*ucbp->pr_cache.ehtp & (1u << 31))
    {
    {
      /* One of the predefined standard routines.  */
      /* One of the predefined standard routines.  */
      _uw idx = (*(_uw *) ucbp->pr_cache.ehtp >> 24) & 0xf;
      _uw idx = (*(_uw *) ucbp->pr_cache.ehtp >> 24) & 0xf;
      if (idx == 0)
      if (idx == 0)
        UCB_PR_ADDR (ucbp) = (_uw) &__aeabi_unwind_cpp_pr0;
        UCB_PR_ADDR (ucbp) = (_uw) &__aeabi_unwind_cpp_pr0;
      else if (idx == 1)
      else if (idx == 1)
        UCB_PR_ADDR (ucbp) = (_uw) &__aeabi_unwind_cpp_pr1;
        UCB_PR_ADDR (ucbp) = (_uw) &__aeabi_unwind_cpp_pr1;
      else if (idx == 2)
      else if (idx == 2)
        UCB_PR_ADDR (ucbp) = (_uw) &__aeabi_unwind_cpp_pr2;
        UCB_PR_ADDR (ucbp) = (_uw) &__aeabi_unwind_cpp_pr2;
      else
      else
        { /* Failed */
        { /* Failed */
          UCB_PR_ADDR (ucbp) = 0;
          UCB_PR_ADDR (ucbp) = 0;
          return _URC_FAILURE;
          return _URC_FAILURE;
        }
        }
    }
    }
  else
  else
    {
    {
      /* Execute region offset to PR */
      /* Execute region offset to PR */
      UCB_PR_ADDR (ucbp) = selfrel_offset31 (ucbp->pr_cache.ehtp);
      UCB_PR_ADDR (ucbp) = selfrel_offset31 (ucbp->pr_cache.ehtp);
    }
    }
  return _URC_OK;
  return _URC_OK;
}
}
 
 
 
 
/* Perform phase2 unwinding.  VRS is the initial virtual register state.  */
/* Perform phase2 unwinding.  VRS is the initial virtual register state.  */
 
 
static void __attribute__((noreturn))
static void __attribute__((noreturn))
unwind_phase2 (_Unwind_Control_Block * ucbp, phase2_vrs * vrs)
unwind_phase2 (_Unwind_Control_Block * ucbp, phase2_vrs * vrs)
{
{
  _Unwind_Reason_Code pr_result;
  _Unwind_Reason_Code pr_result;
 
 
  do
  do
    {
    {
      /* Find the entry for this routine.  */
      /* Find the entry for this routine.  */
      if (get_eit_entry (ucbp, vrs->core.r[R_PC]) != _URC_OK)
      if (get_eit_entry (ucbp, vrs->core.r[R_PC]) != _URC_OK)
        abort ();
        abort ();
 
 
      UCB_SAVED_CALLSITE_ADDR (ucbp) = vrs->core.r[R_PC];
      UCB_SAVED_CALLSITE_ADDR (ucbp) = vrs->core.r[R_PC];
 
 
      /* Call the pr to decide what to do.  */
      /* Call the pr to decide what to do.  */
      pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
      pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
        (_US_UNWIND_FRAME_STARTING, ucbp, (_Unwind_Context *) vrs);
        (_US_UNWIND_FRAME_STARTING, ucbp, (_Unwind_Context *) vrs);
    }
    }
  while (pr_result == _URC_CONTINUE_UNWIND);
  while (pr_result == _URC_CONTINUE_UNWIND);
 
 
  if (pr_result != _URC_INSTALL_CONTEXT)
  if (pr_result != _URC_INSTALL_CONTEXT)
    abort();
    abort();
 
 
  restore_core_regs (&vrs->core);
  restore_core_regs (&vrs->core);
}
}
 
 
/* Perform phase2 forced unwinding.  */
/* Perform phase2 forced unwinding.  */
 
 
static _Unwind_Reason_Code
static _Unwind_Reason_Code
unwind_phase2_forced (_Unwind_Control_Block *ucbp, phase2_vrs *entry_vrs,
unwind_phase2_forced (_Unwind_Control_Block *ucbp, phase2_vrs *entry_vrs,
                      int resuming)
                      int resuming)
{
{
  _Unwind_Stop_Fn stop_fn = (_Unwind_Stop_Fn) UCB_FORCED_STOP_FN (ucbp);
  _Unwind_Stop_Fn stop_fn = (_Unwind_Stop_Fn) UCB_FORCED_STOP_FN (ucbp);
  void *stop_arg = (void *)UCB_FORCED_STOP_ARG (ucbp);
  void *stop_arg = (void *)UCB_FORCED_STOP_ARG (ucbp);
  _Unwind_Reason_Code pr_result = 0;
  _Unwind_Reason_Code pr_result = 0;
  /* We use phase1_vrs here even though we do not demand save, for the
  /* We use phase1_vrs here even though we do not demand save, for the
     prev_sp field.  */
     prev_sp field.  */
  phase1_vrs saved_vrs, next_vrs;
  phase1_vrs saved_vrs, next_vrs;
 
 
  /* Save the core registers.  */
  /* Save the core registers.  */
  saved_vrs.core = entry_vrs->core;
  saved_vrs.core = entry_vrs->core;
  /* We don't need to demand-save the non-core registers, because we
  /* We don't need to demand-save the non-core registers, because we
     unwind in a single pass.  */
     unwind in a single pass.  */
  saved_vrs.demand_save_flags = 0;
  saved_vrs.demand_save_flags = 0;
 
 
  /* Unwind until we reach a propagation barrier.  */
  /* Unwind until we reach a propagation barrier.  */
  do
  do
    {
    {
      _Unwind_State action;
      _Unwind_State action;
      _Unwind_Reason_Code entry_code;
      _Unwind_Reason_Code entry_code;
      _Unwind_Reason_Code stop_code;
      _Unwind_Reason_Code stop_code;
 
 
      /* Find the entry for this routine.  */
      /* Find the entry for this routine.  */
      entry_code = get_eit_entry (ucbp, saved_vrs.core.r[R_PC]);
      entry_code = get_eit_entry (ucbp, saved_vrs.core.r[R_PC]);
 
 
      if (resuming)
      if (resuming)
        {
        {
          action = _US_UNWIND_FRAME_RESUME | _US_FORCE_UNWIND;
          action = _US_UNWIND_FRAME_RESUME | _US_FORCE_UNWIND;
          resuming = 0;
          resuming = 0;
        }
        }
      else
      else
        action = _US_UNWIND_FRAME_STARTING | _US_FORCE_UNWIND;
        action = _US_UNWIND_FRAME_STARTING | _US_FORCE_UNWIND;
 
 
      if (entry_code == _URC_OK)
      if (entry_code == _URC_OK)
        {
        {
          UCB_SAVED_CALLSITE_ADDR (ucbp) = saved_vrs.core.r[R_PC];
          UCB_SAVED_CALLSITE_ADDR (ucbp) = saved_vrs.core.r[R_PC];
 
 
          next_vrs = saved_vrs;
          next_vrs = saved_vrs;
 
 
          /* Call the pr to decide what to do.  */
          /* Call the pr to decide what to do.  */
          pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
          pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
            (action, ucbp, (void *) &next_vrs);
            (action, ucbp, (void *) &next_vrs);
 
 
          saved_vrs.prev_sp = next_vrs.core.r[R_SP];
          saved_vrs.prev_sp = next_vrs.core.r[R_SP];
        }
        }
      else
      else
        {
        {
          /* Treat any failure as the end of unwinding, to cope more
          /* Treat any failure as the end of unwinding, to cope more
             gracefully with missing EH information.  Mixed EH and
             gracefully with missing EH information.  Mixed EH and
             non-EH within one object will usually result in failure,
             non-EH within one object will usually result in failure,
             because the .ARM.exidx tables do not indicate the end
             because the .ARM.exidx tables do not indicate the end
             of the code to which they apply; but mixed EH and non-EH
             of the code to which they apply; but mixed EH and non-EH
             shared objects should return an unwind failure at the
             shared objects should return an unwind failure at the
             entry of a non-EH shared object.  */
             entry of a non-EH shared object.  */
          action |= _US_END_OF_STACK;
          action |= _US_END_OF_STACK;
 
 
          saved_vrs.prev_sp = saved_vrs.core.r[R_SP];
          saved_vrs.prev_sp = saved_vrs.core.r[R_SP];
        }
        }
 
 
      stop_code = stop_fn (1, action, ucbp->exception_class, ucbp,
      stop_code = stop_fn (1, action, ucbp->exception_class, ucbp,
                           (void *)&saved_vrs, stop_arg);
                           (void *)&saved_vrs, stop_arg);
      if (stop_code != _URC_NO_REASON)
      if (stop_code != _URC_NO_REASON)
        return _URC_FAILURE;
        return _URC_FAILURE;
 
 
      if (entry_code != _URC_OK)
      if (entry_code != _URC_OK)
        return entry_code;
        return entry_code;
 
 
      saved_vrs = next_vrs;
      saved_vrs = next_vrs;
    }
    }
  while (pr_result == _URC_CONTINUE_UNWIND);
  while (pr_result == _URC_CONTINUE_UNWIND);
 
 
  if (pr_result != _URC_INSTALL_CONTEXT)
  if (pr_result != _URC_INSTALL_CONTEXT)
    {
    {
      /* Some sort of failure has occurred in the pr and probably the
      /* Some sort of failure has occurred in the pr and probably the
         pr returned _URC_FAILURE.  */
         pr returned _URC_FAILURE.  */
      return _URC_FAILURE;
      return _URC_FAILURE;
    }
    }
 
 
  restore_core_regs (&saved_vrs.core);
  restore_core_regs (&saved_vrs.core);
}
}
 
 
/* This is a very limited implementation of _Unwind_GetCFA.  It returns
/* This is a very limited implementation of _Unwind_GetCFA.  It returns
   the stack pointer as it is about to be unwound, and is only valid
   the stack pointer as it is about to be unwound, and is only valid
   while calling the stop function during forced unwinding.  If the
   while calling the stop function during forced unwinding.  If the
   current personality routine result is going to run a cleanup, this
   current personality routine result is going to run a cleanup, this
   will not be the CFA; but when the frame is really unwound, it will
   will not be the CFA; but when the frame is really unwound, it will
   be.  */
   be.  */
 
 
_Unwind_Word
_Unwind_Word
_Unwind_GetCFA (_Unwind_Context *context)
_Unwind_GetCFA (_Unwind_Context *context)
{
{
  return ((phase1_vrs *) context)->prev_sp;
  return ((phase1_vrs *) context)->prev_sp;
}
}
 
 
/* Perform phase1 unwinding.  UCBP is the exception being thrown, and
/* Perform phase1 unwinding.  UCBP is the exception being thrown, and
   entry_VRS is the register state on entry to _Unwind_RaiseException.  */
   entry_VRS is the register state on entry to _Unwind_RaiseException.  */
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_RaiseException (_Unwind_Control_Block *, phase2_vrs *);
__gnu_Unwind_RaiseException (_Unwind_Control_Block *, phase2_vrs *);
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_RaiseException (_Unwind_Control_Block * ucbp,
__gnu_Unwind_RaiseException (_Unwind_Control_Block * ucbp,
                             phase2_vrs * entry_vrs)
                             phase2_vrs * entry_vrs)
{
{
  phase1_vrs saved_vrs;
  phase1_vrs saved_vrs;
  _Unwind_Reason_Code pr_result;
  _Unwind_Reason_Code pr_result;
 
 
  /* Set the pc to the call site.  */
  /* Set the pc to the call site.  */
  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
 
 
  /* Save the core registers.  */
  /* Save the core registers.  */
  saved_vrs.core = entry_vrs->core;
  saved_vrs.core = entry_vrs->core;
  /* Set demand-save flags.  */
  /* Set demand-save flags.  */
  saved_vrs.demand_save_flags = ~(_uw) 0;
  saved_vrs.demand_save_flags = ~(_uw) 0;
 
 
  /* Unwind until we reach a propagation barrier.  */
  /* Unwind until we reach a propagation barrier.  */
  do
  do
    {
    {
      /* Find the entry for this routine.  */
      /* Find the entry for this routine.  */
      if (get_eit_entry (ucbp, saved_vrs.core.r[R_PC]) != _URC_OK)
      if (get_eit_entry (ucbp, saved_vrs.core.r[R_PC]) != _URC_OK)
        return _URC_FAILURE;
        return _URC_FAILURE;
 
 
      /* Call the pr to decide what to do.  */
      /* Call the pr to decide what to do.  */
      pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
      pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
        (_US_VIRTUAL_UNWIND_FRAME, ucbp, (void *) &saved_vrs);
        (_US_VIRTUAL_UNWIND_FRAME, ucbp, (void *) &saved_vrs);
    }
    }
  while (pr_result == _URC_CONTINUE_UNWIND);
  while (pr_result == _URC_CONTINUE_UNWIND);
 
 
  /* We've unwound as far as we want to go, so restore the original
  /* We've unwound as far as we want to go, so restore the original
     register state.  */
     register state.  */
  restore_non_core_regs (&saved_vrs);
  restore_non_core_regs (&saved_vrs);
  if (pr_result != _URC_HANDLER_FOUND)
  if (pr_result != _URC_HANDLER_FOUND)
    {
    {
      /* Some sort of failure has occurred in the pr and probably the
      /* Some sort of failure has occurred in the pr and probably the
         pr returned _URC_FAILURE.  */
         pr returned _URC_FAILURE.  */
      return _URC_FAILURE;
      return _URC_FAILURE;
    }
    }
 
 
  unwind_phase2 (ucbp, entry_vrs);
  unwind_phase2 (ucbp, entry_vrs);
}
}
 
 
/* Resume unwinding after a cleanup has been run.  UCBP is the exception
/* Resume unwinding after a cleanup has been run.  UCBP is the exception
   being thrown and ENTRY_VRS is the register state on entry to
   being thrown and ENTRY_VRS is the register state on entry to
   _Unwind_Resume.  */
   _Unwind_Resume.  */
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_ForcedUnwind (_Unwind_Control_Block *,
__gnu_Unwind_ForcedUnwind (_Unwind_Control_Block *,
                           _Unwind_Stop_Fn, void *, phase2_vrs *);
                           _Unwind_Stop_Fn, void *, phase2_vrs *);
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_ForcedUnwind (_Unwind_Control_Block *ucbp,
__gnu_Unwind_ForcedUnwind (_Unwind_Control_Block *ucbp,
                           _Unwind_Stop_Fn stop_fn, void *stop_arg,
                           _Unwind_Stop_Fn stop_fn, void *stop_arg,
                           phase2_vrs *entry_vrs)
                           phase2_vrs *entry_vrs)
{
{
  UCB_FORCED_STOP_FN (ucbp) = (_uw) stop_fn;
  UCB_FORCED_STOP_FN (ucbp) = (_uw) stop_fn;
  UCB_FORCED_STOP_ARG (ucbp) = (_uw) stop_arg;
  UCB_FORCED_STOP_ARG (ucbp) = (_uw) stop_arg;
 
 
  /* Set the pc to the call site.  */
  /* Set the pc to the call site.  */
  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
 
 
  return unwind_phase2_forced (ucbp, entry_vrs, 0);
  return unwind_phase2_forced (ucbp, entry_vrs, 0);
}
}
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_Resume (_Unwind_Control_Block *, phase2_vrs *);
__gnu_Unwind_Resume (_Unwind_Control_Block *, phase2_vrs *);
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_Resume (_Unwind_Control_Block * ucbp, phase2_vrs * entry_vrs)
__gnu_Unwind_Resume (_Unwind_Control_Block * ucbp, phase2_vrs * entry_vrs)
{
{
  _Unwind_Reason_Code pr_result;
  _Unwind_Reason_Code pr_result;
 
 
  /* Recover the saved address.  */
  /* Recover the saved address.  */
  entry_vrs->core.r[R_PC] = UCB_SAVED_CALLSITE_ADDR (ucbp);
  entry_vrs->core.r[R_PC] = UCB_SAVED_CALLSITE_ADDR (ucbp);
 
 
  if (UCB_FORCED_STOP_FN (ucbp))
  if (UCB_FORCED_STOP_FN (ucbp))
    {
    {
      unwind_phase2_forced (ucbp, entry_vrs, 1);
      unwind_phase2_forced (ucbp, entry_vrs, 1);
 
 
      /* We can't return failure at this point.  */
      /* We can't return failure at this point.  */
      abort ();
      abort ();
    }
    }
 
 
  /* Call the cached PR.  */
  /* Call the cached PR.  */
  pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
  pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
        (_US_UNWIND_FRAME_RESUME, ucbp, (_Unwind_Context *) entry_vrs);
        (_US_UNWIND_FRAME_RESUME, ucbp, (_Unwind_Context *) entry_vrs);
 
 
  switch (pr_result)
  switch (pr_result)
    {
    {
    case _URC_INSTALL_CONTEXT:
    case _URC_INSTALL_CONTEXT:
      /* Upload the registers to enter the landing pad.  */
      /* Upload the registers to enter the landing pad.  */
      restore_core_regs (&entry_vrs->core);
      restore_core_regs (&entry_vrs->core);
 
 
    case _URC_CONTINUE_UNWIND:
    case _URC_CONTINUE_UNWIND:
      /* Continue unwinding the next frame.  */
      /* Continue unwinding the next frame.  */
      unwind_phase2 (ucbp, entry_vrs);
      unwind_phase2 (ucbp, entry_vrs);
 
 
    default:
    default:
      abort ();
      abort ();
    }
    }
}
}
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_Resume_or_Rethrow (_Unwind_Control_Block *, phase2_vrs *);
__gnu_Unwind_Resume_or_Rethrow (_Unwind_Control_Block *, phase2_vrs *);
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__gnu_Unwind_Resume_or_Rethrow (_Unwind_Control_Block * ucbp,
__gnu_Unwind_Resume_or_Rethrow (_Unwind_Control_Block * ucbp,
                                phase2_vrs * entry_vrs)
                                phase2_vrs * entry_vrs)
{
{
  if (!UCB_FORCED_STOP_FN (ucbp))
  if (!UCB_FORCED_STOP_FN (ucbp))
    return __gnu_Unwind_RaiseException (ucbp, entry_vrs);
    return __gnu_Unwind_RaiseException (ucbp, entry_vrs);
 
 
  /* Set the pc to the call site.  */
  /* Set the pc to the call site.  */
  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
  entry_vrs->core.r[R_PC] = entry_vrs->core.r[R_LR];
  /* Continue unwinding the next frame.  */
  /* Continue unwinding the next frame.  */
  return unwind_phase2_forced (ucbp, entry_vrs, 0);
  return unwind_phase2_forced (ucbp, entry_vrs, 0);
}
}
 
 
/* Clean up an exception object when unwinding is complete.  */
/* Clean up an exception object when unwinding is complete.  */
void
void
_Unwind_Complete (_Unwind_Control_Block * ucbp __attribute__((unused)))
_Unwind_Complete (_Unwind_Control_Block * ucbp __attribute__((unused)))
{
{
}
}
 
 
 
 
/* Get the _Unwind_Control_Block from an _Unwind_Context.  */
/* Get the _Unwind_Control_Block from an _Unwind_Context.  */
 
 
static inline _Unwind_Control_Block *
static inline _Unwind_Control_Block *
unwind_UCB_from_context (_Unwind_Context * context)
unwind_UCB_from_context (_Unwind_Context * context)
{
{
  return (_Unwind_Control_Block *) _Unwind_GetGR (context, R_IP);
  return (_Unwind_Control_Block *) _Unwind_GetGR (context, R_IP);
}
}
 
 
 
 
/* Free an exception.  */
/* Free an exception.  */
 
 
void
void
_Unwind_DeleteException (_Unwind_Exception * exc)
_Unwind_DeleteException (_Unwind_Exception * exc)
{
{
  if (exc->exception_cleanup)
  if (exc->exception_cleanup)
    (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc);
    (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc);
}
}
 
 
 
 
/* Common implementation for ARM ABI defined personality routines.
/* Common implementation for ARM ABI defined personality routines.
   ID is the index of the personality routine, other arguments are as defined
   ID is the index of the personality routine, other arguments are as defined
   by __aeabi_unwind_cpp_pr{0,1,2}.  */
   by __aeabi_unwind_cpp_pr{0,1,2}.  */
 
 
static _Unwind_Reason_Code
static _Unwind_Reason_Code
__gnu_unwind_pr_common (_Unwind_State state,
__gnu_unwind_pr_common (_Unwind_State state,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Context *context,
                        _Unwind_Context *context,
                        int id)
                        int id)
{
{
  __gnu_unwind_state uws;
  __gnu_unwind_state uws;
  _uw *data;
  _uw *data;
  _uw offset;
  _uw offset;
  _uw len;
  _uw len;
  _uw rtti_count;
  _uw rtti_count;
  int phase2_call_unexpected_after_unwind = 0;
  int phase2_call_unexpected_after_unwind = 0;
  int in_range = 0;
  int in_range = 0;
  int forced_unwind = state & _US_FORCE_UNWIND;
  int forced_unwind = state & _US_FORCE_UNWIND;
 
 
  state &= _US_ACTION_MASK;
  state &= _US_ACTION_MASK;
 
 
  data = (_uw *) ucbp->pr_cache.ehtp;
  data = (_uw *) ucbp->pr_cache.ehtp;
  uws.data = *(data++);
  uws.data = *(data++);
  uws.next = data;
  uws.next = data;
  if (id == 0)
  if (id == 0)
    {
    {
      uws.data <<= 8;
      uws.data <<= 8;
      uws.words_left = 0;
      uws.words_left = 0;
      uws.bytes_left = 3;
      uws.bytes_left = 3;
    }
    }
  else
  else
    {
    {
      uws.words_left = (uws.data >> 16) & 0xff;
      uws.words_left = (uws.data >> 16) & 0xff;
      uws.data <<= 16;
      uws.data <<= 16;
      uws.bytes_left = 2;
      uws.bytes_left = 2;
      data += uws.words_left;
      data += uws.words_left;
    }
    }
 
 
  /* Restore the saved pointer.  */
  /* Restore the saved pointer.  */
  if (state == _US_UNWIND_FRAME_RESUME)
  if (state == _US_UNWIND_FRAME_RESUME)
    data = (_uw *) ucbp->cleanup_cache.bitpattern[0];
    data = (_uw *) ucbp->cleanup_cache.bitpattern[0];
 
 
  if ((ucbp->pr_cache.additional & 1) == 0)
  if ((ucbp->pr_cache.additional & 1) == 0)
    {
    {
      /* Process descriptors.  */
      /* Process descriptors.  */
      while (*data)
      while (*data)
        {
        {
          _uw addr;
          _uw addr;
          _uw fnstart;
          _uw fnstart;
 
 
          if (id == 2)
          if (id == 2)
            {
            {
              len = ((EHT32 *) data)->length;
              len = ((EHT32 *) data)->length;
              offset = ((EHT32 *) data)->offset;
              offset = ((EHT32 *) data)->offset;
              data += 2;
              data += 2;
            }
            }
          else
          else
            {
            {
              len = ((EHT16 *) data)->length;
              len = ((EHT16 *) data)->length;
              offset = ((EHT16 *) data)->offset;
              offset = ((EHT16 *) data)->offset;
              data++;
              data++;
            }
            }
 
 
          fnstart = ucbp->pr_cache.fnstart + (offset & ~1);
          fnstart = ucbp->pr_cache.fnstart + (offset & ~1);
          addr = _Unwind_GetGR (context, R_PC);
          addr = _Unwind_GetGR (context, R_PC);
          in_range = (fnstart <= addr && addr < fnstart + (len & ~1));
          in_range = (fnstart <= addr && addr < fnstart + (len & ~1));
 
 
          switch (((offset & 1) << 1) | (len & 1))
          switch (((offset & 1) << 1) | (len & 1))
            {
            {
            case 0:
            case 0:
              /* Cleanup.  */
              /* Cleanup.  */
              if (state != _US_VIRTUAL_UNWIND_FRAME
              if (state != _US_VIRTUAL_UNWIND_FRAME
                  && in_range)
                  && in_range)
                {
                {
                  /* Cleanup in range, and we are running cleanups.  */
                  /* Cleanup in range, and we are running cleanups.  */
                  _uw lp;
                  _uw lp;
 
 
                  /* Landing pad address is 31-bit pc-relative offset.  */
                  /* Landing pad address is 31-bit pc-relative offset.  */
                  lp = selfrel_offset31 (data);
                  lp = selfrel_offset31 (data);
                  data++;
                  data++;
                  /* Save the exception data pointer.  */
                  /* Save the exception data pointer.  */
                  ucbp->cleanup_cache.bitpattern[0] = (_uw) data;
                  ucbp->cleanup_cache.bitpattern[0] = (_uw) data;
                  if (!__cxa_begin_cleanup (ucbp))
                  if (!__cxa_begin_cleanup (ucbp))
                    return _URC_FAILURE;
                    return _URC_FAILURE;
                  /* Setup the VRS to enter the landing pad.  */
                  /* Setup the VRS to enter the landing pad.  */
                  _Unwind_SetGR (context, R_PC, lp);
                  _Unwind_SetGR (context, R_PC, lp);
                  return _URC_INSTALL_CONTEXT;
                  return _URC_INSTALL_CONTEXT;
                }
                }
              /* Cleanup not in range, or we are in stage 1.  */
              /* Cleanup not in range, or we are in stage 1.  */
              data++;
              data++;
              break;
              break;
 
 
            case 1:
            case 1:
              /* Catch handler.  */
              /* Catch handler.  */
              if (state == _US_VIRTUAL_UNWIND_FRAME)
              if (state == _US_VIRTUAL_UNWIND_FRAME)
                {
                {
                  if (in_range)
                  if (in_range)
                    {
                    {
                      /* Check for a barrier.  */
                      /* Check for a barrier.  */
                      _uw rtti;
                      _uw rtti;
                      void *matched;
                      void *matched;
 
 
                      /* Check for no-throw areas.  */
                      /* Check for no-throw areas.  */
                      if (data[1] == (_uw) -2)
                      if (data[1] == (_uw) -2)
                        return _URC_FAILURE;
                        return _URC_FAILURE;
 
 
                      /* The thrown object immediately follows the ECB.  */
                      /* The thrown object immediately follows the ECB.  */
                      matched = (void *)(ucbp + 1);
                      matched = (void *)(ucbp + 1);
                      if (data[1] != (_uw) -1)
                      if (data[1] != (_uw) -1)
                        {
                        {
                          /* Match a catch specification.  */
                          /* Match a catch specification.  */
                          rtti = _Unwind_decode_target2 ((_uw) &data[1]);
                          rtti = _Unwind_decode_target2 ((_uw) &data[1]);
                          if (!__cxa_type_match (ucbp, (type_info *) rtti,
                          if (!__cxa_type_match (ucbp, (type_info *) rtti,
                                                 &matched))
                                                 &matched))
                            matched = (void *)0;
                            matched = (void *)0;
                        }
                        }
 
 
                      if (matched)
                      if (matched)
                        {
                        {
                          ucbp->barrier_cache.sp =
                          ucbp->barrier_cache.sp =
                            _Unwind_GetGR (context, R_SP);
                            _Unwind_GetGR (context, R_SP);
                          ucbp->barrier_cache.bitpattern[0] = (_uw) matched;
                          ucbp->barrier_cache.bitpattern[0] = (_uw) matched;
                          ucbp->barrier_cache.bitpattern[1] = (_uw) data;
                          ucbp->barrier_cache.bitpattern[1] = (_uw) data;
                          return _URC_HANDLER_FOUND;
                          return _URC_HANDLER_FOUND;
                        }
                        }
                    }
                    }
                  /* Handler out of range, or not matched.  */
                  /* Handler out of range, or not matched.  */
                }
                }
              else if (ucbp->barrier_cache.sp == _Unwind_GetGR (context, R_SP)
              else if (ucbp->barrier_cache.sp == _Unwind_GetGR (context, R_SP)
                       && ucbp->barrier_cache.bitpattern[1] == (_uw) data)
                       && ucbp->barrier_cache.bitpattern[1] == (_uw) data)
                {
                {
                  /* Matched a previous propagation barrier.  */
                  /* Matched a previous propagation barrier.  */
                  _uw lp;
                  _uw lp;
 
 
                  /* Setup for entry to the handler.  */
                  /* Setup for entry to the handler.  */
                  lp = selfrel_offset31 (data);
                  lp = selfrel_offset31 (data);
                  _Unwind_SetGR (context, R_PC, lp);
                  _Unwind_SetGR (context, R_PC, lp);
                  _Unwind_SetGR (context, 0, (_uw) ucbp);
                  _Unwind_SetGR (context, 0, (_uw) ucbp);
                  return _URC_INSTALL_CONTEXT;
                  return _URC_INSTALL_CONTEXT;
                }
                }
              /* Catch handler not matched.  Advance to the next descriptor.  */
              /* Catch handler not matched.  Advance to the next descriptor.  */
              data += 2;
              data += 2;
              break;
              break;
 
 
            case 2:
            case 2:
              rtti_count = data[0] & 0x7fffffff;
              rtti_count = data[0] & 0x7fffffff;
              /* Exception specification.  */
              /* Exception specification.  */
              if (state == _US_VIRTUAL_UNWIND_FRAME)
              if (state == _US_VIRTUAL_UNWIND_FRAME)
                {
                {
                  if (in_range && (!forced_unwind || !rtti_count))
                  if (in_range && (!forced_unwind || !rtti_count))
                    {
                    {
                      /* Match against the exception specification.  */
                      /* Match against the exception specification.  */
                      _uw i;
                      _uw i;
                      _uw rtti;
                      _uw rtti;
                      void *matched;
                      void *matched;
 
 
                      for (i = 0; i < rtti_count; i++)
                      for (i = 0; i < rtti_count; i++)
                        {
                        {
                          matched = (void *)(ucbp + 1);
                          matched = (void *)(ucbp + 1);
                          rtti = _Unwind_decode_target2 ((_uw) &data[i + 1]);
                          rtti = _Unwind_decode_target2 ((_uw) &data[i + 1]);
                          if (__cxa_type_match (ucbp, (type_info *) rtti,
                          if (__cxa_type_match (ucbp, (type_info *) rtti,
                                                &matched))
                                                &matched))
                            break;
                            break;
                        }
                        }
 
 
                      if (i == rtti_count)
                      if (i == rtti_count)
                        {
                        {
                          /* Exception does not match the spec.  */
                          /* Exception does not match the spec.  */
                          ucbp->barrier_cache.sp =
                          ucbp->barrier_cache.sp =
                            _Unwind_GetGR (context, R_SP);
                            _Unwind_GetGR (context, R_SP);
                          ucbp->barrier_cache.bitpattern[0] = (_uw) matched;
                          ucbp->barrier_cache.bitpattern[0] = (_uw) matched;
                          ucbp->barrier_cache.bitpattern[1] = (_uw) data;
                          ucbp->barrier_cache.bitpattern[1] = (_uw) data;
                          return _URC_HANDLER_FOUND;
                          return _URC_HANDLER_FOUND;
                        }
                        }
                    }
                    }
                  /* Handler out of range, or exception is permitted.  */
                  /* Handler out of range, or exception is permitted.  */
                }
                }
              else if (ucbp->barrier_cache.sp == _Unwind_GetGR (context, R_SP)
              else if (ucbp->barrier_cache.sp == _Unwind_GetGR (context, R_SP)
                       && ucbp->barrier_cache.bitpattern[1] == (_uw) data)
                       && ucbp->barrier_cache.bitpattern[1] == (_uw) data)
                {
                {
                  /* Matched a previous propagation barrier.  */
                  /* Matched a previous propagation barrier.  */
                  _uw lp;
                  _uw lp;
                  /* Record the RTTI list for __cxa_call_unexpected.  */
                  /* Record the RTTI list for __cxa_call_unexpected.  */
                  ucbp->barrier_cache.bitpattern[1] = rtti_count;
                  ucbp->barrier_cache.bitpattern[1] = rtti_count;
                  ucbp->barrier_cache.bitpattern[2] = 0;
                  ucbp->barrier_cache.bitpattern[2] = 0;
                  ucbp->barrier_cache.bitpattern[3] = 4;
                  ucbp->barrier_cache.bitpattern[3] = 4;
                  ucbp->barrier_cache.bitpattern[4] = (_uw) &data[1];
                  ucbp->barrier_cache.bitpattern[4] = (_uw) &data[1];
 
 
                  if (data[0] & uint32_highbit)
                  if (data[0] & uint32_highbit)
                    phase2_call_unexpected_after_unwind = 1;
                    phase2_call_unexpected_after_unwind = 1;
                  else
                  else
                    {
                    {
                      data += rtti_count + 1;
                      data += rtti_count + 1;
                      /* Setup for entry to the handler.  */
                      /* Setup for entry to the handler.  */
                      lp = selfrel_offset31 (data);
                      lp = selfrel_offset31 (data);
                      data++;
                      data++;
                      _Unwind_SetGR (context, R_PC, lp);
                      _Unwind_SetGR (context, R_PC, lp);
                      _Unwind_SetGR (context, 0, (_uw) ucbp);
                      _Unwind_SetGR (context, 0, (_uw) ucbp);
                      return _URC_INSTALL_CONTEXT;
                      return _URC_INSTALL_CONTEXT;
                    }
                    }
                }
                }
              if (data[0] & uint32_highbit)
              if (data[0] & uint32_highbit)
                data++;
                data++;
              data += rtti_count + 1;
              data += rtti_count + 1;
              break;
              break;
 
 
            default:
            default:
              /* Should never happen.  */
              /* Should never happen.  */
              return _URC_FAILURE;
              return _URC_FAILURE;
            }
            }
          /* Finished processing this descriptor.  */
          /* Finished processing this descriptor.  */
        }
        }
    }
    }
 
 
  if (__gnu_unwind_execute (context, &uws) != _URC_OK)
  if (__gnu_unwind_execute (context, &uws) != _URC_OK)
    return _URC_FAILURE;
    return _URC_FAILURE;
 
 
  if (phase2_call_unexpected_after_unwind)
  if (phase2_call_unexpected_after_unwind)
    {
    {
      /* Enter __cxa_unexpected as if called from the call site.  */
      /* Enter __cxa_unexpected as if called from the call site.  */
      _Unwind_SetGR (context, R_LR, _Unwind_GetGR (context, R_PC));
      _Unwind_SetGR (context, R_LR, _Unwind_GetGR (context, R_PC));
      _Unwind_SetGR (context, R_PC, (_uw) &__cxa_call_unexpected);
      _Unwind_SetGR (context, R_PC, (_uw) &__cxa_call_unexpected);
      return _URC_INSTALL_CONTEXT;
      return _URC_INSTALL_CONTEXT;
    }
    }
 
 
  return _URC_CONTINUE_UNWIND;
  return _URC_CONTINUE_UNWIND;
}
}
 
 
 
 
/* ABI defined personality routine entry points.  */
/* ABI defined personality routine entry points.  */
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__aeabi_unwind_cpp_pr0 (_Unwind_State state,
__aeabi_unwind_cpp_pr0 (_Unwind_State state,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Context *context)
                        _Unwind_Context *context)
{
{
  return __gnu_unwind_pr_common (state, ucbp, context, 0);
  return __gnu_unwind_pr_common (state, ucbp, context, 0);
}
}
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__aeabi_unwind_cpp_pr1 (_Unwind_State state,
__aeabi_unwind_cpp_pr1 (_Unwind_State state,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Context *context)
                        _Unwind_Context *context)
{
{
  return __gnu_unwind_pr_common (state, ucbp, context, 1);
  return __gnu_unwind_pr_common (state, ucbp, context, 1);
}
}
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
__aeabi_unwind_cpp_pr2 (_Unwind_State state,
__aeabi_unwind_cpp_pr2 (_Unwind_State state,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Control_Block *ucbp,
                        _Unwind_Context *context)
                        _Unwind_Context *context)
{
{
  return __gnu_unwind_pr_common (state, ucbp, context, 2);
  return __gnu_unwind_pr_common (state, ucbp, context, 2);
}
}
 
 
/* These two should never be used.  */
/* These two should never be used.  */
_Unwind_Ptr
_Unwind_Ptr
_Unwind_GetDataRelBase (_Unwind_Context *context __attribute__ ((unused)))
_Unwind_GetDataRelBase (_Unwind_Context *context __attribute__ ((unused)))
{
{
  abort ();
  abort ();
}
}
 
 
_Unwind_Ptr
_Unwind_Ptr
_Unwind_GetTextRelBase (_Unwind_Context *context __attribute__ ((unused)))
_Unwind_GetTextRelBase (_Unwind_Context *context __attribute__ ((unused)))
{
{
  abort ();
  abort ();
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.