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; |
80aab579 | 424 | op->exp.X_unsigned = 1; |
10a3e374 | 425 | op->type = IMM8; |
033400ec SC |
426 | return idx; |
427 | ||
428 | } | |
10a3e374 | 429 | |
033400ec SC |
430 | /* The many forms of operand: |
431 | ||
432 | Rn Register direct | |
433 | @Rn Register indirect | |
434 | @(disp[:size], Rn) Register indirect with displacement | |
435 | @Rn+ | |
436 | @-Rn | |
437 | @aa[:size] absolute | |
438 | #xx[:size] immediate data | |
439 | ||
440 | */ | |
441 | ||
442 | static void | |
10a3e374 | 443 | get_operand (ptr, op, ispage) |
033400ec SC |
444 | char **ptr; |
445 | h8500_operand_info *op; | |
10a3e374 | 446 | char ispage; |
033400ec SC |
447 | { |
448 | char *src = *ptr; | |
449 | int mode; | |
450 | unsigned int num; | |
451 | unsigned int len; | |
3adb6ca9 | 452 | op->page = 0; |
033400ec | 453 | if (src[0] == '(' && src[1] == 'r') |
10a3e374 SC |
454 | { |
455 | /* This is a register list */ | |
456 | *ptr = src + parse_reglist (src, op); | |
457 | return; | |
458 | } | |
033400ec SC |
459 | |
460 | len = parse_reg (src, &op->type, &op->reg); | |
461 | ||
462 | if (len) | |
463 | { | |
464 | *ptr = src + len; | |
465 | return; | |
466 | } | |
467 | ||
468 | if (*src == '@') | |
469 | { | |
470 | src++; | |
471 | if (*src == '-') | |
472 | { | |
473 | src++; | |
474 | len = parse_reg (src, &mode, &num); | |
475 | if (len == 0) | |
476 | { | |
477 | /* Oops, not a reg after all, must be ordinary exp */ | |
478 | src--; | |
479 | /* must be a symbol */ | |
10a3e374 SC |
480 | *ptr = skip_colonthing (exp_unsigned, src, |
481 | op, ABS16, ABS8, ABS16, ABS24); | |
033400ec SC |
482 | return; |
483 | } | |
484 | ||
485 | op->type = RNDEC; | |
486 | op->reg = num; | |
487 | *ptr = src + len; | |
488 | return; | |
489 | } | |
490 | if (*src == '(') | |
491 | { | |
492 | /* Disp */ | |
493 | src++; | |
494 | ||
10a3e374 SC |
495 | src = skip_colonthing (exp_signed, src, |
496 | op, RNIND_D16, RNIND_D8, RNIND_D16, 0); | |
033400ec SC |
497 | |
498 | if (*src != ',') | |
499 | { | |
500 | as_bad ("expected @(exp, Rn)"); | |
501 | return; | |
502 | } | |
503 | src++; | |
504 | len = parse_reg (src, &mode, &op->reg); | |
505 | if (len == 0 || mode != RN) | |
506 | { | |
507 | as_bad ("expected @(exp, Rn)"); | |
508 | return; | |
509 | } | |
510 | src += len; | |
511 | if (*src != ')') | |
512 | { | |
513 | as_bad ("expected @(exp, Rn)"); | |
514 | return; | |
515 | } | |
516 | *ptr = src + 1; | |
517 | return; | |
518 | } | |
519 | len = parse_reg (src, &mode, &num); | |
520 | ||
521 | if (len) | |
522 | { | |
523 | src += len; | |
524 | if (*src == '+') | |
525 | { | |
526 | src++; | |
527 | if (mode != RN) | |
528 | { | |
529 | as_bad ("@Rn+ needs word register"); | |
530 | return; | |
531 | } | |
532 | op->type = RNINC; | |
533 | op->reg = num; | |
534 | *ptr = src; | |
535 | return; | |
536 | } | |
537 | if (mode != RN) | |
538 | { | |
539 | as_bad ("@Rn needs word register"); | |
540 | return; | |
541 | } | |
542 | op->type = RNIND; | |
543 | op->reg = num; | |
544 | *ptr = src; | |
545 | return; | |
546 | } | |
547 | else | |
548 | { | |
549 | /* must be a symbol */ | |
10a3e374 SC |
550 | *ptr = |
551 | skip_colonthing (exp_unsigned, src, op, | |
552 | ispage ? ABS24 : ABS16, ABS8, ABS16, ABS24); | |
033400ec SC |
553 | return; |
554 | } | |
555 | } | |
556 | ||
557 | if (*src == '#') | |
558 | { | |
559 | src++; | |
10a3e374 | 560 | *ptr = skip_colonthing (exp_sandu, src, op, IMM16, IMM8, IMM16, ABS24); |
033400ec SC |
561 | return; |
562 | } | |
563 | else | |
564 | { | |
10a3e374 SC |
565 | *ptr = skip_colonthing (exp_signed, src, op, |
566 | ispage ? ABS24 : PCREL8, PCREL8, PCREL16, ABS24); | |
033400ec SC |
567 | } |
568 | } | |
569 | ||
570 | static | |
571 | char * | |
572 | get_operands (info, args, operand) | |
573 | h8500_opcode_info *info; | |
574 | char *args; | |
575 | h8500_operand_info *operand; | |
576 | ||
577 | { | |
578 | char *ptr = args; | |
579 | ||
580 | switch (info->nargs) | |
581 | { | |
582 | case 0: | |
583 | operand[0].type = 0; | |
584 | operand[1].type = 0; | |
585 | break; | |
586 | ||
587 | case 1: | |
588 | ptr++; | |
10a3e374 | 589 | get_operand (&ptr, operand + 0, info->name[0] == 'p'); |
033400ec SC |
590 | operand[1].type = 0; |
591 | break; | |
592 | ||
593 | case 2: | |
594 | ptr++; | |
595 | get_operand (&ptr, operand + 0, 0); | |
596 | if (*ptr == ',') | |
597 | ptr++; | |
10a3e374 | 598 | get_operand (&ptr, operand + 1, 0); |
033400ec SC |
599 | break; |
600 | ||
601 | default: | |
602 | abort (); | |
603 | } | |
604 | ||
605 | return ptr; | |
606 | } | |
607 | ||
608 | /* Passed a pointer to a list of opcodes which use different | |
609 | addressing modes, return the opcode which matches the opcodes | |
610 | provided | |
611 | */ | |
612 | ||
10a3e374 | 613 | int pcrel8; /* Set when we've seen a pcrel operand */ |
033400ec SC |
614 | |
615 | static | |
616 | h8500_opcode_info * | |
617 | get_specific (opcode, operands) | |
618 | h8500_opcode_info *opcode; | |
619 | h8500_operand_info *operands; | |
620 | { | |
621 | h8500_opcode_info *this_try = opcode; | |
622 | int found = 0; | |
623 | unsigned int noperands = opcode->nargs; | |
624 | ||
033400ec SC |
625 | unsigned int this_index = opcode->idx; |
626 | ||
627 | while (this_index == opcode->idx && !found) | |
628 | { | |
629 | unsigned int i; | |
630 | ||
631 | this_try = opcode++; | |
632 | ||
633 | /* look at both operands needed by the opcodes and provided by | |
634 | the user*/ | |
635 | for (i = 0; i < noperands; i++) | |
636 | { | |
637 | h8500_operand_info *user = operands + i; | |
638 | ||
639 | switch (this_try->arg_type[i]) | |
640 | { | |
033400ec SC |
641 | case FPIND_D8: |
642 | /* Opcode needs (disp:8,fp) */ | |
10a3e374 | 643 | if (user->type == RNIND_D8 && user->reg == 6) |
033400ec SC |
644 | { |
645 | displacement = user->exp; | |
646 | continue; | |
647 | } | |
648 | break; | |
649 | case RDIND_D16: | |
650 | if (user->type == RNIND_D16) | |
651 | { | |
652 | displacement = user->exp; | |
653 | rd = user->reg; | |
654 | continue; | |
655 | } | |
656 | break; | |
657 | case RDIND_D8: | |
658 | if (user->type == RNIND_D8) | |
659 | { | |
660 | displacement = user->exp; | |
661 | rd = user->reg; | |
662 | continue; | |
663 | } | |
664 | break; | |
665 | case RNIND_D16: | |
666 | case RNIND_D8: | |
667 | if (user->type == this_try->arg_type[i]) | |
668 | { | |
669 | displacement = user->exp; | |
670 | rn = user->reg; | |
671 | continue; | |
672 | } | |
673 | break; | |
10a3e374 | 674 | |
033400ec SC |
675 | case SPDEC: |
676 | if (user->type == RNDEC && user->reg == 7) | |
677 | { | |
678 | continue; | |
679 | } | |
680 | break; | |
3adb6ca9 SC |
681 | case SPINC: |
682 | if (user->type == RNINC && user->reg == 7) | |
683 | { | |
684 | continue; | |
685 | } | |
686 | break; | |
033400ec SC |
687 | case ABS16: |
688 | if (user->type == ABS16) | |
689 | { | |
690 | absolute = user->exp; | |
691 | continue; | |
692 | } | |
693 | break; | |
694 | case ABS8: | |
695 | if (user->type == ABS8) | |
696 | { | |
697 | absolute = user->exp; | |
698 | continue; | |
699 | } | |
700 | break; | |
701 | case ABS24: | |
702 | if (user->type == ABS24) | |
703 | { | |
704 | absolute = user->exp; | |
705 | continue; | |
706 | } | |
707 | break; | |
10a3e374 | 708 | |
033400ec | 709 | case CRB: |
10a3e374 | 710 | if ((user->type == CRB || user->type == CR) && user->reg != 0) |
033400ec SC |
711 | { |
712 | crb = user->reg; | |
713 | continue; | |
714 | } | |
715 | break; | |
716 | case CRW: | |
10a3e374 | 717 | if ((user->type == CRW || user->type == CR) && user->reg == 0) |
033400ec SC |
718 | { |
719 | crw = user->reg; | |
720 | continue; | |
721 | } | |
722 | break; | |
723 | case DISP16: | |
724 | if (user->type == DISP16) | |
725 | { | |
726 | displacement = user->exp; | |
727 | continue; | |
728 | } | |
729 | break; | |
730 | case DISP8: | |
731 | if (user->type == DISP8) | |
732 | { | |
733 | displacement = user->exp; | |
734 | continue; | |
735 | } | |
736 | break; | |
737 | case FP: | |
738 | if (user->type == RN && user->reg == 6) | |
739 | { | |
740 | continue; | |
741 | } | |
742 | break; | |
743 | case PCREL16: | |
744 | if (user->type == PCREL16) | |
745 | { | |
746 | displacement = user->exp; | |
747 | continue; | |
748 | } | |
749 | break; | |
750 | case PCREL8: | |
751 | if (user->type == PCREL8) | |
752 | { | |
753 | displacement = user->exp; | |
754 | pcrel8 = 1; | |
755 | continue; | |
756 | } | |
757 | break; | |
758 | ||
759 | case IMM16: | |
10a3e374 | 760 | if (user->type == IMM16 |
033400ec SC |
761 | || user->type == IMM8) |
762 | { | |
763 | immediate_inpage = user->page; | |
764 | immediate = user->exp; | |
765 | continue; | |
766 | } | |
767 | break; | |
10a3e374 | 768 | case RLIST: |
033400ec SC |
769 | case IMM8: |
770 | if (user->type == IMM8) | |
771 | { | |
772 | immediate_inpage = user->page; | |
773 | immediate = user->exp; | |
774 | continue; | |
775 | } | |
776 | break; | |
777 | case IMM4: | |
778 | if (user->type == IMM8) | |
779 | { | |
780 | immediate_inpage = user->page; | |
781 | immediate = user->exp; | |
782 | continue; | |
783 | } | |
784 | break; | |
785 | case QIM: | |
786 | if (user->type == IMM8 | |
5ac34ac3 | 787 | && user->exp.X_op == O_constant |
033400ec SC |
788 | && |
789 | (user->exp.X_add_number == -2 | |
790 | || user->exp.X_add_number == -1 | |
791 | || user->exp.X_add_number == 1 | |
792 | || user->exp.X_add_number == 2)) | |
793 | { | |
794 | immediate_inpage = user->page; | |
795 | immediate = user->exp; | |
796 | continue; | |
797 | } | |
798 | break; | |
799 | case RD: | |
800 | if (user->type == RN) | |
801 | { | |
802 | rd = user->reg; | |
803 | continue; | |
804 | } | |
805 | break; | |
806 | case RS: | |
807 | if (user->type == RN) | |
808 | { | |
809 | rs = user->reg; | |
810 | continue; | |
811 | } | |
812 | break; | |
10a3e374 | 813 | case RDIND: |
033400ec | 814 | if (user->type == RNIND) |
10a3e374 SC |
815 | { |
816 | rd = user->reg; | |
817 | continue; | |
818 | ||
819 | } | |
033400ec SC |
820 | break; |
821 | case RNINC: | |
822 | case RNIND: | |
823 | case RNDEC: | |
824 | case RN: | |
825 | ||
826 | if (user->type == this_try->arg_type[i]) | |
827 | { | |
828 | rn = user->reg; | |
829 | continue; | |
830 | } | |
831 | break; | |
832 | case SP: | |
833 | if (user->type == RN && user->reg == 7) | |
834 | { | |
835 | continue; | |
836 | } | |
837 | break; | |
838 | default: | |
839 | printf ("unhandled %d\n", this_try->arg_type[i]); | |
840 | break; | |
841 | } | |
842 | ||
843 | /* If we get here this didn't work out */ | |
844 | goto fail; | |
845 | } | |
846 | found = 1; | |
847 | fail:; | |
848 | ||
849 | } | |
850 | ||
851 | if (found) | |
852 | return this_try; | |
853 | else | |
854 | return 0; | |
855 | } | |
856 | ||
857 | int | |
858 | check (operand, low, high) | |
859 | expressionS *operand; | |
860 | int low; | |
861 | int high; | |
862 | { | |
5ac34ac3 | 863 | if (operand->X_op != O_constant |
033400ec SC |
864 | || operand->X_add_number < low |
865 | || operand->X_add_number > high) | |
866 | { | |
867 | as_bad ("operand must be absolute in range %d..%d", low, high); | |
868 | } | |
869 | return operand->X_add_number; | |
870 | } | |
871 | ||
10a3e374 SC |
872 | static |
873 | void | |
874 | insert (output, index, exp, reloc, pcrel) | |
033400ec SC |
875 | char *output; |
876 | int index; | |
877 | expressionS *exp; | |
10a3e374 SC |
878 | int reloc; |
879 | int pcrel; | |
033400ec | 880 | { |
5ac34ac3 ILT |
881 | fix_new_exp (frag_now, |
882 | output - frag_now->fr_literal + index, | |
883 | 4, /* always say size is 4, but we know better */ | |
88b457e5 | 884 | exp, |
5ac34ac3 ILT |
885 | pcrel, |
886 | reloc); | |
033400ec SC |
887 | } |
888 | ||
889 | void | |
890 | build_relaxable_instruction (opcode, operand) | |
891 | h8500_opcode_info *opcode; | |
892 | h8500_operand_info *operand; | |
893 | { | |
894 | /* All relaxable instructions start life as two bytes but can become | |
895 | three bytes long if a lonely branch and up to 9 bytes if long scb | |
896 | */ | |
897 | char *p; | |
898 | int len; | |
899 | int type; | |
900 | ||
901 | if (opcode->bytes[0].contents == 0x01) | |
10a3e374 SC |
902 | { |
903 | type = SCB_F; | |
904 | } | |
033400ec SC |
905 | else if (opcode->bytes[0].contents == 0x06 |
906 | || opcode->bytes[0].contents == 0x07) | |
10a3e374 SC |
907 | { |
908 | type = SCB_TST; | |
909 | } | |
033400ec | 910 | else |
10a3e374 SC |
911 | { |
912 | type = BRANCH; | |
913 | } | |
033400ec SC |
914 | |
915 | p = frag_var (rs_machine_dependent, | |
916 | md_relax_table[C (type, WORD_DISP)].rlx_length, | |
917 | len = md_relax_table[C (type, BYTE_DISP)].rlx_length, | |
918 | C (type, UNDEF_BYTE_DISP), | |
919 | displacement.X_add_symbol, | |
920 | displacement.X_add_number, | |
921 | 0); | |
922 | ||
923 | p[0] = opcode->bytes[0].contents; | |
10a3e374 SC |
924 | if (type != BRANCH) |
925 | { | |
926 | p[1] = opcode->bytes[1].contents | rs; | |
927 | } | |
033400ec SC |
928 | } |
929 | ||
930 | /* Now we know what sort of opcodes it is, lets build the bytes - | |
931 | */ | |
932 | static void | |
933 | build_bytes (opcode, operand) | |
934 | h8500_opcode_info *opcode; | |
935 | h8500_operand_info *operand; | |
936 | ||
937 | { | |
033400ec | 938 | int index; |
033400ec SC |
939 | |
940 | if (pcrel8) | |
941 | { | |
942 | pcrel8 = 0; | |
943 | build_relaxable_instruction (opcode, operand); | |
944 | } | |
945 | else | |
946 | { | |
947 | char *output = frag_more (opcode->length); | |
948 | ||
949 | memset (output, 0, opcode->length); | |
950 | for (index = 0; index < opcode->length; index++) | |
951 | { | |
952 | output[index] = opcode->bytes[index].contents; | |
953 | ||
954 | switch (opcode->bytes[index].insert) | |
955 | { | |
956 | default: | |
957 | printf ("failed for %d\n", opcode->bytes[index].insert); | |
958 | break; | |
959 | case 0: | |
960 | break; | |
961 | case RN: | |
962 | output[index] |= rn; | |
963 | break; | |
964 | case RD: | |
1f55e556 SC |
965 | case RDIND: |
966 | ||
033400ec SC |
967 | output[index] |= rd; |
968 | break; | |
969 | case RS: | |
970 | output[index] |= rs; | |
971 | break; | |
972 | case DISP16: | |
10a3e374 | 973 | insert (output, index, &displacement, R_H8500_IMM16, 0); |
033400ec SC |
974 | index++; |
975 | break; | |
976 | case DISP8: | |
977 | case FPIND_D8: | |
10a3e374 | 978 | insert (output, index, &displacement, R_H8500_IMM8, 0); |
033400ec | 979 | break; |
489a93f3 | 980 | |
033400ec | 981 | case IMM16: |
489a93f3 SC |
982 | { |
983 | int p; | |
984 | switch (immediate_inpage) { | |
985 | case 'p': | |
986 | p = R_H8500_LOW16; | |
987 | break; | |
988 | case 'h': | |
989 | p = R_H8500_HIGH16; | |
990 | break; | |
991 | default: | |
992 | p = R_H8500_IMM16; | |
993 | break; | |
994 | } | |
995 | ||
996 | insert (output, index, &immediate,p, 0); | |
997 | } | |
998 | ||
033400ec SC |
999 | index++; |
1000 | break; | |
10a3e374 | 1001 | case RLIST: |
033400ec | 1002 | case IMM8: |
10a3e374 SC |
1003 | if (immediate_inpage) |
1004 | { | |
1005 | insert (output, index, &immediate, R_H8500_HIGH8, 0); | |
1006 | } | |
1007 | else | |
1008 | { | |
1009 | insert (output, index, &immediate, R_H8500_IMM8, 0); | |
1010 | } | |
033400ec SC |
1011 | break; |
1012 | case PCREL16: | |
10a3e374 | 1013 | insert (output, index, &displacement, R_H8500_PCREL16, 1); |
033400ec SC |
1014 | index++; |
1015 | break; | |
1016 | case PCREL8: | |
10a3e374 | 1017 | insert (output, index, &displacement, R_H8500_PCREL8, 1); |
033400ec SC |
1018 | break; |
1019 | case IMM4: | |
1020 | output[index] |= check (&immediate, 0, 15); | |
1021 | break; | |
10a3e374 SC |
1022 | case CR: |
1023 | ||
1024 | output[index] |= cr; | |
1025 | if (cr == 0) | |
1026 | { | |
1027 | output[0] |= 0x8; | |
1028 | } | |
1029 | else | |
1030 | { | |
1031 | output[0] &= ~0x8; | |
1032 | } | |
1033 | ||
1034 | break; | |
1035 | ||
033400ec SC |
1036 | case CRB: |
1037 | output[index] |= crb; | |
10a3e374 | 1038 | output[0] &= ~0x8; |
033400ec SC |
1039 | break; |
1040 | case CRW: | |
1041 | output[index] |= crw; | |
10a3e374 SC |
1042 | output[0] |= 0x8; |
1043 | break; | |
1044 | case ABS24: | |
1f55e556 | 1045 | insert (output, index, &absolute, R_H8500_IMM24, 0); |
10a3e374 | 1046 | index += 2; |
033400ec SC |
1047 | break; |
1048 | case ABS16: | |
1f55e556 | 1049 | insert (output, index, &absolute, R_H8500_IMM16, 0); |
033400ec SC |
1050 | index++; |
1051 | break; | |
1052 | case ABS8: | |
1f55e556 | 1053 | insert (output, index, &absolute, R_H8500_IMM8, 0); |
033400ec SC |
1054 | break; |
1055 | case QIM: | |
1056 | switch (immediate.X_add_number) | |
1057 | { | |
1058 | case -2: | |
1059 | output[index] |= 0x5; | |
1060 | break; | |
1061 | case -1: | |
1062 | output[index] |= 0x4; | |
1063 | break; | |
1064 | case 1: | |
1065 | output[index] |= 0; | |
1066 | break; | |
1067 | case 2: | |
1068 | output[index] |= 1; | |
1069 | break; | |
1070 | } | |
1071 | break; | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | } | |
1076 | ||
1077 | /* This is the guts of the machine-dependent assembler. STR points to a | |
1078 | machine dependent instruction. This funciton is supposed to emit | |
1079 | the frags/bytes it assembles to. | |
1080 | */ | |
1081 | ||
1082 | void | |
1083 | DEFUN (md_assemble, (str), | |
1084 | char *str) | |
1085 | { | |
1086 | char *op_start; | |
1087 | char *op_end; | |
033400ec SC |
1088 | h8500_operand_info operand[2]; |
1089 | h8500_opcode_info *opcode; | |
1090 | h8500_opcode_info *prev_opcode; | |
1091 | char name[11]; | |
033400ec SC |
1092 | |
1093 | int nlen = 0; | |
1094 | ||
1095 | /* Drop leading whitespace */ | |
1096 | while (*str == ' ') | |
1097 | str++; | |
1098 | ||
1099 | /* find the op code end */ | |
1100 | for (op_start = op_end = str; | |
10a3e374 SC |
1101 | *op_end && |
1102 | !is_end_of_line[*op_end] && *op_end != ' '; | |
033400ec SC |
1103 | op_end++) |
1104 | { | |
10a3e374 | 1105 | if ( /**op_end != '.' |
033400ec | 1106 | && *op_end != ':' |
10a3e374 | 1107 | && */ nlen < 10) |
033400ec SC |
1108 | { |
1109 | name[nlen++] = *op_end; | |
1110 | } | |
1111 | } | |
1112 | name[nlen] = 0; | |
1113 | ||
1114 | if (op_end == op_start) | |
1115 | { | |
1116 | as_bad ("can't find opcode "); | |
1117 | } | |
1118 | ||
1119 | opcode = (h8500_opcode_info *) hash_find (opcode_hash_control, name); | |
1120 | ||
1121 | if (opcode == NULL) | |
1122 | { | |
1123 | as_bad ("unknown opcode"); | |
1124 | return; | |
1125 | } | |
1126 | ||
1127 | input_line_pointer = get_operands (opcode, op_end, operand); | |
1128 | prev_opcode = opcode; | |
1129 | ||
1130 | opcode = get_specific (opcode, operand); | |
1131 | ||
1132 | if (opcode == 0) | |
1133 | { | |
1134 | /* Couldn't find an opcode which matched the operands */ | |
1135 | char *where = frag_more (2); | |
1136 | ||
1137 | where[0] = 0x0; | |
1138 | where[1] = 0x0; | |
1139 | as_bad ("invalid operands for opcode"); | |
1140 | return; | |
1141 | } | |
1142 | ||
1143 | build_bytes (opcode, operand); | |
1144 | ||
1145 | } | |
1146 | ||
1147 | void | |
1148 | DEFUN (tc_crawl_symbol_chain, (headers), | |
1149 | object_headers * headers) | |
1150 | { | |
1151 | printf ("call to tc_crawl_symbol_chain \n"); | |
1152 | } | |
1153 | ||
1154 | symbolS * | |
1155 | DEFUN (md_undefined_symbol, (name), | |
1156 | char *name) | |
1157 | { | |
1158 | return 0; | |
1159 | } | |
1160 | ||
1161 | void | |
1162 | DEFUN (tc_headers_hook, (headers), | |
1163 | object_headers * headers) | |
1164 | { | |
1165 | printf ("call to tc_headers_hook \n"); | |
1166 | } | |
1167 | ||
1168 | void | |
1169 | DEFUN_VOID (md_end) | |
1170 | { | |
1171 | } | |
1172 | ||
1173 | /* Various routines to kill one day */ | |
1174 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
1175 | #define MAX_LITTLENUMS 6 | |
1176 | ||
1177 | /* Turn a string in input_line_pointer into a floating point constant of type | |
1178 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
1179 | emitted is stored in *sizeP . An error message is returned, or NULL on OK. | |
1180 | */ | |
1181 | char * | |
1182 | md_atof (type, litP, sizeP) | |
1183 | char type; | |
1184 | char *litP; | |
1185 | int *sizeP; | |
1186 | { | |
1187 | int prec; | |
1188 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1189 | LITTLENUM_TYPE *wordP; | |
1190 | char *t; | |
1191 | char *atof_ieee (); | |
1192 | ||
1193 | switch (type) | |
1194 | { | |
1195 | case 'f': | |
1196 | case 'F': | |
1197 | case 's': | |
1198 | case 'S': | |
1199 | prec = 2; | |
1200 | break; | |
1201 | ||
1202 | case 'd': | |
1203 | case 'D': | |
1204 | case 'r': | |
1205 | case 'R': | |
1206 | prec = 4; | |
1207 | break; | |
1208 | ||
1209 | case 'x': | |
1210 | case 'X': | |
1211 | prec = 6; | |
1212 | break; | |
1213 | ||
1214 | case 'p': | |
1215 | case 'P': | |
1216 | prec = 6; | |
1217 | break; | |
1218 | ||
1219 | default: | |
1220 | *sizeP = 0; | |
1221 | return "Bad call to MD_ATOF()"; | |
1222 | } | |
1223 | t = atof_ieee (input_line_pointer, type, words); | |
1224 | if (t) | |
1225 | input_line_pointer = t; | |
1226 | ||
1227 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
1228 | for (wordP = words; prec--;) | |
1229 | { | |
1230 | md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
1231 | litP += sizeof (LITTLENUM_TYPE); | |
1232 | } | |
99024047 | 1233 | return 0; |
033400ec SC |
1234 | } |
1235 | ||
1236 | int | |
1237 | md_parse_option (argP, cntP, vecP) | |
1238 | char **argP; | |
1239 | int *cntP; | |
1240 | char ***vecP; | |
1241 | ||
1242 | { | |
1243 | return 0; | |
033400ec SC |
1244 | } |
1245 | ||
1246 | int md_short_jump_size; | |
1247 | ||
1248 | void | |
1249 | tc_aout_fix_to_chars () | |
1250 | { | |
1251 | printf ("call to tc_aout_fix_to_chars \n"); | |
1252 | abort (); | |
1253 | } | |
1254 | ||
1255 | void | |
1256 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1257 | char *ptr; | |
025b0302 ME |
1258 | addressT from_addr; |
1259 | addressT to_addr; | |
033400ec SC |
1260 | fragS *frag; |
1261 | symbolS *to_symbol; | |
1262 | { | |
1263 | as_fatal ("failed sanity check."); | |
1264 | } | |
1265 | ||
1266 | void | |
1267 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1268 | char *ptr; | |
025b0302 | 1269 | addressT from_addr, to_addr; |
033400ec SC |
1270 | fragS *frag; |
1271 | symbolS *to_symbol; | |
1272 | { | |
1273 | as_fatal ("failed sanity check."); | |
1274 | } | |
1275 | ||
1276 | static | |
1277 | void | |
1278 | wordify_scb (buffer, disp_size, inst_size) | |
1279 | char *buffer; | |
1280 | int *disp_size; | |
1281 | int *inst_size; | |
1282 | { | |
1283 | int rn = buffer[1] & 0x7; | |
1284 | ||
1285 | switch (buffer[0]) | |
1286 | { | |
10a3e374 | 1287 | case 0x0e: /* BSR */ |
033400ec SC |
1288 | case 0x20: |
1289 | case 0x21: | |
1290 | case 0x22: | |
1291 | case 0x23: | |
10a3e374 | 1292 | case 0x24: |
033400ec SC |
1293 | case 0x25: |
1294 | case 0x26: | |
1295 | case 0x27: | |
1296 | case 0x28: | |
1297 | case 0x29: | |
1298 | case 0x2a: | |
1299 | case 0x2b: | |
1300 | case 0x2c: | |
1301 | case 0x2d: | |
1302 | case 0x2e: | |
1303 | case 0x2f: | |
1304 | buffer[0] |= 0x10; | |
1305 | buffer[1] = 0; | |
1306 | buffer[2] = 0; | |
1307 | *disp_size = 2; | |
1308 | *inst_size = 1; | |
1309 | return; | |
1310 | default: | |
1311 | abort (); | |
1312 | ||
1313 | case 0x01: | |
1314 | *inst_size = 6; | |
1315 | *disp_size = 2; | |
1316 | break; | |
1317 | case 0x06: | |
1318 | *inst_size = 8; | |
1319 | *disp_size = 2; | |
1320 | ||
1321 | *buffer++ = 0x26; /* bne + 8 */ | |
1322 | *buffer++ = 0x08; | |
1323 | break; | |
1324 | case 0x07: | |
1325 | *inst_size = 8; | |
1326 | *disp_size = 2; | |
1327 | *buffer++ = 0x27; /* bne + 8 */ | |
1328 | *buffer++ = 0x08; | |
1329 | break; | |
1330 | ||
1331 | } | |
1332 | *buffer++ = 0xa8 | rn; /* addq -1,rn */ | |
1333 | *buffer++ = 0x0c; | |
1334 | *buffer++ = 0x04; /* cmp #0xff:8, rn */ | |
1335 | *buffer++ = 0xff; | |
1336 | *buffer++ = 0x70 | rn; | |
1337 | *buffer++ = 0x36; /* bne ... */ | |
1338 | *buffer++ = 0; | |
1339 | *buffer++ = 0; | |
1340 | } | |
1341 | ||
1342 | /* | |
1343 | called after relaxing, change the frags so they know how big they are | |
1344 | */ | |
1345 | void | |
1346 | md_convert_frag (headers, fragP) | |
1347 | object_headers *headers; | |
1348 | fragS *fragP; | |
1349 | ||
1350 | { | |
033400ec SC |
1351 | int disp_size = 0; |
1352 | int inst_size = 0; | |
1353 | char *buffer = fragP->fr_fix + fragP->fr_literal; | |
1354 | ||
1355 | switch (fragP->fr_subtype) | |
1356 | { | |
1357 | case C (BRANCH, BYTE_DISP): | |
1358 | disp_size = 1; | |
1359 | inst_size = 1; | |
1360 | break; | |
1361 | ||
1362 | case C (SCB_F, BYTE_DISP): | |
1363 | case C (SCB_TST, BYTE_DISP): | |
1364 | disp_size = 1; | |
1365 | inst_size = 2; | |
1366 | break; | |
1367 | ||
1368 | /* Branches to a known 16 bit displacement */ | |
1369 | ||
1370 | /* Turn on the 16bit bit */ | |
1371 | case C (BRANCH, WORD_DISP): | |
1372 | case C (SCB_F, WORD_DISP): | |
1373 | case C (SCB_TST, WORD_DISP): | |
1374 | wordify_scb (buffer, &disp_size, &inst_size); | |
1375 | break; | |
1376 | ||
1377 | case C (BRANCH, UNDEF_WORD_DISP): | |
1378 | case C (SCB_F, UNDEF_WORD_DISP): | |
1379 | case C (SCB_TST, UNDEF_WORD_DISP): | |
1380 | /* This tried to be relaxed, but didn't manage it, it now needs a | |
1381 | fix */ | |
1382 | wordify_scb (buffer, &disp_size, &inst_size); | |
1383 | ||
1384 | /* Make a reloc */ | |
10a3e374 SC |
1385 | fix_new (fragP, |
1386 | fragP->fr_fix + inst_size, | |
1387 | 4, | |
1388 | fragP->fr_symbol, | |
10a3e374 SC |
1389 | fragP->fr_offset, |
1390 | 0, | |
1391 | R_H8500_PCREL16); | |
033400ec SC |
1392 | |
1393 | fragP->fr_fix += disp_size + inst_size; | |
1394 | fragP->fr_var = 0; | |
1395 | return; | |
1396 | break; | |
1397 | default: | |
1398 | abort (); | |
1399 | } | |
1400 | if (inst_size) | |
1401 | { | |
1402 | /* Get the address of the end of the instruction */ | |
1403 | int next_inst = fragP->fr_fix + fragP->fr_address + disp_size + inst_size; | |
1404 | int targ_addr = (S_GET_VALUE (fragP->fr_symbol) + | |
1405 | fragP->fr_offset); | |
1406 | int disp = targ_addr - next_inst; | |
1407 | ||
1408 | md_number_to_chars (buffer + inst_size, disp, disp_size); | |
1409 | fragP->fr_fix += disp_size + inst_size; | |
1410 | fragP->fr_var = 0; | |
1411 | } | |
1412 | ||
1413 | } | |
1414 | ||
025b0302 | 1415 | valueT |
489a93f3 SC |
1416 | md_section_align (seg, size) |
1417 | segT seg ; | |
1418 | valueT size; | |
033400ec | 1419 | { |
10a3e374 SC |
1420 | return ((size + (1 << section_alignment[(int) seg]) - 1) |
1421 | & (-1 << section_alignment[(int) seg])); | |
033400ec SC |
1422 | |
1423 | } | |
1424 | ||
1425 | void | |
1426 | md_apply_fix (fixP, val) | |
1427 | fixS *fixP; | |
1428 | long val; | |
1429 | { | |
1430 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
1431 | ||
10a3e374 | 1432 | if (fixP->fx_r_type == 0) |
033400ec | 1433 | { |
10a3e374 SC |
1434 | fixP->fx_r_type = fixP->fx_size == 4 ? R_H8500_IMM32 : R_H8500_IMM16; |
1435 | } | |
1436 | ||
1437 | switch (fixP->fx_r_type) | |
1438 | { | |
1439 | ||
1440 | case R_H8500_IMM8: | |
1441 | case R_H8500_PCREL8: | |
033400ec SC |
1442 | *buf++ = val; |
1443 | break; | |
10a3e374 SC |
1444 | case R_H8500_IMM16: |
1445 | case R_H8500_LOW16: | |
1446 | case R_H8500_PCREL16: | |
033400ec SC |
1447 | *buf++ = (val >> 8); |
1448 | *buf++ = val; | |
1449 | break; | |
10a3e374 SC |
1450 | case R_H8500_HIGH8: |
1451 | *buf++ = val >> 16; | |
1452 | break; | |
489a93f3 SC |
1453 | case R_H8500_HIGH16: |
1454 | *buf++ = val >> 24; | |
1455 | *buf++ = val >> 16; | |
1456 | break; | |
10a3e374 SC |
1457 | case R_H8500_IMM24: |
1458 | *buf++ = (val >> 16); | |
1459 | *buf++ = (val >> 8); | |
1460 | *buf++ = val; | |
1461 | break; | |
1462 | case R_H8500_IMM32: | |
033400ec SC |
1463 | *buf++ = (val >> 24); |
1464 | *buf++ = (val >> 16); | |
1465 | *buf++ = (val >> 8); | |
1466 | *buf++ = val; | |
1467 | break; | |
1468 | default: | |
1469 | abort (); | |
1470 | ||
1471 | } | |
1472 | } | |
1473 | ||
1474 | void | |
1475 | DEFUN (md_operand, (expressionP), expressionS * expressionP) | |
1476 | { | |
1477 | } | |
1478 | ||
1479 | int md_long_jump_size; | |
1480 | ||
1481 | /* | |
1482 | called just before address relaxation, return the length | |
1483 | by which a fragment must grow to reach it's destination | |
1484 | */ | |
1485 | int | |
1486 | md_estimate_size_before_relax (fragP, segment_type) | |
1487 | register fragS *fragP; | |
1488 | register segT segment_type; | |
1489 | { | |
033400ec SC |
1490 | int what = GET_WHAT (fragP->fr_subtype); |
1491 | ||
1492 | switch (fragP->fr_subtype) | |
1493 | { | |
10a3e374 SC |
1494 | default: |
1495 | abort (); | |
033400ec SC |
1496 | case C (BRANCH, UNDEF_BYTE_DISP): |
1497 | case C (SCB_F, UNDEF_BYTE_DISP): | |
1498 | case C (SCB_TST, UNDEF_BYTE_DISP): | |
1499 | /* used to be a branch to somewhere which was unknown */ | |
1500 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
1501 | { | |
1502 | /* Got a symbol and it's defined in this segment, become byte | |
1503 | sized - maybe it will fix up */ | |
1504 | fragP->fr_subtype = C (what, BYTE_DISP); | |
10a3e374 | 1505 | fragP->fr_var = md_relax_table[C (what, BYTE_DISP)].rlx_length; |
033400ec SC |
1506 | } |
1507 | else | |
1508 | { | |
1509 | /* Its got a segment, but its not ours, so it will always be long */ | |
1510 | fragP->fr_subtype = C (what, UNDEF_WORD_DISP); | |
10a3e374 SC |
1511 | fragP->fr_var = md_relax_table[C (what, WORD_DISP)].rlx_length; |
1512 | return md_relax_table[C (what, WORD_DISP)].rlx_length; | |
033400ec SC |
1513 | } |
1514 | } | |
10a3e374 | 1515 | return fragP->fr_var; |
033400ec SC |
1516 | } |
1517 | ||
1518 | /* Put number into target byte order */ | |
1519 | ||
1520 | void | |
1521 | md_number_to_chars (ptr, use, nbytes) | |
1522 | char *ptr; | |
025b0302 | 1523 | valueT use; |
033400ec SC |
1524 | int nbytes; |
1525 | { | |
1526 | switch (nbytes) | |
1527 | { | |
1528 | case 4: | |
1529 | *ptr++ = (use >> 24) & 0xff; | |
1530 | case 3: | |
1531 | *ptr++ = (use >> 16) & 0xff; | |
1532 | case 2: | |
1533 | *ptr++ = (use >> 8) & 0xff; | |
1534 | case 1: | |
1535 | *ptr++ = (use >> 0) & 0xff; | |
1536 | break; | |
1537 | default: | |
1538 | abort (); | |
1539 | } | |
1540 | } | |
1541 | long | |
1542 | md_pcrel_from (fixP) | |
1543 | fixS *fixP; | |
1544 | ||
1545 | { | |
1546 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; | |
1547 | } | |
1548 | ||
1549 | void | |
1550 | tc_coff_symbol_emit_hook () | |
1551 | { | |
1552 | } | |
1553 | ||
10a3e374 SC |
1554 | short |
1555 | tc_coff_fix2rtype (fix_ptr) | |
1556 | fixS *fix_ptr; | |
1557 | { | |
1558 | if (fix_ptr->fx_r_type == RELOC_32) | |
1559 | { | |
1560 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
1561 | */ | |
1562 | switch (fix_ptr->fx_size) | |
1563 | { | |
1564 | case 2: | |
1565 | return R_H8500_IMM16; | |
1566 | break; | |
1567 | case 1: | |
1568 | return R_H8500_IMM8; | |
1569 | break; | |
1570 | default: | |
1571 | abort (); | |
1572 | } | |
1573 | } | |
1574 | return fix_ptr->fx_r_type; | |
1575 | } | |
1576 | ||
033400ec SC |
1577 | void |
1578 | tc_reloc_mangle (fix_ptr, intr, base) | |
1579 | fixS *fix_ptr; | |
1580 | struct internal_reloc *intr; | |
1581 | bfd_vma base; | |
1582 | ||
1583 | { | |
1584 | symbolS *symbol_ptr; | |
1585 | ||
1586 | symbol_ptr = fix_ptr->fx_addsy; | |
1587 | ||
1588 | /* If this relocation is attached to a symbol then it's ok | |
1589 | to output it */ | |
1590 | if (fix_ptr->fx_r_type == RELOC_32) | |
1591 | { | |
1592 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
1593 | */ | |
1594 | switch (fix_ptr->fx_size) | |
1595 | { | |
1596 | case 2: | |
1597 | intr->r_type = R_IMM16; | |
1598 | break; | |
1599 | case 1: | |
1600 | intr->r_type = R_IMM8; | |
1601 | break; | |
1602 | default: | |
1603 | abort (); | |
1604 | } | |
1605 | } | |
1606 | else | |
1607 | { | |
1608 | intr->r_type = fix_ptr->fx_r_type; | |
1609 | } | |
1610 | ||
1611 | intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base; | |
1612 | intr->r_offset = fix_ptr->fx_offset; | |
1613 | ||
10a3e374 | 1614 | /* Turn the segment of the symbol into an offset. */ |
033400ec | 1615 | if (symbol_ptr) |
10a3e374 SC |
1616 | { |
1617 | symbolS *dot; | |
1618 | ||
1619 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot; | |
1620 | if (dot) | |
1621 | { | |
1622 | /* intr->r_offset -= | |
1623 | segment_info[S_GET_SEGMENT(symbol_ptr)].scnhdr.s_paddr;*/ | |
1624 | intr->r_offset += S_GET_VALUE (symbol_ptr); | |
1625 | intr->r_symndx = dot->sy_number; | |
1626 | } | |
1627 | else | |
1628 | { | |
1629 | intr->r_symndx = symbol_ptr->sy_number; | |
1630 | } | |
1631 | ||
1632 | } | |
033400ec | 1633 | else |
10a3e374 SC |
1634 | { |
1635 | intr->r_symndx = -1; | |
1636 | } | |
033400ec SC |
1637 | |
1638 | } | |
1639 | ||
1f55e556 | 1640 | |
10a3e374 SC |
1641 | |
1642 | int | |
1643 | start_label (ptr) | |
1644 | char *ptr; | |
1645 | { | |
1646 | /* Check for :s.w */ | |
1647 | if (isalpha (ptr[1]) && ptr[2] == '.') | |
1648 | return 0; | |
1649 | /* Check for :s */ | |
1650 | if (isalpha (ptr[1]) && !isalpha (ptr[2])) | |
1651 | return 0; | |
1652 | return 1; | |
1653 | } | |
1f55e556 SC |
1654 | |
1655 | /* end of tc-h8500.c */ |