Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-h8300.c -- Assemble code for the Hitachi H8/300 |
7e0de7bf | 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001 |
f7e42eb4 | 3 | 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" | |
28 | #define DEFINE_TABLE | |
29 | #define h8_opcodes ops | |
30 | #include "opcode/h8300.h" | |
31 | #include <ctype.h> | |
32 | ||
7e0de7bf JL |
33 | #ifdef OBJ_ELF |
34 | #include "elf/h8.h" | |
35 | ||
36 | #define R_MOV24B1 BFD_RELOC_H8_DIR24A8 | |
37 | #define R_MOVL1 BFD_RELOC_H8_DIR32A16 | |
38 | #define R_MOV24B1 BFD_RELOC_H8_DIR24A8 | |
39 | #define R_MOVL1 BFD_RELOC_H8_DIR32A16 | |
40 | #define R_RELLONG BFD_RELOC_32 | |
41 | #define R_MOV16B1 BFD_RELOC_H8_DIR16A8 | |
42 | #define R_RELWORD BFD_RELOC_16 | |
43 | #define R_RELBYTE BFD_RELOC_8 | |
44 | #define R_PCRWORD BFD_RELOC_16_PCREL | |
45 | #define R_PCRBYTE BFD_RELOC_8_PCREL | |
46 | #define R_JMPL1 BFD_RELOC_H8_DIR24R8 | |
47 | #endif | |
48 | ||
63a0b638 | 49 | const char comment_chars[] = ";"; |
252b5132 | 50 | const char line_comment_chars[] = "#"; |
63a0b638 | 51 | const char line_separator_chars[] = ""; |
252b5132 RH |
52 | |
53 | /* This table describes all the machine specific pseudo-ops the assembler | |
54 | has to support. The fields are: | |
55 | pseudo-op name without dot | |
56 | function to call to execute this pseudo-op | |
57 | Integer arg to pass to the function | |
58 | */ | |
59 | ||
60 | void cons (); | |
61 | ||
62 | int Hmode; | |
63 | int Smode; | |
64 | #define PSIZE (Hmode ? L_32 : L_16) | |
65 | #define DMODE (L_16) | |
66 | #define DSYMMODE (Hmode ? L_24 : L_16) | |
67 | int bsize = L_8; /* default branch displacement */ | |
68 | ||
252b5132 RH |
69 | void |
70 | h8300hmode () | |
71 | { | |
72 | Hmode = 1; | |
73 | Smode = 0; | |
83e20b45 JL |
74 | #ifdef BFD_ASSEMBLER |
75 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300h)) | |
76 | as_warn (_("could not set architecture and machine")); | |
77 | #endif | |
252b5132 RH |
78 | } |
79 | ||
80 | void | |
81 | h8300smode () | |
82 | { | |
83 | Smode = 1; | |
84 | Hmode = 1; | |
83e20b45 JL |
85 | #ifdef BFD_ASSEMBLER |
86 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300s)) | |
87 | as_warn (_("could not set architecture and machine")); | |
88 | #endif | |
252b5132 | 89 | } |
70d6ecf3 | 90 | |
252b5132 RH |
91 | void |
92 | sbranch (size) | |
93 | int size; | |
94 | { | |
95 | bsize = size; | |
96 | } | |
97 | ||
70d6ecf3 AM |
98 | static void |
99 | pint () | |
252b5132 RH |
100 | { |
101 | cons (Hmode ? 4 : 2); | |
102 | } | |
103 | ||
104 | const pseudo_typeS md_pseudo_table[] = | |
105 | { | |
252b5132 RH |
106 | {"h8300h", h8300hmode, 0}, |
107 | {"h8300s", h8300smode, 0}, | |
108 | {"sbranch", sbranch, L_8}, | |
109 | {"lbranch", sbranch, L_16}, | |
110 | ||
111 | {"int", pint, 0}, | |
112 | {"data.b", cons, 1}, | |
113 | {"data.w", cons, 2}, | |
114 | {"data.l", cons, 4}, | |
115 | {"form", listing_psize, 0}, | |
116 | {"heading", listing_title, 0}, | |
117 | {"import", s_ignore, 0}, | |
118 | {"page", listing_eject, 0}, | |
119 | {"program", s_ignore, 0}, | |
120 | {0, 0, 0} | |
121 | }; | |
122 | ||
123 | const int md_reloc_size; | |
124 | ||
125 | const char EXP_CHARS[] = "eE"; | |
126 | ||
127 | /* Chars that mean this number is a floating point constant */ | |
128 | /* As in 0f12.456 */ | |
129 | /* or 0d1.2345e12 */ | |
130 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
131 | ||
132 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics */ | |
133 | ||
70d6ecf3 AM |
134 | /* This function is called once, at assembler startup time. This |
135 | should set up all the tables, etc. that the MD part of the assembler | |
136 | needs. */ | |
252b5132 RH |
137 | void |
138 | md_begin () | |
139 | { | |
140 | struct h8_opcode *opcode; | |
141 | char prev_buffer[100]; | |
142 | int idx = 0; | |
143 | ||
83e20b45 JL |
144 | #ifdef BFD_ASSEMBLER |
145 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300)) | |
146 | as_warn (_("could not set architecture and machine")); | |
147 | #endif | |
148 | ||
252b5132 RH |
149 | opcode_hash_control = hash_new (); |
150 | prev_buffer[0] = 0; | |
151 | ||
152 | for (opcode = h8_opcodes; opcode->name; opcode++) | |
153 | { | |
154 | /* Strip off any . part when inserting the opcode and only enter | |
70d6ecf3 | 155 | unique codes into the hash table. */ |
252b5132 RH |
156 | char *src = opcode->name; |
157 | unsigned int len = strlen (src); | |
158 | char *dst = malloc (len + 1); | |
159 | char *buffer = dst; | |
160 | ||
161 | opcode->size = 0; | |
162 | while (*src) | |
163 | { | |
164 | if (*src == '.') | |
165 | { | |
166 | src++; | |
167 | opcode->size = *src; | |
168 | break; | |
169 | } | |
170 | *dst++ = *src++; | |
171 | } | |
172 | *dst++ = 0; | |
173 | if (strcmp (buffer, prev_buffer)) | |
174 | { | |
175 | hash_insert (opcode_hash_control, buffer, (char *) opcode); | |
176 | strcpy (prev_buffer, buffer); | |
177 | idx++; | |
178 | } | |
179 | opcode->idx = idx; | |
180 | ||
70d6ecf3 | 181 | /* Find the number of operands. */ |
252b5132 RH |
182 | opcode->noperands = 0; |
183 | while (opcode->args.nib[opcode->noperands] != E) | |
184 | opcode->noperands++; | |
70d6ecf3 AM |
185 | |
186 | /* Find the length of the opcode in bytes. */ | |
252b5132 RH |
187 | opcode->length = 0; |
188 | while (opcode->data.nib[opcode->length * 2] != E) | |
189 | opcode->length++; | |
190 | } | |
191 | ||
192 | linkrelax = 1; | |
193 | } | |
194 | ||
252b5132 RH |
195 | struct h8_exp |
196 | { | |
197 | char *e_beg; | |
198 | char *e_end; | |
199 | expressionS e_exp; | |
200 | }; | |
70d6ecf3 | 201 | |
252b5132 RH |
202 | int dispreg; |
203 | int opsize; /* Set when a register size is seen */ | |
204 | ||
252b5132 RH |
205 | struct h8_op |
206 | { | |
207 | op_type mode; | |
208 | unsigned reg; | |
209 | expressionS exp; | |
210 | }; | |
211 | ||
212 | /* | |
213 | parse operands | |
214 | WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp | |
215 | r0l,r0h,..r7l,r7h | |
216 | @WREG | |
217 | @WREG+ | |
218 | @-WREG | |
219 | #const | |
220 | ccr | |
221 | */ | |
222 | ||
bc0d738a NC |
223 | /* Try to parse a reg name. Return the number of chars consumed. */ |
224 | ||
40f09f82 | 225 | static int |
252b5132 RH |
226 | parse_reg (src, mode, reg, direction) |
227 | char *src; | |
228 | op_type *mode; | |
229 | unsigned int *reg; | |
230 | int direction; | |
231 | ||
232 | { | |
233 | char *end; | |
234 | int len; | |
235 | ||
70d6ecf3 | 236 | /* Cribbed from get_symbol_end. */ |
252b5132 RH |
237 | if (!is_name_beginner (*src) || *src == '\001') |
238 | return 0; | |
70d6ecf3 | 239 | end = src + 1; |
252b5132 RH |
240 | while (is_part_of_name (*end) || *end == '\001') |
241 | end++; | |
242 | len = end - src; | |
243 | ||
244 | if (len == 2 && src[0] == 's' && src[1] == 'p') | |
245 | { | |
246 | *mode = PSIZE | REG | direction; | |
247 | *reg = 7; | |
248 | return len; | |
249 | } | |
250 | if (len == 3 && src[0] == 'c' && src[1] == 'c' && src[2] == 'r') | |
251 | { | |
252 | *mode = CCR; | |
253 | *reg = 0; | |
254 | return len; | |
255 | } | |
256 | if (len == 3 && src[0] == 'e' && src[1] == 'x' && src[2] == 'r') | |
257 | { | |
258 | *mode = EXR; | |
259 | *reg = 0; | |
260 | return len; | |
261 | } | |
262 | if (len == 2 && src[0] == 'f' && src[1] == 'p') | |
263 | { | |
264 | *mode = PSIZE | REG | direction; | |
265 | *reg = 6; | |
266 | return len; | |
267 | } | |
268 | if (len == 3 && src[0] == 'e' && src[1] == 'r' | |
269 | && src[2] >= '0' && src[2] <= '7') | |
270 | { | |
271 | *mode = L_32 | REG | direction; | |
272 | *reg = src[2] - '0'; | |
273 | if (!Hmode) | |
274 | as_warn (_("Reg not valid for H8/300")); | |
275 | return len; | |
276 | } | |
277 | if (len == 2 && src[0] == 'e' && src[1] >= '0' && src[1] <= '7') | |
278 | { | |
279 | *mode = L_16 | REG | direction; | |
280 | *reg = src[1] - '0' + 8; | |
281 | if (!Hmode) | |
282 | as_warn (_("Reg not valid for H8/300")); | |
283 | return len; | |
284 | } | |
285 | ||
286 | if (src[0] == 'r') | |
287 | { | |
288 | if (src[1] >= '0' && src[1] <= '7') | |
289 | { | |
290 | if (len == 3 && src[2] == 'l') | |
291 | { | |
292 | *mode = L_8 | REG | direction; | |
293 | *reg = (src[1] - '0') + 8; | |
294 | return len; | |
295 | } | |
296 | if (len == 3 && src[2] == 'h') | |
297 | { | |
298 | *mode = L_8 | REG | direction; | |
299 | *reg = (src[1] - '0'); | |
300 | return len; | |
301 | } | |
302 | if (len == 2) | |
303 | { | |
304 | *mode = L_16 | REG | direction; | |
305 | *reg = (src[1] - '0'); | |
306 | return len; | |
307 | } | |
308 | } | |
309 | } | |
310 | ||
311 | return 0; | |
312 | } | |
313 | ||
40f09f82 | 314 | static char * |
252b5132 RH |
315 | parse_exp (s, op) |
316 | char *s; | |
70d6ecf3 | 317 | expressionS *op; |
252b5132 RH |
318 | { |
319 | char *save = input_line_pointer; | |
320 | char *new; | |
321 | ||
322 | input_line_pointer = s; | |
323 | expression (op); | |
324 | if (op->X_op == O_absent) | |
325 | as_bad (_("missing operand")); | |
326 | new = input_line_pointer; | |
327 | input_line_pointer = save; | |
328 | return new; | |
329 | } | |
330 | ||
331 | static char * | |
332 | skip_colonthing (ptr, exp, mode) | |
333 | char *ptr; | |
dbbc7809 | 334 | expressionS *exp ATTRIBUTE_UNUSED; |
252b5132 RH |
335 | int *mode; |
336 | { | |
337 | if (*ptr == ':') | |
338 | { | |
339 | ptr++; | |
340 | *mode &= ~SIZE; | |
341 | if (*ptr == '8') | |
342 | { | |
343 | ptr++; | |
344 | /* ff fill any 8 bit quantity */ | |
70d6ecf3 | 345 | /* exp->X_add_number -= 0x100; */ |
252b5132 RH |
346 | *mode |= L_8; |
347 | } | |
348 | else | |
349 | { | |
350 | if (*ptr == '2') | |
351 | { | |
352 | *mode |= L_24; | |
353 | } | |
354 | else if (*ptr == '3') | |
355 | { | |
356 | *mode |= L_32; | |
357 | } | |
358 | else if (*ptr == '1') | |
359 | { | |
360 | *mode |= L_16; | |
361 | } | |
362 | while (isdigit (*ptr)) | |
363 | ptr++; | |
364 | } | |
365 | } | |
366 | return ptr; | |
367 | } | |
368 | ||
369 | /* The many forms of operand: | |
370 | ||
371 | Rn Register direct | |
372 | @Rn Register indirect | |
373 | @(exp[:16], Rn) Register indirect with displacement | |
374 | @Rn+ | |
375 | @-Rn | |
70d6ecf3 AM |
376 | @aa:8 absolute 8 bit |
377 | @aa:16 absolute 16 bit | |
252b5132 RH |
378 | @aa absolute 16 bit |
379 | ||
380 | #xx[:size] immediate data | |
70d6ecf3 | 381 | @(exp:[8], pc) pc rel |
252b5132 RH |
382 | @@aa[:8] memory indirect |
383 | ||
384 | */ | |
385 | ||
386 | char * | |
387 | colonmod24 (op, src) | |
388 | struct h8_op *op; | |
389 | char *src; | |
390 | ||
391 | { | |
392 | int mode = 0; | |
393 | src = skip_colonthing (src, &op->exp, &mode); | |
394 | ||
395 | if (!mode) | |
396 | { | |
70d6ecf3 | 397 | /* Choose a default mode. */ |
252b5132 RH |
398 | if (op->exp.X_add_number < -32768 |
399 | || op->exp.X_add_number > 32767) | |
400 | { | |
401 | if (Hmode) | |
402 | mode = L_24; | |
403 | else | |
404 | mode = L_16; | |
405 | } | |
406 | else if (op->exp.X_add_symbol | |
407 | || op->exp.X_op_symbol) | |
408 | mode = DSYMMODE; | |
409 | else | |
410 | mode = DMODE; | |
411 | } | |
412 | op->mode |= mode; | |
413 | return src; | |
414 | ||
415 | } | |
416 | ||
252b5132 RH |
417 | static void |
418 | get_operand (ptr, op, dst, direction) | |
419 | char **ptr; | |
420 | struct h8_op *op; | |
dbbc7809 | 421 | unsigned int dst ATTRIBUTE_UNUSED; |
252b5132 RH |
422 | int direction; |
423 | { | |
424 | char *src = *ptr; | |
425 | op_type mode; | |
426 | unsigned int num; | |
427 | unsigned int len; | |
428 | ||
429 | op->mode = E; | |
430 | ||
431 | /* Gross. Gross. ldm and stm have a format not easily handled | |
432 | by get_operand. We deal with it explicitly here. */ | |
70d6ecf3 AM |
433 | if (src[0] == 'e' && src[1] == 'r' && isdigit (src[2]) |
434 | && src[3] == '-' && src[4] == 'e' && src[5] == 'r' && isdigit (src[6])) | |
252b5132 RH |
435 | { |
436 | int low, high; | |
437 | ||
438 | low = src[2] - '0'; | |
439 | high = src[6] - '0'; | |
440 | ||
441 | if (high < low) | |
442 | as_bad (_("Invalid register list for ldm/stm\n")); | |
443 | ||
444 | if (low % 2) | |
445 | as_bad (_("Invalid register list for ldm/stm\n")); | |
446 | ||
447 | if (high - low > 3) | |
448 | as_bad (_("Invalid register list for ldm/stm\n")); | |
449 | ||
450 | if (high - low != 1 | |
451 | && low % 4) | |
452 | as_bad (_("Invalid register list for ldm/stm\n")); | |
453 | ||
454 | /* Even sicker. We encode two registers into op->reg. One | |
455 | for the low register to save, the other for the high | |
456 | register to save; we also set the high bit in op->reg | |
457 | so we know this is "very special". */ | |
458 | op->reg = 0x80000000 | (high << 8) | low; | |
459 | op->mode = REG; | |
460 | *ptr = src + 7; | |
461 | return; | |
462 | } | |
463 | ||
464 | len = parse_reg (src, &op->mode, &op->reg, direction); | |
465 | if (len) | |
466 | { | |
467 | *ptr = src + len; | |
468 | return; | |
469 | } | |
470 | ||
471 | if (*src == '@') | |
472 | { | |
473 | src++; | |
474 | if (*src == '@') | |
475 | { | |
476 | src++; | |
477 | src = parse_exp (src, &op->exp); | |
478 | ||
479 | src = skip_colonthing (src, &op->exp, &op->mode); | |
480 | ||
481 | *ptr = src; | |
482 | ||
483 | op->mode = MEMIND; | |
484 | return; | |
252b5132 RH |
485 | } |
486 | ||
252b5132 RH |
487 | if (*src == '-') |
488 | { | |
489 | src++; | |
490 | len = parse_reg (src, &mode, &num, direction); | |
491 | if (len == 0) | |
492 | { | |
70d6ecf3 | 493 | /* Oops, not a reg after all, must be ordinary exp. */ |
252b5132 | 494 | src--; |
70d6ecf3 | 495 | /* Must be a symbol. */ |
252b5132 RH |
496 | op->mode = ABS | PSIZE | direction; |
497 | *ptr = skip_colonthing (parse_exp (src, &op->exp), | |
498 | &op->exp, &op->mode); | |
499 | ||
500 | return; | |
252b5132 RH |
501 | } |
502 | ||
252b5132 RH |
503 | if ((mode & SIZE) != PSIZE) |
504 | as_bad (_("Wrong size pointer register for architecture.")); | |
505 | op->mode = RDDEC; | |
506 | op->reg = num; | |
507 | *ptr = src + len; | |
508 | return; | |
509 | } | |
510 | if (*src == '(') | |
511 | { | |
70d6ecf3 | 512 | /* Disp. */ |
252b5132 RH |
513 | src++; |
514 | ||
70d6ecf3 | 515 | /* Start off assuming a 16 bit offset. */ |
252b5132 RH |
516 | |
517 | src = parse_exp (src, &op->exp); | |
518 | ||
519 | src = colonmod24 (op, src); | |
520 | ||
521 | if (*src == ')') | |
522 | { | |
523 | src++; | |
524 | op->mode |= ABS | direction; | |
525 | *ptr = src; | |
526 | return; | |
527 | } | |
528 | ||
529 | if (*src != ',') | |
530 | { | |
531 | as_bad (_("expected @(exp, reg16)")); | |
532 | return; | |
533 | ||
534 | } | |
535 | src++; | |
536 | ||
537 | len = parse_reg (src, &mode, &op->reg, direction); | |
538 | if (len == 0 || !(mode & REG)) | |
539 | { | |
540 | as_bad (_("expected @(exp, reg16)")); | |
541 | return; | |
542 | } | |
543 | op->mode |= DISP | direction; | |
544 | dispreg = op->reg; | |
545 | src += len; | |
546 | src = skip_colonthing (src, &op->exp, &op->mode); | |
547 | ||
548 | if (*src != ')' && '(') | |
549 | { | |
550 | as_bad (_("expected @(exp, reg16)")); | |
551 | return; | |
552 | } | |
553 | *ptr = src + 1; | |
554 | ||
555 | return; | |
556 | } | |
557 | len = parse_reg (src, &mode, &num, direction); | |
558 | ||
559 | if (len) | |
560 | { | |
561 | src += len; | |
562 | if (*src == '+') | |
563 | { | |
564 | src++; | |
565 | if ((mode & SIZE) != PSIZE) | |
566 | as_bad (_("Wrong size pointer register for architecture.")); | |
567 | op->mode = RSINC; | |
568 | op->reg = num; | |
569 | *ptr = src; | |
570 | return; | |
571 | } | |
572 | if ((mode & SIZE) != PSIZE) | |
573 | as_bad (_("Wrong size pointer register for architecture.")); | |
574 | ||
575 | op->mode = direction | IND | PSIZE; | |
576 | op->reg = num; | |
577 | *ptr = src; | |
578 | ||
579 | return; | |
580 | } | |
581 | else | |
582 | { | |
583 | /* must be a symbol */ | |
584 | ||
585 | op->mode = ABS | direction; | |
586 | src = parse_exp (src, &op->exp); | |
587 | ||
588 | *ptr = colonmod24 (op, src); | |
589 | ||
590 | return; | |
591 | } | |
592 | } | |
593 | ||
252b5132 RH |
594 | if (*src == '#') |
595 | { | |
596 | src++; | |
597 | op->mode = IMM; | |
598 | src = parse_exp (src, &op->exp); | |
599 | *ptr = skip_colonthing (src, &op->exp, &op->mode); | |
600 | ||
601 | return; | |
602 | } | |
603 | else if (strncmp (src, "mach", 4) == 0 | |
604 | || strncmp (src, "macl", 4) == 0) | |
605 | { | |
606 | op->reg = src[3] == 'l'; | |
607 | op->mode = MACREG; | |
608 | *ptr = src + 4; | |
609 | return; | |
610 | } | |
611 | else | |
612 | { | |
613 | src = parse_exp (src, &op->exp); | |
614 | /* Trailing ':' size ? */ | |
615 | if (*src == ':') | |
616 | { | |
617 | if (src[1] == '1' && src[2] == '6') | |
618 | { | |
619 | op->mode = PCREL | L_16; | |
620 | src += 3; | |
621 | } | |
622 | else if (src[1] == '8') | |
623 | { | |
624 | op->mode = PCREL | L_8; | |
625 | src += 2; | |
626 | } | |
627 | else | |
628 | { | |
629 | as_bad (_("expect :8 or :16 here")); | |
630 | } | |
631 | } | |
632 | else | |
633 | { | |
634 | op->mode = PCREL | bsize; | |
635 | } | |
636 | *ptr = src; | |
637 | } | |
638 | } | |
639 | ||
70d6ecf3 | 640 | static char * |
252b5132 RH |
641 | get_operands (noperands, op_end, operand) |
642 | unsigned int noperands; | |
643 | char *op_end; | |
644 | struct h8_op *operand; | |
645 | { | |
646 | char *ptr = op_end; | |
647 | ||
648 | switch (noperands) | |
649 | { | |
650 | case 0: | |
651 | operand[0].mode = 0; | |
652 | operand[1].mode = 0; | |
653 | break; | |
654 | ||
655 | case 1: | |
656 | ptr++; | |
657 | get_operand (&ptr, operand + 0, 0, SRC); | |
658 | if (*ptr == ',') | |
659 | { | |
660 | ptr++; | |
661 | get_operand (&ptr, operand + 1, 1, DST); | |
662 | } | |
663 | else | |
664 | { | |
665 | operand[1].mode = 0; | |
666 | } | |
252b5132 | 667 | break; |
70d6ecf3 | 668 | |
252b5132 RH |
669 | case 2: |
670 | ptr++; | |
671 | get_operand (&ptr, operand + 0, 0, SRC); | |
672 | if (*ptr == ',') | |
673 | ptr++; | |
674 | get_operand (&ptr, operand + 1, 1, DST); | |
675 | break; | |
676 | ||
677 | default: | |
678 | abort (); | |
679 | } | |
680 | ||
252b5132 RH |
681 | return ptr; |
682 | } | |
683 | ||
684 | /* Passed a pointer to a list of opcodes which use different | |
685 | addressing modes, return the opcode which matches the opcodes | |
70d6ecf3 AM |
686 | provided. */ |
687 | static struct h8_opcode * | |
252b5132 RH |
688 | get_specific (opcode, operands, size) |
689 | struct h8_opcode *opcode; | |
690 | struct h8_op *operands; | |
691 | int size; | |
692 | { | |
693 | struct h8_opcode *this_try = opcode; | |
694 | int found = 0; | |
695 | ||
696 | unsigned int this_index = opcode->idx; | |
697 | ||
698 | /* There's only one ldm/stm and it's easier to just | |
699 | get out quick for them. */ | |
700 | if (strcmp (opcode->name, "stm.l") == 0 | |
701 | || strcmp (opcode->name, "ldm.l") == 0) | |
702 | return this_try; | |
703 | ||
704 | while (this_index == opcode->idx && !found) | |
705 | { | |
706 | found = 1; | |
707 | ||
708 | this_try = opcode++; | |
709 | if (this_try->noperands == 0) | |
710 | { | |
711 | int this_size; | |
712 | ||
713 | this_size = this_try->how & SN; | |
714 | if (this_size != size && (this_size != SB || size != SN)) | |
715 | found = 0; | |
716 | } | |
717 | else | |
718 | { | |
719 | unsigned int i; | |
720 | ||
721 | for (i = 0; i < this_try->noperands && found; i++) | |
722 | { | |
723 | op_type op = this_try->args.nib[i]; | |
724 | int x = operands[i].mode; | |
725 | ||
726 | if ((op & (DISP | REG)) == (DISP | REG) | |
727 | && ((x & (DISP | REG)) == (DISP | REG))) | |
728 | { | |
729 | dispreg = operands[i].reg; | |
730 | } | |
731 | else if (op & REG) | |
732 | { | |
733 | if (!(x & REG)) | |
734 | found = 0; | |
735 | ||
736 | if (x & L_P) | |
737 | x = (x & ~L_P) | (Hmode ? L_32 : L_16); | |
738 | if (op & L_P) | |
739 | op = (op & ~L_P) | (Hmode ? L_32 : L_16); | |
740 | ||
741 | opsize = op & SIZE; | |
742 | ||
70d6ecf3 | 743 | /* The size of the reg is v important. */ |
252b5132 RH |
744 | if ((op & SIZE) != (x & SIZE)) |
745 | found = 0; | |
746 | } | |
747 | else if ((op & ABSJMP) && (x & ABS)) | |
748 | { | |
749 | operands[i].mode &= ~ABS; | |
750 | operands[i].mode |= ABSJMP; | |
70d6ecf3 | 751 | /* But it may not be 24 bits long. */ |
252b5132 RH |
752 | if (!Hmode) |
753 | { | |
754 | operands[i].mode &= ~SIZE; | |
755 | operands[i].mode |= L_16; | |
756 | } | |
757 | } | |
758 | else if ((op & (KBIT | DBIT)) && (x & IMM)) | |
759 | { | |
70d6ecf3 | 760 | /* This is ok if the immediate value is sensible. */ |
252b5132 RH |
761 | } |
762 | else if (op & PCREL) | |
763 | { | |
70d6ecf3 | 764 | /* The size of the displacement is important. */ |
252b5132 RH |
765 | if ((op & SIZE) != (x & SIZE)) |
766 | found = 0; | |
767 | } | |
768 | else if ((op & (DISP | IMM | ABS)) | |
769 | && (op & (DISP | IMM | ABS)) == (x & (DISP | IMM | ABS))) | |
770 | { | |
771 | /* Promote a L_24 to L_32 if it makes us match. */ | |
772 | if ((x & L_24) && (op & L_32)) | |
773 | { | |
774 | x &= ~L_24; | |
775 | x |= L_32; | |
776 | } | |
777 | /* Promote an L8 to L_16 if it makes us match. */ | |
70d6ecf3 | 778 | if (op & ABS && op & L_8 && op & DISP) |
252b5132 RH |
779 | { |
780 | if (x & L_16) | |
70d6ecf3 | 781 | found = 1; |
252b5132 RH |
782 | } |
783 | else if ((x & SIZE) != 0 | |
784 | && ((op & SIZE) != (x & SIZE))) | |
785 | found = 0; | |
786 | } | |
787 | else if ((op & MACREG) != (x & MACREG)) | |
788 | { | |
789 | found = 0; | |
790 | } | |
791 | else if ((op & MODE) != (x & MODE)) | |
792 | { | |
793 | found = 0; | |
70d6ecf3 | 794 | } |
252b5132 RH |
795 | } |
796 | } | |
797 | } | |
798 | if (found) | |
799 | return this_try; | |
800 | else | |
801 | return 0; | |
802 | } | |
803 | ||
804 | static void | |
805 | check_operand (operand, width, string) | |
806 | struct h8_op *operand; | |
807 | unsigned int width; | |
808 | char *string; | |
809 | { | |
810 | if (operand->exp.X_add_symbol == 0 | |
811 | && operand->exp.X_op_symbol == 0) | |
812 | { | |
70d6ecf3 AM |
813 | /* No symbol involved, let's look at offset, it's dangerous if |
814 | any of the high bits are not 0 or ff's, find out by oring or | |
815 | anding with the width and seeing if the answer is 0 or all | |
816 | fs. */ | |
252b5132 | 817 | |
252b5132 RH |
818 | if ((operand->exp.X_add_number & ~width) != 0 && |
819 | (operand->exp.X_add_number | width) != (~0)) | |
820 | { | |
70d6ecf3 | 821 | if (width == 255 |
252b5132 RH |
822 | && (operand->exp.X_add_number & 0xff00) == 0xff00) |
823 | { | |
824 | /* Just ignore this one - which happens when trying to | |
825 | fit a 16 bit address truncated into an 8 bit address | |
826 | of something like bset. */ | |
827 | } | |
70d6ecf3 | 828 | else |
252b5132 RH |
829 | { |
830 | as_warn (_("operand %s0x%lx out of range."), string, | |
831 | (unsigned long) operand->exp.X_add_number); | |
832 | } | |
833 | } | |
834 | } | |
252b5132 RH |
835 | } |
836 | ||
837 | /* RELAXMODE has one of 3 values: | |
838 | ||
839 | 0 Output a "normal" reloc, no relaxing possible for this insn/reloc | |
840 | ||
841 | 1 Output a relaxable 24bit absolute mov.w address relocation | |
842 | (may relax into a 16bit absolute address). | |
843 | ||
844 | 2 Output a relaxable 16/24 absolute mov.b address relocation | |
845 | (may relax into an 8bit absolute address). */ | |
846 | ||
847 | static void | |
848 | do_a_fix_imm (offset, operand, relaxmode) | |
849 | int offset; | |
850 | struct h8_op *operand; | |
851 | int relaxmode; | |
852 | { | |
853 | int idx; | |
854 | int size; | |
855 | int where; | |
856 | ||
252b5132 RH |
857 | char *t = operand->mode & IMM ? "#" : "@"; |
858 | ||
859 | if (operand->exp.X_add_symbol == 0) | |
860 | { | |
861 | char *bytes = frag_now->fr_literal + offset; | |
862 | switch (operand->mode & SIZE) | |
863 | { | |
864 | case L_2: | |
865 | check_operand (operand, 0x3, t); | |
866 | bytes[0] |= (operand->exp.X_add_number) << 4; | |
867 | break; | |
868 | case L_3: | |
869 | check_operand (operand, 0x7, t); | |
870 | bytes[0] |= (operand->exp.X_add_number) << 4; | |
871 | break; | |
872 | case L_8: | |
873 | check_operand (operand, 0xff, t); | |
874 | bytes[0] = operand->exp.X_add_number; | |
875 | break; | |
876 | case L_16: | |
877 | check_operand (operand, 0xffff, t); | |
878 | bytes[0] = operand->exp.X_add_number >> 8; | |
879 | bytes[1] = operand->exp.X_add_number >> 0; | |
880 | break; | |
881 | case L_24: | |
882 | check_operand (operand, 0xffffff, t); | |
883 | bytes[0] = operand->exp.X_add_number >> 16; | |
884 | bytes[1] = operand->exp.X_add_number >> 8; | |
885 | bytes[2] = operand->exp.X_add_number >> 0; | |
886 | break; | |
887 | ||
888 | case L_32: | |
70d6ecf3 | 889 | /* This should be done with bfd. */ |
252b5132 RH |
890 | bytes[0] = operand->exp.X_add_number >> 24; |
891 | bytes[1] = operand->exp.X_add_number >> 16; | |
892 | bytes[2] = operand->exp.X_add_number >> 8; | |
893 | bytes[3] = operand->exp.X_add_number >> 0; | |
4132022d AM |
894 | if (relaxmode != 0) |
895 | { | |
896 | idx = (relaxmode == 2) ? R_MOV24B1 : R_MOVL1; | |
897 | fix_new_exp (frag_now, offset, 4, &operand->exp, 0, idx); | |
898 | } | |
252b5132 RH |
899 | break; |
900 | } | |
252b5132 RH |
901 | } |
902 | else | |
903 | { | |
904 | switch (operand->mode & SIZE) | |
905 | { | |
252b5132 RH |
906 | case L_24: |
907 | case L_32: | |
908 | size = 4; | |
909 | where = (operand->mode & SIZE) == L_24 ? -1 : 0; | |
910 | if (relaxmode == 2) | |
911 | idx = R_MOV24B1; | |
912 | else if (relaxmode == 1) | |
913 | idx = R_MOVL1; | |
914 | else | |
915 | idx = R_RELLONG; | |
916 | break; | |
917 | default: | |
70d6ecf3 | 918 | as_bad (_("Can't work out size of operand.\n")); |
252b5132 RH |
919 | case L_16: |
920 | size = 2; | |
921 | where = 0; | |
922 | if (relaxmode == 2) | |
923 | idx = R_MOV16B1; | |
924 | else | |
925 | idx = R_RELWORD; | |
4132022d AM |
926 | operand->exp.X_add_number = |
927 | ((operand->exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000; | |
252b5132 RH |
928 | break; |
929 | case L_8: | |
930 | size = 1; | |
931 | where = 0; | |
932 | idx = R_RELBYTE; | |
4132022d AM |
933 | operand->exp.X_add_number = |
934 | ((operand->exp.X_add_number & 0xff) ^ 0x80) - 0x80; | |
252b5132 RH |
935 | } |
936 | ||
937 | fix_new_exp (frag_now, | |
938 | offset + where, | |
939 | size, | |
940 | &operand->exp, | |
941 | 0, | |
942 | idx); | |
943 | } | |
252b5132 RH |
944 | } |
945 | ||
70d6ecf3 | 946 | /* Now we know what sort of opcodes it is, let's build the bytes. */ |
252b5132 RH |
947 | static void |
948 | build_bytes (this_try, operand) | |
949 | struct h8_opcode *this_try; | |
950 | struct h8_op *operand; | |
951 | { | |
952 | unsigned int i; | |
953 | ||
954 | char *output = frag_more (this_try->length); | |
955 | op_type *nibble_ptr = this_try->data.nib; | |
956 | op_type c; | |
957 | unsigned int nibble_count = 0; | |
958 | int absat; | |
959 | int immat; | |
960 | int nib; | |
961 | int movb = 0; | |
962 | char asnibbles[30]; | |
963 | char *p = asnibbles; | |
964 | ||
965 | if (!(this_try->inbase || Hmode)) | |
966 | as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"), | |
967 | this_try->name); | |
968 | ||
969 | while (*nibble_ptr != E) | |
970 | { | |
971 | int d; | |
972 | c = *nibble_ptr++; | |
973 | ||
974 | d = (c & (DST | SRC_IN_DST)) != 0; | |
975 | ||
976 | if (c < 16) | |
977 | { | |
978 | nib = c; | |
979 | } | |
980 | else | |
981 | { | |
252b5132 RH |
982 | if (c & (REG | IND | INC | DEC)) |
983 | { | |
984 | nib = operand[d].reg; | |
985 | } | |
986 | else if ((c & DISPREG) == (DISPREG)) | |
987 | { | |
988 | nib = dispreg; | |
989 | } | |
70d6ecf3 | 990 | else if (c & ABS) |
252b5132 RH |
991 | { |
992 | operand[d].mode = c; | |
993 | absat = nibble_count / 2; | |
994 | nib = 0; | |
995 | } | |
996 | else if (c & (IMM | PCREL | ABS | ABSJMP | DISP)) | |
997 | { | |
998 | operand[d].mode = c; | |
999 | immat = nibble_count / 2; | |
1000 | nib = 0; | |
1001 | } | |
1002 | else if (c & IGNORE) | |
1003 | { | |
1004 | nib = 0; | |
1005 | } | |
1006 | else if (c & DBIT) | |
1007 | { | |
1008 | switch (operand[0].exp.X_add_number) | |
1009 | { | |
1010 | case 1: | |
1011 | nib = c; | |
1012 | break; | |
1013 | case 2: | |
1014 | nib = 0x8 | c; | |
1015 | break; | |
1016 | default: | |
1017 | as_bad (_("Need #1 or #2 here")); | |
1018 | } | |
1019 | } | |
1020 | else if (c & KBIT) | |
1021 | { | |
1022 | switch (operand[0].exp.X_add_number) | |
1023 | { | |
1024 | case 1: | |
1025 | nib = 0; | |
1026 | break; | |
1027 | case 2: | |
1028 | nib = 8; | |
1029 | break; | |
1030 | case 4: | |
1031 | if (!Hmode) | |
1032 | as_warn (_("#4 not valid on H8/300.")); | |
1033 | nib = 9; | |
1034 | break; | |
1035 | ||
1036 | default: | |
1037 | as_bad (_("Need #1 or #2 here")); | |
1038 | break; | |
1039 | } | |
70d6ecf3 | 1040 | /* Stop it making a fix. */ |
252b5132 RH |
1041 | operand[0].mode = 0; |
1042 | } | |
1043 | ||
1044 | if (c & MEMRELAX) | |
1045 | { | |
1046 | operand[d].mode |= MEMRELAX; | |
1047 | } | |
1048 | ||
1049 | if (c & B31) | |
1050 | { | |
1051 | nib |= 0x8; | |
1052 | } | |
1053 | ||
1054 | if (c & MACREG) | |
1055 | { | |
f0c56b90 NC |
1056 | if (operand[0].mode == MACREG) |
1057 | /* stmac has mac[hl] as the first operand. */ | |
1058 | nib = 2 + operand[0].reg; | |
1059 | else | |
1060 | /* ldmac has mac[hl] as the second operand. */ | |
1061 | nib = 2 + operand[1].reg; | |
252b5132 RH |
1062 | } |
1063 | } | |
1064 | nibble_count++; | |
1065 | ||
1066 | *p++ = nib; | |
1067 | } | |
1068 | ||
1069 | /* Disgusting. Why, oh why didn't someone ask us for advice | |
1070 | on the assembler format. */ | |
1071 | if (strcmp (this_try->name, "stm.l") == 0 | |
1072 | || strcmp (this_try->name, "ldm.l") == 0) | |
1073 | { | |
1074 | int high, low; | |
1075 | high = (operand[this_try->name[0] == 'l' ? 1 : 0].reg >> 8) & 0xf; | |
1076 | low = operand[this_try->name[0] == 'l' ? 1 : 0].reg & 0xf; | |
1077 | ||
1078 | asnibbles[2] = high - low; | |
1079 | asnibbles[7] = (this_try->name[0] == 'l') ? high : low; | |
1080 | } | |
1081 | ||
1082 | for (i = 0; i < this_try->length; i++) | |
1083 | { | |
1084 | output[i] = (asnibbles[i * 2] << 4) | asnibbles[i * 2 + 1]; | |
1085 | } | |
1086 | ||
1087 | /* Note if this is a movb instruction -- there's a special relaxation | |
1088 | which only applies to them. */ | |
1089 | if (strcmp (this_try->name, "mov.b") == 0) | |
1090 | movb = 1; | |
1091 | ||
70d6ecf3 | 1092 | /* Output any fixes. */ |
252b5132 RH |
1093 | for (i = 0; i < 2; i++) |
1094 | { | |
1095 | int x = operand[i].mode; | |
1096 | ||
1097 | if (x & (IMM | DISP)) | |
1098 | { | |
1099 | do_a_fix_imm (output - frag_now->fr_literal + immat, | |
1100 | operand + i, x & MEMRELAX != 0); | |
1101 | } | |
1102 | else if (x & ABS) | |
1103 | { | |
1104 | do_a_fix_imm (output - frag_now->fr_literal + absat, | |
1105 | operand + i, x & MEMRELAX ? movb + 1 : 0); | |
1106 | } | |
1107 | else if (x & PCREL) | |
1108 | { | |
1109 | int size16 = x & L_16; | |
1110 | int where = size16 ? 2 : 1; | |
1111 | int size = size16 ? 2 : 1; | |
1112 | int type = size16 ? R_PCRWORD : R_PCRBYTE; | |
1113 | ||
1114 | check_operand (operand + i, size16 ? 0x7fff : 0x7f, "@"); | |
1115 | ||
1116 | if (operand[i].exp.X_add_number & 1) | |
1117 | { | |
1118 | as_warn (_("branch operand has odd offset (%lx)\n"), | |
1119 | (unsigned long) operand->exp.X_add_number); | |
1120 | } | |
1121 | ||
1122 | operand[i].exp.X_add_number -= 1; | |
4132022d AM |
1123 | operand[i].exp.X_add_number = |
1124 | ((operand[i].exp.X_add_number & 0xff) ^ 0x80) - 0x80; | |
252b5132 RH |
1125 | |
1126 | fix_new_exp (frag_now, | |
1127 | output - frag_now->fr_literal + where, | |
1128 | size, | |
1129 | &operand[i].exp, | |
1130 | 1, | |
1131 | type); | |
1132 | } | |
1133 | else if (x & MEMIND) | |
1134 | { | |
252b5132 RH |
1135 | check_operand (operand + i, 0xff, "@@"); |
1136 | fix_new_exp (frag_now, | |
1137 | output - frag_now->fr_literal + 1, | |
1138 | 1, | |
1139 | &operand[i].exp, | |
1140 | 0, | |
1141 | R_MEM_INDIRECT); | |
1142 | } | |
1143 | else if (x & ABSJMP) | |
1144 | { | |
70d6ecf3 | 1145 | /* This jmp may be a jump or a branch. */ |
252b5132 RH |
1146 | |
1147 | check_operand (operand + i, Hmode ? 0xffffff : 0xffff, "@"); | |
1148 | if (operand[i].exp.X_add_number & 1) | |
1149 | { | |
1150 | as_warn (_("branch operand has odd offset (%lx)\n"), | |
1151 | (unsigned long) operand->exp.X_add_number); | |
1152 | } | |
1153 | if (!Hmode) | |
70d6ecf3 | 1154 | operand[i].exp.X_add_number = |
4132022d | 1155 | ((operand[i].exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000; |
252b5132 RH |
1156 | fix_new_exp (frag_now, |
1157 | output - frag_now->fr_literal, | |
1158 | 4, | |
1159 | &operand[i].exp, | |
1160 | 0, | |
1161 | R_JMPL1); | |
1162 | } | |
1163 | } | |
252b5132 RH |
1164 | } |
1165 | ||
70d6ecf3 AM |
1166 | /* Try to give an intelligent error message for common and simple to |
1167 | detect errors. */ | |
252b5132 RH |
1168 | static void |
1169 | clever_message (opcode, operand) | |
1170 | struct h8_opcode *opcode; | |
1171 | struct h8_op *operand; | |
1172 | { | |
70d6ecf3 | 1173 | /* Find out if there was more than one possible opcode. */ |
252b5132 RH |
1174 | |
1175 | if ((opcode + 1)->idx != opcode->idx) | |
1176 | { | |
1177 | unsigned int argn; | |
1178 | ||
70d6ecf3 AM |
1179 | /* Only one opcode of this flavour, try to guess which operand |
1180 | didn't match. */ | |
252b5132 RH |
1181 | for (argn = 0; argn < opcode->noperands; argn++) |
1182 | { | |
1183 | switch (opcode->args.nib[argn]) | |
1184 | { | |
1185 | case RD16: | |
1186 | if (operand[argn].mode != RD16) | |
1187 | { | |
1188 | as_bad (_("destination operand must be 16 bit register")); | |
1189 | return; | |
1190 | ||
1191 | } | |
1192 | break; | |
1193 | ||
1194 | case RS8: | |
252b5132 RH |
1195 | if (operand[argn].mode != RS8) |
1196 | { | |
1197 | as_bad (_("source operand must be 8 bit register")); | |
1198 | return; | |
1199 | } | |
1200 | break; | |
1201 | ||
1202 | case ABS16DST: | |
1203 | if (operand[argn].mode != ABS16DST) | |
1204 | { | |
1205 | as_bad (_("destination operand must be 16bit absolute address")); | |
1206 | return; | |
1207 | } | |
1208 | break; | |
1209 | case RD8: | |
1210 | if (operand[argn].mode != RD8) | |
1211 | { | |
1212 | as_bad (_("destination operand must be 8 bit register")); | |
1213 | return; | |
1214 | } | |
1215 | break; | |
1216 | ||
252b5132 RH |
1217 | case ABS16SRC: |
1218 | if (operand[argn].mode != ABS16SRC) | |
1219 | { | |
1220 | as_bad (_("source operand must be 16bit absolute address")); | |
1221 | return; | |
1222 | } | |
1223 | break; | |
1224 | ||
1225 | } | |
1226 | } | |
1227 | } | |
1228 | as_bad (_("invalid operands")); | |
1229 | } | |
1230 | ||
70d6ecf3 AM |
1231 | /* This is the guts of the machine-dependent assembler. STR points to |
1232 | a machine dependent instruction. This function is supposed to emit | |
1233 | the frags/bytes it assembles. */ | |
252b5132 RH |
1234 | void |
1235 | md_assemble (str) | |
1236 | char *str; | |
1237 | { | |
1238 | char *op_start; | |
1239 | char *op_end; | |
1240 | struct h8_op operand[2]; | |
1241 | struct h8_opcode *opcode; | |
1242 | struct h8_opcode *prev_opcode; | |
1243 | ||
1244 | char *dot = 0; | |
1245 | char c; | |
1246 | int size; | |
1247 | ||
70d6ecf3 | 1248 | /* Drop leading whitespace. */ |
252b5132 RH |
1249 | while (*str == ' ') |
1250 | str++; | |
1251 | ||
70d6ecf3 | 1252 | /* Find the op code end. */ |
252b5132 RH |
1253 | for (op_start = op_end = str; |
1254 | *op_end != 0 && *op_end != ' '; | |
1255 | op_end++) | |
1256 | { | |
1257 | if (*op_end == '.') | |
1258 | { | |
1259 | dot = op_end + 1; | |
1260 | *op_end = 0; | |
1261 | op_end += 2; | |
1262 | break; | |
1263 | } | |
1264 | } | |
1265 | ||
252b5132 RH |
1266 | if (op_end == op_start) |
1267 | { | |
1268 | as_bad (_("can't find opcode ")); | |
1269 | } | |
1270 | c = *op_end; | |
1271 | ||
1272 | *op_end = 0; | |
1273 | ||
1274 | opcode = (struct h8_opcode *) hash_find (opcode_hash_control, | |
1275 | op_start); | |
1276 | ||
1277 | if (opcode == NULL) | |
1278 | { | |
1279 | as_bad (_("unknown opcode")); | |
1280 | return; | |
1281 | } | |
1282 | ||
70d6ecf3 | 1283 | /* We used to set input_line_pointer to the result of get_operands, |
252b5132 RH |
1284 | but that is wrong. Our caller assumes we don't change it. */ |
1285 | ||
1286 | (void) get_operands (opcode->noperands, op_end, operand); | |
1287 | *op_end = c; | |
1288 | prev_opcode = opcode; | |
1289 | ||
1290 | size = SN; | |
1291 | if (dot) | |
1292 | { | |
1293 | switch (*dot) | |
1294 | { | |
1295 | case 'b': | |
1296 | size = SB; | |
1297 | break; | |
1298 | ||
1299 | case 'w': | |
1300 | size = SW; | |
1301 | break; | |
1302 | ||
1303 | case 'l': | |
1304 | size = SL; | |
1305 | break; | |
1306 | } | |
1307 | } | |
1308 | opcode = get_specific (opcode, operand, size); | |
1309 | ||
1310 | if (opcode == 0) | |
1311 | { | |
70d6ecf3 | 1312 | /* Couldn't find an opcode which matched the operands. */ |
252b5132 RH |
1313 | char *where = frag_more (2); |
1314 | ||
1315 | where[0] = 0x0; | |
1316 | where[1] = 0x0; | |
1317 | clever_message (prev_opcode, operand); | |
1318 | ||
1319 | return; | |
1320 | } | |
1321 | if (opcode->size && dot) | |
1322 | { | |
1323 | if (opcode->size != *dot) | |
1324 | { | |
1325 | as_warn (_("mismatch between opcode size and operand size")); | |
1326 | } | |
1327 | } | |
1328 | ||
1329 | build_bytes (opcode, operand); | |
252b5132 RH |
1330 | } |
1331 | ||
5facebfc | 1332 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
1333 | void |
1334 | tc_crawl_symbol_chain (headers) | |
70d6ecf3 | 1335 | object_headers *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
1336 | { |
1337 | printf (_("call to tc_crawl_symbol_chain \n")); | |
1338 | } | |
f333765f | 1339 | #endif |
252b5132 RH |
1340 | |
1341 | symbolS * | |
1342 | md_undefined_symbol (name) | |
dbbc7809 | 1343 | char *name ATTRIBUTE_UNUSED; |
252b5132 RH |
1344 | { |
1345 | return 0; | |
1346 | } | |
1347 | ||
5facebfc | 1348 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
1349 | void |
1350 | tc_headers_hook (headers) | |
70d6ecf3 | 1351 | object_headers *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
1352 | { |
1353 | printf (_("call to tc_headers_hook \n")); | |
1354 | } | |
f333765f | 1355 | #endif |
252b5132 RH |
1356 | |
1357 | /* Various routines to kill one day */ | |
1358 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
1359 | #define MAX_LITTLENUMS 6 | |
1360 | ||
70d6ecf3 AM |
1361 | /* Turn a string in input_line_pointer into a floating point constant |
1362 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
bc0d738a | 1363 | of LITTLENUMS emitted is stored in *SIZEP. An error message is |
70d6ecf3 | 1364 | returned, or NULL on OK. */ |
bc0d738a | 1365 | |
252b5132 RH |
1366 | char * |
1367 | md_atof (type, litP, sizeP) | |
1368 | char type; | |
1369 | char *litP; | |
1370 | int *sizeP; | |
1371 | { | |
1372 | int prec; | |
1373 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1374 | LITTLENUM_TYPE *wordP; | |
1375 | char *t; | |
1376 | char *atof_ieee (); | |
1377 | ||
1378 | switch (type) | |
1379 | { | |
1380 | case 'f': | |
1381 | case 'F': | |
1382 | case 's': | |
1383 | case 'S': | |
1384 | prec = 2; | |
1385 | break; | |
1386 | ||
1387 | case 'd': | |
1388 | case 'D': | |
1389 | case 'r': | |
1390 | case 'R': | |
1391 | prec = 4; | |
1392 | break; | |
1393 | ||
1394 | case 'x': | |
1395 | case 'X': | |
1396 | prec = 6; | |
1397 | break; | |
1398 | ||
1399 | case 'p': | |
1400 | case 'P': | |
1401 | prec = 6; | |
1402 | break; | |
1403 | ||
1404 | default: | |
1405 | *sizeP = 0; | |
1406 | return _("Bad call to MD_ATOF()"); | |
1407 | } | |
1408 | t = atof_ieee (input_line_pointer, type, words); | |
1409 | if (t) | |
1410 | input_line_pointer = t; | |
1411 | ||
1412 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
1413 | for (wordP = words; prec--;) | |
1414 | { | |
1415 | md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
1416 | litP += sizeof (LITTLENUM_TYPE); | |
1417 | } | |
1418 | return 0; | |
1419 | } | |
1420 | \f | |
1421 | CONST char *md_shortopts = ""; | |
1422 | struct option md_longopts[] = { | |
1423 | {NULL, no_argument, NULL, 0} | |
1424 | }; | |
70d6ecf3 AM |
1425 | |
1426 | size_t md_longopts_size = sizeof (md_longopts); | |
252b5132 RH |
1427 | |
1428 | int | |
1429 | md_parse_option (c, arg) | |
dbbc7809 JL |
1430 | int c ATTRIBUTE_UNUSED; |
1431 | char *arg ATTRIBUTE_UNUSED; | |
252b5132 RH |
1432 | { |
1433 | return 0; | |
1434 | } | |
1435 | ||
1436 | void | |
1437 | md_show_usage (stream) | |
dbbc7809 | 1438 | FILE *stream ATTRIBUTE_UNUSED; |
252b5132 RH |
1439 | { |
1440 | } | |
1441 | \f | |
1442 | void | |
1443 | tc_aout_fix_to_chars () | |
1444 | { | |
1445 | printf (_("call to tc_aout_fix_to_chars \n")); | |
1446 | abort (); | |
1447 | } | |
1448 | ||
1449 | void | |
1450 | md_convert_frag (headers, seg, fragP) | |
dbbc7809 JL |
1451 | object_headers *headers ATTRIBUTE_UNUSED; |
1452 | segT seg ATTRIBUTE_UNUSED; | |
1453 | fragS *fragP ATTRIBUTE_UNUSED; | |
252b5132 RH |
1454 | { |
1455 | printf (_("call to md_convert_frag \n")); | |
1456 | abort (); | |
1457 | } | |
1458 | ||
70d6ecf3 | 1459 | valueT |
252b5132 RH |
1460 | md_section_align (seg, size) |
1461 | segT seg; | |
1462 | valueT size; | |
1463 | { | |
70d6ecf3 AM |
1464 | return ((size + (1 << section_alignment[(int) seg]) - 1) |
1465 | & (-1 << section_alignment[(int) seg])); | |
252b5132 RH |
1466 | } |
1467 | ||
1468 | void | |
1469 | md_apply_fix (fixP, val) | |
1470 | fixS *fixP; | |
1471 | long val; | |
1472 | { | |
1473 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
1474 | ||
1475 | switch (fixP->fx_size) | |
1476 | { | |
1477 | case 1: | |
1478 | *buf++ = val; | |
1479 | break; | |
1480 | case 2: | |
1481 | *buf++ = (val >> 8); | |
1482 | *buf++ = val; | |
1483 | break; | |
1484 | case 4: | |
1485 | *buf++ = (val >> 24); | |
1486 | *buf++ = (val >> 16); | |
1487 | *buf++ = (val >> 8); | |
1488 | *buf++ = val; | |
1489 | break; | |
1490 | default: | |
1491 | abort (); | |
1492 | } | |
1493 | } | |
1494 | ||
1495 | int | |
1496 | md_estimate_size_before_relax (fragP, segment_type) | |
dbbc7809 JL |
1497 | register fragS *fragP ATTRIBUTE_UNUSED; |
1498 | register segT segment_type ATTRIBUTE_UNUSED; | |
252b5132 RH |
1499 | { |
1500 | printf (_("call tomd_estimate_size_before_relax \n")); | |
1501 | abort (); | |
1502 | } | |
1503 | ||
70d6ecf3 | 1504 | /* Put number into target byte order. */ |
252b5132 RH |
1505 | void |
1506 | md_number_to_chars (ptr, use, nbytes) | |
1507 | char *ptr; | |
1508 | valueT use; | |
1509 | int nbytes; | |
1510 | { | |
1511 | number_to_chars_bigendian (ptr, use, nbytes); | |
1512 | } | |
70d6ecf3 | 1513 | |
252b5132 RH |
1514 | long |
1515 | md_pcrel_from (fixP) | |
dbbc7809 | 1516 | fixS *fixP ATTRIBUTE_UNUSED; |
252b5132 RH |
1517 | { |
1518 | abort (); | |
1519 | } | |
1520 | ||
5facebfc | 1521 | #ifndef BFD_ASSEMBLER |
252b5132 RH |
1522 | void |
1523 | tc_reloc_mangle (fix_ptr, intr, base) | |
1524 | fixS *fix_ptr; | |
1525 | struct internal_reloc *intr; | |
1526 | bfd_vma base; | |
1527 | ||
1528 | { | |
1529 | symbolS *symbol_ptr; | |
1530 | ||
1531 | symbol_ptr = fix_ptr->fx_addsy; | |
1532 | ||
1533 | /* If this relocation is attached to a symbol then it's ok | |
70d6ecf3 | 1534 | to output it. */ |
252b5132 RH |
1535 | if (fix_ptr->fx_r_type == TC_CONS_RELOC) |
1536 | { | |
1537 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
1538 | */ | |
1539 | switch (fix_ptr->fx_size) | |
1540 | { | |
1541 | case 4: | |
1542 | intr->r_type = R_RELLONG; | |
1543 | break; | |
1544 | case 2: | |
1545 | intr->r_type = R_RELWORD; | |
1546 | break; | |
1547 | case 1: | |
1548 | intr->r_type = R_RELBYTE; | |
1549 | break; | |
1550 | default: | |
1551 | abort (); | |
252b5132 | 1552 | } |
252b5132 RH |
1553 | } |
1554 | else | |
1555 | { | |
1556 | intr->r_type = fix_ptr->fx_r_type; | |
1557 | } | |
1558 | ||
1559 | intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base; | |
1560 | intr->r_offset = fix_ptr->fx_offset; | |
1561 | ||
1562 | if (symbol_ptr) | |
1563 | { | |
1564 | if (symbol_ptr->sy_number != -1) | |
1565 | intr->r_symndx = symbol_ptr->sy_number; | |
1566 | else | |
1567 | { | |
1568 | symbolS *segsym; | |
1569 | ||
1570 | /* This case arises when a reference is made to `.'. */ | |
1571 | segsym = seg_info (S_GET_SEGMENT (symbol_ptr))->dot; | |
1572 | if (segsym == NULL) | |
1573 | intr->r_symndx = -1; | |
1574 | else | |
1575 | { | |
1576 | intr->r_symndx = segsym->sy_number; | |
1577 | intr->r_offset += S_GET_VALUE (symbol_ptr); | |
1578 | } | |
1579 | } | |
1580 | } | |
1581 | else | |
1582 | intr->r_symndx = -1; | |
252b5132 | 1583 | } |
5facebfc | 1584 | #else /* BFD_ASSEMBLER */ |
f333765f JL |
1585 | arelent * |
1586 | tc_gen_reloc (section, fixp) | |
1587 | asection *section ATTRIBUTE_UNUSED; | |
1588 | fixS *fixp; | |
1589 | { | |
1590 | arelent *rel; | |
1591 | bfd_reloc_code_real_type r_type; | |
1592 | ||
1593 | rel = (arelent *) xmalloc (sizeof (arelent)); | |
1594 | rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
1595 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
1596 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
1597 | rel->addend = fixp->fx_offset; | |
1598 | ||
1599 | r_type = fixp->fx_r_type; | |
1600 | ||
1601 | #define DEBUG 0 | |
1602 | #if DEBUG | |
1603 | fprintf (stderr, "%s\n", bfd_get_reloc_code_name (r_type)); | |
1604 | fflush(stderr); | |
1605 | #endif | |
1606 | rel->howto = bfd_reloc_type_lookup (stdoutput, r_type); | |
1607 | if (rel->howto == NULL) | |
1608 | { | |
1609 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1610 | _("Cannot represent relocation type %s"), | |
1611 | bfd_get_reloc_code_name (r_type)); | |
1612 | return NULL; | |
1613 | } | |
1614 | ||
1615 | return rel; | |
1616 | } | |
1617 | #endif |