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