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