1 /* Instruction building/extraction support for mt. -*- C -*- 2 3 THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator. 4 - the resultant file is machine generated, cgen-ibld.in isn't 5 6 Copyright (C) 1996-2014 Free Software Foundation, Inc. 7 8 This file is part of libopcodes. 9 10 This library is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 3, or (at your option) 13 any later version. 14 15 It is distributed in the hope that it will be useful, but WITHOUT 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 18 License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software Foundation, Inc., 22 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 23 24 /* ??? Eventually more and more of this stuff can go to cpu-independent files. 25 Keep that in mind. */ 26 27 #include "sysdep.h" 28 #include <stdio.h> 29 #include "ansidecl.h" 30 #include "dis-asm.h" 31 #include "bfd.h" 32 #include "symcat.h" 33 #include "mt-desc.h" 34 #include "mt-opc.h" 35 #include "cgen/basic-modes.h" 36 #include "opintl.h" 37 #include "safe-ctype.h" 38 39 #undef min 40 #define min(a,b) ((a) < (b) ? (a) : (b)) 41 #undef max 42 #define max(a,b) ((a) > (b) ? (a) : (b)) 43 44 /* Used by the ifield rtx function. */ 45 #define FLD(f) (fields->f) 46 47 static const char * insert_normal 48 (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int, 49 unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR); 50 static const char * insert_insn_normal 51 (CGEN_CPU_DESC, const CGEN_INSN *, 52 CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma); 53 static int extract_normal 54 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, 55 unsigned int, unsigned int, unsigned int, unsigned int, 56 unsigned int, unsigned int, bfd_vma, long *); 57 static int extract_insn_normal 58 (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *, 59 CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma); 60 #if CGEN_INT_INSN_P 61 static void put_insn_int_value 62 (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT); 63 #endif 64 #if ! CGEN_INT_INSN_P 65 static CGEN_INLINE void insert_1 66 (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *); 67 static CGEN_INLINE int fill_cache 68 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, bfd_vma); 69 static CGEN_INLINE long extract_1 70 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma); 71 #endif 72 73 /* Operand insertion. */ 75 76 #if ! CGEN_INT_INSN_P 77 78 /* Subroutine of insert_normal. */ 79 80 static CGEN_INLINE void 81 insert_1 (CGEN_CPU_DESC cd, 82 unsigned long value, 83 int start, 84 int length, 85 int word_length, 86 unsigned char *bufp) 87 { 88 unsigned long x,mask; 89 int shift; 90 91 x = cgen_get_insn_value (cd, bufp, word_length); 92 93 /* Written this way to avoid undefined behaviour. */ 94 mask = (((1L << (length - 1)) - 1) << 1) | 1; 95 if (CGEN_INSN_LSB0_P) 96 shift = (start + 1) - length; 97 else 98 shift = (word_length - (start + length)); 99 x = (x & ~(mask << shift)) | ((value & mask) << shift); 100 101 cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x); 102 } 103 104 #endif /* ! CGEN_INT_INSN_P */ 105 106 /* Default insertion routine. 107 108 ATTRS is a mask of the boolean attributes. 109 WORD_OFFSET is the offset in bits from the start of the insn of the value. 110 WORD_LENGTH is the length of the word in bits in which the value resides. 111 START is the starting bit number in the word, architecture origin. 112 LENGTH is the length of VALUE in bits. 113 TOTAL_LENGTH is the total length of the insn in bits. 114 115 The result is an error message or NULL if success. */ 116 117 /* ??? This duplicates functionality with bfd's howto table and 118 bfd_install_relocation. */ 119 /* ??? This doesn't handle bfd_vma's. Create another function when 120 necessary. */ 121 122 static const char * 123 insert_normal (CGEN_CPU_DESC cd, 124 long value, 125 unsigned int attrs, 126 unsigned int word_offset, 127 unsigned int start, 128 unsigned int length, 129 unsigned int word_length, 130 unsigned int total_length, 131 CGEN_INSN_BYTES_PTR buffer) 132 { 133 static char errbuf[100]; 134 /* Written this way to avoid undefined behaviour. */ 135 unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1; 136 137 /* If LENGTH is zero, this operand doesn't contribute to the value. */ 138 if (length == 0) 139 return NULL; 140 141 if (word_length > 8 * sizeof (CGEN_INSN_INT)) 142 abort (); 143 144 /* For architectures with insns smaller than the base-insn-bitsize, 145 word_length may be too big. */ 146 if (cd->min_insn_bitsize < cd->base_insn_bitsize) 147 { 148 if (word_offset == 0 149 && word_length > total_length) 150 word_length = total_length; 151 } 152 153 /* Ensure VALUE will fit. */ 154 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT)) 155 { 156 long minval = - (1L << (length - 1)); 157 unsigned long maxval = mask; 158 159 if ((value > 0 && (unsigned long) value > maxval) 160 || value < minval) 161 { 162 /* xgettext:c-format */ 163 sprintf (errbuf, 164 _("operand out of range (%ld not between %ld and %lu)"), 165 value, minval, maxval); 166 return errbuf; 167 } 168 } 169 else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)) 170 { 171 unsigned long maxval = mask; 172 unsigned long val = (unsigned long) value; 173 174 /* For hosts with a word size > 32 check to see if value has been sign 175 extended beyond 32 bits. If so then ignore these higher sign bits 176 as the user is attempting to store a 32-bit signed value into an 177 unsigned 32-bit field which is allowed. */ 178 if (sizeof (unsigned long) > 4 && ((value >> 32) == -1)) 179 val &= 0xFFFFFFFF; 180 181 if (val > maxval) 182 { 183 /* xgettext:c-format */ 184 sprintf (errbuf, 185 _("operand out of range (0x%lx not between 0 and 0x%lx)"), 186 val, maxval); 187 return errbuf; 188 } 189 } 190 else 191 { 192 if (! cgen_signed_overflow_ok_p (cd)) 193 { 194 long minval = - (1L << (length - 1)); 195 long maxval = (1L << (length - 1)) - 1; 196 197 if (value < minval || value > maxval) 198 { 199 sprintf 200 /* xgettext:c-format */ 201 (errbuf, _("operand out of range (%ld not between %ld and %ld)"), 202 value, minval, maxval); 203 return errbuf; 204 } 205 } 206 } 207 208 #if CGEN_INT_INSN_P 209 210 { 211 int shift; 212 213 if (CGEN_INSN_LSB0_P) 214 shift = (word_offset + start + 1) - length; 215 else 216 shift = total_length - (word_offset + start + length); 217 *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift); 218 } 219 220 #else /* ! CGEN_INT_INSN_P */ 221 222 { 223 unsigned char *bufp = (unsigned char *) buffer + word_offset / 8; 224 225 insert_1 (cd, value, start, length, word_length, bufp); 226 } 227 228 #endif /* ! CGEN_INT_INSN_P */ 229 230 return NULL; 231 } 232 233 /* Default insn builder (insert handler). 234 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning 235 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is 236 recorded in host byte order, otherwise BUFFER is an array of bytes 237 and the value is recorded in target byte order). 238 The result is an error message or NULL if success. */ 239 240 static const char * 241 insert_insn_normal (CGEN_CPU_DESC cd, 242 const CGEN_INSN * insn, 243 CGEN_FIELDS * fields, 244 CGEN_INSN_BYTES_PTR buffer, 245 bfd_vma pc) 246 { 247 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); 248 unsigned long value; 249 const CGEN_SYNTAX_CHAR_TYPE * syn; 250 251 CGEN_INIT_INSERT (cd); 252 value = CGEN_INSN_BASE_VALUE (insn); 253 254 /* If we're recording insns as numbers (rather than a string of bytes), 255 target byte order handling is deferred until later. */ 256 257 #if CGEN_INT_INSN_P 258 259 put_insn_int_value (cd, buffer, cd->base_insn_bitsize, 260 CGEN_FIELDS_BITSIZE (fields), value); 261 262 #else 263 264 cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize, 265 (unsigned) CGEN_FIELDS_BITSIZE (fields)), 266 value); 267 268 #endif /* ! CGEN_INT_INSN_P */ 269 270 /* ??? It would be better to scan the format's fields. 271 Still need to be able to insert a value based on the operand though; 272 e.g. storing a branch displacement that got resolved later. 273 Needs more thought first. */ 274 275 for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn) 276 { 277 const char *errmsg; 278 279 if (CGEN_SYNTAX_CHAR_P (* syn)) 280 continue; 281 282 errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn), 283 fields, buffer, pc); 284 if (errmsg) 285 return errmsg; 286 } 287 288 return NULL; 289 } 290 291 #if CGEN_INT_INSN_P 292 /* Cover function to store an insn value into an integral insn. Must go here 293 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */ 294 295 static void 296 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, 297 CGEN_INSN_BYTES_PTR buf, 298 int length, 299 int insn_length, 300 CGEN_INSN_INT value) 301 { 302 /* For architectures with insns smaller than the base-insn-bitsize, 303 length may be too big. */ 304 if (length > insn_length) 305 *buf = value; 306 else 307 { 308 int shift = insn_length - length; 309 /* Written this way to avoid undefined behaviour. */ 310 CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1; 311 312 *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift); 313 } 314 } 315 #endif 316 317 /* Operand extraction. */ 319 320 #if ! CGEN_INT_INSN_P 321 322 /* Subroutine of extract_normal. 323 Ensure sufficient bytes are cached in EX_INFO. 324 OFFSET is the offset in bytes from the start of the insn of the value. 325 BYTES is the length of the needed value. 326 Returns 1 for success, 0 for failure. */ 327 328 static CGEN_INLINE int 329 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, 330 CGEN_EXTRACT_INFO *ex_info, 331 int offset, 332 int bytes, 333 bfd_vma pc) 334 { 335 /* It's doubtful that the middle part has already been fetched so 336 we don't optimize that case. kiss. */ 337 unsigned int mask; 338 disassemble_info *info = (disassemble_info *) ex_info->dis_info; 339 340 /* First do a quick check. */ 341 mask = (1 << bytes) - 1; 342 if (((ex_info->valid >> offset) & mask) == mask) 343 return 1; 344 345 /* Search for the first byte we need to read. */ 346 for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1) 347 if (! (mask & ex_info->valid)) 348 break; 349 350 if (bytes) 351 { 352 int status; 353 354 pc += offset; 355 status = (*info->read_memory_func) 356 (pc, ex_info->insn_bytes + offset, bytes, info); 357 358 if (status != 0) 359 { 360 (*info->memory_error_func) (status, pc, info); 361 return 0; 362 } 363 364 ex_info->valid |= ((1 << bytes) - 1) << offset; 365 } 366 367 return 1; 368 } 369 370 /* Subroutine of extract_normal. */ 371 372 static CGEN_INLINE long 373 extract_1 (CGEN_CPU_DESC cd, 374 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED, 375 int start, 376 int length, 377 int word_length, 378 unsigned char *bufp, 379 bfd_vma pc ATTRIBUTE_UNUSED) 380 { 381 unsigned long x; 382 int shift; 383 384 x = cgen_get_insn_value (cd, bufp, word_length); 385 386 if (CGEN_INSN_LSB0_P) 387 shift = (start + 1) - length; 388 else 389 shift = (word_length - (start + length)); 390 return x >> shift; 391 } 392 393 #endif /* ! CGEN_INT_INSN_P */ 394 395 /* Default extraction routine. 396 397 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order, 398 or sometimes less for cases like the m32r where the base insn size is 32 399 but some insns are 16 bits. 400 ATTRS is a mask of the boolean attributes. We only need `SIGNED', 401 but for generality we take a bitmask of all of them. 402 WORD_OFFSET is the offset in bits from the start of the insn of the value. 403 WORD_LENGTH is the length of the word in bits in which the value resides. 404 START is the starting bit number in the word, architecture origin. 405 LENGTH is the length of VALUE in bits. 406 TOTAL_LENGTH is the total length of the insn in bits. 407 408 Returns 1 for success, 0 for failure. */ 409 410 /* ??? The return code isn't properly used. wip. */ 411 412 /* ??? This doesn't handle bfd_vma's. Create another function when 413 necessary. */ 414 415 static int 416 extract_normal (CGEN_CPU_DESC cd, 417 #if ! CGEN_INT_INSN_P 418 CGEN_EXTRACT_INFO *ex_info, 419 #else 420 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED, 421 #endif 422 CGEN_INSN_INT insn_value, 423 unsigned int attrs, 424 unsigned int word_offset, 425 unsigned int start, 426 unsigned int length, 427 unsigned int word_length, 428 unsigned int total_length, 429 #if ! CGEN_INT_INSN_P 430 bfd_vma pc, 431 #else 432 bfd_vma pc ATTRIBUTE_UNUSED, 433 #endif 434 long *valuep) 435 { 436 long value, mask; 437 438 /* If LENGTH is zero, this operand doesn't contribute to the value 439 so give it a standard value of zero. */ 440 if (length == 0) 441 { 442 *valuep = 0; 443 return 1; 444 } 445 446 if (word_length > 8 * sizeof (CGEN_INSN_INT)) 447 abort (); 448 449 /* For architectures with insns smaller than the insn-base-bitsize, 450 word_length may be too big. */ 451 if (cd->min_insn_bitsize < cd->base_insn_bitsize) 452 { 453 if (word_offset + word_length > total_length) 454 word_length = total_length - word_offset; 455 } 456 457 /* Does the value reside in INSN_VALUE, and at the right alignment? */ 458 459 if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length)) 460 { 461 if (CGEN_INSN_LSB0_P) 462 value = insn_value >> ((word_offset + start + 1) - length); 463 else 464 value = insn_value >> (total_length - ( word_offset + start + length)); 465 } 466 467 #if ! CGEN_INT_INSN_P 468 469 else 470 { 471 unsigned char *bufp = ex_info->insn_bytes + word_offset / 8; 472 473 if (word_length > 8 * sizeof (CGEN_INSN_INT)) 474 abort (); 475 476 if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0) 477 return 0; 478 479 value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc); 480 } 481 482 #endif /* ! CGEN_INT_INSN_P */ 483 484 /* Written this way to avoid undefined behaviour. */ 485 mask = (((1L << (length - 1)) - 1) << 1) | 1; 486 487 value &= mask; 488 /* sign extend? */ 489 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED) 490 && (value & (1L << (length - 1)))) 491 value |= ~mask; 492 493 *valuep = value; 494 495 return 1; 496 } 497 498 /* Default insn extractor. 499 500 INSN_VALUE is the first base_insn_bitsize bits, translated to host order. 501 The extracted fields are stored in FIELDS. 502 EX_INFO is used to handle reading variable length insns. 503 Return the length of the insn in bits, or 0 if no match, 504 or -1 if an error occurs fetching data (memory_error_func will have 505 been called). */ 506 507 static int 508 extract_insn_normal (CGEN_CPU_DESC cd, 509 const CGEN_INSN *insn, 510 CGEN_EXTRACT_INFO *ex_info, 511 CGEN_INSN_INT insn_value, 512 CGEN_FIELDS *fields, 513 bfd_vma pc) 514 { 515 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); 516 const CGEN_SYNTAX_CHAR_TYPE *syn; 517 518 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); 519 520 CGEN_INIT_EXTRACT (cd); 521 522 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn) 523 { 524 int length; 525 526 if (CGEN_SYNTAX_CHAR_P (*syn)) 527 continue; 528 529 length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn), 530 ex_info, insn_value, fields, pc); 531 if (length <= 0) 532 return length; 533 } 534 535 /* We recognized and successfully extracted this insn. */ 536 return CGEN_INSN_BITSIZE (insn); 537 } 538 539 /* Machine generated code added here. */ 541 542 const char * mt_cgen_insert_operand 543 (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma); 544 545 /* Main entry point for operand insertion. 546 547 This function is basically just a big switch statement. Earlier versions 548 used tables to look up the function to use, but 549 - if the table contains both assembler and disassembler functions then 550 the disassembler contains much of the assembler and vice-versa, 551 - there's a lot of inlining possibilities as things grow, 552 - using a switch statement avoids the function call overhead. 553 554 This function could be moved into `parse_insn_normal', but keeping it 555 separate makes clear the interface between `parse_insn_normal' and each of 556 the handlers. It's also needed by GAS to insert operands that couldn't be 557 resolved during parsing. */ 558 559 const char * 560 mt_cgen_insert_operand (CGEN_CPU_DESC cd, 561 int opindex, 562 CGEN_FIELDS * fields, 563 CGEN_INSN_BYTES_PTR buffer, 564 bfd_vma pc ATTRIBUTE_UNUSED) 565 { 566 const char * errmsg = NULL; 567 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); 568 569 switch (opindex) 570 { 571 case MT_OPERAND_A23 : 572 errmsg = insert_normal (cd, fields->f_a23, 0, 0, 23, 1, 32, total_length, buffer); 573 break; 574 case MT_OPERAND_BALL : 575 errmsg = insert_normal (cd, fields->f_ball, 0, 0, 19, 1, 32, total_length, buffer); 576 break; 577 case MT_OPERAND_BALL2 : 578 errmsg = insert_normal (cd, fields->f_ball2, 0, 0, 15, 1, 32, total_length, buffer); 579 break; 580 case MT_OPERAND_BANKADDR : 581 errmsg = insert_normal (cd, fields->f_bankaddr, 0, 0, 25, 13, 32, total_length, buffer); 582 break; 583 case MT_OPERAND_BRC : 584 errmsg = insert_normal (cd, fields->f_brc, 0, 0, 18, 3, 32, total_length, buffer); 585 break; 586 case MT_OPERAND_BRC2 : 587 errmsg = insert_normal (cd, fields->f_brc2, 0, 0, 14, 3, 32, total_length, buffer); 588 break; 589 case MT_OPERAND_CB1INCR : 590 errmsg = insert_normal (cd, fields->f_cb1incr, 0|(1<<CGEN_IFLD_SIGNED), 0, 19, 6, 32, total_length, buffer); 591 break; 592 case MT_OPERAND_CB1SEL : 593 errmsg = insert_normal (cd, fields->f_cb1sel, 0, 0, 25, 3, 32, total_length, buffer); 594 break; 595 case MT_OPERAND_CB2INCR : 596 errmsg = insert_normal (cd, fields->f_cb2incr, 0|(1<<CGEN_IFLD_SIGNED), 0, 13, 6, 32, total_length, buffer); 597 break; 598 case MT_OPERAND_CB2SEL : 599 errmsg = insert_normal (cd, fields->f_cb2sel, 0, 0, 22, 3, 32, total_length, buffer); 600 break; 601 case MT_OPERAND_CBRB : 602 errmsg = insert_normal (cd, fields->f_cbrb, 0, 0, 10, 1, 32, total_length, buffer); 603 break; 604 case MT_OPERAND_CBS : 605 errmsg = insert_normal (cd, fields->f_cbs, 0, 0, 19, 2, 32, total_length, buffer); 606 break; 607 case MT_OPERAND_CBX : 608 errmsg = insert_normal (cd, fields->f_cbx, 0, 0, 14, 3, 32, total_length, buffer); 609 break; 610 case MT_OPERAND_CCB : 611 errmsg = insert_normal (cd, fields->f_ccb, 0, 0, 11, 1, 32, total_length, buffer); 612 break; 613 case MT_OPERAND_CDB : 614 errmsg = insert_normal (cd, fields->f_cdb, 0, 0, 10, 1, 32, total_length, buffer); 615 break; 616 case MT_OPERAND_CELL : 617 errmsg = insert_normal (cd, fields->f_cell, 0, 0, 9, 3, 32, total_length, buffer); 618 break; 619 case MT_OPERAND_COLNUM : 620 errmsg = insert_normal (cd, fields->f_colnum, 0, 0, 18, 3, 32, total_length, buffer); 621 break; 622 case MT_OPERAND_CONTNUM : 623 errmsg = insert_normal (cd, fields->f_contnum, 0, 0, 8, 9, 32, total_length, buffer); 624 break; 625 case MT_OPERAND_CR : 626 errmsg = insert_normal (cd, fields->f_cr, 0, 0, 22, 3, 32, total_length, buffer); 627 break; 628 case MT_OPERAND_CTXDISP : 629 errmsg = insert_normal (cd, fields->f_ctxdisp, 0, 0, 5, 6, 32, total_length, buffer); 630 break; 631 case MT_OPERAND_DUP : 632 errmsg = insert_normal (cd, fields->f_dup, 0, 0, 6, 1, 32, total_length, buffer); 633 break; 634 case MT_OPERAND_FBDISP : 635 errmsg = insert_normal (cd, fields->f_fbdisp, 0, 0, 15, 6, 32, total_length, buffer); 636 break; 637 case MT_OPERAND_FBINCR : 638 errmsg = insert_normal (cd, fields->f_fbincr, 0, 0, 23, 4, 32, total_length, buffer); 639 break; 640 case MT_OPERAND_FRDR : 641 errmsg = insert_normal (cd, fields->f_dr, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, buffer); 642 break; 643 case MT_OPERAND_FRDRRR : 644 errmsg = insert_normal (cd, fields->f_drrr, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 4, 32, total_length, buffer); 645 break; 646 case MT_OPERAND_FRSR1 : 647 errmsg = insert_normal (cd, fields->f_sr1, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 23, 4, 32, total_length, buffer); 648 break; 649 case MT_OPERAND_FRSR2 : 650 errmsg = insert_normal (cd, fields->f_sr2, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, buffer); 651 break; 652 case MT_OPERAND_ID : 653 errmsg = insert_normal (cd, fields->f_id, 0, 0, 14, 1, 32, total_length, buffer); 654 break; 655 case MT_OPERAND_IMM16 : 656 { 657 long value = fields->f_imm16s; 658 value = ((value) + (0)); 659 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, buffer); 660 } 661 break; 662 case MT_OPERAND_IMM16L : 663 errmsg = insert_normal (cd, fields->f_imm16l, 0, 0, 23, 16, 32, total_length, buffer); 664 break; 665 case MT_OPERAND_IMM16O : 666 { 667 long value = fields->f_imm16s; 668 value = ((value) + (0)); 669 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, buffer); 670 } 671 break; 672 case MT_OPERAND_IMM16Z : 673 errmsg = insert_normal (cd, fields->f_imm16u, 0, 0, 15, 16, 32, total_length, buffer); 674 break; 675 case MT_OPERAND_INCAMT : 676 errmsg = insert_normal (cd, fields->f_incamt, 0, 0, 19, 8, 32, total_length, buffer); 677 break; 678 case MT_OPERAND_INCR : 679 errmsg = insert_normal (cd, fields->f_incr, 0, 0, 17, 6, 32, total_length, buffer); 680 break; 681 case MT_OPERAND_LENGTH : 682 errmsg = insert_normal (cd, fields->f_length, 0, 0, 15, 3, 32, total_length, buffer); 683 break; 684 case MT_OPERAND_LOOPSIZE : 685 { 686 long value = fields->f_loopo; 687 value = ((USI) (value) >> (2)); 688 errmsg = insert_normal (cd, value, 0, 0, 7, 8, 32, total_length, buffer); 689 } 690 break; 691 case MT_OPERAND_MASK : 692 errmsg = insert_normal (cd, fields->f_mask, 0, 0, 25, 16, 32, total_length, buffer); 693 break; 694 case MT_OPERAND_MASK1 : 695 errmsg = insert_normal (cd, fields->f_mask1, 0, 0, 22, 3, 32, total_length, buffer); 696 break; 697 case MT_OPERAND_MODE : 698 errmsg = insert_normal (cd, fields->f_mode, 0, 0, 25, 2, 32, total_length, buffer); 699 break; 700 case MT_OPERAND_PERM : 701 errmsg = insert_normal (cd, fields->f_perm, 0, 0, 25, 2, 32, total_length, buffer); 702 break; 703 case MT_OPERAND_RBBC : 704 errmsg = insert_normal (cd, fields->f_rbbc, 0, 0, 25, 2, 32, total_length, buffer); 705 break; 706 case MT_OPERAND_RC : 707 errmsg = insert_normal (cd, fields->f_rc, 0, 0, 15, 1, 32, total_length, buffer); 708 break; 709 case MT_OPERAND_RC1 : 710 errmsg = insert_normal (cd, fields->f_rc1, 0, 0, 11, 1, 32, total_length, buffer); 711 break; 712 case MT_OPERAND_RC2 : 713 errmsg = insert_normal (cd, fields->f_rc2, 0, 0, 6, 1, 32, total_length, buffer); 714 break; 715 case MT_OPERAND_RC3 : 716 errmsg = insert_normal (cd, fields->f_rc3, 0, 0, 7, 1, 32, total_length, buffer); 717 break; 718 case MT_OPERAND_RCNUM : 719 errmsg = insert_normal (cd, fields->f_rcnum, 0, 0, 14, 3, 32, total_length, buffer); 720 break; 721 case MT_OPERAND_RDA : 722 errmsg = insert_normal (cd, fields->f_rda, 0, 0, 25, 1, 32, total_length, buffer); 723 break; 724 case MT_OPERAND_ROWNUM : 725 errmsg = insert_normal (cd, fields->f_rownum, 0, 0, 14, 3, 32, total_length, buffer); 726 break; 727 case MT_OPERAND_ROWNUM1 : 728 errmsg = insert_normal (cd, fields->f_rownum1, 0, 0, 12, 3, 32, total_length, buffer); 729 break; 730 case MT_OPERAND_ROWNUM2 : 731 errmsg = insert_normal (cd, fields->f_rownum2, 0, 0, 9, 3, 32, total_length, buffer); 732 break; 733 case MT_OPERAND_SIZE : 734 errmsg = insert_normal (cd, fields->f_size, 0, 0, 13, 14, 32, total_length, buffer); 735 break; 736 case MT_OPERAND_TYPE : 737 errmsg = insert_normal (cd, fields->f_type, 0, 0, 21, 2, 32, total_length, buffer); 738 break; 739 case MT_OPERAND_WR : 740 errmsg = insert_normal (cd, fields->f_wr, 0, 0, 24, 1, 32, total_length, buffer); 741 break; 742 case MT_OPERAND_XMODE : 743 errmsg = insert_normal (cd, fields->f_xmode, 0, 0, 23, 1, 32, total_length, buffer); 744 break; 745 746 default : 747 /* xgettext:c-format */ 748 fprintf (stderr, _("Unrecognized field %d while building insn.\n"), 749 opindex); 750 abort (); 751 } 752 753 return errmsg; 754 } 755 756 int mt_cgen_extract_operand 757 (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma); 758 759 /* Main entry point for operand extraction. 760 The result is <= 0 for error, >0 for success. 761 ??? Actual values aren't well defined right now. 762 763 This function is basically just a big switch statement. Earlier versions 764 used tables to look up the function to use, but 765 - if the table contains both assembler and disassembler functions then 766 the disassembler contains much of the assembler and vice-versa, 767 - there's a lot of inlining possibilities as things grow, 768 - using a switch statement avoids the function call overhead. 769 770 This function could be moved into `print_insn_normal', but keeping it 771 separate makes clear the interface between `print_insn_normal' and each of 772 the handlers. */ 773 774 int 775 mt_cgen_extract_operand (CGEN_CPU_DESC cd, 776 int opindex, 777 CGEN_EXTRACT_INFO *ex_info, 778 CGEN_INSN_INT insn_value, 779 CGEN_FIELDS * fields, 780 bfd_vma pc) 781 { 782 /* Assume success (for those operands that are nops). */ 783 int length = 1; 784 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); 785 786 switch (opindex) 787 { 788 case MT_OPERAND_A23 : 789 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 1, 32, total_length, pc, & fields->f_a23); 790 break; 791 case MT_OPERAND_BALL : 792 length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 1, 32, total_length, pc, & fields->f_ball); 793 break; 794 case MT_OPERAND_BALL2 : 795 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 1, 32, total_length, pc, & fields->f_ball2); 796 break; 797 case MT_OPERAND_BANKADDR : 798 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 13, 32, total_length, pc, & fields->f_bankaddr); 799 break; 800 case MT_OPERAND_BRC : 801 length = extract_normal (cd, ex_info, insn_value, 0, 0, 18, 3, 32, total_length, pc, & fields->f_brc); 802 break; 803 case MT_OPERAND_BRC2 : 804 length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_brc2); 805 break; 806 case MT_OPERAND_CB1INCR : 807 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 19, 6, 32, total_length, pc, & fields->f_cb1incr); 808 break; 809 case MT_OPERAND_CB1SEL : 810 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 3, 32, total_length, pc, & fields->f_cb1sel); 811 break; 812 case MT_OPERAND_CB2INCR : 813 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 13, 6, 32, total_length, pc, & fields->f_cb2incr); 814 break; 815 case MT_OPERAND_CB2SEL : 816 length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_cb2sel); 817 break; 818 case MT_OPERAND_CBRB : 819 length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_cbrb); 820 break; 821 case MT_OPERAND_CBS : 822 length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 2, 32, total_length, pc, & fields->f_cbs); 823 break; 824 case MT_OPERAND_CBX : 825 length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_cbx); 826 break; 827 case MT_OPERAND_CCB : 828 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_ccb); 829 break; 830 case MT_OPERAND_CDB : 831 length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_cdb); 832 break; 833 case MT_OPERAND_CELL : 834 length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 3, 32, total_length, pc, & fields->f_cell); 835 break; 836 case MT_OPERAND_COLNUM : 837 length = extract_normal (cd, ex_info, insn_value, 0, 0, 18, 3, 32, total_length, pc, & fields->f_colnum); 838 break; 839 case MT_OPERAND_CONTNUM : 840 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 9, 32, total_length, pc, & fields->f_contnum); 841 break; 842 case MT_OPERAND_CR : 843 length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_cr); 844 break; 845 case MT_OPERAND_CTXDISP : 846 length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 6, 32, total_length, pc, & fields->f_ctxdisp); 847 break; 848 case MT_OPERAND_DUP : 849 length = extract_normal (cd, ex_info, insn_value, 0, 0, 6, 1, 32, total_length, pc, & fields->f_dup); 850 break; 851 case MT_OPERAND_FBDISP : 852 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 6, 32, total_length, pc, & fields->f_fbdisp); 853 break; 854 case MT_OPERAND_FBINCR : 855 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 4, 32, total_length, pc, & fields->f_fbincr); 856 break; 857 case MT_OPERAND_FRDR : 858 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, pc, & fields->f_dr); 859 break; 860 case MT_OPERAND_FRDRRR : 861 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 4, 32, total_length, pc, & fields->f_drrr); 862 break; 863 case MT_OPERAND_FRSR1 : 864 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 23, 4, 32, total_length, pc, & fields->f_sr1); 865 break; 866 case MT_OPERAND_FRSR2 : 867 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, pc, & fields->f_sr2); 868 break; 869 case MT_OPERAND_ID : 870 length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 1, 32, total_length, pc, & fields->f_id); 871 break; 872 case MT_OPERAND_IMM16 : 873 { 874 long value; 875 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, pc, & value); 876 value = ((value) + (0)); 877 fields->f_imm16s = value; 878 } 879 break; 880 case MT_OPERAND_IMM16L : 881 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 16, 32, total_length, pc, & fields->f_imm16l); 882 break; 883 case MT_OPERAND_IMM16O : 884 { 885 long value; 886 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, pc, & value); 887 value = ((value) + (0)); 888 fields->f_imm16s = value; 889 } 890 break; 891 case MT_OPERAND_IMM16Z : 892 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm16u); 893 break; 894 case MT_OPERAND_INCAMT : 895 length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 8, 32, total_length, pc, & fields->f_incamt); 896 break; 897 case MT_OPERAND_INCR : 898 length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 6, 32, total_length, pc, & fields->f_incr); 899 break; 900 case MT_OPERAND_LENGTH : 901 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 3, 32, total_length, pc, & fields->f_length); 902 break; 903 case MT_OPERAND_LOOPSIZE : 904 { 905 long value; 906 length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 32, total_length, pc, & value); 907 value = ((((value) << (2))) + (8)); 908 fields->f_loopo = value; 909 } 910 break; 911 case MT_OPERAND_MASK : 912 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 16, 32, total_length, pc, & fields->f_mask); 913 break; 914 case MT_OPERAND_MASK1 : 915 length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_mask1); 916 break; 917 case MT_OPERAND_MODE : 918 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_mode); 919 break; 920 case MT_OPERAND_PERM : 921 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_perm); 922 break; 923 case MT_OPERAND_RBBC : 924 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_rbbc); 925 break; 926 case MT_OPERAND_RC : 927 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 1, 32, total_length, pc, & fields->f_rc); 928 break; 929 case MT_OPERAND_RC1 : 930 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_rc1); 931 break; 932 case MT_OPERAND_RC2 : 933 length = extract_normal (cd, ex_info, insn_value, 0, 0, 6, 1, 32, total_length, pc, & fields->f_rc2); 934 break; 935 case MT_OPERAND_RC3 : 936 length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 1, 32, total_length, pc, & fields->f_rc3); 937 break; 938 case MT_OPERAND_RCNUM : 939 length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_rcnum); 940 break; 941 case MT_OPERAND_RDA : 942 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 1, 32, total_length, pc, & fields->f_rda); 943 break; 944 case MT_OPERAND_ROWNUM : 945 length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_rownum); 946 break; 947 case MT_OPERAND_ROWNUM1 : 948 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 3, 32, total_length, pc, & fields->f_rownum1); 949 break; 950 case MT_OPERAND_ROWNUM2 : 951 length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 3, 32, total_length, pc, & fields->f_rownum2); 952 break; 953 case MT_OPERAND_SIZE : 954 length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 14, 32, total_length, pc, & fields->f_size); 955 break; 956 case MT_OPERAND_TYPE : 957 length = extract_normal (cd, ex_info, insn_value, 0, 0, 21, 2, 32, total_length, pc, & fields->f_type); 958 break; 959 case MT_OPERAND_WR : 960 length = extract_normal (cd, ex_info, insn_value, 0, 0, 24, 1, 32, total_length, pc, & fields->f_wr); 961 break; 962 case MT_OPERAND_XMODE : 963 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 1, 32, total_length, pc, & fields->f_xmode); 964 break; 965 966 default : 967 /* xgettext:c-format */ 968 fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"), 969 opindex); 970 abort (); 971 } 972 973 return length; 974 } 975 976 cgen_insert_fn * const mt_cgen_insert_handlers[] = 977 { 978 insert_insn_normal, 979 }; 980 981 cgen_extract_fn * const mt_cgen_extract_handlers[] = 982 { 983 extract_insn_normal, 984 }; 985 986 int mt_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *); 987 bfd_vma mt_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *); 988 989 /* Getting values from cgen_fields is handled by a collection of functions. 990 They are distinguished by the type of the VALUE argument they return. 991 TODO: floating point, inlining support, remove cases where result type 992 not appropriate. */ 993 994 int 995 mt_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, 996 int opindex, 997 const CGEN_FIELDS * fields) 998 { 999 int value; 1000 1001 switch (opindex) 1002 { 1003 case MT_OPERAND_A23 : 1004 value = fields->f_a23; 1005 break; 1006 case MT_OPERAND_BALL : 1007 value = fields->f_ball; 1008 break; 1009 case MT_OPERAND_BALL2 : 1010 value = fields->f_ball2; 1011 break; 1012 case MT_OPERAND_BANKADDR : 1013 value = fields->f_bankaddr; 1014 break; 1015 case MT_OPERAND_BRC : 1016 value = fields->f_brc; 1017 break; 1018 case MT_OPERAND_BRC2 : 1019 value = fields->f_brc2; 1020 break; 1021 case MT_OPERAND_CB1INCR : 1022 value = fields->f_cb1incr; 1023 break; 1024 case MT_OPERAND_CB1SEL : 1025 value = fields->f_cb1sel; 1026 break; 1027 case MT_OPERAND_CB2INCR : 1028 value = fields->f_cb2incr; 1029 break; 1030 case MT_OPERAND_CB2SEL : 1031 value = fields->f_cb2sel; 1032 break; 1033 case MT_OPERAND_CBRB : 1034 value = fields->f_cbrb; 1035 break; 1036 case MT_OPERAND_CBS : 1037 value = fields->f_cbs; 1038 break; 1039 case MT_OPERAND_CBX : 1040 value = fields->f_cbx; 1041 break; 1042 case MT_OPERAND_CCB : 1043 value = fields->f_ccb; 1044 break; 1045 case MT_OPERAND_CDB : 1046 value = fields->f_cdb; 1047 break; 1048 case MT_OPERAND_CELL : 1049 value = fields->f_cell; 1050 break; 1051 case MT_OPERAND_COLNUM : 1052 value = fields->f_colnum; 1053 break; 1054 case MT_OPERAND_CONTNUM : 1055 value = fields->f_contnum; 1056 break; 1057 case MT_OPERAND_CR : 1058 value = fields->f_cr; 1059 break; 1060 case MT_OPERAND_CTXDISP : 1061 value = fields->f_ctxdisp; 1062 break; 1063 case MT_OPERAND_DUP : 1064 value = fields->f_dup; 1065 break; 1066 case MT_OPERAND_FBDISP : 1067 value = fields->f_fbdisp; 1068 break; 1069 case MT_OPERAND_FBINCR : 1070 value = fields->f_fbincr; 1071 break; 1072 case MT_OPERAND_FRDR : 1073 value = fields->f_dr; 1074 break; 1075 case MT_OPERAND_FRDRRR : 1076 value = fields->f_drrr; 1077 break; 1078 case MT_OPERAND_FRSR1 : 1079 value = fields->f_sr1; 1080 break; 1081 case MT_OPERAND_FRSR2 : 1082 value = fields->f_sr2; 1083 break; 1084 case MT_OPERAND_ID : 1085 value = fields->f_id; 1086 break; 1087 case MT_OPERAND_IMM16 : 1088 value = fields->f_imm16s; 1089 break; 1090 case MT_OPERAND_IMM16L : 1091 value = fields->f_imm16l; 1092 break; 1093 case MT_OPERAND_IMM16O : 1094 value = fields->f_imm16s; 1095 break; 1096 case MT_OPERAND_IMM16Z : 1097 value = fields->f_imm16u; 1098 break; 1099 case MT_OPERAND_INCAMT : 1100 value = fields->f_incamt; 1101 break; 1102 case MT_OPERAND_INCR : 1103 value = fields->f_incr; 1104 break; 1105 case MT_OPERAND_LENGTH : 1106 value = fields->f_length; 1107 break; 1108 case MT_OPERAND_LOOPSIZE : 1109 value = fields->f_loopo; 1110 break; 1111 case MT_OPERAND_MASK : 1112 value = fields->f_mask; 1113 break; 1114 case MT_OPERAND_MASK1 : 1115 value = fields->f_mask1; 1116 break; 1117 case MT_OPERAND_MODE : 1118 value = fields->f_mode; 1119 break; 1120 case MT_OPERAND_PERM : 1121 value = fields->f_perm; 1122 break; 1123 case MT_OPERAND_RBBC : 1124 value = fields->f_rbbc; 1125 break; 1126 case MT_OPERAND_RC : 1127 value = fields->f_rc; 1128 break; 1129 case MT_OPERAND_RC1 : 1130 value = fields->f_rc1; 1131 break; 1132 case MT_OPERAND_RC2 : 1133 value = fields->f_rc2; 1134 break; 1135 case MT_OPERAND_RC3 : 1136 value = fields->f_rc3; 1137 break; 1138 case MT_OPERAND_RCNUM : 1139 value = fields->f_rcnum; 1140 break; 1141 case MT_OPERAND_RDA : 1142 value = fields->f_rda; 1143 break; 1144 case MT_OPERAND_ROWNUM : 1145 value = fields->f_rownum; 1146 break; 1147 case MT_OPERAND_ROWNUM1 : 1148 value = fields->f_rownum1; 1149 break; 1150 case MT_OPERAND_ROWNUM2 : 1151 value = fields->f_rownum2; 1152 break; 1153 case MT_OPERAND_SIZE : 1154 value = fields->f_size; 1155 break; 1156 case MT_OPERAND_TYPE : 1157 value = fields->f_type; 1158 break; 1159 case MT_OPERAND_WR : 1160 value = fields->f_wr; 1161 break; 1162 case MT_OPERAND_XMODE : 1163 value = fields->f_xmode; 1164 break; 1165 1166 default : 1167 /* xgettext:c-format */ 1168 fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"), 1169 opindex); 1170 abort (); 1171 } 1172 1173 return value; 1174 } 1175 1176 bfd_vma 1177 mt_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, 1178 int opindex, 1179 const CGEN_FIELDS * fields) 1180 { 1181 bfd_vma value; 1182 1183 switch (opindex) 1184 { 1185 case MT_OPERAND_A23 : 1186 value = fields->f_a23; 1187 break; 1188 case MT_OPERAND_BALL : 1189 value = fields->f_ball; 1190 break; 1191 case MT_OPERAND_BALL2 : 1192 value = fields->f_ball2; 1193 break; 1194 case MT_OPERAND_BANKADDR : 1195 value = fields->f_bankaddr; 1196 break; 1197 case MT_OPERAND_BRC : 1198 value = fields->f_brc; 1199 break; 1200 case MT_OPERAND_BRC2 : 1201 value = fields->f_brc2; 1202 break; 1203 case MT_OPERAND_CB1INCR : 1204 value = fields->f_cb1incr; 1205 break; 1206 case MT_OPERAND_CB1SEL : 1207 value = fields->f_cb1sel; 1208 break; 1209 case MT_OPERAND_CB2INCR : 1210 value = fields->f_cb2incr; 1211 break; 1212 case MT_OPERAND_CB2SEL : 1213 value = fields->f_cb2sel; 1214 break; 1215 case MT_OPERAND_CBRB : 1216 value = fields->f_cbrb; 1217 break; 1218 case MT_OPERAND_CBS : 1219 value = fields->f_cbs; 1220 break; 1221 case MT_OPERAND_CBX : 1222 value = fields->f_cbx; 1223 break; 1224 case MT_OPERAND_CCB : 1225 value = fields->f_ccb; 1226 break; 1227 case MT_OPERAND_CDB : 1228 value = fields->f_cdb; 1229 break; 1230 case MT_OPERAND_CELL : 1231 value = fields->f_cell; 1232 break; 1233 case MT_OPERAND_COLNUM : 1234 value = fields->f_colnum; 1235 break; 1236 case MT_OPERAND_CONTNUM : 1237 value = fields->f_contnum; 1238 break; 1239 case MT_OPERAND_CR : 1240 value = fields->f_cr; 1241 break; 1242 case MT_OPERAND_CTXDISP : 1243 value = fields->f_ctxdisp; 1244 break; 1245 case MT_OPERAND_DUP : 1246 value = fields->f_dup; 1247 break; 1248 case MT_OPERAND_FBDISP : 1249 value = fields->f_fbdisp; 1250 break; 1251 case MT_OPERAND_FBINCR : 1252 value = fields->f_fbincr; 1253 break; 1254 case MT_OPERAND_FRDR : 1255 value = fields->f_dr; 1256 break; 1257 case MT_OPERAND_FRDRRR : 1258 value = fields->f_drrr; 1259 break; 1260 case MT_OPERAND_FRSR1 : 1261 value = fields->f_sr1; 1262 break; 1263 case MT_OPERAND_FRSR2 : 1264 value = fields->f_sr2; 1265 break; 1266 case MT_OPERAND_ID : 1267 value = fields->f_id; 1268 break; 1269 case MT_OPERAND_IMM16 : 1270 value = fields->f_imm16s; 1271 break; 1272 case MT_OPERAND_IMM16L : 1273 value = fields->f_imm16l; 1274 break; 1275 case MT_OPERAND_IMM16O : 1276 value = fields->f_imm16s; 1277 break; 1278 case MT_OPERAND_IMM16Z : 1279 value = fields->f_imm16u; 1280 break; 1281 case MT_OPERAND_INCAMT : 1282 value = fields->f_incamt; 1283 break; 1284 case MT_OPERAND_INCR : 1285 value = fields->f_incr; 1286 break; 1287 case MT_OPERAND_LENGTH : 1288 value = fields->f_length; 1289 break; 1290 case MT_OPERAND_LOOPSIZE : 1291 value = fields->f_loopo; 1292 break; 1293 case MT_OPERAND_MASK : 1294 value = fields->f_mask; 1295 break; 1296 case MT_OPERAND_MASK1 : 1297 value = fields->f_mask1; 1298 break; 1299 case MT_OPERAND_MODE : 1300 value = fields->f_mode; 1301 break; 1302 case MT_OPERAND_PERM : 1303 value = fields->f_perm; 1304 break; 1305 case MT_OPERAND_RBBC : 1306 value = fields->f_rbbc; 1307 break; 1308 case MT_OPERAND_RC : 1309 value = fields->f_rc; 1310 break; 1311 case MT_OPERAND_RC1 : 1312 value = fields->f_rc1; 1313 break; 1314 case MT_OPERAND_RC2 : 1315 value = fields->f_rc2; 1316 break; 1317 case MT_OPERAND_RC3 : 1318 value = fields->f_rc3; 1319 break; 1320 case MT_OPERAND_RCNUM : 1321 value = fields->f_rcnum; 1322 break; 1323 case MT_OPERAND_RDA : 1324 value = fields->f_rda; 1325 break; 1326 case MT_OPERAND_ROWNUM : 1327 value = fields->f_rownum; 1328 break; 1329 case MT_OPERAND_ROWNUM1 : 1330 value = fields->f_rownum1; 1331 break; 1332 case MT_OPERAND_ROWNUM2 : 1333 value = fields->f_rownum2; 1334 break; 1335 case MT_OPERAND_SIZE : 1336 value = fields->f_size; 1337 break; 1338 case MT_OPERAND_TYPE : 1339 value = fields->f_type; 1340 break; 1341 case MT_OPERAND_WR : 1342 value = fields->f_wr; 1343 break; 1344 case MT_OPERAND_XMODE : 1345 value = fields->f_xmode; 1346 break; 1347 1348 default : 1349 /* xgettext:c-format */ 1350 fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"), 1351 opindex); 1352 abort (); 1353 } 1354 1355 return value; 1356 } 1357 1358 void mt_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int); 1359 void mt_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma); 1360 1361 /* Stuffing values in cgen_fields is handled by a collection of functions. 1362 They are distinguished by the type of the VALUE argument they accept. 1363 TODO: floating point, inlining support, remove cases where argument type 1364 not appropriate. */ 1365 1366 void 1367 mt_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, 1368 int opindex, 1369 CGEN_FIELDS * fields, 1370 int value) 1371 { 1372 switch (opindex) 1373 { 1374 case MT_OPERAND_A23 : 1375 fields->f_a23 = value; 1376 break; 1377 case MT_OPERAND_BALL : 1378 fields->f_ball = value; 1379 break; 1380 case MT_OPERAND_BALL2 : 1381 fields->f_ball2 = value; 1382 break; 1383 case MT_OPERAND_BANKADDR : 1384 fields->f_bankaddr = value; 1385 break; 1386 case MT_OPERAND_BRC : 1387 fields->f_brc = value; 1388 break; 1389 case MT_OPERAND_BRC2 : 1390 fields->f_brc2 = value; 1391 break; 1392 case MT_OPERAND_CB1INCR : 1393 fields->f_cb1incr = value; 1394 break; 1395 case MT_OPERAND_CB1SEL : 1396 fields->f_cb1sel = value; 1397 break; 1398 case MT_OPERAND_CB2INCR : 1399 fields->f_cb2incr = value; 1400 break; 1401 case MT_OPERAND_CB2SEL : 1402 fields->f_cb2sel = value; 1403 break; 1404 case MT_OPERAND_CBRB : 1405 fields->f_cbrb = value; 1406 break; 1407 case MT_OPERAND_CBS : 1408 fields->f_cbs = value; 1409 break; 1410 case MT_OPERAND_CBX : 1411 fields->f_cbx = value; 1412 break; 1413 case MT_OPERAND_CCB : 1414 fields->f_ccb = value; 1415 break; 1416 case MT_OPERAND_CDB : 1417 fields->f_cdb = value; 1418 break; 1419 case MT_OPERAND_CELL : 1420 fields->f_cell = value; 1421 break; 1422 case MT_OPERAND_COLNUM : 1423 fields->f_colnum = value; 1424 break; 1425 case MT_OPERAND_CONTNUM : 1426 fields->f_contnum = value; 1427 break; 1428 case MT_OPERAND_CR : 1429 fields->f_cr = value; 1430 break; 1431 case MT_OPERAND_CTXDISP : 1432 fields->f_ctxdisp = value; 1433 break; 1434 case MT_OPERAND_DUP : 1435 fields->f_dup = value; 1436 break; 1437 case MT_OPERAND_FBDISP : 1438 fields->f_fbdisp = value; 1439 break; 1440 case MT_OPERAND_FBINCR : 1441 fields->f_fbincr = value; 1442 break; 1443 case MT_OPERAND_FRDR : 1444 fields->f_dr = value; 1445 break; 1446 case MT_OPERAND_FRDRRR : 1447 fields->f_drrr = value; 1448 break; 1449 case MT_OPERAND_FRSR1 : 1450 fields->f_sr1 = value; 1451 break; 1452 case MT_OPERAND_FRSR2 : 1453 fields->f_sr2 = value; 1454 break; 1455 case MT_OPERAND_ID : 1456 fields->f_id = value; 1457 break; 1458 case MT_OPERAND_IMM16 : 1459 fields->f_imm16s = value; 1460 break; 1461 case MT_OPERAND_IMM16L : 1462 fields->f_imm16l = value; 1463 break; 1464 case MT_OPERAND_IMM16O : 1465 fields->f_imm16s = value; 1466 break; 1467 case MT_OPERAND_IMM16Z : 1468 fields->f_imm16u = value; 1469 break; 1470 case MT_OPERAND_INCAMT : 1471 fields->f_incamt = value; 1472 break; 1473 case MT_OPERAND_INCR : 1474 fields->f_incr = value; 1475 break; 1476 case MT_OPERAND_LENGTH : 1477 fields->f_length = value; 1478 break; 1479 case MT_OPERAND_LOOPSIZE : 1480 fields->f_loopo = value; 1481 break; 1482 case MT_OPERAND_MASK : 1483 fields->f_mask = value; 1484 break; 1485 case MT_OPERAND_MASK1 : 1486 fields->f_mask1 = value; 1487 break; 1488 case MT_OPERAND_MODE : 1489 fields->f_mode = value; 1490 break; 1491 case MT_OPERAND_PERM : 1492 fields->f_perm = value; 1493 break; 1494 case MT_OPERAND_RBBC : 1495 fields->f_rbbc = value; 1496 break; 1497 case MT_OPERAND_RC : 1498 fields->f_rc = value; 1499 break; 1500 case MT_OPERAND_RC1 : 1501 fields->f_rc1 = value; 1502 break; 1503 case MT_OPERAND_RC2 : 1504 fields->f_rc2 = value; 1505 break; 1506 case MT_OPERAND_RC3 : 1507 fields->f_rc3 = value; 1508 break; 1509 case MT_OPERAND_RCNUM : 1510 fields->f_rcnum = value; 1511 break; 1512 case MT_OPERAND_RDA : 1513 fields->f_rda = value; 1514 break; 1515 case MT_OPERAND_ROWNUM : 1516 fields->f_rownum = value; 1517 break; 1518 case MT_OPERAND_ROWNUM1 : 1519 fields->f_rownum1 = value; 1520 break; 1521 case MT_OPERAND_ROWNUM2 : 1522 fields->f_rownum2 = value; 1523 break; 1524 case MT_OPERAND_SIZE : 1525 fields->f_size = value; 1526 break; 1527 case MT_OPERAND_TYPE : 1528 fields->f_type = value; 1529 break; 1530 case MT_OPERAND_WR : 1531 fields->f_wr = value; 1532 break; 1533 case MT_OPERAND_XMODE : 1534 fields->f_xmode = value; 1535 break; 1536 1537 default : 1538 /* xgettext:c-format */ 1539 fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"), 1540 opindex); 1541 abort (); 1542 } 1543 } 1544 1545 void 1546 mt_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, 1547 int opindex, 1548 CGEN_FIELDS * fields, 1549 bfd_vma value) 1550 { 1551 switch (opindex) 1552 { 1553 case MT_OPERAND_A23 : 1554 fields->f_a23 = value; 1555 break; 1556 case MT_OPERAND_BALL : 1557 fields->f_ball = value; 1558 break; 1559 case MT_OPERAND_BALL2 : 1560 fields->f_ball2 = value; 1561 break; 1562 case MT_OPERAND_BANKADDR : 1563 fields->f_bankaddr = value; 1564 break; 1565 case MT_OPERAND_BRC : 1566 fields->f_brc = value; 1567 break; 1568 case MT_OPERAND_BRC2 : 1569 fields->f_brc2 = value; 1570 break; 1571 case MT_OPERAND_CB1INCR : 1572 fields->f_cb1incr = value; 1573 break; 1574 case MT_OPERAND_CB1SEL : 1575 fields->f_cb1sel = value; 1576 break; 1577 case MT_OPERAND_CB2INCR : 1578 fields->f_cb2incr = value; 1579 break; 1580 case MT_OPERAND_CB2SEL : 1581 fields->f_cb2sel = value; 1582 break; 1583 case MT_OPERAND_CBRB : 1584 fields->f_cbrb = value; 1585 break; 1586 case MT_OPERAND_CBS : 1587 fields->f_cbs = value; 1588 break; 1589 case MT_OPERAND_CBX : 1590 fields->f_cbx = value; 1591 break; 1592 case MT_OPERAND_CCB : 1593 fields->f_ccb = value; 1594 break; 1595 case MT_OPERAND_CDB : 1596 fields->f_cdb = value; 1597 break; 1598 case MT_OPERAND_CELL : 1599 fields->f_cell = value; 1600 break; 1601 case MT_OPERAND_COLNUM : 1602 fields->f_colnum = value; 1603 break; 1604 case MT_OPERAND_CONTNUM : 1605 fields->f_contnum = value; 1606 break; 1607 case MT_OPERAND_CR : 1608 fields->f_cr = value; 1609 break; 1610 case MT_OPERAND_CTXDISP : 1611 fields->f_ctxdisp = value; 1612 break; 1613 case MT_OPERAND_DUP : 1614 fields->f_dup = value; 1615 break; 1616 case MT_OPERAND_FBDISP : 1617 fields->f_fbdisp = value; 1618 break; 1619 case MT_OPERAND_FBINCR : 1620 fields->f_fbincr = value; 1621 break; 1622 case MT_OPERAND_FRDR : 1623 fields->f_dr = value; 1624 break; 1625 case MT_OPERAND_FRDRRR : 1626 fields->f_drrr = value; 1627 break; 1628 case MT_OPERAND_FRSR1 : 1629 fields->f_sr1 = value; 1630 break; 1631 case MT_OPERAND_FRSR2 : 1632 fields->f_sr2 = value; 1633 break; 1634 case MT_OPERAND_ID : 1635 fields->f_id = value; 1636 break; 1637 case MT_OPERAND_IMM16 : 1638 fields->f_imm16s = value; 1639 break; 1640 case MT_OPERAND_IMM16L : 1641 fields->f_imm16l = value; 1642 break; 1643 case MT_OPERAND_IMM16O : 1644 fields->f_imm16s = value; 1645 break; 1646 case MT_OPERAND_IMM16Z : 1647 fields->f_imm16u = value; 1648 break; 1649 case MT_OPERAND_INCAMT : 1650 fields->f_incamt = value; 1651 break; 1652 case MT_OPERAND_INCR : 1653 fields->f_incr = value; 1654 break; 1655 case MT_OPERAND_LENGTH : 1656 fields->f_length = value; 1657 break; 1658 case MT_OPERAND_LOOPSIZE : 1659 fields->f_loopo = value; 1660 break; 1661 case MT_OPERAND_MASK : 1662 fields->f_mask = value; 1663 break; 1664 case MT_OPERAND_MASK1 : 1665 fields->f_mask1 = value; 1666 break; 1667 case MT_OPERAND_MODE : 1668 fields->f_mode = value; 1669 break; 1670 case MT_OPERAND_PERM : 1671 fields->f_perm = value; 1672 break; 1673 case MT_OPERAND_RBBC : 1674 fields->f_rbbc = value; 1675 break; 1676 case MT_OPERAND_RC : 1677 fields->f_rc = value; 1678 break; 1679 case MT_OPERAND_RC1 : 1680 fields->f_rc1 = value; 1681 break; 1682 case MT_OPERAND_RC2 : 1683 fields->f_rc2 = value; 1684 break; 1685 case MT_OPERAND_RC3 : 1686 fields->f_rc3 = value; 1687 break; 1688 case MT_OPERAND_RCNUM : 1689 fields->f_rcnum = value; 1690 break; 1691 case MT_OPERAND_RDA : 1692 fields->f_rda = value; 1693 break; 1694 case MT_OPERAND_ROWNUM : 1695 fields->f_rownum = value; 1696 break; 1697 case MT_OPERAND_ROWNUM1 : 1698 fields->f_rownum1 = value; 1699 break; 1700 case MT_OPERAND_ROWNUM2 : 1701 fields->f_rownum2 = value; 1702 break; 1703 case MT_OPERAND_SIZE : 1704 fields->f_size = value; 1705 break; 1706 case MT_OPERAND_TYPE : 1707 fields->f_type = value; 1708 break; 1709 case MT_OPERAND_WR : 1710 fields->f_wr = value; 1711 break; 1712 case MT_OPERAND_XMODE : 1713 fields->f_xmode = value; 1714 break; 1715 1716 default : 1717 /* xgettext:c-format */ 1718 fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"), 1719 opindex); 1720 abort (); 1721 } 1722 } 1723 1724 /* Function to call before using the instruction builder tables. */ 1725 1726 void 1727 mt_cgen_init_ibld_table (CGEN_CPU_DESC cd) 1728 { 1729 cd->insert_handlers = & mt_cgen_insert_handlers[0]; 1730 cd->extract_handlers = & mt_cgen_extract_handlers[0]; 1731 1732 cd->insert_operand = mt_cgen_insert_operand; 1733 cd->extract_operand = mt_cgen_extract_operand; 1734 1735 cd->get_int_operand = mt_cgen_get_int_operand; 1736 cd->set_int_operand = mt_cgen_set_int_operand; 1737 cd->get_vma_operand = mt_cgen_get_vma_operand; 1738 cd->set_vma_operand = mt_cgen_set_vma_operand; 1739 } 1740