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