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