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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [libgloss/] [sparc/] [fixctors.c] - Diff between revs 158 and 816

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

Rev 158 Rev 816
/* Code to byte-swap static constructor/destructor tables on
/* Code to byte-swap static constructor/destructor tables on
   broken a.out little-endian targets. The startup code should call
   broken a.out little-endian targets. The startup code should call
   __fix_ctors just before calling main.  It is safe to use on non-broken
   __fix_ctors just before calling main.  It is safe to use on non-broken
   or big-endian targets. */
   or big-endian targets. */
 
 
extern long __CTOR_LIST__[];
extern long __CTOR_LIST__[];
extern long __DTOR_LIST__[];
extern long __DTOR_LIST__[];
 
 
static void
static void
byte_swap (long *entry)
byte_swap (long *entry)
{
{
  unsigned char *p = (unsigned char *)entry;
  unsigned char *p = (unsigned char *)entry;
  unsigned char tmp;
  unsigned char tmp;
 
 
  tmp = p[0];
  tmp = p[0];
  p[0] = p[3];
  p[0] = p[3];
  p[3] = tmp;
  p[3] = tmp;
  tmp = p[1];
  tmp = p[1];
  p[1] = p[2];
  p[1] = p[2];
  p[2] = tmp;
  p[2] = tmp;
}
}
 
 
static void
static void
fix_table (long *table)
fix_table (long *table)
{
{
  long len = table[0];
  long len = table[0];
 
 
  /* The heuristic for deciding if a table is broken is to examine
  /* The heuristic for deciding if a table is broken is to examine
     the word at the start of the table, which contains the number
     the word at the start of the table, which contains the number
     of function pointers immediately following.  If the low word
     of function pointers immediately following.  If the low word
     is zero, and the high word is non-zero, it's very likely that
     is zero, and the high word is non-zero, it's very likely that
     it is byte-swapped.  This test will fail if the program has
     it is byte-swapped.  This test will fail if the program has
     an exact multiple of 64K static constructors or destructors, a very
     an exact multiple of 64K static constructors or destructors, a very
     unlikely situation. */
     unlikely situation. */
  if ((len & 0xffff) == 0 && (len & 0xffff0000) != 0)
  if ((len & 0xffff) == 0 && (len & 0xffff0000) != 0)
    {
    {
 
 
      /* The table looks broken.  Byte-swap all the words in the table, up
      /* The table looks broken.  Byte-swap all the words in the table, up
         to a NULL entry, which marks the end of the table. */
         to a NULL entry, which marks the end of the table. */
      do
      do
        {
        {
          byte_swap (table);
          byte_swap (table);
          table++;
          table++;
        }
        }
      while (*table);
      while (*table);
    }
    }
}
}
 
 
void
void
__fix_ctors (void)
__fix_ctors (void)
{
{
  fix_table (__CTOR_LIST__);
  fix_table (__CTOR_LIST__);
  fix_table (__DTOR_LIST__);
  fix_table (__DTOR_LIST__);
}
}
 
 

powered by: WebSVN 2.1.0

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