~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to o/rel_sun4.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright William Schelter. All rights reserved.  This file does
 
2
the low level relocation which tends to be very system dependent.
 
3
It is included by the file sfasl.c
 
4
Thanks to Blewett@research.att.com, for an initial effort on this.
 
5
*/
 
6
 
 
7
/*
 
8
   Unfortunately the original documentation of the relocation types
 
9
was rather sketchy, so I was not able to determine the correct
 
10
behaviour of types which were not currently being output.
 
11
   
 
12
  These will have to be added later, for the moment an abort will occur.
 
13
One way to check your work is to compile sfasl.c defining STAND, and then
 
14
compare (using comp.c) the output from it with the output from ld.
 
15
  */
 
16
 
 
17
relocate()
 
18
{
 
19
  char *where;
 
20
  {
 
21
    unsigned int new_value;
 
22
    long x;
 
23
    where = the_start + relocation_info.r_address;
 
24
    dprintf (where has %x , *where);
 
25
    dprintf(   at %x -->, where );
 
26
#ifdef DEBUG    
 
27
    dshow();
 
28
#endif    
 
29
    if(relocation_info.r_extern)
 
30
      {
 
31
        switch (relocation_info.r_type)
 
32
          {
 
33
          case RELOC_DISP8:            /* Disp's (pc-rel)    */
 
34
          case RELOC_DISP16:
 
35
          case RELOC_DISP32:  abort();
 
36
          case RELOC_WDISP30:
 
37
            dprintf (         symbol_table[relocation_info.r_index].n_value %d,
 
38
                              symbol_table[relocation_info.r_index].n_value);
 
39
            new_value =
 
40
              symbol_table[relocation_info.r_index].n_value
 
41
                + relocation_info.r_addend
 
42
                  - (int)start_address;
 
43
            break;
 
44
          case RELOC_8:         /* simplest relocs    */
 
45
          case RELOC_16:                     
 
46
          case RELOC_32:                    
 
47
          case RELOC_HI22:      /* SR 22-bit relocs   */ 
 
48
          case RELOC_LO10:
 
49
            dprintf(   symbol_table[relocation_info.r_index].n_value = %d ,
 
50
                         symbol_table[relocation_info.r_index].n_value);
 
51
            new_value =
 
52
              symbol_table[relocation_info.r_index].n_value;
 
53
 
 
54
            break;
 
55
          default:
 
56
            printf ("extern non-supported relocation_info.r_type=%d\n",
 
57
                    relocation_info.r_type);
 
58
            fflush (stdout);
 
59
            goto DONT;
 
60
          }
 
61
        dprintf( new value %x , new_value);
 
62
        dprintf( rtype %x , relocation_info.r_type);
 
63
      }
 
64
    else
 
65
      {
 
66
        switch(relocation_info.r_index) /* was symbolnum */
 
67
          {
 
68
          case N_DATA: case N_BSS: case N_TEXT:
 
69
            new_value= (int)start_address;
 
70
            break;
 
71
          default:
 
72
            abort();
 
73
            goto DONT;
 
74
          }
 
75
      }
 
76
 
 
77
    switch (relocation_info.r_type)
 
78
      {
 
79
#define WHERE relocation_info.r_addend
 
80
      case RELOC_8:             /* simplest relocs    */
 
81
        *(char *)where = x = new_value + WHERE;
 
82
        break;
 
83
      case RELOC_16:
 
84
        *(short *)where = x = new_value + WHERE;
 
85
        break;
 
86
      case RELOC_32:
 
87
        *(int *)where = x = new_value + WHERE;
 
88
        break;
 
89
 
 
90
      case RELOC_DISP8:         /* Disp's (pc-rel)    */
 
91
        abort();
 
92
        *(char *)where = x = new_value + *(char *) where;
 
93
        break;
 
94
      case RELOC_DISP16:
 
95
        abort();
 
96
        *(short *)where = x = new_value + *(short *) where;
 
97
        break;
 
98
      case RELOC_DISP32:
 
99
        abort();
 
100
        *(int *)where = new_value + *(int *) where;
 
101
        x =  new_value + *( int *) where;
 
102
        break;
 
103
 
 
104
      case RELOC_WDISP30:       /* SR word disp's     */
 
105
#define MASK30BITS 0x3FFFFFFF
 
106
        *(int *)where = ((((int) new_value) >> 2) & MASK30BITS)
 
107
          | (~MASK30BITS & ( *(int *) where));
 
108
        break;
 
109
 
 
110
      case RELOC_WDISP22:
 
111
        goto Default;
 
112
 
 
113
      case RELOC_HI22:          /* SR 22-bit relocs   */
 
114
        x = ((unsigned long) (new_value + relocation_info.r_addend)) >> 10;
 
115
#define MASK22 0x3fffff 
 
116
        *(long *) where= (~MASK22 & *(long *)where) | x;
 
117
        break;
 
118
 
 
119
      case RELOC_22:
 
120
      case RELOC_13:            /* SR 13&10-bit relocs*/
 
121
        goto Default;
 
122
      case RELOC_LO10:
 
123
        x = ((unsigned long) (new_value + relocation_info.r_addend)) & 0x3ff;
 
124
        *(unsigned short *)(where + 2) |= x;
 
125
        break;
 
126
 
 
127
      case RELOC_SFA_BASE:      /* SR S.F.A. relocs   */
 
128
      case RELOC_SFA_OFF13:
 
129
      case RELOC_BASE10:        /* base_relative pic */
 
130
      case RELOC_BASE13:
 
131
      case RELOC_BASE22:
 
132
      case RELOC_PC10:          /* special pc-rel pic*/
 
133
      case RELOC_PC22:
 
134
      case RELOC_JMP_TBL:       /* jmp_tbl_rel in pic */
 
135
      case RELOC_SEGOFF16:      /* ShLib offset-in-seg*/
 
136
      case RELOC_GLOB_DAT:      /* rtld relocs */
 
137
      case RELOC_JMP_SLOT:
 
138
      case RELOC_RELATIVE:
 
139
 
 
140
      Default:
 
141
      default:
 
142
        printf ("non-supported relocation_info.r_type=%d\n",
 
143
                relocation_info.r_type);
 
144
        fflush (stdout);
 
145
        abort();
 
146
      }
 
147
  DONT:;
 
148
  }
 
149
 
 
150
}
 
151
 
 
152
 
 
153
#ifdef DEBUG
 
154
 
 
155
dshow()
 
156
{ if(debug)
 
157
  printf("\nrelocation_info:{r_address %d,r_index %d,r_extern %d \n r_type %d, r_addend %d"
 
158
         , relocation_info.r_address
 
159
, relocation_info.r_index
 
160
, relocation_info.r_extern
 
161
, relocation_info.r_type
 
162
, relocation_info.r_addend);
 
163
    fflush(stdout);}
 
164
 
 
165
#endif /* DEBUG */
 
166