Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-h8500.c -- Assemble code for the Hitachi H8/500 |
e7b305a2 | 2 | Copyright (C) 1993, 94, 95, 98, 2000 Free Software Foundation. |
252b5132 RH |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
20 | ||
4a4f25cf | 21 | /* Written By Steve Chamberlain <sac@cygnus.com>. */ |
252b5132 RH |
22 | |
23 | #include <stdio.h> | |
24 | #include "as.h" | |
25 | #include "bfd.h" | |
26 | #include "subsegs.h" | |
27 | #define DEFINE_TABLE | |
28 | #define ASSEMBLER_TABLE | |
29 | #include "opcodes/h8500-opc.h" | |
30 | #include <ctype.h> | |
31 | ||
32 | const char comment_chars[] = "!"; | |
33 | const char line_separator_chars[] = ";"; | |
34 | const char line_comment_chars[] = "!#"; | |
35 | ||
36 | /* This table describes all the machine specific pseudo-ops the assembler | |
37 | has to support. The fields are: | |
38 | pseudo-op name without dot | |
39 | function to call to execute this pseudo-op | |
40 | Integer arg to pass to the function | |
41 | */ | |
42 | ||
43 | void cons (); | |
44 | ||
45 | const pseudo_typeS md_pseudo_table[] = | |
46 | { | |
47 | {"int", cons, 2}, | |
48 | {"data.b", cons, 1}, | |
49 | {"data.w", cons, 2}, | |
50 | {"data.l", cons, 4}, | |
51 | {"form", listing_psize, 0}, | |
52 | {"heading", listing_title, 0}, | |
53 | {"import", s_ignore, 0}, | |
54 | {"page", listing_eject, 0}, | |
55 | {"program", s_ignore, 0}, | |
56 | {0, 0, 0} | |
57 | }; | |
58 | ||
59 | const int md_reloc_size; | |
60 | ||
61 | const char EXP_CHARS[] = "eE"; | |
62 | ||
63 | /* Chars that mean this number is a floating point constant */ | |
64 | /* As in 0f12.456 */ | |
65 | /* or 0d1.2345e12 */ | |
66 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
67 | ||
68 | #define C(a,b) ENCODE_RELAX(a,b) | |
69 | #define ENCODE_RELAX(what,length) (((what) << 2) + (length)) | |
70 | ||
71 | #define GET_WHAT(x) ((x>>2)) | |
72 | ||
73 | #define BYTE_DISP 1 | |
74 | #define WORD_DISP 2 | |
75 | #define UNDEF_BYTE_DISP 0 | |
76 | #define UNDEF_WORD_DISP 3 | |
77 | ||
78 | #define BRANCH 1 | |
79 | #define SCB_F 2 | |
80 | #define SCB_TST 3 | |
81 | #define END 4 | |
82 | ||
83 | #define BYTE_F 127 | |
84 | #define BYTE_B -126 | |
85 | #define WORD_F 32767 | |
86 | #define WORD_B 32768 | |
87 | ||
88 | relax_typeS md_relax_table[C (END, 0)]; | |
89 | ||
90 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics */ | |
91 | ||
92 | /* | |
93 | This function is called once, at assembler startup time. This should | |
e7b305a2 | 94 | set up all the tables, etc. that the MD part of the assembler needs |
252b5132 RH |
95 | */ |
96 | ||
97 | void | |
98 | md_begin () | |
99 | { | |
100 | h8500_opcode_info *opcode; | |
101 | char prev_buffer[100]; | |
102 | int idx = 0; | |
103 | register relax_typeS *table; | |
104 | ||
105 | opcode_hash_control = hash_new (); | |
106 | prev_buffer[0] = 0; | |
107 | ||
108 | /* Insert unique names into hash table */ | |
109 | for (opcode = h8500_table; opcode->name; opcode++) | |
110 | { | |
111 | if (idx != opcode->idx) | |
112 | { | |
113 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode); | |
114 | idx++; | |
115 | } | |
116 | } | |
117 | ||
118 | /* Initialize the relax table. We use a local variable to avoid | |
119 | warnings about modifying a supposedly const data structure. */ | |
120 | table = (relax_typeS *) md_relax_table; | |
121 | table[C (BRANCH, BYTE_DISP)].rlx_forward = BYTE_F; | |
122 | table[C (BRANCH, BYTE_DISP)].rlx_backward = BYTE_B; | |
123 | table[C (BRANCH, BYTE_DISP)].rlx_length = 2; | |
124 | table[C (BRANCH, BYTE_DISP)].rlx_more = C (BRANCH, WORD_DISP); | |
125 | ||
126 | table[C (BRANCH, WORD_DISP)].rlx_forward = WORD_F; | |
127 | table[C (BRANCH, WORD_DISP)].rlx_backward = WORD_B; | |
128 | table[C (BRANCH, WORD_DISP)].rlx_length = 3; | |
129 | table[C (BRANCH, WORD_DISP)].rlx_more = 0; | |
130 | ||
131 | table[C (SCB_F, BYTE_DISP)].rlx_forward = BYTE_F; | |
132 | table[C (SCB_F, BYTE_DISP)].rlx_backward = BYTE_B; | |
133 | table[C (SCB_F, BYTE_DISP)].rlx_length = 3; | |
134 | table[C (SCB_F, BYTE_DISP)].rlx_more = C (SCB_F, WORD_DISP); | |
135 | ||
136 | table[C (SCB_F, WORD_DISP)].rlx_forward = WORD_F; | |
137 | table[C (SCB_F, WORD_DISP)].rlx_backward = WORD_B; | |
138 | table[C (SCB_F, WORD_DISP)].rlx_length = 8; | |
139 | table[C (SCB_F, WORD_DISP)].rlx_more = 0; | |
140 | ||
141 | table[C (SCB_TST, BYTE_DISP)].rlx_forward = BYTE_F; | |
142 | table[C (SCB_TST, BYTE_DISP)].rlx_backward = BYTE_B; | |
143 | table[C (SCB_TST, BYTE_DISP)].rlx_length = 3; | |
144 | table[C (SCB_TST, BYTE_DISP)].rlx_more = C (SCB_TST, WORD_DISP); | |
145 | ||
146 | table[C (SCB_TST, WORD_DISP)].rlx_forward = WORD_F; | |
147 | table[C (SCB_TST, WORD_DISP)].rlx_backward = WORD_B; | |
148 | table[C (SCB_TST, WORD_DISP)].rlx_length = 10; | |
149 | table[C (SCB_TST, WORD_DISP)].rlx_more = 0; | |
150 | ||
151 | } | |
152 | ||
153 | static int rn; /* register number used by RN */ | |
154 | static int rs; /* register number used by RS */ | |
155 | static int rd; /* register number used by RD */ | |
156 | static int crb; /* byte size cr */ | |
157 | static int crw; /* word sized cr */ | |
158 | static int cr; /* unknown size cr */ | |
159 | ||
160 | static expressionS displacement;/* displacement expression */ | |
161 | static int displacement_size; /* and size if given */ | |
162 | ||
163 | static int immediate_inpage; | |
164 | static expressionS immediate; /* immediate expression */ | |
165 | static int immediate_size; /* and size if given */ | |
166 | ||
167 | static expressionS absolute; /* absolute expression */ | |
168 | static int absolute_size; /* and size if given */ | |
169 | ||
170 | typedef struct | |
171 | { | |
172 | int type; | |
173 | int reg; | |
174 | expressionS exp; | |
175 | int page; | |
176 | } | |
177 | ||
178 | h8500_operand_info; | |
179 | ||
bc0d738a NC |
180 | /* Try to parse a reg name. Return the number of chars consumed. */ |
181 | ||
252b5132 RH |
182 | static int |
183 | parse_reg (src, mode, reg) | |
184 | char *src; | |
185 | int *mode; | |
186 | int *reg; | |
187 | { | |
188 | char *end; | |
189 | int len; | |
190 | ||
191 | /* Cribbed from get_symbol_end(). */ | |
192 | if (!is_name_beginner (*src) || *src == '\001') | |
193 | return 0; | |
3dd5103b | 194 | end = src + 1; |
252b5132 RH |
195 | while (is_part_of_name (*end) || *end == '\001') |
196 | end++; | |
197 | len = end - src; | |
198 | ||
199 | if (len == 2 && src[0] == 'r') | |
200 | { | |
201 | if (src[1] >= '0' && src[1] <= '7') | |
202 | { | |
203 | *mode = RN; | |
204 | *reg = (src[1] - '0'); | |
205 | return len; | |
206 | } | |
207 | } | |
208 | if (len == 2 && src[0] == 's' && src[1] == 'p') | |
209 | { | |
210 | *mode = RN; | |
211 | *reg = 7; | |
212 | return len; | |
213 | } | |
214 | if (len == 3 && src[0] == 'c' && src[1] == 'c' && src[2] == 'r') | |
215 | { | |
216 | *mode = CRB; | |
217 | *reg = 1; | |
218 | return len; | |
219 | } | |
220 | if (len == 2 && src[0] == 's' && src[1] == 'r') | |
221 | { | |
222 | *mode = CRW; | |
223 | *reg = 0; | |
224 | return len; | |
225 | } | |
226 | if (len == 2 && src[0] == 'b' && src[1] == 'r') | |
227 | { | |
228 | *mode = CRB; | |
229 | *reg = 3; | |
230 | return len; | |
231 | } | |
232 | if (len == 2 && src[0] == 'e' && src[1] == 'p') | |
233 | { | |
234 | *mode = CRB; | |
235 | *reg = 4; | |
236 | return len; | |
237 | } | |
238 | if (len == 2 && src[0] == 'd' && src[1] == 'p') | |
239 | { | |
240 | *mode = CRB; | |
241 | *reg = 5; | |
242 | return len; | |
243 | } | |
244 | if (len == 2 && src[0] == 't' && src[1] == 'p') | |
245 | { | |
246 | *mode = CRB; | |
247 | *reg = 7; | |
248 | return len; | |
249 | } | |
250 | if (len == 2 && src[0] == 'f' && src[1] == 'p') | |
251 | { | |
252 | *mode = RN; | |
253 | *reg = 6; | |
254 | return len; | |
255 | } | |
256 | return 0; | |
257 | } | |
258 | ||
3dd5103b | 259 | static char * |
252b5132 RH |
260 | parse_exp (s, op, page) |
261 | char *s; | |
262 | expressionS *op; | |
263 | int *page; | |
264 | { | |
265 | char *save; | |
266 | char *new; | |
267 | ||
268 | save = input_line_pointer; | |
269 | ||
270 | *page = 0; | |
271 | if (s[0] == '%') | |
272 | { | |
273 | if (s[1] == 'p' && s[2] == 'a' && s[3] == 'g' && s[4] == 'e') | |
274 | { | |
275 | s += 5; | |
276 | *page = 'p'; | |
277 | } | |
278 | if (s[1] == 'h' && s[2] == 'i' && s[3] == '1' && s[4] == '6') | |
279 | { | |
280 | s += 5; | |
281 | *page = 'h'; | |
282 | } | |
283 | else if (s[1] == 'o' && s[2] == 'f' && s[3] == 'f') | |
284 | { | |
285 | s += 4; | |
286 | *page = 'o'; | |
287 | } | |
288 | } | |
289 | ||
290 | input_line_pointer = s; | |
291 | ||
292 | expression (op); | |
293 | if (op->X_op == O_absent) | |
294 | as_bad (_("missing operand")); | |
295 | new = input_line_pointer; | |
296 | input_line_pointer = save; | |
297 | return new; | |
298 | } | |
299 | ||
300 | typedef enum | |
301 | { | |
302 | exp_signed, exp_unsigned, exp_sandu | |
303 | } sign_type; | |
304 | ||
252b5132 RH |
305 | static char * |
306 | skip_colonthing (sign, ptr, exp, def, size8, size16, size24) | |
307 | sign_type sign; | |
308 | char *ptr; | |
309 | h8500_operand_info *exp; | |
310 | int def; | |
311 | int size8; | |
312 | int size16; | |
313 | int size24; | |
314 | { | |
315 | ptr = parse_exp (ptr, &exp->exp, &exp->page); | |
316 | if (*ptr == ':') | |
317 | { | |
318 | ptr++; | |
319 | if (*ptr == '8') | |
320 | { | |
321 | ptr++; | |
322 | exp->type = size8; | |
323 | } | |
324 | else if (ptr[0] == '1' & ptr[1] == '6') | |
325 | { | |
326 | ptr += 2; | |
327 | exp->type = size16; | |
328 | } | |
329 | else if (ptr[0] == '2' & ptr[1] == '4') | |
330 | { | |
331 | if (!size24) | |
332 | { | |
333 | as_bad (_(":24 not valid for this opcode")); | |
334 | } | |
335 | ptr += 2; | |
336 | exp->type = size24; | |
337 | } | |
338 | else | |
339 | { | |
340 | as_bad (_("expect :8,:16 or :24")); | |
341 | exp->type = size16; | |
342 | } | |
343 | } | |
344 | else | |
345 | { | |
346 | if (exp->page == 'p') | |
347 | { | |
348 | exp->type = IMM8; | |
349 | } | |
350 | else if (exp->page == 'h') | |
351 | { | |
352 | exp->type = IMM16; | |
353 | } | |
354 | else | |
355 | { | |
356 | /* Let's work out the size from the context */ | |
357 | int n = exp->exp.X_add_number; | |
358 | if (size8 | |
359 | && exp->exp.X_op == O_constant | |
360 | && ((sign == exp_signed && (n >= -128 && n <= 127)) | |
361 | || (sign == exp_unsigned && (n >= 0 && (n <= 255))) | |
362 | || (sign == exp_sandu && (n >= -128 && (n <= 255))))) | |
363 | { | |
364 | exp->type = size8; | |
365 | } | |
366 | else | |
367 | { | |
368 | exp->type = def; | |
369 | } | |
370 | } | |
371 | } | |
372 | return ptr; | |
373 | } | |
374 | ||
375 | static int | |
376 | parse_reglist (src, op) | |
377 | char *src; | |
378 | h8500_operand_info *op; | |
379 | { | |
380 | int mode; | |
381 | int rn; | |
382 | int mask = 0; | |
383 | int rm; | |
384 | int idx = 1; /* skip ( */ | |
385 | ||
386 | while (src[idx] && src[idx] != ')') | |
387 | { | |
388 | int done = parse_reg (src + idx, &mode, &rn); | |
389 | ||
390 | if (done) | |
391 | { | |
392 | idx += done; | |
393 | mask |= 1 << rn; | |
394 | } | |
395 | else | |
396 | { | |
397 | as_bad (_("syntax error in reg list")); | |
398 | return 0; | |
399 | } | |
400 | if (src[idx] == '-') | |
401 | { | |
402 | idx++; | |
403 | done = parse_reg (src + idx, &mode, &rm); | |
404 | if (done) | |
405 | { | |
406 | idx += done; | |
407 | while (rn <= rm) | |
408 | { | |
409 | mask |= 1 << rn; | |
410 | rn++; | |
411 | } | |
412 | } | |
413 | else | |
414 | { | |
415 | as_bad (_("missing final register in range")); | |
416 | } | |
417 | } | |
418 | if (src[idx] == ',') | |
419 | idx++; | |
420 | } | |
421 | idx++; | |
422 | op->exp.X_add_symbol = 0; | |
423 | op->exp.X_op_symbol = 0; | |
424 | op->exp.X_add_number = mask; | |
425 | op->exp.X_op = O_constant; | |
426 | op->exp.X_unsigned = 1; | |
427 | op->type = IMM8; | |
428 | return idx; | |
429 | ||
430 | } | |
431 | ||
432 | /* The many forms of operand: | |
433 | ||
434 | Rn Register direct | |
435 | @Rn Register indirect | |
436 | @(disp[:size], Rn) Register indirect with displacement | |
437 | @Rn+ | |
438 | @-Rn | |
439 | @aa[:size] absolute | |
440 | #xx[:size] immediate data | |
441 | ||
442 | */ | |
443 | ||
444 | static void | |
445 | get_operand (ptr, op, ispage) | |
446 | char **ptr; | |
447 | h8500_operand_info *op; | |
448 | char ispage; | |
449 | { | |
450 | char *src = *ptr; | |
451 | int mode; | |
452 | unsigned int num; | |
453 | unsigned int len; | |
454 | op->page = 0; | |
455 | if (src[0] == '(' && src[1] == 'r') | |
456 | { | |
457 | /* This is a register list */ | |
458 | *ptr = src + parse_reglist (src, op); | |
459 | return; | |
460 | } | |
461 | ||
462 | len = parse_reg (src, &op->type, &op->reg); | |
463 | ||
464 | if (len) | |
465 | { | |
466 | *ptr = src + len; | |
467 | return; | |
468 | } | |
469 | ||
470 | if (*src == '@') | |
471 | { | |
472 | src++; | |
473 | if (*src == '-') | |
474 | { | |
475 | src++; | |
476 | len = parse_reg (src, &mode, &num); | |
477 | if (len == 0) | |
478 | { | |
479 | /* Oops, not a reg after all, must be ordinary exp */ | |
480 | src--; | |
481 | /* must be a symbol */ | |
482 | *ptr = skip_colonthing (exp_unsigned, src, | |
483 | op, ABS16, ABS8, ABS16, ABS24); | |
484 | return; | |
485 | } | |
486 | ||
487 | op->type = RNDEC; | |
488 | op->reg = num; | |
489 | *ptr = src + len; | |
490 | return; | |
491 | } | |
492 | if (*src == '(') | |
493 | { | |
494 | /* Disp */ | |
495 | src++; | |
496 | ||
3dd5103b | 497 | src = skip_colonthing (exp_signed, src, |
252b5132 RH |
498 | op, RNIND_D16, RNIND_D8, RNIND_D16, 0); |
499 | ||
500 | if (*src != ',') | |
501 | { | |
502 | as_bad (_("expected @(exp, Rn)")); | |
503 | return; | |
504 | } | |
505 | src++; | |
506 | len = parse_reg (src, &mode, &op->reg); | |
507 | if (len == 0 || mode != RN) | |
508 | { | |
509 | as_bad (_("expected @(exp, Rn)")); | |
510 | return; | |
511 | } | |
512 | src += len; | |
513 | if (*src != ')') | |
514 | { | |
515 | as_bad (_("expected @(exp, Rn)")); | |
516 | return; | |
517 | } | |
518 | *ptr = src + 1; | |
519 | return; | |
520 | } | |
521 | len = parse_reg (src, &mode, &num); | |
522 | ||
523 | if (len) | |
524 | { | |
525 | src += len; | |
526 | if (*src == '+') | |
527 | { | |
528 | src++; | |
529 | if (mode != RN) | |
530 | { | |
531 | as_bad (_("@Rn+ needs word register")); | |
532 | return; | |
533 | } | |
534 | op->type = RNINC; | |
535 | op->reg = num; | |
536 | *ptr = src; | |
537 | return; | |
538 | } | |
539 | if (mode != RN) | |
540 | { | |
541 | as_bad (_("@Rn needs word register")); | |
542 | return; | |
543 | } | |
544 | op->type = RNIND; | |
545 | op->reg = num; | |
546 | *ptr = src; | |
547 | return; | |
548 | } | |
549 | else | |
550 | { | |
551 | /* must be a symbol */ | |
552 | *ptr = | |
553 | skip_colonthing (exp_unsigned, src, op, | |
554 | ispage ? ABS24 : ABS16, ABS8, ABS16, ABS24); | |
555 | return; | |
556 | } | |
557 | } | |
558 | ||
559 | if (*src == '#') | |
560 | { | |
561 | src++; | |
562 | *ptr = skip_colonthing (exp_sandu, src, op, IMM16, IMM8, IMM16, ABS24); | |
563 | return; | |
564 | } | |
565 | else | |
566 | { | |
567 | *ptr = skip_colonthing (exp_signed, src, op, | |
568 | ispage ? ABS24 : PCREL8, PCREL8, PCREL16, ABS24); | |
569 | } | |
570 | } | |
571 | ||
3dd5103b | 572 | static char * |
252b5132 RH |
573 | get_operands (info, args, operand) |
574 | h8500_opcode_info *info; | |
575 | char *args; | |
576 | h8500_operand_info *operand; | |
577 | ||
578 | { | |
579 | char *ptr = args; | |
580 | ||
581 | switch (info->nargs) | |
582 | { | |
583 | case 0: | |
584 | operand[0].type = 0; | |
585 | operand[1].type = 0; | |
586 | break; | |
587 | ||
588 | case 1: | |
589 | ptr++; | |
590 | get_operand (&ptr, operand + 0, info->name[0] == 'p'); | |
591 | operand[1].type = 0; | |
592 | break; | |
593 | ||
594 | case 2: | |
595 | ptr++; | |
596 | get_operand (&ptr, operand + 0, 0); | |
597 | if (*ptr == ',') | |
598 | ptr++; | |
599 | get_operand (&ptr, operand + 1, 0); | |
600 | break; | |
601 | ||
602 | default: | |
603 | abort (); | |
604 | } | |
605 | ||
606 | return ptr; | |
607 | } | |
608 | ||
609 | /* Passed a pointer to a list of opcodes which use different | |
610 | addressing modes, return the opcode which matches the opcodes | |
3dd5103b | 611 | provided. */ |
252b5132 RH |
612 | |
613 | int pcrel8; /* Set when we've seen a pcrel operand */ | |
614 | ||
3dd5103b | 615 | static h8500_opcode_info * |
252b5132 RH |
616 | get_specific (opcode, operands) |
617 | h8500_opcode_info *opcode; | |
618 | h8500_operand_info *operands; | |
619 | { | |
620 | h8500_opcode_info *this_try = opcode; | |
621 | int found = 0; | |
622 | unsigned int noperands = opcode->nargs; | |
623 | ||
624 | unsigned int this_index = opcode->idx; | |
625 | ||
626 | while (this_index == opcode->idx && !found) | |
627 | { | |
628 | unsigned int i; | |
629 | ||
630 | this_try = opcode++; | |
631 | ||
632 | /* look at both operands needed by the opcodes and provided by | |
633 | the user*/ | |
634 | for (i = 0; i < noperands; i++) | |
635 | { | |
636 | h8500_operand_info *user = operands + i; | |
637 | ||
638 | switch (this_try->arg_type[i]) | |
639 | { | |
640 | case FPIND_D8: | |
641 | /* Opcode needs (disp:8,fp) */ | |
642 | if (user->type == RNIND_D8 && user->reg == 6) | |
643 | { | |
644 | displacement = user->exp; | |
645 | continue; | |
646 | } | |
647 | break; | |
648 | case RDIND_D16: | |
649 | if (user->type == RNIND_D16) | |
650 | { | |
651 | displacement = user->exp; | |
652 | rd = user->reg; | |
653 | continue; | |
654 | } | |
655 | break; | |
656 | case RDIND_D8: | |
657 | if (user->type == RNIND_D8) | |
658 | { | |
659 | displacement = user->exp; | |
660 | rd = user->reg; | |
661 | continue; | |
662 | } | |
663 | break; | |
664 | case RNIND_D16: | |
665 | case RNIND_D8: | |
666 | if (user->type == this_try->arg_type[i]) | |
667 | { | |
668 | displacement = user->exp; | |
669 | rn = user->reg; | |
670 | continue; | |
671 | } | |
672 | break; | |
673 | ||
674 | case SPDEC: | |
675 | if (user->type == RNDEC && user->reg == 7) | |
676 | { | |
677 | continue; | |
678 | } | |
679 | break; | |
680 | case SPINC: | |
681 | if (user->type == RNINC && user->reg == 7) | |
682 | { | |
683 | continue; | |
684 | } | |
685 | break; | |
686 | case ABS16: | |
687 | if (user->type == ABS16) | |
688 | { | |
689 | absolute = user->exp; | |
690 | continue; | |
691 | } | |
692 | break; | |
693 | case ABS8: | |
694 | if (user->type == ABS8) | |
695 | { | |
696 | absolute = user->exp; | |
697 | continue; | |
698 | } | |
699 | break; | |
700 | case ABS24: | |
701 | if (user->type == ABS24) | |
702 | { | |
703 | absolute = user->exp; | |
704 | continue; | |
705 | } | |
706 | break; | |
707 | ||
708 | case CRB: | |
709 | if ((user->type == CRB || user->type == CR) && user->reg != 0) | |
710 | { | |
711 | crb = user->reg; | |
712 | continue; | |
713 | } | |
714 | break; | |
715 | case CRW: | |
716 | if ((user->type == CRW || user->type == CR) && user->reg == 0) | |
717 | { | |
718 | crw = user->reg; | |
719 | continue; | |
720 | } | |
721 | break; | |
722 | case DISP16: | |
723 | if (user->type == DISP16) | |
724 | { | |
725 | displacement = user->exp; | |
726 | continue; | |
727 | } | |
728 | break; | |
729 | case DISP8: | |
730 | if (user->type == DISP8) | |
731 | { | |
732 | displacement = user->exp; | |
733 | continue; | |
734 | } | |
735 | break; | |
736 | case FP: | |
737 | if (user->type == RN && user->reg == 6) | |
738 | { | |
739 | continue; | |
740 | } | |
741 | break; | |
742 | case PCREL16: | |
743 | if (user->type == PCREL16) | |
744 | { | |
745 | displacement = user->exp; | |
746 | continue; | |
747 | } | |
748 | break; | |
749 | case PCREL8: | |
750 | if (user->type == PCREL8) | |
751 | { | |
752 | displacement = user->exp; | |
753 | pcrel8 = 1; | |
754 | continue; | |
755 | } | |
756 | break; | |
757 | ||
758 | case IMM16: | |
759 | if (user->type == IMM16 | |
760 | || user->type == IMM8) | |
761 | { | |
762 | immediate_inpage = user->page; | |
763 | immediate = user->exp; | |
764 | continue; | |
765 | } | |
766 | break; | |
767 | case RLIST: | |
768 | case IMM8: | |
769 | if (user->type == IMM8) | |
770 | { | |
771 | immediate_inpage = user->page; | |
772 | immediate = user->exp; | |
773 | continue; | |
774 | } | |
775 | break; | |
776 | case IMM4: | |
777 | if (user->type == IMM8) | |
778 | { | |
779 | immediate_inpage = user->page; | |
780 | immediate = user->exp; | |
781 | continue; | |
782 | } | |
783 | break; | |
784 | case QIM: | |
785 | if (user->type == IMM8 | |
786 | && user->exp.X_op == O_constant | |
787 | && | |
788 | (user->exp.X_add_number == -2 | |
789 | || user->exp.X_add_number == -1 | |
790 | || user->exp.X_add_number == 1 | |
791 | || user->exp.X_add_number == 2)) | |
792 | { | |
793 | immediate_inpage = user->page; | |
794 | immediate = user->exp; | |
795 | continue; | |
796 | } | |
797 | break; | |
798 | case RD: | |
799 | if (user->type == RN) | |
800 | { | |
801 | rd = user->reg; | |
802 | continue; | |
803 | } | |
804 | break; | |
805 | case RS: | |
806 | if (user->type == RN) | |
807 | { | |
808 | rs = user->reg; | |
809 | continue; | |
810 | } | |
811 | break; | |
812 | case RDIND: | |
813 | if (user->type == RNIND) | |
814 | { | |
815 | rd = user->reg; | |
816 | continue; | |
817 | ||
818 | } | |
819 | break; | |
820 | case RNINC: | |
821 | case RNIND: | |
822 | case RNDEC: | |
823 | case RN: | |
824 | ||
825 | if (user->type == this_try->arg_type[i]) | |
826 | { | |
827 | rn = user->reg; | |
828 | continue; | |
829 | } | |
830 | break; | |
831 | case SP: | |
832 | if (user->type == RN && user->reg == 7) | |
833 | { | |
834 | continue; | |
835 | } | |
836 | break; | |
837 | default: | |
838 | printf (_("unhandled %d\n"), this_try->arg_type[i]); | |
839 | break; | |
840 | } | |
841 | ||
842 | /* If we get here this didn't work out */ | |
843 | goto fail; | |
844 | } | |
845 | found = 1; | |
846 | fail:; | |
847 | ||
848 | } | |
849 | ||
850 | if (found) | |
851 | return this_try; | |
852 | else | |
853 | return 0; | |
854 | } | |
855 | ||
856 | int | |
857 | check (operand, low, high) | |
858 | expressionS *operand; | |
859 | int low; | |
860 | int high; | |
861 | { | |
862 | if (operand->X_op != O_constant | |
863 | || operand->X_add_number < low | |
864 | || operand->X_add_number > high) | |
865 | { | |
866 | as_bad (_("operand must be absolute in range %d..%d"), low, high); | |
867 | } | |
868 | return operand->X_add_number; | |
869 | } | |
870 | ||
3dd5103b | 871 | static void |
252b5132 RH |
872 | insert (output, index, exp, reloc, pcrel) |
873 | char *output; | |
874 | int index; | |
875 | expressionS *exp; | |
876 | int reloc; | |
877 | int pcrel; | |
878 | { | |
879 | fix_new_exp (frag_now, | |
880 | output - frag_now->fr_literal + index, | |
881 | 4, /* always say size is 4, but we know better */ | |
882 | exp, | |
883 | pcrel, | |
884 | reloc); | |
885 | } | |
886 | ||
887 | void | |
888 | build_relaxable_instruction (opcode, operand) | |
889 | h8500_opcode_info *opcode; | |
890 | h8500_operand_info *operand; | |
891 | { | |
892 | /* All relaxable instructions start life as two bytes but can become | |
3dd5103b NC |
893 | three bytes long if a lonely branch and up to 9 bytes if long |
894 | scb. */ | |
252b5132 RH |
895 | char *p; |
896 | int len; | |
897 | int type; | |
898 | ||
899 | if (opcode->bytes[0].contents == 0x01) | |
900 | { | |
901 | type = SCB_F; | |
902 | } | |
903 | else if (opcode->bytes[0].contents == 0x06 | |
904 | || opcode->bytes[0].contents == 0x07) | |
905 | { | |
906 | type = SCB_TST; | |
907 | } | |
908 | else | |
909 | { | |
910 | type = BRANCH; | |
911 | } | |
912 | ||
913 | p = frag_var (rs_machine_dependent, | |
914 | md_relax_table[C (type, WORD_DISP)].rlx_length, | |
915 | len = md_relax_table[C (type, BYTE_DISP)].rlx_length, | |
916 | C (type, UNDEF_BYTE_DISP), | |
917 | displacement.X_add_symbol, | |
918 | displacement.X_add_number, | |
919 | 0); | |
920 | ||
921 | p[0] = opcode->bytes[0].contents; | |
922 | if (type != BRANCH) | |
923 | { | |
924 | p[1] = opcode->bytes[1].contents | rs; | |
925 | } | |
926 | } | |
927 | ||
3dd5103b NC |
928 | /* Now we know what sort of opcodes it is, let's build the bytes. */ |
929 | ||
252b5132 RH |
930 | static void |
931 | build_bytes (opcode, operand) | |
932 | h8500_opcode_info *opcode; | |
933 | h8500_operand_info *operand; | |
934 | ||
935 | { | |
936 | int index; | |
937 | ||
938 | if (pcrel8) | |
939 | { | |
940 | pcrel8 = 0; | |
941 | build_relaxable_instruction (opcode, operand); | |
942 | } | |
943 | else | |
944 | { | |
945 | char *output = frag_more (opcode->length); | |
946 | ||
947 | memset (output, 0, opcode->length); | |
948 | for (index = 0; index < opcode->length; index++) | |
949 | { | |
950 | output[index] = opcode->bytes[index].contents; | |
951 | ||
952 | switch (opcode->bytes[index].insert) | |
953 | { | |
954 | default: | |
955 | printf (_("failed for %d\n"), opcode->bytes[index].insert); | |
956 | break; | |
957 | case 0: | |
958 | break; | |
959 | case RN: | |
960 | output[index] |= rn; | |
961 | break; | |
962 | case RD: | |
963 | case RDIND: | |
252b5132 RH |
964 | output[index] |= rd; |
965 | break; | |
966 | case RS: | |
967 | output[index] |= rs; | |
968 | break; | |
969 | case DISP16: | |
970 | insert (output, index, &displacement, R_H8500_IMM16, 0); | |
971 | index++; | |
972 | break; | |
973 | case DISP8: | |
974 | case FPIND_D8: | |
975 | insert (output, index, &displacement, R_H8500_IMM8, 0); | |
976 | break; | |
252b5132 RH |
977 | case IMM16: |
978 | { | |
979 | int p; | |
3dd5103b NC |
980 | |
981 | switch (immediate_inpage) | |
982 | { | |
983 | case 'p': | |
984 | p = R_H8500_HIGH16; | |
985 | break; | |
986 | case 'h': | |
987 | p = R_H8500_HIGH16; | |
988 | break; | |
989 | default: | |
990 | p = R_H8500_IMM16; | |
991 | break; | |
992 | } | |
993 | insert (output, index, &immediate, p, 0); | |
252b5132 | 994 | } |
252b5132 RH |
995 | index++; |
996 | break; | |
997 | case RLIST: | |
998 | case IMM8: | |
999 | if (immediate_inpage) | |
3dd5103b | 1000 | insert (output, index, &immediate, R_H8500_HIGH8, 0); |
252b5132 | 1001 | else |
3dd5103b | 1002 | insert (output, index, &immediate, R_H8500_IMM8, 0); |
252b5132 RH |
1003 | break; |
1004 | case PCREL16: | |
1005 | insert (output, index, &displacement, R_H8500_PCREL16, 1); | |
1006 | index++; | |
1007 | break; | |
1008 | case PCREL8: | |
1009 | insert (output, index, &displacement, R_H8500_PCREL8, 1); | |
1010 | break; | |
1011 | case IMM4: | |
1012 | output[index] |= check (&immediate, 0, 15); | |
1013 | break; | |
1014 | case CR: | |
252b5132 RH |
1015 | output[index] |= cr; |
1016 | if (cr == 0) | |
3dd5103b | 1017 | output[0] |= 0x8; |
252b5132 | 1018 | else |
3dd5103b | 1019 | output[0] &= ~0x8; |
252b5132 | 1020 | break; |
252b5132 RH |
1021 | case CRB: |
1022 | output[index] |= crb; | |
1023 | output[0] &= ~0x8; | |
1024 | break; | |
1025 | case CRW: | |
1026 | output[index] |= crw; | |
1027 | output[0] |= 0x8; | |
1028 | break; | |
1029 | case ABS24: | |
1030 | insert (output, index, &absolute, R_H8500_IMM24, 0); | |
1031 | index += 2; | |
1032 | break; | |
1033 | case ABS16: | |
1034 | insert (output, index, &absolute, R_H8500_IMM16, 0); | |
1035 | index++; | |
1036 | break; | |
1037 | case ABS8: | |
1038 | insert (output, index, &absolute, R_H8500_IMM8, 0); | |
1039 | break; | |
1040 | case QIM: | |
1041 | switch (immediate.X_add_number) | |
1042 | { | |
1043 | case -2: | |
1044 | output[index] |= 0x5; | |
1045 | break; | |
1046 | case -1: | |
1047 | output[index] |= 0x4; | |
1048 | break; | |
1049 | case 1: | |
1050 | output[index] |= 0; | |
1051 | break; | |
1052 | case 2: | |
1053 | output[index] |= 1; | |
1054 | break; | |
1055 | } | |
1056 | break; | |
1057 | } | |
1058 | } | |
1059 | } | |
1060 | } | |
1061 | ||
3dd5103b NC |
1062 | /* This is the guts of the machine-dependent assembler. STR points to |
1063 | a machine dependent instruction. This function is supposed to emit | |
1064 | the frags/bytes it assembles to. */ | |
252b5132 RH |
1065 | |
1066 | void | |
c0fecd35 AM |
1067 | md_assemble (str) |
1068 | char *str; | |
252b5132 RH |
1069 | { |
1070 | char *op_start; | |
1071 | char *op_end; | |
1072 | h8500_operand_info operand[2]; | |
1073 | h8500_opcode_info *opcode; | |
1074 | h8500_opcode_info *prev_opcode; | |
1075 | char name[11]; | |
1076 | ||
1077 | int nlen = 0; | |
1078 | ||
3dd5103b | 1079 | /* Drop leading whitespace. */ |
252b5132 RH |
1080 | while (*str == ' ') |
1081 | str++; | |
1082 | ||
3dd5103b | 1083 | /* Find the op code end. */ |
252b5132 | 1084 | for (op_start = op_end = str; |
b75c0c92 | 1085 | !is_end_of_line[(unsigned char) *op_end] && *op_end != ' '; |
252b5132 RH |
1086 | op_end++) |
1087 | { | |
1088 | if ( /**op_end != '.' | |
1089 | && *op_end != ':' | |
1090 | && */ nlen < 10) | |
1091 | { | |
1092 | name[nlen++] = *op_end; | |
1093 | } | |
1094 | } | |
1095 | name[nlen] = 0; | |
1096 | ||
1097 | if (op_end == op_start) | |
3dd5103b | 1098 | as_bad (_("can't find opcode ")); |
252b5132 RH |
1099 | |
1100 | opcode = (h8500_opcode_info *) hash_find (opcode_hash_control, name); | |
1101 | ||
1102 | if (opcode == NULL) | |
1103 | { | |
1104 | as_bad (_("unknown opcode")); | |
1105 | return; | |
1106 | } | |
1107 | ||
1108 | get_operands (opcode, op_end, operand); | |
1109 | prev_opcode = opcode; | |
1110 | ||
1111 | opcode = get_specific (opcode, operand); | |
1112 | ||
1113 | if (opcode == 0) | |
1114 | { | |
1115 | /* Couldn't find an opcode which matched the operands */ | |
1116 | char *where = frag_more (2); | |
1117 | ||
1118 | where[0] = 0x0; | |
1119 | where[1] = 0x0; | |
1120 | as_bad (_("invalid operands for opcode")); | |
1121 | return; | |
1122 | } | |
1123 | ||
1124 | build_bytes (opcode, operand); | |
252b5132 RH |
1125 | } |
1126 | ||
1127 | void | |
c0fecd35 AM |
1128 | tc_crawl_symbol_chain (headers) |
1129 | object_headers *headers; | |
252b5132 RH |
1130 | { |
1131 | printf (_("call to tc_crawl_symbol_chain \n")); | |
1132 | } | |
1133 | ||
1134 | symbolS * | |
c0fecd35 AM |
1135 | md_undefined_symbol (name) |
1136 | char *name; | |
252b5132 RH |
1137 | { |
1138 | return 0; | |
1139 | } | |
1140 | ||
1141 | void | |
c0fecd35 AM |
1142 | tc_headers_hook (headers) |
1143 | object_headers *headers; | |
252b5132 RH |
1144 | { |
1145 | printf (_("call to tc_headers_hook \n")); | |
1146 | } | |
1147 | ||
3dd5103b NC |
1148 | /* Various routines to kill one day. */ |
1149 | /* Equal to MAX_PRECISION in atof-ieee.c. */ | |
252b5132 RH |
1150 | #define MAX_LITTLENUMS 6 |
1151 | ||
bc0d738a NC |
1152 | /* Turn a string in input_line_pointer into a floating point constant |
1153 | of type type, and store the appropriate bytes in *LITP. The number | |
1154 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1155 | returned, or NULL on OK. */ | |
1156 | ||
252b5132 RH |
1157 | char * |
1158 | md_atof (type, litP, sizeP) | |
1159 | char type; | |
1160 | char *litP; | |
1161 | int *sizeP; | |
1162 | { | |
1163 | int prec; | |
1164 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1165 | LITTLENUM_TYPE *wordP; | |
1166 | char *t; | |
1167 | char *atof_ieee (); | |
1168 | ||
1169 | switch (type) | |
1170 | { | |
1171 | case 'f': | |
1172 | case 'F': | |
1173 | case 's': | |
1174 | case 'S': | |
1175 | prec = 2; | |
1176 | break; | |
1177 | ||
1178 | case 'd': | |
1179 | case 'D': | |
1180 | case 'r': | |
1181 | case 'R': | |
1182 | prec = 4; | |
1183 | break; | |
1184 | ||
1185 | case 'x': | |
1186 | case 'X': | |
1187 | prec = 6; | |
1188 | break; | |
1189 | ||
1190 | case 'p': | |
1191 | case 'P': | |
1192 | prec = 6; | |
1193 | break; | |
1194 | ||
1195 | default: | |
1196 | *sizeP = 0; | |
1197 | return _("Bad call to MD_ATOF()"); | |
1198 | } | |
1199 | t = atof_ieee (input_line_pointer, type, words); | |
1200 | if (t) | |
1201 | input_line_pointer = t; | |
1202 | ||
1203 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
1204 | for (wordP = words; prec--;) | |
1205 | { | |
1206 | md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
1207 | litP += sizeof (LITTLENUM_TYPE); | |
1208 | } | |
1209 | return 0; | |
1210 | } | |
1211 | \f | |
1212 | CONST char *md_shortopts = ""; | |
1213 | struct option md_longopts[] = { | |
1214 | {NULL, no_argument, NULL, 0} | |
1215 | }; | |
3dd5103b | 1216 | size_t md_longopts_size = sizeof (md_longopts); |
252b5132 RH |
1217 | |
1218 | int | |
1219 | md_parse_option (c, arg) | |
1220 | int c; | |
1221 | char *arg; | |
1222 | { | |
1223 | return 0; | |
1224 | } | |
1225 | ||
1226 | void | |
1227 | md_show_usage (stream) | |
1228 | FILE *stream; | |
1229 | { | |
1230 | } | |
1231 | \f | |
1232 | void | |
1233 | tc_aout_fix_to_chars () | |
1234 | { | |
1235 | printf (_("call to tc_aout_fix_to_chars \n")); | |
1236 | abort (); | |
1237 | } | |
1238 | ||
3dd5103b | 1239 | static void |
252b5132 RH |
1240 | wordify_scb (buffer, disp_size, inst_size) |
1241 | char *buffer; | |
1242 | int *disp_size; | |
1243 | int *inst_size; | |
1244 | { | |
1245 | int rn = buffer[1] & 0x7; | |
1246 | ||
1247 | switch (buffer[0]) | |
1248 | { | |
1249 | case 0x0e: /* BSR */ | |
1250 | case 0x20: | |
1251 | case 0x21: | |
1252 | case 0x22: | |
1253 | case 0x23: | |
1254 | case 0x24: | |
1255 | case 0x25: | |
1256 | case 0x26: | |
1257 | case 0x27: | |
1258 | case 0x28: | |
1259 | case 0x29: | |
1260 | case 0x2a: | |
1261 | case 0x2b: | |
1262 | case 0x2c: | |
1263 | case 0x2d: | |
1264 | case 0x2e: | |
1265 | case 0x2f: | |
1266 | buffer[0] |= 0x10; | |
1267 | buffer[1] = 0; | |
1268 | buffer[2] = 0; | |
1269 | *disp_size = 2; | |
1270 | *inst_size = 1; | |
1271 | return; | |
1272 | default: | |
1273 | abort (); | |
1274 | ||
1275 | case 0x01: | |
1276 | *inst_size = 6; | |
1277 | *disp_size = 2; | |
1278 | break; | |
1279 | case 0x06: | |
1280 | *inst_size = 8; | |
1281 | *disp_size = 2; | |
1282 | ||
1283 | *buffer++ = 0x26; /* bne + 8 */ | |
1284 | *buffer++ = 0x08; | |
1285 | break; | |
1286 | case 0x07: | |
1287 | *inst_size = 8; | |
1288 | *disp_size = 2; | |
1289 | *buffer++ = 0x27; /* bne + 8 */ | |
1290 | *buffer++ = 0x08; | |
1291 | break; | |
1292 | ||
1293 | } | |
1294 | *buffer++ = 0xa8 | rn; /* addq -1,rn */ | |
1295 | *buffer++ = 0x0c; | |
1296 | *buffer++ = 0x04; /* cmp #0xff:8, rn */ | |
1297 | *buffer++ = 0xff; | |
1298 | *buffer++ = 0x70 | rn; | |
4a4f25cf | 1299 | *buffer++ = 0x36; /* bne ... */ |
252b5132 RH |
1300 | *buffer++ = 0; |
1301 | *buffer++ = 0; | |
1302 | } | |
1303 | ||
3dd5103b NC |
1304 | /* Called after relaxing, change the frags so they know how big they |
1305 | are. */ | |
1306 | ||
252b5132 RH |
1307 | void |
1308 | md_convert_frag (headers, seg, fragP) | |
1309 | object_headers *headers; | |
1310 | segT seg; | |
1311 | fragS *fragP; | |
1312 | { | |
1313 | int disp_size = 0; | |
1314 | int inst_size = 0; | |
1315 | char *buffer = fragP->fr_fix + fragP->fr_literal; | |
1316 | ||
1317 | switch (fragP->fr_subtype) | |
1318 | { | |
1319 | case C (BRANCH, BYTE_DISP): | |
1320 | disp_size = 1; | |
1321 | inst_size = 1; | |
1322 | break; | |
1323 | ||
1324 | case C (SCB_F, BYTE_DISP): | |
1325 | case C (SCB_TST, BYTE_DISP): | |
1326 | disp_size = 1; | |
1327 | inst_size = 2; | |
1328 | break; | |
1329 | ||
3dd5103b | 1330 | /* Branches to a known 16 bit displacement. */ |
252b5132 | 1331 | |
3dd5103b | 1332 | /* Turn on the 16bit bit. */ |
252b5132 RH |
1333 | case C (BRANCH, WORD_DISP): |
1334 | case C (SCB_F, WORD_DISP): | |
1335 | case C (SCB_TST, WORD_DISP): | |
1336 | wordify_scb (buffer, &disp_size, &inst_size); | |
1337 | break; | |
1338 | ||
1339 | case C (BRANCH, UNDEF_WORD_DISP): | |
1340 | case C (SCB_F, UNDEF_WORD_DISP): | |
1341 | case C (SCB_TST, UNDEF_WORD_DISP): | |
3dd5103b NC |
1342 | /* This tried to be relaxed, but didn't manage it, it now needs |
1343 | a fix. */ | |
252b5132 RH |
1344 | wordify_scb (buffer, &disp_size, &inst_size); |
1345 | ||
1346 | /* Make a reloc */ | |
1347 | fix_new (fragP, | |
1348 | fragP->fr_fix + inst_size, | |
1349 | 4, | |
1350 | fragP->fr_symbol, | |
1351 | fragP->fr_offset, | |
1352 | 0, | |
1353 | R_H8500_PCREL16); | |
1354 | ||
1355 | fragP->fr_fix += disp_size + inst_size; | |
1356 | fragP->fr_var = 0; | |
1357 | return; | |
1358 | break; | |
1359 | default: | |
1360 | abort (); | |
1361 | } | |
1362 | if (inst_size) | |
1363 | { | |
1364 | /* Get the address of the end of the instruction */ | |
1365 | int next_inst = fragP->fr_fix + fragP->fr_address + disp_size + inst_size; | |
1366 | int targ_addr = (S_GET_VALUE (fragP->fr_symbol) + | |
1367 | fragP->fr_offset); | |
1368 | int disp = targ_addr - next_inst; | |
1369 | ||
1370 | md_number_to_chars (buffer + inst_size, disp, disp_size); | |
1371 | fragP->fr_fix += disp_size + inst_size; | |
1372 | fragP->fr_var = 0; | |
1373 | } | |
1374 | } | |
1375 | ||
1376 | valueT | |
1377 | md_section_align (seg, size) | |
1378 | segT seg ; | |
1379 | valueT size; | |
1380 | { | |
3dd5103b | 1381 | return ((size + (1 << section_alignment[(int) seg]) - 1) |
252b5132 RH |
1382 | & (-1 << section_alignment[(int) seg])); |
1383 | ||
1384 | } | |
1385 | ||
1386 | void | |
1387 | md_apply_fix (fixP, val) | |
1388 | fixS *fixP; | |
1389 | long val; | |
1390 | { | |
1391 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
1392 | ||
1393 | if (fixP->fx_r_type == 0) | |
1394 | { | |
1395 | fixP->fx_r_type = fixP->fx_size == 4 ? R_H8500_IMM32 : R_H8500_IMM16; | |
1396 | } | |
1397 | ||
1398 | switch (fixP->fx_r_type) | |
1399 | { | |
1400 | ||
1401 | case R_H8500_IMM8: | |
1402 | case R_H8500_PCREL8: | |
1403 | *buf++ = val; | |
1404 | break; | |
1405 | case R_H8500_IMM16: | |
1406 | case R_H8500_LOW16: | |
1407 | case R_H8500_PCREL16: | |
1408 | *buf++ = (val >> 8); | |
1409 | *buf++ = val; | |
1410 | break; | |
1411 | case R_H8500_HIGH8: | |
1412 | *buf++ = val >> 16; | |
1413 | break; | |
1414 | case R_H8500_HIGH16: | |
1415 | *buf++ = val >> 24; | |
1416 | *buf++ = val >> 16; | |
1417 | break; | |
1418 | case R_H8500_IMM24: | |
1419 | *buf++ = (val >> 16); | |
1420 | *buf++ = (val >> 8); | |
1421 | *buf++ = val; | |
1422 | break; | |
1423 | case R_H8500_IMM32: | |
1424 | *buf++ = (val >> 24); | |
1425 | *buf++ = (val >> 16); | |
1426 | *buf++ = (val >> 8); | |
1427 | *buf++ = val; | |
1428 | break; | |
1429 | default: | |
1430 | abort (); | |
1431 | ||
1432 | } | |
1433 | } | |
1434 | ||
1435 | /* | |
1436 | called just before address relaxation, return the length | |
1437 | by which a fragment must grow to reach it's destination | |
1438 | */ | |
1439 | int | |
1440 | md_estimate_size_before_relax (fragP, segment_type) | |
1441 | register fragS *fragP; | |
1442 | register segT segment_type; | |
1443 | { | |
1444 | int what = GET_WHAT (fragP->fr_subtype); | |
1445 | ||
1446 | switch (fragP->fr_subtype) | |
1447 | { | |
1448 | default: | |
1449 | abort (); | |
1450 | case C (BRANCH, UNDEF_BYTE_DISP): | |
1451 | case C (SCB_F, UNDEF_BYTE_DISP): | |
1452 | case C (SCB_TST, UNDEF_BYTE_DISP): | |
1453 | /* used to be a branch to somewhere which was unknown */ | |
1454 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
1455 | { | |
1456 | /* Got a symbol and it's defined in this segment, become byte | |
3dd5103b | 1457 | sized - maybe it will fix up. */ |
252b5132 RH |
1458 | fragP->fr_subtype = C (what, BYTE_DISP); |
1459 | fragP->fr_var = md_relax_table[C (what, BYTE_DISP)].rlx_length; | |
1460 | } | |
1461 | else | |
1462 | { | |
3dd5103b NC |
1463 | /* Its got a segment, but its not ours, so it will always be |
1464 | long. */ | |
252b5132 RH |
1465 | fragP->fr_subtype = C (what, UNDEF_WORD_DISP); |
1466 | fragP->fr_var = md_relax_table[C (what, WORD_DISP)].rlx_length; | |
1467 | return md_relax_table[C (what, WORD_DISP)].rlx_length; | |
1468 | } | |
1469 | } | |
1470 | return fragP->fr_var; | |
1471 | } | |
1472 | ||
3dd5103b | 1473 | /* Put number into target byte order. */ |
252b5132 RH |
1474 | |
1475 | void | |
1476 | md_number_to_chars (ptr, use, nbytes) | |
1477 | char *ptr; | |
1478 | valueT use; | |
1479 | int nbytes; | |
1480 | { | |
1481 | number_to_chars_bigendian (ptr, use, nbytes); | |
1482 | } | |
1483 | ||
1484 | long | |
1485 | md_pcrel_from (fixP) | |
1486 | fixS *fixP; | |
1487 | { | |
1488 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
1489 | } | |
1490 | ||
252b5132 RH |
1491 | void |
1492 | tc_coff_symbol_emit_hook (ignore) | |
1493 | symbolS *ignore; | |
1494 | { | |
1495 | } | |
1496 | ||
1497 | short | |
1498 | tc_coff_fix2rtype (fix_ptr) | |
1499 | fixS *fix_ptr; | |
1500 | { | |
1501 | if (fix_ptr->fx_r_type == RELOC_32) | |
1502 | { | |
1503 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
1504 | */ | |
1505 | switch (fix_ptr->fx_size) | |
1506 | { | |
1507 | case 2: | |
1508 | return R_H8500_IMM16; | |
1509 | break; | |
1510 | case 1: | |
1511 | return R_H8500_IMM8; | |
1512 | break; | |
1513 | default: | |
1514 | abort (); | |
1515 | } | |
1516 | } | |
1517 | return fix_ptr->fx_r_type; | |
1518 | } | |
1519 | ||
1520 | void | |
1521 | tc_reloc_mangle (fix_ptr, intr, base) | |
1522 | fixS *fix_ptr; | |
1523 | struct internal_reloc *intr; | |
1524 | bfd_vma base; | |
1525 | ||
1526 | { | |
1527 | symbolS *symbol_ptr; | |
1528 | ||
1529 | symbol_ptr = fix_ptr->fx_addsy; | |
1530 | ||
1531 | /* If this relocation is attached to a symbol then it's ok | |
1532 | to output it */ | |
1533 | if (fix_ptr->fx_r_type == RELOC_32) | |
1534 | { | |
1535 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
1536 | */ | |
1537 | switch (fix_ptr->fx_size) | |
1538 | { | |
1539 | case 2: | |
1540 | intr->r_type = R_IMM16; | |
1541 | break; | |
1542 | case 1: | |
1543 | intr->r_type = R_IMM8; | |
1544 | break; | |
1545 | default: | |
1546 | abort (); | |
1547 | } | |
1548 | } | |
1549 | else | |
1550 | { | |
1551 | intr->r_type = fix_ptr->fx_r_type; | |
1552 | } | |
1553 | ||
1554 | intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base; | |
1555 | intr->r_offset = fix_ptr->fx_offset; | |
1556 | ||
1557 | /* Turn the segment of the symbol into an offset. */ | |
1558 | if (symbol_ptr) | |
1559 | { | |
1560 | symbolS *dot; | |
1561 | ||
1562 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot; | |
1563 | if (dot) | |
1564 | { | |
3dd5103b NC |
1565 | #if 0 |
1566 | intr->r_offset -= | |
1567 | segment_info[S_GET_SEGMENT (symbol_ptr)].scnhdr.s_paddr; | |
1568 | #endif | |
252b5132 RH |
1569 | intr->r_offset += S_GET_VALUE (symbol_ptr); |
1570 | intr->r_symndx = dot->sy_number; | |
1571 | } | |
1572 | else | |
1573 | { | |
1574 | intr->r_symndx = symbol_ptr->sy_number; | |
1575 | } | |
1576 | ||
1577 | } | |
1578 | else | |
1579 | { | |
1580 | intr->r_symndx = -1; | |
1581 | } | |
1582 | ||
1583 | } | |
1584 | ||
252b5132 RH |
1585 | int |
1586 | start_label (ptr) | |
1587 | char *ptr; | |
1588 | { | |
1589 | /* Check for :s.w */ | |
1590 | if (isalpha (ptr[1]) && ptr[2] == '.') | |
1591 | return 0; | |
1592 | /* Check for :s */ | |
1593 | if (isalpha (ptr[1]) && !isalpha (ptr[2])) | |
1594 | return 0; | |
1595 | return 1; | |
1596 | } | |
1597 | ||
252b5132 RH |
1598 | int |
1599 | tc_coff_sizemachdep (frag) | |
1600 | fragS *frag; | |
1601 | { | |
1602 | return md_relax_table[frag->fr_subtype].rlx_length; | |
1603 | } |