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