Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mn10300.c -- Assembler code for the Matsushita 10300 |
310b5aa2 | 2 | Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation. |
252b5132 RH |
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, 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <ctype.h> | |
23 | #include "as.h" | |
24 | #include "subsegs.h" | |
25 | #include "opcode/mn10300.h" | |
26 | \f | |
27 | /* Structure to hold information about predefined registers. */ | |
28 | struct reg_name | |
29 | { | |
30 | const char *name; | |
31 | int value; | |
32 | }; | |
33 | ||
34 | /* Generic assembler global variables which must be defined by all targets. */ | |
35 | ||
36 | /* Characters which always start a comment. */ | |
37 | const char comment_chars[] = "#"; | |
38 | ||
39 | /* Characters which start a comment at the beginning of a line. */ | |
40 | const char line_comment_chars[] = ";#"; | |
41 | ||
42 | /* Characters which may be used to separate multiple commands on a | |
43 | single line. */ | |
44 | const char line_separator_chars[] = ";"; | |
45 | ||
46 | /* Characters which are used to indicate an exponent in a floating | |
47 | point number. */ | |
48 | const char EXP_CHARS[] = "eE"; | |
49 | ||
50 | /* Characters which mean that a number is a floating point constant, | |
51 | as in 0d1.0. */ | |
52 | const char FLT_CHARS[] = "dD"; | |
53 | \f | |
54 | ||
55 | const relax_typeS md_relax_table[] = { | |
56 | /* bCC relaxing */ | |
57 | {0x7f, -0x80, 2, 1}, | |
58 | {0x7fff, -0x8000, 5, 2}, | |
59 | {0x7fffffff, -0x80000000, 7, 0}, | |
60 | ||
61 | /* bCC relaxing (uncommon cases) */ | |
62 | {0x7f, -0x80, 3, 4}, | |
63 | {0x7fff, -0x8000, 6, 5}, | |
64 | {0x7fffffff, -0x80000000, 8, 0}, | |
65 | ||
66 | /* call relaxing */ | |
67 | {0x7fff, -0x8000, 5, 7}, | |
68 | {0x7fffffff, -0x80000000, 7, 0}, | |
69 | ||
70 | /* calls relaxing */ | |
71 | {0x7fff, -0x8000, 4, 9}, | |
72 | {0x7fffffff, -0x80000000, 6, 0}, | |
73 | ||
74 | /* jmp relaxing */ | |
75 | {0x7f, -0x80, 2, 11}, | |
76 | {0x7fff, -0x8000, 3, 12}, | |
77 | {0x7fffffff, -0x80000000, 5, 0}, | |
78 | ||
79 | }; | |
80 | ||
81 | /* local functions */ | |
82 | static void mn10300_insert_operand PARAMS ((unsigned long *, unsigned long *, | |
83 | const struct mn10300_operand *, | |
84 | offsetT, char *, unsigned, | |
85 | unsigned)); | |
86 | static unsigned long check_operand PARAMS ((unsigned long, | |
87 | const struct mn10300_operand *, | |
88 | offsetT)); | |
89 | static int reg_name_search PARAMS ((const struct reg_name *, int, const char *)); | |
90 | static boolean data_register_name PARAMS ((expressionS *expressionP)); | |
91 | static boolean address_register_name PARAMS ((expressionS *expressionP)); | |
92 | static boolean other_register_name PARAMS ((expressionS *expressionP)); | |
93 | static void set_arch_mach PARAMS ((int)); | |
94 | ||
95 | static int current_machine; | |
96 | ||
97 | /* fixups */ | |
98 | #define MAX_INSN_FIXUPS (5) | |
99 | struct mn10300_fixup | |
100 | { | |
101 | expressionS exp; | |
102 | int opindex; | |
103 | bfd_reloc_code_real_type reloc; | |
104 | }; | |
105 | struct mn10300_fixup fixups[MAX_INSN_FIXUPS]; | |
106 | static int fc; | |
107 | ||
108 | /* We must store the value of each register operand so that we can | |
109 | verify that certain registers do not match. */ | |
110 | int mn10300_reg_operands[MN10300_MAX_OPERANDS]; | |
111 | \f | |
112 | const char *md_shortopts = ""; | |
113 | struct option md_longopts[] = { | |
114 | {NULL, no_argument, NULL, 0} | |
115 | }; | |
116 | size_t md_longopts_size = sizeof(md_longopts); | |
117 | ||
118 | /* The target specific pseudo-ops which we support. */ | |
119 | const pseudo_typeS md_pseudo_table[] = | |
120 | { | |
121 | { "am30", set_arch_mach, 300 }, | |
85cb2cf9 | 122 | { "am33", set_arch_mach, 330 }, |
252b5132 RH |
123 | { "mn10300", set_arch_mach, 300 }, |
124 | {NULL, 0, 0} | |
125 | }; | |
126 | ||
127 | /* Opcode hash table. */ | |
128 | static struct hash_control *mn10300_hash; | |
129 | ||
130 | /* This table is sorted. Suitable for searching by a binary search. */ | |
131 | static const struct reg_name data_registers[] = | |
132 | { | |
133 | { "d0", 0 }, | |
134 | { "d1", 1 }, | |
135 | { "d2", 2 }, | |
136 | { "d3", 3 }, | |
137 | }; | |
138 | #define DATA_REG_NAME_CNT (sizeof(data_registers) / sizeof(struct reg_name)) | |
139 | ||
140 | static const struct reg_name address_registers[] = | |
141 | { | |
142 | { "a0", 0 }, | |
143 | { "a1", 1 }, | |
144 | { "a2", 2 }, | |
145 | { "a3", 3 }, | |
146 | }; | |
147 | #define ADDRESS_REG_NAME_CNT (sizeof(address_registers) / sizeof(struct reg_name)) | |
148 | ||
85cb2cf9 JL |
149 | static const struct reg_name r_registers[] = |
150 | { | |
151 | { "a0", 8 }, | |
152 | { "a1", 9 }, | |
153 | { "a2", 10 }, | |
154 | { "a3", 11 }, | |
155 | { "d0", 12 }, | |
156 | { "d1", 13 }, | |
157 | { "d2", 14 }, | |
158 | { "d3", 15 }, | |
159 | { "e0", 0 }, | |
160 | { "e1", 1 }, | |
161 | { "e10", 10 }, | |
162 | { "e11", 11 }, | |
163 | { "e12", 12 }, | |
164 | { "e13", 13 }, | |
165 | { "e14", 14 }, | |
166 | { "e15", 15 }, | |
167 | { "e2", 2 }, | |
168 | { "e3", 3 }, | |
169 | { "e4", 4 }, | |
170 | { "e5", 5 }, | |
171 | { "e6", 6 }, | |
172 | { "e7", 7 }, | |
173 | { "e8", 8 }, | |
174 | { "e9", 9 }, | |
175 | { "r0", 0 }, | |
176 | { "r1", 1 }, | |
177 | { "r10", 10 }, | |
178 | { "r11", 11 }, | |
179 | { "r12", 12 }, | |
180 | { "r13", 13 }, | |
181 | { "r14", 14 }, | |
182 | { "r15", 15 }, | |
183 | { "r2", 2 }, | |
184 | { "r3", 3 }, | |
185 | { "r4", 4 }, | |
186 | { "r5", 5 }, | |
187 | { "r6", 6 }, | |
188 | { "r7", 7 }, | |
189 | { "r8", 8 }, | |
190 | { "r9", 9 }, | |
191 | }; | |
192 | #define R_REG_NAME_CNT (sizeof(r_registers) / sizeof(struct reg_name)) | |
193 | ||
194 | static const struct reg_name xr_registers[] = | |
195 | { | |
196 | { "mcrh", 2 }, | |
197 | { "mcrl", 3 }, | |
198 | { "mcvf", 4 }, | |
199 | { "mdrq", 1 }, | |
200 | { "sp", 0 }, | |
201 | { "xr0", 0 }, | |
202 | { "xr1", 1 }, | |
203 | { "xr10", 10 }, | |
204 | { "xr11", 11 }, | |
205 | { "xr12", 12 }, | |
206 | { "xr13", 13 }, | |
207 | { "xr14", 14 }, | |
208 | { "xr15", 15 }, | |
209 | { "xr2", 2 }, | |
210 | { "xr3", 3 }, | |
211 | { "xr4", 4 }, | |
212 | { "xr5", 5 }, | |
213 | { "xr6", 6 }, | |
214 | { "xr7", 7 }, | |
215 | { "xr8", 8 }, | |
216 | { "xr9", 9 }, | |
217 | }; | |
218 | #define XR_REG_NAME_CNT (sizeof(xr_registers) / sizeof(struct reg_name)) | |
219 | ||
252b5132 RH |
220 | |
221 | static const struct reg_name other_registers[] = | |
222 | { | |
223 | { "mdr", 0 }, | |
224 | { "psw", 0 }, | |
225 | { "sp", 0 }, | |
226 | }; | |
227 | #define OTHER_REG_NAME_CNT (sizeof(other_registers) / sizeof(struct reg_name)) | |
228 | ||
229 | /* reg_name_search does a binary search of the given register table | |
230 | to see if "name" is a valid regiter name. Returns the register | |
231 | number from the array on success, or -1 on failure. */ | |
232 | ||
233 | static int | |
234 | reg_name_search (regs, regcount, name) | |
235 | const struct reg_name *regs; | |
236 | int regcount; | |
237 | const char *name; | |
238 | { | |
239 | int middle, low, high; | |
240 | int cmp; | |
241 | ||
242 | low = 0; | |
243 | high = regcount - 1; | |
244 | ||
245 | do | |
246 | { | |
247 | middle = (low + high) / 2; | |
248 | cmp = strcasecmp (name, regs[middle].name); | |
249 | if (cmp < 0) | |
250 | high = middle - 1; | |
251 | else if (cmp > 0) | |
252 | low = middle + 1; | |
253 | else | |
254 | return regs[middle].value; | |
255 | } | |
256 | while (low <= high); | |
257 | return -1; | |
258 | } | |
259 | ||
260 | ||
85cb2cf9 JL |
261 | /* Summary of register_name(). |
262 | * | |
263 | * in: Input_line_pointer points to 1st char of operand. | |
264 | * | |
265 | * out: A expressionS. | |
266 | * The operand may have been a register: in this case, X_op == O_register, | |
267 | * X_add_number is set to the register number, and truth is returned. | |
268 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
269 | * its original state. | |
270 | */ | |
271 | static boolean | |
272 | r_register_name (expressionP) | |
273 | expressionS *expressionP; | |
274 | { | |
275 | int reg_number; | |
276 | char *name; | |
277 | char *start; | |
278 | char c; | |
279 | ||
280 | /* Find the spelling of the operand */ | |
281 | start = name = input_line_pointer; | |
282 | ||
283 | c = get_symbol_end (); | |
284 | reg_number = reg_name_search (r_registers, R_REG_NAME_CNT, name); | |
285 | ||
286 | /* look to see if it's in the register table */ | |
287 | if (reg_number >= 0) | |
288 | { | |
289 | expressionP->X_op = O_register; | |
290 | expressionP->X_add_number = reg_number; | |
291 | ||
292 | /* make the rest nice */ | |
293 | expressionP->X_add_symbol = NULL; | |
294 | expressionP->X_op_symbol = NULL; | |
295 | *input_line_pointer = c; /* put back the delimiting char */ | |
296 | return true; | |
297 | } | |
298 | else | |
299 | { | |
300 | /* reset the line as if we had not done anything */ | |
301 | *input_line_pointer = c; /* put back the delimiting char */ | |
302 | input_line_pointer = start; /* reset input_line pointer */ | |
303 | return false; | |
304 | } | |
305 | } | |
306 | ||
307 | /* Summary of register_name(). | |
308 | * | |
309 | * in: Input_line_pointer points to 1st char of operand. | |
310 | * | |
311 | * out: A expressionS. | |
312 | * The operand may have been a register: in this case, X_op == O_register, | |
313 | * X_add_number is set to the register number, and truth is returned. | |
314 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
315 | * its original state. | |
316 | */ | |
317 | static boolean | |
318 | xr_register_name (expressionP) | |
319 | expressionS *expressionP; | |
320 | { | |
321 | int reg_number; | |
322 | char *name; | |
323 | char *start; | |
324 | char c; | |
325 | ||
326 | /* Find the spelling of the operand */ | |
327 | start = name = input_line_pointer; | |
328 | ||
329 | c = get_symbol_end (); | |
330 | reg_number = reg_name_search (xr_registers, XR_REG_NAME_CNT, name); | |
331 | ||
332 | /* look to see if it's in the register table */ | |
333 | if (reg_number >= 0) | |
334 | { | |
335 | expressionP->X_op = O_register; | |
336 | expressionP->X_add_number = reg_number; | |
337 | ||
338 | /* make the rest nice */ | |
339 | expressionP->X_add_symbol = NULL; | |
340 | expressionP->X_op_symbol = NULL; | |
341 | *input_line_pointer = c; /* put back the delimiting char */ | |
342 | return true; | |
343 | } | |
344 | else | |
345 | { | |
346 | /* reset the line as if we had not done anything */ | |
347 | *input_line_pointer = c; /* put back the delimiting char */ | |
348 | input_line_pointer = start; /* reset input_line pointer */ | |
349 | return false; | |
350 | } | |
351 | } | |
252b5132 RH |
352 | |
353 | /* Summary of register_name(). | |
354 | * | |
355 | * in: Input_line_pointer points to 1st char of operand. | |
356 | * | |
357 | * out: A expressionS. | |
358 | * The operand may have been a register: in this case, X_op == O_register, | |
359 | * X_add_number is set to the register number, and truth is returned. | |
360 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
361 | * its original state. | |
362 | */ | |
363 | static boolean | |
364 | data_register_name (expressionP) | |
365 | expressionS *expressionP; | |
366 | { | |
367 | int reg_number; | |
368 | char *name; | |
369 | char *start; | |
370 | char c; | |
371 | ||
372 | /* Find the spelling of the operand */ | |
373 | start = name = input_line_pointer; | |
374 | ||
375 | c = get_symbol_end (); | |
376 | reg_number = reg_name_search (data_registers, DATA_REG_NAME_CNT, name); | |
377 | ||
378 | /* look to see if it's in the register table */ | |
379 | if (reg_number >= 0) | |
380 | { | |
381 | expressionP->X_op = O_register; | |
382 | expressionP->X_add_number = reg_number; | |
383 | ||
384 | /* make the rest nice */ | |
385 | expressionP->X_add_symbol = NULL; | |
386 | expressionP->X_op_symbol = NULL; | |
387 | *input_line_pointer = c; /* put back the delimiting char */ | |
388 | return true; | |
389 | } | |
390 | else | |
391 | { | |
392 | /* reset the line as if we had not done anything */ | |
393 | *input_line_pointer = c; /* put back the delimiting char */ | |
394 | input_line_pointer = start; /* reset input_line pointer */ | |
395 | return false; | |
396 | } | |
397 | } | |
398 | ||
399 | /* Summary of register_name(). | |
400 | * | |
401 | * in: Input_line_pointer points to 1st char of operand. | |
402 | * | |
403 | * out: A expressionS. | |
404 | * The operand may have been a register: in this case, X_op == O_register, | |
405 | * X_add_number is set to the register number, and truth is returned. | |
406 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
407 | * its original state. | |
408 | */ | |
409 | static boolean | |
410 | address_register_name (expressionP) | |
411 | expressionS *expressionP; | |
412 | { | |
413 | int reg_number; | |
414 | char *name; | |
415 | char *start; | |
416 | char c; | |
417 | ||
418 | /* Find the spelling of the operand */ | |
419 | start = name = input_line_pointer; | |
420 | ||
421 | c = get_symbol_end (); | |
422 | reg_number = reg_name_search (address_registers, ADDRESS_REG_NAME_CNT, name); | |
423 | ||
424 | /* look to see if it's in the register table */ | |
425 | if (reg_number >= 0) | |
426 | { | |
427 | expressionP->X_op = O_register; | |
428 | expressionP->X_add_number = reg_number; | |
429 | ||
430 | /* make the rest nice */ | |
431 | expressionP->X_add_symbol = NULL; | |
432 | expressionP->X_op_symbol = NULL; | |
433 | *input_line_pointer = c; /* put back the delimiting char */ | |
434 | return true; | |
435 | } | |
436 | else | |
437 | { | |
438 | /* reset the line as if we had not done anything */ | |
439 | *input_line_pointer = c; /* put back the delimiting char */ | |
440 | input_line_pointer = start; /* reset input_line pointer */ | |
441 | return false; | |
442 | } | |
443 | } | |
444 | ||
445 | /* Summary of register_name(). | |
446 | * | |
447 | * in: Input_line_pointer points to 1st char of operand. | |
448 | * | |
449 | * out: A expressionS. | |
450 | * The operand may have been a register: in this case, X_op == O_register, | |
451 | * X_add_number is set to the register number, and truth is returned. | |
452 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
453 | * its original state. | |
454 | */ | |
455 | static boolean | |
456 | other_register_name (expressionP) | |
457 | expressionS *expressionP; | |
458 | { | |
459 | int reg_number; | |
460 | char *name; | |
461 | char *start; | |
462 | char c; | |
463 | ||
464 | /* Find the spelling of the operand */ | |
465 | start = name = input_line_pointer; | |
466 | ||
467 | c = get_symbol_end (); | |
468 | reg_number = reg_name_search (other_registers, OTHER_REG_NAME_CNT, name); | |
469 | ||
470 | /* look to see if it's in the register table */ | |
471 | if (reg_number >= 0) | |
472 | { | |
473 | expressionP->X_op = O_register; | |
474 | expressionP->X_add_number = reg_number; | |
475 | ||
476 | /* make the rest nice */ | |
477 | expressionP->X_add_symbol = NULL; | |
478 | expressionP->X_op_symbol = NULL; | |
479 | *input_line_pointer = c; /* put back the delimiting char */ | |
480 | return true; | |
481 | } | |
482 | else | |
483 | { | |
484 | /* reset the line as if we had not done anything */ | |
485 | *input_line_pointer = c; /* put back the delimiting char */ | |
486 | input_line_pointer = start; /* reset input_line pointer */ | |
487 | return false; | |
488 | } | |
489 | } | |
490 | ||
491 | void | |
492 | md_show_usage (stream) | |
493 | FILE *stream; | |
494 | { | |
495 | fprintf(stream, _("MN10300 options:\n\ | |
496 | none yet\n")); | |
497 | } | |
498 | ||
499 | int | |
500 | md_parse_option (c, arg) | |
501 | int c; | |
502 | char *arg; | |
503 | { | |
504 | return 0; | |
505 | } | |
506 | ||
507 | symbolS * | |
508 | md_undefined_symbol (name) | |
509 | char *name; | |
510 | { | |
511 | return 0; | |
512 | } | |
513 | ||
514 | char * | |
515 | md_atof (type, litp, sizep) | |
516 | int type; | |
517 | char *litp; | |
518 | int *sizep; | |
519 | { | |
520 | int prec; | |
521 | LITTLENUM_TYPE words[4]; | |
522 | char *t; | |
523 | int i; | |
524 | ||
525 | switch (type) | |
526 | { | |
527 | case 'f': | |
528 | prec = 2; | |
529 | break; | |
530 | ||
531 | case 'd': | |
532 | prec = 4; | |
533 | break; | |
534 | ||
535 | default: | |
536 | *sizep = 0; | |
537 | return "bad call to md_atof"; | |
538 | } | |
539 | ||
540 | t = atof_ieee (input_line_pointer, type, words); | |
541 | if (t) | |
542 | input_line_pointer = t; | |
543 | ||
544 | *sizep = prec * 2; | |
545 | ||
546 | for (i = prec - 1; i >= 0; i--) | |
547 | { | |
548 | md_number_to_chars (litp, (valueT) words[i], 2); | |
549 | litp += 2; | |
550 | } | |
551 | ||
552 | return NULL; | |
553 | } | |
554 | ||
555 | ||
556 | void | |
557 | md_convert_frag (abfd, sec, fragP) | |
558 | bfd *abfd; | |
559 | asection *sec; | |
560 | fragS *fragP; | |
561 | { | |
562 | static unsigned long label_count = 0; | |
563 | char buf[40]; | |
564 | ||
565 | subseg_change (sec, 0); | |
566 | if (fragP->fr_subtype == 0) | |
567 | { | |
568 | fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol, | |
569 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL); | |
570 | fragP->fr_var = 0; | |
571 | fragP->fr_fix += 2; | |
572 | } | |
573 | else if (fragP->fr_subtype == 1) | |
574 | { | |
575 | /* Reverse the condition of the first branch. */ | |
576 | int offset = fragP->fr_fix; | |
577 | int opcode = fragP->fr_literal[offset] & 0xff; | |
578 | ||
579 | switch (opcode) | |
580 | { | |
581 | case 0xc8: | |
582 | opcode = 0xc9; | |
583 | break; | |
584 | case 0xc9: | |
585 | opcode = 0xc8; | |
586 | break; | |
587 | case 0xc0: | |
588 | opcode = 0xc2; | |
589 | break; | |
590 | case 0xc2: | |
591 | opcode = 0xc0; | |
592 | break; | |
593 | case 0xc3: | |
594 | opcode = 0xc1; | |
595 | break; | |
596 | case 0xc1: | |
597 | opcode = 0xc3; | |
598 | break; | |
599 | case 0xc4: | |
600 | opcode = 0xc6; | |
601 | break; | |
602 | case 0xc6: | |
603 | opcode = 0xc4; | |
604 | break; | |
605 | case 0xc7: | |
606 | opcode = 0xc5; | |
607 | break; | |
608 | case 0xc5: | |
609 | opcode = 0xc7; | |
610 | break; | |
611 | default: | |
612 | abort (); | |
613 | } | |
614 | fragP->fr_literal[offset] = opcode; | |
615 | ||
616 | /* Create a fixup for the reversed conditional branch. */ | |
617 | sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++); | |
618 | fix_new (fragP, fragP->fr_fix + 1, 1, | |
619 | symbol_new (buf, sec, 0, fragP->fr_next), | |
620 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL); | |
621 | ||
622 | /* Now create the unconditional branch + fixup to the | |
623 | final target. */ | |
624 | fragP->fr_literal[offset + 2] = 0xcc; | |
625 | fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol, | |
626 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL); | |
627 | fragP->fr_var = 0; | |
628 | fragP->fr_fix += 5; | |
629 | } | |
630 | else if (fragP->fr_subtype == 2) | |
631 | { | |
632 | /* Reverse the condition of the first branch. */ | |
633 | int offset = fragP->fr_fix; | |
634 | int opcode = fragP->fr_literal[offset] & 0xff; | |
635 | ||
636 | switch (opcode) | |
637 | { | |
638 | case 0xc8: | |
639 | opcode = 0xc9; | |
640 | break; | |
641 | case 0xc9: | |
642 | opcode = 0xc8; | |
643 | break; | |
644 | case 0xc0: | |
645 | opcode = 0xc2; | |
646 | break; | |
647 | case 0xc2: | |
648 | opcode = 0xc0; | |
649 | break; | |
650 | case 0xc3: | |
651 | opcode = 0xc1; | |
652 | break; | |
653 | case 0xc1: | |
654 | opcode = 0xc3; | |
655 | break; | |
656 | case 0xc4: | |
657 | opcode = 0xc6; | |
658 | break; | |
659 | case 0xc6: | |
660 | opcode = 0xc4; | |
661 | break; | |
662 | case 0xc7: | |
663 | opcode = 0xc5; | |
664 | break; | |
665 | case 0xc5: | |
666 | opcode = 0xc7; | |
667 | break; | |
668 | default: | |
669 | abort (); | |
670 | } | |
671 | fragP->fr_literal[offset] = opcode; | |
672 | ||
673 | /* Create a fixup for the reversed conditional branch. */ | |
674 | sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++); | |
675 | fix_new (fragP, fragP->fr_fix + 1, 1, | |
676 | symbol_new (buf, sec, 0, fragP->fr_next), | |
677 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL); | |
678 | ||
679 | /* Now create the unconditional branch + fixup to the | |
680 | final target. */ | |
681 | fragP->fr_literal[offset + 2] = 0xdc; | |
682 | fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol, | |
683 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL); | |
684 | fragP->fr_var = 0; | |
685 | fragP->fr_fix += 7; | |
686 | } | |
687 | else if (fragP->fr_subtype == 3) | |
688 | { | |
689 | fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol, | |
690 | fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL); | |
691 | fragP->fr_var = 0; | |
692 | fragP->fr_fix += 3; | |
693 | } | |
694 | else if (fragP->fr_subtype == 4) | |
695 | { | |
696 | /* Reverse the condition of the first branch. */ | |
697 | int offset = fragP->fr_fix; | |
698 | int opcode = fragP->fr_literal[offset + 1] & 0xff; | |
699 | ||
700 | switch (opcode) | |
701 | { | |
702 | case 0xe8: | |
703 | opcode = 0xe9; | |
704 | break; | |
705 | case 0xe9: | |
706 | opcode = 0xe8; | |
707 | break; | |
708 | case 0xea: | |
709 | opcode = 0xeb; | |
710 | break; | |
711 | case 0xeb: | |
712 | opcode = 0xea; | |
713 | break; | |
714 | default: | |
715 | abort (); | |
716 | } | |
717 | fragP->fr_literal[offset + 1] = opcode; | |
718 | ||
719 | /* Create a fixup for the reversed conditional branch. */ | |
720 | sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++); | |
721 | fix_new (fragP, fragP->fr_fix + 2, 1, | |
722 | symbol_new (buf, sec, 0, fragP->fr_next), | |
723 | fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL); | |
724 | ||
725 | /* Now create the unconditional branch + fixup to the | |
726 | final target. */ | |
727 | fragP->fr_literal[offset + 3] = 0xcc; | |
728 | fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol, | |
729 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL); | |
730 | fragP->fr_var = 0; | |
731 | fragP->fr_fix += 6; | |
732 | } | |
733 | else if (fragP->fr_subtype == 5) | |
734 | { | |
735 | /* Reverse the condition of the first branch. */ | |
736 | int offset = fragP->fr_fix; | |
737 | int opcode = fragP->fr_literal[offset + 1] & 0xff; | |
738 | ||
739 | switch (opcode) | |
740 | { | |
741 | case 0xe8: | |
742 | opcode = 0xe9; | |
743 | break; | |
744 | case 0xea: | |
745 | opcode = 0xeb; | |
746 | break; | |
747 | case 0xeb: | |
748 | opcode = 0xea; | |
749 | break; | |
750 | default: | |
751 | abort (); | |
752 | } | |
753 | fragP->fr_literal[offset + 1] = opcode; | |
754 | ||
755 | /* Create a fixup for the reversed conditional branch. */ | |
756 | sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++); | |
757 | fix_new (fragP, fragP->fr_fix + 2, 1, | |
758 | symbol_new (buf, sec, 0, fragP->fr_next), | |
759 | fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL); | |
760 | ||
761 | /* Now create the unconditional branch + fixup to the | |
762 | final target. */ | |
763 | fragP->fr_literal[offset + 3] = 0xdc; | |
764 | fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol, | |
765 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL); | |
766 | fragP->fr_var = 0; | |
767 | fragP->fr_fix += 8; | |
768 | } | |
769 | else if (fragP->fr_subtype == 6) | |
770 | { | |
771 | int offset = fragP->fr_fix; | |
772 | fragP->fr_literal[offset] = 0xcd; | |
773 | fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol, | |
774 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL); | |
775 | fragP->fr_var = 0; | |
776 | fragP->fr_fix += 5; | |
777 | } | |
778 | else if (fragP->fr_subtype == 7) | |
779 | { | |
780 | int offset = fragP->fr_fix; | |
781 | fragP->fr_literal[offset] = 0xdd; | |
782 | fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3]; | |
783 | fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4]; | |
784 | ||
785 | fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol, | |
786 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL); | |
787 | fragP->fr_var = 0; | |
788 | fragP->fr_fix += 7; | |
789 | } | |
790 | else if (fragP->fr_subtype == 8) | |
791 | { | |
792 | int offset = fragP->fr_fix; | |
793 | fragP->fr_literal[offset] = 0xfa; | |
794 | fragP->fr_literal[offset + 1] = 0xff; | |
795 | fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol, | |
796 | fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL); | |
797 | fragP->fr_var = 0; | |
798 | fragP->fr_fix += 4; | |
799 | } | |
800 | else if (fragP->fr_subtype == 9) | |
801 | { | |
802 | int offset = fragP->fr_fix; | |
803 | fragP->fr_literal[offset] = 0xfc; | |
804 | fragP->fr_literal[offset + 1] = 0xff; | |
805 | ||
806 | fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol, | |
807 | fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL); | |
808 | fragP->fr_var = 0; | |
809 | fragP->fr_fix += 6; | |
810 | } | |
811 | else if (fragP->fr_subtype == 10) | |
812 | { | |
813 | fragP->fr_literal[fragP->fr_fix] = 0xca; | |
814 | fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol, | |
815 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL); | |
816 | fragP->fr_var = 0; | |
817 | fragP->fr_fix += 2; | |
818 | } | |
819 | else if (fragP->fr_subtype == 11) | |
820 | { | |
821 | int offset = fragP->fr_fix; | |
822 | fragP->fr_literal[offset] = 0xcc; | |
823 | ||
824 | fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol, | |
825 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL); | |
826 | fragP->fr_var = 0; | |
827 | fragP->fr_fix += 3; | |
828 | } | |
829 | else if (fragP->fr_subtype == 12) | |
830 | { | |
831 | int offset = fragP->fr_fix; | |
832 | fragP->fr_literal[offset] = 0xdc; | |
833 | ||
834 | fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol, | |
835 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL); | |
836 | fragP->fr_var = 0; | |
837 | fragP->fr_fix += 5; | |
838 | } | |
839 | else | |
840 | abort (); | |
841 | } | |
842 | ||
843 | valueT | |
844 | md_section_align (seg, addr) | |
845 | asection *seg; | |
846 | valueT addr; | |
847 | { | |
848 | int align = bfd_get_section_alignment (stdoutput, seg); | |
849 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
850 | } | |
851 | ||
852 | void | |
853 | md_begin () | |
854 | { | |
855 | char *prev_name = ""; | |
856 | register const struct mn10300_opcode *op; | |
857 | ||
858 | mn10300_hash = hash_new(); | |
859 | ||
860 | /* Insert unique names into hash table. The MN10300 instruction set | |
861 | has many identical opcode names that have different opcodes based | |
862 | on the operands. This hash table then provides a quick index to | |
863 | the first opcode with a particular name in the opcode table. */ | |
864 | ||
865 | op = mn10300_opcodes; | |
866 | while (op->name) | |
867 | { | |
868 | if (strcmp (prev_name, op->name)) | |
869 | { | |
870 | prev_name = (char *) op->name; | |
871 | hash_insert (mn10300_hash, op->name, (char *) op); | |
872 | } | |
873 | op++; | |
874 | } | |
875 | ||
876 | /* This is both a simplification (we don't have to write md_apply_fix) | |
877 | and support for future optimizations (branch shortening and similar | |
878 | stuff in the linker). */ | |
879 | linkrelax = 1; | |
880 | ||
881 | /* Set the default machine type. */ | |
882 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, 300)) | |
883 | as_warn (_("could not set architecture and machine")); | |
884 | ||
885 | current_machine = 300; | |
886 | } | |
887 | ||
888 | void | |
889 | md_assemble (str) | |
890 | char *str; | |
891 | { | |
892 | char *s; | |
893 | struct mn10300_opcode *opcode; | |
894 | struct mn10300_opcode *next_opcode; | |
895 | const unsigned char *opindex_ptr; | |
896 | int next_opindex, relaxable; | |
897 | unsigned long insn, extension, size = 0; | |
898 | char *f; | |
899 | int i; | |
900 | int match; | |
901 | ||
902 | /* Get the opcode. */ | |
903 | for (s = str; *s != '\0' && ! isspace (*s); s++) | |
904 | ; | |
905 | if (*s != '\0') | |
906 | *s++ = '\0'; | |
907 | ||
908 | /* find the first opcode with the proper name */ | |
909 | opcode = (struct mn10300_opcode *)hash_find (mn10300_hash, str); | |
910 | if (opcode == NULL) | |
911 | { | |
912 | as_bad (_("Unrecognized opcode: `%s'"), str); | |
913 | return; | |
914 | } | |
915 | ||
916 | str = s; | |
917 | while (isspace (*str)) | |
918 | ++str; | |
919 | ||
920 | input_line_pointer = str; | |
921 | ||
922 | for(;;) | |
923 | { | |
924 | const char *errmsg; | |
925 | int op_idx; | |
926 | char *hold; | |
927 | int extra_shift = 0; | |
928 | ||
929 | ||
930 | errmsg = _("Invalid opcode/operands"); | |
931 | ||
932 | /* Reset the array of register operands. */ | |
933 | memset (mn10300_reg_operands, -1, sizeof (mn10300_reg_operands)); | |
934 | ||
935 | relaxable = 0; | |
936 | fc = 0; | |
937 | match = 0; | |
938 | next_opindex = 0; | |
939 | insn = opcode->opcode; | |
940 | extension = 0; | |
941 | ||
942 | /* If the instruction is not available on the current machine | |
943 | then it can not possibly match. */ | |
944 | if (opcode->machine | |
945 | && (opcode->machine != current_machine)) | |
946 | goto error; | |
947 | ||
948 | for (op_idx = 1, opindex_ptr = opcode->operands; | |
949 | *opindex_ptr != 0; | |
950 | opindex_ptr++, op_idx++) | |
951 | { | |
952 | const struct mn10300_operand *operand; | |
953 | expressionS ex; | |
954 | ||
955 | if (next_opindex == 0) | |
956 | { | |
957 | operand = &mn10300_operands[*opindex_ptr]; | |
958 | } | |
959 | else | |
960 | { | |
961 | operand = &mn10300_operands[next_opindex]; | |
962 | next_opindex = 0; | |
963 | } | |
964 | ||
965 | while (*str == ' ' || *str == ',') | |
966 | ++str; | |
967 | ||
968 | if (operand->flags & MN10300_OPERAND_RELAX) | |
969 | relaxable = 1; | |
970 | ||
971 | /* Gather the operand. */ | |
972 | hold = input_line_pointer; | |
973 | input_line_pointer = str; | |
974 | ||
975 | if (operand->flags & MN10300_OPERAND_PAREN) | |
976 | { | |
977 | if (*input_line_pointer != ')' && *input_line_pointer != '(') | |
978 | { | |
979 | input_line_pointer = hold; | |
980 | str = hold; | |
981 | goto error; | |
982 | } | |
983 | input_line_pointer++; | |
984 | goto keep_going; | |
985 | } | |
986 | /* See if we can match the operands. */ | |
987 | else if (operand->flags & MN10300_OPERAND_DREG) | |
988 | { | |
989 | if (!data_register_name (&ex)) | |
990 | { | |
991 | input_line_pointer = hold; | |
992 | str = hold; | |
993 | goto error; | |
994 | } | |
995 | } | |
996 | else if (operand->flags & MN10300_OPERAND_AREG) | |
997 | { | |
998 | if (!address_register_name (&ex)) | |
999 | { | |
1000 | input_line_pointer = hold; | |
1001 | str = hold; | |
1002 | goto error; | |
1003 | } | |
1004 | } | |
1005 | else if (operand->flags & MN10300_OPERAND_SP) | |
1006 | { | |
1007 | char *start = input_line_pointer; | |
1008 | char c = get_symbol_end (); | |
1009 | ||
1010 | if (strcasecmp (start, "sp") != 0) | |
1011 | { | |
1012 | *input_line_pointer = c; | |
1013 | input_line_pointer = hold; | |
1014 | str = hold; | |
1015 | goto error; | |
1016 | } | |
1017 | *input_line_pointer = c; | |
1018 | goto keep_going; | |
1019 | } | |
85cb2cf9 JL |
1020 | else if (operand->flags & MN10300_OPERAND_RREG) |
1021 | { | |
1022 | if (!r_register_name (&ex)) | |
1023 | { | |
1024 | input_line_pointer = hold; | |
1025 | str = hold; | |
1026 | goto error; | |
1027 | } | |
1028 | } | |
1029 | else if (operand->flags & MN10300_OPERAND_XRREG) | |
1030 | { | |
1031 | if (!xr_register_name (&ex)) | |
1032 | { | |
1033 | input_line_pointer = hold; | |
1034 | str = hold; | |
1035 | goto error; | |
1036 | } | |
1037 | } | |
1038 | else if (operand->flags & MN10300_OPERAND_USP) | |
1039 | { | |
1040 | char *start = input_line_pointer; | |
1041 | char c = get_symbol_end (); | |
1042 | ||
1043 | if (strcasecmp (start, "usp") != 0) | |
1044 | { | |
1045 | *input_line_pointer = c; | |
1046 | input_line_pointer = hold; | |
1047 | str = hold; | |
1048 | goto error; | |
1049 | } | |
1050 | *input_line_pointer = c; | |
1051 | goto keep_going; | |
1052 | } | |
1053 | else if (operand->flags & MN10300_OPERAND_SSP) | |
1054 | { | |
1055 | char *start = input_line_pointer; | |
1056 | char c = get_symbol_end (); | |
1057 | ||
1058 | if (strcasecmp (start, "ssp") != 0) | |
1059 | { | |
1060 | *input_line_pointer = c; | |
1061 | input_line_pointer = hold; | |
1062 | str = hold; | |
1063 | goto error; | |
1064 | } | |
1065 | *input_line_pointer = c; | |
1066 | goto keep_going; | |
1067 | } | |
1068 | else if (operand->flags & MN10300_OPERAND_MSP) | |
1069 | { | |
1070 | char *start = input_line_pointer; | |
1071 | char c = get_symbol_end (); | |
1072 | ||
1073 | if (strcasecmp (start, "msp") != 0) | |
1074 | { | |
1075 | *input_line_pointer = c; | |
1076 | input_line_pointer = hold; | |
1077 | str = hold; | |
1078 | goto error; | |
1079 | } | |
1080 | *input_line_pointer = c; | |
1081 | goto keep_going; | |
1082 | } | |
1083 | else if (operand->flags & MN10300_OPERAND_PC) | |
1084 | { | |
1085 | char *start = input_line_pointer; | |
1086 | char c = get_symbol_end (); | |
1087 | ||
1088 | if (strcasecmp (start, "pc") != 0) | |
1089 | { | |
1090 | *input_line_pointer = c; | |
1091 | input_line_pointer = hold; | |
1092 | str = hold; | |
1093 | goto error; | |
1094 | } | |
1095 | *input_line_pointer = c; | |
1096 | goto keep_going; | |
1097 | } | |
1098 | else if (operand->flags & MN10300_OPERAND_EPSW) | |
1099 | { | |
1100 | char *start = input_line_pointer; | |
1101 | char c = get_symbol_end (); | |
1102 | ||
1103 | if (strcasecmp (start, "epsw") != 0) | |
1104 | { | |
1105 | *input_line_pointer = c; | |
1106 | input_line_pointer = hold; | |
1107 | str = hold; | |
1108 | goto error; | |
1109 | } | |
1110 | *input_line_pointer = c; | |
1111 | goto keep_going; | |
1112 | } | |
1113 | else if (operand->flags & MN10300_OPERAND_PLUS) | |
1114 | { | |
1115 | if (*input_line_pointer != '+') | |
1116 | { | |
1117 | input_line_pointer = hold; | |
1118 | str = hold; | |
1119 | goto error; | |
1120 | } | |
1121 | input_line_pointer++; | |
1122 | goto keep_going; | |
1123 | } | |
252b5132 RH |
1124 | else if (operand->flags & MN10300_OPERAND_PSW) |
1125 | { | |
1126 | char *start = input_line_pointer; | |
1127 | char c = get_symbol_end (); | |
1128 | ||
1129 | if (strcasecmp (start, "psw") != 0) | |
1130 | { | |
1131 | *input_line_pointer = c; | |
1132 | input_line_pointer = hold; | |
1133 | str = hold; | |
1134 | goto error; | |
1135 | } | |
1136 | *input_line_pointer = c; | |
1137 | goto keep_going; | |
1138 | } | |
1139 | else if (operand->flags & MN10300_OPERAND_MDR) | |
1140 | { | |
1141 | char *start = input_line_pointer; | |
1142 | char c = get_symbol_end (); | |
1143 | ||
1144 | if (strcasecmp (start, "mdr") != 0) | |
1145 | { | |
1146 | *input_line_pointer = c; | |
1147 | input_line_pointer = hold; | |
1148 | str = hold; | |
1149 | goto error; | |
1150 | } | |
1151 | *input_line_pointer = c; | |
1152 | goto keep_going; | |
1153 | } | |
1154 | else if (operand->flags & MN10300_OPERAND_REG_LIST) | |
1155 | { | |
1156 | unsigned int value = 0; | |
1157 | if (*input_line_pointer != '[') | |
1158 | { | |
1159 | input_line_pointer = hold; | |
1160 | str = hold; | |
1161 | goto error; | |
1162 | } | |
1163 | ||
1164 | /* Eat the '['. */ | |
1165 | input_line_pointer++; | |
1166 | ||
1167 | /* We used to reject a null register list here; however, | |
1168 | we accept it now so the compiler can emit "call" instructions | |
1169 | for all calls to named functions. | |
1170 | ||
1171 | The linker can then fill in the appropriate bits for the | |
1172 | register list and stack size or change the instruction | |
1173 | into a "calls" if using "call" is not profitable. */ | |
1174 | while (*input_line_pointer != ']') | |
1175 | { | |
1176 | char *start; | |
1177 | char c; | |
1178 | ||
1179 | if (*input_line_pointer == ',') | |
1180 | input_line_pointer++; | |
1181 | ||
1182 | start = input_line_pointer; | |
1183 | c = get_symbol_end (); | |
1184 | ||
1185 | if (strcasecmp (start, "d2") == 0) | |
1186 | { | |
1187 | value |= 0x80; | |
1188 | *input_line_pointer = c; | |
1189 | } | |
1190 | else if (strcasecmp (start, "d3") == 0) | |
1191 | { | |
1192 | value |= 0x40; | |
1193 | *input_line_pointer = c; | |
1194 | } | |
1195 | else if (strcasecmp (start, "a2") == 0) | |
1196 | { | |
1197 | value |= 0x20; | |
1198 | *input_line_pointer = c; | |
1199 | } | |
1200 | else if (strcasecmp (start, "a3") == 0) | |
1201 | { | |
1202 | value |= 0x10; | |
1203 | *input_line_pointer = c; | |
1204 | } | |
1205 | else if (strcasecmp (start, "other") == 0) | |
1206 | { | |
1207 | value |= 0x08; | |
1208 | *input_line_pointer = c; | |
1209 | } | |
85cb2cf9 JL |
1210 | else if (current_machine == 330 |
1211 | && strcasecmp (start, "exreg0") == 0) | |
1212 | { | |
1213 | value |= 0x04; | |
1214 | *input_line_pointer = c; | |
1215 | } | |
1216 | else if (current_machine == 330 | |
1217 | && strcasecmp (start, "exreg1") == 0) | |
1218 | { | |
1219 | value |= 0x02; | |
1220 | *input_line_pointer = c; | |
1221 | } | |
1222 | else if (current_machine == 330 | |
1223 | && strcasecmp (start, "exother") == 0) | |
1224 | { | |
1225 | value |= 0x01; | |
1226 | *input_line_pointer = c; | |
1227 | } | |
1228 | else if (current_machine == 330 | |
1229 | && strcasecmp (start, "all") == 0) | |
1230 | { | |
1231 | value |= 0xff; | |
1232 | *input_line_pointer = c; | |
1233 | } | |
252b5132 RH |
1234 | else |
1235 | { | |
1236 | input_line_pointer = hold; | |
1237 | str = hold; | |
1238 | goto error; | |
1239 | } | |
1240 | } | |
1241 | input_line_pointer++; | |
1242 | mn10300_insert_operand (&insn, &extension, operand, | |
1243 | value, (char *) NULL, 0, 0); | |
1244 | goto keep_going; | |
1245 | ||
1246 | } | |
1247 | else if (data_register_name (&ex)) | |
1248 | { | |
1249 | input_line_pointer = hold; | |
1250 | str = hold; | |
1251 | goto error; | |
1252 | } | |
1253 | else if (address_register_name (&ex)) | |
1254 | { | |
1255 | input_line_pointer = hold; | |
1256 | str = hold; | |
1257 | goto error; | |
1258 | } | |
1259 | else if (other_register_name (&ex)) | |
1260 | { | |
1261 | input_line_pointer = hold; | |
1262 | str = hold; | |
1263 | goto error; | |
1264 | } | |
85cb2cf9 JL |
1265 | else if (r_register_name (&ex)) |
1266 | { | |
1267 | input_line_pointer = hold; | |
1268 | str = hold; | |
1269 | goto error; | |
1270 | } | |
1271 | else if (xr_register_name (&ex)) | |
1272 | { | |
1273 | input_line_pointer = hold; | |
1274 | str = hold; | |
1275 | goto error; | |
1276 | } | |
252b5132 RH |
1277 | else if (*str == ')' || *str == '(') |
1278 | { | |
1279 | input_line_pointer = hold; | |
1280 | str = hold; | |
1281 | goto error; | |
1282 | } | |
1283 | else | |
1284 | { | |
1285 | expression (&ex); | |
1286 | } | |
1287 | ||
1288 | switch (ex.X_op) | |
1289 | { | |
1290 | case O_illegal: | |
1291 | errmsg = _("illegal operand"); | |
1292 | goto error; | |
1293 | case O_absent: | |
1294 | errmsg = _("missing operand"); | |
1295 | goto error; | |
1296 | case O_register: | |
1297 | { | |
1298 | int mask; | |
1299 | ||
1300 | mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG; | |
85cb2cf9 | 1301 | mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG; |
252b5132 RH |
1302 | if ((operand->flags & mask) == 0) |
1303 | { | |
1304 | input_line_pointer = hold; | |
1305 | str = hold; | |
1306 | goto error; | |
1307 | } | |
1308 | ||
1309 | if (opcode->format == FMT_D1 || opcode->format == FMT_S1) | |
1310 | extra_shift = 8; | |
1311 | else if (opcode->format == FMT_D2 | |
1312 | || opcode->format == FMT_D4 | |
1313 | || opcode->format == FMT_S2 | |
1314 | || opcode->format == FMT_S4 | |
1315 | || opcode->format == FMT_S6 | |
1316 | || opcode->format == FMT_D5) | |
1317 | extra_shift = 16; | |
85cb2cf9 JL |
1318 | else if (opcode->format == FMT_D7) |
1319 | extra_shift = 8; | |
1320 | else if (opcode->format == FMT_D8 || opcode->format == FMT_D9) | |
1321 | extra_shift = 8; | |
252b5132 RH |
1322 | else |
1323 | extra_shift = 0; | |
1324 | ||
1325 | mn10300_insert_operand (&insn, &extension, operand, | |
1326 | ex.X_add_number, (char *) NULL, | |
1327 | 0, extra_shift); | |
1328 | ||
1329 | ||
1330 | /* And note the register number in the register array. */ | |
1331 | mn10300_reg_operands[op_idx - 1] = ex.X_add_number; | |
1332 | break; | |
1333 | } | |
1334 | ||
1335 | case O_constant: | |
1336 | /* If this operand can be promoted, and it doesn't | |
1337 | fit into the allocated bitfield for this insn, | |
1338 | then promote it (ie this opcode does not match). */ | |
1339 | if (operand->flags | |
1340 | & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX) | |
1341 | && ! check_operand (insn, operand, ex.X_add_number)) | |
1342 | { | |
1343 | input_line_pointer = hold; | |
1344 | str = hold; | |
1345 | goto error; | |
1346 | } | |
1347 | ||
1348 | mn10300_insert_operand (&insn, &extension, operand, | |
1349 | ex.X_add_number, (char *) NULL, | |
1350 | 0, 0); | |
1351 | break; | |
1352 | ||
1353 | default: | |
1354 | /* If this operand can be promoted, then this opcode didn't | |
1355 | match since we can't know if it needed promotion! */ | |
1356 | if (operand->flags & MN10300_OPERAND_PROMOTE) | |
1357 | { | |
1358 | input_line_pointer = hold; | |
1359 | str = hold; | |
1360 | goto error; | |
1361 | } | |
1362 | ||
1363 | /* We need to generate a fixup for this expression. */ | |
1364 | if (fc >= MAX_INSN_FIXUPS) | |
1365 | as_fatal (_("too many fixups")); | |
1366 | fixups[fc].exp = ex; | |
1367 | fixups[fc].opindex = *opindex_ptr; | |
1368 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
1369 | ++fc; | |
1370 | break; | |
1371 | } | |
1372 | ||
1373 | keep_going: | |
1374 | str = input_line_pointer; | |
1375 | input_line_pointer = hold; | |
1376 | ||
1377 | while (*str == ' ' || *str == ',') | |
1378 | ++str; | |
1379 | ||
1380 | } | |
1381 | ||
1382 | /* Make sure we used all the operands! */ | |
1383 | if (*str != ',') | |
1384 | match = 1; | |
1385 | ||
1386 | /* If this instruction has registers that must not match, verify | |
1387 | that they do indeed not match. */ | |
1388 | if (opcode->no_match_operands) | |
1389 | { | |
1390 | int i; | |
1391 | ||
1392 | /* Look at each operand to see if it's marked. */ | |
1393 | for (i = 0; i < MN10300_MAX_OPERANDS; i++) | |
1394 | { | |
1395 | if ((1 << i) & opcode->no_match_operands) | |
1396 | { | |
1397 | int j; | |
1398 | ||
1399 | /* operand I is marked. Check that it does not match any | |
1400 | operands > I which are marked. */ | |
1401 | for (j = i + 1; j < MN10300_MAX_OPERANDS; j++) | |
1402 | { | |
1403 | if (((1 << j) & opcode->no_match_operands) | |
1404 | && mn10300_reg_operands[i] == mn10300_reg_operands[j]) | |
1405 | { | |
1406 | errmsg = _("Invalid register specification."); | |
1407 | match = 0; | |
1408 | goto error; | |
1409 | } | |
1410 | } | |
1411 | } | |
1412 | } | |
1413 | } | |
1414 | ||
1415 | error: | |
1416 | if (match == 0) | |
1417 | { | |
1418 | next_opcode = opcode + 1; | |
1419 | if (!strcmp(next_opcode->name, opcode->name)) | |
1420 | { | |
1421 | opcode = next_opcode; | |
1422 | continue; | |
1423 | } | |
1424 | ||
1425 | as_bad ("%s", errmsg); | |
1426 | return; | |
1427 | } | |
1428 | break; | |
1429 | } | |
1430 | ||
1431 | while (isspace (*str)) | |
1432 | ++str; | |
1433 | ||
1434 | if (*str != '\0') | |
1435 | as_bad (_("junk at end of line: `%s'"), str); | |
1436 | ||
1437 | input_line_pointer = str; | |
1438 | ||
1439 | /* Determine the size of the instruction. */ | |
1440 | if (opcode->format == FMT_S0) | |
1441 | size = 1; | |
1442 | ||
1443 | if (opcode->format == FMT_S1 || opcode->format == FMT_D0) | |
1444 | size = 2; | |
1445 | ||
1446 | if (opcode->format == FMT_S2 || opcode->format == FMT_D1) | |
1447 | size = 3; | |
1448 | ||
85cb2cf9 JL |
1449 | if (opcode->format == FMT_D6) |
1450 | size = 3; | |
1451 | ||
1452 | if (opcode->format == FMT_D7 || opcode->format == FMT_D10) | |
1453 | size = 4; | |
1454 | ||
1455 | if (opcode->format == FMT_D8) | |
1456 | size = 6; | |
1457 | ||
1458 | if (opcode->format == FMT_D9) | |
1459 | size = 7; | |
252b5132 RH |
1460 | |
1461 | if (opcode->format == FMT_S4) | |
1462 | size = 5; | |
1463 | ||
1464 | if (opcode->format == FMT_S6 || opcode->format == FMT_D5) | |
1465 | size = 7; | |
1466 | ||
1467 | if (opcode->format == FMT_D2) | |
1468 | size = 4; | |
1469 | ||
1470 | if (opcode->format == FMT_D4) | |
1471 | size = 6; | |
1472 | ||
1473 | if (relaxable && fc > 0) | |
1474 | { | |
1475 | int type; | |
1476 | ||
1477 | /* bCC */ | |
1478 | if (size == 2) | |
1479 | { | |
1480 | /* Handle bra specially. Basically treat it like jmp so | |
1481 | that we automatically handle 8, 16 and 32 bit offsets | |
1482 | correctly as well as jumps to an undefined address. | |
1483 | ||
1484 | It is also important to not treat it like other bCC | |
1485 | instructions since the long forms of bra is different | |
1486 | from other bCC instructions. */ | |
1487 | if (opcode->opcode == 0xca00) | |
1488 | type = 10; | |
1489 | else | |
1490 | type = 0; | |
1491 | } | |
1492 | /* call */ | |
1493 | else if (size == 5) | |
1494 | type = 6; | |
1495 | /* calls */ | |
1496 | else if (size == 4) | |
1497 | type = 8; | |
1498 | /* jmp */ | |
1499 | else if (size == 3 && opcode->opcode == 0xcc0000) | |
1500 | type = 10; | |
1501 | /* bCC (uncommon cases) */ | |
1502 | else | |
1503 | type = 3; | |
1504 | ||
1505 | f = frag_var (rs_machine_dependent, 8, 8 - size, type, | |
1506 | fixups[0].exp.X_add_symbol, | |
1507 | fixups[0].exp.X_add_number, | |
1508 | (char *)fixups[0].opindex); | |
1509 | ||
1510 | /* This is pretty hokey. We basically just care about the | |
1511 | opcode, so we have to write out the first word big endian. | |
1512 | ||
1513 | The exception is "call", which has two operands that we | |
1514 | care about. | |
1515 | ||
1516 | The first operand (the register list) happens to be in the | |
1517 | first instruction word, and will be in the right place if | |
1518 | we output the first word in big endian mode. | |
1519 | ||
1520 | The second operand (stack size) is in the extension word, | |
1521 | and we want it to appear as the first character in the extension | |
1522 | word (as it appears in memory). Luckily, writing the extension | |
1523 | word in big endian format will do what we want. */ | |
1524 | number_to_chars_bigendian (f, insn, size > 4 ? 4 : size); | |
1525 | if (size > 8) | |
1526 | { | |
1527 | number_to_chars_bigendian (f + 4, extension, 4); | |
1528 | number_to_chars_bigendian (f + 8, 0, size - 8); | |
1529 | } | |
1530 | else if (size > 4) | |
1531 | number_to_chars_bigendian (f + 4, extension, size - 4); | |
1532 | } | |
1533 | else | |
1534 | { | |
1535 | /* Allocate space for the instruction. */ | |
1536 | f = frag_more (size); | |
1537 | ||
1538 | /* Fill in bytes for the instruction. Note that opcode fields | |
1539 | are written big-endian, 16 & 32bit immediates are written | |
1540 | little endian. Egad. */ | |
1541 | if (opcode->format == FMT_S0 | |
1542 | || opcode->format == FMT_S1 | |
1543 | || opcode->format == FMT_D0 | |
85cb2cf9 JL |
1544 | || opcode->format == FMT_D6 |
1545 | || opcode->format == FMT_D7 | |
1546 | || opcode->format == FMT_D10 | |
252b5132 RH |
1547 | || opcode->format == FMT_D1) |
1548 | { | |
1549 | number_to_chars_bigendian (f, insn, size); | |
1550 | } | |
1551 | else if (opcode->format == FMT_S2 | |
1552 | && opcode->opcode != 0xdf0000 | |
1553 | && opcode->opcode != 0xde0000) | |
1554 | { | |
1555 | /* A format S2 instruction that is _not_ "ret" and "retf". */ | |
1556 | number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1); | |
1557 | number_to_chars_littleendian (f + 1, insn & 0xffff, 2); | |
1558 | } | |
1559 | else if (opcode->format == FMT_S2) | |
1560 | { | |
1561 | /* This must be a ret or retf, which is written entirely in | |
1562 | big-endian format. */ | |
1563 | number_to_chars_bigendian (f, insn, 3); | |
1564 | } | |
1565 | else if (opcode->format == FMT_S4 | |
1566 | && opcode->opcode != 0xdc000000) | |
1567 | { | |
1568 | /* This must be a format S4 "call" instruction. What a pain. */ | |
1569 | unsigned long temp = (insn >> 8) & 0xffff; | |
1570 | number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1); | |
1571 | number_to_chars_littleendian (f + 1, temp, 2); | |
1572 | number_to_chars_bigendian (f + 3, insn & 0xff, 1); | |
1573 | number_to_chars_bigendian (f + 4, extension & 0xff, 1); | |
1574 | } | |
1575 | else if (opcode->format == FMT_S4) | |
1576 | { | |
1577 | /* This must be a format S4 "jmp" instruction. */ | |
1578 | unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff); | |
1579 | number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1); | |
1580 | number_to_chars_littleendian (f + 1, temp, 4); | |
1581 | } | |
1582 | else if (opcode->format == FMT_S6) | |
1583 | { | |
1584 | unsigned long temp = ((insn & 0xffffff) << 8) | |
1585 | | ((extension >> 16) & 0xff); | |
1586 | number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1); | |
1587 | number_to_chars_littleendian (f + 1, temp, 4); | |
1588 | number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1); | |
1589 | number_to_chars_bigendian (f + 6, extension & 0xff, 1); | |
1590 | } | |
1591 | else if (opcode->format == FMT_D2 | |
1592 | && opcode->opcode != 0xfaf80000 | |
1593 | && opcode->opcode != 0xfaf00000 | |
1594 | && opcode->opcode != 0xfaf40000) | |
1595 | { | |
1596 | /* A format D2 instruction where the 16bit immediate is | |
1597 | really a single 16bit value, not two 8bit values. */ | |
1598 | number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2); | |
1599 | number_to_chars_littleendian (f + 2, insn & 0xffff, 2); | |
1600 | } | |
1601 | else if (opcode->format == FMT_D2) | |
1602 | { | |
1603 | /* A format D2 instruction where the 16bit immediate | |
1604 | is really two 8bit immediates. */ | |
1605 | number_to_chars_bigendian (f, insn, 4); | |
1606 | } | |
1607 | else if (opcode->format == FMT_D4) | |
1608 | { | |
1609 | unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff); | |
1610 | number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2); | |
1611 | number_to_chars_littleendian (f + 2, temp, 4); | |
1612 | } | |
1613 | else if (opcode->format == FMT_D5) | |
1614 | { | |
1615 | unsigned long temp = ((insn & 0xffff) << 16) | |
1616 | | ((extension >> 8) & 0xffff); | |
1617 | number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2); | |
1618 | number_to_chars_littleendian (f + 2, temp, 4); | |
1619 | number_to_chars_bigendian (f + 6, extension & 0xff, 1); | |
1620 | } | |
85cb2cf9 JL |
1621 | else if (opcode->format == FMT_D8) |
1622 | { | |
1623 | unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff); | |
1624 | number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3); | |
1625 | number_to_chars_bigendian (f + 3, (temp & 0xff), 1); | |
1626 | number_to_chars_littleendian (f + 4, temp >> 8, 2); | |
1627 | } | |
1628 | else if (opcode->format == FMT_D9) | |
1629 | { | |
1630 | unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff); | |
1631 | number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3); | |
1632 | number_to_chars_littleendian (f + 3, temp, 4); | |
1633 | } | |
252b5132 RH |
1634 | |
1635 | /* Create any fixups. */ | |
1636 | for (i = 0; i < fc; i++) | |
1637 | { | |
1638 | const struct mn10300_operand *operand; | |
1639 | ||
1640 | operand = &mn10300_operands[fixups[i].opindex]; | |
1641 | if (fixups[i].reloc != BFD_RELOC_UNUSED) | |
1642 | { | |
1643 | reloc_howto_type *reloc_howto; | |
1644 | int size; | |
1645 | int offset; | |
1646 | fixS *fixP; | |
1647 | ||
1648 | reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); | |
1649 | ||
1650 | if (!reloc_howto) | |
1651 | abort(); | |
1652 | ||
1653 | size = bfd_get_reloc_size (reloc_howto); | |
1654 | ||
1655 | if (size < 1 || size > 4) | |
1656 | abort(); | |
1657 | ||
1658 | offset = 4 - size; | |
1659 | fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, | |
1660 | size, &fixups[i].exp, | |
1661 | reloc_howto->pc_relative, | |
1662 | fixups[i].reloc); | |
1663 | } | |
1664 | else | |
1665 | { | |
1666 | int reloc, pcrel, reloc_size, offset; | |
1667 | fixS *fixP; | |
1668 | ||
1669 | reloc = BFD_RELOC_NONE; | |
1670 | /* How big is the reloc? Remember SPLIT relocs are | |
1671 | implicitly 32bits. */ | |
1672 | if ((operand->flags & MN10300_OPERAND_SPLIT) != 0) | |
1673 | reloc_size = 32; | |
85cb2cf9 JL |
1674 | else if ((operand->flags & MN10300_OPERAND_24BIT) != 0) |
1675 | reloc_size = 24; | |
252b5132 RH |
1676 | else |
1677 | reloc_size = operand->bits; | |
1678 | ||
1679 | /* Is the reloc pc-relative? */ | |
1680 | pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0; | |
1681 | ||
1682 | /* Gross. This disgusting hack is to make sure we | |
1683 | get the right offset for the 16/32 bit reloc in | |
1684 | "call" instructions. Basically they're a pain | |
1685 | because the reloc isn't at the end of the instruction. */ | |
1686 | if ((size == 5 || size == 7) | |
1687 | && (((insn >> 24) & 0xff) == 0xcd | |
1688 | || ((insn >> 24) & 0xff) == 0xdd)) | |
1689 | size -= 2; | |
1690 | ||
1691 | /* Similarly for certain bit instructions which don't | |
1692 | hav their 32bit reloc at the tail of the instruction. */ | |
1693 | if (size == 7 | |
1694 | && (((insn >> 16) & 0xffff) == 0xfe00 | |
1695 | || ((insn >> 16) & 0xffff) == 0xfe01 | |
1696 | || ((insn >> 16) & 0xffff) == 0xfe02)) | |
1697 | size -= 1; | |
1698 | ||
1699 | offset = size - reloc_size / 8; | |
1700 | ||
1701 | /* Choose a proper BFD relocation type. */ | |
1702 | if (pcrel) | |
1703 | { | |
1704 | if (reloc_size == 32) | |
1705 | reloc = BFD_RELOC_32_PCREL; | |
1706 | else if (reloc_size == 16) | |
1707 | reloc = BFD_RELOC_16_PCREL; | |
1708 | else if (reloc_size == 8) | |
1709 | reloc = BFD_RELOC_8_PCREL; | |
1710 | else | |
1711 | abort (); | |
1712 | } | |
1713 | else | |
1714 | { | |
1715 | if (reloc_size == 32) | |
1716 | reloc = BFD_RELOC_32; | |
1717 | else if (reloc_size == 16) | |
1718 | reloc = BFD_RELOC_16; | |
1719 | else if (reloc_size == 8) | |
1720 | reloc = BFD_RELOC_8; | |
1721 | else | |
1722 | abort (); | |
1723 | } | |
1724 | ||
1725 | /* Convert the size of the reloc into what fix_new_exp wants. */ | |
1726 | reloc_size = reloc_size / 8; | |
1727 | if (reloc_size == 8) | |
1728 | reloc_size = 0; | |
1729 | else if (reloc_size == 16) | |
1730 | reloc_size = 1; | |
1731 | else if (reloc_size == 32) | |
1732 | reloc_size = 2; | |
1733 | ||
1734 | fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, | |
1735 | reloc_size, &fixups[i].exp, pcrel, | |
1736 | ((bfd_reloc_code_real_type) reloc)); | |
1737 | ||
1738 | if (pcrel) | |
1739 | fixP->fx_offset += offset; | |
1740 | } | |
1741 | } | |
1742 | } | |
1743 | } | |
1744 | ||
1745 | ||
1746 | /* if while processing a fixup, a reloc really needs to be created */ | |
1747 | /* then it is done here */ | |
1748 | ||
1749 | arelent * | |
1750 | tc_gen_reloc (seg, fixp) | |
1751 | asection *seg; | |
1752 | fixS *fixp; | |
1753 | { | |
1754 | arelent *reloc; | |
1755 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
1756 | ||
1757 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
1758 | if (reloc->howto == (reloc_howto_type *) NULL) | |
1759 | { | |
1760 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1761 | _("reloc %d not supported by object file format"), | |
1762 | (int)fixp->fx_r_type); | |
1763 | return NULL; | |
1764 | } | |
1765 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
1766 | ||
1767 | if (fixp->fx_addsy && fixp->fx_subsy) | |
1768 | { | |
1769 | ||
1770 | if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy)) | |
1771 | || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section) | |
1772 | { | |
1773 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1774 | "Difference of symbols in different sections is not supported"); | |
1775 | return NULL; | |
1776 | } | |
1777 | ||
1778 | reloc->sym_ptr_ptr = &bfd_abs_symbol; | |
1779 | reloc->addend = (S_GET_VALUE (fixp->fx_addsy) | |
1780 | - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset); | |
1781 | } | |
1782 | else | |
1783 | { | |
310b5aa2 ILT |
1784 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof( asymbol *)); |
1785 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
1786 | reloc->addend = fixp->fx_offset; |
1787 | } | |
1788 | return reloc; | |
1789 | } | |
1790 | ||
1791 | int | |
1792 | md_estimate_size_before_relax (fragp, seg) | |
1793 | fragS *fragp; | |
1794 | asection *seg; | |
1795 | { | |
1796 | if (fragp->fr_subtype == 0) | |
1797 | return 2; | |
1798 | if (fragp->fr_subtype == 3) | |
1799 | return 3; | |
1800 | if (fragp->fr_subtype == 6) | |
1801 | { | |
1802 | if (!S_IS_DEFINED (fragp->fr_symbol) | |
1803 | || seg != S_GET_SEGMENT (fragp->fr_symbol)) | |
1804 | { | |
1805 | fragp->fr_subtype = 7; | |
1806 | return 7; | |
1807 | } | |
1808 | else | |
1809 | return 5; | |
1810 | } | |
1811 | if (fragp->fr_subtype == 8) | |
1812 | { | |
1813 | if (!S_IS_DEFINED (fragp->fr_symbol) | |
1814 | || seg != S_GET_SEGMENT (fragp->fr_symbol)) | |
1815 | { | |
1816 | fragp->fr_subtype = 9; | |
1817 | return 6; | |
1818 | } | |
1819 | else | |
1820 | return 4; | |
1821 | } | |
1822 | if (fragp->fr_subtype == 10) | |
1823 | { | |
1824 | if (!S_IS_DEFINED (fragp->fr_symbol) | |
1825 | || seg != S_GET_SEGMENT (fragp->fr_symbol)) | |
1826 | { | |
1827 | fragp->fr_subtype = 12; | |
1828 | return 5; | |
1829 | } | |
1830 | else | |
1831 | return 2; | |
1832 | } | |
1833 | } | |
1834 | ||
1835 | long | |
1836 | md_pcrel_from (fixp) | |
1837 | fixS *fixp; | |
1838 | { | |
1839 | return fixp->fx_frag->fr_address; | |
1840 | #if 0 | |
1841 | if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy)) | |
1842 | { | |
1843 | /* The symbol is undefined. Let the linker figure it out. */ | |
1844 | return 0; | |
1845 | } | |
1846 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
1847 | #endif | |
1848 | } | |
1849 | ||
1850 | int | |
1851 | md_apply_fix3 (fixp, valuep, seg) | |
1852 | fixS *fixp; | |
1853 | valueT *valuep; | |
1854 | segT seg; | |
1855 | { | |
1856 | /* We shouldn't ever get here because linkrelax is nonzero. */ | |
1857 | abort (); | |
1858 | fixp->fx_done = 1; | |
1859 | return 0; | |
1860 | } | |
1861 | ||
1862 | /* Insert an operand value into an instruction. */ | |
1863 | ||
1864 | static void | |
1865 | mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift) | |
1866 | unsigned long *insnp; | |
1867 | unsigned long *extensionp; | |
1868 | const struct mn10300_operand *operand; | |
1869 | offsetT val; | |
1870 | char *file; | |
1871 | unsigned int line; | |
1872 | unsigned int shift; | |
1873 | { | |
1874 | /* No need to check 32bit operands for a bit. Note that | |
1875 | MN10300_OPERAND_SPLIT is an implicit 32bit operand. */ | |
1876 | if (operand->bits != 32 | |
1877 | && (operand->flags & MN10300_OPERAND_SPLIT) == 0) | |
1878 | { | |
1879 | long min, max; | |
1880 | offsetT test; | |
1881 | int bits; | |
1882 | ||
1883 | bits = operand->bits; | |
85cb2cf9 JL |
1884 | if (operand->flags & MN10300_OPERAND_24BIT) |
1885 | bits = 24; | |
252b5132 RH |
1886 | |
1887 | if ((operand->flags & MN10300_OPERAND_SIGNED) != 0) | |
1888 | { | |
1889 | max = (1 << (bits - 1)) - 1; | |
1890 | min = - (1 << (bits - 1)); | |
1891 | } | |
1892 | else | |
1893 | { | |
1894 | max = (1 << bits) - 1; | |
1895 | min = 0; | |
1896 | } | |
1897 | ||
1898 | test = val; | |
1899 | ||
1900 | ||
1901 | if (test < (offsetT) min || test > (offsetT) max) | |
1902 | { | |
1903 | const char *err = | |
1904 | _("operand out of range (%s not between %ld and %ld)"); | |
1905 | char buf[100]; | |
1906 | ||
1907 | sprint_value (buf, test); | |
1908 | if (file == (char *) NULL) | |
1909 | as_warn (err, buf, min, max); | |
1910 | else | |
1911 | as_warn_where (file, line, err, buf, min, max); | |
1912 | } | |
1913 | } | |
1914 | ||
1915 | if ((operand->flags & MN10300_OPERAND_SPLIT) != 0) | |
1916 | { | |
1917 | *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1); | |
1918 | *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1)) | |
1919 | << operand->shift); | |
1920 | } | |
85cb2cf9 JL |
1921 | else if ((operand->flags & MN10300_OPERAND_24BIT) != 0) |
1922 | { | |
1923 | *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1); | |
1924 | *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1)) | |
1925 | << operand->shift); | |
1926 | } | |
252b5132 RH |
1927 | else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0) |
1928 | { | |
1929 | *insnp |= (((long) val & ((1 << operand->bits) - 1)) | |
1930 | << (operand->shift + shift)); | |
1931 | ||
1932 | if ((operand->flags & MN10300_OPERAND_REPEATED) != 0) | |
1933 | *insnp |= (((long) val & ((1 << operand->bits) - 1)) | |
1934 | << (operand->shift + shift + operand->bits)); | |
1935 | } | |
1936 | else | |
1937 | { | |
1938 | *extensionp |= (((long) val & ((1 << operand->bits) - 1)) | |
1939 | << (operand->shift + shift)); | |
1940 | ||
1941 | if ((operand->flags & MN10300_OPERAND_REPEATED) != 0) | |
1942 | *extensionp |= (((long) val & ((1 << operand->bits) - 1)) | |
1943 | << (operand->shift + shift + operand->bits)); | |
1944 | } | |
1945 | } | |
1946 | ||
1947 | static unsigned long | |
1948 | check_operand (insn, operand, val) | |
1949 | unsigned long insn; | |
1950 | const struct mn10300_operand *operand; | |
1951 | offsetT val; | |
1952 | { | |
1953 | /* No need to check 32bit operands for a bit. Note that | |
1954 | MN10300_OPERAND_SPLIT is an implicit 32bit operand. */ | |
1955 | if (operand->bits != 32 | |
1956 | && (operand->flags & MN10300_OPERAND_SPLIT) == 0) | |
1957 | { | |
1958 | long min, max; | |
1959 | offsetT test; | |
1960 | int bits; | |
1961 | ||
1962 | bits = operand->bits; | |
85cb2cf9 JL |
1963 | if (operand->flags & MN10300_OPERAND_24BIT) |
1964 | bits = 24; | |
252b5132 RH |
1965 | |
1966 | if ((operand->flags & MN10300_OPERAND_SIGNED) != 0) | |
1967 | { | |
1968 | max = (1 << (bits - 1)) - 1; | |
1969 | min = - (1 << (bits - 1)); | |
1970 | } | |
1971 | else | |
1972 | { | |
1973 | max = (1 << bits) - 1; | |
1974 | min = 0; | |
1975 | } | |
1976 | ||
1977 | test = val; | |
1978 | ||
1979 | ||
1980 | if (test < (offsetT) min || test > (offsetT) max) | |
1981 | return 0; | |
1982 | else | |
1983 | return 1; | |
1984 | } | |
1985 | return 1; | |
1986 | } | |
1987 | ||
1988 | static void | |
1989 | set_arch_mach (mach) | |
1990 | int mach; | |
1991 | { | |
1992 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach)) | |
1993 | as_warn (_("could not set architecture and machine")); | |
1994 | ||
1995 | current_machine = mach; | |
1996 | } |