tc-tic30.c revision 1.5 1 1.1 christos /* tc-c30.c -- Assembly code for the Texas Instruments TMS320C30
2 1.5 christos Copyright (C) 1998-2016 Free Software Foundation, Inc.
3 1.1 christos Contributed by Steven Haworth (steve (at) pm.cse.rmit.edu.au)
4 1.1 christos
5 1.1 christos This file is part of GAS, the GNU Assembler.
6 1.1 christos
7 1.1 christos GAS is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3, or (at your option)
10 1.1 christos any later version.
11 1.1 christos
12 1.1 christos GAS is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with GAS; see the file COPYING. If not, write to the Free
19 1.1 christos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 1.1 christos 02110-1301, USA. */
21 1.1 christos
22 1.1 christos /* Texas Instruments TMS320C30 machine specific gas.
23 1.1 christos Written by Steven Haworth (steve (at) pm.cse.rmit.edu.au).
24 1.1 christos Bugs & suggestions are completely welcome. This is free software.
25 1.1 christos Please help us make it better. */
26 1.1 christos
27 1.1 christos #include "as.h"
28 1.1 christos #include "safe-ctype.h"
29 1.1 christos #include "opcode/tic30.h"
30 1.1 christos
31 1.1 christos /* Put here all non-digit non-letter characters that may occur in an
32 1.1 christos operand. */
33 1.1 christos static char operand_special_chars[] = "%$-+(,)*._~/<>&^!:[@]";
34 1.5 christos static const char *ordinal_names[] =
35 1.1 christos {
36 1.1 christos N_("first"), N_("second"), N_("third"), N_("fourth"), N_("fifth")
37 1.1 christos };
38 1.1 christos
39 1.1 christos const char comment_chars[] = ";";
40 1.1 christos const char line_comment_chars[] = "*";
41 1.1 christos const char line_separator_chars[] = "";
42 1.1 christos
43 1.1 christos const char *md_shortopts = "";
44 1.1 christos struct option md_longopts[] =
45 1.1 christos {
46 1.1 christos {NULL, no_argument, NULL, 0}
47 1.1 christos };
48 1.1 christos
49 1.1 christos size_t md_longopts_size = sizeof (md_longopts);
50 1.1 christos
51 1.1 christos /* Chars that mean this number is a floating point constant.
52 1.1 christos As in 0f12.456
53 1.1 christos or 0d1.2345e12. */
54 1.1 christos const char FLT_CHARS[] = "fFdDxX";
55 1.1 christos
56 1.1 christos /* Chars that can be used to separate mant from exp in floating point
57 1.1 christos nums. */
58 1.1 christos const char EXP_CHARS[] = "eE";
59 1.1 christos
60 1.1 christos /* Tables for lexical analysis. */
61 1.1 christos static char opcode_chars[256];
62 1.1 christos static char register_chars[256];
63 1.1 christos static char operand_chars[256];
64 1.1 christos static char space_chars[256];
65 1.1 christos static char identifier_chars[256];
66 1.1 christos static char digit_chars[256];
67 1.1 christos
68 1.1 christos /* Lexical macros. */
69 1.1 christos #define is_opcode_char(x) (opcode_chars [(unsigned char) x])
70 1.1 christos #define is_operand_char(x) (operand_chars [(unsigned char) x])
71 1.1 christos #define is_register_char(x) (register_chars [(unsigned char) x])
72 1.1 christos #define is_space_char(x) (space_chars [(unsigned char) x])
73 1.1 christos #define is_identifier_char(x) (identifier_chars [(unsigned char) x])
74 1.1 christos #define is_digit_char(x) (digit_chars [(unsigned char) x])
75 1.1 christos
76 1.1 christos const pseudo_typeS md_pseudo_table[] =
77 1.1 christos {
78 1.1 christos {0, 0, 0}
79 1.1 christos };
80 1.1 christos
81 1.1 christos static int ATTRIBUTE_PRINTF_1
82 1.1 christos debug (const char *string, ...)
83 1.1 christos {
84 1.1 christos if (flag_debug)
85 1.1 christos {
86 1.1 christos char str[100];
87 1.3 christos va_list argptr;
88 1.1 christos
89 1.3 christos va_start (argptr, string);
90 1.1 christos vsprintf (str, string, argptr);
91 1.3 christos va_end (argptr);
92 1.1 christos if (str[0] == '\0')
93 1.1 christos return (0);
94 1.1 christos fputs (str, USE_STDOUT ? stdout : stderr);
95 1.1 christos return strlen (str);
96 1.1 christos }
97 1.1 christos else
98 1.1 christos return 0;
99 1.1 christos }
100 1.1 christos
101 1.1 christos /* Hash table for opcode lookup. */
102 1.1 christos static struct hash_control *op_hash;
103 1.1 christos /* Hash table for parallel opcode lookup. */
104 1.1 christos static struct hash_control *parop_hash;
105 1.1 christos /* Hash table for register lookup. */
106 1.1 christos static struct hash_control *reg_hash;
107 1.1 christos /* Hash table for indirect addressing lookup. */
108 1.1 christos static struct hash_control *ind_hash;
109 1.1 christos
110 1.1 christos void
111 1.1 christos md_begin (void)
112 1.1 christos {
113 1.1 christos const char *hash_err;
114 1.1 christos
115 1.1 christos debug ("In md_begin()\n");
116 1.1 christos op_hash = hash_new ();
117 1.1 christos
118 1.1 christos {
119 1.1 christos const insn_template *current_optab = tic30_optab;
120 1.1 christos
121 1.1 christos for (; current_optab < tic30_optab_end; current_optab++)
122 1.1 christos {
123 1.1 christos hash_err = hash_insert (op_hash, current_optab->name,
124 1.1 christos (char *) current_optab);
125 1.1 christos if (hash_err)
126 1.1 christos as_fatal ("Internal Error: Can't Hash %s: %s",
127 1.1 christos current_optab->name, hash_err);
128 1.1 christos }
129 1.1 christos }
130 1.1 christos
131 1.1 christos parop_hash = hash_new ();
132 1.1 christos
133 1.1 christos {
134 1.1 christos const partemplate *current_parop = tic30_paroptab;
135 1.1 christos
136 1.1 christos for (; current_parop < tic30_paroptab_end; current_parop++)
137 1.1 christos {
138 1.1 christos hash_err = hash_insert (parop_hash, current_parop->name,
139 1.1 christos (char *) current_parop);
140 1.1 christos if (hash_err)
141 1.1 christos as_fatal ("Internal Error: Can't Hash %s: %s",
142 1.1 christos current_parop->name, hash_err);
143 1.1 christos }
144 1.1 christos }
145 1.1 christos
146 1.1 christos reg_hash = hash_new ();
147 1.1 christos
148 1.1 christos {
149 1.1 christos const reg *current_reg = tic30_regtab;
150 1.1 christos
151 1.1 christos for (; current_reg < tic30_regtab_end; current_reg++)
152 1.1 christos {
153 1.1 christos hash_err = hash_insert (reg_hash, current_reg->name,
154 1.1 christos (char *) current_reg);
155 1.1 christos if (hash_err)
156 1.1 christos as_fatal ("Internal Error: Can't Hash %s: %s",
157 1.1 christos current_reg->name, hash_err);
158 1.1 christos }
159 1.1 christos }
160 1.1 christos
161 1.1 christos ind_hash = hash_new ();
162 1.1 christos
163 1.1 christos {
164 1.1 christos const ind_addr_type *current_ind = tic30_indaddr_tab;
165 1.1 christos
166 1.1 christos for (; current_ind < tic30_indaddrtab_end; current_ind++)
167 1.1 christos {
168 1.1 christos hash_err = hash_insert (ind_hash, current_ind->syntax,
169 1.1 christos (char *) current_ind);
170 1.1 christos if (hash_err)
171 1.1 christos as_fatal ("Internal Error: Can't Hash %s: %s",
172 1.1 christos current_ind->syntax, hash_err);
173 1.1 christos }
174 1.1 christos }
175 1.1 christos
176 1.1 christos /* Fill in lexical tables: opcode_chars, operand_chars, space_chars. */
177 1.1 christos {
178 1.1 christos int c;
179 1.1 christos char *p;
180 1.1 christos
181 1.1 christos for (c = 0; c < 256; c++)
182 1.1 christos {
183 1.1 christos if (ISLOWER (c) || ISDIGIT (c))
184 1.1 christos {
185 1.1 christos opcode_chars[c] = c;
186 1.1 christos register_chars[c] = c;
187 1.1 christos }
188 1.1 christos else if (ISUPPER (c))
189 1.1 christos {
190 1.1 christos opcode_chars[c] = TOLOWER (c);
191 1.1 christos register_chars[c] = opcode_chars[c];
192 1.1 christos }
193 1.1 christos else if (c == ')' || c == '(')
194 1.1 christos register_chars[c] = c;
195 1.1 christos
196 1.1 christos if (ISUPPER (c) || ISLOWER (c) || ISDIGIT (c))
197 1.1 christos operand_chars[c] = c;
198 1.1 christos
199 1.1 christos if (ISDIGIT (c) || c == '-')
200 1.1 christos digit_chars[c] = c;
201 1.1 christos
202 1.1 christos if (ISALPHA (c) || c == '_' || c == '.' || ISDIGIT (c))
203 1.1 christos identifier_chars[c] = c;
204 1.1 christos
205 1.1 christos if (c == ' ' || c == '\t')
206 1.1 christos space_chars[c] = c;
207 1.1 christos
208 1.1 christos if (c == '_')
209 1.1 christos opcode_chars[c] = c;
210 1.1 christos }
211 1.1 christos for (p = operand_special_chars; *p != '\0'; p++)
212 1.1 christos operand_chars[(unsigned char) *p] = *p;
213 1.1 christos }
214 1.1 christos }
215 1.1 christos
216 1.1 christos /* Address Mode OR values. */
217 1.1 christos #define AM_Register 0x00000000
218 1.1 christos #define AM_Direct 0x00200000
219 1.1 christos #define AM_Indirect 0x00400000
220 1.1 christos #define AM_Immediate 0x00600000
221 1.1 christos #define AM_NotReq 0xFFFFFFFF
222 1.1 christos
223 1.1 christos /* PC Relative OR values. */
224 1.1 christos #define PC_Register 0x00000000
225 1.1 christos #define PC_Relative 0x02000000
226 1.1 christos
227 1.1 christos typedef struct
228 1.1 christos {
229 1.1 christos unsigned op_type;
230 1.1 christos struct
231 1.1 christos {
232 1.1 christos int resolved;
233 1.1 christos unsigned address;
234 1.1 christos char *label;
235 1.1 christos expressionS direct_expr;
236 1.1 christos } direct;
237 1.1 christos struct
238 1.1 christos {
239 1.1 christos unsigned mod;
240 1.1 christos int ARnum;
241 1.1 christos unsigned char disp;
242 1.1 christos } indirect;
243 1.1 christos struct
244 1.1 christos {
245 1.1 christos unsigned opcode;
246 1.1 christos } reg;
247 1.1 christos struct
248 1.1 christos {
249 1.1 christos int resolved;
250 1.1 christos int decimal_found;
251 1.1 christos float f_number;
252 1.1 christos int s_number;
253 1.1 christos unsigned int u_number;
254 1.1 christos char *label;
255 1.1 christos expressionS imm_expr;
256 1.1 christos } immediate;
257 1.1 christos } operand;
258 1.1 christos
259 1.1 christos insn_template *opcode;
260 1.1 christos
261 1.1 christos struct tic30_insn
262 1.1 christos {
263 1.1 christos insn_template *tm; /* Template of current instruction. */
264 1.1 christos unsigned opcode; /* Final opcode. */
265 1.1 christos unsigned int operands; /* Number of given operands. */
266 1.1 christos /* Type of operand given in instruction. */
267 1.1 christos operand *operand_type[MAX_OPERANDS];
268 1.1 christos unsigned addressing_mode; /* Final addressing mode of instruction. */
269 1.1 christos };
270 1.1 christos
271 1.1 christos struct tic30_insn insn;
272 1.1 christos static int found_parallel_insn;
273 1.1 christos
274 1.1 christos static char output_invalid_buf[sizeof (unsigned char) * 2 + 6];
275 1.1 christos
276 1.1 christos static char *
277 1.1 christos output_invalid (char c)
278 1.1 christos {
279 1.1 christos if (ISPRINT (c))
280 1.1 christos snprintf (output_invalid_buf, sizeof (output_invalid_buf),
281 1.1 christos "'%c'", c);
282 1.1 christos else
283 1.3 christos snprintf (output_invalid_buf, sizeof (output_invalid_buf),
284 1.1 christos "(0x%x)", (unsigned char) c);
285 1.1 christos return output_invalid_buf;
286 1.1 christos }
287 1.1 christos
288 1.1 christos /* next_line points to the next line after the current instruction
289 1.1 christos (current_line). Search for the parallel bars, and if found, merge two
290 1.1 christos lines into internal syntax for a parallel instruction:
291 1.1 christos q_[INSN1]_[INSN2] [OPERANDS1] | [OPERANDS2]
292 1.1 christos By this stage, all comments are scrubbed, and only the bare lines are
293 1.1 christos given. */
294 1.1 christos
295 1.1 christos #define NONE 0
296 1.1 christos #define START_OPCODE 1
297 1.1 christos #define END_OPCODE 2
298 1.1 christos #define START_OPERANDS 3
299 1.1 christos #define END_OPERANDS 4
300 1.1 christos
301 1.1 christos static char *
302 1.1 christos tic30_find_parallel_insn (char *current_line, char *next_line)
303 1.1 christos {
304 1.1 christos int found_parallel = 0;
305 1.1 christos char first_opcode[256];
306 1.1 christos char second_opcode[256];
307 1.1 christos char first_operands[256];
308 1.1 christos char second_operands[256];
309 1.1 christos char *parallel_insn;
310 1.1 christos
311 1.1 christos debug ("In tic30_find_parallel_insn()\n");
312 1.1 christos while (!is_end_of_line[(unsigned char) *next_line])
313 1.1 christos {
314 1.1 christos if (*next_line == PARALLEL_SEPARATOR
315 1.1 christos && *(next_line + 1) == PARALLEL_SEPARATOR)
316 1.1 christos {
317 1.1 christos found_parallel = 1;
318 1.1 christos next_line++;
319 1.1 christos break;
320 1.1 christos }
321 1.1 christos next_line++;
322 1.1 christos }
323 1.1 christos if (!found_parallel)
324 1.1 christos return NULL;
325 1.1 christos debug ("Found a parallel instruction\n");
326 1.1 christos
327 1.1 christos {
328 1.1 christos int i;
329 1.1 christos char *op, *operands, *line;
330 1.1 christos
331 1.1 christos for (i = 0; i < 2; i++)
332 1.1 christos {
333 1.1 christos if (i == 0)
334 1.1 christos {
335 1.1 christos op = &first_opcode[0];
336 1.1 christos operands = &first_operands[0];
337 1.1 christos line = current_line;
338 1.1 christos }
339 1.1 christos else
340 1.1 christos {
341 1.1 christos op = &second_opcode[0];
342 1.1 christos operands = &second_operands[0];
343 1.1 christos line = next_line;
344 1.1 christos }
345 1.1 christos
346 1.1 christos {
347 1.1 christos int search_status = NONE;
348 1.1 christos int char_ptr = 0;
349 1.1 christos char c;
350 1.1 christos
351 1.1 christos while (!is_end_of_line[(unsigned char) (c = *line)])
352 1.1 christos {
353 1.1 christos if (is_opcode_char (c) && search_status == NONE)
354 1.1 christos {
355 1.1 christos op[char_ptr++] = TOLOWER (c);
356 1.1 christos search_status = START_OPCODE;
357 1.1 christos }
358 1.1 christos else if (is_opcode_char (c) && search_status == START_OPCODE)
359 1.1 christos op[char_ptr++] = TOLOWER (c);
360 1.1 christos else if (!is_opcode_char (c) && search_status == START_OPCODE)
361 1.1 christos {
362 1.1 christos op[char_ptr] = '\0';
363 1.1 christos char_ptr = 0;
364 1.1 christos search_status = END_OPCODE;
365 1.1 christos }
366 1.1 christos else if (is_operand_char (c) && search_status == START_OPERANDS)
367 1.1 christos operands[char_ptr++] = c;
368 1.1 christos
369 1.1 christos if (is_operand_char (c) && search_status == END_OPCODE)
370 1.1 christos {
371 1.1 christos operands[char_ptr++] = c;
372 1.1 christos search_status = START_OPERANDS;
373 1.1 christos }
374 1.1 christos
375 1.1 christos line++;
376 1.1 christos }
377 1.1 christos if (search_status != START_OPERANDS)
378 1.1 christos return NULL;
379 1.1 christos operands[char_ptr] = '\0';
380 1.1 christos }
381 1.1 christos }
382 1.1 christos }
383 1.5 christos
384 1.5 christos parallel_insn = concat ("q_", first_opcode, "_", second_opcode, " ",
385 1.5 christos first_operands, " | ", second_operands,
386 1.5 christos (char *) NULL);
387 1.1 christos debug ("parallel insn = %s\n", parallel_insn);
388 1.1 christos return parallel_insn;
389 1.1 christos }
390 1.1 christos
391 1.1 christos #undef NONE
392 1.1 christos #undef START_OPCODE
393 1.1 christos #undef END_OPCODE
394 1.1 christos #undef START_OPERANDS
395 1.1 christos #undef END_OPERANDS
396 1.1 christos
397 1.1 christos static operand *
398 1.1 christos tic30_operand (char *token)
399 1.1 christos {
400 1.1 christos unsigned int count;
401 1.1 christos operand *current_op;
402 1.1 christos
403 1.1 christos debug ("In tic30_operand with %s\n", token);
404 1.5 christos current_op = XCNEW (operand);
405 1.1 christos
406 1.1 christos if (*token == DIRECT_REFERENCE)
407 1.1 christos {
408 1.1 christos char *token_posn = token + 1;
409 1.1 christos int direct_label = 0;
410 1.1 christos
411 1.1 christos debug ("Found direct reference\n");
412 1.1 christos while (*token_posn)
413 1.1 christos {
414 1.1 christos if (!is_digit_char (*token_posn))
415 1.1 christos direct_label = 1;
416 1.1 christos token_posn++;
417 1.1 christos }
418 1.1 christos
419 1.1 christos if (direct_label)
420 1.1 christos {
421 1.1 christos char *save_input_line_pointer;
422 1.1 christos segT retval;
423 1.1 christos
424 1.1 christos debug ("Direct reference is a label\n");
425 1.1 christos current_op->direct.label = token + 1;
426 1.1 christos save_input_line_pointer = input_line_pointer;
427 1.1 christos input_line_pointer = token + 1;
428 1.1 christos debug ("Current input_line_pointer: %s\n", input_line_pointer);
429 1.1 christos retval = expression (¤t_op->direct.direct_expr);
430 1.1 christos
431 1.1 christos debug ("Expression type: %d\n",
432 1.1 christos current_op->direct.direct_expr.X_op);
433 1.1 christos debug ("Expression addnum: %ld\n",
434 1.1 christos (long) current_op->direct.direct_expr.X_add_number);
435 1.1 christos debug ("Segment: %p\n", retval);
436 1.1 christos
437 1.1 christos input_line_pointer = save_input_line_pointer;
438 1.1 christos
439 1.1 christos if (current_op->direct.direct_expr.X_op == O_constant)
440 1.1 christos {
441 1.1 christos current_op->direct.address =
442 1.1 christos current_op->direct.direct_expr.X_add_number;
443 1.1 christos current_op->direct.resolved = 1;
444 1.1 christos }
445 1.1 christos }
446 1.1 christos else
447 1.1 christos {
448 1.1 christos debug ("Direct reference is a number\n");
449 1.1 christos current_op->direct.address = atoi (token + 1);
450 1.1 christos current_op->direct.resolved = 1;
451 1.1 christos }
452 1.1 christos current_op->op_type = Direct;
453 1.1 christos }
454 1.1 christos else if (*token == INDIRECT_REFERENCE)
455 1.1 christos {
456 1.1 christos /* Indirect reference operand. */
457 1.1 christos int found_ar = 0;
458 1.1 christos int found_disp = 0;
459 1.1 christos int ar_number = -1;
460 1.1 christos int disp_number = 0;
461 1.1 christos int buffer_posn = 1;
462 1.1 christos ind_addr_type *ind_addr_op;
463 1.5 christos char * ind_buffer;
464 1.5 christos
465 1.5 christos ind_buffer = XNEWVEC (char, strlen (token));
466 1.1 christos
467 1.1 christos debug ("Found indirect reference\n");
468 1.1 christos ind_buffer[0] = *token;
469 1.1 christos
470 1.1 christos for (count = 1; count < strlen (token); count++)
471 1.1 christos {
472 1.1 christos /* Strip operand. */
473 1.1 christos ind_buffer[buffer_posn] = TOLOWER (*(token + count));
474 1.1 christos
475 1.1 christos if ((*(token + count - 1) == 'a' || *(token + count - 1) == 'A')
476 1.1 christos && (*(token + count) == 'r' || *(token + count) == 'R'))
477 1.1 christos {
478 1.1 christos /* AR reference is found, so get its number and remove
479 1.1 christos it from the buffer so it can pass through hash_find(). */
480 1.1 christos if (found_ar)
481 1.1 christos {
482 1.1 christos as_bad (_("More than one AR register found in indirect reference"));
483 1.5 christos free (ind_buffer);
484 1.1 christos return NULL;
485 1.1 christos }
486 1.1 christos if (*(token + count + 1) < '0' || *(token + count + 1) > '7')
487 1.1 christos {
488 1.1 christos as_bad (_("Illegal AR register in indirect reference"));
489 1.5 christos free (ind_buffer);
490 1.1 christos return NULL;
491 1.1 christos }
492 1.1 christos ar_number = *(token + count + 1) - '0';
493 1.1 christos found_ar = 1;
494 1.1 christos count++;
495 1.1 christos }
496 1.1 christos
497 1.1 christos if (*(token + count) == '(')
498 1.1 christos {
499 1.1 christos /* Parenthesis found, so check if a displacement value is
500 1.1 christos inside. If so, get the value and remove it from the
501 1.1 christos buffer. */
502 1.1 christos if (is_digit_char (*(token + count + 1)))
503 1.1 christos {
504 1.1 christos char disp[10];
505 1.1 christos int disp_posn = 0;
506 1.1 christos
507 1.1 christos if (found_disp)
508 1.1 christos {
509 1.1 christos as_bad (_("More than one displacement found in indirect reference"));
510 1.5 christos free (ind_buffer);
511 1.1 christos return NULL;
512 1.1 christos }
513 1.1 christos count++;
514 1.1 christos while (*(token + count) != ')')
515 1.1 christos {
516 1.1 christos if (!is_digit_char (*(token + count)))
517 1.1 christos {
518 1.1 christos as_bad (_("Invalid displacement in indirect reference"));
519 1.5 christos free (ind_buffer);
520 1.1 christos return NULL;
521 1.1 christos }
522 1.1 christos disp[disp_posn++] = *(token + (count++));
523 1.1 christos }
524 1.1 christos disp[disp_posn] = '\0';
525 1.1 christos disp_number = atoi (disp);
526 1.1 christos count--;
527 1.1 christos found_disp = 1;
528 1.1 christos }
529 1.1 christos }
530 1.1 christos buffer_posn++;
531 1.1 christos }
532 1.1 christos
533 1.1 christos ind_buffer[buffer_posn] = '\0';
534 1.1 christos if (!found_ar)
535 1.1 christos {
536 1.1 christos as_bad (_("AR register not found in indirect reference"));
537 1.5 christos free (ind_buffer);
538 1.1 christos return NULL;
539 1.1 christos }
540 1.1 christos
541 1.1 christos ind_addr_op = (ind_addr_type *) hash_find (ind_hash, ind_buffer);
542 1.1 christos if (ind_addr_op)
543 1.1 christos {
544 1.1 christos debug ("Found indirect reference: %s\n", ind_addr_op->syntax);
545 1.1 christos if (ind_addr_op->displacement == IMPLIED_DISP)
546 1.1 christos {
547 1.1 christos found_disp = 1;
548 1.1 christos disp_number = 1;
549 1.1 christos }
550 1.1 christos else if ((ind_addr_op->displacement == DISP_REQUIRED) && !found_disp)
551 1.1 christos {
552 1.1 christos /* Maybe an implied displacement of 1 again. */
553 1.1 christos as_bad (_("required displacement wasn't given in indirect reference"));
554 1.5 christos free (ind_buffer);
555 1.5 christos return NULL;
556 1.1 christos }
557 1.1 christos }
558 1.1 christos else
559 1.1 christos {
560 1.1 christos as_bad (_("illegal indirect reference"));
561 1.5 christos free (ind_buffer);
562 1.1 christos return NULL;
563 1.1 christos }
564 1.1 christos
565 1.1 christos if (found_disp && (disp_number < 0 || disp_number > 255))
566 1.1 christos {
567 1.1 christos as_bad (_("displacement must be an unsigned 8-bit number"));
568 1.5 christos free (ind_buffer);
569 1.1 christos return NULL;
570 1.1 christos }
571 1.1 christos
572 1.1 christos current_op->indirect.mod = ind_addr_op->modfield;
573 1.1 christos current_op->indirect.disp = disp_number;
574 1.1 christos current_op->indirect.ARnum = ar_number;
575 1.1 christos current_op->op_type = Indirect;
576 1.5 christos free (ind_buffer);
577 1.1 christos }
578 1.1 christos else
579 1.1 christos {
580 1.1 christos reg *regop = (reg *) hash_find (reg_hash, token);
581 1.1 christos
582 1.1 christos if (regop)
583 1.1 christos {
584 1.1 christos debug ("Found register operand: %s\n", regop->name);
585 1.1 christos if (regop->regtype == REG_ARn)
586 1.1 christos current_op->op_type = ARn;
587 1.1 christos else if (regop->regtype == REG_Rn)
588 1.1 christos current_op->op_type = Rn;
589 1.1 christos else if (regop->regtype == REG_DP)
590 1.1 christos current_op->op_type = DPReg;
591 1.1 christos else
592 1.1 christos current_op->op_type = OtherReg;
593 1.1 christos current_op->reg.opcode = regop->opcode;
594 1.1 christos }
595 1.1 christos else
596 1.1 christos {
597 1.1 christos if (!is_digit_char (*token)
598 1.1 christos || *(token + 1) == 'x'
599 1.1 christos || strchr (token, 'h'))
600 1.1 christos {
601 1.1 christos char *save_input_line_pointer;
602 1.1 christos segT retval;
603 1.1 christos
604 1.1 christos debug ("Probably a label: %s\n", token);
605 1.5 christos current_op->immediate.label = xstrdup (token);
606 1.1 christos save_input_line_pointer = input_line_pointer;
607 1.1 christos input_line_pointer = token;
608 1.1 christos
609 1.1 christos debug ("Current input_line_pointer: %s\n", input_line_pointer);
610 1.1 christos retval = expression (¤t_op->immediate.imm_expr);
611 1.1 christos debug ("Expression type: %d\n",
612 1.1 christos current_op->immediate.imm_expr.X_op);
613 1.1 christos debug ("Expression addnum: %ld\n",
614 1.1 christos (long) current_op->immediate.imm_expr.X_add_number);
615 1.1 christos debug ("Segment: %p\n", retval);
616 1.1 christos input_line_pointer = save_input_line_pointer;
617 1.1 christos
618 1.1 christos if (current_op->immediate.imm_expr.X_op == O_constant)
619 1.1 christos {
620 1.1 christos current_op->immediate.s_number
621 1.1 christos = current_op->immediate.imm_expr.X_add_number;
622 1.1 christos current_op->immediate.u_number
623 1.1 christos = (unsigned int) current_op->immediate.imm_expr.X_add_number;
624 1.1 christos current_op->immediate.resolved = 1;
625 1.1 christos }
626 1.1 christos }
627 1.1 christos else
628 1.1 christos {
629 1.1 christos debug ("Found a number or displacement\n");
630 1.1 christos for (count = 0; count < strlen (token); count++)
631 1.1 christos if (*(token + count) == '.')
632 1.1 christos current_op->immediate.decimal_found = 1;
633 1.5 christos current_op->immediate.label = xstrdup (token);
634 1.1 christos current_op->immediate.f_number = (float) atof (token);
635 1.1 christos current_op->immediate.s_number = (int) atoi (token);
636 1.1 christos current_op->immediate.u_number = (unsigned int) atoi (token);
637 1.1 christos current_op->immediate.resolved = 1;
638 1.1 christos }
639 1.1 christos current_op->op_type = Disp | Abs24 | Imm16 | Imm24;
640 1.1 christos if (current_op->immediate.u_number <= 31)
641 1.1 christos current_op->op_type |= IVector;
642 1.1 christos }
643 1.1 christos }
644 1.1 christos return current_op;
645 1.1 christos }
646 1.1 christos
647 1.1 christos struct tic30_par_insn
648 1.1 christos {
649 1.1 christos partemplate *tm; /* Template of current parallel instruction. */
650 1.1 christos unsigned operands[2]; /* Number of given operands for each insn. */
651 1.1 christos /* Type of operand given in instruction. */
652 1.1 christos operand *operand_type[2][MAX_OPERANDS];
653 1.1 christos int swap_operands; /* Whether to swap operands around. */
654 1.1 christos unsigned p_field; /* Value of p field in multiply add/sub instructions. */
655 1.1 christos unsigned opcode; /* Final opcode. */
656 1.1 christos };
657 1.1 christos
658 1.1 christos struct tic30_par_insn p_insn;
659 1.1 christos
660 1.1 christos static int
661 1.1 christos tic30_parallel_insn (char *token)
662 1.1 christos {
663 1.1 christos static partemplate *p_opcode;
664 1.1 christos char *current_posn = token;
665 1.1 christos char *token_start;
666 1.1 christos char save_char;
667 1.1 christos
668 1.1 christos debug ("In tic30_parallel_insn with %s\n", token);
669 1.1 christos memset (&p_insn, '\0', sizeof (p_insn));
670 1.1 christos
671 1.1 christos while (is_opcode_char (*current_posn))
672 1.1 christos current_posn++;
673 1.1 christos {
674 1.1 christos /* Find instruction. */
675 1.1 christos save_char = *current_posn;
676 1.1 christos *current_posn = '\0';
677 1.1 christos p_opcode = (partemplate *) hash_find (parop_hash, token);
678 1.1 christos if (p_opcode)
679 1.1 christos {
680 1.1 christos debug ("Found instruction %s\n", p_opcode->name);
681 1.1 christos p_insn.tm = p_opcode;
682 1.1 christos }
683 1.1 christos else
684 1.1 christos {
685 1.1 christos char first_opcode[6] = {0};
686 1.1 christos char second_opcode[6] = {0};
687 1.1 christos unsigned int i;
688 1.1 christos int current_opcode = -1;
689 1.1 christos int char_ptr = 0;
690 1.1 christos
691 1.1 christos for (i = 0; i < strlen (token); i++)
692 1.1 christos {
693 1.1 christos char ch = *(token + i);
694 1.1 christos
695 1.1 christos if (ch == '_' && current_opcode == -1)
696 1.1 christos {
697 1.1 christos current_opcode = 0;
698 1.1 christos continue;
699 1.1 christos }
700 1.1 christos
701 1.1 christos if (ch == '_' && current_opcode == 0)
702 1.1 christos {
703 1.1 christos current_opcode = 1;
704 1.1 christos char_ptr = 0;
705 1.1 christos continue;
706 1.1 christos }
707 1.1 christos
708 1.1 christos switch (current_opcode)
709 1.1 christos {
710 1.1 christos case 0:
711 1.1 christos first_opcode[char_ptr++] = ch;
712 1.1 christos break;
713 1.1 christos case 1:
714 1.1 christos second_opcode[char_ptr++] = ch;
715 1.1 christos break;
716 1.1 christos }
717 1.1 christos }
718 1.1 christos
719 1.1 christos debug ("first_opcode = %s\n", first_opcode);
720 1.1 christos debug ("second_opcode = %s\n", second_opcode);
721 1.1 christos sprintf (token, "q_%s_%s", second_opcode, first_opcode);
722 1.1 christos p_opcode = (partemplate *) hash_find (parop_hash, token);
723 1.1 christos
724 1.1 christos if (p_opcode)
725 1.1 christos {
726 1.1 christos debug ("Found instruction %s\n", p_opcode->name);
727 1.1 christos p_insn.tm = p_opcode;
728 1.1 christos p_insn.swap_operands = 1;
729 1.1 christos }
730 1.1 christos else
731 1.1 christos return 0;
732 1.1 christos }
733 1.1 christos *current_posn = save_char;
734 1.1 christos }
735 1.1 christos
736 1.1 christos {
737 1.1 christos /* Find operands. */
738 1.1 christos int paren_not_balanced;
739 1.1 christos int expecting_operand = 0;
740 1.1 christos int found_separator = 0;
741 1.1 christos
742 1.1 christos do
743 1.1 christos {
744 1.1 christos /* Skip optional white space before operand. */
745 1.1 christos while (!is_operand_char (*current_posn)
746 1.1 christos && *current_posn != END_OF_INSN)
747 1.1 christos {
748 1.1 christos if (!is_space_char (*current_posn)
749 1.1 christos && *current_posn != PARALLEL_SEPARATOR)
750 1.1 christos {
751 1.1 christos as_bad (_("Invalid character %s before %s operand"),
752 1.1 christos output_invalid (*current_posn),
753 1.1 christos ordinal_names[insn.operands]);
754 1.1 christos return 1;
755 1.1 christos }
756 1.1 christos if (*current_posn == PARALLEL_SEPARATOR)
757 1.1 christos found_separator = 1;
758 1.1 christos current_posn++;
759 1.1 christos }
760 1.1 christos
761 1.1 christos token_start = current_posn;
762 1.1 christos paren_not_balanced = 0;
763 1.1 christos
764 1.1 christos while (paren_not_balanced || *current_posn != ',')
765 1.1 christos {
766 1.1 christos if (*current_posn == END_OF_INSN)
767 1.1 christos {
768 1.1 christos if (paren_not_balanced)
769 1.1 christos {
770 1.1 christos as_bad (_("Unbalanced parenthesis in %s operand."),
771 1.1 christos ordinal_names[insn.operands]);
772 1.1 christos return 1;
773 1.1 christos }
774 1.1 christos else
775 1.1 christos break;
776 1.1 christos }
777 1.1 christos else if (*current_posn == PARALLEL_SEPARATOR)
778 1.1 christos {
779 1.1 christos while (is_space_char (*(current_posn - 1)))
780 1.1 christos current_posn--;
781 1.1 christos break;
782 1.1 christos }
783 1.1 christos else if (!is_operand_char (*current_posn)
784 1.1 christos && !is_space_char (*current_posn))
785 1.1 christos {
786 1.1 christos as_bad (_("Invalid character %s in %s operand"),
787 1.1 christos output_invalid (*current_posn),
788 1.1 christos ordinal_names[insn.operands]);
789 1.1 christos return 1;
790 1.1 christos }
791 1.1 christos
792 1.1 christos if (*current_posn == '(')
793 1.1 christos ++paren_not_balanced;
794 1.1 christos if (*current_posn == ')')
795 1.1 christos --paren_not_balanced;
796 1.1 christos current_posn++;
797 1.1 christos }
798 1.1 christos
799 1.1 christos if (current_posn != token_start)
800 1.1 christos {
801 1.1 christos /* Yes, we've read in another operand. */
802 1.1 christos p_insn.operands[found_separator]++;
803 1.1 christos if (p_insn.operands[found_separator] > MAX_OPERANDS)
804 1.1 christos {
805 1.1 christos as_bad (_("Spurious operands; (%d operands/instruction max)"),
806 1.1 christos MAX_OPERANDS);
807 1.1 christos return 1;
808 1.1 christos }
809 1.1 christos
810 1.1 christos /* Now parse operand adding info to 'insn' as we go along. */
811 1.1 christos save_char = *current_posn;
812 1.1 christos *current_posn = '\0';
813 1.1 christos p_insn.operand_type[found_separator][p_insn.operands[found_separator] - 1] =
814 1.1 christos tic30_operand (token_start);
815 1.1 christos *current_posn = save_char;
816 1.1 christos if (!p_insn.operand_type[found_separator][p_insn.operands[found_separator] - 1])
817 1.1 christos return 1;
818 1.1 christos }
819 1.1 christos else
820 1.1 christos {
821 1.1 christos if (expecting_operand)
822 1.1 christos {
823 1.1 christos as_bad (_("Expecting operand after ','; got nothing"));
824 1.1 christos return 1;
825 1.1 christos }
826 1.1 christos if (*current_posn == ',')
827 1.1 christos {
828 1.1 christos as_bad (_("Expecting operand before ','; got nothing"));
829 1.1 christos return 1;
830 1.1 christos }
831 1.1 christos }
832 1.1 christos
833 1.1 christos /* Now *current_posn must be either ',' or END_OF_INSN. */
834 1.1 christos if (*current_posn == ',')
835 1.1 christos {
836 1.1 christos if (*++current_posn == END_OF_INSN)
837 1.1 christos {
838 1.1 christos /* Just skip it, if it's \n complain. */
839 1.1 christos as_bad (_("Expecting operand after ','; got nothing"));
840 1.1 christos return 1;
841 1.1 christos }
842 1.1 christos expecting_operand = 1;
843 1.1 christos }
844 1.1 christos }
845 1.1 christos while (*current_posn != END_OF_INSN);
846 1.1 christos }
847 1.1 christos
848 1.1 christos if (p_insn.swap_operands)
849 1.1 christos {
850 1.1 christos int temp_num, i;
851 1.1 christos operand *temp_op;
852 1.1 christos
853 1.1 christos temp_num = p_insn.operands[0];
854 1.1 christos p_insn.operands[0] = p_insn.operands[1];
855 1.1 christos p_insn.operands[1] = temp_num;
856 1.1 christos for (i = 0; i < MAX_OPERANDS; i++)
857 1.1 christos {
858 1.1 christos temp_op = p_insn.operand_type[0][i];
859 1.1 christos p_insn.operand_type[0][i] = p_insn.operand_type[1][i];
860 1.1 christos p_insn.operand_type[1][i] = temp_op;
861 1.1 christos }
862 1.1 christos }
863 1.1 christos
864 1.1 christos if (p_insn.operands[0] != p_insn.tm->operands_1)
865 1.1 christos {
866 1.1 christos as_bad (_("incorrect number of operands given in the first instruction"));
867 1.1 christos return 1;
868 1.1 christos }
869 1.1 christos
870 1.1 christos if (p_insn.operands[1] != p_insn.tm->operands_2)
871 1.1 christos {
872 1.1 christos as_bad (_("incorrect number of operands given in the second instruction"));
873 1.1 christos return 1;
874 1.1 christos }
875 1.1 christos
876 1.1 christos debug ("Number of operands in first insn: %d\n", p_insn.operands[0]);
877 1.1 christos debug ("Number of operands in second insn: %d\n", p_insn.operands[1]);
878 1.1 christos
879 1.1 christos {
880 1.1 christos /* Now check if operands are correct. */
881 1.1 christos int count;
882 1.1 christos int num_rn = 0;
883 1.1 christos int num_ind = 0;
884 1.1 christos
885 1.1 christos for (count = 0; count < 2; count++)
886 1.1 christos {
887 1.1 christos unsigned int i;
888 1.1 christos for (i = 0; i < p_insn.operands[count]; i++)
889 1.1 christos {
890 1.1 christos if ((p_insn.operand_type[count][i]->op_type &
891 1.1 christos p_insn.tm->operand_types[count][i]) == 0)
892 1.1 christos {
893 1.1 christos as_bad (_("%s instruction, operand %d doesn't match"),
894 1.1 christos ordinal_names[count], i + 1);
895 1.1 christos return 1;
896 1.1 christos }
897 1.1 christos
898 1.1 christos /* Get number of R register and indirect reference contained
899 1.1 christos within the first two operands of each instruction. This is
900 1.1 christos required for the multiply parallel instructions which require
901 1.1 christos two R registers and two indirect references, but not in any
902 1.1 christos particular place. */
903 1.1 christos if ((p_insn.operand_type[count][i]->op_type & Rn) && i < 2)
904 1.1 christos num_rn++;
905 1.1 christos else if ((p_insn.operand_type[count][i]->op_type & Indirect)
906 1.1 christos && i < 2)
907 1.1 christos num_ind++;
908 1.1 christos }
909 1.1 christos }
910 1.1 christos
911 1.1 christos if ((p_insn.tm->operand_types[0][0] & (Indirect | Rn))
912 1.1 christos == (Indirect | Rn))
913 1.1 christos {
914 1.1 christos /* Check for the multiply instructions. */
915 1.1 christos if (num_rn != 2)
916 1.1 christos {
917 1.1 christos as_bad (_("incorrect format for multiply parallel instruction"));
918 1.1 christos return 1;
919 1.1 christos }
920 1.1 christos
921 1.1 christos if (num_ind != 2)
922 1.1 christos {
923 1.1 christos /* Shouldn't get here. */
924 1.1 christos as_bad (_("incorrect format for multiply parallel instruction"));
925 1.1 christos return 1;
926 1.1 christos }
927 1.1 christos
928 1.1 christos if ((p_insn.operand_type[0][2]->reg.opcode != 0x00)
929 1.1 christos && (p_insn.operand_type[0][2]->reg.opcode != 0x01))
930 1.1 christos {
931 1.1 christos as_bad (_("destination for multiply can only be R0 or R1"));
932 1.1 christos return 1;
933 1.1 christos }
934 1.1 christos
935 1.1 christos if ((p_insn.operand_type[1][2]->reg.opcode != 0x02)
936 1.1 christos && (p_insn.operand_type[1][2]->reg.opcode != 0x03))
937 1.1 christos {
938 1.1 christos as_bad (_("destination for add/subtract can only be R2 or R3"));
939 1.1 christos return 1;
940 1.1 christos }
941 1.1 christos
942 1.1 christos /* Now determine the P field for the instruction. */
943 1.1 christos if (p_insn.operand_type[0][0]->op_type & Indirect)
944 1.1 christos {
945 1.1 christos if (p_insn.operand_type[0][1]->op_type & Indirect)
946 1.1 christos p_insn.p_field = 0x00000000; /* Ind * Ind, Rn +/- Rn. */
947 1.1 christos else if (p_insn.operand_type[1][0]->op_type & Indirect)
948 1.1 christos p_insn.p_field = 0x01000000; /* Ind * Rn, Ind +/- Rn. */
949 1.1 christos else
950 1.1 christos p_insn.p_field = 0x03000000; /* Ind * Rn, Rn +/- Ind. */
951 1.1 christos }
952 1.1 christos else
953 1.1 christos {
954 1.1 christos if (p_insn.operand_type[0][1]->op_type & Rn)
955 1.1 christos p_insn.p_field = 0x02000000; /* Rn * Rn, Ind +/- Ind. */
956 1.1 christos else if (p_insn.operand_type[1][0]->op_type & Indirect)
957 1.1 christos {
958 1.1 christos operand *temp;
959 1.1 christos p_insn.p_field = 0x01000000; /* Rn * Ind, Ind +/- Rn. */
960 1.1 christos /* Need to swap the two multiply operands around so that
961 1.1 christos everything is in its place for the opcode makeup.
962 1.1 christos ie so Ind * Rn, Ind +/- Rn. */
963 1.1 christos temp = p_insn.operand_type[0][0];
964 1.1 christos p_insn.operand_type[0][0] = p_insn.operand_type[0][1];
965 1.1 christos p_insn.operand_type[0][1] = temp;
966 1.1 christos }
967 1.1 christos else
968 1.1 christos {
969 1.1 christos operand *temp;
970 1.1 christos p_insn.p_field = 0x03000000; /* Rn * Ind, Rn +/- Ind. */
971 1.1 christos temp = p_insn.operand_type[0][0];
972 1.1 christos p_insn.operand_type[0][0] = p_insn.operand_type[0][1];
973 1.1 christos p_insn.operand_type[0][1] = temp;
974 1.1 christos }
975 1.1 christos }
976 1.1 christos }
977 1.1 christos }
978 1.1 christos
979 1.1 christos debug ("P field: %08X\n", p_insn.p_field);
980 1.1 christos
981 1.1 christos /* Finalise opcode. This is easier for parallel instructions as they have
982 1.1 christos to be fully resolved, there are no memory addresses allowed, except
983 1.1 christos through indirect addressing, so there are no labels to resolve. */
984 1.1 christos p_insn.opcode = p_insn.tm->base_opcode;
985 1.1 christos
986 1.1 christos switch (p_insn.tm->oporder)
987 1.1 christos {
988 1.1 christos case OO_4op1:
989 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum);
990 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 3);
991 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
992 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
993 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
994 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 22);
995 1.1 christos break;
996 1.1 christos
997 1.1 christos case OO_4op2:
998 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum);
999 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 3);
1000 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.ARnum << 8);
1001 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.mod << 11);
1002 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->reg.opcode << 19);
1003 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 22);
1004 1.1 christos if (p_insn.operand_type[1][1]->reg.opcode == p_insn.operand_type[0][1]->reg.opcode)
1005 1.1 christos as_warn (_("loading the same register in parallel operation"));
1006 1.1 christos break;
1007 1.1 christos
1008 1.1 christos case OO_4op3:
1009 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.ARnum);
1010 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.mod << 3);
1011 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
1012 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
1013 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
1014 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->reg.opcode << 22);
1015 1.1 christos break;
1016 1.1 christos
1017 1.1 christos case OO_5op1:
1018 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum);
1019 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 3);
1020 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
1021 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
1022 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
1023 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 19);
1024 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][2]->reg.opcode << 22);
1025 1.1 christos break;
1026 1.1 christos
1027 1.1 christos case OO_5op2:
1028 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.ARnum);
1029 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.mod << 3);
1030 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
1031 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
1032 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
1033 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->reg.opcode << 19);
1034 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][2]->reg.opcode << 22);
1035 1.1 christos break;
1036 1.1 christos
1037 1.1 christos case OO_PField:
1038 1.1 christos p_insn.opcode |= p_insn.p_field;
1039 1.1 christos if (p_insn.operand_type[0][2]->reg.opcode == 0x01)
1040 1.1 christos p_insn.opcode |= 0x00800000;
1041 1.1 christos if (p_insn.operand_type[1][2]->reg.opcode == 0x03)
1042 1.1 christos p_insn.opcode |= 0x00400000;
1043 1.1 christos
1044 1.1 christos switch (p_insn.p_field)
1045 1.1 christos {
1046 1.1 christos case 0x00000000:
1047 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.ARnum);
1048 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.mod << 3);
1049 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum << 8);
1050 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 11);
1051 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->reg.opcode << 16);
1052 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 19);
1053 1.1 christos break;
1054 1.1 christos case 0x01000000:
1055 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.ARnum);
1056 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.mod << 3);
1057 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum << 8);
1058 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 11);
1059 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->reg.opcode << 16);
1060 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 19);
1061 1.1 christos break;
1062 1.1 christos case 0x02000000:
1063 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum);
1064 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 3);
1065 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.ARnum << 8);
1066 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.mod << 11);
1067 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 16);
1068 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->reg.opcode << 19);
1069 1.1 christos break;
1070 1.1 christos case 0x03000000:
1071 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum);
1072 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 3);
1073 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum << 8);
1074 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 11);
1075 1.1 christos p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
1076 1.1 christos p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 19);
1077 1.1 christos break;
1078 1.1 christos }
1079 1.1 christos break;
1080 1.1 christos }
1081 1.1 christos
1082 1.1 christos {
1083 1.1 christos char *p;
1084 1.1 christos
1085 1.1 christos p = frag_more (INSN_SIZE);
1086 1.1 christos md_number_to_chars (p, (valueT) p_insn.opcode, INSN_SIZE);
1087 1.1 christos }
1088 1.1 christos
1089 1.1 christos {
1090 1.1 christos unsigned int i, j;
1091 1.1 christos
1092 1.1 christos for (i = 0; i < 2; i++)
1093 1.1 christos for (j = 0; j < p_insn.operands[i]; j++)
1094 1.1 christos free (p_insn.operand_type[i][j]);
1095 1.1 christos }
1096 1.1 christos
1097 1.1 christos debug ("Final opcode: %08X\n", p_insn.opcode);
1098 1.1 christos debug ("\n");
1099 1.1 christos
1100 1.1 christos return 1;
1101 1.1 christos }
1102 1.1 christos
1103 1.1 christos /* In order to get gas to ignore any | chars at the start of a line,
1104 1.1 christos this function returns true if a | is found in a line. */
1105 1.1 christos
1106 1.1 christos int
1107 1.1 christos tic30_unrecognized_line (int c)
1108 1.1 christos {
1109 1.1 christos debug ("In tc_unrecognized_line\n");
1110 1.1 christos return (c == PARALLEL_SEPARATOR);
1111 1.1 christos }
1112 1.1 christos
1113 1.1 christos int
1114 1.1 christos md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1115 1.1 christos segT segment ATTRIBUTE_UNUSED)
1116 1.1 christos {
1117 1.1 christos debug ("In md_estimate_size_before_relax()\n");
1118 1.1 christos return 0;
1119 1.1 christos }
1120 1.1 christos
1121 1.1 christos void
1122 1.1 christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1123 1.1 christos segT sec ATTRIBUTE_UNUSED,
1124 1.3 christos fragS *fragP ATTRIBUTE_UNUSED)
1125 1.1 christos {
1126 1.1 christos debug ("In md_convert_frag()\n");
1127 1.1 christos }
1128 1.1 christos
1129 1.1 christos void
1130 1.1 christos md_apply_fix (fixS *fixP,
1131 1.1 christos valueT *valP,
1132 1.1 christos segT seg ATTRIBUTE_UNUSED)
1133 1.1 christos {
1134 1.1 christos valueT value = *valP;
1135 1.1 christos
1136 1.1 christos debug ("In md_apply_fix() with value = %ld\n", (long) value);
1137 1.1 christos debug ("Values in fixP\n");
1138 1.1 christos debug ("fx_size = %d\n", fixP->fx_size);
1139 1.1 christos debug ("fx_pcrel = %d\n", fixP->fx_pcrel);
1140 1.1 christos debug ("fx_where = %ld\n", fixP->fx_where);
1141 1.1 christos debug ("fx_offset = %d\n", (int) fixP->fx_offset);
1142 1.1 christos {
1143 1.1 christos char *buf = fixP->fx_frag->fr_literal + fixP->fx_where;
1144 1.1 christos
1145 1.1 christos value /= INSN_SIZE;
1146 1.1 christos if (fixP->fx_size == 1)
1147 1.1 christos /* Special fix for LDP instruction. */
1148 1.1 christos value = (value & 0x00FF0000) >> 16;
1149 1.1 christos
1150 1.1 christos debug ("new value = %ld\n", (long) value);
1151 1.1 christos md_number_to_chars (buf, value, fixP->fx_size);
1152 1.1 christos }
1153 1.1 christos
1154 1.1 christos if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1155 1.1 christos fixP->fx_done = 1;
1156 1.1 christos }
1157 1.1 christos
1158 1.1 christos int
1159 1.1 christos md_parse_option (int c ATTRIBUTE_UNUSED,
1160 1.5 christos const char *arg ATTRIBUTE_UNUSED)
1161 1.1 christos {
1162 1.1 christos debug ("In md_parse_option()\n");
1163 1.1 christos return 0;
1164 1.1 christos }
1165 1.1 christos
1166 1.1 christos void
1167 1.1 christos md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
1168 1.1 christos {
1169 1.1 christos debug ("In md_show_usage()\n");
1170 1.1 christos }
1171 1.1 christos
1172 1.1 christos symbolS *
1173 1.1 christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1174 1.1 christos {
1175 1.1 christos debug ("In md_undefined_symbol()\n");
1176 1.1 christos return (symbolS *) 0;
1177 1.1 christos }
1178 1.1 christos
1179 1.1 christos valueT
1180 1.1 christos md_section_align (segT segment, valueT size)
1181 1.1 christos {
1182 1.1 christos debug ("In md_section_align() segment = %p and size = %lu\n",
1183 1.1 christos segment, (unsigned long) size);
1184 1.1 christos size = (size + 3) / 4;
1185 1.1 christos size *= 4;
1186 1.1 christos debug ("New size value = %lu\n", (unsigned long) size);
1187 1.1 christos return size;
1188 1.1 christos }
1189 1.1 christos
1190 1.1 christos long
1191 1.1 christos md_pcrel_from (fixS *fixP)
1192 1.1 christos {
1193 1.1 christos int offset;
1194 1.1 christos
1195 1.1 christos debug ("In md_pcrel_from()\n");
1196 1.1 christos debug ("fx_where = %ld\n", fixP->fx_where);
1197 1.1 christos debug ("fx_size = %d\n", fixP->fx_size);
1198 1.1 christos /* Find the opcode that represents the current instruction in the
1199 1.1 christos fr_literal storage area, and check bit 21. Bit 21 contains whether the
1200 1.1 christos current instruction is a delayed one or not, and then set the offset
1201 1.1 christos value appropriately. */
1202 1.1 christos if (fixP->fx_frag->fr_literal[fixP->fx_where - fixP->fx_size + 1] & 0x20)
1203 1.1 christos offset = 3;
1204 1.1 christos else
1205 1.1 christos offset = 1;
1206 1.1 christos debug ("offset = %d\n", offset);
1207 1.1 christos /* PC Relative instructions have a format:
1208 1.1 christos displacement = Label - (PC + offset)
1209 1.1 christos This function returns PC + offset where:
1210 1.1 christos fx_where - fx_size = PC
1211 1.1 christos INSN_SIZE * offset = offset number of instructions. */
1212 1.1 christos return fixP->fx_where - fixP->fx_size + (INSN_SIZE * offset);
1213 1.1 christos }
1214 1.1 christos
1215 1.5 christos const char *
1216 1.1 christos md_atof (int what_statement_type,
1217 1.1 christos char *literalP,
1218 1.1 christos int *sizeP)
1219 1.1 christos {
1220 1.1 christos int prec;
1221 1.1 christos char *token;
1222 1.1 christos char keepval;
1223 1.1 christos unsigned long value;
1224 1.1 christos float float_value;
1225 1.1 christos
1226 1.1 christos debug ("In md_atof()\n");
1227 1.1 christos debug ("precision = %c\n", what_statement_type);
1228 1.1 christos debug ("literal = %s\n", literalP);
1229 1.1 christos debug ("line = ");
1230 1.1 christos token = input_line_pointer;
1231 1.1 christos while (!is_end_of_line[(unsigned char) *input_line_pointer]
1232 1.1 christos && (*input_line_pointer != ','))
1233 1.1 christos {
1234 1.1 christos debug ("%c", *input_line_pointer);
1235 1.1 christos input_line_pointer++;
1236 1.1 christos }
1237 1.1 christos
1238 1.1 christos keepval = *input_line_pointer;
1239 1.1 christos *input_line_pointer = '\0';
1240 1.1 christos debug ("\n");
1241 1.1 christos float_value = (float) atof (token);
1242 1.1 christos *input_line_pointer = keepval;
1243 1.1 christos debug ("float_value = %f\n", float_value);
1244 1.1 christos
1245 1.1 christos switch (what_statement_type)
1246 1.1 christos {
1247 1.1 christos case 'f':
1248 1.1 christos case 'F':
1249 1.1 christos case 's':
1250 1.1 christos case 'S':
1251 1.1 christos prec = 2;
1252 1.1 christos break;
1253 1.1 christos
1254 1.1 christos case 'd':
1255 1.1 christos case 'D':
1256 1.1 christos case 'r':
1257 1.1 christos case 'R':
1258 1.1 christos prec = 4;
1259 1.1 christos break;
1260 1.1 christos
1261 1.1 christos default:
1262 1.1 christos *sizeP = 0;
1263 1.1 christos return _("Unrecognized or unsupported floating point constant");
1264 1.1 christos }
1265 1.1 christos
1266 1.1 christos if (float_value == 0.0)
1267 1.1 christos value = (prec == 2) ? 0x00008000L : 0x80000000L;
1268 1.1 christos else
1269 1.1 christos {
1270 1.1 christos unsigned long exp, sign, mant, tmsfloat;
1271 1.1 christos union
1272 1.1 christos {
1273 1.1 christos float f;
1274 1.1 christos long l;
1275 1.1 christos }
1276 1.1 christos converter;
1277 1.1 christos
1278 1.1 christos converter.f = float_value;
1279 1.1 christos tmsfloat = converter.l;
1280 1.1 christos sign = tmsfloat & 0x80000000;
1281 1.1 christos mant = tmsfloat & 0x007FFFFF;
1282 1.1 christos exp = tmsfloat & 0x7F800000;
1283 1.1 christos exp <<= 1;
1284 1.1 christos if (exp == 0xFF000000)
1285 1.1 christos {
1286 1.1 christos if (mant == 0)
1287 1.1 christos value = 0x7F7FFFFF;
1288 1.1 christos else if (sign == 0)
1289 1.1 christos value = 0x7F7FFFFF;
1290 1.1 christos else
1291 1.1 christos value = 0x7F800000;
1292 1.1 christos }
1293 1.1 christos else
1294 1.1 christos {
1295 1.1 christos exp -= 0x7F000000;
1296 1.1 christos if (sign)
1297 1.1 christos {
1298 1.1 christos mant = mant & 0x007FFFFF;
1299 1.1 christos mant = -mant;
1300 1.1 christos mant = mant & 0x00FFFFFF;
1301 1.1 christos if (mant == 0)
1302 1.1 christos {
1303 1.1 christos mant |= 0x00800000;
1304 1.1 christos exp = (long) exp - 0x01000000;
1305 1.1 christos }
1306 1.1 christos }
1307 1.1 christos tmsfloat = exp | mant;
1308 1.1 christos value = tmsfloat;
1309 1.1 christos }
1310 1.1 christos if (prec == 2)
1311 1.1 christos {
1312 1.1 christos long expon, mantis;
1313 1.1 christos
1314 1.1 christos if (tmsfloat == 0x80000000)
1315 1.1 christos value = 0x8000;
1316 1.1 christos else
1317 1.1 christos {
1318 1.1 christos value = 0;
1319 1.1 christos expon = (tmsfloat & 0xFF000000);
1320 1.1 christos expon >>= 24;
1321 1.1 christos mantis = tmsfloat & 0x007FFFFF;
1322 1.1 christos if (tmsfloat & 0x00800000)
1323 1.1 christos {
1324 1.1 christos mantis |= 0xFF000000;
1325 1.1 christos mantis += 0x00000800;
1326 1.1 christos mantis >>= 12;
1327 1.1 christos mantis |= 0x00000800;
1328 1.1 christos mantis &= 0x0FFF;
1329 1.1 christos if (expon > 7)
1330 1.1 christos value = 0x7800;
1331 1.1 christos }
1332 1.1 christos else
1333 1.1 christos {
1334 1.1 christos mantis |= 0x00800000;
1335 1.1 christos mantis += 0x00000800;
1336 1.1 christos expon += (mantis >> 24);
1337 1.1 christos mantis >>= 12;
1338 1.1 christos mantis &= 0x07FF;
1339 1.1 christos if (expon > 7)
1340 1.1 christos value = 0x77FF;
1341 1.1 christos }
1342 1.1 christos if (expon < -8)
1343 1.1 christos value = 0x8000;
1344 1.1 christos if (value == 0)
1345 1.1 christos {
1346 1.1 christos mantis = (expon << 12) | mantis;
1347 1.1 christos value = mantis & 0xFFFF;
1348 1.1 christos }
1349 1.1 christos }
1350 1.1 christos }
1351 1.1 christos }
1352 1.1 christos md_number_to_chars (literalP, value, prec);
1353 1.1 christos *sizeP = prec;
1354 1.1 christos return NULL;
1355 1.1 christos }
1356 1.1 christos
1357 1.1 christos void
1358 1.1 christos md_number_to_chars (char *buf, valueT val, int n)
1359 1.1 christos {
1360 1.1 christos debug ("In md_number_to_chars()\n");
1361 1.1 christos number_to_chars_bigendian (buf, val, n);
1362 1.1 christos }
1363 1.1 christos
1364 1.1 christos #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1365 1.1 christos #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1366 1.1 christos
1367 1.1 christos arelent *
1368 1.1 christos tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
1369 1.1 christos {
1370 1.1 christos arelent *rel;
1371 1.1 christos bfd_reloc_code_real_type code = 0;
1372 1.1 christos
1373 1.1 christos debug ("In tc_gen_reloc()\n");
1374 1.1 christos debug ("fixP.size = %d\n", fixP->fx_size);
1375 1.1 christos debug ("fixP.pcrel = %d\n", fixP->fx_pcrel);
1376 1.1 christos debug ("addsy.name = %s\n", S_GET_NAME (fixP->fx_addsy));
1377 1.1 christos
1378 1.1 christos switch (F (fixP->fx_size, fixP->fx_pcrel))
1379 1.1 christos {
1380 1.1 christos MAP (1, 0, BFD_RELOC_TIC30_LDP);
1381 1.1 christos MAP (2, 0, BFD_RELOC_16);
1382 1.1 christos MAP (3, 0, BFD_RELOC_24);
1383 1.1 christos MAP (2, 1, BFD_RELOC_16_PCREL);
1384 1.1 christos MAP (4, 0, BFD_RELOC_32);
1385 1.1 christos default:
1386 1.1 christos as_bad (_("Can not do %d byte %srelocation"), fixP->fx_size,
1387 1.1 christos fixP->fx_pcrel ? _("pc-relative ") : "");
1388 1.1 christos }
1389 1.1 christos #undef MAP
1390 1.1 christos #undef F
1391 1.1 christos
1392 1.5 christos rel = XNEW (arelent);
1393 1.1 christos gas_assert (rel != 0);
1394 1.5 christos rel->sym_ptr_ptr = XNEW (asymbol *);
1395 1.1 christos *rel->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
1396 1.1 christos rel->address = fixP->fx_frag->fr_address + fixP->fx_where;
1397 1.1 christos rel->addend = 0;
1398 1.1 christos rel->howto = bfd_reloc_type_lookup (stdoutput, code);
1399 1.1 christos if (!rel->howto)
1400 1.1 christos {
1401 1.1 christos const char *name;
1402 1.1 christos
1403 1.1 christos name = S_GET_NAME (fixP->fx_addsy);
1404 1.1 christos if (name == NULL)
1405 1.1 christos name = "<unknown>";
1406 1.1 christos as_fatal ("Cannot generate relocation type for symbol %s, code %s",
1407 1.1 christos name, bfd_get_reloc_code_name (code));
1408 1.1 christos }
1409 1.1 christos return rel;
1410 1.1 christos }
1411 1.1 christos
1412 1.1 christos void
1413 1.1 christos md_operand (expressionS *expressionP ATTRIBUTE_UNUSED)
1414 1.1 christos {
1415 1.1 christos debug ("In md_operand()\n");
1416 1.1 christos }
1417 1.1 christos
1418 1.1 christos void
1419 1.1 christos md_assemble (char *line)
1420 1.1 christos {
1421 1.1 christos insn_template *op;
1422 1.1 christos char *current_posn;
1423 1.1 christos char *token_start;
1424 1.1 christos char save_char;
1425 1.1 christos unsigned int count;
1426 1.1 christos
1427 1.1 christos debug ("In md_assemble() with argument %s\n", line);
1428 1.1 christos memset (&insn, '\0', sizeof (insn));
1429 1.1 christos if (found_parallel_insn)
1430 1.1 christos {
1431 1.1 christos debug ("Line is second part of parallel instruction\n\n");
1432 1.1 christos found_parallel_insn = 0;
1433 1.1 christos return;
1434 1.1 christos }
1435 1.1 christos if ((current_posn =
1436 1.1 christos tic30_find_parallel_insn (line, input_line_pointer + 1)) == NULL)
1437 1.1 christos current_posn = line;
1438 1.1 christos else
1439 1.1 christos found_parallel_insn = 1;
1440 1.1 christos
1441 1.1 christos while (is_space_char (*current_posn))
1442 1.1 christos current_posn++;
1443 1.1 christos
1444 1.1 christos token_start = current_posn;
1445 1.1 christos
1446 1.1 christos if (!is_opcode_char (*current_posn))
1447 1.1 christos {
1448 1.1 christos as_bad (_("Invalid character %s in opcode"),
1449 1.1 christos output_invalid (*current_posn));
1450 1.1 christos return;
1451 1.1 christos }
1452 1.1 christos /* Check if instruction is a parallel instruction
1453 1.1 christos by seeing if the first character is a q. */
1454 1.1 christos if (*token_start == 'q')
1455 1.1 christos {
1456 1.1 christos if (tic30_parallel_insn (token_start))
1457 1.1 christos {
1458 1.1 christos if (found_parallel_insn)
1459 1.1 christos free (token_start);
1460 1.1 christos return;
1461 1.1 christos }
1462 1.1 christos }
1463 1.1 christos while (is_opcode_char (*current_posn))
1464 1.1 christos current_posn++;
1465 1.1 christos {
1466 1.1 christos /* Find instruction. */
1467 1.1 christos save_char = *current_posn;
1468 1.1 christos *current_posn = '\0';
1469 1.1 christos op = (insn_template *) hash_find (op_hash, token_start);
1470 1.1 christos if (op)
1471 1.1 christos {
1472 1.1 christos debug ("Found instruction %s\n", op->name);
1473 1.1 christos insn.tm = op;
1474 1.1 christos }
1475 1.1 christos else
1476 1.1 christos {
1477 1.1 christos debug ("Didn't find insn\n");
1478 1.1 christos as_bad (_("Unknown TMS320C30 instruction: %s"), token_start);
1479 1.1 christos return;
1480 1.1 christos }
1481 1.1 christos *current_posn = save_char;
1482 1.1 christos }
1483 1.1 christos
1484 1.1 christos if (*current_posn != END_OF_INSN)
1485 1.1 christos {
1486 1.1 christos /* Find operands. */
1487 1.1 christos int paren_not_balanced;
1488 1.1 christos int expecting_operand = 0;
1489 1.1 christos int this_operand;
1490 1.1 christos do
1491 1.1 christos {
1492 1.1 christos /* Skip optional white space before operand. */
1493 1.1 christos while (!is_operand_char (*current_posn)
1494 1.1 christos && *current_posn != END_OF_INSN)
1495 1.1 christos {
1496 1.1 christos if (!is_space_char (*current_posn))
1497 1.1 christos {
1498 1.1 christos as_bad (_("Invalid character %s before %s operand"),
1499 1.1 christos output_invalid (*current_posn),
1500 1.1 christos ordinal_names[insn.operands]);
1501 1.1 christos return;
1502 1.1 christos }
1503 1.1 christos current_posn++;
1504 1.1 christos }
1505 1.1 christos token_start = current_posn;
1506 1.1 christos paren_not_balanced = 0;
1507 1.1 christos while (paren_not_balanced || *current_posn != ',')
1508 1.1 christos {
1509 1.1 christos if (*current_posn == END_OF_INSN)
1510 1.1 christos {
1511 1.1 christos if (paren_not_balanced)
1512 1.1 christos {
1513 1.1 christos as_bad (_("Unbalanced parenthesis in %s operand."),
1514 1.1 christos ordinal_names[insn.operands]);
1515 1.1 christos return;
1516 1.1 christos }
1517 1.1 christos else
1518 1.1 christos break;
1519 1.1 christos }
1520 1.1 christos else if (!is_operand_char (*current_posn)
1521 1.1 christos && !is_space_char (*current_posn))
1522 1.1 christos {
1523 1.1 christos as_bad (_("Invalid character %s in %s operand"),
1524 1.1 christos output_invalid (*current_posn),
1525 1.1 christos ordinal_names[insn.operands]);
1526 1.1 christos return;
1527 1.1 christos }
1528 1.1 christos if (*current_posn == '(')
1529 1.1 christos ++paren_not_balanced;
1530 1.1 christos if (*current_posn == ')')
1531 1.1 christos --paren_not_balanced;
1532 1.1 christos current_posn++;
1533 1.1 christos }
1534 1.1 christos if (current_posn != token_start)
1535 1.1 christos {
1536 1.1 christos /* Yes, we've read in another operand. */
1537 1.1 christos this_operand = insn.operands++;
1538 1.1 christos if (insn.operands > MAX_OPERANDS)
1539 1.1 christos {
1540 1.1 christos as_bad (_("Spurious operands; (%d operands/instruction max)"),
1541 1.1 christos MAX_OPERANDS);
1542 1.1 christos return;
1543 1.1 christos }
1544 1.1 christos
1545 1.1 christos /* Now parse operand adding info to 'insn' as we go along. */
1546 1.1 christos save_char = *current_posn;
1547 1.1 christos *current_posn = '\0';
1548 1.1 christos insn.operand_type[this_operand] = tic30_operand (token_start);
1549 1.1 christos *current_posn = save_char;
1550 1.1 christos if (insn.operand_type[this_operand] == NULL)
1551 1.1 christos return;
1552 1.1 christos }
1553 1.1 christos else
1554 1.1 christos {
1555 1.1 christos if (expecting_operand)
1556 1.1 christos {
1557 1.1 christos as_bad (_("Expecting operand after ','; got nothing"));
1558 1.1 christos return;
1559 1.1 christos }
1560 1.1 christos if (*current_posn == ',')
1561 1.1 christos {
1562 1.1 christos as_bad (_("Expecting operand before ','; got nothing"));
1563 1.1 christos return;
1564 1.1 christos }
1565 1.1 christos }
1566 1.1 christos
1567 1.1 christos /* Now *current_posn must be either ',' or END_OF_INSN. */
1568 1.1 christos if (*current_posn == ',')
1569 1.1 christos {
1570 1.1 christos if (*++current_posn == END_OF_INSN)
1571 1.1 christos {
1572 1.1 christos /* Just skip it, if it's \n complain. */
1573 1.1 christos as_bad (_("Expecting operand after ','; got nothing"));
1574 1.1 christos return;
1575 1.1 christos }
1576 1.1 christos expecting_operand = 1;
1577 1.1 christos }
1578 1.1 christos }
1579 1.1 christos while (*current_posn != END_OF_INSN);
1580 1.1 christos }
1581 1.1 christos
1582 1.1 christos debug ("Number of operands found: %d\n", insn.operands);
1583 1.1 christos
1584 1.1 christos /* Check that number of operands is correct. */
1585 1.1 christos if (insn.operands != insn.tm->operands)
1586 1.1 christos {
1587 1.1 christos unsigned int i;
1588 1.1 christos unsigned int numops = insn.tm->operands;
1589 1.1 christos
1590 1.1 christos /* If operands are not the same, then see if any of the operands are
1591 1.1 christos not required. Then recheck with number of given operands. If they
1592 1.1 christos are still not the same, then give an error, otherwise carry on. */
1593 1.1 christos for (i = 0; i < insn.tm->operands; i++)
1594 1.1 christos if (insn.tm->operand_types[i] & NotReq)
1595 1.1 christos numops--;
1596 1.1 christos if (insn.operands != numops)
1597 1.1 christos {
1598 1.1 christos as_bad (_("Incorrect number of operands given"));
1599 1.1 christos return;
1600 1.1 christos }
1601 1.1 christos }
1602 1.1 christos insn.addressing_mode = AM_NotReq;
1603 1.1 christos for (count = 0; count < insn.operands; count++)
1604 1.1 christos {
1605 1.1 christos if (insn.operand_type[count]->op_type & insn.tm->operand_types[count])
1606 1.1 christos {
1607 1.1 christos debug ("Operand %d matches\n", count + 1);
1608 1.1 christos /* If instruction has two operands and has an AddressMode
1609 1.1 christos modifier then set addressing mode type for instruction. */
1610 1.1 christos if (insn.tm->opcode_modifier == AddressMode)
1611 1.1 christos {
1612 1.1 christos int addr_insn = 0;
1613 1.1 christos /* Store instruction uses the second
1614 1.1 christos operand for the address mode. */
1615 1.1 christos if ((insn.tm->operand_types[1] & (Indirect | Direct))
1616 1.1 christos == (Indirect | Direct))
1617 1.1 christos addr_insn = 1;
1618 1.1 christos
1619 1.1 christos if (insn.operand_type[addr_insn]->op_type & (AllReg))
1620 1.1 christos insn.addressing_mode = AM_Register;
1621 1.1 christos else if (insn.operand_type[addr_insn]->op_type & Direct)
1622 1.1 christos insn.addressing_mode = AM_Direct;
1623 1.1 christos else if (insn.operand_type[addr_insn]->op_type & Indirect)
1624 1.1 christos insn.addressing_mode = AM_Indirect;
1625 1.1 christos else
1626 1.1 christos insn.addressing_mode = AM_Immediate;
1627 1.1 christos }
1628 1.1 christos }
1629 1.1 christos else
1630 1.1 christos {
1631 1.1 christos as_bad (_("The %s operand doesn't match"), ordinal_names[count]);
1632 1.1 christos return;
1633 1.1 christos }
1634 1.1 christos }
1635 1.1 christos
1636 1.1 christos /* Now set the addressing mode for 3 operand instructions. */
1637 1.1 christos if ((insn.tm->operand_types[0] & op3T1)
1638 1.1 christos && (insn.tm->operand_types[1] & op3T2))
1639 1.1 christos {
1640 1.1 christos /* Set the addressing mode to the values used for 2 operand
1641 1.1 christos instructions in the G addressing field of the opcode. */
1642 1.1 christos char *p;
1643 1.1 christos switch (insn.operand_type[0]->op_type)
1644 1.1 christos {
1645 1.1 christos case Rn:
1646 1.1 christos case ARn:
1647 1.1 christos case DPReg:
1648 1.1 christos case OtherReg:
1649 1.1 christos if (insn.operand_type[1]->op_type & (AllReg))
1650 1.1 christos insn.addressing_mode = AM_Register;
1651 1.1 christos else if (insn.operand_type[1]->op_type & Indirect)
1652 1.1 christos insn.addressing_mode = AM_Direct;
1653 1.1 christos else
1654 1.1 christos {
1655 1.1 christos /* Shouldn't make it to this stage. */
1656 1.1 christos as_bad (_("Incompatible first and second operands in instruction"));
1657 1.1 christos return;
1658 1.1 christos }
1659 1.1 christos break;
1660 1.1 christos case Indirect:
1661 1.1 christos if (insn.operand_type[1]->op_type & (AllReg))
1662 1.1 christos insn.addressing_mode = AM_Indirect;
1663 1.1 christos else if (insn.operand_type[1]->op_type & Indirect)
1664 1.1 christos insn.addressing_mode = AM_Immediate;
1665 1.1 christos else
1666 1.1 christos {
1667 1.1 christos /* Shouldn't make it to this stage. */
1668 1.1 christos as_bad (_("Incompatible first and second operands in instruction"));
1669 1.1 christos return;
1670 1.1 christos }
1671 1.1 christos break;
1672 1.1 christos }
1673 1.1 christos /* Now make up the opcode for the 3 operand instructions. As in
1674 1.1 christos parallel instructions, there will be no unresolved values, so they
1675 1.1 christos can be fully formed and added to the frag table. */
1676 1.1 christos insn.opcode = insn.tm->base_opcode;
1677 1.1 christos if (insn.operand_type[0]->op_type & Indirect)
1678 1.1 christos {
1679 1.1 christos insn.opcode |= (insn.operand_type[0]->indirect.ARnum);
1680 1.1 christos insn.opcode |= (insn.operand_type[0]->indirect.mod << 3);
1681 1.1 christos }
1682 1.1 christos else
1683 1.1 christos insn.opcode |= (insn.operand_type[0]->reg.opcode);
1684 1.1 christos
1685 1.1 christos if (insn.operand_type[1]->op_type & Indirect)
1686 1.1 christos {
1687 1.1 christos insn.opcode |= (insn.operand_type[1]->indirect.ARnum << 8);
1688 1.1 christos insn.opcode |= (insn.operand_type[1]->indirect.mod << 11);
1689 1.1 christos }
1690 1.1 christos else
1691 1.1 christos insn.opcode |= (insn.operand_type[1]->reg.opcode << 8);
1692 1.1 christos
1693 1.1 christos if (insn.operands == 3)
1694 1.1 christos insn.opcode |= (insn.operand_type[2]->reg.opcode << 16);
1695 1.1 christos
1696 1.1 christos insn.opcode |= insn.addressing_mode;
1697 1.1 christos p = frag_more (INSN_SIZE);
1698 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1699 1.1 christos }
1700 1.1 christos else
1701 1.1 christos {
1702 1.1 christos /* Not a three operand instruction. */
1703 1.1 christos char *p;
1704 1.1 christos int am_insn = -1;
1705 1.1 christos insn.opcode = insn.tm->base_opcode;
1706 1.1 christos /* Create frag for instruction - all instructions are 4 bytes long. */
1707 1.1 christos p = frag_more (INSN_SIZE);
1708 1.1 christos if ((insn.operands > 0) && (insn.tm->opcode_modifier == AddressMode))
1709 1.1 christos {
1710 1.1 christos insn.opcode |= insn.addressing_mode;
1711 1.1 christos if (insn.addressing_mode == AM_Indirect)
1712 1.1 christos {
1713 1.1 christos /* Determine which operand gives the addressing mode. */
1714 1.1 christos if (insn.operand_type[0]->op_type & Indirect)
1715 1.1 christos am_insn = 0;
1716 1.1 christos if ((insn.operands > 1)
1717 1.1 christos && (insn.operand_type[1]->op_type & Indirect))
1718 1.1 christos am_insn = 1;
1719 1.1 christos insn.opcode |= (insn.operand_type[am_insn]->indirect.disp);
1720 1.1 christos insn.opcode |= (insn.operand_type[am_insn]->indirect.ARnum << 8);
1721 1.1 christos insn.opcode |= (insn.operand_type[am_insn]->indirect.mod << 11);
1722 1.1 christos if (insn.operands > 1)
1723 1.1 christos insn.opcode |= (insn.operand_type[!am_insn]->reg.opcode << 16);
1724 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1725 1.1 christos }
1726 1.1 christos else if (insn.addressing_mode == AM_Register)
1727 1.1 christos {
1728 1.1 christos insn.opcode |= (insn.operand_type[0]->reg.opcode);
1729 1.1 christos if (insn.operands > 1)
1730 1.1 christos insn.opcode |= (insn.operand_type[1]->reg.opcode << 16);
1731 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1732 1.1 christos }
1733 1.1 christos else if (insn.addressing_mode == AM_Direct)
1734 1.1 christos {
1735 1.1 christos if (insn.operand_type[0]->op_type & Direct)
1736 1.1 christos am_insn = 0;
1737 1.1 christos if ((insn.operands > 1)
1738 1.1 christos && (insn.operand_type[1]->op_type & Direct))
1739 1.1 christos am_insn = 1;
1740 1.1 christos if (insn.operands > 1)
1741 1.1 christos insn.opcode |=
1742 1.1 christos (insn.operand_type[! am_insn]->reg.opcode << 16);
1743 1.1 christos if (insn.operand_type[am_insn]->direct.resolved == 1)
1744 1.1 christos {
1745 1.1 christos /* Resolved values can be placed straight
1746 1.1 christos into instruction word, and output. */
1747 1.1 christos insn.opcode |=
1748 1.1 christos (insn.operand_type[am_insn]->direct.address & 0x0000FFFF);
1749 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1750 1.1 christos }
1751 1.1 christos else
1752 1.1 christos {
1753 1.1 christos /* Unresolved direct addressing mode instruction. */
1754 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1755 1.1 christos fix_new_exp (frag_now, p + 2 - (frag_now->fr_literal), 2,
1756 1.1 christos & insn.operand_type[am_insn]->direct.direct_expr,
1757 1.1 christos 0, 0);
1758 1.1 christos }
1759 1.1 christos }
1760 1.1 christos else if (insn.addressing_mode == AM_Immediate)
1761 1.1 christos {
1762 1.1 christos if (insn.operand_type[0]->immediate.resolved == 1)
1763 1.1 christos {
1764 1.1 christos char *keeploc;
1765 1.1 christos int size;
1766 1.1 christos
1767 1.1 christos if (insn.operands > 1)
1768 1.1 christos insn.opcode |= (insn.operand_type[1]->reg.opcode << 16);
1769 1.1 christos
1770 1.1 christos switch (insn.tm->imm_arg_type)
1771 1.1 christos {
1772 1.1 christos case Imm_Float:
1773 1.1 christos debug ("Floating point first operand\n");
1774 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1775 1.1 christos
1776 1.1 christos keeploc = input_line_pointer;
1777 1.1 christos input_line_pointer =
1778 1.1 christos insn.operand_type[0]->immediate.label;
1779 1.1 christos
1780 1.1 christos if (md_atof ('f', p + 2, & size) != 0)
1781 1.1 christos {
1782 1.1 christos as_bad (_("invalid short form floating point immediate operand"));
1783 1.1 christos return;
1784 1.1 christos }
1785 1.1 christos
1786 1.1 christos input_line_pointer = keeploc;
1787 1.1 christos break;
1788 1.1 christos
1789 1.1 christos case Imm_UInt:
1790 1.1 christos debug ("Unsigned int first operand\n");
1791 1.1 christos if (insn.operand_type[0]->immediate.decimal_found)
1792 1.1 christos as_warn (_("rounding down first operand float to unsigned int"));
1793 1.1 christos if (insn.operand_type[0]->immediate.u_number > 0xFFFF)
1794 1.1 christos as_warn (_("only lower 16-bits of first operand are used"));
1795 1.1 christos insn.opcode |=
1796 1.1 christos (insn.operand_type[0]->immediate.u_number & 0x0000FFFFL);
1797 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1798 1.1 christos break;
1799 1.1 christos
1800 1.1 christos case Imm_SInt:
1801 1.1 christos debug ("Int first operand\n");
1802 1.1 christos
1803 1.1 christos if (insn.operand_type[0]->immediate.decimal_found)
1804 1.1 christos as_warn (_("rounding down first operand float to signed int"));
1805 1.1 christos
1806 1.1 christos if (insn.operand_type[0]->immediate.s_number < -32768 ||
1807 1.1 christos insn.operand_type[0]->immediate.s_number > 32767)
1808 1.1 christos {
1809 1.1 christos as_bad (_("first operand is too large for 16-bit signed int"));
1810 1.1 christos return;
1811 1.1 christos }
1812 1.1 christos insn.opcode |=
1813 1.1 christos (insn.operand_type[0]->immediate.s_number & 0x0000FFFFL);
1814 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1815 1.1 christos break;
1816 1.1 christos }
1817 1.1 christos }
1818 1.1 christos else
1819 1.1 christos {
1820 1.1 christos /* Unresolved immediate label. */
1821 1.1 christos if (insn.operands > 1)
1822 1.1 christos insn.opcode |= (insn.operand_type[1]->reg.opcode << 16);
1823 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1824 1.1 christos fix_new_exp (frag_now, p + 2 - (frag_now->fr_literal), 2,
1825 1.1 christos & insn.operand_type[0]->immediate.imm_expr,
1826 1.1 christos 0, 0);
1827 1.1 christos }
1828 1.1 christos }
1829 1.1 christos }
1830 1.1 christos else if (insn.tm->opcode_modifier == PCRel)
1831 1.1 christos {
1832 1.1 christos /* Conditional Branch and Call instructions. */
1833 1.1 christos if ((insn.tm->operand_types[0] & (AllReg | Disp))
1834 1.1 christos == (AllReg | Disp))
1835 1.1 christos {
1836 1.1 christos if (insn.operand_type[0]->op_type & (AllReg))
1837 1.1 christos {
1838 1.1 christos insn.opcode |= (insn.operand_type[0]->reg.opcode);
1839 1.1 christos insn.opcode |= PC_Register;
1840 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1841 1.1 christos }
1842 1.1 christos else
1843 1.1 christos {
1844 1.1 christos insn.opcode |= PC_Relative;
1845 1.1 christos if (insn.operand_type[0]->immediate.resolved == 1)
1846 1.1 christos {
1847 1.1 christos insn.opcode |=
1848 1.1 christos (insn.operand_type[0]->immediate.s_number & 0x0000FFFF);
1849 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1850 1.1 christos }
1851 1.1 christos else
1852 1.1 christos {
1853 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1854 1.1 christos fix_new_exp (frag_now, p + 2 - (frag_now->fr_literal),
1855 1.1 christos 2, & insn.operand_type[0]->immediate.imm_expr,
1856 1.1 christos 1, 0);
1857 1.1 christos }
1858 1.1 christos }
1859 1.1 christos }
1860 1.1 christos else if ((insn.tm->operand_types[0] & ARn) == ARn)
1861 1.1 christos {
1862 1.1 christos /* Decrement and Branch instructions. */
1863 1.1 christos insn.opcode |= ((insn.operand_type[0]->reg.opcode - 0x08) << 22);
1864 1.1 christos if (insn.operand_type[1]->op_type & (AllReg))
1865 1.1 christos {
1866 1.1 christos insn.opcode |= (insn.operand_type[1]->reg.opcode);
1867 1.1 christos insn.opcode |= PC_Register;
1868 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1869 1.1 christos }
1870 1.1 christos else if (insn.operand_type[1]->immediate.resolved == 1)
1871 1.1 christos {
1872 1.1 christos if (insn.operand_type[0]->immediate.decimal_found)
1873 1.1 christos {
1874 1.1 christos as_bad (_("first operand is floating point"));
1875 1.1 christos return;
1876 1.1 christos }
1877 1.1 christos if (insn.operand_type[0]->immediate.s_number < -32768 ||
1878 1.1 christos insn.operand_type[0]->immediate.s_number > 32767)
1879 1.1 christos {
1880 1.1 christos as_bad (_("first operand is too large for 16-bit signed int"));
1881 1.1 christos return;
1882 1.1 christos }
1883 1.1 christos insn.opcode |= (insn.operand_type[1]->immediate.s_number);
1884 1.1 christos insn.opcode |= PC_Relative;
1885 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1886 1.1 christos }
1887 1.1 christos else
1888 1.1 christos {
1889 1.1 christos insn.opcode |= PC_Relative;
1890 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1891 1.1 christos fix_new_exp (frag_now, p + 2 - frag_now->fr_literal, 2,
1892 1.1 christos & insn.operand_type[1]->immediate.imm_expr,
1893 1.1 christos 1, 0);
1894 1.1 christos }
1895 1.1 christos }
1896 1.1 christos }
1897 1.1 christos else if (insn.tm->operand_types[0] == IVector)
1898 1.1 christos {
1899 1.1 christos /* Trap instructions. */
1900 1.1 christos if (insn.operand_type[0]->op_type & IVector)
1901 1.1 christos insn.opcode |= (insn.operand_type[0]->immediate.u_number);
1902 1.1 christos else
1903 1.1 christos {
1904 1.1 christos /* Shouldn't get here. */
1905 1.1 christos as_bad (_("interrupt vector for trap instruction out of range"));
1906 1.1 christos return;
1907 1.1 christos }
1908 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1909 1.1 christos }
1910 1.1 christos else if (insn.tm->opcode_modifier == StackOp
1911 1.1 christos || insn.tm->opcode_modifier == Rotate)
1912 1.1 christos {
1913 1.1 christos /* Push, Pop and Rotate instructions. */
1914 1.1 christos insn.opcode |= (insn.operand_type[0]->reg.opcode << 16);
1915 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1916 1.1 christos }
1917 1.1 christos else if ((insn.tm->operand_types[0] & (Abs24 | Direct))
1918 1.1 christos == (Abs24 | Direct))
1919 1.1 christos {
1920 1.1 christos /* LDP Instruction needs to be tested
1921 1.1 christos for before the next section. */
1922 1.1 christos if (insn.operand_type[0]->op_type & Direct)
1923 1.1 christos {
1924 1.1 christos if (insn.operand_type[0]->direct.resolved == 1)
1925 1.1 christos {
1926 1.1 christos /* Direct addressing uses lower 8 bits of direct address. */
1927 1.1 christos insn.opcode |=
1928 1.1 christos (insn.operand_type[0]->direct.address & 0x00FF0000) >> 16;
1929 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1930 1.1 christos }
1931 1.1 christos else
1932 1.1 christos {
1933 1.1 christos fixS *fix;
1934 1.1 christos
1935 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1936 1.1 christos fix = fix_new_exp (frag_now, p + 3 - (frag_now->fr_literal),
1937 1.1 christos 1, &insn.operand_type[0]->direct.direct_expr, 0, 0);
1938 1.1 christos /* Ensure that the assembler doesn't complain
1939 1.1 christos about fitting a 24-bit address into 8 bits. */
1940 1.1 christos fix->fx_no_overflow = 1;
1941 1.1 christos }
1942 1.1 christos }
1943 1.1 christos else
1944 1.1 christos {
1945 1.1 christos if (insn.operand_type[0]->immediate.resolved == 1)
1946 1.1 christos {
1947 1.1 christos /* Immediate addressing uses upper 8 bits of address. */
1948 1.1 christos if (insn.operand_type[0]->immediate.u_number > 0x00FFFFFF)
1949 1.1 christos {
1950 1.1 christos as_bad (_("LDP instruction needs a 24-bit operand"));
1951 1.1 christos return;
1952 1.1 christos }
1953 1.1 christos insn.opcode |=
1954 1.1 christos ((insn.operand_type[0]->immediate.u_number & 0x00FF0000) >> 16);
1955 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1956 1.1 christos }
1957 1.1 christos else
1958 1.1 christos {
1959 1.1 christos fixS *fix;
1960 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1961 1.1 christos fix = fix_new_exp (frag_now, p + 3 - (frag_now->fr_literal),
1962 1.1 christos 1, &insn.operand_type[0]->immediate.imm_expr,
1963 1.1 christos 0, 0);
1964 1.1 christos fix->fx_no_overflow = 1;
1965 1.1 christos }
1966 1.1 christos }
1967 1.1 christos }
1968 1.1 christos else if (insn.tm->operand_types[0] & (Imm24))
1969 1.1 christos {
1970 1.1 christos /* Unconditional Branch and Call instructions. */
1971 1.1 christos if (insn.operand_type[0]->immediate.resolved == 1)
1972 1.1 christos {
1973 1.1 christos if (insn.operand_type[0]->immediate.u_number > 0x00FFFFFF)
1974 1.1 christos as_warn (_("first operand is too large for a 24-bit displacement"));
1975 1.1 christos insn.opcode |=
1976 1.1 christos (insn.operand_type[0]->immediate.u_number & 0x00FFFFFF);
1977 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1978 1.1 christos }
1979 1.1 christos else
1980 1.1 christos {
1981 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1982 1.1 christos fix_new_exp (frag_now, p + 1 - (frag_now->fr_literal), 3,
1983 1.1 christos & insn.operand_type[0]->immediate.imm_expr, 0, 0);
1984 1.1 christos }
1985 1.1 christos }
1986 1.1 christos else if (insn.tm->operand_types[0] & NotReq)
1987 1.1 christos /* Check for NOP instruction without arguments. */
1988 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1989 1.1 christos
1990 1.1 christos else if (insn.tm->operands == 0)
1991 1.1 christos /* Check for instructions without operands. */
1992 1.1 christos md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
1993 1.1 christos }
1994 1.1 christos debug ("Addressing mode: %08X\n", insn.addressing_mode);
1995 1.1 christos {
1996 1.1 christos unsigned int i;
1997 1.1 christos
1998 1.1 christos for (i = 0; i < insn.operands; i++)
1999 1.1 christos {
2000 1.1 christos if (insn.operand_type[i]->immediate.label)
2001 1.1 christos free (insn.operand_type[i]->immediate.label);
2002 1.1 christos free (insn.operand_type[i]);
2003 1.1 christos }
2004 1.1 christos }
2005 1.1 christos debug ("Final opcode: %08X\n", insn.opcode);
2006 1.1 christos debug ("\n");
2007 1.1 christos }
2008