Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-sh.c -- Assemble code for the Hitachi Super-H |
5b8274e3 | 2 | Copyright (C) 1993, 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation. |
252b5132 RH |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS 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 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS 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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | /* | |
22 | Written By Steve Chamberlain | |
23 | sac@cygnus.com | |
24 | */ | |
25 | ||
26 | #include <stdio.h> | |
27 | #include "as.h" | |
28 | #include "bfd.h" | |
29 | #include "subsegs.h" | |
30 | #define DEFINE_TABLE | |
31 | #include "opcodes/sh-opc.h" | |
32 | #include <ctype.h> | |
43841e91 | 33 | #include "struc-symbol.h" |
d4845d57 JR |
34 | |
35 | #ifdef OBJ_ELF | |
36 | #include "elf/sh.h" | |
37 | #endif | |
38 | ||
252b5132 RH |
39 | const char comment_chars[] = "!"; |
40 | const char line_separator_chars[] = ";"; | |
41 | const char line_comment_chars[] = "!#"; | |
42 | ||
43 | static void s_uses PARAMS ((int)); | |
44 | ||
45 | static void sh_count_relocs PARAMS ((bfd *, segT, PTR)); | |
46 | static void sh_frob_section PARAMS ((bfd *, segT, PTR)); | |
47 | ||
252b5132 RH |
48 | void cons (); |
49 | void s_align_bytes (); | |
50 | static void s_uacons PARAMS ((int)); | |
d4845d57 JR |
51 | static sh_opcode_info *find_cooked_opcode PARAMS ((char **)); |
52 | static void assemble_ppi PARAMS ((char *, sh_opcode_info *)); | |
252b5132 RH |
53 | |
54 | int shl = 0; | |
55 | ||
56 | static void | |
57 | little (ignore) | |
43841e91 | 58 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
59 | { |
60 | shl = 1; | |
61 | target_big_endian = 0; | |
62 | } | |
63 | ||
d4845d57 JR |
64 | /* This table describes all the machine specific pseudo-ops the assembler |
65 | has to support. The fields are: | |
66 | pseudo-op name without dot | |
67 | function to call to execute this pseudo-op | |
68 | Integer arg to pass to the function | |
69 | */ | |
70 | ||
252b5132 RH |
71 | const pseudo_typeS md_pseudo_table[] = |
72 | { | |
73 | {"int", cons, 4}, | |
74 | {"word", cons, 2}, | |
75 | {"form", listing_psize, 0}, | |
76 | {"little", little, 0}, | |
77 | {"heading", listing_title, 0}, | |
78 | {"import", s_ignore, 0}, | |
79 | {"page", listing_eject, 0}, | |
80 | {"program", s_ignore, 0}, | |
81 | {"uses", s_uses, 0}, | |
82 | {"uaword", s_uacons, 2}, | |
83 | {"ualong", s_uacons, 4}, | |
84 | {0, 0, 0} | |
85 | }; | |
86 | ||
87 | /*int md_reloc_size; */ | |
88 | ||
89 | int sh_relax; /* set if -relax seen */ | |
90 | ||
91 | /* Whether -small was seen. */ | |
92 | ||
93 | int sh_small; | |
94 | ||
d4845d57 JR |
95 | /* Whether -dsp was seen. */ |
96 | ||
97 | static int sh_dsp; | |
98 | ||
99 | /* The bit mask of architectures that could | |
100 | accomodate the insns seen so far. */ | |
101 | static int valid_arch; | |
102 | ||
252b5132 RH |
103 | const char EXP_CHARS[] = "eE"; |
104 | ||
105 | /* Chars that mean this number is a floating point constant */ | |
106 | /* As in 0f12.456 */ | |
107 | /* or 0d1.2345e12 */ | |
108 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
109 | ||
110 | #define C(a,b) ENCODE_RELAX(a,b) | |
111 | ||
112 | #define JREG 14 /* Register used as a temp when relaxing */ | |
113 | #define ENCODE_RELAX(what,length) (((what) << 4) + (length)) | |
114 | #define GET_WHAT(x) ((x>>4)) | |
115 | ||
116 | /* These are the three types of relaxable instrction */ | |
117 | #define COND_JUMP 1 | |
118 | #define COND_JUMP_DELAY 2 | |
119 | #define UNCOND_JUMP 3 | |
120 | #define END 4 | |
121 | ||
122 | #define UNDEF_DISP 0 | |
123 | #define COND8 1 | |
124 | #define COND12 2 | |
125 | #define COND32 3 | |
126 | #define UNCOND12 1 | |
127 | #define UNCOND32 2 | |
128 | #define UNDEF_WORD_DISP 4 | |
129 | ||
130 | #define UNCOND12 1 | |
131 | #define UNCOND32 2 | |
132 | ||
133 | /* Branch displacements are from the address of the branch plus | |
134 | four, thus all minimum and maximum values have 4 added to them. */ | |
135 | #define COND8_F 258 | |
136 | #define COND8_M -252 | |
137 | #define COND8_LENGTH 2 | |
138 | ||
139 | /* There is one extra instruction before the branch, so we must add | |
140 | two more bytes to account for it. */ | |
141 | #define COND12_F 4100 | |
142 | #define COND12_M -4090 | |
143 | #define COND12_LENGTH 6 | |
144 | ||
145 | #define COND12_DELAY_LENGTH 4 | |
146 | ||
147 | /* ??? The minimum and maximum values are wrong, but this does not matter | |
148 | since this relocation type is not supported yet. */ | |
149 | #define COND32_F (1<<30) | |
150 | #define COND32_M -(1<<30) | |
151 | #define COND32_LENGTH 14 | |
152 | ||
153 | #define UNCOND12_F 4098 | |
154 | #define UNCOND12_M -4092 | |
155 | #define UNCOND12_LENGTH 2 | |
156 | ||
157 | /* ??? The minimum and maximum values are wrong, but this does not matter | |
158 | since this relocation type is not supported yet. */ | |
159 | #define UNCOND32_F (1<<30) | |
160 | #define UNCOND32_M -(1<<30) | |
161 | #define UNCOND32_LENGTH 14 | |
162 | ||
43841e91 NC |
163 | #define EMPTY { 0, 0, 0, 0 } |
164 | ||
252b5132 | 165 | const relax_typeS md_relax_table[C (END, 0)] = { |
43841e91 NC |
166 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
167 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, | |
252b5132 | 168 | |
43841e91 | 169 | EMPTY, |
252b5132 RH |
170 | /* C (COND_JUMP, COND8) */ |
171 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) }, | |
172 | /* C (COND_JUMP, COND12) */ | |
173 | { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), }, | |
174 | /* C (COND_JUMP, COND32) */ | |
175 | { COND32_F, COND32_M, COND32_LENGTH, 0, }, | |
43841e91 NC |
176 | EMPTY, EMPTY, EMPTY, EMPTY, |
177 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, | |
252b5132 | 178 | |
43841e91 | 179 | EMPTY, |
252b5132 RH |
180 | /* C (COND_JUMP_DELAY, COND8) */ |
181 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP_DELAY, COND12) }, | |
182 | /* C (COND_JUMP_DELAY, COND12) */ | |
183 | { COND12_F, COND12_M, COND12_DELAY_LENGTH, C (COND_JUMP_DELAY, COND32), }, | |
184 | /* C (COND_JUMP_DELAY, COND32) */ | |
185 | { COND32_F, COND32_M, COND32_LENGTH, 0, }, | |
43841e91 NC |
186 | EMPTY, EMPTY, EMPTY, EMPTY, |
187 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, | |
252b5132 | 188 | |
43841e91 | 189 | EMPTY, |
252b5132 RH |
190 | /* C (UNCOND_JUMP, UNCOND12) */ |
191 | { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), }, | |
192 | /* C (UNCOND_JUMP, UNCOND32) */ | |
193 | { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, }, | |
43841e91 NC |
194 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
195 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, | |
252b5132 RH |
196 | }; |
197 | ||
43841e91 NC |
198 | #undef EMPTY |
199 | ||
252b5132 RH |
200 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics */ |
201 | ||
202 | /* | |
203 | This function is called once, at assembler startup time. This should | |
204 | set up all the tables, etc that the MD part of the assembler needs | |
205 | */ | |
206 | ||
207 | void | |
208 | md_begin () | |
209 | { | |
210 | sh_opcode_info *opcode; | |
211 | char *prev_name = ""; | |
d4845d57 | 212 | int target_arch; |
252b5132 | 213 | |
056350c6 NC |
214 | #ifdef TE_PE |
215 | /* The WinCE OS only supports little endian executables. */ | |
216 | target_big_endian = 0; | |
217 | #else | |
252b5132 RH |
218 | if (! shl) |
219 | target_big_endian = 1; | |
056350c6 | 220 | #endif |
252b5132 | 221 | |
d4845d57 JR |
222 | target_arch = arch_sh1_up & ~(sh_dsp ? arch_sh3e_up : arch_sh_dsp_up); |
223 | valid_arch = target_arch; | |
224 | ||
252b5132 RH |
225 | opcode_hash_control = hash_new (); |
226 | ||
227 | /* Insert unique names into hash table */ | |
228 | for (opcode = sh_table; opcode->name; opcode++) | |
229 | { | |
a37c8f88 | 230 | if (strcmp (prev_name, opcode->name)) |
252b5132 | 231 | { |
a37c8f88 JR |
232 | if (! (opcode->arch & target_arch)) |
233 | continue; | |
252b5132 RH |
234 | prev_name = opcode->name; |
235 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode); | |
236 | } | |
237 | else | |
238 | { | |
239 | /* Make all the opcodes with the same name point to the same | |
240 | string */ | |
241 | opcode->name = prev_name; | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
246 | static int reg_m; | |
247 | static int reg_n; | |
d4845d57 JR |
248 | static int reg_x, reg_y; |
249 | static int reg_efg; | |
252b5132 RH |
250 | static int reg_b; |
251 | ||
252b5132 RH |
252 | typedef struct |
253 | { | |
254 | sh_arg_type type; | |
255 | int reg; | |
015551fc | 256 | expressionS immediate; |
252b5132 | 257 | } |
252b5132 RH |
258 | sh_operand_info; |
259 | ||
dead1419 JR |
260 | #define IDENT_CHAR(c) (isalnum (c) || (c) == '_') |
261 | ||
252b5132 RH |
262 | /* try and parse a reg name, returns number of chars consumed */ |
263 | static int | |
264 | parse_reg (src, mode, reg) | |
265 | char *src; | |
266 | int *mode; | |
267 | int *reg; | |
268 | { | |
dead1419 | 269 | /* We use ! IDENT_CHAR for the next character after the register name, to |
252b5132 | 270 | make sure that we won't accidentally recognize a symbol name such as |
dead1419 | 271 | 'sram' or sr_ram as being a reference to the register 'sr'. */ |
252b5132 RH |
272 | |
273 | if (src[0] == 'r') | |
274 | { | |
d4845d57 JR |
275 | if (src[1] == '1') |
276 | { | |
277 | if (src[2] >= '0' && src[2] <= '5' | |
dead1419 | 278 | && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
279 | { |
280 | *mode = A_REG_N; | |
281 | *reg = 10 + src[2] - '0'; | |
282 | return 3; | |
283 | } | |
284 | } | |
285 | if (src[1] >= '0' && src[1] <= '9' | |
dead1419 | 286 | && ! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
287 | { |
288 | *mode = A_REG_N; | |
289 | *reg = (src[1] - '0'); | |
290 | return 2; | |
291 | } | |
dead1419 JR |
292 | if (src[1] >= '0' && src[1] <= '7' && strncmp (&src[2], "_bank", 5) == 0 |
293 | && ! IDENT_CHAR ((unsigned char) src[7])) | |
294 | { | |
295 | *mode = A_REG_B; | |
296 | *reg = (src[1] - '0'); | |
297 | return 7; | |
298 | } | |
d4845d57 | 299 | |
dead1419 | 300 | if (src[1] == 'e' && ! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
301 | { |
302 | *mode = A_RE; | |
303 | return 2; | |
304 | } | |
dead1419 | 305 | if (src[1] == 's' && ! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
306 | { |
307 | *mode = A_RS; | |
308 | return 2; | |
309 | } | |
252b5132 RH |
310 | } |
311 | ||
d4845d57 | 312 | if (src[0] == 'a') |
252b5132 | 313 | { |
d4845d57 JR |
314 | if (src[1] == '0') |
315 | { | |
dead1419 | 316 | if (! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
317 | { |
318 | *mode = DSP_REG_N; | |
319 | *reg = A_A0_NUM; | |
320 | return 2; | |
321 | } | |
dead1419 | 322 | if (src[2] == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
323 | { |
324 | *mode = DSP_REG_N; | |
325 | *reg = A_A0G_NUM; | |
326 | return 3; | |
327 | } | |
328 | } | |
252b5132 RH |
329 | if (src[1] == '1') |
330 | { | |
dead1419 | 331 | if (! IDENT_CHAR ((unsigned char) src[2])) |
252b5132 | 332 | { |
d4845d57 JR |
333 | *mode = DSP_REG_N; |
334 | *reg = A_A1_NUM; | |
335 | return 2; | |
336 | } | |
dead1419 | 337 | if (src[2] == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
338 | { |
339 | *mode = DSP_REG_N; | |
340 | *reg = A_A1G_NUM; | |
252b5132 RH |
341 | return 3; |
342 | } | |
343 | } | |
d4845d57 JR |
344 | |
345 | if (src[1] == 'x' && src[2] >= '0' && src[2] <= '1' | |
dead1419 | 346 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
347 | { |
348 | *mode = A_REG_N; | |
d4845d57 JR |
349 | *reg = 4 + (src[1] - '0'); |
350 | return 3; | |
351 | } | |
352 | if (src[1] == 'y' && src[2] >= '0' && src[2] <= '1' | |
dead1419 | 353 | && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
354 | { |
355 | *mode = A_REG_N; | |
356 | *reg = 6 + (src[1] - '0'); | |
357 | return 3; | |
358 | } | |
359 | if (src[1] == 's' && src[2] >= '0' && src[2] <= '3' | |
dead1419 | 360 | && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
361 | { |
362 | int n = src[1] - '0'; | |
363 | ||
364 | *mode = A_REG_N; | |
365 | *reg = n | ((~n & 2) << 1); | |
366 | return 3; | |
367 | } | |
368 | } | |
369 | ||
dead1419 | 370 | if (src[0] == 'i' && src[1] && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
371 | { |
372 | if (src[1] == 's') | |
373 | { | |
374 | *mode = A_REG_N; | |
375 | *reg = 8; | |
252b5132 RH |
376 | return 2; |
377 | } | |
d4845d57 JR |
378 | if (src[1] == 'x') |
379 | { | |
380 | *mode = A_REG_N; | |
381 | *reg = 8; | |
382 | return 2; | |
383 | } | |
384 | if (src[1] == 'y') | |
385 | { | |
386 | *mode = A_REG_N; | |
387 | *reg = 9; | |
388 | return 2; | |
389 | } | |
390 | } | |
391 | ||
392 | if (src[0] == 'x' && src[1] >= '0' && src[1] <= '1' | |
dead1419 | 393 | && ! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
394 | { |
395 | *mode = DSP_REG_N; | |
396 | *reg = A_X0_NUM + src[1] - '0'; | |
397 | return 2; | |
398 | } | |
399 | ||
400 | if (src[0] == 'y' && src[1] >= '0' && src[1] <= '1' | |
dead1419 | 401 | && ! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
402 | { |
403 | *mode = DSP_REG_N; | |
404 | *reg = A_Y0_NUM + src[1] - '0'; | |
405 | return 2; | |
406 | } | |
407 | ||
408 | if (src[0] == 'm' && src[1] >= '0' && src[1] <= '1' | |
dead1419 | 409 | && ! IDENT_CHAR ((unsigned char) src[2])) |
d4845d57 JR |
410 | { |
411 | *mode = DSP_REG_N; | |
412 | *reg = src[1] == '0' ? A_M0_NUM : A_M1_NUM; | |
413 | return 2; | |
252b5132 RH |
414 | } |
415 | ||
416 | if (src[0] == 's' | |
417 | && src[1] == 's' | |
dead1419 | 418 | && src[2] == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
419 | { |
420 | *mode = A_SSR; | |
421 | return 3; | |
422 | } | |
423 | ||
424 | if (src[0] == 's' && src[1] == 'p' && src[2] == 'c' | |
dead1419 | 425 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
426 | { |
427 | *mode = A_SPC; | |
428 | return 3; | |
429 | } | |
430 | ||
431 | if (src[0] == 's' && src[1] == 'g' && src[2] == 'r' | |
dead1419 | 432 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
433 | { |
434 | *mode = A_SGR; | |
435 | return 3; | |
436 | } | |
437 | ||
d4845d57 | 438 | if (src[0] == 'd' && src[1] == 's' && src[2] == 'r' |
dead1419 | 439 | && ! IDENT_CHAR ((unsigned char) src[3])) |
d4845d57 JR |
440 | { |
441 | *mode = A_DSR; | |
442 | return 3; | |
443 | } | |
444 | ||
252b5132 | 445 | if (src[0] == 'd' && src[1] == 'b' && src[2] == 'r' |
dead1419 | 446 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
447 | { |
448 | *mode = A_DBR; | |
449 | return 3; | |
450 | } | |
451 | ||
dead1419 | 452 | if (src[0] == 's' && src[1] == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) |
252b5132 RH |
453 | { |
454 | *mode = A_SR; | |
455 | return 2; | |
456 | } | |
457 | ||
dead1419 | 458 | if (src[0] == 's' && src[1] == 'p' && ! IDENT_CHAR ((unsigned char) src[2])) |
252b5132 RH |
459 | { |
460 | *mode = A_REG_N; | |
461 | *reg = 15; | |
462 | return 2; | |
463 | } | |
464 | ||
dead1419 | 465 | if (src[0] == 'p' && src[1] == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) |
252b5132 RH |
466 | { |
467 | *mode = A_PR; | |
468 | return 2; | |
469 | } | |
dead1419 | 470 | if (src[0] == 'p' && src[1] == 'c' && ! IDENT_CHAR ((unsigned char) src[2])) |
252b5132 | 471 | { |
015551fc JR |
472 | /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0' |
473 | and use an uninitialized immediate. */ | |
474 | *mode = A_PC; | |
252b5132 RH |
475 | return 2; |
476 | } | |
477 | if (src[0] == 'g' && src[1] == 'b' && src[2] == 'r' | |
dead1419 | 478 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
479 | { |
480 | *mode = A_GBR; | |
481 | return 3; | |
482 | } | |
483 | if (src[0] == 'v' && src[1] == 'b' && src[2] == 'r' | |
dead1419 | 484 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
485 | { |
486 | *mode = A_VBR; | |
487 | return 3; | |
488 | } | |
489 | ||
490 | if (src[0] == 'm' && src[1] == 'a' && src[2] == 'c' | |
dead1419 | 491 | && ! IDENT_CHAR ((unsigned char) src[4])) |
252b5132 RH |
492 | { |
493 | if (src[3] == 'l') | |
494 | { | |
495 | *mode = A_MACL; | |
496 | return 4; | |
497 | } | |
498 | if (src[3] == 'h') | |
499 | { | |
500 | *mode = A_MACH; | |
501 | return 4; | |
502 | } | |
503 | } | |
d4845d57 | 504 | if (src[0] == 'm' && src[1] == 'o' && src[2] == 'd' |
dead1419 | 505 | && ! IDENT_CHAR ((unsigned char) src[4])) |
d4845d57 JR |
506 | { |
507 | *mode = A_MOD; | |
508 | return 3; | |
509 | } | |
252b5132 RH |
510 | if (src[0] == 'f' && src[1] == 'r') |
511 | { | |
512 | if (src[2] == '1') | |
513 | { | |
514 | if (src[3] >= '0' && src[3] <= '5' | |
dead1419 | 515 | && ! IDENT_CHAR ((unsigned char) src[4])) |
252b5132 RH |
516 | { |
517 | *mode = F_REG_N; | |
518 | *reg = 10 + src[3] - '0'; | |
519 | return 4; | |
520 | } | |
521 | } | |
522 | if (src[2] >= '0' && src[2] <= '9' | |
dead1419 | 523 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
524 | { |
525 | *mode = F_REG_N; | |
526 | *reg = (src[2] - '0'); | |
527 | return 3; | |
528 | } | |
529 | } | |
530 | if (src[0] == 'd' && src[1] == 'r') | |
531 | { | |
532 | if (src[2] == '1') | |
533 | { | |
534 | if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1) | |
dead1419 | 535 | && ! IDENT_CHAR ((unsigned char) src[4])) |
252b5132 RH |
536 | { |
537 | *mode = D_REG_N; | |
538 | *reg = 10 + src[3] - '0'; | |
539 | return 4; | |
540 | } | |
541 | } | |
542 | if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1) | |
dead1419 | 543 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
544 | { |
545 | *mode = D_REG_N; | |
546 | *reg = (src[2] - '0'); | |
547 | return 3; | |
548 | } | |
549 | } | |
550 | if (src[0] == 'x' && src[1] == 'd') | |
551 | { | |
552 | if (src[2] == '1') | |
553 | { | |
554 | if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1) | |
dead1419 | 555 | && ! IDENT_CHAR ((unsigned char) src[4])) |
252b5132 RH |
556 | { |
557 | *mode = X_REG_N; | |
558 | *reg = 11 + src[3] - '0'; | |
559 | return 4; | |
560 | } | |
561 | } | |
562 | if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1) | |
dead1419 | 563 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
564 | { |
565 | *mode = X_REG_N; | |
566 | *reg = (src[2] - '0') + 1; | |
567 | return 3; | |
568 | } | |
569 | } | |
570 | if (src[0] == 'f' && src[1] == 'v') | |
571 | { | |
dead1419 | 572 | if (src[2] == '1'&& src[3] == '2' && ! IDENT_CHAR ((unsigned char) src[4])) |
252b5132 RH |
573 | { |
574 | *mode = V_REG_N; | |
575 | *reg = 12; | |
576 | return 4; | |
577 | } | |
578 | if ((src[2] == '0' || src[2] == '4' || src[2] == '8') | |
dead1419 | 579 | && ! IDENT_CHAR ((unsigned char) src[3])) |
252b5132 RH |
580 | { |
581 | *mode = V_REG_N; | |
582 | *reg = (src[2] - '0'); | |
583 | return 3; | |
584 | } | |
585 | } | |
586 | if (src[0] == 'f' && src[1] == 'p' && src[2] == 'u' && src[3] == 'l' | |
dead1419 | 587 | && ! IDENT_CHAR ((unsigned char) src[4])) |
252b5132 RH |
588 | { |
589 | *mode = FPUL_N; | |
590 | return 4; | |
591 | } | |
592 | ||
593 | if (src[0] == 'f' && src[1] == 'p' && src[2] == 's' && src[3] == 'c' | |
dead1419 | 594 | && src[4] == 'r' && ! IDENT_CHAR ((unsigned char) src[5])) |
252b5132 RH |
595 | { |
596 | *mode = FPSCR_N; | |
597 | return 5; | |
598 | } | |
599 | ||
600 | if (src[0] == 'x' && src[1] == 'm' && src[2] == 't' && src[3] == 'r' | |
dead1419 | 601 | && src[4] == 'x' && ! IDENT_CHAR ((unsigned char) src[5])) |
252b5132 RH |
602 | { |
603 | *mode = XMTRX_M4; | |
604 | return 5; | |
605 | } | |
606 | ||
607 | return 0; | |
608 | } | |
609 | ||
610 | static symbolS *dot() | |
611 | { | |
612 | const char *fake; | |
613 | ||
614 | /* JF: '.' is pseudo symbol with value of current location | |
615 | in current segment. */ | |
616 | fake = FAKE_LABEL_NAME; | |
617 | return symbol_new (fake, | |
618 | now_seg, | |
619 | (valueT) frag_now_fix (), | |
620 | frag_now); | |
621 | ||
622 | } | |
623 | ||
624 | ||
625 | static | |
626 | char * | |
015551fc | 627 | parse_exp (s, op) |
252b5132 | 628 | char *s; |
015551fc | 629 | sh_operand_info *op; |
252b5132 RH |
630 | { |
631 | char *save; | |
632 | char *new; | |
633 | ||
634 | save = input_line_pointer; | |
635 | input_line_pointer = s; | |
015551fc JR |
636 | expression (&op->immediate); |
637 | if (op->immediate.X_op == O_absent) | |
252b5132 RH |
638 | as_bad (_("missing operand")); |
639 | new = input_line_pointer; | |
640 | input_line_pointer = save; | |
641 | return new; | |
642 | } | |
643 | ||
644 | ||
645 | /* The many forms of operand: | |
646 | ||
647 | Rn Register direct | |
648 | @Rn Register indirect | |
649 | @Rn+ Autoincrement | |
650 | @-Rn Autodecrement | |
651 | @(disp:4,Rn) | |
652 | @(disp:8,GBR) | |
653 | @(disp:8,PC) | |
654 | ||
655 | @(R0,Rn) | |
656 | @(R0,GBR) | |
657 | ||
658 | disp:8 | |
659 | disp:12 | |
660 | #imm8 | |
661 | pr, gbr, vbr, macl, mach | |
662 | ||
663 | */ | |
664 | ||
665 | static | |
666 | char * | |
667 | parse_at (src, op) | |
668 | char *src; | |
669 | sh_operand_info *op; | |
670 | { | |
671 | int len; | |
672 | int mode; | |
673 | src++; | |
674 | if (src[0] == '-') | |
675 | { | |
676 | /* Must be predecrement */ | |
677 | src++; | |
678 | ||
679 | len = parse_reg (src, &mode, &(op->reg)); | |
680 | if (mode != A_REG_N) | |
681 | as_bad (_("illegal register after @-")); | |
682 | ||
683 | op->type = A_DEC_N; | |
684 | src += len; | |
685 | } | |
686 | else if (src[0] == '(') | |
687 | { | |
688 | /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or | |
689 | @(r0, rn) */ | |
690 | src++; | |
691 | len = parse_reg (src, &mode, &(op->reg)); | |
692 | if (len && mode == A_REG_N) | |
693 | { | |
694 | src += len; | |
695 | if (op->reg != 0) | |
696 | { | |
697 | as_bad (_("must be @(r0,...)")); | |
698 | } | |
699 | if (src[0] == ',') | |
700 | src++; | |
701 | /* Now can be rn or gbr */ | |
702 | len = parse_reg (src, &mode, &(op->reg)); | |
703 | if (mode == A_GBR) | |
704 | { | |
705 | op->type = A_R0_GBR; | |
706 | } | |
707 | else if (mode == A_REG_N) | |
708 | { | |
709 | op->type = A_IND_R0_REG_N; | |
710 | } | |
711 | else | |
712 | { | |
713 | as_bad (_("syntax error in @(r0,...)")); | |
714 | } | |
715 | } | |
716 | else | |
717 | { | |
718 | /* Must be an @(disp,.. thing) */ | |
015551fc | 719 | src = parse_exp (src, op); |
252b5132 RH |
720 | if (src[0] == ',') |
721 | src++; | |
722 | /* Now can be rn, gbr or pc */ | |
723 | len = parse_reg (src, &mode, &op->reg); | |
724 | if (len) | |
725 | { | |
726 | if (mode == A_REG_N) | |
727 | { | |
728 | op->type = A_DISP_REG_N; | |
729 | } | |
730 | else if (mode == A_GBR) | |
731 | { | |
732 | op->type = A_DISP_GBR; | |
733 | } | |
015551fc | 734 | else if (mode == A_PC) |
252b5132 RH |
735 | { |
736 | /* Turn a plain @(4,pc) into @(.+4,pc) */ | |
015551fc JR |
737 | if (op->immediate.X_op == O_constant) { |
738 | op->immediate.X_add_symbol = dot(); | |
739 | op->immediate.X_op = O_symbol; | |
252b5132 RH |
740 | } |
741 | op->type = A_DISP_PC; | |
742 | } | |
743 | else | |
744 | { | |
745 | as_bad (_("syntax error in @(disp,[Rn, gbr, pc])")); | |
746 | } | |
747 | } | |
748 | else | |
749 | { | |
750 | as_bad (_("syntax error in @(disp,[Rn, gbr, pc])")); | |
751 | } | |
752 | } | |
753 | src += len; | |
754 | if (src[0] != ')') | |
755 | as_bad (_("expecting )")); | |
756 | else | |
757 | src++; | |
758 | } | |
759 | else | |
760 | { | |
761 | src += parse_reg (src, &mode, &(op->reg)); | |
762 | if (mode != A_REG_N) | |
763 | { | |
764 | as_bad (_("illegal register after @")); | |
765 | } | |
766 | if (src[0] == '+') | |
767 | { | |
252b5132 | 768 | src++; |
d4845d57 JR |
769 | if ((src[0] == 'r' && src[1] == '8') |
770 | || (src[0] == 'i' && (src[1] == 'x' || src[1] == 's'))) | |
771 | { | |
772 | src += 2; | |
773 | op->type = A_PMOD_N; | |
774 | } | |
775 | if ((src[0] == 'r' && src[1] == '9') | |
776 | || (src[0] == 'i' && src[1] == 'y')) | |
777 | { | |
778 | src += 2; | |
779 | op->type = A_PMODY_N; | |
780 | } | |
781 | else | |
782 | op->type = A_INC_N; | |
252b5132 RH |
783 | } |
784 | else | |
785 | { | |
786 | op->type = A_IND_N; | |
787 | } | |
788 | } | |
789 | return src; | |
790 | } | |
791 | ||
792 | static void | |
793 | get_operand (ptr, op) | |
794 | char **ptr; | |
795 | sh_operand_info *op; | |
796 | { | |
797 | char *src = *ptr; | |
798 | int mode = -1; | |
799 | unsigned int len; | |
800 | ||
801 | if (src[0] == '#') | |
802 | { | |
803 | src++; | |
015551fc | 804 | *ptr = parse_exp (src, op); |
252b5132 RH |
805 | op->type = A_IMM; |
806 | return; | |
807 | } | |
808 | ||
809 | else if (src[0] == '@') | |
810 | { | |
811 | *ptr = parse_at (src, op); | |
812 | return; | |
813 | } | |
814 | len = parse_reg (src, &mode, &(op->reg)); | |
815 | if (len) | |
816 | { | |
817 | *ptr = src + len; | |
818 | op->type = mode; | |
819 | return; | |
820 | } | |
821 | else | |
822 | { | |
823 | /* Not a reg, the only thing left is a displacement */ | |
015551fc | 824 | *ptr = parse_exp (src, op); |
252b5132 RH |
825 | op->type = A_DISP_PC; |
826 | return; | |
827 | } | |
828 | } | |
829 | ||
830 | static | |
831 | char * | |
832 | get_operands (info, args, operand) | |
833 | sh_opcode_info *info; | |
834 | char *args; | |
835 | sh_operand_info *operand; | |
252b5132 RH |
836 | { |
837 | char *ptr = args; | |
838 | if (info->arg[0]) | |
839 | { | |
d4845d57 JR |
840 | /* The pre-processor will eliminate whitespace in front of '@' |
841 | after the first argument; we may be called multiple times | |
842 | from assemble_ppi, so don't insist on finding whitespace here. */ | |
843 | if (*ptr == ' ') | |
844 | ptr++; | |
252b5132 RH |
845 | |
846 | get_operand (&ptr, operand + 0); | |
847 | if (info->arg[1]) | |
848 | { | |
849 | if (*ptr == ',') | |
850 | { | |
851 | ptr++; | |
852 | } | |
853 | get_operand (&ptr, operand + 1); | |
52ccafd0 JR |
854 | /* ??? Hack: psha/pshl have a varying operand number depending on |
855 | the type of the first operand. We handle this by having the | |
856 | three-operand version first and reducing the number of operands | |
857 | parsed to two if we see that the first operand is an immediate. | |
858 | This works because no insn with three operands has an immediate | |
859 | as first operand. */ | |
860 | if (info->arg[2] && operand[0].type != A_IMM) | |
252b5132 RH |
861 | { |
862 | if (*ptr == ',') | |
863 | { | |
864 | ptr++; | |
865 | } | |
866 | get_operand (&ptr, operand + 2); | |
867 | } | |
868 | else | |
869 | { | |
870 | operand[2].type = 0; | |
871 | } | |
872 | } | |
873 | else | |
874 | { | |
875 | operand[1].type = 0; | |
876 | operand[2].type = 0; | |
877 | } | |
878 | } | |
879 | else | |
880 | { | |
881 | operand[0].type = 0; | |
882 | operand[1].type = 0; | |
883 | operand[2].type = 0; | |
884 | } | |
885 | return ptr; | |
886 | } | |
887 | ||
888 | /* Passed a pointer to a list of opcodes which use different | |
889 | addressing modes, return the opcode which matches the opcodes | |
890 | provided | |
891 | */ | |
892 | ||
893 | static | |
894 | sh_opcode_info * | |
895 | get_specific (opcode, operands) | |
896 | sh_opcode_info *opcode; | |
897 | sh_operand_info *operands; | |
898 | { | |
899 | sh_opcode_info *this_try = opcode; | |
900 | char *name = opcode->name; | |
901 | int n = 0; | |
902 | while (opcode->name) | |
903 | { | |
904 | this_try = opcode++; | |
905 | if (this_try->name != name) | |
906 | { | |
907 | /* We've looked so far down the table that we've run out of | |
908 | opcodes with the same name */ | |
909 | return 0; | |
910 | } | |
911 | /* look at both operands needed by the opcodes and provided by | |
912 | the user - since an arg test will often fail on the same arg | |
913 | again and again, we'll try and test the last failing arg the | |
914 | first on each opcode try */ | |
915 | ||
916 | for (n = 0; this_try->arg[n]; n++) | |
917 | { | |
918 | sh_operand_info *user = operands + n; | |
919 | sh_arg_type arg = this_try->arg[n]; | |
920 | switch (arg) | |
921 | { | |
922 | case A_IMM: | |
923 | case A_BDISP12: | |
924 | case A_BDISP8: | |
925 | case A_DISP_GBR: | |
926 | case A_DISP_PC: | |
927 | case A_MACH: | |
928 | case A_PR: | |
929 | case A_MACL: | |
930 | if (user->type != arg) | |
931 | goto fail; | |
932 | break; | |
933 | case A_R0: | |
934 | /* opcode needs r0 */ | |
935 | if (user->type != A_REG_N || user->reg != 0) | |
936 | goto fail; | |
937 | break; | |
938 | case A_R0_GBR: | |
939 | if (user->type != A_R0_GBR || user->reg != 0) | |
940 | goto fail; | |
941 | break; | |
942 | case F_FR0: | |
943 | if (user->type != F_REG_N || user->reg != 0) | |
944 | goto fail; | |
945 | break; | |
946 | ||
947 | case A_REG_N: | |
948 | case A_INC_N: | |
949 | case A_DEC_N: | |
950 | case A_IND_N: | |
951 | case A_IND_R0_REG_N: | |
952 | case A_DISP_REG_N: | |
953 | case F_REG_N: | |
954 | case D_REG_N: | |
955 | case X_REG_N: | |
956 | case V_REG_N: | |
957 | case FPUL_N: | |
958 | case FPSCR_N: | |
d4845d57 JR |
959 | case A_PMOD_N: |
960 | case A_PMODY_N: | |
961 | case DSP_REG_N: | |
252b5132 RH |
962 | /* Opcode needs rn */ |
963 | if (user->type != arg) | |
964 | goto fail; | |
965 | reg_n = user->reg; | |
966 | break; | |
252b5132 RH |
967 | case DX_REG_N: |
968 | if (user->type != D_REG_N && user->type != X_REG_N) | |
969 | goto fail; | |
970 | reg_n = user->reg; | |
971 | break; | |
972 | case A_GBR: | |
973 | case A_SR: | |
974 | case A_VBR: | |
d4845d57 JR |
975 | case A_DSR: |
976 | case A_MOD: | |
977 | case A_RE: | |
978 | case A_RS: | |
252b5132 RH |
979 | case A_SSR: |
980 | case A_SPC: | |
981 | case A_SGR: | |
982 | case A_DBR: | |
983 | if (user->type != arg) | |
984 | goto fail; | |
985 | break; | |
986 | ||
987 | case A_REG_B: | |
988 | if (user->type != arg) | |
989 | goto fail; | |
990 | reg_b = user->reg; | |
991 | break; | |
992 | ||
993 | case A_REG_M: | |
994 | case A_INC_M: | |
995 | case A_DEC_M: | |
996 | case A_IND_M: | |
997 | case A_IND_R0_REG_M: | |
998 | case A_DISP_REG_M: | |
d4845d57 | 999 | case DSP_REG_M: |
252b5132 RH |
1000 | /* Opcode needs rn */ |
1001 | if (user->type != arg - A_REG_M + A_REG_N) | |
1002 | goto fail; | |
1003 | reg_m = user->reg; | |
1004 | break; | |
1005 | ||
d4845d57 JR |
1006 | case DSP_REG_X: |
1007 | if (user->type != DSP_REG_N) | |
1008 | goto fail; | |
1009 | switch (user->reg) | |
1010 | { | |
1011 | case A_X0_NUM: | |
1012 | reg_x = 0; | |
1013 | break; | |
1014 | case A_X1_NUM: | |
1015 | reg_x = 1; | |
1016 | break; | |
1017 | case A_A0_NUM: | |
1018 | reg_x = 2; | |
1019 | break; | |
1020 | case A_A1_NUM: | |
1021 | reg_x = 3; | |
1022 | break; | |
1023 | default: | |
1024 | goto fail; | |
1025 | } | |
1026 | break; | |
1027 | ||
1028 | case DSP_REG_Y: | |
1029 | if (user->type != DSP_REG_N) | |
1030 | goto fail; | |
1031 | switch (user->reg) | |
1032 | { | |
1033 | case A_Y0_NUM: | |
1034 | reg_y = 0; | |
1035 | break; | |
1036 | case A_Y1_NUM: | |
1037 | reg_y = 1; | |
1038 | break; | |
1039 | case A_M0_NUM: | |
1040 | reg_y = 2; | |
1041 | break; | |
1042 | case A_M1_NUM: | |
1043 | reg_y = 3; | |
1044 | break; | |
1045 | default: | |
1046 | goto fail; | |
1047 | } | |
1048 | break; | |
1049 | ||
1050 | case DSP_REG_E: | |
1051 | if (user->type != DSP_REG_N) | |
1052 | goto fail; | |
1053 | switch (user->reg) | |
1054 | { | |
1055 | case A_X0_NUM: | |
1056 | reg_efg = 0 << 10; | |
1057 | break; | |
1058 | case A_X1_NUM: | |
1059 | reg_efg = 1 << 10; | |
1060 | break; | |
1061 | case A_Y0_NUM: | |
1062 | reg_efg = 2 << 10; | |
1063 | break; | |
1064 | case A_A1_NUM: | |
1065 | reg_efg = 3 << 10; | |
1066 | break; | |
1067 | default: | |
1068 | goto fail; | |
1069 | } | |
1070 | break; | |
1071 | ||
1072 | case DSP_REG_F: | |
1073 | if (user->type != DSP_REG_N) | |
1074 | goto fail; | |
1075 | switch (user->reg) | |
1076 | { | |
1077 | case A_Y0_NUM: | |
1078 | reg_efg |= 0 << 8; | |
1079 | break; | |
1080 | case A_Y1_NUM: | |
1081 | reg_efg |= 1 << 8; | |
1082 | break; | |
1083 | case A_X0_NUM: | |
1084 | reg_efg |= 2 << 8; | |
1085 | break; | |
1086 | case A_A1_NUM: | |
1087 | reg_efg |= 3 << 8; | |
1088 | break; | |
1089 | default: | |
1090 | goto fail; | |
1091 | } | |
1092 | break; | |
1093 | ||
1094 | case DSP_REG_G: | |
1095 | if (user->type != DSP_REG_N) | |
1096 | goto fail; | |
1097 | switch (user->reg) | |
1098 | { | |
1099 | case A_M0_NUM: | |
1100 | reg_efg |= 0 << 2; | |
1101 | break; | |
1102 | case A_M1_NUM: | |
1103 | reg_efg |= 1 << 2; | |
1104 | break; | |
1105 | case A_A0_NUM: | |
1106 | reg_efg |= 2 << 2; | |
1107 | break; | |
1108 | case A_A1_NUM: | |
1109 | reg_efg |= 3 << 2; | |
1110 | break; | |
1111 | default: | |
1112 | goto fail; | |
1113 | } | |
1114 | break; | |
1115 | ||
1116 | case A_A0: | |
1117 | if (user->type != DSP_REG_N || user->reg != A_A0_NUM) | |
1118 | goto fail; | |
1119 | break; | |
1120 | case A_X0: | |
1121 | if (user->type != DSP_REG_N || user->reg != A_X0_NUM) | |
1122 | goto fail; | |
1123 | break; | |
1124 | case A_X1: | |
1125 | if (user->type != DSP_REG_N || user->reg != A_X1_NUM) | |
1126 | goto fail; | |
1127 | break; | |
1128 | case A_Y0: | |
1129 | if (user->type != DSP_REG_N || user->reg != A_Y0_NUM) | |
1130 | goto fail; | |
1131 | break; | |
1132 | case A_Y1: | |
1133 | if (user->type != DSP_REG_N || user->reg != A_Y1_NUM) | |
1134 | goto fail; | |
1135 | break; | |
1136 | ||
252b5132 RH |
1137 | case F_REG_M: |
1138 | case D_REG_M: | |
1139 | case X_REG_M: | |
1140 | case V_REG_M: | |
1141 | case FPUL_M: | |
1142 | case FPSCR_M: | |
1143 | /* Opcode needs rn */ | |
1144 | if (user->type != arg - F_REG_M + F_REG_N) | |
1145 | goto fail; | |
1146 | reg_m = user->reg; | |
1147 | break; | |
1148 | case DX_REG_M: | |
1149 | if (user->type != D_REG_N && user->type != X_REG_N) | |
1150 | goto fail; | |
1151 | reg_m = user->reg; | |
1152 | break; | |
1153 | case XMTRX_M4: | |
1154 | if (user->type != XMTRX_M4) | |
1155 | goto fail; | |
1156 | reg_m = 4; | |
1157 | break; | |
1158 | ||
1159 | default: | |
1160 | printf (_("unhandled %d\n"), arg); | |
1161 | goto fail; | |
1162 | } | |
1163 | } | |
a37c8f88 JR |
1164 | if ( !(valid_arch & this_try->arch)) |
1165 | goto fail; | |
d4845d57 | 1166 | valid_arch &= this_try->arch; |
252b5132 RH |
1167 | return this_try; |
1168 | fail:; | |
1169 | } | |
1170 | ||
1171 | return 0; | |
1172 | } | |
1173 | ||
1174 | int | |
1175 | check (operand, low, high) | |
1176 | expressionS *operand; | |
1177 | int low; | |
1178 | int high; | |
1179 | { | |
1180 | if (operand->X_op != O_constant | |
1181 | || operand->X_add_number < low | |
1182 | || operand->X_add_number > high) | |
1183 | { | |
1184 | as_bad (_("operand must be absolute in range %d..%d"), low, high); | |
1185 | } | |
1186 | return operand->X_add_number; | |
1187 | } | |
1188 | ||
1189 | ||
1190 | static void | |
015551fc | 1191 | insert (where, how, pcrel, op) |
252b5132 RH |
1192 | char *where; |
1193 | int how; | |
1194 | int pcrel; | |
015551fc | 1195 | sh_operand_info *op; |
252b5132 RH |
1196 | { |
1197 | fix_new_exp (frag_now, | |
1198 | where - frag_now->fr_literal, | |
1199 | 2, | |
015551fc | 1200 | &op->immediate, |
252b5132 RH |
1201 | pcrel, |
1202 | how); | |
1203 | } | |
1204 | ||
1205 | static void | |
015551fc | 1206 | build_relax (opcode, op) |
252b5132 | 1207 | sh_opcode_info *opcode; |
015551fc | 1208 | sh_operand_info *op; |
252b5132 RH |
1209 | { |
1210 | int high_byte = target_big_endian ? 0 : 1; | |
1211 | char *p; | |
1212 | ||
1213 | if (opcode->arg[0] == A_BDISP8) | |
1214 | { | |
1215 | int what = (opcode->nibbles[1] & 4) ? COND_JUMP_DELAY : COND_JUMP; | |
1216 | p = frag_var (rs_machine_dependent, | |
1217 | md_relax_table[C (what, COND32)].rlx_length, | |
1218 | md_relax_table[C (what, COND8)].rlx_length, | |
1219 | C (what, 0), | |
015551fc JR |
1220 | op->immediate.X_add_symbol, |
1221 | op->immediate.X_add_number, | |
252b5132 RH |
1222 | 0); |
1223 | p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]); | |
1224 | } | |
1225 | else if (opcode->arg[0] == A_BDISP12) | |
1226 | { | |
1227 | p = frag_var (rs_machine_dependent, | |
1228 | md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length, | |
1229 | md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length, | |
1230 | C (UNCOND_JUMP, 0), | |
015551fc JR |
1231 | op->immediate.X_add_symbol, |
1232 | op->immediate.X_add_number, | |
252b5132 RH |
1233 | 0); |
1234 | p[high_byte] = (opcode->nibbles[0] << 4); | |
1235 | } | |
1236 | ||
1237 | } | |
1238 | ||
015551fc JR |
1239 | /* insert ldrs & ldre with fancy relocations that relaxation can recognize. */ |
1240 | static char * | |
1241 | insert_loop_bounds (output, operand) | |
1242 | char *output; | |
1243 | sh_operand_info *operand; | |
1244 | { | |
1245 | char *name; | |
1246 | symbolS *end_sym; | |
1247 | ||
1248 | /* Since the low byte of the opcode will be overwritten by the reloc, we | |
1249 | can just stash the high byte into both bytes and ignore endianness. */ | |
1250 | output[0] = 0x8c; | |
1251 | output[1] = 0x8c; | |
1252 | insert (output, BFD_RELOC_SH_LOOP_START, 1, operand); | |
1253 | insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1); | |
1254 | ||
1255 | if (sh_relax) | |
1256 | { | |
1257 | static int count = 0; | |
1258 | ||
1259 | /* If the last loop insn is a two-byte-insn, it is in danger of being | |
1260 | swapped with the insn after it. To prevent this, create a new | |
1261 | symbol - complete with SH_LABEL reloc - after the last loop insn. | |
1262 | If the last loop insn is four bytes long, the symbol will be | |
1263 | right in the middle, but four byte insns are not swapped anyways. */ | |
1264 | /* A REPEAT takes 6 bytes. The SH has a 32 bit address space. | |
1265 | Hence a 9 digit number should be enough to count all REPEATs. */ | |
1266 | name = alloca (11); | |
1267 | sprintf (name, "_R%x", count++ & 0x3fffffff); | |
1268 | end_sym = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
1269 | /* Make this a local symbol. */ | |
1270 | #ifdef OBJ_COFF | |
1271 | SF_SET_LOCAL (end_sym); | |
1272 | #endif /* OBJ_COFF */ | |
1273 | symbol_table_insert (end_sym); | |
1274 | end_sym->sy_value = operand[1].immediate; | |
1275 | end_sym->sy_value.X_add_number += 2; | |
1276 | fix_new (frag_now, frag_now_fix (), 2, end_sym, 0, 1, BFD_RELOC_SH_LABEL); | |
1277 | } | |
1278 | ||
1279 | output = frag_more (2); | |
1280 | output[0] = 0x8e; | |
1281 | output[1] = 0x8e; | |
1282 | insert (output, BFD_RELOC_SH_LOOP_START, 1, operand); | |
1283 | insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1); | |
1284 | ||
1285 | return frag_more (2); | |
1286 | } | |
1287 | ||
1994a7c7 | 1288 | /* Now we know what sort of opcodes it is, lets build the bytes. */ |
252b5132 RH |
1289 | static void |
1290 | build_Mytes (opcode, operand) | |
1291 | sh_opcode_info *opcode; | |
1292 | sh_operand_info *operand; | |
1293 | ||
1294 | { | |
1295 | int index; | |
1296 | char nbuf[4]; | |
1297 | char *output = frag_more (2); | |
1298 | int low_byte = target_big_endian ? 1 : 0; | |
1299 | nbuf[0] = 0; | |
1300 | nbuf[1] = 0; | |
1301 | nbuf[2] = 0; | |
1302 | nbuf[3] = 0; | |
1303 | ||
1304 | for (index = 0; index < 4; index++) | |
1305 | { | |
1306 | sh_nibble_type i = opcode->nibbles[index]; | |
1307 | if (i < 16) | |
1308 | { | |
1309 | nbuf[index] = i; | |
1310 | } | |
1311 | else | |
1312 | { | |
1313 | switch (i) | |
1314 | { | |
1315 | case REG_N: | |
1316 | nbuf[index] = reg_n; | |
1317 | break; | |
1318 | case REG_M: | |
1319 | nbuf[index] = reg_m; | |
1320 | break; | |
d4845d57 JR |
1321 | case SDT_REG_N: |
1322 | if (reg_n < 2 || reg_n > 5) | |
1323 | as_bad (_("Invalid register: 'r%d'"), reg_n); | |
1324 | nbuf[index] = (reg_n & 3) | 4; | |
1325 | break; | |
252b5132 RH |
1326 | case REG_NM: |
1327 | nbuf[index] = reg_n | (reg_m >> 2); | |
1328 | break; | |
1329 | case REG_B: | |
1330 | nbuf[index] = reg_b | 0x08; | |
1331 | break; | |
015551fc JR |
1332 | case IMM0_4BY4: |
1333 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand); | |
1334 | break; | |
1335 | case IMM0_4BY2: | |
1336 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand); | |
1337 | break; | |
1338 | case IMM0_4: | |
1339 | insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand); | |
1340 | break; | |
1341 | case IMM1_4BY4: | |
1342 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand + 1); | |
1343 | break; | |
1344 | case IMM1_4BY2: | |
1345 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand + 1); | |
252b5132 | 1346 | break; |
015551fc JR |
1347 | case IMM1_4: |
1348 | insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand + 1); | |
252b5132 | 1349 | break; |
015551fc JR |
1350 | case IMM0_8BY4: |
1351 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand); | |
252b5132 | 1352 | break; |
015551fc JR |
1353 | case IMM0_8BY2: |
1354 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand); | |
252b5132 | 1355 | break; |
015551fc JR |
1356 | case IMM0_8: |
1357 | insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand); | |
252b5132 | 1358 | break; |
015551fc JR |
1359 | case IMM1_8BY4: |
1360 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand + 1); | |
252b5132 | 1361 | break; |
015551fc JR |
1362 | case IMM1_8BY2: |
1363 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand + 1); | |
1364 | break; | |
1365 | case IMM1_8: | |
1366 | insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand + 1); | |
252b5132 RH |
1367 | break; |
1368 | case PCRELIMM_8BY4: | |
015551fc | 1369 | insert (output, BFD_RELOC_SH_PCRELIMM8BY4, 1, operand); |
252b5132 RH |
1370 | break; |
1371 | case PCRELIMM_8BY2: | |
015551fc JR |
1372 | insert (output, BFD_RELOC_SH_PCRELIMM8BY2, 1, operand); |
1373 | break; | |
1374 | case REPEAT: | |
1375 | output = insert_loop_bounds (output, operand); | |
1376 | nbuf[index] = opcode->nibbles[3]; | |
1377 | operand += 2; | |
252b5132 RH |
1378 | break; |
1379 | default: | |
1380 | printf (_("failed for %d\n"), i); | |
1381 | } | |
1382 | } | |
1383 | } | |
1384 | if (! target_big_endian) { | |
1385 | output[1] = (nbuf[0] << 4) | (nbuf[1]); | |
1386 | output[0] = (nbuf[2] << 4) | (nbuf[3]); | |
1387 | } | |
1388 | else { | |
1389 | output[0] = (nbuf[0] << 4) | (nbuf[1]); | |
1390 | output[1] = (nbuf[2] << 4) | (nbuf[3]); | |
1391 | } | |
1392 | } | |
1393 | ||
d4845d57 JR |
1394 | /* Find an opcode at the start of *STR_P in the hash table, and set |
1395 | *STR_P to the first character after the last one read. */ | |
252b5132 | 1396 | |
d4845d57 JR |
1397 | static sh_opcode_info * |
1398 | find_cooked_opcode (str_p) | |
1399 | char **str_p; | |
252b5132 | 1400 | { |
d4845d57 | 1401 | char *str = *str_p; |
252b5132 RH |
1402 | unsigned char *op_start; |
1403 | unsigned char *op_end; | |
252b5132 RH |
1404 | char name[20]; |
1405 | int nlen = 0; | |
1406 | /* Drop leading whitespace */ | |
1407 | while (*str == ' ') | |
1408 | str++; | |
1409 | ||
d4845d57 JR |
1410 | /* Find the op code end. |
1411 | The pre-processor will eliminate whitespace in front of | |
1412 | any '@' after the first argument; we may be called from | |
1413 | assemble_ppi, so the opcode might be terminated by an '@'. */ | |
252b5132 RH |
1414 | for (op_start = op_end = (unsigned char *) (str); |
1415 | *op_end | |
1416 | && nlen < 20 | |
d4845d57 | 1417 | && !is_end_of_line[*op_end] && *op_end != ' ' && *op_end != '@'; |
252b5132 RH |
1418 | op_end++) |
1419 | { | |
1420 | unsigned char c = op_start[nlen]; | |
1421 | ||
1422 | /* The machine independent code will convert CMP/EQ into cmp/EQ | |
d4845d57 JR |
1423 | because it thinks the '/' is the end of the symbol. Moreover, |
1424 | all but the first sub-insn is a parallel processing insn won't | |
1425 | be capitailzed. Instead of hacking up the machine independent | |
1426 | code, we just deal with it here. */ | |
252b5132 RH |
1427 | c = isupper (c) ? tolower (c) : c; |
1428 | name[nlen] = c; | |
1429 | nlen++; | |
1430 | } | |
1431 | name[nlen] = 0; | |
d4845d57 | 1432 | *str_p = op_end; |
252b5132 RH |
1433 | |
1434 | if (nlen == 0) | |
1435 | { | |
1436 | as_bad (_("can't find opcode ")); | |
1437 | } | |
1438 | ||
d4845d57 JR |
1439 | return (sh_opcode_info *) hash_find (opcode_hash_control, name); |
1440 | } | |
1441 | ||
1442 | /* Assemble a parallel processing insn. */ | |
1443 | #define DDT_BASE 0xf000 /* Base value for double data transfer insns */ | |
1444 | static void | |
1445 | assemble_ppi (op_end, opcode) | |
1446 | char *op_end; | |
1447 | sh_opcode_info *opcode; | |
1448 | { | |
1449 | int movx = 0; | |
1450 | int movy = 0; | |
1451 | int cond = 0; | |
1452 | int field_b = 0; | |
1453 | char *output; | |
1454 | int move_code; | |
1455 | ||
1456 | /* Some insn ignore one or more register fields, e.g. psts machl,a0. | |
1457 | Make sure we encode a defined insn pattern. */ | |
1458 | reg_x = 0; | |
1459 | reg_y = 0; | |
1460 | ||
1461 | for (;;) | |
1462 | { | |
1463 | sh_operand_info operand[3]; | |
1464 | ||
1465 | if (opcode->arg[0] != A_END) | |
1466 | op_end = get_operands (opcode, op_end, operand); | |
1467 | opcode = get_specific (opcode, operand); | |
1468 | if (opcode == 0) | |
1469 | { | |
1470 | /* Couldn't find an opcode which matched the operands */ | |
1471 | char *where = frag_more (2); | |
1472 | ||
1473 | where[0] = 0x0; | |
1474 | where[1] = 0x0; | |
1475 | as_bad (_("invalid operands for opcode")); | |
1476 | return; | |
1477 | } | |
1478 | if (opcode->nibbles[0] != PPI) | |
1479 | as_bad (_("insn can't be combined with parallel processing insn")); | |
1480 | ||
1481 | switch (opcode->nibbles[1]) | |
1482 | { | |
1483 | ||
1484 | case NOPX: | |
1485 | if (movx) | |
1486 | as_bad (_("multiple movx specifications")); | |
1487 | movx = DDT_BASE; | |
1488 | break; | |
1489 | case NOPY: | |
1490 | if (movy) | |
1491 | as_bad (_("multiple movy specifications")); | |
1492 | movy = DDT_BASE; | |
1493 | break; | |
1494 | ||
1495 | case MOVX: | |
1496 | if (movx) | |
1497 | as_bad (_("multiple movx specifications")); | |
1498 | if (reg_n < 4 || reg_n > 5) | |
1499 | as_bad (_("invalid movx address register")); | |
1500 | if (opcode->nibbles[2] & 8) | |
1501 | { | |
1502 | if (reg_m == A_A1_NUM) | |
1503 | movx = 1 << 7; | |
1504 | else if (reg_m != A_A0_NUM) | |
1505 | as_bad (_("invalid movx dsp register")); | |
1506 | } | |
1507 | else | |
1508 | { | |
1509 | if (reg_x > 1) | |
1510 | as_bad (_("invalid movx dsp register")); | |
1511 | movx = reg_x << 7; | |
1512 | } | |
1513 | movx += ((reg_n - 4) << 9) + (opcode->nibbles[2] << 2) + DDT_BASE; | |
1514 | break; | |
1515 | ||
1516 | case MOVY: | |
1517 | if (movy) | |
1518 | as_bad (_("multiple movy specifications")); | |
1519 | if (opcode->nibbles[2] & 8) | |
1520 | { | |
1521 | /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode, | |
1522 | so add 8 more. */ | |
1523 | movy = 8; | |
1524 | if (reg_m == A_A1_NUM) | |
1525 | movy += 1 << 6; | |
1526 | else if (reg_m != A_A0_NUM) | |
1527 | as_bad (_("invalid movy dsp register")); | |
1528 | } | |
1529 | else | |
1530 | { | |
1531 | if (reg_y > 1) | |
1532 | as_bad (_("invalid movy dsp register")); | |
1533 | movy = reg_y << 6; | |
1534 | } | |
1535 | if (reg_n < 6 || reg_n > 7) | |
1536 | as_bad (_("invalid movy address register")); | |
1537 | movy += ((reg_n - 6) << 8) + opcode->nibbles[2] + DDT_BASE; | |
1538 | break; | |
1539 | ||
1540 | case PSH: | |
015551fc | 1541 | if (operand[0].immediate.X_op != O_constant) |
d4845d57 JR |
1542 | as_bad (_("dsp immediate shift value not constant")); |
1543 | field_b = ((opcode->nibbles[2] << 12) | |
015551fc | 1544 | | (operand[0].immediate.X_add_number & 127) << 4 |
d4845d57 JR |
1545 | | reg_n); |
1546 | break; | |
1547 | case PPI3: | |
1548 | if (field_b) | |
1549 | as_bad (_("multiple parallel processing specifications")); | |
1550 | field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8) | |
1551 | + (reg_x << 6) + (reg_y << 4) + reg_n); | |
1552 | break; | |
1553 | case PDC: | |
1554 | if (cond) | |
1555 | as_bad (_("multiple condition specifications")); | |
1556 | cond = opcode->nibbles[2] << 8; | |
1557 | if (*op_end) | |
1558 | goto skip_cond_check; | |
1559 | break; | |
1560 | case PPIC: | |
1561 | if (field_b) | |
1562 | as_bad (_("multiple parallel processing specifications")); | |
1563 | field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8) | |
1564 | + cond + (reg_x << 6) + (reg_y << 4) + reg_n); | |
1565 | cond = 0; | |
1566 | break; | |
1567 | case PMUL: | |
1568 | if (field_b) | |
1569 | { | |
1570 | if ((field_b & 0xef00) != 0xa100) | |
1571 | as_bad (_("insn cannot be combined with pmuls")); | |
1572 | field_b -= 0x8100; | |
1573 | switch (field_b & 0xf) | |
1574 | { | |
1575 | case A_X0_NUM: | |
1576 | field_b += 0 - A_X0_NUM; | |
1577 | break; | |
1578 | case A_Y0_NUM: | |
1579 | field_b += 1 - A_Y0_NUM; | |
1580 | break; | |
1581 | case A_A0_NUM: | |
1582 | field_b += 2 - A_A0_NUM; | |
1583 | break; | |
1584 | case A_A1_NUM: | |
1585 | field_b += 3 - A_A1_NUM; | |
1586 | break; | |
1587 | default: | |
1588 | as_bad (_("bad padd / psub pmuls output operand")); | |
1589 | } | |
1590 | } | |
1591 | field_b += 0x4000 + reg_efg; | |
1592 | break; | |
1593 | default: | |
1594 | abort (); | |
1595 | } | |
1596 | if (cond) | |
1597 | { | |
1598 | as_bad (_("condition not followed by conditionalizable insn")); | |
1599 | cond = 0; | |
1600 | } | |
1601 | if (! *op_end) | |
1602 | break; | |
1603 | skip_cond_check: | |
1604 | opcode = find_cooked_opcode (&op_end); | |
1605 | if (opcode == NULL) | |
1606 | { | |
1607 | (as_bad | |
1608 | (_("unrecognized characters at end of parallel processing insn"))); | |
1609 | break; | |
1610 | } | |
1611 | } | |
1612 | ||
1613 | move_code = movx | movy; | |
1614 | if (field_b) | |
1615 | { | |
1616 | /* Parallel processing insn. */ | |
1617 | unsigned long ppi_code = (movx | movy | 0xf800) << 16 | field_b; | |
1618 | ||
1619 | output = frag_more (4); | |
1620 | if (! target_big_endian) | |
1621 | { | |
1622 | output[3] = ppi_code >> 8; | |
1623 | output[2] = ppi_code; | |
1624 | } | |
1625 | else | |
1626 | { | |
1627 | output[2] = ppi_code >> 8; | |
1628 | output[3] = ppi_code; | |
1629 | } | |
1630 | move_code |= 0xf800; | |
1631 | } | |
1632 | else | |
1633 | /* Just a double data transfer. */ | |
1634 | output = frag_more (2); | |
1635 | if (! target_big_endian) | |
1636 | { | |
1637 | output[1] = move_code >> 8; | |
1638 | output[0] = move_code; | |
1639 | } | |
1640 | else | |
1641 | { | |
1642 | output[0] = move_code >> 8; | |
1643 | output[1] = move_code; | |
1644 | } | |
1645 | } | |
1646 | ||
1647 | /* This is the guts of the machine-dependent assembler. STR points to a | |
1648 | machine dependent instruction. This function is supposed to emit | |
1649 | the frags/bytes it assembles to. | |
1650 | */ | |
1651 | ||
1652 | void | |
1653 | md_assemble (str) | |
1654 | char *str; | |
1655 | { | |
1656 | unsigned char *op_end; | |
1657 | sh_operand_info operand[3]; | |
1658 | sh_opcode_info *opcode; | |
1659 | ||
1660 | opcode = find_cooked_opcode (&str); | |
1661 | op_end = str; | |
252b5132 RH |
1662 | |
1663 | if (opcode == NULL) | |
1664 | { | |
1665 | as_bad (_("unknown opcode")); | |
1666 | return; | |
1667 | } | |
1668 | ||
1669 | if (sh_relax | |
1670 | && ! seg_info (now_seg)->tc_segment_info_data.in_code) | |
1671 | { | |
1672 | /* Output a CODE reloc to tell the linker that the following | |
1673 | bytes are instructions, not data. */ | |
1674 | fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0, | |
1675 | BFD_RELOC_SH_CODE); | |
1676 | seg_info (now_seg)->tc_segment_info_data.in_code = 1; | |
1677 | } | |
1678 | ||
d4845d57 JR |
1679 | if (opcode->nibbles[0] == PPI) |
1680 | { | |
1681 | assemble_ppi (op_end, opcode); | |
1682 | return; | |
1683 | } | |
1684 | ||
252b5132 RH |
1685 | if (opcode->arg[0] == A_BDISP12 |
1686 | || opcode->arg[0] == A_BDISP8) | |
1687 | { | |
015551fc JR |
1688 | parse_exp (op_end + 1, &operand[0]); |
1689 | build_relax (opcode, &operand[0]); | |
252b5132 RH |
1690 | } |
1691 | else | |
1692 | { | |
5fc44b2d | 1693 | if (opcode->arg[0] == A_END) |
252b5132 | 1694 | { |
5fc44b2d JR |
1695 | /* Ignore trailing whitespace. If there is any, it has already |
1696 | been compressed to a single space. */ | |
1697 | if (*op_end == ' ') | |
1698 | op_end++; | |
1699 | } | |
1700 | else | |
1701 | { | |
1702 | op_end = get_operands (opcode, op_end, operand); | |
252b5132 RH |
1703 | } |
1704 | opcode = get_specific (opcode, operand); | |
1705 | ||
1706 | if (opcode == 0) | |
1707 | { | |
1708 | /* Couldn't find an opcode which matched the operands */ | |
1709 | char *where = frag_more (2); | |
1710 | ||
1711 | where[0] = 0x0; | |
1712 | where[1] = 0x0; | |
1713 | as_bad (_("invalid operands for opcode")); | |
1714 | return; | |
1715 | } | |
1716 | ||
5fc44b2d JR |
1717 | if (*op_end) |
1718 | as_bad (_("excess operands: '%s'"), op_end); | |
1719 | ||
252b5132 RH |
1720 | build_Mytes (opcode, operand); |
1721 | } | |
1722 | ||
1723 | } | |
1724 | ||
1725 | /* This routine is called each time a label definition is seen. It | |
1726 | emits a BFD_RELOC_SH_LABEL reloc if necessary. */ | |
1727 | ||
1728 | void | |
1729 | sh_frob_label () | |
1730 | { | |
1731 | static fragS *last_label_frag; | |
1732 | static int last_label_offset; | |
1733 | ||
1734 | if (sh_relax | |
1735 | && seg_info (now_seg)->tc_segment_info_data.in_code) | |
1736 | { | |
1737 | int offset; | |
1738 | ||
1739 | offset = frag_now_fix (); | |
1740 | if (frag_now != last_label_frag | |
1741 | || offset != last_label_offset) | |
1742 | { | |
1743 | fix_new (frag_now, offset, 2, &abs_symbol, 0, 0, BFD_RELOC_SH_LABEL); | |
1744 | last_label_frag = frag_now; | |
1745 | last_label_offset = offset; | |
1746 | } | |
1747 | } | |
1748 | } | |
1749 | ||
1750 | /* This routine is called when the assembler is about to output some | |
1751 | data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */ | |
1752 | ||
1753 | void | |
1754 | sh_flush_pending_output () | |
1755 | { | |
1756 | if (sh_relax | |
1757 | && seg_info (now_seg)->tc_segment_info_data.in_code) | |
1758 | { | |
1759 | fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0, | |
1760 | BFD_RELOC_SH_DATA); | |
1761 | seg_info (now_seg)->tc_segment_info_data.in_code = 0; | |
1762 | } | |
1763 | } | |
1764 | ||
1765 | symbolS * | |
c0fecd35 AM |
1766 | md_undefined_symbol (name) |
1767 | char *name; | |
252b5132 RH |
1768 | { |
1769 | return 0; | |
1770 | } | |
1771 | ||
1772 | #ifdef OBJ_COFF | |
056350c6 | 1773 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
1774 | |
1775 | void | |
c0fecd35 AM |
1776 | tc_crawl_symbol_chain (headers) |
1777 | object_headers *headers; | |
252b5132 RH |
1778 | { |
1779 | printf (_("call to tc_crawl_symbol_chain \n")); | |
1780 | } | |
1781 | ||
1782 | void | |
c0fecd35 AM |
1783 | tc_headers_hook (headers) |
1784 | object_headers *headers; | |
252b5132 RH |
1785 | { |
1786 | printf (_("call to tc_headers_hook \n")); | |
1787 | } | |
1788 | ||
056350c6 | 1789 | #endif |
252b5132 RH |
1790 | #endif |
1791 | ||
1792 | /* Various routines to kill one day */ | |
1793 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
1794 | #define MAX_LITTLENUMS 6 | |
1795 | ||
1796 | /* Turn a string in input_line_pointer into a floating point constant of type | |
1797 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
1798 | emitted is stored in *sizeP . An error message is returned, or NULL on OK. | |
1799 | */ | |
1800 | char * | |
1801 | md_atof (type, litP, sizeP) | |
1802 | int type; | |
1803 | char *litP; | |
1804 | int *sizeP; | |
1805 | { | |
1806 | int prec; | |
1807 | LITTLENUM_TYPE words[4]; | |
1808 | char *t; | |
1809 | int i; | |
1810 | ||
1811 | switch (type) | |
1812 | { | |
1813 | case 'f': | |
1814 | prec = 2; | |
1815 | break; | |
1816 | ||
1817 | case 'd': | |
1818 | prec = 4; | |
1819 | break; | |
1820 | ||
1821 | default: | |
1822 | *sizeP = 0; | |
1823 | return _("bad call to md_atof"); | |
1824 | } | |
1825 | ||
1826 | t = atof_ieee (input_line_pointer, type, words); | |
1827 | if (t) | |
1828 | input_line_pointer = t; | |
1829 | ||
1830 | *sizeP = prec * 2; | |
1831 | ||
1832 | if (! target_big_endian) | |
1833 | { | |
1834 | for (i = prec - 1; i >= 0; i--) | |
1835 | { | |
1836 | md_number_to_chars (litP, (valueT) words[i], 2); | |
1837 | litP += 2; | |
1838 | } | |
1839 | } | |
1840 | else | |
1841 | { | |
1842 | for (i = 0; i < prec; i++) | |
1843 | { | |
1844 | md_number_to_chars (litP, (valueT) words[i], 2); | |
1845 | litP += 2; | |
1846 | } | |
1847 | } | |
1848 | ||
1849 | return NULL; | |
1850 | } | |
1851 | ||
1852 | /* Handle the .uses pseudo-op. This pseudo-op is used just before a | |
1853 | call instruction. It refers to a label of the instruction which | |
1854 | loads the register which the call uses. We use it to generate a | |
1855 | special reloc for the linker. */ | |
1856 | ||
1857 | static void | |
1858 | s_uses (ignore) | |
43841e91 | 1859 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1860 | { |
1861 | expressionS ex; | |
1862 | ||
1863 | if (! sh_relax) | |
1864 | as_warn (_(".uses pseudo-op seen when not relaxing")); | |
1865 | ||
1866 | expression (&ex); | |
1867 | ||
1868 | if (ex.X_op != O_symbol || ex.X_add_number != 0) | |
1869 | { | |
1870 | as_bad (_("bad .uses format")); | |
1871 | ignore_rest_of_line (); | |
1872 | return; | |
1873 | } | |
1874 | ||
1875 | fix_new_exp (frag_now, frag_now_fix (), 2, &ex, 1, BFD_RELOC_SH_USES); | |
1876 | ||
1877 | demand_empty_rest_of_line (); | |
1878 | } | |
1879 | \f | |
1880 | CONST char *md_shortopts = ""; | |
1881 | struct option md_longopts[] = { | |
1882 | ||
1883 | #define OPTION_RELAX (OPTION_MD_BASE) | |
1884 | #define OPTION_LITTLE (OPTION_MD_BASE + 1) | |
1885 | #define OPTION_SMALL (OPTION_LITTLE + 1) | |
d4845d57 | 1886 | #define OPTION_DSP (OPTION_SMALL + 1) |
252b5132 RH |
1887 | |
1888 | {"relax", no_argument, NULL, OPTION_RELAX}, | |
1889 | {"little", no_argument, NULL, OPTION_LITTLE}, | |
1890 | {"small", no_argument, NULL, OPTION_SMALL}, | |
d4845d57 | 1891 | {"dsp", no_argument, NULL, OPTION_DSP}, |
252b5132 RH |
1892 | {NULL, no_argument, NULL, 0} |
1893 | }; | |
1894 | size_t md_longopts_size = sizeof(md_longopts); | |
1895 | ||
1896 | int | |
1897 | md_parse_option (c, arg) | |
1898 | int c; | |
43841e91 | 1899 | char *arg ATTRIBUTE_UNUSED; |
252b5132 RH |
1900 | { |
1901 | switch (c) | |
1902 | { | |
1903 | case OPTION_RELAX: | |
1904 | sh_relax = 1; | |
1905 | break; | |
1906 | ||
1907 | case OPTION_LITTLE: | |
1908 | shl = 1; | |
1909 | target_big_endian = 0; | |
1910 | break; | |
1911 | ||
1912 | case OPTION_SMALL: | |
1913 | sh_small = 1; | |
1914 | break; | |
1915 | ||
d4845d57 JR |
1916 | case OPTION_DSP: |
1917 | sh_dsp = 1; | |
1918 | break; | |
1919 | ||
252b5132 RH |
1920 | default: |
1921 | return 0; | |
1922 | } | |
1923 | ||
1924 | return 1; | |
1925 | } | |
1926 | ||
1927 | void | |
1928 | md_show_usage (stream) | |
1929 | FILE *stream; | |
1930 | { | |
1931 | fprintf(stream, _("\ | |
1932 | SH options:\n\ | |
1933 | -little generate little endian code\n\ | |
1934 | -relax alter jump instructions for long displacements\n\ | |
5b8274e3 | 1935 | -small align sections to 4 byte boundaries, not 16\n\ |
182e89d3 | 1936 | -dsp enable sh-dsp insns, and disable sh3e / sh4 insns.\n")); |
252b5132 RH |
1937 | } |
1938 | \f | |
1939 | void | |
1940 | tc_Nout_fix_to_chars () | |
1941 | { | |
1942 | printf (_("call to tc_Nout_fix_to_chars \n")); | |
1943 | abort (); | |
1944 | } | |
1945 | ||
1946 | /* This struct is used to pass arguments to sh_count_relocs through | |
1947 | bfd_map_over_sections. */ | |
1948 | ||
1949 | struct sh_count_relocs | |
1950 | { | |
1951 | /* Symbol we are looking for. */ | |
1952 | symbolS *sym; | |
1953 | /* Count of relocs found. */ | |
1954 | int count; | |
1955 | }; | |
1956 | ||
1957 | /* Count the number of fixups in a section which refer to a particular | |
1958 | symbol. When using BFD_ASSEMBLER, this is called via | |
1959 | bfd_map_over_sections. */ | |
1960 | ||
1961 | /*ARGSUSED*/ | |
1962 | static void | |
1963 | sh_count_relocs (abfd, sec, data) | |
43841e91 | 1964 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1965 | segT sec; |
1966 | PTR data; | |
1967 | { | |
1968 | struct sh_count_relocs *info = (struct sh_count_relocs *) data; | |
1969 | segment_info_type *seginfo; | |
1970 | symbolS *sym; | |
1971 | fixS *fix; | |
1972 | ||
1973 | seginfo = seg_info (sec); | |
1974 | if (seginfo == NULL) | |
1975 | return; | |
1976 | ||
1977 | sym = info->sym; | |
1978 | for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next) | |
1979 | { | |
1980 | if (fix->fx_addsy == sym) | |
1981 | { | |
1982 | ++info->count; | |
1983 | fix->fx_tcbit = 1; | |
1984 | } | |
1985 | } | |
1986 | } | |
1987 | ||
1988 | /* Handle the count relocs for a particular section. When using | |
1989 | BFD_ASSEMBLER, this is called via bfd_map_over_sections. */ | |
1990 | ||
1991 | /*ARGSUSED*/ | |
1992 | static void | |
1993 | sh_frob_section (abfd, sec, ignore) | |
43841e91 | 1994 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 1995 | segT sec; |
43841e91 | 1996 | PTR ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1997 | { |
1998 | segment_info_type *seginfo; | |
1999 | fixS *fix; | |
2000 | ||
2001 | seginfo = seg_info (sec); | |
2002 | if (seginfo == NULL) | |
2003 | return; | |
2004 | ||
2005 | for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next) | |
2006 | { | |
2007 | symbolS *sym; | |
2008 | bfd_vma val; | |
2009 | fixS *fscan; | |
2010 | struct sh_count_relocs info; | |
2011 | ||
2012 | if (fix->fx_r_type != BFD_RELOC_SH_USES) | |
2013 | continue; | |
2014 | ||
2015 | /* The BFD_RELOC_SH_USES reloc should refer to a defined local | |
2016 | symbol in the same section. */ | |
2017 | sym = fix->fx_addsy; | |
2018 | if (sym == NULL | |
2019 | || fix->fx_subsy != NULL | |
2020 | || fix->fx_addnumber != 0 | |
2021 | || S_GET_SEGMENT (sym) != sec | |
2022 | #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF) | |
2023 | || S_GET_STORAGE_CLASS (sym) == C_EXT | |
2024 | #endif | |
2025 | || S_IS_EXTERNAL (sym)) | |
2026 | { | |
2027 | as_warn_where (fix->fx_file, fix->fx_line, | |
2028 | _(".uses does not refer to a local symbol in the same section")); | |
2029 | continue; | |
2030 | } | |
2031 | ||
2032 | /* Look through the fixups again, this time looking for one | |
2033 | at the same location as sym. */ | |
2034 | val = S_GET_VALUE (sym); | |
2035 | for (fscan = seginfo->fix_root; | |
2036 | fscan != NULL; | |
2037 | fscan = fscan->fx_next) | |
2038 | if (val == fscan->fx_frag->fr_address + fscan->fx_where | |
2039 | && fscan->fx_r_type != BFD_RELOC_SH_ALIGN | |
2040 | && fscan->fx_r_type != BFD_RELOC_SH_CODE | |
2041 | && fscan->fx_r_type != BFD_RELOC_SH_DATA | |
2042 | && fscan->fx_r_type != BFD_RELOC_SH_LABEL) | |
2043 | break; | |
2044 | if (fscan == NULL) | |
2045 | { | |
2046 | as_warn_where (fix->fx_file, fix->fx_line, | |
2047 | _("can't find fixup pointed to by .uses")); | |
2048 | continue; | |
2049 | } | |
2050 | ||
2051 | if (fscan->fx_tcbit) | |
2052 | { | |
2053 | /* We've already done this one. */ | |
2054 | continue; | |
2055 | } | |
2056 | ||
2057 | /* fscan should also be a fixup to a local symbol in the same | |
2058 | section. */ | |
2059 | sym = fscan->fx_addsy; | |
2060 | if (sym == NULL | |
2061 | || fscan->fx_subsy != NULL | |
2062 | || fscan->fx_addnumber != 0 | |
2063 | || S_GET_SEGMENT (sym) != sec | |
2064 | #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF) | |
2065 | || S_GET_STORAGE_CLASS (sym) == C_EXT | |
2066 | #endif | |
2067 | || S_IS_EXTERNAL (sym)) | |
2068 | { | |
2069 | as_warn_where (fix->fx_file, fix->fx_line, | |
2070 | _(".uses target does not refer to a local symbol in the same section")); | |
2071 | continue; | |
2072 | } | |
2073 | ||
2074 | /* Now we look through all the fixups of all the sections, | |
2075 | counting the number of times we find a reference to sym. */ | |
2076 | info.sym = sym; | |
2077 | info.count = 0; | |
2078 | #ifdef BFD_ASSEMBLER | |
2079 | bfd_map_over_sections (stdoutput, sh_count_relocs, (PTR) &info); | |
2080 | #else | |
2081 | { | |
2082 | int iscan; | |
2083 | ||
2084 | for (iscan = SEG_E0; iscan < SEG_UNKNOWN; iscan++) | |
2085 | sh_count_relocs ((bfd *) NULL, iscan, (PTR) &info); | |
2086 | } | |
2087 | #endif | |
2088 | ||
2089 | if (info.count < 1) | |
2090 | abort (); | |
2091 | ||
2092 | /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym. | |
2093 | We have already adjusted the value of sym to include the | |
2094 | fragment address, so we undo that adjustment here. */ | |
2095 | subseg_change (sec, 0); | |
49309057 ILT |
2096 | fix_new (symbol_get_frag (sym), |
2097 | S_GET_VALUE (sym) - symbol_get_frag (sym)->fr_address, | |
252b5132 RH |
2098 | 4, &abs_symbol, info.count, 0, BFD_RELOC_SH_COUNT); |
2099 | } | |
2100 | } | |
2101 | ||
2102 | /* This function is called after the symbol table has been completed, | |
2103 | but before the relocs or section contents have been written out. | |
2104 | If we have seen any .uses pseudo-ops, they point to an instruction | |
2105 | which loads a register with the address of a function. We look | |
2106 | through the fixups to find where the function address is being | |
2107 | loaded from. We then generate a COUNT reloc giving the number of | |
2108 | times that function address is referred to. The linker uses this | |
2109 | information when doing relaxing, to decide when it can eliminate | |
2110 | the stored function address entirely. */ | |
2111 | ||
2112 | void | |
2113 | sh_frob_file () | |
2114 | { | |
2115 | if (! sh_relax) | |
2116 | return; | |
2117 | ||
2118 | #ifdef BFD_ASSEMBLER | |
2119 | bfd_map_over_sections (stdoutput, sh_frob_section, (PTR) NULL); | |
2120 | #else | |
2121 | { | |
2122 | int iseg; | |
2123 | ||
2124 | for (iseg = SEG_E0; iseg < SEG_UNKNOWN; iseg++) | |
2125 | sh_frob_section ((bfd *) NULL, iseg, (PTR) NULL); | |
2126 | } | |
2127 | #endif | |
2128 | } | |
2129 | ||
2130 | /* Called after relaxing. Set the correct sizes of the fragments, and | |
2131 | create relocs so that md_apply_fix will fill in the correct values. */ | |
2132 | ||
2133 | void | |
2134 | md_convert_frag (headers, seg, fragP) | |
2135 | #ifdef BFD_ASSEMBLER | |
43841e91 | 2136 | bfd *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
2137 | #else |
2138 | object_headers *headers; | |
2139 | #endif | |
2140 | segT seg; | |
2141 | fragS *fragP; | |
2142 | { | |
2143 | int donerelax = 0; | |
2144 | ||
2145 | switch (fragP->fr_subtype) | |
2146 | { | |
2147 | case C (COND_JUMP, COND8): | |
2148 | case C (COND_JUMP_DELAY, COND8): | |
2149 | subseg_change (seg, 0); | |
2150 | fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset, | |
2151 | 1, BFD_RELOC_SH_PCDISP8BY2); | |
2152 | fragP->fr_fix += 2; | |
2153 | fragP->fr_var = 0; | |
2154 | break; | |
2155 | ||
2156 | case C (UNCOND_JUMP, UNCOND12): | |
2157 | subseg_change (seg, 0); | |
2158 | fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset, | |
2159 | 1, BFD_RELOC_SH_PCDISP12BY2); | |
2160 | fragP->fr_fix += 2; | |
2161 | fragP->fr_var = 0; | |
2162 | break; | |
2163 | ||
2164 | case C (UNCOND_JUMP, UNCOND32): | |
2165 | case C (UNCOND_JUMP, UNDEF_WORD_DISP): | |
2166 | if (fragP->fr_symbol == NULL) | |
2167 | as_bad (_("at 0x%lx, displacement overflows 12-bit field"), | |
2168 | (unsigned long) fragP->fr_address); | |
2169 | else if (S_IS_DEFINED (fragP->fr_symbol)) | |
2170 | as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 12-bit field"), | |
2171 | (unsigned long) fragP->fr_address, | |
2172 | S_GET_NAME (fragP->fr_symbol)); | |
2173 | else | |
2174 | as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 12-bit field"), | |
2175 | (unsigned long) fragP->fr_address, | |
2176 | S_GET_NAME (fragP->fr_symbol)); | |
2177 | ||
2178 | #if 0 /* This code works, but generates poor code and the compiler | |
2179 | should never produce a sequence that requires it to be used. */ | |
2180 | ||
2181 | /* A jump wont fit in 12 bits, make code which looks like | |
2182 | bra foo | |
2183 | mov.w @(0, PC), r14 | |
2184 | .long disp | |
2185 | foo: bra @r14 | |
2186 | */ | |
2187 | int t = buffer[0] & 0x10; | |
2188 | ||
2189 | buffer[highbyte] = 0xa0; /* branch over move and disp */ | |
2190 | buffer[lowbyte] = 3; | |
2191 | buffer[highbyte+2] = 0xd0 | JREG; /* Build mov insn */ | |
2192 | buffer[lowbyte+2] = 0x00; | |
2193 | ||
2194 | buffer[highbyte+4] = 0; /* space for 32 bit jump disp */ | |
2195 | buffer[lowbyte+4] = 0; | |
2196 | buffer[highbyte+6] = 0; | |
2197 | buffer[lowbyte+6] = 0; | |
2198 | ||
2199 | buffer[highbyte+8] = 0x40 | JREG; /* Build jmp @JREG */ | |
2200 | buffer[lowbyte+8] = t ? 0xb : 0x2b; | |
2201 | ||
2202 | buffer[highbyte+10] = 0x20; /* build nop */ | |
2203 | buffer[lowbyte+10] = 0x0b; | |
2204 | ||
2205 | /* Make reloc for the long disp */ | |
2206 | fix_new (fragP, | |
2207 | fragP->fr_fix + 4, | |
2208 | 4, | |
2209 | fragP->fr_symbol, | |
2210 | fragP->fr_offset, | |
2211 | 0, | |
2212 | BFD_RELOC_32); | |
2213 | fragP->fr_fix += UNCOND32_LENGTH; | |
2214 | fragP->fr_var = 0; | |
2215 | donerelax = 1; | |
2216 | #endif | |
2217 | ||
2218 | break; | |
2219 | ||
2220 | case C (COND_JUMP, COND12): | |
2221 | case C (COND_JUMP_DELAY, COND12): | |
2222 | /* A bcond won't fit, so turn it into a b!cond; bra disp; nop */ | |
2223 | /* I found that a relax failure for gcc.c-torture/execute/930628-1.c | |
2224 | was due to gas incorrectly relaxing an out-of-range conditional | |
2225 | branch with delay slot. It turned: | |
2226 | bf.s L6 (slot mov.l r12,@(44,r0)) | |
2227 | into: | |
2228 | ||
2229 | 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6) | |
2230 | 30: 00 09 nop | |
2231 | 32: 10 cb mov.l r12,@(44,r0) | |
2232 | Therefore, branches with delay slots have to be handled | |
2233 | differently from ones without delay slots. */ | |
2234 | { | |
2235 | unsigned char *buffer = | |
2236 | (unsigned char *) (fragP->fr_fix + fragP->fr_literal); | |
2237 | int highbyte = target_big_endian ? 0 : 1; | |
2238 | int lowbyte = target_big_endian ? 1 : 0; | |
2239 | int delay = fragP->fr_subtype == C (COND_JUMP_DELAY, COND12); | |
2240 | ||
2241 | /* Toggle the true/false bit of the bcond. */ | |
2242 | buffer[highbyte] ^= 0x2; | |
2243 | ||
2244 | /* If this is a dalayed branch, we may not put the the bra in the | |
2245 | slot. So we change it to a non-delayed branch, like that: | |
2246 | b! cond slot_label; bra disp; slot_label: slot_insn | |
2247 | ??? We should try if swapping the conditional branch and | |
2248 | its delay-slot insn already makes the branch reach. */ | |
2249 | ||
2250 | /* Build a relocation to six / four bytes farther on. */ | |
2251 | subseg_change (seg, 0); | |
2252 | fix_new (fragP, fragP->fr_fix, 2, | |
2253 | #ifdef BFD_ASSEMBLER | |
2254 | section_symbol (seg), | |
2255 | #else | |
2256 | seg_info (seg)->dot, | |
2257 | #endif | |
2258 | fragP->fr_address + fragP->fr_fix + (delay ? 4 : 6), | |
2259 | 1, BFD_RELOC_SH_PCDISP8BY2); | |
2260 | ||
2261 | /* Set up a jump instruction. */ | |
2262 | buffer[highbyte + 2] = 0xa0; | |
2263 | buffer[lowbyte + 2] = 0; | |
2264 | fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol, | |
2265 | fragP->fr_offset, 1, BFD_RELOC_SH_PCDISP12BY2); | |
2266 | ||
2267 | if (delay) | |
2268 | { | |
2269 | buffer[highbyte] &= ~0x4; /* Removes delay slot from branch. */ | |
2270 | fragP->fr_fix += 4; | |
2271 | } | |
2272 | else | |
2273 | { | |
2274 | /* Fill in a NOP instruction. */ | |
2275 | buffer[highbyte + 4] = 0x0; | |
2276 | buffer[lowbyte + 4] = 0x9; | |
2277 | ||
2278 | fragP->fr_fix += 6; | |
2279 | } | |
2280 | fragP->fr_var = 0; | |
2281 | donerelax = 1; | |
2282 | } | |
2283 | break; | |
2284 | ||
2285 | case C (COND_JUMP, COND32): | |
2286 | case C (COND_JUMP_DELAY, COND32): | |
2287 | case C (COND_JUMP, UNDEF_WORD_DISP): | |
2288 | case C (COND_JUMP_DELAY, UNDEF_WORD_DISP): | |
2289 | if (fragP->fr_symbol == NULL) | |
2290 | as_bad (_("at 0x%lx, displacement overflows 8-bit field"), | |
2291 | (unsigned long) fragP->fr_address); | |
2292 | else if (S_IS_DEFINED (fragP->fr_symbol)) | |
2293 | as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 8-bit field "), | |
2294 | (unsigned long) fragP->fr_address, | |
2295 | S_GET_NAME (fragP->fr_symbol)); | |
2296 | else | |
2297 | as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 8-bit field "), | |
2298 | (unsigned long) fragP->fr_address, | |
2299 | S_GET_NAME (fragP->fr_symbol)); | |
2300 | ||
2301 | #if 0 /* This code works, but generates poor code, and the compiler | |
2302 | should never produce a sequence that requires it to be used. */ | |
2303 | ||
2304 | /* A bcond won't fit and it won't go into a 12 bit | |
2305 | displacement either, the code sequence looks like: | |
2306 | b!cond foop | |
2307 | mov.w @(n, PC), r14 | |
2308 | jmp @r14 | |
2309 | nop | |
2310 | .long where | |
2311 | foop: | |
2312 | */ | |
2313 | ||
2314 | buffer[0] ^= 0x2; /* Toggle T/F bit */ | |
2315 | #define JREG 14 | |
2316 | buffer[1] = 5; /* branch over mov, jump, nop and ptr */ | |
2317 | buffer[2] = 0xd0 | JREG; /* Build mov insn */ | |
2318 | buffer[3] = 0x2; | |
2319 | buffer[4] = 0x40 | JREG; /* Build jmp @JREG */ | |
2320 | buffer[5] = 0x0b; | |
2321 | buffer[6] = 0x20; /* build nop */ | |
2322 | buffer[7] = 0x0b; | |
2323 | buffer[8] = 0; /* space for 32 bit jump disp */ | |
2324 | buffer[9] = 0; | |
2325 | buffer[10] = 0; | |
2326 | buffer[11] = 0; | |
2327 | buffer[12] = 0; | |
2328 | buffer[13] = 0; | |
2329 | /* Make reloc for the long disp */ | |
2330 | fix_new (fragP, | |
2331 | fragP->fr_fix + 8, | |
2332 | 4, | |
2333 | fragP->fr_symbol, | |
2334 | fragP->fr_offset, | |
2335 | 0, | |
2336 | BFD_RELOC_32); | |
2337 | fragP->fr_fix += COND32_LENGTH; | |
2338 | fragP->fr_var = 0; | |
2339 | donerelax = 1; | |
2340 | #endif | |
2341 | ||
2342 | break; | |
2343 | ||
2344 | default: | |
2345 | abort (); | |
2346 | } | |
2347 | ||
2348 | if (donerelax && !sh_relax) | |
2349 | as_warn_where (fragP->fr_file, fragP->fr_line, | |
2350 | _("overflow in branch to %s; converted into longer instruction sequence"), | |
2351 | (fragP->fr_symbol != NULL | |
2352 | ? S_GET_NAME (fragP->fr_symbol) | |
2353 | : "")); | |
2354 | } | |
2355 | ||
2356 | valueT | |
c0fecd35 AM |
2357 | md_section_align (seg, size) |
2358 | segT seg; | |
2359 | valueT size; | |
252b5132 RH |
2360 | { |
2361 | #ifdef BFD_ASSEMBLER | |
2362 | #ifdef OBJ_ELF | |
2363 | return size; | |
2364 | #else /* ! OBJ_ELF */ | |
2365 | return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1) | |
2366 | & (-1 << bfd_get_section_alignment (stdoutput, seg))); | |
2367 | #endif /* ! OBJ_ELF */ | |
2368 | #else /* ! BFD_ASSEMBLER */ | |
2369 | return ((size + (1 << section_alignment[(int) seg]) - 1) | |
2370 | & (-1 << section_alignment[(int) seg])); | |
2371 | #endif /* ! BFD_ASSEMBLER */ | |
2372 | } | |
2373 | ||
2374 | /* This static variable is set by s_uacons to tell sh_cons_align that | |
2375 | the expession does not need to be aligned. */ | |
2376 | ||
2377 | static int sh_no_align_cons = 0; | |
2378 | ||
2379 | /* This handles the unaligned space allocation pseudo-ops, such as | |
2380 | .uaword. .uaword is just like .word, but the value does not need | |
2381 | to be aligned. */ | |
2382 | ||
2383 | static void | |
2384 | s_uacons (bytes) | |
2385 | int bytes; | |
2386 | { | |
2387 | /* Tell sh_cons_align not to align this value. */ | |
2388 | sh_no_align_cons = 1; | |
2389 | cons (bytes); | |
2390 | } | |
2391 | ||
2392 | /* If a .word, et. al., pseud-op is seen, warn if the value is not | |
2393 | aligned correctly. Note that this can cause warnings to be issued | |
2394 | when assembling initialized structured which were declared with the | |
2395 | packed attribute. FIXME: Perhaps we should require an option to | |
2396 | enable this warning? */ | |
2397 | ||
2398 | void | |
2399 | sh_cons_align (nbytes) | |
2400 | int nbytes; | |
2401 | { | |
2402 | int nalign; | |
2403 | char *p; | |
2404 | ||
2405 | if (sh_no_align_cons) | |
2406 | { | |
2407 | /* This is an unaligned pseudo-op. */ | |
2408 | sh_no_align_cons = 0; | |
2409 | return; | |
2410 | } | |
2411 | ||
2412 | nalign = 0; | |
2413 | while ((nbytes & 1) == 0) | |
2414 | { | |
2415 | ++nalign; | |
2416 | nbytes >>= 1; | |
2417 | } | |
2418 | ||
2419 | if (nalign == 0) | |
2420 | return; | |
2421 | ||
2422 | if (now_seg == absolute_section) | |
2423 | { | |
2424 | if ((abs_section_offset & ((1 << nalign) - 1)) != 0) | |
2425 | as_warn (_("misaligned data")); | |
2426 | return; | |
2427 | } | |
2428 | ||
2429 | p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0, | |
2430 | (symbolS *) NULL, (offsetT) nalign, (char *) NULL); | |
2431 | ||
2432 | record_alignment (now_seg, nalign); | |
2433 | } | |
2434 | ||
2435 | /* When relaxing, we need to output a reloc for any .align directive | |
2436 | that requests alignment to a four byte boundary or larger. This is | |
2437 | also where we check for misaligned data. */ | |
2438 | ||
2439 | void | |
2440 | sh_handle_align (frag) | |
2441 | fragS *frag; | |
2442 | { | |
2443 | if (sh_relax | |
2444 | && frag->fr_type == rs_align | |
2445 | && frag->fr_address + frag->fr_fix > 0 | |
2446 | && frag->fr_offset > 1 | |
2447 | && now_seg != bss_section) | |
2448 | fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0, | |
2449 | BFD_RELOC_SH_ALIGN); | |
2450 | ||
2451 | if (frag->fr_type == rs_align_code | |
2452 | && frag->fr_next->fr_address - frag->fr_address - frag->fr_fix != 0) | |
2453 | as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data")); | |
2454 | } | |
2455 | ||
2456 | /* This macro decides whether a particular reloc is an entry in a | |
2457 | switch table. It is used when relaxing, because the linker needs | |
2458 | to know about all such entries so that it can adjust them if | |
2459 | necessary. */ | |
2460 | ||
2461 | #ifdef BFD_ASSEMBLER | |
2462 | #define SWITCH_TABLE_CONS(fix) (0) | |
2463 | #else | |
2464 | #define SWITCH_TABLE_CONS(fix) \ | |
2465 | ((fix)->fx_r_type == 0 \ | |
2466 | && ((fix)->fx_size == 2 \ | |
2467 | || (fix)->fx_size == 1 \ | |
2468 | || (fix)->fx_size == 4)) | |
2469 | #endif | |
2470 | ||
2471 | #define SWITCH_TABLE(fix) \ | |
2472 | ((fix)->fx_addsy != NULL \ | |
2473 | && (fix)->fx_subsy != NULL \ | |
2474 | && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \ | |
2475 | && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \ | |
2476 | && ((fix)->fx_r_type == BFD_RELOC_32 \ | |
2477 | || (fix)->fx_r_type == BFD_RELOC_16 \ | |
2478 | || (fix)->fx_r_type == BFD_RELOC_8 \ | |
2479 | || SWITCH_TABLE_CONS (fix))) | |
2480 | ||
2481 | /* See whether we need to force a relocation into the output file. | |
2482 | This is used to force out switch and PC relative relocations when | |
2483 | relaxing. */ | |
2484 | ||
2485 | int | |
2486 | sh_force_relocation (fix) | |
2487 | fixS *fix; | |
2488 | { | |
2489 | ||
2490 | if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
015551fc JR |
2491 | || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
2492 | || fix->fx_r_type == BFD_RELOC_SH_LOOP_START | |
2493 | || fix->fx_r_type == BFD_RELOC_SH_LOOP_END) | |
252b5132 RH |
2494 | return 1; |
2495 | ||
2496 | if (! sh_relax) | |
2497 | return 0; | |
2498 | ||
2499 | return (fix->fx_pcrel | |
2500 | || SWITCH_TABLE (fix) | |
2501 | || fix->fx_r_type == BFD_RELOC_SH_COUNT | |
2502 | || fix->fx_r_type == BFD_RELOC_SH_ALIGN | |
2503 | || fix->fx_r_type == BFD_RELOC_SH_CODE | |
2504 | || fix->fx_r_type == BFD_RELOC_SH_DATA | |
2505 | || fix->fx_r_type == BFD_RELOC_SH_LABEL); | |
2506 | } | |
2507 | ||
2508 | #ifdef OBJ_ELF | |
2509 | boolean | |
2510 | sh_fix_adjustable (fixP) | |
2511 | fixS *fixP; | |
2512 | { | |
2513 | ||
2514 | if (fixP->fx_addsy == NULL) | |
2515 | return 1; | |
2516 | ||
2517 | /* We need the symbol name for the VTABLE entries */ | |
2518 | if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
2519 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
2520 | return 0; | |
2521 | ||
2522 | return 1; | |
2523 | } | |
d4845d57 JR |
2524 | |
2525 | void sh_elf_final_processing() | |
2526 | { | |
2527 | int val; | |
2528 | ||
2529 | /* Set file-specific flags to indicate if this code needs | |
2530 | a processor with the sh-dsp / sh3e ISA to execute. */ | |
2531 | if (valid_arch & arch_sh1) | |
2532 | val = EF_SH1; | |
2533 | else if (valid_arch & arch_sh2) | |
2534 | val = EF_SH2; | |
2535 | else if (valid_arch & arch_sh_dsp) | |
2536 | val = EF_SH_DSP; | |
2537 | else if (valid_arch & arch_sh3) | |
2538 | val = EF_SH3; | |
2539 | else if (valid_arch & arch_sh3_dsp) | |
2540 | val = EF_SH_DSP; | |
2541 | else if (valid_arch & arch_sh3e) | |
2542 | val = EF_SH3E; | |
2543 | else if (valid_arch & arch_sh4) | |
2544 | val = EF_SH4; | |
2545 | else | |
2546 | abort (); | |
2547 | ||
2548 | elf_elfheader (stdoutput)->e_flags &= ~EF_SH_MACH_MASK; | |
2549 | elf_elfheader (stdoutput)->e_flags |= val; | |
2550 | } | |
252b5132 RH |
2551 | #endif |
2552 | ||
2553 | /* Apply a fixup to the object file. */ | |
2554 | ||
2555 | #ifdef BFD_ASSEMBLER | |
2556 | int | |
2557 | md_apply_fix (fixP, valp) | |
2558 | fixS *fixP; | |
2559 | valueT *valp; | |
2560 | #else | |
2561 | void | |
2562 | md_apply_fix (fixP, val) | |
2563 | fixS *fixP; | |
2564 | long val; | |
2565 | #endif | |
2566 | { | |
2567 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
2568 | int lowbyte = target_big_endian ? 1 : 0; | |
2569 | int highbyte = target_big_endian ? 0 : 1; | |
2570 | #ifdef BFD_ASSEMBLER | |
2571 | long val = *valp; | |
2572 | #endif | |
2573 | long max, min; | |
2574 | int shift; | |
2575 | ||
2576 | #ifdef BFD_ASSEMBLER | |
2577 | /* adjust_reloc_syms won't convert a reloc against a weak symbol | |
2578 | into a reloc against a section, but bfd_install_relocation will | |
2579 | screw up if the symbol is defined, so we have to adjust val here | |
2580 | to avoid the screw up later. */ | |
2581 | if (fixP->fx_addsy != NULL | |
2582 | && S_IS_WEAK (fixP->fx_addsy)) | |
2583 | val -= S_GET_VALUE (fixP->fx_addsy); | |
2584 | #endif | |
2585 | ||
2586 | #ifndef BFD_ASSEMBLER | |
2587 | if (fixP->fx_r_type == 0) | |
2588 | { | |
2589 | if (fixP->fx_size == 2) | |
2590 | fixP->fx_r_type = BFD_RELOC_16; | |
2591 | else if (fixP->fx_size == 4) | |
2592 | fixP->fx_r_type = BFD_RELOC_32; | |
2593 | else if (fixP->fx_size == 1) | |
2594 | fixP->fx_r_type = BFD_RELOC_8; | |
2595 | else | |
2596 | abort (); | |
2597 | } | |
2598 | #endif | |
2599 | ||
2600 | max = min = 0; | |
2601 | shift = 0; | |
2602 | switch (fixP->fx_r_type) | |
2603 | { | |
2604 | case BFD_RELOC_SH_IMM4: | |
2605 | max = 0xf; | |
2606 | *buf = (*buf & 0xf0) | (val & 0xf); | |
2607 | break; | |
2608 | ||
2609 | case BFD_RELOC_SH_IMM4BY2: | |
2610 | max = 0xf; | |
2611 | shift = 1; | |
2612 | *buf = (*buf & 0xf0) | ((val >> 1) & 0xf); | |
2613 | break; | |
2614 | ||
2615 | case BFD_RELOC_SH_IMM4BY4: | |
2616 | max = 0xf; | |
2617 | shift = 2; | |
2618 | *buf = (*buf & 0xf0) | ((val >> 2) & 0xf); | |
2619 | break; | |
2620 | ||
2621 | case BFD_RELOC_SH_IMM8BY2: | |
2622 | max = 0xff; | |
2623 | shift = 1; | |
2624 | *buf = val >> 1; | |
2625 | break; | |
2626 | ||
2627 | case BFD_RELOC_SH_IMM8BY4: | |
2628 | max = 0xff; | |
2629 | shift = 2; | |
2630 | *buf = val >> 2; | |
2631 | break; | |
2632 | ||
2633 | case BFD_RELOC_8: | |
2634 | case BFD_RELOC_SH_IMM8: | |
2635 | /* Sometimes the 8 bit value is sign extended (e.g., add) and | |
2636 | sometimes it is not (e.g., and). We permit any 8 bit value. | |
2637 | Note that adding further restrictions may invalidate | |
2638 | reasonable looking assembly code, such as ``and -0x1,r0''. */ | |
2639 | max = 0xff; | |
2640 | min = - 0xff; | |
2641 | *buf++ = val; | |
2642 | break; | |
2643 | ||
2644 | case BFD_RELOC_SH_PCRELIMM8BY4: | |
2645 | /* The lower two bits of the PC are cleared before the | |
2646 | displacement is added in. We can assume that the destination | |
2647 | is on a 4 byte bounday. If this instruction is also on a 4 | |
2648 | byte boundary, then we want | |
2649 | (target - here) / 4 | |
2650 | and target - here is a multiple of 4. | |
2651 | Otherwise, we are on a 2 byte boundary, and we want | |
2652 | (target - (here - 2)) / 4 | |
2653 | and target - here is not a multiple of 4. Computing | |
2654 | (target - (here - 2)) / 4 == (target - here + 2) / 4 | |
2655 | works for both cases, since in the first case the addition of | |
2656 | 2 will be removed by the division. target - here is in the | |
2657 | variable val. */ | |
2658 | val = (val + 2) / 4; | |
2659 | if (val & ~0xff) | |
2660 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); | |
2661 | buf[lowbyte] = val; | |
2662 | break; | |
2663 | ||
2664 | case BFD_RELOC_SH_PCRELIMM8BY2: | |
2665 | val /= 2; | |
2666 | if (val & ~0xff) | |
2667 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); | |
2668 | buf[lowbyte] = val; | |
2669 | break; | |
2670 | ||
2671 | case BFD_RELOC_SH_PCDISP8BY2: | |
2672 | val /= 2; | |
2673 | if (val < -0x80 || val > 0x7f) | |
2674 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); | |
2675 | buf[lowbyte] = val; | |
2676 | break; | |
2677 | ||
2678 | case BFD_RELOC_SH_PCDISP12BY2: | |
2679 | val /= 2; | |
2680 | if (val < -0x800 || val >= 0x7ff) | |
2681 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); | |
2682 | buf[lowbyte] = val & 0xff; | |
2683 | buf[highbyte] |= (val >> 8) & 0xf; | |
2684 | break; | |
2685 | ||
2686 | case BFD_RELOC_32: | |
2687 | if (! target_big_endian) | |
2688 | { | |
2689 | *buf++ = val >> 0; | |
2690 | *buf++ = val >> 8; | |
2691 | *buf++ = val >> 16; | |
2692 | *buf++ = val >> 24; | |
2693 | } | |
2694 | else | |
2695 | { | |
2696 | *buf++ = val >> 24; | |
2697 | *buf++ = val >> 16; | |
2698 | *buf++ = val >> 8; | |
2699 | *buf++ = val >> 0; | |
2700 | } | |
2701 | break; | |
2702 | ||
2703 | case BFD_RELOC_16: | |
2704 | if (! target_big_endian) | |
2705 | { | |
2706 | *buf++ = val >> 0; | |
2707 | *buf++ = val >> 8; | |
2708 | } | |
2709 | else | |
2710 | { | |
2711 | *buf++ = val >> 8; | |
2712 | *buf++ = val >> 0; | |
2713 | } | |
2714 | break; | |
2715 | ||
2716 | case BFD_RELOC_SH_USES: | |
2717 | /* Pass the value into sh_coff_reloc_mangle. */ | |
2718 | fixP->fx_addnumber = val; | |
2719 | break; | |
2720 | ||
2721 | case BFD_RELOC_SH_COUNT: | |
2722 | case BFD_RELOC_SH_ALIGN: | |
2723 | case BFD_RELOC_SH_CODE: | |
2724 | case BFD_RELOC_SH_DATA: | |
2725 | case BFD_RELOC_SH_LABEL: | |
2726 | /* Nothing to do here. */ | |
2727 | break; | |
2728 | ||
015551fc JR |
2729 | case BFD_RELOC_SH_LOOP_START: |
2730 | case BFD_RELOC_SH_LOOP_END: | |
2731 | ||
252b5132 RH |
2732 | case BFD_RELOC_VTABLE_INHERIT: |
2733 | case BFD_RELOC_VTABLE_ENTRY: | |
2734 | fixP->fx_done = 0; | |
49309057 ILT |
2735 | #ifdef BFD_ASSEMBLER |
2736 | return 0; | |
2737 | #else | |
252b5132 | 2738 | return; |
49309057 | 2739 | #endif |
252b5132 RH |
2740 | |
2741 | default: | |
2742 | abort (); | |
2743 | } | |
2744 | ||
2745 | if (shift != 0) | |
2746 | { | |
2747 | if ((val & ((1 << shift) - 1)) != 0) | |
2748 | as_bad_where (fixP->fx_file, fixP->fx_line, _("misaligned offset")); | |
2749 | if (val >= 0) | |
2750 | val >>= shift; | |
2751 | else | |
2752 | val = ((val >> shift) | |
2753 | | ((long) -1 & ~ ((long) -1 >> shift))); | |
2754 | } | |
2755 | if (max != 0 && (val < min || val > max)) | |
2756 | as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range")); | |
2757 | ||
2758 | #ifdef BFD_ASSEMBLER | |
2759 | return 0; | |
2760 | #endif | |
2761 | } | |
2762 | ||
2763 | /* Called just before address relaxation. Return the length | |
2764 | by which a fragment must grow to reach it's destination. */ | |
2765 | ||
2766 | int | |
2767 | md_estimate_size_before_relax (fragP, segment_type) | |
2768 | register fragS *fragP; | |
2769 | register segT segment_type; | |
2770 | { | |
2771 | switch (fragP->fr_subtype) | |
2772 | { | |
2773 | case C (UNCOND_JUMP, UNDEF_DISP): | |
2774 | /* used to be a branch to somewhere which was unknown */ | |
2775 | if (!fragP->fr_symbol) | |
2776 | { | |
2777 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12); | |
2778 | fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length; | |
2779 | } | |
2780 | else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
2781 | { | |
2782 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12); | |
2783 | fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length; | |
2784 | } | |
2785 | else | |
2786 | { | |
2787 | fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP); | |
2788 | fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length; | |
2789 | return md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length; | |
2790 | } | |
2791 | break; | |
2792 | ||
2793 | default: | |
2794 | abort (); | |
2795 | case C (COND_JUMP, UNDEF_DISP): | |
2796 | case C (COND_JUMP_DELAY, UNDEF_DISP): | |
2797 | /* used to be a branch to somewhere which was unknown */ | |
2798 | if (fragP->fr_symbol | |
2799 | && S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
2800 | { | |
2801 | int what = GET_WHAT (fragP->fr_subtype); | |
2802 | /* Got a symbol and it's defined in this segment, become byte | |
2803 | sized - maybe it will fix up */ | |
2804 | fragP->fr_subtype = C (what, COND8); | |
2805 | fragP->fr_var = md_relax_table[C (what, COND8)].rlx_length; | |
2806 | } | |
2807 | else if (fragP->fr_symbol) | |
2808 | { | |
2809 | int what = GET_WHAT (fragP->fr_subtype); | |
2810 | /* Its got a segment, but its not ours, so it will always be long */ | |
2811 | fragP->fr_subtype = C (what, UNDEF_WORD_DISP); | |
2812 | fragP->fr_var = md_relax_table[C (what, COND32)].rlx_length; | |
2813 | return md_relax_table[C (what, COND32)].rlx_length; | |
2814 | } | |
2815 | else | |
2816 | { | |
2817 | int what = GET_WHAT (fragP->fr_subtype); | |
2818 | /* We know the abs value */ | |
2819 | fragP->fr_subtype = C (what, COND8); | |
2820 | fragP->fr_var = md_relax_table[C (what, COND8)].rlx_length; | |
2821 | } | |
2822 | ||
2823 | break; | |
2824 | } | |
2825 | return fragP->fr_var; | |
2826 | } | |
2827 | ||
2828 | /* Put number into target byte order */ | |
2829 | ||
2830 | void | |
2831 | md_number_to_chars (ptr, use, nbytes) | |
2832 | char *ptr; | |
2833 | valueT use; | |
2834 | int nbytes; | |
2835 | { | |
2836 | if (! target_big_endian) | |
2837 | number_to_chars_littleendian (ptr, use, nbytes); | |
2838 | else | |
2839 | number_to_chars_bigendian (ptr, use, nbytes); | |
2840 | } | |
2841 | ||
2842 | long | |
2843 | md_pcrel_from (fixP) | |
2844 | fixS *fixP; | |
2845 | { | |
2846 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address + 2; | |
2847 | } | |
2848 | ||
2849 | #ifdef OBJ_COFF | |
2850 | ||
2851 | int | |
2852 | tc_coff_sizemachdep (frag) | |
2853 | fragS *frag; | |
2854 | { | |
2855 | return md_relax_table[frag->fr_subtype].rlx_length; | |
2856 | } | |
2857 | ||
2858 | #endif /* OBJ_COFF */ | |
2859 | ||
2860 | /* When we align the .text section, insert the correct NOP pattern. */ | |
2861 | ||
2862 | int | |
2863 | sh_do_align (n, fill, len, max) | |
2864 | int n; | |
2865 | const char *fill; | |
43841e91 | 2866 | int len ATTRIBUTE_UNUSED; |
252b5132 RH |
2867 | int max; |
2868 | { | |
2869 | if (fill == NULL | |
b9e57a38 | 2870 | && subseg_text_p (now_seg) |
252b5132 RH |
2871 | && n > 1) |
2872 | { | |
2873 | static const unsigned char big_nop_pattern[] = { 0x00, 0x09 }; | |
2874 | static const unsigned char little_nop_pattern[] = { 0x09, 0x00 }; | |
2875 | ||
2876 | /* First align to a 2 byte boundary, in case there is an odd | |
2877 | .byte. */ | |
2878 | frag_align (1, 0, 0); | |
2879 | if (target_big_endian) | |
2880 | frag_align_pattern (n, big_nop_pattern, sizeof big_nop_pattern, max); | |
2881 | else | |
2882 | frag_align_pattern (n, little_nop_pattern, sizeof little_nop_pattern, | |
2883 | max); | |
2884 | return 1; | |
2885 | } | |
2886 | ||
2887 | return 0; | |
2888 | } | |
2889 | ||
2890 | #ifndef BFD_ASSEMBLER | |
2891 | #ifdef OBJ_COFF | |
2892 | ||
2893 | /* Map BFD relocs to SH COFF relocs. */ | |
2894 | ||
2895 | struct reloc_map | |
2896 | { | |
2897 | bfd_reloc_code_real_type bfd_reloc; | |
2898 | int sh_reloc; | |
2899 | }; | |
2900 | ||
2901 | static const struct reloc_map coff_reloc_map[] = | |
2902 | { | |
2903 | { BFD_RELOC_32, R_SH_IMM32 }, | |
2904 | { BFD_RELOC_16, R_SH_IMM16 }, | |
2905 | { BFD_RELOC_8, R_SH_IMM8 }, | |
2906 | { BFD_RELOC_SH_PCDISP8BY2, R_SH_PCDISP8BY2 }, | |
2907 | { BFD_RELOC_SH_PCDISP12BY2, R_SH_PCDISP }, | |
2908 | { BFD_RELOC_SH_IMM4, R_SH_IMM4 }, | |
2909 | { BFD_RELOC_SH_IMM4BY2, R_SH_IMM4BY2 }, | |
2910 | { BFD_RELOC_SH_IMM4BY4, R_SH_IMM4BY4 }, | |
2911 | { BFD_RELOC_SH_IMM8, R_SH_IMM8 }, | |
2912 | { BFD_RELOC_SH_IMM8BY2, R_SH_IMM8BY2 }, | |
2913 | { BFD_RELOC_SH_IMM8BY4, R_SH_IMM8BY4 }, | |
2914 | { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_PCRELIMM8BY2 }, | |
2915 | { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_PCRELIMM8BY4 }, | |
2916 | { BFD_RELOC_8_PCREL, R_SH_SWITCH8 }, | |
2917 | { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 }, | |
2918 | { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 }, | |
2919 | { BFD_RELOC_SH_USES, R_SH_USES }, | |
2920 | { BFD_RELOC_SH_COUNT, R_SH_COUNT }, | |
2921 | { BFD_RELOC_SH_ALIGN, R_SH_ALIGN }, | |
2922 | { BFD_RELOC_SH_CODE, R_SH_CODE }, | |
2923 | { BFD_RELOC_SH_DATA, R_SH_DATA }, | |
2924 | { BFD_RELOC_SH_LABEL, R_SH_LABEL }, | |
2925 | { BFD_RELOC_UNUSED, 0 } | |
2926 | }; | |
2927 | ||
2928 | /* Adjust a reloc for the SH. This is similar to the generic code, | |
2929 | but does some minor tweaking. */ | |
2930 | ||
2931 | void | |
2932 | sh_coff_reloc_mangle (seg, fix, intr, paddr) | |
2933 | segment_info_type *seg; | |
2934 | fixS *fix; | |
2935 | struct internal_reloc *intr; | |
2936 | unsigned int paddr; | |
2937 | { | |
2938 | symbolS *symbol_ptr = fix->fx_addsy; | |
2939 | symbolS *dot; | |
2940 | ||
2941 | intr->r_vaddr = paddr + fix->fx_frag->fr_address + fix->fx_where; | |
2942 | ||
2943 | if (! SWITCH_TABLE (fix)) | |
2944 | { | |
2945 | const struct reloc_map *rm; | |
2946 | ||
2947 | for (rm = coff_reloc_map; rm->bfd_reloc != BFD_RELOC_UNUSED; rm++) | |
2948 | if (rm->bfd_reloc == (bfd_reloc_code_real_type) fix->fx_r_type) | |
2949 | break; | |
2950 | if (rm->bfd_reloc == BFD_RELOC_UNUSED) | |
2951 | as_bad_where (fix->fx_file, fix->fx_line, | |
2952 | _("Can not represent %s relocation in this object file format"), | |
2953 | bfd_get_reloc_code_name (fix->fx_r_type)); | |
2954 | intr->r_type = rm->sh_reloc; | |
2955 | intr->r_offset = 0; | |
2956 | } | |
2957 | else | |
2958 | { | |
2959 | know (sh_relax); | |
2960 | ||
2961 | if (fix->fx_r_type == BFD_RELOC_16) | |
2962 | intr->r_type = R_SH_SWITCH16; | |
2963 | else if (fix->fx_r_type == BFD_RELOC_8) | |
2964 | intr->r_type = R_SH_SWITCH8; | |
2965 | else if (fix->fx_r_type == BFD_RELOC_32) | |
2966 | intr->r_type = R_SH_SWITCH32; | |
2967 | else | |
2968 | abort (); | |
2969 | ||
2970 | /* For a switch reloc, we set r_offset to the difference between | |
2971 | the reloc address and the subtrahend. When the linker is | |
2972 | doing relaxing, it can use the determine the starting and | |
2973 | ending points of the switch difference expression. */ | |
2974 | intr->r_offset = intr->r_vaddr - S_GET_VALUE (fix->fx_subsy); | |
2975 | } | |
2976 | ||
2977 | /* PC relative relocs are always against the current section. */ | |
2978 | if (symbol_ptr == NULL) | |
2979 | { | |
2980 | switch (fix->fx_r_type) | |
2981 | { | |
2982 | case BFD_RELOC_SH_PCRELIMM8BY2: | |
2983 | case BFD_RELOC_SH_PCRELIMM8BY4: | |
2984 | case BFD_RELOC_SH_PCDISP8BY2: | |
2985 | case BFD_RELOC_SH_PCDISP12BY2: | |
2986 | case BFD_RELOC_SH_USES: | |
2987 | symbol_ptr = seg->dot; | |
2988 | break; | |
2989 | default: | |
2990 | break; | |
2991 | } | |
2992 | } | |
2993 | ||
2994 | if (fix->fx_r_type == BFD_RELOC_SH_USES) | |
2995 | { | |
2996 | /* We can't store the offset in the object file, since this | |
2997 | reloc does not take up any space, so we store it in r_offset. | |
2998 | The fx_addnumber field was set in md_apply_fix. */ | |
2999 | intr->r_offset = fix->fx_addnumber; | |
3000 | } | |
3001 | else if (fix->fx_r_type == BFD_RELOC_SH_COUNT) | |
3002 | { | |
3003 | /* We can't store the count in the object file, since this reloc | |
3004 | does not take up any space, so we store it in r_offset. The | |
3005 | fx_offset field was set when the fixup was created in | |
3006 | sh_coff_frob_file. */ | |
3007 | intr->r_offset = fix->fx_offset; | |
3008 | /* This reloc is always absolute. */ | |
3009 | symbol_ptr = NULL; | |
3010 | } | |
3011 | else if (fix->fx_r_type == BFD_RELOC_SH_ALIGN) | |
3012 | { | |
3013 | /* Store the alignment in the r_offset field. */ | |
3014 | intr->r_offset = fix->fx_offset; | |
3015 | /* This reloc is always absolute. */ | |
3016 | symbol_ptr = NULL; | |
3017 | } | |
3018 | else if (fix->fx_r_type == BFD_RELOC_SH_CODE | |
3019 | || fix->fx_r_type == BFD_RELOC_SH_DATA | |
3020 | || fix->fx_r_type == BFD_RELOC_SH_LABEL) | |
3021 | { | |
3022 | /* These relocs are always absolute. */ | |
3023 | symbol_ptr = NULL; | |
3024 | } | |
3025 | ||
3026 | /* Turn the segment of the symbol into an offset. */ | |
3027 | if (symbol_ptr != NULL) | |
3028 | { | |
3029 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot; | |
3030 | if (dot != NULL) | |
3031 | intr->r_symndx = dot->sy_number; | |
3032 | else | |
3033 | intr->r_symndx = symbol_ptr->sy_number; | |
3034 | } | |
3035 | else | |
3036 | intr->r_symndx = -1; | |
3037 | } | |
3038 | ||
3039 | #endif /* OBJ_COFF */ | |
3040 | #endif /* ! BFD_ASSEMBLER */ | |
3041 | ||
3042 | #ifdef BFD_ASSEMBLER | |
3043 | ||
3044 | /* Create a reloc. */ | |
3045 | ||
3046 | arelent * | |
3047 | tc_gen_reloc (section, fixp) | |
43841e91 | 3048 | asection *section ATTRIBUTE_UNUSED; |
252b5132 RH |
3049 | fixS *fixp; |
3050 | { | |
3051 | arelent *rel; | |
3052 | bfd_reloc_code_real_type r_type; | |
3053 | ||
3054 | rel = (arelent *) xmalloc (sizeof (arelent)); | |
49309057 ILT |
3055 | rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3056 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
3057 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where; |
3058 | ||
3059 | r_type = fixp->fx_r_type; | |
3060 | ||
3061 | if (SWITCH_TABLE (fixp)) | |
3062 | { | |
3063 | rel->addend = rel->address - S_GET_VALUE (fixp->fx_subsy); | |
3064 | if (r_type == BFD_RELOC_16) | |
3065 | r_type = BFD_RELOC_SH_SWITCH16; | |
3066 | else if (r_type == BFD_RELOC_8) | |
3067 | r_type = BFD_RELOC_8_PCREL; | |
3068 | else if (r_type == BFD_RELOC_32) | |
3069 | r_type = BFD_RELOC_SH_SWITCH32; | |
3070 | else | |
3071 | abort (); | |
3072 | } | |
3073 | else if (r_type == BFD_RELOC_SH_USES) | |
3074 | rel->addend = fixp->fx_addnumber; | |
3075 | else if (r_type == BFD_RELOC_SH_COUNT) | |
3076 | rel->addend = fixp->fx_offset; | |
3077 | else if (r_type == BFD_RELOC_SH_ALIGN) | |
3078 | rel->addend = fixp->fx_offset; | |
3079 | else if (r_type == BFD_RELOC_VTABLE_INHERIT | |
3080 | || r_type == BFD_RELOC_VTABLE_ENTRY) | |
3081 | rel->addend = fixp->fx_offset; | |
015551fc JR |
3082 | else if (r_type == BFD_RELOC_SH_LOOP_START |
3083 | || r_type == BFD_RELOC_SH_LOOP_END) | |
3084 | rel->addend = fixp->fx_offset; | |
3085 | else if (r_type == BFD_RELOC_SH_LABEL && fixp->fx_pcrel) | |
3086 | { | |
3087 | rel->addend = 0; | |
3088 | rel->address = rel->addend = fixp->fx_offset; | |
3089 | } | |
252b5132 RH |
3090 | else if (fixp->fx_pcrel) |
3091 | rel->addend = fixp->fx_addnumber; | |
3092 | else | |
3093 | rel->addend = 0; | |
3094 | ||
3095 | rel->howto = bfd_reloc_type_lookup (stdoutput, r_type); | |
3096 | if (rel->howto == NULL) | |
3097 | { | |
3098 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
3099 | _("Cannot represent relocation type %s"), | |
3100 | bfd_get_reloc_code_name (r_type)); | |
3101 | /* Set howto to a garbage value so that we can keep going. */ | |
3102 | rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); | |
3103 | assert (rel->howto != NULL); | |
3104 | } | |
3105 | ||
3106 | return rel; | |
3107 | } | |
3108 | ||
3109 | #endif /* BFD_ASSEMBLER */ |