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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [rs6000/] [host-darwin.c] - Diff between revs 154 and 816

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

Rev 154 Rev 816
/* Darwin/powerpc host-specific hook definitions.
/* Darwin/powerpc host-specific hook definitions.
   Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
   Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 
   This file is part of GCC.
   This file is part of GCC.
 
 
   GCC is free software; you can redistribute it and/or modify it
   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published
   under the terms of the GNU General Public License as published
   by the Free Software Foundation; either version 3, or (at your
   by the Free Software Foundation; either version 3, or (at your
   option) any later version.
   option) any later version.
 
 
   GCC is distributed in the hope that it will be useful, but WITHOUT
   GCC is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.
   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 GCC; see the file COPYING3.  If not see
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */
   <http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include <signal.h>
#include <signal.h>
#include <sys/ucontext.h>
#include <sys/ucontext.h>
#include "hosthooks.h"
#include "hosthooks.h"
#include "hosthooks-def.h"
#include "hosthooks-def.h"
#include "toplev.h"
#include "toplev.h"
#include "diagnostic.h"
#include "diagnostic.h"
#include "config/host-darwin.h"
#include "config/host-darwin.h"
 
 
static void segv_crash_handler (int);
static void segv_crash_handler (int);
static void segv_handler (int, siginfo_t *, void *);
static void segv_handler (int, siginfo_t *, void *);
static void darwin_rs6000_extra_signals (void);
static void darwin_rs6000_extra_signals (void);
 
 
#ifndef HAVE_DECL_SIGALTSTACK
#ifndef HAVE_DECL_SIGALTSTACK
/* This doesn't have a prototype in signal.h in 10.2.x and earlier,
/* This doesn't have a prototype in signal.h in 10.2.x and earlier,
   fixed in later releases.  */
   fixed in later releases.  */
extern int sigaltstack(const struct sigaltstack *, struct sigaltstack *);
extern int sigaltstack(const struct sigaltstack *, struct sigaltstack *);
#endif
#endif
 
 
/* The fields of the mcontext_t type have acquired underscores in later
/* The fields of the mcontext_t type have acquired underscores in later
   OS versions.  */
   OS versions.  */
#ifdef HAS_MCONTEXT_T_UNDERSCORES
#ifdef HAS_MCONTEXT_T_UNDERSCORES
#define MC_FLD(x) __ ## x
#define MC_FLD(x) __ ## x
#else
#else
#define MC_FLD(x) x
#define MC_FLD(x) x
#endif
#endif
 
 
#undef HOST_HOOKS_EXTRA_SIGNALS
#undef HOST_HOOKS_EXTRA_SIGNALS
#define HOST_HOOKS_EXTRA_SIGNALS darwin_rs6000_extra_signals
#define HOST_HOOKS_EXTRA_SIGNALS darwin_rs6000_extra_signals
 
 
/* On Darwin/powerpc, hitting the stack limit turns into a SIGSEGV.
/* On Darwin/powerpc, hitting the stack limit turns into a SIGSEGV.
   This code detects the difference between hitting the stack limit and
   This code detects the difference between hitting the stack limit and
   a true wild pointer dereference by looking at the instruction that
   a true wild pointer dereference by looking at the instruction that
   faulted; only a few kinds of instruction are used to access below
   faulted; only a few kinds of instruction are used to access below
   the previous bottom of the stack.  */
   the previous bottom of the stack.  */
 
 
static void
static void
segv_crash_handler (int sig ATTRIBUTE_UNUSED)
segv_crash_handler (int sig ATTRIBUTE_UNUSED)
{
{
  internal_error ("Segmentation Fault (code)");
  internal_error ("Segmentation Fault (code)");
}
}
 
 
static void
static void
segv_handler (int sig ATTRIBUTE_UNUSED,
segv_handler (int sig ATTRIBUTE_UNUSED,
              siginfo_t *sip ATTRIBUTE_UNUSED,
              siginfo_t *sip ATTRIBUTE_UNUSED,
              void *scp)
              void *scp)
{
{
  ucontext_t *uc = (ucontext_t *)scp;
  ucontext_t *uc = (ucontext_t *)scp;
  sigset_t sigset;
  sigset_t sigset;
  unsigned faulting_insn;
  unsigned faulting_insn;
 
 
  /* The fault might have happened when trying to run some instruction, in
  /* The fault might have happened when trying to run some instruction, in
     which case the next line will segfault _again_.  Handle this case.  */
     which case the next line will segfault _again_.  Handle this case.  */
  signal (SIGSEGV, segv_crash_handler);
  signal (SIGSEGV, segv_crash_handler);
  sigemptyset (&sigset);
  sigemptyset (&sigset);
  sigaddset (&sigset, SIGSEGV);
  sigaddset (&sigset, SIGSEGV);
  sigprocmask (SIG_UNBLOCK, &sigset, NULL);
  sigprocmask (SIG_UNBLOCK, &sigset, NULL);
 
 
  faulting_insn = *(unsigned *)uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0);
  faulting_insn = *(unsigned *)uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0);
 
 
  /* Note that this only has to work for GCC, so we don't have to deal
  /* Note that this only has to work for GCC, so we don't have to deal
     with all the possible cases (GCC has no AltiVec code, for
     with all the possible cases (GCC has no AltiVec code, for
     instance).  It's complicated because Darwin allows stores to
     instance).  It's complicated because Darwin allows stores to
     below the stack pointer, and the prologue code takes advantage of
     below the stack pointer, and the prologue code takes advantage of
     this.  */
     this.  */
 
 
  if ((faulting_insn & 0xFFFF8000) == 0x94218000  /* stwu %r1, -xxx(%r1) */
  if ((faulting_insn & 0xFFFF8000) == 0x94218000  /* stwu %r1, -xxx(%r1) */
      || (faulting_insn & 0xFC1F03FF) == 0x7C01016E /* stwux xxx, %r1, xxx */
      || (faulting_insn & 0xFC1F03FF) == 0x7C01016E /* stwux xxx, %r1, xxx */
      || (faulting_insn & 0xFC1F8000) == 0x90018000 /* stw xxx, -yyy(%r1) */
      || (faulting_insn & 0xFC1F8000) == 0x90018000 /* stw xxx, -yyy(%r1) */
      || (faulting_insn & 0xFC1F8000) == 0xD8018000 /* stfd xxx, -yyy(%r1) */
      || (faulting_insn & 0xFC1F8000) == 0xD8018000 /* stfd xxx, -yyy(%r1) */
      || (faulting_insn & 0xFC1F8000) == 0xBC018000 /* stmw xxx, -yyy(%r1) */)
      || (faulting_insn & 0xFC1F8000) == 0xBC018000 /* stmw xxx, -yyy(%r1) */)
    {
    {
      char *shell_name;
      char *shell_name;
 
 
      fnotice (stderr, "Out of stack space.\n");
      fnotice (stderr, "Out of stack space.\n");
      shell_name = getenv ("SHELL");
      shell_name = getenv ("SHELL");
      if (shell_name != NULL)
      if (shell_name != NULL)
        shell_name = strrchr (shell_name, '/');
        shell_name = strrchr (shell_name, '/');
      if (shell_name != NULL)
      if (shell_name != NULL)
        {
        {
          static const char * shell_commands[][2] = {
          static const char * shell_commands[][2] = {
            { "sh", "ulimit -S -s unlimited" },
            { "sh", "ulimit -S -s unlimited" },
            { "bash", "ulimit -S -s unlimited" },
            { "bash", "ulimit -S -s unlimited" },
            { "tcsh", "limit stacksize unlimited" },
            { "tcsh", "limit stacksize unlimited" },
            { "csh", "limit stacksize unlimited" },
            { "csh", "limit stacksize unlimited" },
            /* zsh doesn't have "unlimited", this will work under the
            /* zsh doesn't have "unlimited", this will work under the
               default configuration.  */
               default configuration.  */
            { "zsh", "limit stacksize 32m" }
            { "zsh", "limit stacksize 32m" }
          };
          };
          size_t i;
          size_t i;
 
 
          for (i = 0; i < ARRAY_SIZE (shell_commands); i++)
          for (i = 0; i < ARRAY_SIZE (shell_commands); i++)
            if (strcmp (shell_commands[i][0], shell_name + 1) == 0)
            if (strcmp (shell_commands[i][0], shell_name + 1) == 0)
              {
              {
                fnotice (stderr,
                fnotice (stderr,
                         "Try running '%s' in the shell to raise its limit.\n",
                         "Try running '%s' in the shell to raise its limit.\n",
                         shell_commands[i][1]);
                         shell_commands[i][1]);
              }
              }
        }
        }
 
 
      if (global_dc->abort_on_error)
      if (global_dc->abort_on_error)
        fancy_abort (__FILE__, __LINE__, __FUNCTION__);
        fancy_abort (__FILE__, __LINE__, __FUNCTION__);
 
 
      exit (FATAL_EXIT_CODE);
      exit (FATAL_EXIT_CODE);
    }
    }
 
 
  fprintf (stderr, "[address=%08lx pc=%08x]\n",
  fprintf (stderr, "[address=%08lx pc=%08x]\n",
           uc->uc_mcontext->MC_FLD(es).MC_FLD(dar),
           uc->uc_mcontext->MC_FLD(es).MC_FLD(dar),
           uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0));
           uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0));
  internal_error ("Segmentation Fault");
  internal_error ("Segmentation Fault");
  exit (FATAL_EXIT_CODE);
  exit (FATAL_EXIT_CODE);
}
}
 
 
static void
static void
darwin_rs6000_extra_signals (void)
darwin_rs6000_extra_signals (void)
{
{
  struct sigaction sact;
  struct sigaction sact;
  stack_t sigstk;
  stack_t sigstk;
 
 
  sigstk.ss_sp = xmalloc (SIGSTKSZ);
  sigstk.ss_sp = xmalloc (SIGSTKSZ);
  sigstk.ss_size = SIGSTKSZ;
  sigstk.ss_size = SIGSTKSZ;
  sigstk.ss_flags = 0;
  sigstk.ss_flags = 0;
  if (sigaltstack (&sigstk, NULL) < 0)
  if (sigaltstack (&sigstk, NULL) < 0)
    fatal_error ("While setting up signal stack: %m");
    fatal_error ("While setting up signal stack: %m");
 
 
  sigemptyset(&sact.sa_mask);
  sigemptyset(&sact.sa_mask);
  sact.sa_flags = SA_ONSTACK | SA_SIGINFO;
  sact.sa_flags = SA_ONSTACK | SA_SIGINFO;
  sact.sa_sigaction = segv_handler;
  sact.sa_sigaction = segv_handler;
  if (sigaction (SIGSEGV, &sact, 0) < 0)
  if (sigaction (SIGSEGV, &sact, 0) < 0)
    fatal_error ("While setting up signal handler: %m");
    fatal_error ("While setting up signal handler: %m");
}
}


 
 
const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
 
 

powered by: WebSVN 2.1.0

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