Commit | Line | Data |
---|---|---|
c6aa56bc C |
1 | /* tc-v850.c -- Assembler code for the NEC V850 |
2 | ||
3 | Copyright (C) 1996 Free Software Foundation. | |
4 | ||
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GAS; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include <stdio.h> | |
23 | #include <ctype.h> | |
24 | #include "as.h" | |
25 | #include "subsegs.h" | |
26 | #include "opcode/v850.h" | |
27 | \f | |
0e8f9bd1 JL |
28 | /* Structure to hold information about predefined registers. */ |
29 | struct reg_name | |
30 | { | |
31 | const char *name; | |
32 | int value; | |
33 | }; | |
34 | ||
c6aa56bc C |
35 | /* Generic assembler global variables which must be defined by all targets. */ |
36 | ||
37 | /* Characters which always start a comment. */ | |
38 | const char comment_chars[] = "#"; | |
39 | ||
40 | /* Characters which start a comment at the beginning of a line. */ | |
dcf5d117 | 41 | const char line_comment_chars[] = ";#"; |
c6aa56bc C |
42 | |
43 | /* Characters which may be used to separate multiple commands on a | |
44 | single line. */ | |
45 | const char line_separator_chars[] = ";"; | |
46 | ||
47 | /* Characters which are used to indicate an exponent in a floating | |
48 | point number. */ | |
49 | const char EXP_CHARS[] = "eE"; | |
50 | ||
51 | /* Characters which mean that a number is a floating point constant, | |
52 | as in 0d1.0. */ | |
53 | const char FLT_CHARS[] = "dD"; | |
54 | \f | |
55 | /* local functions */ | |
56 | static unsigned long v850_insert_operand | |
57 | PARAMS ((unsigned long insn, const struct v850_operand *operand, | |
58 | offsetT val, char *file, unsigned int line)); | |
0e8f9bd1 | 59 | static int reg_name_search PARAMS ((char *name, const struct reg_name *, int)); |
c6aa56bc | 60 | static boolean register_name PARAMS ((expressionS *expressionP)); |
0e8f9bd1 | 61 | static boolean system_register_name PARAMS ((expressionS *expressionP)); |
c9f1b2d9 | 62 | static boolean cc_name PARAMS ((expressionS *expressionP)); |
c6aa56bc C |
63 | static int postfix PARAMS ((char *p)); |
64 | static bfd_reloc_code_real_type get_reloc PARAMS ((struct v850_operand *op)); | |
65 | static unsigned long build_insn PARAMS ((struct v850_opcode *opcode, expressionS *opers)); | |
66 | ||
67 | ||
68 | /* fixups */ | |
69 | #define MAX_INSN_FIXUPS (5) | |
70 | struct v850_fixup | |
71 | { | |
72 | expressionS exp; | |
73 | int opindex; | |
74 | bfd_reloc_code_real_type reloc; | |
75 | }; | |
76 | struct v850_fixup fixups[MAX_INSN_FIXUPS]; | |
77 | static int fc; | |
78 | \f | |
79 | const char *md_shortopts = ""; | |
80 | struct option md_longopts[] = { | |
81 | {NULL, no_argument, NULL, 0} | |
82 | }; | |
83 | size_t md_longopts_size = sizeof(md_longopts); | |
84 | ||
85 | /* The target specific pseudo-ops which we support. */ | |
86 | const pseudo_typeS md_pseudo_table[] = | |
87 | { | |
88 | /* | |
89 | { "byte", ppc_byte, 0 }, | |
90 | { "long", ppc_elf_cons, 4 }, | |
91 | { "word", ppc_elf_cons, 2 }, | |
92 | { "short", ppc_elf_cons, 2 }, | |
93 | { "rdata", ppc_elf_rdata, 0 }, | |
94 | { "rodata", ppc_elf_rdata, 0 }, | |
95 | { "lcomm", ppc_elf_lcomm, 0 }, | |
96 | */ | |
97 | { NULL, NULL, 0 } | |
98 | }; | |
99 | ||
100 | /* Opcode hash table. */ | |
101 | static struct hash_control *v850_hash; | |
102 | ||
1510cd39 C |
103 | /* This table is sorted. Suitable for searching by a binary search. */ |
104 | static const struct reg_name pre_defined_registers[] = | |
c6aa56bc C |
105 | { |
106 | { "ep", 30 }, /* ep - element ptr */ | |
107 | { "gp", 4 }, /* gp - global ptr */ | |
108 | { "lp", 31 }, /* lp - link ptr */ | |
109 | { "r0", 0 }, | |
110 | { "r1", 1 }, | |
111 | { "r10", 10 }, | |
112 | { "r11", 11 }, | |
113 | { "r12", 12 }, | |
114 | { "r13", 13 }, | |
115 | { "r14", 14 }, | |
116 | { "r15", 15 }, | |
117 | { "r16", 16 }, | |
118 | { "r17", 17 }, | |
119 | { "r18", 18 }, | |
120 | { "r19", 19 }, | |
121 | { "r2", 2 }, | |
122 | { "r20", 20 }, | |
123 | { "r21", 21 }, | |
124 | { "r22", 22 }, | |
125 | { "r23", 23 }, | |
126 | { "r24", 24 }, | |
127 | { "r25", 25 }, | |
128 | { "r26", 26 }, | |
129 | { "r27", 27 }, | |
130 | { "r28", 28 }, | |
131 | { "r29", 29 }, | |
132 | { "r3", 3 }, | |
133 | { "r30", 30 }, | |
134 | { "r31", 31 }, | |
135 | { "r4", 4 }, | |
136 | { "r5", 5 }, | |
137 | { "r6", 6 }, | |
138 | { "r7", 7 }, | |
139 | { "r8", 8 }, | |
140 | { "r9", 9 }, | |
141 | { "sp", 3 }, /* sp - stack ptr */ | |
142 | { "tp", 5 }, /* tp - text ptr */ | |
143 | { "zero", 0 }, | |
144 | }; | |
1510cd39 C |
145 | #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct reg_name)) |
146 | ||
147 | ||
148 | static const struct reg_name system_registers[] = | |
149 | { | |
150 | { "eipc", 0 }, | |
151 | { "eipsw", 1 }, | |
152 | { "fepc", 2 }, | |
153 | { "fepsw", 3 }, | |
154 | { "ecr", 4 }, | |
155 | { "psw", 5 }, | |
156 | }; | |
0e8f9bd1 | 157 | #define SYSREG_NAME_CNT (sizeof(system_registers) / sizeof(struct reg_name)) |
1510cd39 C |
158 | |
159 | static const struct reg_name cc_names[] = | |
160 | { | |
161 | { "c", 0x1 }, | |
162 | { "ge", 0xe }, | |
163 | { "gt", 0xf }, | |
164 | { "h", 0xb }, | |
165 | { "l", 0x1 }, | |
166 | { "le", 0x7 }, | |
167 | { "lt", 0x6 }, | |
168 | { "n", 0x4 }, | |
169 | { "nc", 0x9 }, | |
170 | { "nh", 0x3 }, | |
171 | { "nl", 0x9 }, | |
172 | { "ns", 0xc }, | |
173 | { "nv", 0x8 }, | |
174 | { "nz", 0xa }, | |
175 | { "p", 0xc }, | |
176 | { "s", 0x4 }, | |
177 | { "sa", 0xd }, | |
178 | { "t", 0x5 }, | |
179 | { "v", 0x0 }, | |
180 | { "z", 0x2 }, | |
181 | }; | |
c9f1b2d9 | 182 | #define CC_NAME_CNT (sizeof(cc_names) / sizeof(struct reg_name)) |
c6aa56bc | 183 | |
0e8f9bd1 JL |
184 | /* reg_name_search does a binary search of the given register table |
185 | to see if "name" is a valid regiter name. Returns the register | |
c6aa56bc C |
186 | number from the array on success, or -1 on failure. */ |
187 | ||
188 | static int | |
0e8f9bd1 | 189 | reg_name_search (name, table, high) |
c6aa56bc | 190 | char *name; |
0e8f9bd1 JL |
191 | const struct reg_name *table; |
192 | int high; | |
c6aa56bc | 193 | { |
0e8f9bd1 | 194 | int middle, low; |
c6aa56bc C |
195 | int cmp; |
196 | ||
197 | low = 0; | |
c6aa56bc C |
198 | do |
199 | { | |
200 | middle = (low + high) / 2; | |
0e8f9bd1 | 201 | cmp = strcasecmp (name, table[middle].name); |
c6aa56bc C |
202 | if (cmp < 0) |
203 | high = middle - 1; | |
204 | else if (cmp > 0) | |
205 | low = middle + 1; | |
206 | else | |
0e8f9bd1 | 207 | return table[middle].value; |
c6aa56bc C |
208 | } |
209 | while (low <= high); | |
210 | return -1; | |
211 | } | |
212 | ||
213 | ||
214 | /* Summary of register_name(). | |
215 | * | |
216 | * in: Input_line_pointer points to 1st char of operand. | |
217 | * | |
218 | * out: A expressionS. | |
219 | * The operand may have been a register: in this case, X_op == O_register, | |
220 | * X_add_number is set to the register number, and truth is returned. | |
221 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
222 | * its original state. | |
223 | */ | |
224 | static boolean | |
225 | register_name (expressionP) | |
226 | expressionS *expressionP; | |
227 | { | |
228 | int reg_number; | |
229 | char *name; | |
230 | char *start; | |
231 | char c; | |
232 | ||
233 | /* Find the spelling of the operand */ | |
234 | start = name = input_line_pointer; | |
235 | ||
236 | c = get_symbol_end (); | |
0e8f9bd1 JL |
237 | reg_number = reg_name_search (name, pre_defined_registers, REG_NAME_CNT - 1); |
238 | ||
239 | /* look to see if it's in the register table */ | |
240 | if (reg_number >= 0) | |
241 | { | |
242 | expressionP->X_op = O_register; | |
243 | expressionP->X_add_number = reg_number; | |
244 | ||
245 | /* make the rest nice */ | |
246 | expressionP->X_add_symbol = NULL; | |
247 | expressionP->X_op_symbol = NULL; | |
248 | *input_line_pointer = c; /* put back the delimiting char */ | |
249 | return true; | |
250 | } | |
251 | else | |
252 | { | |
253 | /* reset the line as if we had not done anything */ | |
254 | *input_line_pointer = c; /* put back the delimiting char */ | |
255 | input_line_pointer = start; /* reset input_line pointer */ | |
256 | return false; | |
257 | } | |
258 | } | |
259 | ||
260 | /* Summary of system_register_name(). | |
261 | * | |
262 | * in: Input_line_pointer points to 1st char of operand. | |
263 | * | |
264 | * out: A expressionS. | |
265 | * The operand may have been a register: in this case, X_op == O_register, | |
266 | * X_add_number is set to the register number, and truth is returned. | |
267 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
268 | * its original state. | |
269 | */ | |
270 | static boolean | |
271 | system_register_name (expressionP) | |
272 | expressionS *expressionP; | |
273 | { | |
274 | int reg_number; | |
275 | char *name; | |
276 | char *start; | |
277 | char c; | |
278 | ||
279 | /* Find the spelling of the operand */ | |
280 | start = name = input_line_pointer; | |
281 | ||
282 | c = get_symbol_end (); | |
283 | reg_number = reg_name_search (name, system_registers, SYSREG_NAME_CNT - 1); | |
c6aa56bc C |
284 | |
285 | /* look to see if it's in the register table */ | |
286 | if (reg_number >= 0) | |
287 | { | |
288 | expressionP->X_op = O_register; | |
289 | expressionP->X_add_number = reg_number; | |
290 | ||
291 | /* make the rest nice */ | |
292 | expressionP->X_add_symbol = NULL; | |
293 | expressionP->X_op_symbol = NULL; | |
294 | *input_line_pointer = c; /* put back the delimiting char */ | |
295 | return true; | |
296 | } | |
297 | else | |
298 | { | |
299 | /* reset the line as if we had not done anything */ | |
300 | *input_line_pointer = c; /* put back the delimiting char */ | |
301 | input_line_pointer = start; /* reset input_line pointer */ | |
302 | return false; | |
303 | } | |
304 | } | |
305 | ||
c9f1b2d9 JL |
306 | /* Summary of cc_name(). |
307 | * | |
308 | * in: Input_line_pointer points to 1st char of operand. | |
309 | * | |
310 | * out: A expressionS. | |
311 | * The operand may have been a register: in this case, X_op == O_register, | |
312 | * X_add_number is set to the register number, and truth is returned. | |
313 | * Input_line_pointer->(next non-blank) char after operand, or is in | |
314 | * its original state. | |
315 | */ | |
316 | static boolean | |
317 | cc_name (expressionP) | |
318 | expressionS *expressionP; | |
319 | { | |
320 | int reg_number; | |
321 | char *name; | |
322 | char *start; | |
323 | char c; | |
324 | ||
325 | /* Find the spelling of the operand */ | |
326 | start = name = input_line_pointer; | |
327 | ||
328 | c = get_symbol_end (); | |
329 | reg_number = reg_name_search (name, cc_names, CC_NAME_CNT - 1); | |
330 | ||
331 | /* look to see if it's in the register table */ | |
332 | if (reg_number >= 0) | |
333 | { | |
334 | expressionP->X_op = O_constant; | |
335 | expressionP->X_add_number = reg_number; | |
336 | ||
337 | /* make the rest nice */ | |
338 | expressionP->X_add_symbol = NULL; | |
339 | expressionP->X_op_symbol = NULL; | |
340 | *input_line_pointer = c; /* put back the delimiting char */ | |
341 | return true; | |
342 | } | |
343 | else | |
344 | { | |
345 | /* reset the line as if we had not done anything */ | |
346 | *input_line_pointer = c; /* put back the delimiting char */ | |
347 | input_line_pointer = start; /* reset input_line pointer */ | |
348 | return false; | |
349 | } | |
350 | } | |
351 | ||
c6aa56bc C |
352 | void |
353 | md_show_usage (stream) | |
354 | FILE *stream; | |
355 | { | |
356 | fprintf(stream, "V850 options:\n\ | |
357 | none yet\n"); | |
358 | } | |
359 | ||
360 | int | |
361 | md_parse_option (c, arg) | |
362 | int c; | |
363 | char *arg; | |
364 | { | |
365 | return 0; | |
366 | } | |
367 | ||
368 | symbolS * | |
369 | md_undefined_symbol (name) | |
370 | char *name; | |
371 | { | |
372 | return 0; | |
373 | } | |
374 | ||
375 | char * | |
376 | md_atof (type, litp, sizep) | |
377 | int type; | |
378 | char *litp; | |
379 | int *sizep; | |
380 | { | |
381 | int prec; | |
382 | LITTLENUM_TYPE words[4]; | |
383 | char *t; | |
384 | int i; | |
385 | ||
386 | switch (type) | |
387 | { | |
388 | case 'f': | |
389 | prec = 2; | |
390 | break; | |
391 | ||
392 | case 'd': | |
393 | prec = 4; | |
394 | break; | |
395 | ||
396 | default: | |
397 | *sizep = 0; | |
398 | return "bad call to md_atof"; | |
399 | } | |
400 | ||
401 | t = atof_ieee (input_line_pointer, type, words); | |
402 | if (t) | |
403 | input_line_pointer = t; | |
404 | ||
405 | *sizep = prec * 2; | |
406 | ||
407 | for (i = prec - 1; i >= 0; i--) | |
408 | { | |
409 | md_number_to_chars (litp, (valueT) words[i], 2); | |
410 | litp += 2; | |
411 | } | |
412 | ||
413 | return NULL; | |
414 | } | |
415 | ||
416 | ||
417 | void | |
418 | md_convert_frag (abfd, sec, fragP) | |
419 | bfd *abfd; | |
420 | asection *sec; | |
421 | fragS *fragP; | |
422 | { | |
423 | /* printf ("call to md_convert_frag \n"); */ | |
424 | abort (); | |
425 | } | |
426 | ||
427 | valueT | |
428 | md_section_align (seg, addr) | |
429 | asection *seg; | |
430 | valueT addr; | |
431 | { | |
432 | int align = bfd_get_section_alignment (stdoutput, seg); | |
433 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
434 | } | |
435 | ||
436 | void | |
437 | md_begin () | |
438 | { | |
439 | char *prev_name = ""; | |
440 | register const struct v850_opcode *op; | |
441 | const struct v850_opcode *op_end; | |
442 | ||
443 | v850_hash = hash_new(); | |
444 | ||
445 | /* Insert unique names into hash table. The V850 instruction set | |
446 | has many identical opcode names that have different opcodes based | |
447 | on the operands. This hash table then provides a quick index to | |
448 | the first opcode with a particular name in the opcode table. */ | |
449 | ||
450 | op = v850_opcodes; | |
05631de2 | 451 | while (op->name) |
c6aa56bc C |
452 | { |
453 | if (strcmp (prev_name, op->name)) | |
454 | { | |
455 | prev_name = (char *) op->name; | |
456 | hash_insert (v850_hash, op->name, (char *) op); | |
457 | } | |
05631de2 | 458 | op++; |
c6aa56bc C |
459 | } |
460 | } | |
461 | ||
462 | ||
463 | static bfd_reloc_code_real_type | |
464 | get_reloc (op) | |
465 | struct v850_operand *op; | |
466 | { | |
467 | abort (); | |
468 | } | |
469 | ||
470 | ||
c6aa56bc C |
471 | void |
472 | md_assemble (str) | |
473 | char *str; | |
474 | { | |
475 | char *s; | |
476 | struct v850_opcode *opcode; | |
477 | struct v850_opcode *next_opcode; | |
478 | const unsigned char *opindex_ptr; | |
479 | int next_opindex; | |
480 | unsigned long insn; | |
481 | char *f; | |
482 | int i; | |
483 | int numops; | |
484 | int match; | |
485 | ||
486 | int numopts; | |
487 | expressionS myops[5]; | |
488 | ||
489 | /* Get the opcode. */ | |
490 | for (s = str; *s != '\0' && ! isspace (*s); s++) | |
491 | ; | |
492 | if (*s != '\0') | |
493 | *s++ = '\0'; | |
494 | ||
495 | /* find the first opcode with the proper name */ | |
496 | opcode = (struct v850_opcode *)hash_find (v850_hash, str); | |
497 | if (opcode == NULL) | |
498 | { | |
499 | as_bad ("Unrecognized opcode: `%s'", str); | |
500 | return; | |
501 | } | |
502 | ||
503 | str = s; | |
504 | while (isspace (*str)) | |
505 | ++str; | |
506 | ||
507 | input_line_pointer = str; | |
508 | ||
1510cd39 | 509 | for(;;) |
c6aa56bc | 510 | { |
1510cd39 C |
511 | const char *errmsg = NULL; |
512 | ||
513 | fc = 0; | |
514 | match = 0; | |
515 | next_opindex = 0; | |
d5974c57 | 516 | insn = opcode->opcode; |
1510cd39 | 517 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) |
c6aa56bc | 518 | { |
1510cd39 C |
519 | const struct v850_operand *operand; |
520 | char *hold; | |
521 | expressionS ex; | |
522 | char endc; | |
c6aa56bc | 523 | |
1510cd39 | 524 | if (next_opindex == 0) |
c6aa56bc | 525 | { |
1510cd39 C |
526 | operand = &v850_operands[*opindex_ptr]; |
527 | } | |
528 | else | |
529 | { | |
530 | operand = &v850_operands[next_opindex]; | |
531 | next_opindex = 0; | |
c6aa56bc C |
532 | } |
533 | ||
1510cd39 C |
534 | errmsg = NULL; |
535 | ||
536 | while (*str == ' ' || *str == ',' || *str == '[' || *str == ']') | |
537 | ++str; | |
538 | ||
539 | /* Gather the operand. */ | |
540 | hold = input_line_pointer; | |
541 | input_line_pointer = str; | |
542 | ||
543 | if ((operand->flags & V850_OPERAND_REG) != 0) | |
c6aa56bc | 544 | { |
1510cd39 | 545 | if (!register_name(&ex)) |
c6aa56bc | 546 | { |
1510cd39 C |
547 | errmsg = "invalid register name"; |
548 | goto error; | |
c6aa56bc C |
549 | } |
550 | } | |
0e8f9bd1 JL |
551 | else if ((operand->flags & V850_OPERAND_SRG) != 0) |
552 | { | |
553 | if (!system_register_name(&ex)) | |
554 | { | |
555 | errmsg = "invalid system register name"; | |
556 | goto error; | |
557 | } | |
558 | } | |
88b47a85 JL |
559 | else if ((operand->flags & V850_OPERAND_EP) != 0) |
560 | { | |
561 | char *start = input_line_pointer; | |
562 | char c = get_symbol_end (); | |
563 | if (strcmp (start, "ep") != 0 | |
564 | && strcmp (start, "r30") != 0) | |
565 | { | |
566 | /* Put things back the way we found them. */ | |
567 | *input_line_pointer = c; | |
568 | input_line_pointer = start; | |
569 | errmsg = "expected EP register"; | |
570 | goto error; | |
571 | } | |
572 | *input_line_pointer = c; | |
573 | str = input_line_pointer; | |
574 | input_line_pointer = hold; | |
575 | ||
576 | while (*str == ' ' || *str == ',' || *str == '[' || *str == ']') | |
577 | ++str; | |
578 | continue; | |
579 | } | |
c9f1b2d9 JL |
580 | else if ((operand->flags & V850_OPERAND_CC) != 0) |
581 | { | |
582 | if (!cc_name(&ex)) | |
583 | { | |
584 | errmsg = "invalid condition code name"; | |
585 | goto error; | |
586 | } | |
587 | } | |
1510cd39 C |
588 | else if (strncmp(input_line_pointer, "lo(", 3) == 0) |
589 | { | |
590 | input_line_pointer += 3; | |
591 | expression(&ex); | |
c6aa56bc | 592 | |
1510cd39 C |
593 | if (*input_line_pointer++ != ')') |
594 | { | |
595 | errmsg = "syntax error: expected `)'"; | |
596 | goto error; | |
597 | } | |
598 | ||
599 | if (ex.X_op == O_constant) | |
05631de2 | 600 | ex.X_add_number = (signed)((ex.X_add_number & 0xffff) << 16) >> 16; |
1510cd39 C |
601 | else |
602 | { | |
603 | if (fc > MAX_INSN_FIXUPS) | |
604 | as_fatal ("too many fixups"); | |
605 | ||
606 | fixups[fc].exp = ex; | |
607 | fixups[fc].opindex = *opindex_ptr; | |
608 | fixups[fc].reloc = BFD_RELOC_LO16; | |
609 | fc++; | |
610 | } | |
611 | } | |
612 | else if (strncmp(input_line_pointer, "hi(", 3) == 0) | |
613 | { | |
614 | input_line_pointer += 3; | |
615 | expression(&ex); | |
c6aa56bc | 616 | |
1510cd39 C |
617 | if (*input_line_pointer++ != ')') |
618 | { | |
619 | errmsg = "syntax error: expected `)'"; | |
620 | goto error; | |
621 | } | |
622 | ||
623 | if (ex.X_op == O_constant) | |
05631de2 JL |
624 | { |
625 | unsigned long temp = ex.X_add_number; | |
626 | ex.X_add_number = (signed)(temp & 0xffff0000) >> 16; | |
627 | ||
628 | /* If the would be on for the low part, then we have | |
629 | to add it into the high part. */ | |
630 | if (temp & 0x8000) | |
631 | ex.X_add_number += 1; | |
632 | } | |
633 | else | |
634 | { | |
635 | if (fc > MAX_INSN_FIXUPS) | |
636 | as_fatal ("too many fixups"); | |
637 | ||
638 | fixups[fc].exp = ex; | |
639 | fixups[fc].opindex = *opindex_ptr; | |
640 | fixups[fc].reloc = BFD_RELOC_HI16_S; | |
641 | fc++; | |
642 | } | |
643 | } | |
644 | else if (strncmp(input_line_pointer, "hi0(", 4) == 0) | |
645 | { | |
646 | input_line_pointer += 4; | |
647 | expression(&ex); | |
648 | ||
649 | if (*input_line_pointer++ != ')') | |
650 | { | |
651 | errmsg = "syntax error: expected `)'"; | |
652 | goto error; | |
653 | } | |
654 | ||
655 | if (ex.X_op == O_constant) | |
656 | ex.X_add_number = (signed)(ex.X_add_number & 0xffff0000) >> 16; | |
1510cd39 C |
657 | else |
658 | { | |
659 | if (fc > MAX_INSN_FIXUPS) | |
660 | as_fatal ("too many fixups"); | |
661 | ||
662 | fixups[fc].exp = ex; | |
663 | fixups[fc].opindex = *opindex_ptr; | |
664 | fixups[fc].reloc = BFD_RELOC_HI16; | |
665 | fc++; | |
666 | } | |
667 | } | |
c9a32d6c JL |
668 | else if (register_name (&ex) |
669 | && (operand->flags & V850_OPERAND_REG) == 0) | |
670 | { | |
671 | errmsg = "syntax error: register not expected"; | |
672 | goto error; | |
673 | } | |
0e8f9bd1 JL |
674 | else if (system_register_name (&ex) |
675 | && (operand->flags & V850_OPERAND_SRG) == 0) | |
676 | { | |
677 | errmsg = "syntax error: system register not expected"; | |
678 | goto error; | |
679 | } | |
c9f1b2d9 JL |
680 | else if (cc_name (&ex) |
681 | && (operand->flags & V850_OPERAND_CC) == 0) | |
682 | { | |
683 | errmsg = "syntax error: condition code not expected"; | |
684 | goto error; | |
685 | } | |
1510cd39 C |
686 | else |
687 | { | |
688 | expression(&ex); | |
689 | } | |
c6aa56bc | 690 | |
1510cd39 C |
691 | str = input_line_pointer; |
692 | input_line_pointer = hold; | |
c6aa56bc | 693 | |
1510cd39 C |
694 | switch (ex.X_op) |
695 | { | |
696 | case O_illegal: | |
697 | errmsg = "illegal operand"; | |
698 | goto error; | |
699 | case O_absent: | |
700 | errmsg = "missing operand"; | |
701 | goto error; | |
702 | case O_register: | |
0e8f9bd1 | 703 | if ((operand->flags & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0) |
1510cd39 C |
704 | { |
705 | errmsg = "invalid operand"; | |
706 | goto error; | |
707 | } | |
708 | ||
709 | insn = v850_insert_operand (insn, operand, ex.X_add_number, | |
710 | (char *) NULL, 0); | |
711 | break; | |
712 | ||
713 | case O_constant: | |
714 | insn = v850_insert_operand (insn, operand, ex.X_add_number, | |
715 | (char *) NULL, 0); | |
716 | break; | |
717 | ||
718 | default: | |
719 | /* We need to generate a fixup for this expression. */ | |
720 | if (fc >= MAX_INSN_FIXUPS) | |
721 | as_fatal ("too many fixups"); | |
722 | fixups[fc].exp = ex; | |
723 | fixups[fc].opindex = *opindex_ptr; | |
724 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
725 | ++fc; | |
726 | break; | |
727 | } | |
728 | ||
729 | while (*str == ' ' || *str == ',' || *str == '[' || *str == ']') | |
730 | ++str; | |
731 | } | |
732 | match = 1; | |
733 | ||
734 | error: | |
735 | if (match == 0) | |
736 | { | |
737 | next_opcode = opcode + 1; | |
738 | if (next_opcode->opcode != 0 && !strcmp(next_opcode->name, opcode->name)) | |
739 | { | |
740 | opcode = next_opcode; | |
741 | continue; | |
742 | } | |
743 | ||
744 | as_bad ("%s", errmsg); | |
745 | return; | |
746 | } | |
747 | break; | |
748 | } | |
749 | ||
c6aa56bc C |
750 | while (isspace (*str)) |
751 | ++str; | |
752 | ||
753 | if (*str != '\0') | |
754 | as_bad ("junk at end of line: `%s'", str); | |
1510cd39 C |
755 | |
756 | input_line_pointer = str; | |
c6aa56bc | 757 | |
c9a32d6c JL |
758 | f = frag_more (opcode->size); |
759 | md_number_to_chars (f, insn, opcode->size); | |
c6aa56bc C |
760 | } |
761 | ||
762 | ||
763 | /* if while processing a fixup, a reloc really needs to be created */ | |
764 | /* then it is done here */ | |
765 | ||
766 | arelent * | |
767 | tc_gen_reloc (seg, fixp) | |
768 | asection *seg; | |
769 | fixS *fixp; | |
770 | { | |
771 | arelent *reloc; | |
772 | reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent)); | |
773 | reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym; | |
774 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
775 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
776 | if (reloc->howto == (reloc_howto_type *) NULL) | |
777 | { | |
778 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
779 | "reloc %d not supported by object file format", (int)fixp->fx_r_type); | |
780 | return NULL; | |
781 | } | |
782 | reloc->addend = fixp->fx_addnumber; | |
783 | /* printf("tc_gen_reloc: addr=%x addend=%x\n", reloc->address, reloc->addend); */ | |
784 | return reloc; | |
785 | } | |
786 | ||
787 | int | |
788 | md_estimate_size_before_relax (fragp, seg) | |
789 | fragS *fragp; | |
790 | asection *seg; | |
791 | { | |
792 | abort (); | |
793 | return 0; | |
794 | } | |
795 | ||
796 | long | |
797 | md_pcrel_from_section (fixp, sec) | |
798 | fixS *fixp; | |
799 | segT sec; | |
800 | { | |
801 | return 0; | |
802 | /* return fixp->fx_frag->fr_address + fixp->fx_where; */ | |
803 | } | |
804 | ||
805 | int | |
806 | md_apply_fix3 (fixp, valuep, seg) | |
807 | fixS *fixp; | |
808 | valueT *valuep; | |
809 | segT seg; | |
810 | { | |
88b47a85 JL |
811 | as_tsktsk ("relocations not supported yet.\n"); |
812 | fixp->fx_done = 1; | |
813 | return 1; | |
c6aa56bc C |
814 | abort(); |
815 | #if 0 | |
816 | valueT value; | |
817 | char *where; | |
818 | unsigned long insn; | |
819 | int op_type; | |
820 | ||
821 | if (fixp->fx_addsy == (symbolS *) NULL) | |
822 | { | |
823 | value = *valuep; | |
824 | fixp->fx_done = 1; | |
825 | } | |
826 | else if (fixp->fx_pcrel) | |
827 | value = *valuep; | |
828 | else | |
829 | { | |
830 | value = fixp->fx_offset; | |
831 | if (fixp->fx_subsy != (symbolS *) NULL) | |
832 | { | |
833 | if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section) | |
834 | value -= S_GET_VALUE (fixp->fx_subsy); | |
835 | else | |
836 | { | |
837 | /* We don't actually support subtracting a symbol. */ | |
838 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
839 | "expression too complex"); | |
840 | } | |
841 | } | |
842 | } | |
843 | ||
844 | /* printf("md_apply_fix: value=0x%x type=%d\n", value, fixp->fx_r_type); */ | |
845 | ||
846 | op_type = fixp->fx_r_type; | |
847 | fixp->fx_r_type = get_reloc((struct v850_operand *)&v850_operands[op_type]); | |
848 | ||
849 | /* printf("reloc=%d\n",fixp->fx_r_type); */ | |
850 | ||
851 | /* Fetch the instruction, insert the fully resolved operand | |
852 | value, and stuff the instruction back again. */ | |
853 | where = fixp->fx_frag->fr_literal + fixp->fx_where; | |
854 | insn = bfd_getb32 ((unsigned char *) where); | |
855 | /* printf(" insn=%x value=%x\n",insn,value); */ | |
856 | ||
857 | insn = v850_insert_operand (insn, op_type, (offsetT) value); | |
858 | ||
859 | /* printf(" new insn=%x\n",insn); */ | |
860 | ||
861 | bfd_putb32 ((bfd_vma) insn, (unsigned char *) where); | |
862 | ||
863 | if (fixp->fx_done) | |
864 | return 1; | |
865 | ||
866 | fixp->fx_addnumber = value; | |
867 | return 1; | |
868 | #endif | |
869 | } | |
870 | ||
871 | \f | |
872 | /* Insert an operand value into an instruction. */ | |
873 | ||
874 | static unsigned long | |
875 | v850_insert_operand (insn, operand, val, file, line) | |
876 | unsigned long insn; | |
877 | const struct v850_operand *operand; | |
878 | offsetT val; | |
879 | char *file; | |
880 | unsigned int line; | |
881 | { | |
882 | if (operand->bits != 32) | |
883 | { | |
884 | long min, max; | |
885 | offsetT test; | |
886 | ||
1510cd39 | 887 | if ((operand->flags & V850_OPERAND_SIGNED) != 0) |
c6aa56bc | 888 | { |
1510cd39 | 889 | #if 0 |
c6aa56bc C |
890 | if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0 |
891 | && ppc_size == PPC_OPCODE_32) | |
892 | max = (1 << operand->bits) - 1; | |
893 | else | |
1510cd39 | 894 | #endif |
c6aa56bc C |
895 | max = (1 << (operand->bits - 1)) - 1; |
896 | min = - (1 << (operand->bits - 1)); | |
897 | } | |
898 | else | |
c6aa56bc C |
899 | { |
900 | max = (1 << operand->bits) - 1; | |
901 | min = 0; | |
902 | } | |
903 | ||
904 | #if 0 | |
905 | if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0) | |
906 | test = - val; | |
907 | else | |
908 | #endif | |
909 | test = val; | |
910 | ||
911 | ||
912 | if (test < (offsetT) min || test > (offsetT) max) | |
913 | { | |
914 | const char *err = | |
915 | "operand out of range (%s not between %ld and %ld)"; | |
916 | char buf[100]; | |
917 | ||
918 | sprint_value (buf, test); | |
919 | if (file == (char *) NULL) | |
920 | as_warn (err, buf, min, max); | |
921 | else | |
922 | as_warn_where (file, line, err, buf, min, max); | |
923 | } | |
924 | } | |
925 | ||
926 | insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift); | |
927 | return insn; | |
928 | } |