4 * Copyright (C) 1989-2009 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * With enhancements from:
26 * John L. Hartman (JLH)
27 * jhartman@compuserve.com
30 * w_mckinnon@conknet.com
38 * The module lkrloc.c contains the functions which
39 * perform the relocation calculations.
41 * lkrloc.c contains the following functions:
54 /*)Function VOID reloc(c)
58 * The function reloc() calls the proper version
65 * ASxxxx_VERSION ASxxxx REL file version
68 * VOID reloc3() lkrloc3.c
69 * VOID reloc4() lkrloc4.c
72 * Refer to the called relocation functions.
79 switch(ASxxxx_VERSION
) {
89 fprintf(stderr
, "Internal Version Error");
96 /*)Function a_uint evword()
98 * The function evword() combines two byte values
99 * into a single word value.
102 * a_uint v temporary evaluation variable
105 * hilo byte ordering parameter
108 * int eval() lkeval.c
111 * Relocation text line is scanned to combine
112 * two byte values into a single word value.
131 /*)Function a_uint adb_1b(v, i)
133 * a_uint v value to add to byte
134 * int i rtval[] index
136 * The function adb_1b() adds the value of v to
137 * the single byte value contained in rtval[i].
138 * The new value of rtval[i] is returned.
141 * a_uint j temporary evaluation variable
150 * The byte value of rtval[] is changed.
155 adb_1b(a_uint v
, int i
)
160 rtval
[i
] = j
& ((a_uint
) 0x000000FF);
165 /*)Function a_uint adb_2b(v, i)
167 * a_uint v value to add to word
168 * int i rtval[] index
170 * The function adb_2b() adds the value of v to the
171 * 2 byte value contained in rtval[i] and rtval[i+1].
172 * The new value of rtval[i] / rtval[i+1] is returned.
175 * a_uint j temporary evaluation variable
178 * hilo byte ordering parameter
184 * The 2 byte value of rtval[] is changed.
189 adb_2b(a_uint v
, int i
)
194 j
= v
+ (rtval
[i
+0] << 8) +
196 rtval
[i
+0] = (j
>> 8) & ((a_uint
) 0x000000FF);
197 rtval
[i
+1] = (j
>> 0) & ((a_uint
) 0x000000FF);
199 j
= v
+ (rtval
[i
+0] << 0) +
201 rtval
[i
+0] = (j
>> 0) & ((a_uint
) 0x000000FF);
202 rtval
[i
+1] = (j
>> 8) & ((a_uint
) 0x000000FF);
207 /*)Function a_uint adb_3b(v, i)
209 * a_uint v value to add to word
210 * int i rtval[] index
212 * The function adb_3b() adds the value of v to the
213 * three byte value contained in rtval[i], rtval[i+1], and rtval[i+2].
214 * The new value of rtval[i] / rtval[i+1] / rtval[i+2] is returned.
217 * a_uint j temporary evaluation variable
220 * hilo byte ordering parameter
226 * The 3 byte value of rtval[] is changed.
231 adb_3b(a_uint v
, int i
)
236 j
= v
+ (rtval
[i
+0] << 16) +
239 rtval
[i
+0] = (j
>> 16) & ((a_uint
) 0x000000FF);
240 rtval
[i
+1] = (j
>> 8) & ((a_uint
) 0x000000FF);
241 rtval
[i
+2] = (j
>> 0) & ((a_uint
) 0x000000FF);
243 j
= v
+ (rtval
[i
+0] << 0) +
246 rtval
[i
+0] = (j
>> 0) & ((a_uint
) 0x000000FF);
247 rtval
[i
+1] = (j
>> 8) & ((a_uint
) 0x000000FF);
248 rtval
[i
+2] = (j
>> 16) & ((a_uint
) 0x000000FF);
253 /*)Function a_uint adb_4b(v, i)
255 * a_uint v value to add to word
256 * int i rtval[] index
258 * The function adb_4b() adds the value of v to the
259 * four byte value contained in rtval[i], ..., rtval[i+3].
260 * The new value of rtval[i], ..., rtval[i+3] is returned.
263 * a_uint j temporary evaluation variable
266 * hilo byte ordering parameter
272 * The 4 byte value of rtval[] is changed.
277 adb_4b(a_uint v
, int i
)
282 j
= v
+ (rtval
[i
+0] << 24) +
286 rtval
[i
+0] = (j
>> 24) & ((a_uint
) 0x000000FF);
287 rtval
[i
+1] = (j
>> 16) & ((a_uint
) 0x000000FF);
288 rtval
[i
+2] = (j
>> 8) & ((a_uint
) 0x000000FF);
289 rtval
[i
+3] = (j
>> 0) & ((a_uint
) 0x000000FF);
291 j
= v
+ (rtval
[i
+0] << 0) +
295 rtval
[i
+0] = (j
>> 0) & ((a_uint
) 0x000000FF);
296 rtval
[i
+1] = (j
>> 8) & ((a_uint
) 0x000000FF);
297 rtval
[i
+2] = (j
>> 16) & ((a_uint
) 0x000000FF);
298 rtval
[i
+3] = (j
>> 24) & ((a_uint
) 0x000000FF);
303 /*)Function a_uint adb_xb(v, i)
305 * a_uint v value to add to x-bytes
306 * int i rtval[] index
308 * The function adb_xb() adds the value of v to
309 * the value contained in rtval[i] for x-bytes.
310 * The new value of rtval[i] for x-bytes is returned.
316 * int a_bytes T Line Address Bytes
319 * a_uint adb_1b() lkrloc.c
320 * a_uint adb_2b() lkrloc.c
321 * a_uint adb_3b() lkrloc.c
322 * a_uint adb_4b() lkrloc.c
325 * The x-byte value of rtval[] is changed.
330 adb_xb(a_uint v
, int i
)
337 j
= (j
& ((a_uint
) 0x00000080) ? j
| ~((a_uint
) 0x0000007F) : j
& ((a_uint
) 0x0000007F));
341 j
= (j
& ((a_uint
) 0x00008000) ? j
| ~((a_uint
) 0x00007FFF) : j
& ((a_uint
) 0x00007FFF));
345 j
= (j
& ((a_uint
) 0x00800000) ? j
| ~((a_uint
) 0x007FFFFF) : j
& ((a_uint
) 0x007FFFFF));
349 j
= (j
& ((a_uint
) 0x80000000) ? j
| ~((a_uint
) 0x7FFFFFFF) : j
& ((a_uint
) 0x7FFFFFFF));
358 /*)Function VOID prntval(fptr, v)
360 * FILE *fptr output file handle
361 * a_uint v value to output
363 * The function prntval() outputs the value v, in the
364 * currently selected radix, to the device specified
371 * int xflag current radix
374 * int fprintf() c_library
382 prntval(FILE *fptr
, a_uint v
)
391 case 2: frmt
= " %04X\n"; break;
392 case 3: frmt
= " %06X\n"; break;
393 case 4: frmt
= " %08X\n"; break;
399 case 2: frmt
= " %06o\n"; break;
400 case 3: frmt
= " %08o\n"; break;
401 case 4: frmt
= "%011o\n"; break;
407 case 2: frmt
= " %05u\n"; break;
408 case 3: frmt
= " %08u\n"; break;
409 case 4: frmt
= " %010u\n"; break;
413 fprintf(fptr
, frmt
, v
& a_mask
);