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