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; | |
451 | op_end = v850_opcodes + v850_num_opcodes; | |
452 | ||
453 | for (; op < op_end; op++) | |
454 | { | |
455 | if (strcmp (prev_name, op->name)) | |
456 | { | |
457 | prev_name = (char *) op->name; | |
458 | hash_insert (v850_hash, op->name, (char *) op); | |
459 | } | |
460 | } | |
461 | } | |
462 | ||
463 | ||
464 | static bfd_reloc_code_real_type | |
465 | get_reloc (op) | |
466 | struct v850_operand *op; | |
467 | { | |
468 | abort (); | |
469 | } | |
470 | ||
471 | ||
c6aa56bc C |
472 | void |
473 | md_assemble (str) | |
474 | char *str; | |
475 | { | |
476 | char *s; | |
477 | struct v850_opcode *opcode; | |
478 | struct v850_opcode *next_opcode; | |
479 | const unsigned char *opindex_ptr; | |
480 | int next_opindex; | |
481 | unsigned long insn; | |
482 | char *f; | |
483 | int i; | |
484 | int numops; | |
485 | int match; | |
486 | ||
487 | int numopts; | |
488 | expressionS myops[5]; | |
489 | ||
490 | /* Get the opcode. */ | |
491 | for (s = str; *s != '\0' && ! isspace (*s); s++) | |
492 | ; | |
493 | if (*s != '\0') | |
494 | *s++ = '\0'; | |
495 | ||
496 | /* find the first opcode with the proper name */ | |
497 | opcode = (struct v850_opcode *)hash_find (v850_hash, str); | |
498 | if (opcode == NULL) | |
499 | { | |
500 | as_bad ("Unrecognized opcode: `%s'", str); | |
501 | return; | |
502 | } | |
503 | ||
504 | str = s; | |
505 | while (isspace (*str)) | |
506 | ++str; | |
507 | ||
508 | input_line_pointer = str; | |
509 | ||
1510cd39 | 510 | for(;;) |
c6aa56bc | 511 | { |
1510cd39 C |
512 | const char *errmsg = NULL; |
513 | ||
514 | fc = 0; | |
515 | match = 0; | |
516 | next_opindex = 0; | |
d5974c57 | 517 | insn = opcode->opcode; |
1510cd39 | 518 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) |
c6aa56bc | 519 | { |
1510cd39 C |
520 | const struct v850_operand *operand; |
521 | char *hold; | |
522 | expressionS ex; | |
523 | char endc; | |
c6aa56bc | 524 | |
1510cd39 | 525 | if (next_opindex == 0) |
c6aa56bc | 526 | { |
1510cd39 C |
527 | operand = &v850_operands[*opindex_ptr]; |
528 | } | |
529 | else | |
530 | { | |
531 | operand = &v850_operands[next_opindex]; | |
532 | next_opindex = 0; | |
c6aa56bc C |
533 | } |
534 | ||
1510cd39 C |
535 | errmsg = NULL; |
536 | ||
537 | while (*str == ' ' || *str == ',' || *str == '[' || *str == ']') | |
538 | ++str; | |
539 | ||
540 | /* Gather the operand. */ | |
541 | hold = input_line_pointer; | |
542 | input_line_pointer = str; | |
543 | ||
544 | if ((operand->flags & V850_OPERAND_REG) != 0) | |
c6aa56bc | 545 | { |
1510cd39 | 546 | if (!register_name(&ex)) |
c6aa56bc | 547 | { |
1510cd39 C |
548 | errmsg = "invalid register name"; |
549 | goto error; | |
c6aa56bc C |
550 | } |
551 | } | |
0e8f9bd1 JL |
552 | else if ((operand->flags & V850_OPERAND_SRG) != 0) |
553 | { | |
554 | if (!system_register_name(&ex)) | |
555 | { | |
556 | errmsg = "invalid system register name"; | |
557 | goto error; | |
558 | } | |
559 | } | |
88b47a85 JL |
560 | else if ((operand->flags & V850_OPERAND_EP) != 0) |
561 | { | |
562 | char *start = input_line_pointer; | |
563 | char c = get_symbol_end (); | |
564 | if (strcmp (start, "ep") != 0 | |
565 | && strcmp (start, "r30") != 0) | |
566 | { | |
567 | /* Put things back the way we found them. */ | |
568 | *input_line_pointer = c; | |
569 | input_line_pointer = start; | |
570 | errmsg = "expected EP register"; | |
571 | goto error; | |
572 | } | |
573 | *input_line_pointer = c; | |
574 | str = input_line_pointer; | |
575 | input_line_pointer = hold; | |
576 | ||
577 | while (*str == ' ' || *str == ',' || *str == '[' || *str == ']') | |
578 | ++str; | |
579 | continue; | |
580 | } | |
c9f1b2d9 JL |
581 | else if ((operand->flags & V850_OPERAND_CC) != 0) |
582 | { | |
583 | if (!cc_name(&ex)) | |
584 | { | |
585 | errmsg = "invalid condition code name"; | |
586 | goto error; | |
587 | } | |
588 | } | |
1510cd39 C |
589 | else if (strncmp(input_line_pointer, "lo(", 3) == 0) |
590 | { | |
591 | input_line_pointer += 3; | |
592 | expression(&ex); | |
c6aa56bc | 593 | |
1510cd39 C |
594 | if (*input_line_pointer++ != ')') |
595 | { | |
596 | errmsg = "syntax error: expected `)'"; | |
597 | goto error; | |
598 | } | |
599 | ||
600 | if (ex.X_op == O_constant) | |
601 | ex.X_add_number &= 0xffff; | |
602 | else | |
603 | { | |
604 | if (fc > MAX_INSN_FIXUPS) | |
605 | as_fatal ("too many fixups"); | |
606 | ||
607 | fixups[fc].exp = ex; | |
608 | fixups[fc].opindex = *opindex_ptr; | |
609 | fixups[fc].reloc = BFD_RELOC_LO16; | |
610 | fc++; | |
611 | } | |
612 | } | |
613 | else if (strncmp(input_line_pointer, "hi(", 3) == 0) | |
614 | { | |
615 | input_line_pointer += 3; | |
616 | expression(&ex); | |
c6aa56bc | 617 | |
1510cd39 C |
618 | if (*input_line_pointer++ != ')') |
619 | { | |
620 | errmsg = "syntax error: expected `)'"; | |
621 | goto error; | |
622 | } | |
623 | ||
624 | if (ex.X_op == O_constant) | |
625 | ex.X_add_number = (ex.X_add_number >> 16) & 0xffff; | |
626 | else | |
627 | { | |
628 | if (fc > MAX_INSN_FIXUPS) | |
629 | as_fatal ("too many fixups"); | |
630 | ||
631 | fixups[fc].exp = ex; | |
632 | fixups[fc].opindex = *opindex_ptr; | |
633 | fixups[fc].reloc = BFD_RELOC_HI16; | |
634 | fc++; | |
635 | } | |
636 | } | |
c9a32d6c JL |
637 | else if (register_name (&ex) |
638 | && (operand->flags & V850_OPERAND_REG) == 0) | |
639 | { | |
640 | errmsg = "syntax error: register not expected"; | |
641 | goto error; | |
642 | } | |
0e8f9bd1 JL |
643 | else if (system_register_name (&ex) |
644 | && (operand->flags & V850_OPERAND_SRG) == 0) | |
645 | { | |
646 | errmsg = "syntax error: system register not expected"; | |
647 | goto error; | |
648 | } | |
c9f1b2d9 JL |
649 | else if (cc_name (&ex) |
650 | && (operand->flags & V850_OPERAND_CC) == 0) | |
651 | { | |
652 | errmsg = "syntax error: condition code not expected"; | |
653 | goto error; | |
654 | } | |
1510cd39 C |
655 | else |
656 | { | |
657 | expression(&ex); | |
658 | } | |
c6aa56bc | 659 | |
1510cd39 C |
660 | str = input_line_pointer; |
661 | input_line_pointer = hold; | |
c6aa56bc | 662 | |
1510cd39 C |
663 | switch (ex.X_op) |
664 | { | |
665 | case O_illegal: | |
666 | errmsg = "illegal operand"; | |
667 | goto error; | |
668 | case O_absent: | |
669 | errmsg = "missing operand"; | |
670 | goto error; | |
671 | case O_register: | |
0e8f9bd1 | 672 | if ((operand->flags & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0) |
1510cd39 C |
673 | { |
674 | errmsg = "invalid operand"; | |
675 | goto error; | |
676 | } | |
677 | ||
678 | insn = v850_insert_operand (insn, operand, ex.X_add_number, | |
679 | (char *) NULL, 0); | |
680 | break; | |
681 | ||
682 | case O_constant: | |
683 | insn = v850_insert_operand (insn, operand, ex.X_add_number, | |
684 | (char *) NULL, 0); | |
685 | break; | |
686 | ||
687 | default: | |
688 | /* We need to generate a fixup for this expression. */ | |
689 | if (fc >= MAX_INSN_FIXUPS) | |
690 | as_fatal ("too many fixups"); | |
691 | fixups[fc].exp = ex; | |
692 | fixups[fc].opindex = *opindex_ptr; | |
693 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
694 | ++fc; | |
695 | break; | |
696 | } | |
697 | ||
698 | while (*str == ' ' || *str == ',' || *str == '[' || *str == ']') | |
699 | ++str; | |
700 | } | |
701 | match = 1; | |
702 | ||
703 | error: | |
704 | if (match == 0) | |
705 | { | |
706 | next_opcode = opcode + 1; | |
707 | if (next_opcode->opcode != 0 && !strcmp(next_opcode->name, opcode->name)) | |
708 | { | |
709 | opcode = next_opcode; | |
710 | continue; | |
711 | } | |
712 | ||
713 | as_bad ("%s", errmsg); | |
714 | return; | |
715 | } | |
716 | break; | |
717 | } | |
718 | ||
c6aa56bc C |
719 | while (isspace (*str)) |
720 | ++str; | |
721 | ||
722 | if (*str != '\0') | |
723 | as_bad ("junk at end of line: `%s'", str); | |
1510cd39 C |
724 | |
725 | input_line_pointer = str; | |
c6aa56bc | 726 | |
c9a32d6c JL |
727 | f = frag_more (opcode->size); |
728 | md_number_to_chars (f, insn, opcode->size); | |
c6aa56bc C |
729 | } |
730 | ||
731 | ||
732 | /* if while processing a fixup, a reloc really needs to be created */ | |
733 | /* then it is done here */ | |
734 | ||
735 | arelent * | |
736 | tc_gen_reloc (seg, fixp) | |
737 | asection *seg; | |
738 | fixS *fixp; | |
739 | { | |
740 | arelent *reloc; | |
741 | reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent)); | |
742 | reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym; | |
743 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
744 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
745 | if (reloc->howto == (reloc_howto_type *) NULL) | |
746 | { | |
747 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
748 | "reloc %d not supported by object file format", (int)fixp->fx_r_type); | |
749 | return NULL; | |
750 | } | |
751 | reloc->addend = fixp->fx_addnumber; | |
752 | /* printf("tc_gen_reloc: addr=%x addend=%x\n", reloc->address, reloc->addend); */ | |
753 | return reloc; | |
754 | } | |
755 | ||
756 | int | |
757 | md_estimate_size_before_relax (fragp, seg) | |
758 | fragS *fragp; | |
759 | asection *seg; | |
760 | { | |
761 | abort (); | |
762 | return 0; | |
763 | } | |
764 | ||
765 | long | |
766 | md_pcrel_from_section (fixp, sec) | |
767 | fixS *fixp; | |
768 | segT sec; | |
769 | { | |
770 | return 0; | |
771 | /* return fixp->fx_frag->fr_address + fixp->fx_where; */ | |
772 | } | |
773 | ||
774 | int | |
775 | md_apply_fix3 (fixp, valuep, seg) | |
776 | fixS *fixp; | |
777 | valueT *valuep; | |
778 | segT seg; | |
779 | { | |
88b47a85 JL |
780 | as_tsktsk ("relocations not supported yet.\n"); |
781 | fixp->fx_done = 1; | |
782 | return 1; | |
c6aa56bc C |
783 | abort(); |
784 | #if 0 | |
785 | valueT value; | |
786 | char *where; | |
787 | unsigned long insn; | |
788 | int op_type; | |
789 | ||
790 | if (fixp->fx_addsy == (symbolS *) NULL) | |
791 | { | |
792 | value = *valuep; | |
793 | fixp->fx_done = 1; | |
794 | } | |
795 | else if (fixp->fx_pcrel) | |
796 | value = *valuep; | |
797 | else | |
798 | { | |
799 | value = fixp->fx_offset; | |
800 | if (fixp->fx_subsy != (symbolS *) NULL) | |
801 | { | |
802 | if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section) | |
803 | value -= S_GET_VALUE (fixp->fx_subsy); | |
804 | else | |
805 | { | |
806 | /* We don't actually support subtracting a symbol. */ | |
807 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
808 | "expression too complex"); | |
809 | } | |
810 | } | |
811 | } | |
812 | ||
813 | /* printf("md_apply_fix: value=0x%x type=%d\n", value, fixp->fx_r_type); */ | |
814 | ||
815 | op_type = fixp->fx_r_type; | |
816 | fixp->fx_r_type = get_reloc((struct v850_operand *)&v850_operands[op_type]); | |
817 | ||
818 | /* printf("reloc=%d\n",fixp->fx_r_type); */ | |
819 | ||
820 | /* Fetch the instruction, insert the fully resolved operand | |
821 | value, and stuff the instruction back again. */ | |
822 | where = fixp->fx_frag->fr_literal + fixp->fx_where; | |
823 | insn = bfd_getb32 ((unsigned char *) where); | |
824 | /* printf(" insn=%x value=%x\n",insn,value); */ | |
825 | ||
826 | insn = v850_insert_operand (insn, op_type, (offsetT) value); | |
827 | ||
828 | /* printf(" new insn=%x\n",insn); */ | |
829 | ||
830 | bfd_putb32 ((bfd_vma) insn, (unsigned char *) where); | |
831 | ||
832 | if (fixp->fx_done) | |
833 | return 1; | |
834 | ||
835 | fixp->fx_addnumber = value; | |
836 | return 1; | |
837 | #endif | |
838 | } | |
839 | ||
840 | \f | |
841 | /* Insert an operand value into an instruction. */ | |
842 | ||
843 | static unsigned long | |
844 | v850_insert_operand (insn, operand, val, file, line) | |
845 | unsigned long insn; | |
846 | const struct v850_operand *operand; | |
847 | offsetT val; | |
848 | char *file; | |
849 | unsigned int line; | |
850 | { | |
851 | if (operand->bits != 32) | |
852 | { | |
853 | long min, max; | |
854 | offsetT test; | |
855 | ||
1510cd39 | 856 | if ((operand->flags & V850_OPERAND_SIGNED) != 0) |
c6aa56bc | 857 | { |
1510cd39 | 858 | #if 0 |
c6aa56bc C |
859 | if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0 |
860 | && ppc_size == PPC_OPCODE_32) | |
861 | max = (1 << operand->bits) - 1; | |
862 | else | |
1510cd39 | 863 | #endif |
c6aa56bc C |
864 | max = (1 << (operand->bits - 1)) - 1; |
865 | min = - (1 << (operand->bits - 1)); | |
866 | } | |
867 | else | |
c6aa56bc C |
868 | { |
869 | max = (1 << operand->bits) - 1; | |
870 | min = 0; | |
871 | } | |
872 | ||
873 | #if 0 | |
874 | if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0) | |
875 | test = - val; | |
876 | else | |
877 | #endif | |
878 | test = val; | |
879 | ||
880 | ||
881 | if (test < (offsetT) min || test > (offsetT) max) | |
882 | { | |
883 | const char *err = | |
884 | "operand out of range (%s not between %ld and %ld)"; | |
885 | char buf[100]; | |
886 | ||
887 | sprint_value (buf, test); | |
888 | if (file == (char *) NULL) | |
889 | as_warn (err, buf, min, max); | |
890 | else | |
891 | as_warn_where (file, line, err, buf, min, max); | |
892 | } | |
893 | } | |
894 | ||
895 | insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift); | |
896 | return insn; | |
897 | } |