annotate dynodump/ppc/_relocate.c @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents
children c5d627a313b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
2 * Copyright (c) 1995 by Sun Microsystems, Inc.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
3 * All rights reserved.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
4 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
5 * This source code is a product of Sun Microsystems, Inc. and is provided
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
6 * for unrestricted use provided that this legend is included on all tape
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
7 * media and as a part of the software program in whole or part. Users
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
8 * may copy or modify this source code without charge, but are not authorized
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
9 * to license or distribute it to anyone else except as part of a product or
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
10 * program developed by the user.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
11 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
12 * THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
13 * SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
14 * OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
15 * EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
16 * ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
18 * NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
19 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
20 * FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
21 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
22 * This source code is provided with no support and without any obligation on
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
23 * the part of Sun Microsystems, Inc. to assist in its use, correction,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
24 * modification or enhancement.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
25 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
26 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
27 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
28 * SOURCE CODE OR ANY PART THEREOF.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
29 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
30 * Sun Microsystems, Inc.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
31 * 2550 Garcia Avenue
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
32 * Mountain View, California 94043
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
33 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
34
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
35 #pragma ident "@(#) $Id: _relocate.c,v 1.3 1997/05/29 04:23:20 steve Exp $ - SMI"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
36
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
37 /* LINTLIBRARY */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
38
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
39 #include <string.h>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
40 #include <sys/elf_ppc.h>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
41 #include "_dynodump.h"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
42
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
43
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
44 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
45 * NOTE: These macros will work reliably only on 32-bit 2's
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
46 * complement machines. The type of P in all cases should
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
47 * by unsigned char *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
48 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
49 #if defined(_BIG_ENDIAN)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
50
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
51 #define GET4(P) ((long)(((unsigned long)(P)[0] << 24) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
52 ((unsigned long)(P)[1] << 16) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
53 ((unsigned long)(P)[2] << 8) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
54 (unsigned long)(P)[3]))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
55 #define PUT4(V, P) { \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
56 (P)[0] = (unsigned char)((V) >> 24); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
57 (P)[1] = (unsigned char)((V) >> 16); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
58 (P)[2] = (unsigned char)((V) >> 8); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
59 (P)[3] = (unsigned char)(V); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
60 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
61 #define GEThalf(P) ((long) (((unsigned long) (P)[0] << 8) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
62 ((unsigned long) (P)[1])))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
63 #define GETword(P) GET4(P)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
64 #define PUThalf(V, P) { \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
65 (P)[0] = ((V) >> 8); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
66 (P)[1] = ((V)); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
67 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
68 #define PUTword(V, P) PUT4(V, P)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
69
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
70 #elif defined(_LITTLE_ENDIAN)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
71
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
72 #define GET4(P) ((long)(((unsigned long)(P)[0]) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
73 ((unsigned long)(P)[1] << 8) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
74 ((unsigned long)(P)[2] << 16) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
75 ((unsigned long)(P)[3]) << 24))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
76 #define PUT4(V, P) { \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
77 (P)[0] = (unsigned char)(V); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
78 (P)[1] = (unsigned char)((V) >> 8); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
79 (P)[2] = (unsigned char)((V) >> 16); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
80 (P)[3] = (unsigned char)((V) >> 24); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
81 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
82 #define GEThalf(P) ((long) (((unsigned long) (P)[0]) | \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
83 ((unsigned long) (P)[1] << 8)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
84 #define GETword(P) GET4(P)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
85 #define PUThalf(V, P) { \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
86 (P)[0] = (V); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
87 (P)[1] = ((V) >> 8); \
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
88 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
89 #define PUTword(V, P) PUT4(V, P)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
90
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
91 #endif /* defined(_LITTLE_ENDIAN) */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
92
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
93 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
94 * NAME VALUE FIELD CALCULATION
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
95 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
96 * R_PPC_NONE 0 none none
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
97 * R_PPC_ADDR32 1 word32 S + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
98 * R_PPC_ADDR24 2 low24 (S + A) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
99 * R_PPC_ADDR16 3 half16 S + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
100 * R_PPC_ADDR16_LO 4 half16 #lo(S + A)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
101 * R_PPC_ADDR16_HI 5 half16 #hi(S + A)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
102 * R_PPC_ADDR16_HA 6 half16 #ha(S + A)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
103 * R_PPC_ADDR14 7 low14 (S + A) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
104 * R_PPC_ADDR14_BRTAKEN 8 low14 (S + A) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
105 * R_PPC_ADDR14_BRNTAKEN 9 low14 (S + A) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
106 * R_PPC_REL24 10 low24 (S + A - P) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
107 * R_PPC_REL14 11 low14 (S + A - P) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
108 * R_PPC_REL14_BRTAKEN 12 low14 (S + A - P) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
109 * R_PPC_REL14_BRNTAKEN 13 low14 (S + A - P) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
110 * R_PPC_GOT16 14 half16 G + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
111 * R_PPC_GOT16_LO 15 half16 #lo(G + A)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
112 * R_PPC_GOT16_HI 16 half16 #hi(G + A)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
113 * R_PPC_GOT16_HA 17 half16 #ha(G + A)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
114 * R_PPC_PLT24 18 low24 (L + A - P) >> 2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
115 * R_PPC_COPY 19 none none
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
116 * R_PPC_GLOB_DAT 20 word32 S + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
117 * R_PPC_JMP_SLOT 21 none see below
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
118 * R_PPC_RELATIVE 22 word32 B + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
119 * R_PPC_LOCAL24PC 23 low24 see below
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
120 * R_PPC_UADDR32 24 word32 S + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
121 * R_PPC_UADDR16 25 half16 S + A
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
122 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
123 * This is Figure 4-3: Relocation Types from the Draft Copy of
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
124 * the ABI, Printed on 7/25/94.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
125 *
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
126 * The field column specifies how much of the data
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
127 * at the reference address is to be used. The data are assumed to be
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
128 * right-justified with the least significant bit at the right.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
129 * In the case of plt24 addresses, the reference address is
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
130 * assumed to be that of a 6-word PLT entry. The address is the right-
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
131 * most 24 bits of the third word.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
132 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
133 static void
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
134 move_reloc(unsigned char *iaddr, unsigned char *oaddr, unsigned char type)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
135 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
136 switch(type) {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
137 case R_PPC_NONE:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
138 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
139
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
140 case R_PPC_ADDR32:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
141 case R_PPC_UADDR32:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
142 PUTword(GETword(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
143 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
144
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
145 case R_PPC_ADDR24:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
146 case R_PPC_REL24:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
147 case R_PPC_PLT24:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
148 case R_PPC_LOCAL24PC:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
149 /* XXX - big assumption here that the original contents were masked
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
150 * properly. If this assumption proves correct, then these 24bit
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
151 * cases can be folded into the above 32bit cases.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
152 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
153 PUTword(GETword(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
154 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
155
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
156 case R_PPC_ADDR16:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
157 case R_PPC_UADDR16:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
158 case R_PPC_GOT16:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
159 PUThalf(GEThalf(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
160 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
161
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
162 case R_PPC_ADDR16_LO:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
163 case R_PPC_GOT16_LO:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
164 /* XXX - more assumptions which if proved correct, we can
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
165 * do some folding with above cases
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
166 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
167 PUThalf(GEThalf(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
168 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
169
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
170 case R_PPC_ADDR16_HI:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
171 case R_PPC_GOT16_HI:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
172 /* XXX - more assumptions which if proved correct, we can
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
173 * do some folding with above cases
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
174 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
175 PUThalf(GEThalf(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
176 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
177
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
178 case R_PPC_ADDR16_HA:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
179 case R_PPC_GOT16_HA:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
180 /* XXX - more assumptions which if proved correct, we can
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
181 * do some folding with above cases
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
182 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
183 PUThalf(GEThalf(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
184 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
185
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
186 case R_PPC_ADDR14:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
187 case R_PPC_ADDR14_BRTAKEN:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
188 case R_PPC_ADDR14_BRNTAKEN:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
189 case R_PPC_REL14:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
190 case R_PPC_REL14_BRTAKEN:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
191 case R_PPC_REL14_BRNTAKEN:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
192 /* XXX - big assumption here that the original contents were masked
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
193 * properly. If this assumption proves correct, then these 14bit
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
194 * cases can be folded into the above 32bit cases.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
195 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
196 PUTword(GETword(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
197 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
198
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
199 case R_PPC_COPY:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
200 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
201
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
202 case R_PPC_GLOB_DAT:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
203 case R_PPC_RELATIVE:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
204 PUTword(GETword(iaddr), oaddr);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
205 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
206
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
207 case R_PPC_JMP_SLOT:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
208 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
209
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
210 default:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
211 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
212 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
213 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
214
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
215 void
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
216 update_reloc(Cache *ocache, Cache *_ocache, Cache *icache, Cache *_icache, Half shnum)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
217 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
218 Shdr *shdr;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
219 Rel *rels;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
220 int reln, cnt;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
221 Cache *orcache, * ircache;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
222
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
223 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
224 * Set up to read the output relocation table.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
225 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
226 shdr = _ocache->c_shdr;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
227 rels = (Rel *)_ocache->c_data->d_buf;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
228 reln = shdr->sh_size / shdr->sh_entsize;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
229
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
230 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
231 * Determine the section that is being relocated.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
232 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
233 orcache = &ocache[shdr->sh_info];
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
234 shdr = _icache->c_shdr;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
235 ircache = &icache[shdr->sh_info];
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
236
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
237 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
238 * Loop through the relocation table.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
239 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
240 for (cnt = 0; cnt < reln; cnt++, rels++) {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
241 unsigned char type = ELF_R_TYPE(rels->r_info);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
242
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
243 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
244 * Ignore some relocations as these can safely be carried out
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
245 * twice (they simply override any existing data). In fact,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
246 * some relocations like __iob's copy relocation must be carried
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
247 * out each time the process restarts otherwise stdio blows up.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
248 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
249 if ((type == R_PPC_COPY) || (type == R_PPC_JMP_SLOT) ||
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
250 (type == R_PPC_NONE))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
251 continue;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
252
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
253 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
254 unsigned char *iaddr, *oaddr;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
255 Addr off;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
256
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
257 /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
258 * If we are required to restore the relocation location
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
259 * to it's value prior to relocation, then read the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
260 * locations original contents from the input image and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
261 * copy it to the output image.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
262 */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
263 off = rels->r_offset - ircache->c_shdr->sh_addr;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
264 iaddr = (unsigned char *)ircache->c_data->d_buf + off;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
265 oaddr = (unsigned char *)orcache->c_data->d_buf + off;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
266 move_reloc(iaddr, oaddr, type);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
267 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
268 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
269 }