Changeset 609 for branches/GNU/src/binutils/opcodes/m32r-ibld.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/opcodes/m32r-ibld.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 26 26 27 27 #include "sysdep.h" 28 #include <ctype.h>29 28 #include <stdio.h> 30 29 #include "ansidecl.h" … … 35 34 #include "m32r-opc.h" 36 35 #include "opintl.h" 36 #include "safe-ctype.h" 37 37 38 38 #undef min … … 50 50 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, 51 51 CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma)); 52 53 52 static int extract_normal 54 53 PARAMS ((CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, … … 58 57 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *, 59 58 CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma)); 59 #if CGEN_INT_INSN_P 60 60 static void put_insn_int_value 61 61 PARAMS ((CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT)); 62 62 #endif 63 #if ! CGEN_INT_INSN_P 64 static CGEN_INLINE void insert_1 65 PARAMS ((CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *)); 66 static CGEN_INLINE int fill_cache 67 PARAMS ((CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, bfd_vma)); 68 static CGEN_INLINE long extract_1 69 PARAMS ((CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, 70 unsigned char *, bfd_vma)); 71 #endif 63 72 64 73 … … 78 87 unsigned long x,mask; 79 88 int shift; 80 int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG; 81 82 switch (word_length) 83 { 84 case 8: 85 x = *bufp; 86 break; 87 case 16: 88 if (big_p) 89 x = bfd_getb16 (bufp); 90 else 91 x = bfd_getl16 (bufp); 92 break; 93 case 24: 94 /* ??? This may need reworking as these cases don't necessarily 95 want the first byte and the last two bytes handled like this. */ 96 if (big_p) 97 x = (bufp[0] << 16) | bfd_getb16 (bufp + 1); 98 else 99 x = bfd_getl16 (bufp) | (bufp[2] << 16); 100 break; 101 case 32: 102 if (big_p) 103 x = bfd_getb32 (bufp); 104 else 105 x = bfd_getl32 (bufp); 106 break; 107 default : 108 abort (); 109 } 89 90 x = cgen_get_insn_value (cd, bufp, word_length); 110 91 111 92 /* Written this way to avoid undefined behaviour. */ … … 117 98 x = (x & ~(mask << shift)) | ((value & mask) << shift); 118 99 119 switch (word_length) 120 { 121 case 8: 122 *bufp = x; 123 break; 124 case 16: 125 if (big_p) 126 bfd_putb16 (x, bufp); 127 else 128 bfd_putl16 (x, bufp); 129 break; 130 case 24: 131 /* ??? This may need reworking as these cases don't necessarily 132 want the first byte and the last two bytes handled like this. */ 133 if (big_p) 134 { 135 bufp[0] = x >> 16; 136 bfd_putb16 (x, bufp + 1); 137 } 138 else 139 { 140 bfd_putl16 (x, bufp); 141 bufp[2] = x >> 16; 142 } 143 break; 144 case 32: 145 if (big_p) 146 bfd_putb32 (x, bufp); 147 else 148 bfd_putl32 (x, bufp); 149 break; 150 default : 151 abort (); 152 } 100 cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x); 153 101 } 154 102 … … 207 155 208 156 /* Ensure VALUE will fit. */ 209 if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)) 157 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT)) 158 { 159 long minval = - (1L << (length - 1)); 160 unsigned long maxval = mask; 161 162 if ((value > 0 && (unsigned long) value > maxval) 163 || value < minval) 164 { 165 /* xgettext:c-format */ 166 sprintf (errbuf, 167 _("operand out of range (%ld not between %ld and %lu)"), 168 value, minval, maxval); 169 return errbuf; 170 } 171 } 172 else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)) 210 173 { 211 174 unsigned long maxval = mask; … … 264 227 265 228 /* Default insn builder (insert handler). 266 The instruction is recorded in CGEN_INT_INSN_P byte order 267 (meaning that if CGEN_INT_INSN_P BUFFER is an int * and thusthe value is268 recorded in host byte order, otherwise BUFFER is an array of bytes and the269 value is recorded in target byte order).229 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning 230 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is 231 recorded in host byte order, otherwise BUFFER is an array of bytes 232 and the value is recorded in target byte order). 270 233 The result is an error message or NULL if success. */ 271 234 … … 280 243 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); 281 244 unsigned long value; 282 const unsigned char* syn;245 const CGEN_SYNTAX_CHAR_TYPE * syn; 283 246 284 247 CGEN_INIT_INSERT (cd); … … 295 258 #else 296 259 297 cgen_put_insn_value (cd, buffer, min ( cd->base_insn_bitsize,298 CGEN_FIELDS_BITSIZE (fields)),260 cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize, 261 (unsigned) CGEN_FIELDS_BITSIZE (fields)), 299 262 value); 300 263 … … 306 269 Needs more thought first. */ 307 270 308 for (syn = CGEN_SYNTAX_STRING (syntax); * syn != '\0'; ++ syn)271 for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn) 309 272 { 310 273 const char *errmsg; … … 322 285 } 323 286 287 #if CGEN_INT_INSN_P 324 288 /* Cover function to store an insn value into an integral insn. Must go here 325 289 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */ … … 327 291 static void 328 292 put_insn_int_value (cd, buf, length, insn_length, value) 329 CGEN_CPU_DESC cd ;293 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED; 330 294 CGEN_INSN_BYTES_PTR buf; 331 295 int length; … … 345 309 } 346 310 } 311 #endif 347 312 348 313 … … 359 324 static CGEN_INLINE int 360 325 fill_cache (cd, ex_info, offset, bytes, pc) 361 CGEN_CPU_DESC cd ;326 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED; 362 327 CGEN_EXTRACT_INFO *ex_info; 363 328 int offset, bytes; … … 366 331 /* It's doubtful that the middle part has already been fetched so 367 332 we don't optimize that case. kiss. */ 368 int mask;333 unsigned int mask; 369 334 disassemble_info *info = (disassemble_info *) ex_info->dis_info; 370 335 … … 404 369 extract_1 (cd, ex_info, start, length, word_length, bufp, pc) 405 370 CGEN_CPU_DESC cd; 406 CGEN_EXTRACT_INFO *ex_info ;371 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED; 407 372 int start,length,word_length; 408 373 unsigned char *bufp; 409 bfd_vma pc ;410 { 411 unsigned long x ,mask;374 bfd_vma pc ATTRIBUTE_UNUSED; 375 { 376 unsigned long x; 412 377 int shift; 378 #if 0 413 379 int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG; 414 415 switch (word_length) 416 { 417 case 8: 418 x = *bufp; 419 break; 420 case 16: 421 if (big_p) 422 x = bfd_getb16 (bufp); 423 else 424 x = bfd_getl16 (bufp); 425 break; 426 case 24: 427 /* ??? This may need reworking as these cases don't necessarily 428 want the first byte and the last two bytes handled like this. */ 429 if (big_p) 430 x = (bufp[0] << 16) | bfd_getb16 (bufp + 1); 431 else 432 x = bfd_getl16 (bufp) | (bufp[2] << 16); 433 break; 434 case 32: 435 if (big_p) 436 x = bfd_getb32 (bufp); 437 else 438 x = bfd_getl32 (bufp); 439 break; 440 default : 441 abort (); 442 } 443 444 /* Written this way to avoid undefined behaviour. */ 445 mask = (((1L << (length - 1)) - 1) << 1) | 1; 380 #endif 381 x = cgen_get_insn_value (cd, bufp, word_length); 382 446 383 if (CGEN_INSN_LSB0_P) 447 384 shift = (start + 1) - length; 448 385 else 449 386 shift = (word_length - (start + length)); 450 return (x >> shift) & mask;387 return x >> shift; 451 388 } 452 389 … … 492 429 long *valuep; 493 430 { 494 CGEN_INSN_INT value;431 long value, mask; 495 432 496 433 /* If LENGTH is zero, this operand doesn't contribute to the value … … 520 457 } 521 458 522 /* Does the value reside in INSN_VALUE? */ 523 524 if (CGEN_INT_INSN_P || word_offset == 0) 525 { 526 /* Written this way to avoid undefined behaviour. */ 527 CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1; 528 459 /* Does the value reside in INSN_VALUE, and at the right alignment? */ 460 461 if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length)) 462 { 529 463 if (CGEN_INSN_LSB0_P) 530 464 value = insn_value >> ((word_offset + start + 1) - length); 531 465 else 532 466 value = insn_value >> (total_length - ( word_offset + start + length)); 533 value &= mask;534 /* sign extend? */535 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)536 && (value & (1L << (length - 1))))537 value |= ~mask;538 467 } 539 468 … … 554 483 555 484 #endif /* ! CGEN_INT_INSN_P */ 485 486 /* Written this way to avoid undefined behaviour. */ 487 mask = (((1L << (length - 1)) - 1) << 1) | 1; 488 489 value &= mask; 490 /* sign extend? */ 491 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED) 492 && (value & (1L << (length - 1)))) 493 value |= ~mask; 556 494 557 495 *valuep = value; … … 579 517 { 580 518 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); 581 const unsigned char*syn;519 const CGEN_SYNTAX_CHAR_TYPE *syn; 582 520 583 521 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); … … 604 542 605 543 /* machine generated code added here */ 544 545 const char * m32r_cgen_insert_operand 546 PARAMS ((CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma)); 606 547 607 548 /* Main entry point for operand insertion. … … 617 558 separate makes clear the interface between `parse_insn_normal' and each of 618 559 the handlers. It's also needed by GAS to insert operands that couldn't be 619 resolved during parsing. 620 */ 560 resolved during parsing. */ 621 561 622 562 const char * … … 626 566 CGEN_FIELDS * fields; 627 567 CGEN_INSN_BYTES_PTR buffer; 628 bfd_vma pc ;568 bfd_vma pc ATTRIBUTE_UNUSED; 629 569 { 630 570 const char * errmsg = NULL; … … 728 668 } 729 669 670 int m32r_cgen_extract_operand 671 PARAMS ((CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, 672 CGEN_FIELDS *, bfd_vma)); 673 730 674 /* Main entry point for operand extraction. 731 675 The result is <= 0 for error, >0 for success. … … 741 685 This function could be moved into `print_insn_normal', but keeping it 742 686 separate makes clear the interface between `print_insn_normal' and each of 743 the handlers. 744 */ 687 the handlers. */ 745 688 746 689 int … … 868 811 }; 869 812 813 int m32r_cgen_get_int_operand 814 PARAMS ((CGEN_CPU_DESC, int, const CGEN_FIELDS *)); 815 bfd_vma m32r_cgen_get_vma_operand 816 PARAMS ((CGEN_CPU_DESC, int, const CGEN_FIELDS *)); 817 870 818 /* Getting values from cgen_fields is handled by a collection of functions. 871 819 They are distinguished by the type of the VALUE argument they return. … … 875 823 int 876 824 m32r_cgen_get_int_operand (cd, opindex, fields) 877 CGEN_CPU_DESC cd ;825 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED; 878 826 int opindex; 879 827 const CGEN_FIELDS * fields; … … 965 913 bfd_vma 966 914 m32r_cgen_get_vma_operand (cd, opindex, fields) 967 CGEN_CPU_DESC cd ;915 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED; 968 916 int opindex; 969 917 const CGEN_FIELDS * fields; … … 1053 1001 } 1054 1002 1003 void m32r_cgen_set_int_operand 1004 PARAMS ((CGEN_CPU_DESC, int, CGEN_FIELDS *, int)); 1005 void m32r_cgen_set_vma_operand 1006 PARAMS ((CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma)); 1007 1055 1008 /* Stuffing values in cgen_fields is handled by a collection of functions. 1056 1009 They are distinguished by the type of the VALUE argument they accept. … … 1060 1013 void 1061 1014 m32r_cgen_set_int_operand (cd, opindex, fields, value) 1062 CGEN_CPU_DESC cd ;1015 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED; 1063 1016 int opindex; 1064 1017 CGEN_FIELDS * fields; … … 1146 1099 void 1147 1100 m32r_cgen_set_vma_operand (cd, opindex, fields, value) 1148 CGEN_CPU_DESC cd ;1101 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED; 1149 1102 int opindex; 1150 1103 CGEN_FIELDS * fields; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.