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

Subversion Repositories openrisc

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

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Supporting functions for C exception handling.
/* Supporting functions for C exception handling.
   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
   Contributed by Aldy Hernandez <aldy@quesejoda.com>.
   Contributed by Aldy Hernandez <aldy@quesejoda.com>.
   Shamelessly stolen from the Java front end.
   Shamelessly stolen from the Java front end.
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify it under
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
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
Software Foundation; either version 2, or (at your option) any later
version.
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 combined
the file, and distribution when not linked into a combined
executable.)
executable.)
 
 
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
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 GCC; see the file COPYING.  If not, write to the Free
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.  */
02110-1301, USA.  */
 
 
#include "tconfig.h"
#include "tconfig.h"
#include "tsystem.h"
#include "tsystem.h"
#include "unwind.h"
#include "unwind.h"
#define NO_SIZE_OF_ENCODED_VALUE
#define NO_SIZE_OF_ENCODED_VALUE
#include "unwind-pe.h"
#include "unwind-pe.h"
 
 
typedef struct
typedef struct
{
{
  _Unwind_Ptr Start;
  _Unwind_Ptr Start;
  _Unwind_Ptr LPStart;
  _Unwind_Ptr LPStart;
  _Unwind_Ptr ttype_base;
  _Unwind_Ptr ttype_base;
  const unsigned char *TType;
  const unsigned char *TType;
  const unsigned char *action_table;
  const unsigned char *action_table;
  unsigned char ttype_encoding;
  unsigned char ttype_encoding;
  unsigned char call_site_encoding;
  unsigned char call_site_encoding;
} lsda_header_info;
} lsda_header_info;
 
 
static const unsigned char *
static const unsigned char *
parse_lsda_header (struct _Unwind_Context *context, const unsigned char *p,
parse_lsda_header (struct _Unwind_Context *context, const unsigned char *p,
                   lsda_header_info *info)
                   lsda_header_info *info)
{
{
  _Unwind_Word tmp;
  _Unwind_Word tmp;
  unsigned char lpstart_encoding;
  unsigned char lpstart_encoding;
 
 
  info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
  info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
 
 
  /* Find @LPStart, the base to which landing pad offsets are relative.  */
  /* Find @LPStart, the base to which landing pad offsets are relative.  */
  lpstart_encoding = *p++;
  lpstart_encoding = *p++;
  if (lpstart_encoding != DW_EH_PE_omit)
  if (lpstart_encoding != DW_EH_PE_omit)
    p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
    p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
  else
  else
    info->LPStart = info->Start;
    info->LPStart = info->Start;
 
 
  /* Find @TType, the base of the handler and exception spec type data.  */
  /* Find @TType, the base of the handler and exception spec type data.  */
  info->ttype_encoding = *p++;
  info->ttype_encoding = *p++;
  if (info->ttype_encoding != DW_EH_PE_omit)
  if (info->ttype_encoding != DW_EH_PE_omit)
    {
    {
      p = read_uleb128 (p, &tmp);
      p = read_uleb128 (p, &tmp);
      info->TType = p + tmp;
      info->TType = p + tmp;
    }
    }
  else
  else
    info->TType = 0;
    info->TType = 0;
 
 
  /* The encoding and length of the call-site table; the action table
  /* The encoding and length of the call-site table; the action table
     immediately follows.  */
     immediately follows.  */
  info->call_site_encoding = *p++;
  info->call_site_encoding = *p++;
  p = read_uleb128 (p, &tmp);
  p = read_uleb128 (p, &tmp);
  info->action_table = p + tmp;
  info->action_table = p + tmp;
 
 
  return p;
  return p;
}
}
 
 
#ifdef __ARM_EABI_UNWINDER__
#ifdef __ARM_EABI_UNWINDER__
/* ARM EABI personality routines must also unwind the stack.  */
/* ARM EABI personality routines must also unwind the stack.  */
#define CONTINUE_UNWINDING \
#define CONTINUE_UNWINDING \
  do                                                            \
  do                                                            \
    {                                                           \
    {                                                           \
      if (__gnu_unwind_frame (ue_header, context) != _URC_OK)   \
      if (__gnu_unwind_frame (ue_header, context) != _URC_OK)   \
        return _URC_FAILURE;                                    \
        return _URC_FAILURE;                                    \
      return _URC_CONTINUE_UNWIND;                              \
      return _URC_CONTINUE_UNWIND;                              \
    }                                                           \
    }                                                           \
  while (0)
  while (0)
#else
#else
#define CONTINUE_UNWINDING return _URC_CONTINUE_UNWIND
#define CONTINUE_UNWINDING return _URC_CONTINUE_UNWIND
#endif
#endif
 
 
#ifdef __USING_SJLJ_EXCEPTIONS__
#ifdef __USING_SJLJ_EXCEPTIONS__
#define PERSONALITY_FUNCTION    __gcc_personality_sj0
#define PERSONALITY_FUNCTION    __gcc_personality_sj0
#define __builtin_eh_return_data_regno(x) x
#define __builtin_eh_return_data_regno(x) x
#else
#else
#define PERSONALITY_FUNCTION    __gcc_personality_v0
#define PERSONALITY_FUNCTION    __gcc_personality_v0
#endif
#endif
 
 
#ifdef __ARM_EABI_UNWINDER__
#ifdef __ARM_EABI_UNWINDER__
_Unwind_Reason_Code
_Unwind_Reason_Code
PERSONALITY_FUNCTION (_Unwind_State, struct _Unwind_Exception *,
PERSONALITY_FUNCTION (_Unwind_State, struct _Unwind_Exception *,
                      struct _Unwind_Context *);
                      struct _Unwind_Context *);
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
PERSONALITY_FUNCTION (_Unwind_State state,
PERSONALITY_FUNCTION (_Unwind_State state,
                      struct _Unwind_Exception * ue_header,
                      struct _Unwind_Exception * ue_header,
                      struct _Unwind_Context * context)
                      struct _Unwind_Context * context)
#else
#else
_Unwind_Reason_Code
_Unwind_Reason_Code
PERSONALITY_FUNCTION (int, _Unwind_Action, _Unwind_Exception_Class,
PERSONALITY_FUNCTION (int, _Unwind_Action, _Unwind_Exception_Class,
                      struct _Unwind_Exception *, struct _Unwind_Context *);
                      struct _Unwind_Exception *, struct _Unwind_Context *);
 
 
_Unwind_Reason_Code
_Unwind_Reason_Code
PERSONALITY_FUNCTION (int version,
PERSONALITY_FUNCTION (int version,
                      _Unwind_Action actions,
                      _Unwind_Action actions,
                      _Unwind_Exception_Class exception_class ATTRIBUTE_UNUSED,
                      _Unwind_Exception_Class exception_class ATTRIBUTE_UNUSED,
                      struct _Unwind_Exception *ue_header,
                      struct _Unwind_Exception *ue_header,
                      struct _Unwind_Context *context)
                      struct _Unwind_Context *context)
#endif
#endif
{
{
  lsda_header_info info;
  lsda_header_info info;
  const unsigned char *language_specific_data, *p, *action_record;
  const unsigned char *language_specific_data, *p, *action_record;
  _Unwind_Ptr landing_pad, ip;
  _Unwind_Ptr landing_pad, ip;
  int ip_before_insn = 0;
  int ip_before_insn = 0;
 
 
#ifdef __ARM_EABI_UNWINDER__
#ifdef __ARM_EABI_UNWINDER__
  if ((state & _US_ACTION_MASK) != _US_UNWIND_FRAME_STARTING)
  if ((state & _US_ACTION_MASK) != _US_UNWIND_FRAME_STARTING)
    CONTINUE_UNWINDING;
    CONTINUE_UNWINDING;
 
 
  /* The dwarf unwinder assumes the context structure holds things like the
  /* The dwarf unwinder assumes the context structure holds things like the
     function and LSDA pointers.  The ARM implementation caches these in
     function and LSDA pointers.  The ARM implementation caches these in
     the exception header (UCB).  To avoid rewriting everything we make the
     the exception header (UCB).  To avoid rewriting everything we make the
     virtual IP register point at the UCB.  */
     virtual IP register point at the UCB.  */
  ip = (_Unwind_Ptr) ue_header;
  ip = (_Unwind_Ptr) ue_header;
  _Unwind_SetGR (context, 12, ip);
  _Unwind_SetGR (context, 12, ip);
#else
#else
  if (version != 1)
  if (version != 1)
    return _URC_FATAL_PHASE1_ERROR;
    return _URC_FATAL_PHASE1_ERROR;
 
 
  /* Currently we only support cleanups for C.  */
  /* Currently we only support cleanups for C.  */
  if ((actions & _UA_CLEANUP_PHASE) == 0)
  if ((actions & _UA_CLEANUP_PHASE) == 0)
    CONTINUE_UNWINDING;
    CONTINUE_UNWINDING;
#endif
#endif
 
 
  language_specific_data = (const unsigned char *)
  language_specific_data = (const unsigned char *)
    _Unwind_GetLanguageSpecificData (context);
    _Unwind_GetLanguageSpecificData (context);
 
 
  /* If no LSDA, then there are no handlers or cleanups.  */
  /* If no LSDA, then there are no handlers or cleanups.  */
  if (! language_specific_data)
  if (! language_specific_data)
    CONTINUE_UNWINDING;
    CONTINUE_UNWINDING;
 
 
  /* Parse the LSDA header.  */
  /* Parse the LSDA header.  */
  p = parse_lsda_header (context, language_specific_data, &info);
  p = parse_lsda_header (context, language_specific_data, &info);
#ifdef HAVE_GETIPINFO
#ifdef HAVE_GETIPINFO
  ip = _Unwind_GetIPInfo (context, &ip_before_insn);
  ip = _Unwind_GetIPInfo (context, &ip_before_insn);
#else
#else
  ip = _Unwind_GetIP (context);
  ip = _Unwind_GetIP (context);
#endif
#endif
  if (! ip_before_insn)
  if (! ip_before_insn)
    --ip;
    --ip;
  landing_pad = 0;
  landing_pad = 0;
 
 
#ifdef __USING_SJLJ_EXCEPTIONS__
#ifdef __USING_SJLJ_EXCEPTIONS__
  /* The given "IP" is an index into the call-site table, with two
  /* The given "IP" is an index into the call-site table, with two
     exceptions -- -1 means no-action, and 0 means terminate.  But
     exceptions -- -1 means no-action, and 0 means terminate.  But
     since we're using uleb128 values, we've not got random access
     since we're using uleb128 values, we've not got random access
     to the array.  */
     to the array.  */
  if ((int) ip <= 0)
  if ((int) ip <= 0)
    return _URC_CONTINUE_UNWIND;
    return _URC_CONTINUE_UNWIND;
  else
  else
    {
    {
      _Unwind_Word cs_lp, cs_action;
      _Unwind_Word cs_lp, cs_action;
      do
      do
        {
        {
          p = read_uleb128 (p, &cs_lp);
          p = read_uleb128 (p, &cs_lp);
          p = read_uleb128 (p, &cs_action);
          p = read_uleb128 (p, &cs_action);
        }
        }
      while (--ip);
      while (--ip);
 
 
      /* Can never have null landing pad for sjlj -- that would have
      /* Can never have null landing pad for sjlj -- that would have
         been indicated by a -1 call site index.  */
         been indicated by a -1 call site index.  */
      landing_pad = cs_lp + 1;
      landing_pad = cs_lp + 1;
      if (cs_action)
      if (cs_action)
        action_record = info.action_table + cs_action - 1;
        action_record = info.action_table + cs_action - 1;
      goto found_something;
      goto found_something;
    }
    }
#else
#else
  /* Search the call-site table for the action associated with this IP.  */
  /* Search the call-site table for the action associated with this IP.  */
  while (p < info.action_table)
  while (p < info.action_table)
    {
    {
      _Unwind_Ptr cs_start, cs_len, cs_lp;
      _Unwind_Ptr cs_start, cs_len, cs_lp;
      _Unwind_Word cs_action;
      _Unwind_Word cs_action;
 
 
      /* Note that all call-site encodings are "absolute" displacements.  */
      /* Note that all call-site encodings are "absolute" displacements.  */
      p = read_encoded_value (0, info.call_site_encoding, p, &cs_start);
      p = read_encoded_value (0, info.call_site_encoding, p, &cs_start);
      p = read_encoded_value (0, info.call_site_encoding, p, &cs_len);
      p = read_encoded_value (0, info.call_site_encoding, p, &cs_len);
      p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp);
      p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp);
      p = read_uleb128 (p, &cs_action);
      p = read_uleb128 (p, &cs_action);
 
 
      /* The table is sorted, so if we've passed the ip, stop.  */
      /* The table is sorted, so if we've passed the ip, stop.  */
      if (ip < info.Start + cs_start)
      if (ip < info.Start + cs_start)
        p = info.action_table;
        p = info.action_table;
      else if (ip < info.Start + cs_start + cs_len)
      else if (ip < info.Start + cs_start + cs_len)
        {
        {
          if (cs_lp)
          if (cs_lp)
            landing_pad = info.LPStart + cs_lp;
            landing_pad = info.LPStart + cs_lp;
          if (cs_action)
          if (cs_action)
            action_record = info.action_table + cs_action - 1;
            action_record = info.action_table + cs_action - 1;
          goto found_something;
          goto found_something;
        }
        }
    }
    }
#endif
#endif
 
 
  /* IP is not in table.  No associated cleanups.  */
  /* IP is not in table.  No associated cleanups.  */
  /* ??? This is where C++ calls std::terminate to catch throw
  /* ??? This is where C++ calls std::terminate to catch throw
     from a destructor.  */
     from a destructor.  */
  CONTINUE_UNWINDING;
  CONTINUE_UNWINDING;
 
 
 found_something:
 found_something:
  if (landing_pad == 0)
  if (landing_pad == 0)
    {
    {
      /* IP is present, but has a null landing pad.
      /* IP is present, but has a null landing pad.
         No handler to be run.  */
         No handler to be run.  */
      CONTINUE_UNWINDING;
      CONTINUE_UNWINDING;
    }
    }
 
 
  _Unwind_SetGR (context, __builtin_eh_return_data_regno (0),
  _Unwind_SetGR (context, __builtin_eh_return_data_regno (0),
                 (_Unwind_Ptr) ue_header);
                 (_Unwind_Ptr) ue_header);
  _Unwind_SetGR (context, __builtin_eh_return_data_regno (1), 0);
  _Unwind_SetGR (context, __builtin_eh_return_data_regno (1), 0);
  _Unwind_SetIP (context, landing_pad);
  _Unwind_SetIP (context, landing_pad);
  return _URC_INSTALL_CONTEXT;
  return _URC_INSTALL_CONTEXT;
}
}
 
 

powered by: WebSVN 2.1.0

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