aboutsummaryrefslogtreecommitdiffstats
path: root/package/broadcom-57xx
Commit message (Expand)AuthorAgeFilesLines
* remove broadcom-57xx (only used on linux 2.4)Felix Fietkau2010-06-2628-25147/+0
* bump some revisions and update copyrightsAndy Boyett2009-09-101-3/+3
* Added support for identifying the BCM53115 switch found in WRT610N.Felix Fietkau2009-08-281-2/+4
* brcm-2.4: nvram_set has been removed, remove some remaining calls to itFelix Fietkau2009-05-161-7/+0
* get rid of $Id$ - it has never helped us and it has broken too many patches ;)Felix Fietkau2009-04-1715-15/+0
* replace some -I & -L flags with $(TARGET_CPPFLAGS) & $(TARGET_LDFLAGS) when a...Nicolas Thill2009-02-241-3/+4
* remove some unused crapFelix Fietkau2008-06-1512-2361/+0
* (6/6) bcm57xx: packageFelix Fietkau2008-06-1540-0/+27527
5'>115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
/*  GRT stack implementation for Win32 using fibers.
    Copyright (C) 2005 - 2014 Tristan Gingold.

    GHDL 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 2, or (at your option) any later
    version.

    GHDL 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 COPYING.  If not, write to the Free
    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.

    As a special exception, if other files instantiate generics from this
    unit, or you link this unit with other files to produce an executable,
    this unit does not by itself cause the resulting executable to be
    covered by the GNU General Public License. This exception does not
    however invalidate any other reasons why the executable file might be
    covered by the GNU Public License.
*/

#include <windows.h>
#include <winbase.h>
#include <dbghelp.h>
#include <stdio.h>
#include <setjmp.h>
#include <assert.h>
#include <excpt.h>

#include "grt_itf.h"

static int run_env_en;
static jmp_buf run_env;

static EXCEPTION_DISPOSITION
ghdl_SEH_handler (struct _EXCEPTION_RECORD* ExceptionRecord,
		  void *EstablisherFrame,
		  struct _CONTEXT* ContextRecord,
		  void *DispatcherContext);

struct exception_registration
{
  struct exception_registration *prev;
  void *handler;
};

/* Save bactktrace from CTXT to BT, the first SKIP frames are skipped.
   We need to use StackWalk64 as apparently CaptureStackBackTrace doesn't
   work over JIT'ed code.  I suppose it checks whether PC belongs to the text
   section of an image.  */

static void
get_bt_from_context (struct backtrace_addrs *bt, CONTEXT *ctxt, int skip)
{
  STACKFRAME64 frame;
  unsigned mach;

  bt->size = 0;
  bt->skip = 0;
  memset (&frame, 0, sizeof (frame));

#ifdef __i386__
  mach = IMAGE_FILE_MACHINE_I386;

  frame.AddrPC.Offset = ctxt->Eip;
  frame.AddrPC.Mode = AddrModeFlat;
  frame.AddrFrame.Offset = ctxt->Ebp;
  frame.AddrFrame.Mode = AddrModeFlat;
  frame.AddrStack.Offset = ctxt->Esp;
  frame.AddrStack.Mode = AddrModeFlat;

#elif defined (__x86_64__)
  mach = IMAGE_FILE_MACHINE_AMD64;

  frame.AddrPC.Offset = ctxt->Rip;
  frame.AddrPC.Mode = AddrModeFlat;
  frame.AddrFrame.Offset = ctxt->Rsp;
  frame.AddrFrame.Mode = AddrModeFlat;
  frame.AddrStack.Offset = ctxt->Rsp;
  frame.AddrStack.Mode = AddrModeFlat;

#else
#  warning "platform not supported"
  return;
#endif

  while (bt->size < sizeof (bt->addrs) / sizeof (bt->addrs[0]))
    {
      if (skip > 0)
	skip--;
      else
	bt->addrs[bt->size++] = (void *) frame.AddrPC.Offset;

      if (!StackWalk64 (mach, GetCurrentProcess (), GetCurrentThread (),
			&frame, ctxt, NULL, NULL, NULL, NULL))
	break;
    }
}

static EXCEPTION_DISPOSITION
ghdl_SEH_handler (struct _EXCEPTION_RECORD* ExceptionRecord,
		  void *EstablisherFrame,
		  struct _CONTEXT* ContextRecord,
		  void *DispatcherContext)
{
  struct backtrace_addrs bt;
  const char *msg = "";

  switch (ExceptionRecord->ExceptionCode)
    {
    case EXCEPTION_ACCESS_VIOLATION:
      /* Pc is ExceptionRecord->ExceptionAddress.  */
      get_bt_from_context (&bt, ContextRecord, 1);
      grt_null_access_error (&bt);
      break;

    case EXCEPTION_FLT_DENORMAL_OPERAND:
    case EXCEPTION_FLT_DIVIDE_BY_ZERO:
    case EXCEPTION_FLT_INVALID_OPERATION:
    case EXCEPTION_FLT_OVERFLOW:
    case EXCEPTION_FLT_STACK_CHECK:
    case EXCEPTION_FLT_UNDERFLOW:
      msg = "floating point error";
      break;

    case EXCEPTION_INT_DIVIDE_BY_ZERO:
      msg = "division by 0";
      break;

    case EXCEPTION_INT_OVERFLOW:
      get_bt_from_context (&bt, ContextRecord, 1);
      grt_overflow_error (&bt);
      break;

    case EXCEPTION_STACK_OVERFLOW:
      msg = "stack overflow";
      break;

    default:
      msg = "unknown reason";
      break;
    }

  /* FIXME: is it correct?  */
  fprintf (stderr, "exception raised: %s\n", msg);

  __ghdl_maybe_return_via_longjump (1);
  return 0; /* This is never reached, avoid compiler warning  */
}

void
__ghdl_maybe_return_via_longjump (int val)
{
  if (run_env_en)
    longjmp (run_env, val);
}

int
__ghdl_run_through_longjump (int (*func)(void))
{
  int res;

#ifdef __i386__
  /* Install an SEH handler.  */
  struct exception_registration er;
  struct exception_registration *prev;

  /* Get current handler.  */
  asm volatile ("mov %%fs:(0),%0" : "=r" (prev));

  /* Build regisration.  */
  er.prev = prev;
  er.handler = ghdl_SEH_handler;

  /* Register.  */
  asm volatile ("mov %0,%%fs:(0)" : : "r" (&er));
#endif

  run_env_en = 1;
  res = setjmp (run_env);
  if (res == 0)
    res = (*func)();
  run_env_en = 0;

#ifdef __i386__
  /* Restore.  */
  asm volatile ("mov %0,%%fs:(0)" : : "r" (prev));
#endif

  return res;
}

void
grt_save_backtrace (struct backtrace_addrs *bt, int skip)
{
  CONTEXT ctxt;

  RtlCaptureContext (&ctxt);
  get_bt_from_context (bt, &ctxt, skip + 1);
}

#include <math.h>

double acosh (double x)
{
  return log (x + sqrt (x*x - 1));
}

double asinh (double x)
{
  return log (x + sqrt (x*x + 1));
}

double atanh (double x)
{
  return log ((1 + x) / (1 - x)) / 2;
}

#ifndef WITH_GNAT_RUN_TIME
void __gnat_raise_storage_error(void)
{
   abort ();
}

void __gnat_raise_program_error(void)
{
   abort ();
}
#endif