]>
Commit | Line | Data |
---|---|---|
c2dcd04e | 1 | /* tc-h8300.c -- Assemble code for the Renesas H8/300 |
cc8a6dd0 | 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, |
c2dcd04e | 3 | 2001, 2002, 2003 Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GAS; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
bc0d738a | 22 | /* Written By Steve Chamberlain <[email protected]>. */ |
252b5132 RH |
23 | |
24 | #include <stdio.h> | |
25 | #include "as.h" | |
26 | #include "subsegs.h" | |
27 | #include "bfd.h" | |
2c8714f2 NC |
28 | |
29 | #ifdef BFD_ASSEMBLER | |
30 | #include "dwarf2dbg.h" | |
31 | #endif | |
32 | ||
252b5132 RH |
33 | #define DEFINE_TABLE |
34 | #define h8_opcodes ops | |
35 | #include "opcode/h8300.h" | |
3882b010 | 36 | #include "safe-ctype.h" |
252b5132 | 37 | |
7e0de7bf JL |
38 | #ifdef OBJ_ELF |
39 | #include "elf/h8.h" | |
7e0de7bf JL |
40 | #endif |
41 | ||
63a0b638 | 42 | const char comment_chars[] = ";"; |
252b5132 | 43 | const char line_comment_chars[] = "#"; |
63a0b638 | 44 | const char line_separator_chars[] = ""; |
252b5132 | 45 | |
3048287a NC |
46 | void cons PARAMS ((int)); |
47 | void sbranch PARAMS ((int)); | |
48 | void h8300hmode PARAMS ((int)); | |
49 | void h8300smode PARAMS ((int)); | |
8d9cd6b1 NC |
50 | void h8300hnmode PARAMS ((int)); |
51 | void h8300snmode PARAMS ((int)); | |
7ee7b84d | 52 | void h8300sxmode PARAMS ((int)); |
3048287a | 53 | static void pint PARAMS ((int)); |
252b5132 RH |
54 | |
55 | int Hmode; | |
56 | int Smode; | |
8d9cd6b1 | 57 | int Nmode; |
7ee7b84d | 58 | int SXmode; |
3048287a | 59 | |
252b5132 | 60 | #define PSIZE (Hmode ? L_32 : L_16) |
252b5132 | 61 | #define DSYMMODE (Hmode ? L_24 : L_16) |
3048287a | 62 | |
c2dcd04e | 63 | int bsize = L_8; /* Default branch displacement. */ |
252b5132 | 64 | |
a720f7bc KD |
65 | struct h8_instruction |
66 | { | |
67 | int length; | |
68 | int noperands; | |
69 | int idx; | |
70 | int size; | |
71 | const struct h8_opcode *opcode; | |
72 | }; | |
73 | ||
74 | struct h8_instruction *h8_instructions; | |
75 | ||
252b5132 | 76 | void |
3048287a NC |
77 | h8300hmode (arg) |
78 | int arg ATTRIBUTE_UNUSED; | |
252b5132 RH |
79 | { |
80 | Hmode = 1; | |
81 | Smode = 0; | |
83e20b45 JL |
82 | #ifdef BFD_ASSEMBLER |
83 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300h)) | |
84 | as_warn (_("could not set architecture and machine")); | |
85 | #endif | |
252b5132 RH |
86 | } |
87 | ||
88 | void | |
3048287a NC |
89 | h8300smode (arg) |
90 | int arg ATTRIBUTE_UNUSED; | |
252b5132 RH |
91 | { |
92 | Smode = 1; | |
93 | Hmode = 1; | |
83e20b45 JL |
94 | #ifdef BFD_ASSEMBLER |
95 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300s)) | |
96 | as_warn (_("could not set architecture and machine")); | |
97 | #endif | |
252b5132 | 98 | } |
70d6ecf3 | 99 | |
8d9cd6b1 NC |
100 | void |
101 | h8300hnmode (arg) | |
102 | int arg ATTRIBUTE_UNUSED; | |
103 | { | |
104 | Hmode = 1; | |
105 | Smode = 0; | |
106 | Nmode = 1; | |
107 | #ifdef BFD_ASSEMBLER | |
108 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300hn)) | |
109 | as_warn (_("could not set architecture and machine")); | |
110 | #endif | |
111 | } | |
112 | ||
113 | void | |
114 | h8300snmode (arg) | |
115 | int arg ATTRIBUTE_UNUSED; | |
116 | { | |
117 | Smode = 1; | |
118 | Hmode = 1; | |
119 | Nmode = 1; | |
120 | #ifdef BFD_ASSEMBLER | |
121 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sn)) | |
122 | as_warn (_("could not set architecture and machine")); | |
123 | #endif | |
124 | } | |
125 | ||
7ee7b84d MS |
126 | void |
127 | h8300sxmode (arg) | |
128 | int arg ATTRIBUTE_UNUSED; | |
129 | { | |
130 | Smode = 1; | |
131 | Hmode = 1; | |
132 | SXmode = 1; | |
133 | #ifdef BFD_ASSEMBLER | |
134 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sx)) | |
135 | as_warn (_("could not set architecture and machine")); | |
136 | #endif | |
137 | } | |
138 | ||
f4984206 RS |
139 | void |
140 | h8300sxnmode (arg) | |
141 | int arg ATTRIBUTE_UNUSED; | |
142 | { | |
143 | Smode = 1; | |
144 | Hmode = 1; | |
145 | SXmode = 1; | |
146 | Nmode = 1; | |
147 | #ifdef BFD_ASSEMBLER | |
148 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sxn)) | |
149 | as_warn (_("could not set architecture and machine")); | |
150 | #endif | |
151 | } | |
152 | ||
252b5132 RH |
153 | void |
154 | sbranch (size) | |
155 | int size; | |
156 | { | |
157 | bsize = size; | |
158 | } | |
159 | ||
70d6ecf3 | 160 | static void |
3048287a NC |
161 | pint (arg) |
162 | int arg ATTRIBUTE_UNUSED; | |
252b5132 RH |
163 | { |
164 | cons (Hmode ? 4 : 2); | |
165 | } | |
166 | ||
3048287a NC |
167 | /* This table describes all the machine specific pseudo-ops the assembler |
168 | has to support. The fields are: | |
169 | pseudo-op name without dot | |
170 | function to call to execute this pseudo-op | |
171 | Integer arg to pass to the function. */ | |
172 | ||
252b5132 RH |
173 | const pseudo_typeS md_pseudo_table[] = |
174 | { | |
7ee7b84d | 175 | {"h8300h", h8300hmode, 0}, |
8d9cd6b1 | 176 | {"h8300hn", h8300hnmode, 0}, |
7ee7b84d | 177 | {"h8300s", h8300smode, 0}, |
8d9cd6b1 | 178 | {"h8300sn", h8300snmode, 0}, |
7ee7b84d | 179 | {"h8300sx", h8300sxmode, 0}, |
f4984206 | 180 | {"h8300sxn", h8300sxnmode, 0}, |
252b5132 RH |
181 | {"sbranch", sbranch, L_8}, |
182 | {"lbranch", sbranch, L_16}, | |
183 | ||
184 | {"int", pint, 0}, | |
185 | {"data.b", cons, 1}, | |
186 | {"data.w", cons, 2}, | |
187 | {"data.l", cons, 4}, | |
188 | {"form", listing_psize, 0}, | |
189 | {"heading", listing_title, 0}, | |
7ee7b84d MS |
190 | {"import", s_ignore, 0}, |
191 | {"page", listing_eject, 0}, | |
252b5132 RH |
192 | {"program", s_ignore, 0}, |
193 | {0, 0, 0} | |
194 | }; | |
195 | ||
196 | const int md_reloc_size; | |
197 | ||
198 | const char EXP_CHARS[] = "eE"; | |
199 | ||
3048287a NC |
200 | /* Chars that mean this number is a floating point constant |
201 | As in 0f12.456 | |
202 | or 0d1.2345e12. */ | |
252b5132 RH |
203 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; |
204 | ||
3048287a | 205 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics. */ |
252b5132 | 206 | |
70d6ecf3 AM |
207 | /* This function is called once, at assembler startup time. This |
208 | should set up all the tables, etc. that the MD part of the assembler | |
209 | needs. */ | |
3048287a | 210 | |
252b5132 RH |
211 | void |
212 | md_begin () | |
213 | { | |
a720f7bc | 214 | unsigned int nopcodes; |
7ee7b84d | 215 | struct h8_opcode *p, *p1; |
a720f7bc | 216 | struct h8_instruction *pi; |
252b5132 RH |
217 | char prev_buffer[100]; |
218 | int idx = 0; | |
219 | ||
83e20b45 JL |
220 | #ifdef BFD_ASSEMBLER |
221 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300)) | |
222 | as_warn (_("could not set architecture and machine")); | |
223 | #endif | |
224 | ||
252b5132 RH |
225 | opcode_hash_control = hash_new (); |
226 | prev_buffer[0] = 0; | |
227 | ||
a720f7bc KD |
228 | nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode); |
229 | ||
230 | h8_instructions = (struct h8_instruction *) | |
231 | xmalloc (nopcodes * sizeof (struct h8_instruction)); | |
232 | ||
7ee7b84d MS |
233 | pi = h8_instructions; |
234 | p1 = h8_opcodes; | |
235 | /* We do a minimum amount of sorting on the opcode table; this is to | |
236 | make it easy to describe the mova instructions without unnecessary | |
237 | code duplication. | |
238 | Sorting only takes place inside blocks of instructions of the form | |
239 | X/Y, so for example mova/b, mova/w and mova/l can be intermixed. */ | |
240 | while (p1) | |
252b5132 | 241 | { |
7ee7b84d MS |
242 | struct h8_opcode *first_skipped = 0; |
243 | int len, cmplen = 0; | |
244 | char *src = p1->name; | |
245 | char *dst, *buffer; | |
252b5132 | 246 | |
7ee7b84d MS |
247 | if (p1->name == 0) |
248 | break; | |
249 | /* Strip off any . part when inserting the opcode and only enter | |
250 | unique codes into the hash table. */ | |
251 | dst = buffer = malloc (strlen (src) + 1); | |
252b5132 RH |
252 | while (*src) |
253 | { | |
254 | if (*src == '.') | |
255 | { | |
256 | src++; | |
252b5132 RH |
257 | break; |
258 | } | |
7ee7b84d MS |
259 | if (*src == '/') |
260 | cmplen = src - p1->name + 1; | |
252b5132 RH |
261 | *dst++ = *src++; |
262 | } | |
7ee7b84d MS |
263 | *dst = 0; |
264 | len = dst - buffer; | |
265 | if (cmplen == 0) | |
266 | cmplen = len; | |
267 | hash_insert (opcode_hash_control, buffer, (char *) pi); | |
268 | strcpy (prev_buffer, buffer); | |
269 | idx++; | |
270 | ||
271 | for (p = p1; p->name; p++) | |
252b5132 | 272 | { |
7ee7b84d MS |
273 | /* A negative TIME is used to indicate that we've added this opcode |
274 | already. */ | |
275 | if (p->time == -1) | |
276 | continue; | |
277 | if (strncmp (p->name, buffer, cmplen) != 0 | |
278 | || (p->name[cmplen] != '\0' && p->name[cmplen] != '.' | |
279 | && p->name[cmplen - 1] != '/')) | |
280 | { | |
281 | if (first_skipped == 0) | |
282 | first_skipped = p; | |
283 | break; | |
284 | } | |
285 | if (strncmp (p->name, buffer, len) != 0) | |
286 | { | |
287 | if (first_skipped == 0) | |
288 | first_skipped = p; | |
289 | continue; | |
290 | } | |
291 | ||
292 | p->time = -1; | |
293 | pi->size = p->name[len] == '.' ? p->name[len + 1] : 0; | |
294 | pi->idx = idx; | |
252b5132 | 295 | |
7ee7b84d MS |
296 | /* Find the number of operands. */ |
297 | pi->noperands = 0; | |
298 | while (pi->noperands < 3 && p->args.nib[pi->noperands] != (op_type) E) | |
299 | pi->noperands++; | |
70d6ecf3 | 300 | |
7ee7b84d MS |
301 | /* Find the length of the opcode in bytes. */ |
302 | pi->length = 0; | |
303 | while (p->data.nib[pi->length * 2] != (op_type) E) | |
304 | pi->length++; | |
a720f7bc | 305 | |
7ee7b84d MS |
306 | pi->opcode = p; |
307 | pi++; | |
308 | } | |
309 | p1 = first_skipped; | |
252b5132 RH |
310 | } |
311 | ||
a720f7bc KD |
312 | /* Add entry for the NULL vector terminator. */ |
313 | pi->length = 0; | |
314 | pi->noperands = 0; | |
315 | pi->idx = 0; | |
316 | pi->size = 0; | |
7ee7b84d | 317 | pi->opcode = 0; |
a720f7bc | 318 | |
252b5132 RH |
319 | linkrelax = 1; |
320 | } | |
321 | ||
252b5132 RH |
322 | struct h8_exp |
323 | { | |
324 | char *e_beg; | |
325 | char *e_end; | |
326 | expressionS e_exp; | |
327 | }; | |
70d6ecf3 | 328 | |
252b5132 RH |
329 | struct h8_op |
330 | { | |
331 | op_type mode; | |
332 | unsigned reg; | |
333 | expressionS exp; | |
334 | }; | |
335 | ||
a720f7bc | 336 | static void clever_message PARAMS ((const struct h8_instruction *, struct h8_op *)); |
d4ea8842 | 337 | static void fix_operand_size PARAMS ((struct h8_op *, int)); |
a720f7bc | 338 | static void build_bytes PARAMS ((const struct h8_instruction *, struct h8_op *)); |
7ee7b84d | 339 | static void do_a_fix_imm PARAMS ((int, int, struct h8_op *, int)); |
3048287a | 340 | static void check_operand PARAMS ((struct h8_op *, unsigned int, char *)); |
a720f7bc | 341 | static const struct h8_instruction * get_specific PARAMS ((const struct h8_instruction *, struct h8_op *, int)); |
3048287a | 342 | static char * get_operands PARAMS ((unsigned, char *, struct h8_op *)); |
7ee7b84d | 343 | static void get_operand PARAMS ((char **, struct h8_op *, int)); |
3048287a NC |
344 | static char * skip_colonthing PARAMS ((char *, expressionS *, int *)); |
345 | static char * parse_exp PARAMS ((char *, expressionS *)); | |
346 | static int parse_reg PARAMS ((char *, op_type *, unsigned *, int)); | |
347 | char * colonmod24 PARAMS ((struct h8_op *, char *)); | |
348 | ||
7ee7b84d MS |
349 | static int constant_fits_width_p PARAMS ((struct h8_op *, unsigned int)); |
350 | static int constant_fits_size_p PARAMS ((struct h8_op *, int, int)); | |
351 | ||
252b5132 RH |
352 | /* |
353 | parse operands | |
354 | WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp | |
355 | r0l,r0h,..r7l,r7h | |
356 | @WREG | |
357 | @WREG+ | |
358 | @-WREG | |
359 | #const | |
360 | ccr | |
361 | */ | |
362 | ||
bc0d738a NC |
363 | /* Try to parse a reg name. Return the number of chars consumed. */ |
364 | ||
40f09f82 | 365 | static int |
252b5132 RH |
366 | parse_reg (src, mode, reg, direction) |
367 | char *src; | |
368 | op_type *mode; | |
369 | unsigned int *reg; | |
370 | int direction; | |
252b5132 RH |
371 | { |
372 | char *end; | |
373 | int len; | |
374 | ||
70d6ecf3 | 375 | /* Cribbed from get_symbol_end. */ |
252b5132 RH |
376 | if (!is_name_beginner (*src) || *src == '\001') |
377 | return 0; | |
70d6ecf3 | 378 | end = src + 1; |
7ee7b84d | 379 | while ((is_part_of_name (*end) && *end != '.') || *end == '\001') |
252b5132 RH |
380 | end++; |
381 | len = end - src; | |
382 | ||
7ee7b84d | 383 | if (len == 2 && TOLOWER (src[0]) == 's' && TOLOWER (src[1]) == 'p') |
252b5132 RH |
384 | { |
385 | *mode = PSIZE | REG | direction; | |
386 | *reg = 7; | |
387 | return len; | |
388 | } | |
7ee7b84d MS |
389 | if (len == 3 && |
390 | TOLOWER (src[0]) == 'c' && | |
391 | TOLOWER (src[1]) == 'c' && | |
392 | TOLOWER (src[2]) == 'r') | |
252b5132 RH |
393 | { |
394 | *mode = CCR; | |
395 | *reg = 0; | |
396 | return len; | |
397 | } | |
7ee7b84d MS |
398 | if (len == 3 && |
399 | TOLOWER (src[0]) == 'e' && | |
400 | TOLOWER (src[1]) == 'x' && | |
401 | TOLOWER (src[2]) == 'r') | |
252b5132 RH |
402 | { |
403 | *mode = EXR; | |
7ee7b84d MS |
404 | *reg = 1; |
405 | return len; | |
406 | } | |
407 | if (len == 3 && | |
408 | TOLOWER (src[0]) == 'v' && | |
409 | TOLOWER (src[1]) == 'b' && | |
410 | TOLOWER (src[2]) == 'r') | |
411 | { | |
412 | *mode = VBR; | |
413 | *reg = 6; | |
414 | return len; | |
415 | } | |
416 | if (len == 3 && | |
417 | TOLOWER (src[0]) == 's' && | |
418 | TOLOWER (src[1]) == 'b' && | |
419 | TOLOWER (src[2]) == 'r') | |
420 | { | |
421 | *mode = SBR; | |
422 | *reg = 7; | |
252b5132 RH |
423 | return len; |
424 | } | |
7ee7b84d | 425 | if (len == 2 && TOLOWER (src[0]) == 'f' && TOLOWER (src[1]) == 'p') |
252b5132 RH |
426 | { |
427 | *mode = PSIZE | REG | direction; | |
428 | *reg = 6; | |
429 | return len; | |
430 | } | |
7ee7b84d MS |
431 | if (len == 3 && TOLOWER (src[0]) == 'e' && TOLOWER (src[1]) == 'r' && |
432 | src[2] >= '0' && src[2] <= '7') | |
252b5132 RH |
433 | { |
434 | *mode = L_32 | REG | direction; | |
435 | *reg = src[2] - '0'; | |
436 | if (!Hmode) | |
437 | as_warn (_("Reg not valid for H8/300")); | |
438 | return len; | |
439 | } | |
7ee7b84d | 440 | if (len == 2 && TOLOWER (src[0]) == 'e' && src[1] >= '0' && src[1] <= '7') |
252b5132 RH |
441 | { |
442 | *mode = L_16 | REG | direction; | |
443 | *reg = src[1] - '0' + 8; | |
444 | if (!Hmode) | |
445 | as_warn (_("Reg not valid for H8/300")); | |
446 | return len; | |
447 | } | |
448 | ||
7ee7b84d | 449 | if (TOLOWER (src[0]) == 'r') |
252b5132 RH |
450 | { |
451 | if (src[1] >= '0' && src[1] <= '7') | |
452 | { | |
7ee7b84d | 453 | if (len == 3 && TOLOWER (src[2]) == 'l') |
252b5132 RH |
454 | { |
455 | *mode = L_8 | REG | direction; | |
456 | *reg = (src[1] - '0') + 8; | |
457 | return len; | |
458 | } | |
7ee7b84d | 459 | if (len == 3 && TOLOWER (src[2]) == 'h') |
252b5132 RH |
460 | { |
461 | *mode = L_8 | REG | direction; | |
462 | *reg = (src[1] - '0'); | |
463 | return len; | |
464 | } | |
465 | if (len == 2) | |
466 | { | |
467 | *mode = L_16 | REG | direction; | |
468 | *reg = (src[1] - '0'); | |
469 | return len; | |
470 | } | |
471 | } | |
472 | } | |
473 | ||
474 | return 0; | |
475 | } | |
476 | ||
40f09f82 | 477 | static char * |
252b5132 RH |
478 | parse_exp (s, op) |
479 | char *s; | |
70d6ecf3 | 480 | expressionS *op; |
252b5132 RH |
481 | { |
482 | char *save = input_line_pointer; | |
483 | char *new; | |
484 | ||
485 | input_line_pointer = s; | |
486 | expression (op); | |
487 | if (op->X_op == O_absent) | |
488 | as_bad (_("missing operand")); | |
489 | new = input_line_pointer; | |
490 | input_line_pointer = save; | |
491 | return new; | |
492 | } | |
493 | ||
494 | static char * | |
495 | skip_colonthing (ptr, exp, mode) | |
496 | char *ptr; | |
dbbc7809 | 497 | expressionS *exp ATTRIBUTE_UNUSED; |
252b5132 RH |
498 | int *mode; |
499 | { | |
500 | if (*ptr == ':') | |
501 | { | |
502 | ptr++; | |
503 | *mode &= ~SIZE; | |
7ee7b84d MS |
504 | if (ptr[0] == '8' && ! ISDIGIT (ptr[1])) |
505 | *mode |= L_8; | |
506 | else if (ptr[0] == '2' && ! ISDIGIT (ptr[1])) | |
507 | *mode |= L_2; | |
508 | else if (ptr[0] == '3' && ! ISDIGIT (ptr[1])) | |
509 | *mode |= L_3; | |
510 | else if (ptr[0] == '4' && ! ISDIGIT (ptr[1])) | |
511 | *mode |= L_4; | |
512 | else if (ptr[0] == '5' && ! ISDIGIT (ptr[1])) | |
513 | *mode |= L_5; | |
514 | else if (ptr[0] == '2' && ptr[1] == '4') | |
515 | *mode |= L_24; | |
516 | else if (ptr[0] == '3' && ptr[1] == '2') | |
517 | *mode |= L_32; | |
518 | else if (ptr[0] == '1' && ptr[1] == '6') | |
519 | *mode |= L_16; | |
252b5132 | 520 | else |
7ee7b84d MS |
521 | as_bad (_("invalid operand size requested")); |
522 | ||
523 | while (ISDIGIT (*ptr)) | |
524 | ptr++; | |
252b5132 RH |
525 | } |
526 | return ptr; | |
527 | } | |
528 | ||
529 | /* The many forms of operand: | |
530 | ||
531 | Rn Register direct | |
532 | @Rn Register indirect | |
533 | @(exp[:16], Rn) Register indirect with displacement | |
534 | @Rn+ | |
535 | @-Rn | |
70d6ecf3 AM |
536 | @aa:8 absolute 8 bit |
537 | @aa:16 absolute 16 bit | |
252b5132 RH |
538 | @aa absolute 16 bit |
539 | ||
540 | #xx[:size] immediate data | |
70d6ecf3 | 541 | @(exp:[8], pc) pc rel |
3048287a | 542 | @@aa[:8] memory indirect. */ |
252b5132 RH |
543 | |
544 | char * | |
545 | colonmod24 (op, src) | |
546 | struct h8_op *op; | |
547 | char *src; | |
252b5132 RH |
548 | { |
549 | int mode = 0; | |
550 | src = skip_colonthing (src, &op->exp, &mode); | |
551 | ||
552 | if (!mode) | |
553 | { | |
d4ea8842 MS |
554 | /* If the operand is a 16-bit constant integer, leave fix_operand_size |
555 | to calculate its size. Otherwise choose a default here. */ | |
252b5132 RH |
556 | if (op->exp.X_add_number < -32768 |
557 | || op->exp.X_add_number > 32767) | |
558 | { | |
559 | if (Hmode) | |
560 | mode = L_24; | |
561 | else | |
562 | mode = L_16; | |
563 | } | |
564 | else if (op->exp.X_add_symbol | |
565 | || op->exp.X_op_symbol) | |
566 | mode = DSYMMODE; | |
252b5132 | 567 | } |
3048287a | 568 | |
252b5132 RH |
569 | op->mode |= mode; |
570 | return src; | |
252b5132 RH |
571 | } |
572 | ||
7ee7b84d MS |
573 | static int |
574 | constant_fits_width_p (operand, width) | |
575 | struct h8_op *operand; | |
576 | unsigned int width; | |
577 | { | |
578 | return ((operand->exp.X_add_number & ~width) == 0 | |
579 | || (operand->exp.X_add_number | width) == (unsigned)(~0)); | |
580 | } | |
581 | ||
582 | static int | |
583 | constant_fits_size_p (operand, size, no_symbols) | |
584 | struct h8_op *operand; | |
585 | int size, no_symbols; | |
586 | { | |
587 | offsetT num = operand->exp.X_add_number; | |
588 | if (no_symbols | |
589 | && (operand->exp.X_add_symbol != 0 || operand->exp.X_op_symbol != 0)) | |
590 | return 0; | |
591 | switch (size) | |
592 | { | |
593 | case L_2: | |
594 | return (num & ~3) == 0; | |
595 | case L_3: | |
596 | return (num & ~7) == 0; | |
597 | case L_3NZ: | |
598 | return num >= 1 && num < 8; | |
599 | case L_4: | |
600 | return (num & ~15) == 0; | |
601 | case L_5: | |
602 | return num >= 1 && num < 32; | |
603 | case L_8: | |
604 | return (num & ~0xFF) == 0 || ((unsigned)num | 0x7F) == ~0u; | |
605 | case L_8U: | |
606 | return (num & ~0xFF) == 0; | |
607 | case L_16: | |
608 | return (num & ~0xFFFF) == 0 || ((unsigned)num | 0x7FFF) == ~0u; | |
609 | case L_16U: | |
610 | return (num & ~0xFFFF) == 0; | |
611 | case L_32: | |
612 | return 1; | |
613 | default: | |
614 | abort (); | |
615 | } | |
616 | } | |
617 | ||
252b5132 | 618 | static void |
7ee7b84d | 619 | get_operand (ptr, op, direction) |
252b5132 RH |
620 | char **ptr; |
621 | struct h8_op *op; | |
252b5132 RH |
622 | int direction; |
623 | { | |
624 | char *src = *ptr; | |
625 | op_type mode; | |
626 | unsigned int num; | |
627 | unsigned int len; | |
628 | ||
7ee7b84d | 629 | op->mode = 0; |
252b5132 | 630 | |
3048287a NC |
631 | /* Check for '(' and ')' for instructions ldm and stm. */ |
632 | if (src[0] == '(' && src[8] == ')') | |
633 | ++ src; | |
634 | ||
252b5132 RH |
635 | /* Gross. Gross. ldm and stm have a format not easily handled |
636 | by get_operand. We deal with it explicitly here. */ | |
7ee7b84d MS |
637 | if (TOLOWER (src[0]) == 'e' && TOLOWER (src[1]) == 'r' && |
638 | ISDIGIT (src[2]) && src[3] == '-' && | |
639 | TOLOWER (src[4]) == 'e' && TOLOWER (src[5]) == 'r' && ISDIGIT (src[6])) | |
252b5132 RH |
640 | { |
641 | int low, high; | |
642 | ||
643 | low = src[2] - '0'; | |
644 | high = src[6] - '0'; | |
645 | ||
7ee7b84d | 646 | if (high == low) |
252b5132 RH |
647 | as_bad (_("Invalid register list for ldm/stm\n")); |
648 | ||
7ee7b84d | 649 | if (high < low) |
252b5132 RH |
650 | as_bad (_("Invalid register list for ldm/stm\n")); |
651 | ||
652 | if (high - low > 3) | |
7ee7b84d | 653 | as_bad (_("Invalid register list for ldm/stm)\n")); |
252b5132 RH |
654 | |
655 | /* Even sicker. We encode two registers into op->reg. One | |
656 | for the low register to save, the other for the high | |
657 | register to save; we also set the high bit in op->reg | |
658 | so we know this is "very special". */ | |
659 | op->reg = 0x80000000 | (high << 8) | low; | |
660 | op->mode = REG; | |
3048287a NC |
661 | if (src[7] == ')') |
662 | *ptr = src + 8; | |
663 | else | |
664 | *ptr = src + 7; | |
252b5132 RH |
665 | return; |
666 | } | |
667 | ||
668 | len = parse_reg (src, &op->mode, &op->reg, direction); | |
669 | if (len) | |
670 | { | |
7ee7b84d MS |
671 | src += len; |
672 | if (*src == '.') | |
673 | { | |
674 | int size = op->mode & SIZE; | |
675 | switch (src[1]) | |
676 | { | |
677 | case 'l': case 'L': | |
678 | if (size != L_32) | |
679 | as_warn (_("mismatch between register and suffix")); | |
680 | op->mode = (op->mode & ~MODE) | LOWREG; | |
681 | break; | |
682 | case 'w': case 'W': | |
683 | if (size != L_32 && size != L_16) | |
684 | as_warn (_("mismatch between register and suffix")); | |
685 | op->mode = (op->mode & ~MODE) | LOWREG; | |
686 | op->mode = (op->mode & ~SIZE) | L_16; | |
687 | break; | |
688 | case 'b': case 'B': | |
689 | op->mode = (op->mode & ~MODE) | LOWREG; | |
690 | if (size != L_32 && size != L_8) | |
691 | as_warn (_("mismatch between register and suffix")); | |
692 | op->mode = (op->mode & ~MODE) | LOWREG; | |
693 | op->mode = (op->mode & ~SIZE) | L_8; | |
694 | break; | |
695 | default: | |
696 | as_warn ("invalid suffix after register."); | |
697 | break; | |
698 | } | |
699 | src += 2; | |
700 | } | |
701 | *ptr = src; | |
252b5132 RH |
702 | return; |
703 | } | |
704 | ||
705 | if (*src == '@') | |
706 | { | |
707 | src++; | |
708 | if (*src == '@') | |
709 | { | |
710 | src++; | |
711 | src = parse_exp (src, &op->exp); | |
712 | ||
713 | src = skip_colonthing (src, &op->exp, &op->mode); | |
714 | ||
715 | *ptr = src; | |
716 | ||
7ee7b84d MS |
717 | if (op->exp.X_add_number >= 0x100) |
718 | { | |
719 | int divisor; | |
720 | ||
721 | op->mode = VECIND; | |
722 | /* FIXME : 2? or 4? */ | |
723 | if (op->exp.X_add_number >= 0x400) | |
724 | as_bad (_("address too high for vector table jmp/jsr")); | |
725 | else if (op->exp.X_add_number >= 0x200) | |
726 | divisor = 4; | |
727 | else | |
728 | divisor = 2; | |
729 | ||
730 | op->exp.X_add_number = op->exp.X_add_number / divisor - 0x80; | |
731 | } | |
732 | else | |
733 | op->mode = MEMIND; | |
734 | ||
252b5132 | 735 | return; |
252b5132 RH |
736 | } |
737 | ||
7ee7b84d | 738 | if (*src == '-' || *src == '+') |
252b5132 | 739 | { |
7ee7b84d | 740 | char c = *src; |
252b5132 RH |
741 | src++; |
742 | len = parse_reg (src, &mode, &num, direction); | |
743 | if (len == 0) | |
744 | { | |
70d6ecf3 | 745 | /* Oops, not a reg after all, must be ordinary exp. */ |
252b5132 | 746 | src--; |
70d6ecf3 | 747 | /* Must be a symbol. */ |
252b5132 RH |
748 | op->mode = ABS | PSIZE | direction; |
749 | *ptr = skip_colonthing (parse_exp (src, &op->exp), | |
750 | &op->exp, &op->mode); | |
751 | ||
752 | return; | |
252b5132 RH |
753 | } |
754 | ||
252b5132 RH |
755 | if ((mode & SIZE) != PSIZE) |
756 | as_bad (_("Wrong size pointer register for architecture.")); | |
7ee7b84d | 757 | op->mode = c == '-' ? RDPREDEC : RDPREINC; |
252b5132 RH |
758 | op->reg = num; |
759 | *ptr = src + len; | |
760 | return; | |
761 | } | |
762 | if (*src == '(') | |
763 | { | |
252b5132 RH |
764 | src++; |
765 | ||
7ee7b84d MS |
766 | /* See if this is @(ERn.x, PC). */ |
767 | len = parse_reg (src, &mode, &op->reg, direction); | |
768 | if (len != 0 && (mode & MODE) == REG && src[len] == '.') | |
769 | { | |
770 | switch (TOLOWER (src[len + 1])) | |
771 | { | |
772 | case 'b': | |
773 | mode = PCIDXB | direction; | |
774 | break; | |
775 | case 'w': | |
776 | mode = PCIDXW | direction; | |
777 | break; | |
778 | case 'l': | |
779 | mode = PCIDXL | direction; | |
780 | break; | |
781 | default: | |
782 | mode = 0; | |
783 | break; | |
784 | } | |
785 | if (mode | |
786 | && src[len + 2] == ',' | |
787 | && TOLOWER (src[len + 3]) != 'p' | |
788 | && TOLOWER (src[len + 4]) != 'c' | |
789 | && src[len + 5] != ')') | |
790 | { | |
791 | *ptr = src + len + 6; | |
792 | op->mode |= mode; | |
793 | return; | |
794 | } | |
795 | /* Fall through into disp case - the grammar is somewhat | |
796 | ambiguous, so we should try whether it's a DISP operand | |
797 | after all ("ER3.L" might be a poorly named label...). */ | |
798 | } | |
799 | ||
800 | /* Disp. */ | |
801 | ||
70d6ecf3 | 802 | /* Start off assuming a 16 bit offset. */ |
252b5132 RH |
803 | |
804 | src = parse_exp (src, &op->exp); | |
805 | ||
806 | src = colonmod24 (op, src); | |
807 | ||
808 | if (*src == ')') | |
809 | { | |
810 | src++; | |
811 | op->mode |= ABS | direction; | |
812 | *ptr = src; | |
813 | return; | |
814 | } | |
815 | ||
816 | if (*src != ',') | |
817 | { | |
818 | as_bad (_("expected @(exp, reg16)")); | |
819 | return; | |
820 | ||
821 | } | |
822 | src++; | |
823 | ||
824 | len = parse_reg (src, &mode, &op->reg, direction); | |
7ee7b84d | 825 | if (len == 0 || (mode & MODE) != REG) |
252b5132 RH |
826 | { |
827 | as_bad (_("expected @(exp, reg16)")); | |
828 | return; | |
829 | } | |
252b5132 | 830 | src += len; |
7ee7b84d MS |
831 | if (src[0] == '.') |
832 | { | |
833 | switch (TOLOWER (src[1])) | |
834 | { | |
835 | case 'b': | |
836 | op->mode |= INDEXB | direction; | |
837 | break; | |
838 | case 'w': | |
839 | op->mode |= INDEXW | direction; | |
840 | break; | |
841 | case 'l': | |
842 | op->mode |= INDEXL | direction; | |
843 | break; | |
844 | default: | |
845 | as_bad (_("expected .L, .W or .B for register in indexed addressing mode")); | |
846 | } | |
847 | src += 2; | |
848 | op->reg &= 7; | |
849 | } | |
850 | else | |
851 | op->mode |= DISP | direction; | |
252b5132 RH |
852 | src = skip_colonthing (src, &op->exp, &op->mode); |
853 | ||
854 | if (*src != ')' && '(') | |
855 | { | |
856 | as_bad (_("expected @(exp, reg16)")); | |
857 | return; | |
858 | } | |
859 | *ptr = src + 1; | |
860 | ||
861 | return; | |
862 | } | |
863 | len = parse_reg (src, &mode, &num, direction); | |
864 | ||
865 | if (len) | |
866 | { | |
867 | src += len; | |
7ee7b84d | 868 | if (*src == '+' || *src == '-') |
252b5132 | 869 | { |
252b5132 RH |
870 | if ((mode & SIZE) != PSIZE) |
871 | as_bad (_("Wrong size pointer register for architecture.")); | |
7ee7b84d | 872 | op->mode = *src == '+' ? RSPOSTINC : RSPOSTDEC; |
252b5132 | 873 | op->reg = num; |
7ee7b84d | 874 | src++; |
252b5132 RH |
875 | *ptr = src; |
876 | return; | |
877 | } | |
878 | if ((mode & SIZE) != PSIZE) | |
879 | as_bad (_("Wrong size pointer register for architecture.")); | |
880 | ||
881 | op->mode = direction | IND | PSIZE; | |
882 | op->reg = num; | |
883 | *ptr = src; | |
884 | ||
885 | return; | |
886 | } | |
887 | else | |
888 | { | |
889 | /* must be a symbol */ | |
890 | ||
891 | op->mode = ABS | direction; | |
892 | src = parse_exp (src, &op->exp); | |
893 | ||
894 | *ptr = colonmod24 (op, src); | |
895 | ||
896 | return; | |
897 | } | |
898 | } | |
899 | ||
252b5132 RH |
900 | if (*src == '#') |
901 | { | |
902 | src++; | |
903 | op->mode = IMM; | |
904 | src = parse_exp (src, &op->exp); | |
905 | *ptr = skip_colonthing (src, &op->exp, &op->mode); | |
906 | ||
907 | return; | |
908 | } | |
7ee7b84d MS |
909 | else if (strncmp (src, "mach", 4) == 0 || |
910 | strncmp (src, "macl", 4) == 0 || | |
911 | strncmp (src, "MACH", 4) == 0 || | |
912 | strncmp (src, "MACL", 4) == 0) | |
252b5132 | 913 | { |
7ee7b84d | 914 | op->reg = TOLOWER (src[3]) == 'l'; |
252b5132 RH |
915 | op->mode = MACREG; |
916 | *ptr = src + 4; | |
917 | return; | |
918 | } | |
919 | else | |
920 | { | |
921 | src = parse_exp (src, &op->exp); | |
922 | /* Trailing ':' size ? */ | |
923 | if (*src == ':') | |
924 | { | |
925 | if (src[1] == '1' && src[2] == '6') | |
926 | { | |
927 | op->mode = PCREL | L_16; | |
928 | src += 3; | |
929 | } | |
930 | else if (src[1] == '8') | |
931 | { | |
932 | op->mode = PCREL | L_8; | |
933 | src += 2; | |
934 | } | |
935 | else | |
3048287a | 936 | as_bad (_("expect :8 or :16 here")); |
252b5132 RH |
937 | } |
938 | else | |
7ee7b84d MS |
939 | { |
940 | int val = op->exp.X_add_number; | |
941 | ||
942 | op->mode = PCREL; | |
943 | if (-128 < val && val < 127) | |
944 | op->mode |= L_8; | |
945 | else | |
946 | op->mode |= L_16; | |
947 | } | |
3048287a | 948 | |
252b5132 RH |
949 | *ptr = src; |
950 | } | |
951 | } | |
952 | ||
70d6ecf3 | 953 | static char * |
252b5132 RH |
954 | get_operands (noperands, op_end, operand) |
955 | unsigned int noperands; | |
956 | char *op_end; | |
957 | struct h8_op *operand; | |
958 | { | |
959 | char *ptr = op_end; | |
960 | ||
961 | switch (noperands) | |
962 | { | |
963 | case 0: | |
252b5132 RH |
964 | break; |
965 | ||
966 | case 1: | |
967 | ptr++; | |
7ee7b84d | 968 | get_operand (&ptr, operand + 0, SRC); |
252b5132 RH |
969 | if (*ptr == ',') |
970 | { | |
971 | ptr++; | |
7ee7b84d | 972 | get_operand (&ptr, operand + 1, DST); |
252b5132 | 973 | } |
252b5132 | 974 | break; |
70d6ecf3 | 975 | |
252b5132 RH |
976 | case 2: |
977 | ptr++; | |
7ee7b84d | 978 | get_operand (&ptr, operand + 0, SRC); |
252b5132 RH |
979 | if (*ptr == ',') |
980 | ptr++; | |
7ee7b84d MS |
981 | get_operand (&ptr, operand + 1, DST); |
982 | break; | |
983 | ||
984 | case 3: | |
985 | ptr++; | |
986 | get_operand (&ptr, operand + 0, SRC); | |
987 | if (*ptr == ',') | |
988 | ptr++; | |
989 | get_operand (&ptr, operand + 1, DST); | |
990 | if (*ptr == ',') | |
991 | ptr++; | |
992 | get_operand (&ptr, operand + 2, OP3); | |
252b5132 RH |
993 | break; |
994 | ||
995 | default: | |
996 | abort (); | |
997 | } | |
998 | ||
252b5132 RH |
999 | return ptr; |
1000 | } | |
1001 | ||
7ee7b84d MS |
1002 | /* MOVA has special requirements. Rather than adding twice the amount of |
1003 | addressing modes, we simply special case it a bit. */ | |
1004 | static void | |
1005 | get_mova_operands (char *op_end, struct h8_op *operand) | |
1006 | { | |
1007 | char *ptr = op_end; | |
1008 | ||
1009 | if (ptr[1] != '@' || ptr[2] != '(') | |
1010 | goto error; | |
1011 | ptr += 3; | |
1012 | operand[0].mode = 0; | |
1013 | ptr = parse_exp (ptr, &operand[0].exp); | |
1014 | ptr = colonmod24 (operand + 0, ptr); | |
1015 | ||
1016 | if (*ptr !=',') | |
1017 | goto error; | |
1018 | ptr++; | |
1019 | get_operand (&ptr, operand + 1, DST); | |
1020 | ||
1021 | if (*ptr =='.') | |
1022 | { | |
1023 | ptr++; | |
1024 | switch (*ptr++) | |
1025 | { | |
1026 | case 'b': case 'B': | |
1027 | operand[0].mode = (operand[0].mode & ~MODE) | INDEXB; | |
1028 | break; | |
1029 | case 'w': case 'W': | |
1030 | operand[0].mode = (operand[0].mode & ~MODE) | INDEXW; | |
1031 | break; | |
1032 | case 'l': case 'L': | |
1033 | operand[0].mode = (operand[0].mode & ~MODE) | INDEXL; | |
1034 | break; | |
1035 | default: | |
1036 | goto error; | |
1037 | } | |
1038 | } | |
1039 | else if ((operand[1].mode & MODE) == LOWREG) | |
1040 | { | |
1041 | switch (operand[1].mode & SIZE) | |
1042 | { | |
1043 | case L_8: | |
1044 | operand[0].mode = (operand[0].mode & ~MODE) | INDEXB; | |
1045 | break; | |
1046 | case L_16: | |
1047 | operand[0].mode = (operand[0].mode & ~MODE) | INDEXW; | |
1048 | break; | |
1049 | case L_32: | |
1050 | operand[0].mode = (operand[0].mode & ~MODE) | INDEXL; | |
1051 | break; | |
1052 | default: | |
1053 | goto error; | |
1054 | } | |
1055 | } | |
1056 | else | |
1057 | goto error; | |
1058 | ||
1059 | if (*ptr++ != ')' || *ptr++ != ',') | |
1060 | goto error; | |
1061 | get_operand (&ptr, operand + 2, OP3); | |
1062 | /* See if we can use the short form of MOVA. */ | |
1063 | if (((operand[1].mode & MODE) == REG || (operand[1].mode & MODE) == LOWREG) | |
1064 | && (operand[2].mode & MODE) == REG | |
1065 | && (operand[1].reg & 7) == (operand[2].reg & 7)) | |
1066 | { | |
1067 | operand[1].mode = operand[2].mode = 0; | |
1068 | operand[0].reg = operand[2].reg & 7; | |
1069 | } | |
1070 | return; | |
1071 | ||
1072 | error: | |
1073 | as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\"")); | |
1074 | return; | |
1075 | } | |
1076 | ||
1077 | static void | |
1078 | get_rtsl_operands (char *ptr, struct h8_op *operand) | |
1079 | { | |
1080 | int mode, num, num2, len, type = 0; | |
1081 | ||
1082 | ptr++; | |
1083 | if (*ptr == '(') | |
1084 | { | |
1085 | ptr++; | |
1086 | type = 1; | |
1087 | } | |
1088 | len = parse_reg (ptr, &mode, &num, SRC); | |
1089 | if (len == 0 || (mode & MODE) != REG) | |
1090 | { | |
1091 | as_bad (_("expected register")); | |
1092 | return; | |
1093 | } | |
0613284f RS |
1094 | ptr += len; |
1095 | if (*ptr == '-') | |
7ee7b84d | 1096 | { |
0613284f | 1097 | len = parse_reg (++ptr, &mode, &num2, SRC); |
7ee7b84d MS |
1098 | if (len == 0 || (mode & MODE) != REG) |
1099 | { | |
1100 | as_bad (_("expected register")); | |
1101 | return; | |
1102 | } | |
1103 | ptr += len; | |
7ee7b84d MS |
1104 | /* CONST_xxx are used as placeholders in the opcode table. */ |
1105 | num = num2 - num; | |
0613284f | 1106 | if (num < 0 || num > 3) |
7ee7b84d MS |
1107 | { |
1108 | as_bad (_("invalid register list")); | |
1109 | return; | |
1110 | } | |
1111 | } | |
1112 | else | |
1113 | num2 = num, num = 0; | |
0613284f RS |
1114 | if (type == 1 && *ptr++ != ')') |
1115 | { | |
1116 | as_bad (_("expected closing paren")); | |
1117 | return; | |
1118 | } | |
7ee7b84d MS |
1119 | operand[0].mode = RS32; |
1120 | operand[1].mode = RD32; | |
1121 | operand[0].reg = num; | |
1122 | operand[1].reg = num2; | |
1123 | } | |
1124 | ||
252b5132 RH |
1125 | /* Passed a pointer to a list of opcodes which use different |
1126 | addressing modes, return the opcode which matches the opcodes | |
70d6ecf3 | 1127 | provided. */ |
3048287a | 1128 | |
a720f7bc KD |
1129 | static const struct h8_instruction * |
1130 | get_specific (instruction, operands, size) | |
1131 | const struct h8_instruction *instruction; | |
252b5132 RH |
1132 | struct h8_op *operands; |
1133 | int size; | |
1134 | { | |
a720f7bc | 1135 | const struct h8_instruction *this_try = instruction; |
7ee7b84d | 1136 | const struct h8_instruction *found_other = 0, *found_mismatched = 0; |
252b5132 | 1137 | int found = 0; |
a720f7bc | 1138 | int this_index = instruction->idx; |
7ee7b84d | 1139 | int noperands = 0; |
252b5132 RH |
1140 | |
1141 | /* There's only one ldm/stm and it's easier to just | |
1142 | get out quick for them. */ | |
7ee7b84d MS |
1143 | if (OP_KIND (instruction->opcode->how) == O_LDM |
1144 | || OP_KIND (instruction->opcode->how) == O_STM) | |
252b5132 RH |
1145 | return this_try; |
1146 | ||
7ee7b84d MS |
1147 | while (noperands < 3 && operands[noperands].mode != 0) |
1148 | noperands++; | |
1149 | ||
a720f7bc | 1150 | while (this_index == instruction->idx && !found) |
252b5132 | 1151 | { |
7ee7b84d | 1152 | int this_size; |
252b5132 | 1153 | |
7ee7b84d | 1154 | found = 1; |
a720f7bc | 1155 | this_try = instruction++; |
7ee7b84d | 1156 | this_size = this_try->opcode->how & SN; |
252b5132 | 1157 | |
7ee7b84d MS |
1158 | if (this_try->noperands != noperands) |
1159 | found = 0; | |
1160 | else if (this_try->noperands > 0) | |
252b5132 | 1161 | { |
3048287a | 1162 | int i; |
252b5132 RH |
1163 | |
1164 | for (i = 0; i < this_try->noperands && found; i++) | |
1165 | { | |
a720f7bc | 1166 | op_type op = this_try->opcode->args.nib[i]; |
7ee7b84d MS |
1167 | int op_mode = op & MODE; |
1168 | int op_size = op & SIZE; | |
252b5132 | 1169 | int x = operands[i].mode; |
7ee7b84d MS |
1170 | int x_mode = x & MODE; |
1171 | int x_size = x & SIZE; | |
252b5132 | 1172 | |
7ee7b84d | 1173 | if (op_mode == LOWREG && (x_mode == REG || x_mode == LOWREG)) |
252b5132 | 1174 | { |
7ee7b84d MS |
1175 | if ((x_size == L_8 && (operands[i].reg & 8) == 0) |
1176 | || (x_size == L_16 && (operands[i].reg & 8) == 8)) | |
1177 | as_warn (_("can't use high part of register in operand %d"), i); | |
1178 | ||
1179 | if (x_size != op_size) | |
1180 | found = 0; | |
252b5132 | 1181 | } |
7ee7b84d | 1182 | else if (op_mode == REG) |
252b5132 | 1183 | { |
7ee7b84d MS |
1184 | if (x_mode == LOWREG) |
1185 | x_mode = REG; | |
1186 | if (x_mode != REG) | |
252b5132 RH |
1187 | found = 0; |
1188 | ||
7ee7b84d MS |
1189 | if (x_size == L_P) |
1190 | x_size = (Hmode ? L_32 : L_16); | |
1191 | if (op_size == L_P) | |
1192 | op_size = (Hmode ? L_32 : L_16); | |
252b5132 | 1193 | |
70d6ecf3 | 1194 | /* The size of the reg is v important. */ |
7ee7b84d | 1195 | if (op_size != x_size) |
252b5132 RH |
1196 | found = 0; |
1197 | } | |
7ee7b84d | 1198 | else if (op_mode & CTRL) /* control register */ |
252b5132 | 1199 | { |
7ee7b84d MS |
1200 | if (!(x_mode & CTRL)) |
1201 | found = 0; | |
1202 | ||
1203 | switch (x_mode) | |
1204 | { | |
1205 | case CCR: | |
1206 | if (op_mode != CCR && | |
1207 | op_mode != CCR_EXR && | |
1208 | op_mode != CC_EX_VB_SB) | |
1209 | found = 0; | |
1210 | break; | |
1211 | case EXR: | |
1212 | if (op_mode != EXR && | |
1213 | op_mode != CCR_EXR && | |
1214 | op_mode != CC_EX_VB_SB) | |
1215 | found = 0; | |
1216 | break; | |
1217 | case MACH: | |
1218 | if (op_mode != MACH && | |
1219 | op_mode != MACREG) | |
1220 | found = 0; | |
1221 | break; | |
1222 | case MACL: | |
1223 | if (op_mode != MACL && | |
1224 | op_mode != MACREG) | |
1225 | found = 0; | |
1226 | break; | |
1227 | case VBR: | |
1228 | if (op_mode != VBR && | |
1229 | op_mode != VBR_SBR && | |
1230 | op_mode != CC_EX_VB_SB) | |
1231 | found = 0; | |
1232 | break; | |
1233 | case SBR: | |
1234 | if (op_mode != SBR && | |
1235 | op_mode != VBR_SBR && | |
1236 | op_mode != CC_EX_VB_SB) | |
1237 | found = 0; | |
1238 | break; | |
1239 | } | |
1240 | } | |
1241 | else if ((op & ABSJMP) && (x_mode == ABS || x_mode == PCREL)) | |
1242 | { | |
1243 | operands[i].mode &= ~MODE; | |
252b5132 | 1244 | operands[i].mode |= ABSJMP; |
70d6ecf3 | 1245 | /* But it may not be 24 bits long. */ |
7ee7b84d | 1246 | if (x_mode == ABS && !Hmode) |
252b5132 RH |
1247 | { |
1248 | operands[i].mode &= ~SIZE; | |
1249 | operands[i].mode |= L_16; | |
1250 | } | |
7ee7b84d MS |
1251 | if ((operands[i].mode & SIZE) == L_32 |
1252 | && (op_mode & SIZE) != L_32) | |
1253 | found = 0; | |
252b5132 | 1254 | } |
7ee7b84d | 1255 | else if (x_mode == IMM && op_mode != IMM) |
252b5132 | 1256 | { |
7ee7b84d MS |
1257 | offsetT num = operands[i].exp.X_add_number; |
1258 | if (op_mode == KBIT || op_mode == DBIT) | |
1259 | /* This is ok if the immediate value is sensible. */; | |
1260 | else if (op_mode == CONST_2) | |
1261 | found = num == 2; | |
1262 | else if (op_mode == CONST_4) | |
1263 | found = num == 4; | |
1264 | else if (op_mode == CONST_8) | |
1265 | found = num == 8; | |
1266 | else if (op_mode == CONST_16) | |
1267 | found = num == 16; | |
1268 | else | |
1269 | found = 0; | |
252b5132 | 1270 | } |
7ee7b84d | 1271 | else if (op_mode == PCREL && op_mode == x_mode) |
252b5132 | 1272 | { |
7ee7b84d MS |
1273 | /* movsd only comes in PCREL16 flavour: |
1274 | If x_size is L_8, promote it. */ | |
1275 | if (OP_KIND (this_try->opcode->how) == O_MOVSD) | |
1276 | if (x_size == L_8) | |
1277 | x_size = L_16; | |
1278 | ||
70d6ecf3 | 1279 | /* The size of the displacement is important. */ |
7ee7b84d | 1280 | if (op_size != x_size) |
252b5132 RH |
1281 | found = 0; |
1282 | } | |
7ee7b84d MS |
1283 | else if ((op_mode == DISP || op_mode == IMM || op_mode == ABS |
1284 | || op_mode == INDEXB || op_mode == INDEXW | |
1285 | || op_mode == INDEXL) | |
1286 | && op_mode == x_mode) | |
252b5132 RH |
1287 | { |
1288 | /* Promote a L_24 to L_32 if it makes us match. */ | |
7ee7b84d | 1289 | if (x_size == L_24 && op_size == L_32) |
252b5132 | 1290 | { |
7ee7b84d MS |
1291 | x &= ~SIZE; |
1292 | x |= x_size = L_32; | |
252b5132 | 1293 | } |
7ee7b84d MS |
1294 | |
1295 | #if 0 /* ??? */ | |
252b5132 | 1296 | /* Promote an L8 to L_16 if it makes us match. */ |
7ee7b84d | 1297 | if ((op_mode == ABS || op_mode == DISP) && x_size == L_8) |
252b5132 | 1298 | { |
7ee7b84d MS |
1299 | if (op_size == L_16) |
1300 | x_size = L_16; | |
252b5132 | 1301 | } |
7ee7b84d MS |
1302 | #endif |
1303 | ||
1304 | if (((x_size == L_16 && op_size == L_16U) | |
1305 | || (x_size == L_3 && op_size == L_3NZ)) | |
1306 | /* We're deliberately more permissive for ABS modes. */ | |
1307 | && (op_mode == ABS | |
1308 | || constant_fits_size_p (operands + i, op_size, | |
1309 | op & NO_SYMBOLS))) | |
1310 | x_size = op_size; | |
1311 | ||
1312 | if (x_size != 0 && op_size != x_size) | |
1313 | found = 0; | |
1314 | else if (x_size == 0 | |
1315 | && ! constant_fits_size_p (operands + i, op_size, | |
1316 | op & NO_SYMBOLS)) | |
252b5132 RH |
1317 | found = 0; |
1318 | } | |
7ee7b84d | 1319 | else if (op_mode != x_mode) |
252b5132 RH |
1320 | { |
1321 | found = 0; | |
70d6ecf3 | 1322 | } |
252b5132 RH |
1323 | } |
1324 | } | |
7ee7b84d MS |
1325 | if (found) |
1326 | { | |
1327 | if ((this_try->opcode->available == AV_H8SX && ! SXmode) | |
d4ea8842 | 1328 | || (this_try->opcode->available == AV_H8S && ! Smode) |
7ee7b84d MS |
1329 | || (this_try->opcode->available == AV_H8H && ! Hmode)) |
1330 | found = 0, found_other = this_try; | |
1331 | else if (this_size != size && (this_size != SN && size != SN)) | |
1332 | found_mismatched = this_try, found = 0; | |
1333 | ||
1334 | } | |
252b5132 RH |
1335 | } |
1336 | if (found) | |
1337 | return this_try; | |
7ee7b84d MS |
1338 | if (found_other) |
1339 | { | |
1340 | as_warn (_("Opcode `%s' with these operand types not available in %s mode"), | |
1341 | found_other->opcode->name, | |
1342 | (! Hmode && ! Smode ? "H8/300" | |
1343 | : SXmode ? "H8sx" | |
1344 | : Smode ? "H8/300S" | |
1345 | : "H8/300H")); | |
1346 | } | |
1347 | else if (found_mismatched) | |
1348 | { | |
1349 | as_warn (_("mismatch between opcode size and operand size")); | |
1350 | return found_mismatched; | |
1351 | } | |
1352 | return 0; | |
252b5132 RH |
1353 | } |
1354 | ||
1355 | static void | |
1356 | check_operand (operand, width, string) | |
1357 | struct h8_op *operand; | |
1358 | unsigned int width; | |
1359 | char *string; | |
1360 | { | |
1361 | if (operand->exp.X_add_symbol == 0 | |
1362 | && operand->exp.X_op_symbol == 0) | |
1363 | { | |
70d6ecf3 AM |
1364 | /* No symbol involved, let's look at offset, it's dangerous if |
1365 | any of the high bits are not 0 or ff's, find out by oring or | |
1366 | anding with the width and seeing if the answer is 0 or all | |
1367 | fs. */ | |
252b5132 | 1368 | |
7ee7b84d | 1369 | if (! constant_fits_width_p (operand, width)) |
252b5132 | 1370 | { |
70d6ecf3 | 1371 | if (width == 255 |
252b5132 RH |
1372 | && (operand->exp.X_add_number & 0xff00) == 0xff00) |
1373 | { | |
1374 | /* Just ignore this one - which happens when trying to | |
1375 | fit a 16 bit address truncated into an 8 bit address | |
1376 | of something like bset. */ | |
1377 | } | |
166e23f9 KH |
1378 | else if (strcmp (string, "@") == 0 |
1379 | && width == 0xffff | |
1380 | && (operand->exp.X_add_number & 0xff8000) == 0xff8000) | |
1381 | { | |
1382 | /* Just ignore this one - which happens when trying to | |
1383 | fit a 24 bit address truncated into a 16 bit address | |
1384 | of something like mov.w. */ | |
1385 | } | |
70d6ecf3 | 1386 | else |
252b5132 RH |
1387 | { |
1388 | as_warn (_("operand %s0x%lx out of range."), string, | |
1389 | (unsigned long) operand->exp.X_add_number); | |
1390 | } | |
1391 | } | |
1392 | } | |
252b5132 RH |
1393 | } |
1394 | ||
1395 | /* RELAXMODE has one of 3 values: | |
1396 | ||
1397 | 0 Output a "normal" reloc, no relaxing possible for this insn/reloc | |
1398 | ||
1399 | 1 Output a relaxable 24bit absolute mov.w address relocation | |
1400 | (may relax into a 16bit absolute address). | |
1401 | ||
1402 | 2 Output a relaxable 16/24 absolute mov.b address relocation | |
1403 | (may relax into an 8bit absolute address). */ | |
1404 | ||
1405 | static void | |
7ee7b84d MS |
1406 | do_a_fix_imm (offset, nibble, operand, relaxmode) |
1407 | int offset, nibble; | |
252b5132 RH |
1408 | struct h8_op *operand; |
1409 | int relaxmode; | |
1410 | { | |
1411 | int idx; | |
1412 | int size; | |
1413 | int where; | |
7ee7b84d | 1414 | char *bytes = frag_now->fr_literal + offset; |
252b5132 | 1415 | |
7ee7b84d | 1416 | char *t = ((operand->mode & MODE) == IMM) ? "#" : "@"; |
252b5132 RH |
1417 | |
1418 | if (operand->exp.X_add_symbol == 0) | |
1419 | { | |
252b5132 RH |
1420 | switch (operand->mode & SIZE) |
1421 | { | |
1422 | case L_2: | |
1423 | check_operand (operand, 0x3, t); | |
7ee7b84d | 1424 | bytes[0] |= (operand->exp.X_add_number & 3) << (nibble ? 0 : 4); |
252b5132 RH |
1425 | break; |
1426 | case L_3: | |
7ee7b84d | 1427 | case L_3NZ: |
252b5132 | 1428 | check_operand (operand, 0x7, t); |
7ee7b84d MS |
1429 | bytes[0] |= (operand->exp.X_add_number & 7) << (nibble ? 0 : 4); |
1430 | break; | |
1431 | case L_4: | |
1432 | check_operand (operand, 0xF, t); | |
1433 | bytes[0] |= (operand->exp.X_add_number & 15) << (nibble ? 0 : 4); | |
1434 | break; | |
1435 | case L_5: | |
1436 | check_operand (operand, 0x1F, t); | |
1437 | bytes[0] |= operand->exp.X_add_number & 31; | |
252b5132 RH |
1438 | break; |
1439 | case L_8: | |
7ee7b84d | 1440 | case L_8U: |
252b5132 | 1441 | check_operand (operand, 0xff, t); |
7ee7b84d | 1442 | bytes[0] |= operand->exp.X_add_number; |
252b5132 RH |
1443 | break; |
1444 | case L_16: | |
7ee7b84d | 1445 | case L_16U: |
252b5132 | 1446 | check_operand (operand, 0xffff, t); |
7ee7b84d MS |
1447 | bytes[0] |= operand->exp.X_add_number >> 8; |
1448 | bytes[1] |= operand->exp.X_add_number >> 0; | |
252b5132 RH |
1449 | break; |
1450 | case L_24: | |
1451 | check_operand (operand, 0xffffff, t); | |
7ee7b84d MS |
1452 | bytes[0] |= operand->exp.X_add_number >> 16; |
1453 | bytes[1] |= operand->exp.X_add_number >> 8; | |
1454 | bytes[2] |= operand->exp.X_add_number >> 0; | |
252b5132 RH |
1455 | break; |
1456 | ||
1457 | case L_32: | |
70d6ecf3 | 1458 | /* This should be done with bfd. */ |
7ee7b84d MS |
1459 | bytes[0] |= operand->exp.X_add_number >> 24; |
1460 | bytes[1] |= operand->exp.X_add_number >> 16; | |
1461 | bytes[2] |= operand->exp.X_add_number >> 8; | |
1462 | bytes[3] |= operand->exp.X_add_number >> 0; | |
4132022d AM |
1463 | if (relaxmode != 0) |
1464 | { | |
1465 | idx = (relaxmode == 2) ? R_MOV24B1 : R_MOVL1; | |
1466 | fix_new_exp (frag_now, offset, 4, &operand->exp, 0, idx); | |
1467 | } | |
252b5132 RH |
1468 | break; |
1469 | } | |
252b5132 RH |
1470 | } |
1471 | else | |
1472 | { | |
1473 | switch (operand->mode & SIZE) | |
1474 | { | |
252b5132 RH |
1475 | case L_24: |
1476 | case L_32: | |
1477 | size = 4; | |
1478 | where = (operand->mode & SIZE) == L_24 ? -1 : 0; | |
1479 | if (relaxmode == 2) | |
1480 | idx = R_MOV24B1; | |
1481 | else if (relaxmode == 1) | |
1482 | idx = R_MOVL1; | |
1483 | else | |
1484 | idx = R_RELLONG; | |
1485 | break; | |
1486 | default: | |
70d6ecf3 | 1487 | as_bad (_("Can't work out size of operand.\n")); |
252b5132 | 1488 | case L_16: |
7ee7b84d | 1489 | case L_16U: |
252b5132 RH |
1490 | size = 2; |
1491 | where = 0; | |
1492 | if (relaxmode == 2) | |
1493 | idx = R_MOV16B1; | |
1494 | else | |
1495 | idx = R_RELWORD; | |
4132022d AM |
1496 | operand->exp.X_add_number = |
1497 | ((operand->exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000; | |
7ee7b84d | 1498 | operand->exp.X_add_number |= (bytes[0] << 8) | bytes[1]; |
252b5132 RH |
1499 | break; |
1500 | case L_8: | |
1501 | size = 1; | |
1502 | where = 0; | |
1503 | idx = R_RELBYTE; | |
4132022d AM |
1504 | operand->exp.X_add_number = |
1505 | ((operand->exp.X_add_number & 0xff) ^ 0x80) - 0x80; | |
7ee7b84d | 1506 | operand->exp.X_add_number |= bytes[0]; |
252b5132 RH |
1507 | } |
1508 | ||
1509 | fix_new_exp (frag_now, | |
1510 | offset + where, | |
1511 | size, | |
1512 | &operand->exp, | |
1513 | 0, | |
1514 | idx); | |
1515 | } | |
252b5132 RH |
1516 | } |
1517 | ||
70d6ecf3 | 1518 | /* Now we know what sort of opcodes it is, let's build the bytes. */ |
3048287a | 1519 | |
252b5132 RH |
1520 | static void |
1521 | build_bytes (this_try, operand) | |
a720f7bc | 1522 | const struct h8_instruction *this_try; |
252b5132 RH |
1523 | struct h8_op *operand; |
1524 | { | |
3048287a | 1525 | int i; |
252b5132 | 1526 | char *output = frag_more (this_try->length); |
a720f7bc | 1527 | op_type *nibble_ptr = this_try->opcode->data.nib; |
252b5132 RH |
1528 | op_type c; |
1529 | unsigned int nibble_count = 0; | |
7ee7b84d | 1530 | int op_at[3]; |
3048287a | 1531 | int nib = 0; |
252b5132 | 1532 | int movb = 0; |
7ee7b84d | 1533 | char asnibbles[100]; |
252b5132 | 1534 | char *p = asnibbles; |
7ee7b84d | 1535 | int high, low; |
252b5132 | 1536 | |
d4ea8842 | 1537 | if (!Hmode && this_try->opcode->available != AV_H8) |
252b5132 | 1538 | as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"), |
a720f7bc | 1539 | this_try->opcode->name); |
d4ea8842 MS |
1540 | else if (!Smode |
1541 | && this_try->opcode->available != AV_H8 | |
1542 | && this_try->opcode->available != AV_H8H) | |
1543 | as_warn (_("Opcode `%s' with these operand types not available in H8/300H mode"), | |
1544 | this_try->opcode->name); | |
1545 | else if (!SXmode | |
1546 | && this_try->opcode->available != AV_H8 | |
1547 | && this_try->opcode->available != AV_H8H | |
1548 | && this_try->opcode->available != AV_H8S) | |
1549 | as_warn (_("Opcode `%s' with these operand types not available in H8/300S mode"), | |
1550 | this_try->opcode->name); | |
252b5132 | 1551 | |
7ee7b84d | 1552 | while (*nibble_ptr != (op_type) E) |
252b5132 RH |
1553 | { |
1554 | int d; | |
7ee7b84d MS |
1555 | |
1556 | nib = 0; | |
252b5132 RH |
1557 | c = *nibble_ptr++; |
1558 | ||
7ee7b84d | 1559 | d = (c & OP3) == OP3 ? 2 : (c & DST) == DST ? 1 : 0; |
252b5132 RH |
1560 | |
1561 | if (c < 16) | |
3048287a | 1562 | nib = c; |
252b5132 RH |
1563 | else |
1564 | { | |
7ee7b84d MS |
1565 | int c2 = c & MODE; |
1566 | ||
1567 | if (c2 == REG || c2 == LOWREG | |
1568 | || c2 == IND || c2 == PREINC || c2 == PREDEC | |
1569 | || c2 == POSTINC || c2 == POSTDEC) | |
1570 | { | |
1571 | nib = operand[d].reg; | |
1572 | if (c2 == LOWREG) | |
1573 | nib &= 7; | |
1574 | } | |
1575 | ||
1576 | else if (c & CTRL) /* Control reg operand. */ | |
3048287a NC |
1577 | nib = operand[d].reg; |
1578 | ||
252b5132 | 1579 | else if ((c & DISPREG) == (DISPREG)) |
7ee7b84d MS |
1580 | { |
1581 | nib = operand[d].reg; | |
1582 | } | |
1583 | else if (c2 == ABS) | |
252b5132 RH |
1584 | { |
1585 | operand[d].mode = c; | |
7ee7b84d | 1586 | op_at[d] = nibble_count; |
252b5132 RH |
1587 | nib = 0; |
1588 | } | |
7ee7b84d MS |
1589 | else if (c2 == IMM || c2 == PCREL || c2 == ABS |
1590 | || (c & ABSJMP) || c2 == DISP) | |
252b5132 RH |
1591 | { |
1592 | operand[d].mode = c; | |
7ee7b84d | 1593 | op_at[d] = nibble_count; |
252b5132 RH |
1594 | nib = 0; |
1595 | } | |
7ee7b84d | 1596 | else if ((c & IGNORE) || (c & DATA)) |
3048287a NC |
1597 | nib = 0; |
1598 | ||
7ee7b84d | 1599 | else if (c2 == DBIT) |
252b5132 RH |
1600 | { |
1601 | switch (operand[0].exp.X_add_number) | |
1602 | { | |
1603 | case 1: | |
1604 | nib = c; | |
1605 | break; | |
1606 | case 2: | |
1607 | nib = 0x8 | c; | |
1608 | break; | |
1609 | default: | |
1610 | as_bad (_("Need #1 or #2 here")); | |
1611 | } | |
1612 | } | |
7ee7b84d | 1613 | else if (c2 == KBIT) |
252b5132 RH |
1614 | { |
1615 | switch (operand[0].exp.X_add_number) | |
1616 | { | |
1617 | case 1: | |
1618 | nib = 0; | |
1619 | break; | |
1620 | case 2: | |
1621 | nib = 8; | |
1622 | break; | |
1623 | case 4: | |
1624 | if (!Hmode) | |
1625 | as_warn (_("#4 not valid on H8/300.")); | |
1626 | nib = 9; | |
1627 | break; | |
1628 | ||
1629 | default: | |
1630 | as_bad (_("Need #1 or #2 here")); | |
1631 | break; | |
1632 | } | |
70d6ecf3 | 1633 | /* Stop it making a fix. */ |
252b5132 RH |
1634 | operand[0].mode = 0; |
1635 | } | |
1636 | ||
1637 | if (c & MEMRELAX) | |
3048287a | 1638 | operand[d].mode |= MEMRELAX; |
252b5132 RH |
1639 | |
1640 | if (c & B31) | |
3048287a | 1641 | nib |= 0x8; |
252b5132 | 1642 | |
7ee7b84d MS |
1643 | if (c & B21) |
1644 | nib |= 0x4; | |
1645 | ||
1646 | if (c & B11) | |
1647 | nib |= 0x2; | |
1648 | ||
1649 | if (c & B01) | |
1650 | nib |= 0x1; | |
1651 | ||
1652 | if (c2 == MACREG) | |
252b5132 | 1653 | { |
f0c56b90 NC |
1654 | if (operand[0].mode == MACREG) |
1655 | /* stmac has mac[hl] as the first operand. */ | |
1656 | nib = 2 + operand[0].reg; | |
1657 | else | |
1658 | /* ldmac has mac[hl] as the second operand. */ | |
1659 | nib = 2 + operand[1].reg; | |
252b5132 RH |
1660 | } |
1661 | } | |
1662 | nibble_count++; | |
1663 | ||
1664 | *p++ = nib; | |
1665 | } | |
1666 | ||
1667 | /* Disgusting. Why, oh why didn't someone ask us for advice | |
1668 | on the assembler format. */ | |
7ee7b84d | 1669 | if (OP_KIND (this_try->opcode->how) == O_LDM) |
252b5132 | 1670 | { |
7ee7b84d MS |
1671 | high = (operand[1].reg >> 8) & 0xf; |
1672 | low = (operand[1].reg) & 0xf; | |
252b5132 | 1673 | asnibbles[2] = high - low; |
7ee7b84d MS |
1674 | asnibbles[7] = high; |
1675 | } | |
1676 | else if (OP_KIND (this_try->opcode->how) == O_STM) | |
1677 | { | |
1678 | high = (operand[0].reg >> 8) & 0xf; | |
1679 | low = (operand[0].reg) & 0xf; | |
1680 | asnibbles[2] = high - low; | |
1681 | asnibbles[7] = low; | |
252b5132 RH |
1682 | } |
1683 | ||
1684 | for (i = 0; i < this_try->length; i++) | |
3048287a | 1685 | output[i] = (asnibbles[i * 2] << 4) | asnibbles[i * 2 + 1]; |
252b5132 RH |
1686 | |
1687 | /* Note if this is a movb instruction -- there's a special relaxation | |
1688 | which only applies to them. */ | |
7ee7b84d | 1689 | if (this_try->opcode->how == O (O_MOV, SB)) |
252b5132 RH |
1690 | movb = 1; |
1691 | ||
70d6ecf3 | 1692 | /* Output any fixes. */ |
7ee7b84d | 1693 | for (i = 0; i < this_try->noperands; i++) |
252b5132 RH |
1694 | { |
1695 | int x = operand[i].mode; | |
7ee7b84d | 1696 | int x_mode = x & MODE; |
252b5132 | 1697 | |
7ee7b84d MS |
1698 | if (x_mode == IMM || x_mode == DISP) |
1699 | do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2, | |
1700 | op_at[i] & 1, operand + i, (x & MEMRELAX) != 0); | |
3048287a | 1701 | |
7ee7b84d MS |
1702 | else if (x_mode == ABS) |
1703 | do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2, | |
1704 | op_at[i] & 1, operand + i, | |
1705 | (x & MEMRELAX) ? movb + 1 : 0); | |
3048287a | 1706 | |
7ee7b84d | 1707 | else if (x_mode == PCREL) |
252b5132 | 1708 | { |
7ee7b84d | 1709 | int size16 = (x & SIZE) == L_16; |
252b5132 RH |
1710 | int size = size16 ? 2 : 1; |
1711 | int type = size16 ? R_PCRWORD : R_PCRBYTE; | |
36ed2fff | 1712 | fixS *fixP; |
252b5132 RH |
1713 | |
1714 | check_operand (operand + i, size16 ? 0x7fff : 0x7f, "@"); | |
1715 | ||
1716 | if (operand[i].exp.X_add_number & 1) | |
3048287a NC |
1717 | as_warn (_("branch operand has odd offset (%lx)\n"), |
1718 | (unsigned long) operand->exp.X_add_number); | |
36ed2fff JL |
1719 | #ifndef OBJ_ELF |
1720 | /* The COFF port has always been off by one, changing it | |
1721 | now would be an incompatible change, so we leave it as-is. | |
1722 | ||
1723 | We don't want to do this for ELF as we want to be | |
1724 | compatible with the proposed ELF format from Hitachi. */ | |
252b5132 | 1725 | operand[i].exp.X_add_number -= 1; |
36ed2fff | 1726 | #endif |
7ee7b84d MS |
1727 | if (size16) |
1728 | { | |
1729 | operand[i].exp.X_add_number = | |
1730 | ((operand[i].exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000; | |
1731 | } | |
1732 | else | |
1733 | { | |
1734 | operand[i].exp.X_add_number = | |
1735 | ((operand[i].exp.X_add_number & 0xff) ^ 0x80) - 0x80; | |
1736 | } | |
1737 | ||
1738 | /* For BRA/S. */ | |
1739 | if (! size16) | |
1740 | operand[i].exp.X_add_number |= output[op_at[i] / 2]; | |
252b5132 | 1741 | |
36ed2fff | 1742 | fixP = fix_new_exp (frag_now, |
7ee7b84d | 1743 | output - frag_now->fr_literal + op_at[i] / 2, |
36ed2fff JL |
1744 | size, |
1745 | &operand[i].exp, | |
1746 | 1, | |
1747 | type); | |
1748 | fixP->fx_signed = 1; | |
252b5132 | 1749 | } |
7ee7b84d | 1750 | else if (x_mode == MEMIND) |
252b5132 | 1751 | { |
252b5132 RH |
1752 | check_operand (operand + i, 0xff, "@@"); |
1753 | fix_new_exp (frag_now, | |
1754 | output - frag_now->fr_literal + 1, | |
1755 | 1, | |
1756 | &operand[i].exp, | |
1757 | 0, | |
1758 | R_MEM_INDIRECT); | |
1759 | } | |
7ee7b84d MS |
1760 | else if (x_mode == VECIND) |
1761 | { | |
1762 | check_operand (operand + i, 0x7f, "@@"); | |
1763 | /* FIXME: approximating the effect of "B31" here... | |
1764 | This is very hackish, and ought to be done a better way. */ | |
1765 | operand[i].exp.X_add_number |= 0x80; | |
1766 | fix_new_exp (frag_now, | |
1767 | output - frag_now->fr_literal + 1, | |
1768 | 1, | |
1769 | &operand[i].exp, | |
1770 | 0, | |
1771 | R_MEM_INDIRECT); | |
1772 | } | |
252b5132 RH |
1773 | else if (x & ABSJMP) |
1774 | { | |
3c1ba8a3 | 1775 | int where = 0; |
7ee7b84d | 1776 | bfd_reloc_code_real_type reloc_type = R_JMPL1; |
3c1ba8a3 JL |
1777 | |
1778 | #ifdef OBJ_ELF | |
1779 | /* To be compatible with the proposed H8 ELF format, we | |
1780 | want the relocation's offset to point to the first byte | |
1781 | that will be modified, not to the start of the instruction. */ | |
7ee7b84d MS |
1782 | |
1783 | if ((operand->mode & SIZE) == L_32) | |
1784 | { | |
1785 | where = 2; | |
1786 | reloc_type = R_RELLONG; | |
1787 | } | |
1788 | else | |
1789 | where = 1; | |
3c1ba8a3 | 1790 | #endif |
de342d07 | 1791 | |
70d6ecf3 | 1792 | /* This jmp may be a jump or a branch. */ |
252b5132 | 1793 | |
7ee7b84d MS |
1794 | check_operand (operand + i, |
1795 | SXmode ? 0xffffffff : Hmode ? 0xffffff : 0xffff, | |
1796 | "@"); | |
3048287a | 1797 | |
252b5132 | 1798 | if (operand[i].exp.X_add_number & 1) |
3048287a NC |
1799 | as_warn (_("branch operand has odd offset (%lx)\n"), |
1800 | (unsigned long) operand->exp.X_add_number); | |
1801 | ||
252b5132 | 1802 | if (!Hmode) |
70d6ecf3 | 1803 | operand[i].exp.X_add_number = |
4132022d | 1804 | ((operand[i].exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000; |
252b5132 | 1805 | fix_new_exp (frag_now, |
3c1ba8a3 | 1806 | output - frag_now->fr_literal + where, |
252b5132 RH |
1807 | 4, |
1808 | &operand[i].exp, | |
1809 | 0, | |
7ee7b84d | 1810 | reloc_type); |
252b5132 RH |
1811 | } |
1812 | } | |
252b5132 RH |
1813 | } |
1814 | ||
70d6ecf3 AM |
1815 | /* Try to give an intelligent error message for common and simple to |
1816 | detect errors. */ | |
3048287a | 1817 | |
252b5132 | 1818 | static void |
a720f7bc KD |
1819 | clever_message (instruction, operand) |
1820 | const struct h8_instruction *instruction; | |
252b5132 RH |
1821 | struct h8_op *operand; |
1822 | { | |
70d6ecf3 | 1823 | /* Find out if there was more than one possible opcode. */ |
252b5132 | 1824 | |
a720f7bc | 1825 | if ((instruction + 1)->idx != instruction->idx) |
252b5132 | 1826 | { |
3048287a | 1827 | int argn; |
252b5132 | 1828 | |
70d6ecf3 AM |
1829 | /* Only one opcode of this flavour, try to guess which operand |
1830 | didn't match. */ | |
a720f7bc | 1831 | for (argn = 0; argn < instruction->noperands; argn++) |
252b5132 | 1832 | { |
a720f7bc | 1833 | switch (instruction->opcode->args.nib[argn]) |
252b5132 RH |
1834 | { |
1835 | case RD16: | |
1836 | if (operand[argn].mode != RD16) | |
1837 | { | |
1838 | as_bad (_("destination operand must be 16 bit register")); | |
1839 | return; | |
1840 | ||
1841 | } | |
1842 | break; | |
1843 | ||
1844 | case RS8: | |
252b5132 RH |
1845 | if (operand[argn].mode != RS8) |
1846 | { | |
1847 | as_bad (_("source operand must be 8 bit register")); | |
1848 | return; | |
1849 | } | |
1850 | break; | |
1851 | ||
1852 | case ABS16DST: | |
1853 | if (operand[argn].mode != ABS16DST) | |
1854 | { | |
1855 | as_bad (_("destination operand must be 16bit absolute address")); | |
1856 | return; | |
1857 | } | |
1858 | break; | |
1859 | case RD8: | |
1860 | if (operand[argn].mode != RD8) | |
1861 | { | |
1862 | as_bad (_("destination operand must be 8 bit register")); | |
1863 | return; | |
1864 | } | |
1865 | break; | |
1866 | ||
252b5132 RH |
1867 | case ABS16SRC: |
1868 | if (operand[argn].mode != ABS16SRC) | |
1869 | { | |
1870 | as_bad (_("source operand must be 16bit absolute address")); | |
1871 | return; | |
1872 | } | |
1873 | break; | |
1874 | ||
1875 | } | |
1876 | } | |
1877 | } | |
1878 | as_bad (_("invalid operands")); | |
1879 | } | |
1880 | ||
d4ea8842 MS |
1881 | |
1882 | /* Adjust OPERAND's value and size given that it is accessing a field | |
1883 | of SIZE bytes. | |
1884 | ||
1885 | This function handles the choice between @(d:2,ERn) and @(d:16,ERn) | |
1886 | when no size is explicitly given. It also scales down the assembly-level | |
1887 | displacement in an @(d:2,ERn) operand. */ | |
1888 | ||
1889 | static void | |
1890 | fix_operand_size (operand, size) | |
1891 | struct h8_op *operand; | |
1892 | int size; | |
1893 | { | |
1894 | if ((operand->mode & MODE) == DISP) | |
1895 | { | |
1896 | /* If the user didn't specify an operand width, see if we | |
1897 | can use @(d:2,ERn). */ | |
1898 | if (SXmode | |
1899 | && (operand->mode & SIZE) == 0 | |
1900 | && (operand->exp.X_add_number == size | |
1901 | || operand->exp.X_add_number == size * 2 | |
1902 | || operand->exp.X_add_number == size * 3)) | |
1903 | operand->mode |= L_2; | |
1904 | ||
1905 | /* Scale down the displacement in an @(d:2,ERn) operand. | |
1906 | X_add_number then contains the desired field value. */ | |
1907 | if ((operand->mode & SIZE) == L_2) | |
1908 | { | |
1909 | if (operand->exp.X_add_number % size != 0) | |
1910 | as_warn (_("operand/size mis-match")); | |
1911 | operand->exp.X_add_number /= size; | |
1912 | } | |
1913 | } | |
1914 | ||
1915 | /* If the operand needs a size but doesn't have one yet, it must be | |
1916 | a 16-bit integer (see colonmod24). */ | |
1917 | if ((operand->mode & SIZE) == 0) | |
1918 | switch (operand->mode & MODE) | |
1919 | { | |
1920 | case DISP: | |
1921 | case INDEXB: | |
1922 | case INDEXW: | |
1923 | case INDEXL: | |
1924 | case ABS: | |
1925 | operand->mode |= L_16; | |
1926 | break; | |
1927 | } | |
1928 | } | |
1929 | ||
1930 | ||
70d6ecf3 AM |
1931 | /* This is the guts of the machine-dependent assembler. STR points to |
1932 | a machine dependent instruction. This function is supposed to emit | |
1933 | the frags/bytes it assembles. */ | |
3048287a | 1934 | |
252b5132 RH |
1935 | void |
1936 | md_assemble (str) | |
1937 | char *str; | |
1938 | { | |
1939 | char *op_start; | |
1940 | char *op_end; | |
7ee7b84d | 1941 | struct h8_op operand[3]; |
a720f7bc KD |
1942 | const struct h8_instruction *instruction; |
1943 | const struct h8_instruction *prev_instruction; | |
252b5132 RH |
1944 | |
1945 | char *dot = 0; | |
1946 | char c; | |
7ee7b84d | 1947 | int size, i; |
252b5132 | 1948 | |
70d6ecf3 | 1949 | /* Drop leading whitespace. */ |
252b5132 RH |
1950 | while (*str == ' ') |
1951 | str++; | |
1952 | ||
70d6ecf3 | 1953 | /* Find the op code end. */ |
252b5132 RH |
1954 | for (op_start = op_end = str; |
1955 | *op_end != 0 && *op_end != ' '; | |
1956 | op_end++) | |
1957 | { | |
1958 | if (*op_end == '.') | |
1959 | { | |
1960 | dot = op_end + 1; | |
1961 | *op_end = 0; | |
1962 | op_end += 2; | |
1963 | break; | |
1964 | } | |
1965 | } | |
1966 | ||
252b5132 RH |
1967 | if (op_end == op_start) |
1968 | { | |
1969 | as_bad (_("can't find opcode ")); | |
1970 | } | |
1971 | c = *op_end; | |
1972 | ||
1973 | *op_end = 0; | |
1974 | ||
a720f7bc KD |
1975 | instruction = (const struct h8_instruction *) |
1976 | hash_find (opcode_hash_control, op_start); | |
252b5132 | 1977 | |
a720f7bc | 1978 | if (instruction == NULL) |
252b5132 RH |
1979 | { |
1980 | as_bad (_("unknown opcode")); | |
1981 | return; | |
1982 | } | |
1983 | ||
70d6ecf3 | 1984 | /* We used to set input_line_pointer to the result of get_operands, |
252b5132 RH |
1985 | but that is wrong. Our caller assumes we don't change it. */ |
1986 | ||
7ee7b84d MS |
1987 | operand[0].mode = 0; |
1988 | operand[1].mode = 0; | |
1989 | operand[2].mode = 0; | |
1990 | ||
1991 | if (OP_KIND (instruction->opcode->how) == O_MOVAB | |
1992 | || OP_KIND (instruction->opcode->how) == O_MOVAW | |
1993 | || OP_KIND (instruction->opcode->how) == O_MOVAL) | |
1994 | get_mova_operands (op_end, operand); | |
1995 | else if (OP_KIND (instruction->opcode->how) == O_RTEL | |
1996 | || OP_KIND (instruction->opcode->how) == O_RTSL) | |
1997 | get_rtsl_operands (op_end, operand); | |
1998 | else | |
1999 | get_operands (instruction->noperands, op_end, operand); | |
2000 | ||
252b5132 | 2001 | *op_end = c; |
a720f7bc | 2002 | prev_instruction = instruction; |
252b5132 RH |
2003 | |
2004 | size = SN; | |
2005 | if (dot) | |
2006 | { | |
2007 | switch (*dot) | |
2008 | { | |
2009 | case 'b': | |
2010 | size = SB; | |
2011 | break; | |
2012 | ||
2013 | case 'w': | |
2014 | size = SW; | |
2015 | break; | |
2016 | ||
2017 | case 'l': | |
2018 | size = SL; | |
2019 | break; | |
2020 | } | |
2021 | } | |
7ee7b84d MS |
2022 | if (OP_KIND (instruction->opcode->how) == O_MOVAB || |
2023 | OP_KIND (instruction->opcode->how) == O_MOVAW || | |
2024 | OP_KIND (instruction->opcode->how) == O_MOVAL) | |
252b5132 | 2025 | { |
d4ea8842 MS |
2026 | switch (operand[0].mode & MODE) |
2027 | { | |
7ee7b84d MS |
2028 | case INDEXB: |
2029 | default: | |
d4ea8842 | 2030 | fix_operand_size (&operand[1], 1); |
7ee7b84d MS |
2031 | break; |
2032 | case INDEXW: | |
d4ea8842 | 2033 | fix_operand_size (&operand[1], 2); |
7ee7b84d MS |
2034 | break; |
2035 | case INDEXL: | |
d4ea8842 | 2036 | fix_operand_size (&operand[1], 4); |
7ee7b84d | 2037 | break; |
252b5132 RH |
2038 | } |
2039 | } | |
7ee7b84d MS |
2040 | else |
2041 | { | |
d4ea8842 MS |
2042 | for (i = 0; i < 3 && operand[i].mode != 0; i++) |
2043 | switch (size) | |
2044 | { | |
7ee7b84d MS |
2045 | case SN: |
2046 | case SB: | |
2047 | default: | |
d4ea8842 | 2048 | fix_operand_size (&operand[i], 1); |
7ee7b84d MS |
2049 | break; |
2050 | case SW: | |
d4ea8842 | 2051 | fix_operand_size (&operand[i], 2); |
7ee7b84d MS |
2052 | break; |
2053 | case SL: | |
d4ea8842 | 2054 | fix_operand_size (&operand[i], 4); |
7ee7b84d MS |
2055 | break; |
2056 | } | |
2057 | } | |
252b5132 | 2058 | |
d4ea8842 MS |
2059 | instruction = get_specific (instruction, operand, size); |
2060 | ||
2061 | if (instruction == 0) | |
2062 | { | |
2063 | /* Couldn't find an opcode which matched the operands. */ | |
2064 | char *where = frag_more (2); | |
2065 | ||
2066 | where[0] = 0x0; | |
2067 | where[1] = 0x0; | |
2068 | clever_message (prev_instruction, operand); | |
2069 | ||
2070 | return; | |
2071 | } | |
2072 | ||
a720f7bc | 2073 | build_bytes (instruction, operand); |
2c8714f2 NC |
2074 | |
2075 | #ifdef BFD_ASSEMBLER | |
2076 | dwarf2_emit_insn (instruction->length); | |
2077 | #endif | |
252b5132 RH |
2078 | } |
2079 | ||
5facebfc | 2080 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
2081 | void |
2082 | tc_crawl_symbol_chain (headers) | |
70d6ecf3 | 2083 | object_headers *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
2084 | { |
2085 | printf (_("call to tc_crawl_symbol_chain \n")); | |
2086 | } | |
f333765f | 2087 | #endif |
252b5132 RH |
2088 | |
2089 | symbolS * | |
2090 | md_undefined_symbol (name) | |
dbbc7809 | 2091 | char *name ATTRIBUTE_UNUSED; |
252b5132 RH |
2092 | { |
2093 | return 0; | |
2094 | } | |
2095 | ||
5facebfc | 2096 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
2097 | void |
2098 | tc_headers_hook (headers) | |
70d6ecf3 | 2099 | object_headers *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
2100 | { |
2101 | printf (_("call to tc_headers_hook \n")); | |
2102 | } | |
f333765f | 2103 | #endif |
252b5132 RH |
2104 | |
2105 | /* Various routines to kill one day */ | |
2106 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
2107 | #define MAX_LITTLENUMS 6 | |
2108 | ||
70d6ecf3 AM |
2109 | /* Turn a string in input_line_pointer into a floating point constant |
2110 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
bc0d738a | 2111 | of LITTLENUMS emitted is stored in *SIZEP. An error message is |
70d6ecf3 | 2112 | returned, or NULL on OK. */ |
bc0d738a | 2113 | |
252b5132 RH |
2114 | char * |
2115 | md_atof (type, litP, sizeP) | |
2116 | char type; | |
2117 | char *litP; | |
2118 | int *sizeP; | |
2119 | { | |
2120 | int prec; | |
2121 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
2122 | LITTLENUM_TYPE *wordP; | |
2123 | char *t; | |
252b5132 RH |
2124 | |
2125 | switch (type) | |
2126 | { | |
2127 | case 'f': | |
2128 | case 'F': | |
2129 | case 's': | |
2130 | case 'S': | |
2131 | prec = 2; | |
2132 | break; | |
2133 | ||
2134 | case 'd': | |
2135 | case 'D': | |
2136 | case 'r': | |
2137 | case 'R': | |
2138 | prec = 4; | |
2139 | break; | |
2140 | ||
2141 | case 'x': | |
2142 | case 'X': | |
2143 | prec = 6; | |
2144 | break; | |
2145 | ||
2146 | case 'p': | |
2147 | case 'P': | |
2148 | prec = 6; | |
2149 | break; | |
2150 | ||
2151 | default: | |
2152 | *sizeP = 0; | |
2153 | return _("Bad call to MD_ATOF()"); | |
2154 | } | |
2155 | t = atof_ieee (input_line_pointer, type, words); | |
2156 | if (t) | |
2157 | input_line_pointer = t; | |
2158 | ||
2159 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
2160 | for (wordP = words; prec--;) | |
2161 | { | |
2162 | md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
2163 | litP += sizeof (LITTLENUM_TYPE); | |
2164 | } | |
2165 | return 0; | |
2166 | } | |
2167 | \f | |
5a38dc70 | 2168 | const char *md_shortopts = ""; |
252b5132 RH |
2169 | struct option md_longopts[] = { |
2170 | {NULL, no_argument, NULL, 0} | |
2171 | }; | |
70d6ecf3 AM |
2172 | |
2173 | size_t md_longopts_size = sizeof (md_longopts); | |
252b5132 RH |
2174 | |
2175 | int | |
2176 | md_parse_option (c, arg) | |
dbbc7809 JL |
2177 | int c ATTRIBUTE_UNUSED; |
2178 | char *arg ATTRIBUTE_UNUSED; | |
252b5132 RH |
2179 | { |
2180 | return 0; | |
2181 | } | |
2182 | ||
2183 | void | |
2184 | md_show_usage (stream) | |
dbbc7809 | 2185 | FILE *stream ATTRIBUTE_UNUSED; |
252b5132 RH |
2186 | { |
2187 | } | |
2188 | \f | |
3048287a NC |
2189 | void tc_aout_fix_to_chars PARAMS ((void)); |
2190 | ||
252b5132 RH |
2191 | void |
2192 | tc_aout_fix_to_chars () | |
2193 | { | |
2194 | printf (_("call to tc_aout_fix_to_chars \n")); | |
2195 | abort (); | |
2196 | } | |
2197 | ||
2198 | void | |
2199 | md_convert_frag (headers, seg, fragP) | |
36ed2fff JL |
2200 | #ifdef BFD_ASSEMBLER |
2201 | bfd *headers ATTRIBUTE_UNUSED; | |
2202 | #else | |
dbbc7809 | 2203 | object_headers *headers ATTRIBUTE_UNUSED; |
36ed2fff | 2204 | #endif |
dbbc7809 JL |
2205 | segT seg ATTRIBUTE_UNUSED; |
2206 | fragS *fragP ATTRIBUTE_UNUSED; | |
252b5132 RH |
2207 | { |
2208 | printf (_("call to md_convert_frag \n")); | |
2209 | abort (); | |
2210 | } | |
2211 | ||
3c1ba8a3 JL |
2212 | #ifdef BFD_ASSEMBLER |
2213 | valueT | |
2214 | md_section_align (segment, size) | |
2215 | segT segment; | |
2216 | valueT size; | |
2217 | { | |
2218 | int align = bfd_get_section_alignment (stdoutput, segment); | |
2219 | return ((size + (1 << align) - 1) & (-1 << align)); | |
2220 | } | |
2221 | #else | |
70d6ecf3 | 2222 | valueT |
252b5132 RH |
2223 | md_section_align (seg, size) |
2224 | segT seg; | |
2225 | valueT size; | |
2226 | { | |
70d6ecf3 | 2227 | return ((size + (1 << section_alignment[(int) seg]) - 1) |
cc8a6dd0 | 2228 | & (-1 << section_alignment[(int) seg])); |
252b5132 | 2229 | } |
3c1ba8a3 JL |
2230 | #endif |
2231 | ||
252b5132 RH |
2232 | |
2233 | void | |
94f592af | 2234 | md_apply_fix3 (fixP, valP, seg) |
252b5132 | 2235 | fixS *fixP; |
94f592af NC |
2236 | valueT *valP; |
2237 | segT seg ATTRIBUTE_UNUSED; | |
252b5132 RH |
2238 | { |
2239 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
a161fe53 | 2240 | long val = *valP; |
252b5132 RH |
2241 | |
2242 | switch (fixP->fx_size) | |
2243 | { | |
2244 | case 1: | |
2245 | *buf++ = val; | |
2246 | break; | |
2247 | case 2: | |
2248 | *buf++ = (val >> 8); | |
2249 | *buf++ = val; | |
2250 | break; | |
2251 | case 4: | |
2252 | *buf++ = (val >> 24); | |
2253 | *buf++ = (val >> 16); | |
2254 | *buf++ = (val >> 8); | |
2255 | *buf++ = val; | |
2256 | break; | |
2257 | default: | |
2258 | abort (); | |
2259 | } | |
94f592af NC |
2260 | |
2261 | if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) | |
2262 | fixP->fx_done = 1; | |
252b5132 RH |
2263 | } |
2264 | ||
2265 | int | |
2266 | md_estimate_size_before_relax (fragP, segment_type) | |
dbbc7809 JL |
2267 | register fragS *fragP ATTRIBUTE_UNUSED; |
2268 | register segT segment_type ATTRIBUTE_UNUSED; | |
252b5132 RH |
2269 | { |
2270 | printf (_("call tomd_estimate_size_before_relax \n")); | |
2271 | abort (); | |
2272 | } | |
2273 | ||
70d6ecf3 | 2274 | /* Put number into target byte order. */ |
252b5132 RH |
2275 | void |
2276 | md_number_to_chars (ptr, use, nbytes) | |
2277 | char *ptr; | |
2278 | valueT use; | |
2279 | int nbytes; | |
2280 | { | |
2281 | number_to_chars_bigendian (ptr, use, nbytes); | |
2282 | } | |
70d6ecf3 | 2283 | |
252b5132 RH |
2284 | long |
2285 | md_pcrel_from (fixP) | |
dbbc7809 | 2286 | fixS *fixP ATTRIBUTE_UNUSED; |
252b5132 RH |
2287 | { |
2288 | abort (); | |
2289 | } | |
2290 | ||
5facebfc | 2291 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
2292 | void |
2293 | tc_reloc_mangle (fix_ptr, intr, base) | |
2294 | fixS *fix_ptr; | |
2295 | struct internal_reloc *intr; | |
2296 | bfd_vma base; | |
2297 | ||
2298 | { | |
2299 | symbolS *symbol_ptr; | |
2300 | ||
2301 | symbol_ptr = fix_ptr->fx_addsy; | |
2302 | ||
2303 | /* If this relocation is attached to a symbol then it's ok | |
70d6ecf3 | 2304 | to output it. */ |
252b5132 RH |
2305 | if (fix_ptr->fx_r_type == TC_CONS_RELOC) |
2306 | { | |
2307 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
2308 | */ | |
2309 | switch (fix_ptr->fx_size) | |
2310 | { | |
2311 | case 4: | |
2312 | intr->r_type = R_RELLONG; | |
2313 | break; | |
2314 | case 2: | |
2315 | intr->r_type = R_RELWORD; | |
2316 | break; | |
2317 | case 1: | |
2318 | intr->r_type = R_RELBYTE; | |
2319 | break; | |
2320 | default: | |
2321 | abort (); | |
252b5132 | 2322 | } |
252b5132 RH |
2323 | } |
2324 | else | |
2325 | { | |
2326 | intr->r_type = fix_ptr->fx_r_type; | |
2327 | } | |
2328 | ||
2329 | intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base; | |
2330 | intr->r_offset = fix_ptr->fx_offset; | |
2331 | ||
2332 | if (symbol_ptr) | |
2333 | { | |
2334 | if (symbol_ptr->sy_number != -1) | |
2335 | intr->r_symndx = symbol_ptr->sy_number; | |
2336 | else | |
2337 | { | |
2338 | symbolS *segsym; | |
2339 | ||
2340 | /* This case arises when a reference is made to `.'. */ | |
2341 | segsym = seg_info (S_GET_SEGMENT (symbol_ptr))->dot; | |
2342 | if (segsym == NULL) | |
2343 | intr->r_symndx = -1; | |
2344 | else | |
2345 | { | |
2346 | intr->r_symndx = segsym->sy_number; | |
2347 | intr->r_offset += S_GET_VALUE (symbol_ptr); | |
2348 | } | |
2349 | } | |
2350 | } | |
2351 | else | |
2352 | intr->r_symndx = -1; | |
252b5132 | 2353 | } |
5facebfc | 2354 | #else /* BFD_ASSEMBLER */ |
f333765f JL |
2355 | arelent * |
2356 | tc_gen_reloc (section, fixp) | |
2357 | asection *section ATTRIBUTE_UNUSED; | |
2358 | fixS *fixp; | |
2359 | { | |
2360 | arelent *rel; | |
2361 | bfd_reloc_code_real_type r_type; | |
2362 | ||
de342d07 JL |
2363 | if (fixp->fx_addsy && fixp->fx_subsy) |
2364 | { | |
2365 | if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy)) | |
2366 | || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section) | |
2367 | { | |
2368 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
2369 | "Difference of symbols in different sections is not supported"); | |
2370 | return NULL; | |
2371 | } | |
2372 | } | |
2373 | ||
f333765f JL |
2374 | rel = (arelent *) xmalloc (sizeof (arelent)); |
2375 | rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
2376 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
2377 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
2378 | rel->addend = fixp->fx_offset; | |
2379 | ||
2380 | r_type = fixp->fx_r_type; | |
2381 | ||
2382 | #define DEBUG 0 | |
2383 | #if DEBUG | |
2384 | fprintf (stderr, "%s\n", bfd_get_reloc_code_name (r_type)); | |
2385 | fflush(stderr); | |
2386 | #endif | |
2387 | rel->howto = bfd_reloc_type_lookup (stdoutput, r_type); | |
2388 | if (rel->howto == NULL) | |
2389 | { | |
2390 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
2391 | _("Cannot represent relocation type %s"), | |
2392 | bfd_get_reloc_code_name (r_type)); | |
2393 | return NULL; | |
2394 | } | |
2395 | ||
2396 | return rel; | |
2397 | } | |
2398 | #endif |