OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [libgloss/] [sparc/] [fixctors.c] - Blame information for rev 252

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Code to byte-swap static constructor/destructor tables on
2
   broken a.out little-endian targets. The startup code should call
3
   __fix_ctors just before calling main.  It is safe to use on non-broken
4
   or big-endian targets. */
5
 
6
extern long __CTOR_LIST__[];
7
extern long __DTOR_LIST__[];
8
 
9
static void
10
byte_swap (long *entry)
11
{
12
  unsigned char *p = (unsigned char *)entry;
13
  unsigned char tmp;
14
 
15
  tmp = p[0];
16
  p[0] = p[3];
17
  p[3] = tmp;
18
  tmp = p[1];
19
  p[1] = p[2];
20
  p[2] = tmp;
21
}
22
 
23
static void
24
fix_table (long *table)
25
{
26
  long len = table[0];
27
 
28
  /* The heuristic for deciding if a table is broken is to examine
29
     the word at the start of the table, which contains the number
30
     of function pointers immediately following.  If the low word
31
     is zero, and the high word is non-zero, it's very likely that
32
     it is byte-swapped.  This test will fail if the program has
33
     an exact multiple of 64K static constructors or destructors, a very
34
     unlikely situation. */
35
  if ((len & 0xffff) == 0 && (len & 0xffff0000) != 0)
36
    {
37
 
38
      /* The table looks broken.  Byte-swap all the words in the table, up
39
         to a NULL entry, which marks the end of the table. */
40
      do
41
        {
42
          byte_swap (table);
43
          table++;
44
        }
45
      while (*table);
46
    }
47
}
48
 
49
void
50
__fix_ctors (void)
51
{
52
  fix_table (__CTOR_LIST__);
53
  fix_table (__DTOR_LIST__);
54
}

powered by: WebSVN 2.1.0

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