Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 #ifdef _KEEP_RCS_ID 00037 static const char source_file[] = __FILE__; 00038 #endif /* _KEEP_RCS_ID */ 00039 00040 #include <stdio.h> 00041 #include <assert.h> 00042 #include <strings.h> 00043 00044 #include "topcode.h" 00045 #include "targ_isa_operands.h" 00046 #include "targ_isa_print.h" 00047 #include "targ_isa_pack.h" 00048 #include "targ_isa_bundle.h" 00049 #include "targ_isa_decode.h" 00050 #include "targ_isa_pseudo.h" 00051 #include "targ_isa_enums.h" 00052 #include "targ_isa_operands.h" 00053 #include "targ_abi_properties.h" 00054 #include "targ_proc_properties.h" 00055 00056 #include "ti_errors.h" 00057 #include "ti_asm.h" 00058 00059 /* ==================================================================== 00060 * 00061 * TI_ASM_Pack_Inst 00062 * 00063 * See interface description 00064 * 00065 * ==================================================================== 00066 */ 00067 INT TI_ASM_Pack_Inst( 00068 TOP topcode, 00069 const INT64 *result, 00070 const INT64 *opnd, 00071 ISA_PACK_INST *pinst) 00072 { 00073 INT comp; 00074 INT words; 00075 INT w; 00076 const ISA_PACK_INFO *pinfo; 00077 const ISA_PACK_ADJ_INFO *ainfo; 00078 INT64 bopnd[ISA_OPERAND_max_operands]; 00079 INT64 bresult[ISA_OPERAND_max_results]; 00080 00081 bcopy(opnd, bopnd, sizeof(bopnd)); 00082 bcopy(result, bresult, sizeof(bresult)); 00083 00084 topcode = ISA_PSEUDO_Translate(topcode, 00085 bresult, 00086 bopnd, 00087 ISA_PSEUDO_to_machine); 00088 00089 pinfo = ISA_PACK_Info(topcode); 00090 if (!pinfo) { 00091 sprintf(TI_errmsg, "no ISA_PACK_INFO for %s", TOP_Name(topcode)); 00092 return TI_RC_ERROR; 00093 } 00094 00095 ainfo = ISA_PACK_Adj_Info(topcode); 00096 if (ainfo) ISA_PACK_Adjust_Operands(ainfo, bopnd, FALSE); 00097 00098 words = ISA_PACK_Inst_Words(topcode); 00099 for (w = 0; w < words; ++w) { 00100 ISA_PACK_INST inst = ISA_PACK_Init_Mask(topcode, w); 00101 do { 00102 UINT64 mask = ISA_PACK_INFO_Mask(pinfo); 00103 UINT opndpos = ISA_PACK_INFO_OpndPos(pinfo); 00104 UINT instpos = ISA_PACK_INFO_InstPos(pinfo); 00105 comp = ISA_PACK_INFO_Comp(pinfo); 00106 00107 switch (comp) { 00108 case ISA_PACK_COMP_opnd: 00109 case ISA_PACK_COMP_opnd+1: 00110 case ISA_PACK_COMP_opnd+2: 00111 case ISA_PACK_COMP_opnd+3: 00112 case ISA_PACK_COMP_opnd+4: 00113 case ISA_PACK_COMP_opnd+5: 00114 { 00115 INT n = comp - ISA_PACK_COMP_opnd; 00116 inst |= ((bopnd[n] >> opndpos) & mask) << instpos; 00117 } 00118 break; 00119 00120 case ISA_PACK_COMP_result: 00121 case ISA_PACK_COMP_result+1: 00122 { 00123 INT n = comp - ISA_PACK_COMP_result; 00124 inst |= ((bresult[n] >> opndpos) & mask) << instpos; 00125 } 00126 break; 00127 00128 case ISA_PACK_COMP_end: 00129 pinst[w] = inst; 00130 break; 00131 00132 default: 00133 sprintf(TI_errmsg, "Unhandled packing component %d for %s", 00134 comp, TOP_Name(topcode)); 00135 return TI_RC_ERROR; 00136 } 00137 } while (++pinfo, comp != ISA_PACK_COMP_end); 00138 } 00139 00140 return words; 00141 } 00142 00143 /* ==================================================================== 00144 * 00145 * TI_ASM_Print_Inst 00146 * 00147 * See interface description 00148 * 00149 * ==================================================================== 00150 */ 00151 INT TI_ASM_Print_Inst( 00152 TOP topcode, 00153 const char **result, 00154 const char **opnd, 00155 FILE *f) 00156 { 00157 INT i; 00158 INT st; 00159 INT comp; 00160 const char *arg[ISA_PRINT_COMP_MAX]; 00161 const ISA_PRINT_INFO *pinfo = ISA_PRINT_Info(topcode); 00162 00163 if (!pinfo) { 00164 sprintf(TI_errmsg, "no ISA_PRINT_INFO for %s", TOP_Name(topcode)); 00165 return TI_RC_ERROR; 00166 } 00167 00168 i = 0; 00169 do { 00170 comp = ISA_PRINT_INFO_Comp(pinfo, i); 00171 00172 switch (comp) { 00173 case ISA_PRINT_COMP_name: 00174 arg[i] = ISA_PRINT_AsmName(topcode); 00175 break; 00176 00177 case ISA_PRINT_COMP_opnd: 00178 case ISA_PRINT_COMP_opnd+1: 00179 case ISA_PRINT_COMP_opnd+2: 00180 case ISA_PRINT_COMP_opnd+3: 00181 case ISA_PRINT_COMP_opnd+4: 00182 case ISA_PRINT_COMP_opnd+5: 00183 arg[i] = opnd[comp - ISA_PRINT_COMP_opnd]; 00184 break; 00185 00186 case ISA_PRINT_COMP_result: 00187 case ISA_PRINT_COMP_result+1: 00188 arg[i] = result[comp - ISA_PRINT_COMP_result]; 00189 break; 00190 00191 case ISA_PRINT_COMP_end: 00192 break; 00193 00194 default: 00195 sprintf(TI_errmsg, "Unhandled listing component %d for %s", 00196 comp, TOP_Name(topcode)); 00197 return TI_RC_ERROR; 00198 /*NOTREACHED*/ 00199 } 00200 } while (++i, comp != ISA_PRINT_COMP_end); 00201 00202 st = fprintf (f, ISA_PRINT_INFO_Format(pinfo), 00203 arg[0], arg[1], arg[2], arg[3], 00204 arg[4], arg[5], arg[6], arg[7], 00205 arg[8]); 00206 if (st == -1) { 00207 sprintf(TI_errmsg, "fprintf failed: not enough disk space"); 00208 return TI_RC_ERROR; 00209 } 00210 else return st; 00211 } 00212 00213 /* ==================================================================== 00214 * 00215 * Format_Operand 00216 * 00217 * Format an operand for disassembly. 00218 * 00219 * ==================================================================== 00220 */ 00221 static INT Format_Operand( 00222 char *buf, 00223 INT64 pc, 00224 const ISA_OPERAND_VALTYP *vtype, 00225 ISA_OPERAND_USE use, 00226 INT64 val, 00227 INT flags) 00228 { 00229 if (ISA_OPERAND_VALTYP_Is_Register(vtype)) { 00230 const char *rname; 00231 const char *fmt = (use == OU_predicate) ? ISA_PRINT_PREDICATE : "%s"; 00232 ISA_REGISTER_CLASS rc = ISA_OPERAND_VALTYP_Register_Class(vtype); 00233 if ( !(flags & TI_ASM_DISASM_TRUE_PRED) 00234 && (use == OU_predicate) 00235 && ABI_PROPERTY_Is_true_predicate(rc, val)) 00236 { 00237 rname = ""; 00238 fmt = "%s"; 00239 } else if (flags & TI_ASM_DISASM_ABI_REGS) { 00240 rname = ABI_PROPERTY_Reg_Name(rc, val); 00241 } else { 00242 const ISA_REGISTER_CLASS_INFO *rcinfo = ISA_REGISTER_CLASS_Info(rc); 00243 rname = ISA_REGISTER_CLASS_INFO_Reg_Name(rcinfo, val); 00244 } 00245 return sprintf(buf, fmt, rname) + 1; 00246 } else if (ISA_OPERAND_VALTYP_Is_Enum(vtype)) { 00247 ISA_ENUM_CLASS_VALUE ecv = (ISA_ENUM_CLASS_VALUE)val; 00248 return sprintf(buf, "%s", ISA_ECV_Name(ecv)) + 1; 00249 } 00250 00251 assert(ISA_OPERAND_VALTYP_Is_Literal(vtype)); 00252 00253 if (ISA_OPERAND_VALTYP_Is_PCRel(vtype)) { 00254 val += pc; 00255 if (PROC_has_branch_delay_slot()) val += sizeof(ISA_BUNDLE); 00256 return sprintf(buf, "0x%llx", val) + 1; 00257 } else if (ISA_OPERAND_VALTYP_Is_Signed(vtype)) { 00258 return sprintf(buf, "%lld", val) + 1; 00259 } else { 00260 return sprintf(buf, "%llu", val) + 1; 00261 } 00262 } 00263 00264 00265 /* ==================================================================== 00266 * 00267 * TI_ASM_DisAsm_Inst 00268 * 00269 * See interface description 00270 * 00271 * ==================================================================== 00272 */ 00273 INT TI_ASM_DisAsm_Inst( 00274 TOP topcode, 00275 INT64 *result, 00276 INT64 *opnd, 00277 INT64 pc, 00278 INT flags, 00279 char *bufptr) 00280 { 00281 INT comp; 00282 const char *arg[ISA_PRINT_COMP_MAX]; 00283 char buf[80]; 00284 int i; 00285 INT cursor; 00286 const ISA_PRINT_INFO *pinfo = ISA_PRINT_Info(topcode); 00287 const ISA_OPERAND_INFO *oinfo = ISA_OPERAND_Info(topcode); 00288 00289 cursor = 0; 00290 i = 0; 00291 do { 00292 comp = ISA_PRINT_INFO_Comp(pinfo, i); 00293 switch (comp) { 00294 case ISA_PRINT_COMP_name: 00295 arg[i] = ISA_PRINT_AsmName(topcode); 00296 break; 00297 00298 case ISA_PRINT_COMP_opnd: 00299 case ISA_PRINT_COMP_opnd+1: 00300 case ISA_PRINT_COMP_opnd+2: 00301 case ISA_PRINT_COMP_opnd+3: 00302 case ISA_PRINT_COMP_opnd+4: 00303 case ISA_PRINT_COMP_opnd+5: 00304 { 00305 INT n = comp - ISA_PRINT_COMP_opnd; 00306 const ISA_OPERAND_VALTYP *vtype = ISA_OPERAND_INFO_Operand(oinfo, n); 00307 ISA_OPERAND_USE use = ISA_OPERAND_INFO_Use(oinfo, n); 00308 arg[i] = buf + cursor; 00309 cursor += Format_Operand(buf + cursor, pc, vtype, use, opnd[n], flags); 00310 } 00311 break; 00312 00313 case ISA_PRINT_COMP_result: 00314 case ISA_PRINT_COMP_result+1: 00315 { 00316 INT n = comp - ISA_PRINT_COMP_result; 00317 const ISA_OPERAND_VALTYP *vtype = ISA_OPERAND_INFO_Result(oinfo, n); 00318 arg[i] = buf + cursor; 00319 cursor += Format_Operand(buf + cursor, 0, vtype, OU_UNDEFINED, 00320 result[n], flags); 00321 } 00322 break; 00323 00324 case ISA_PRINT_COMP_end: 00325 break; 00326 00327 default: 00328 assert(0); 00329 /*NOTREACHED*/ 00330 } 00331 } while (++i, comp != ISA_PRINT_COMP_end); 00332 00333 return sprintf(bufptr, ISA_PRINT_INFO_Format(pinfo), 00334 arg[0], arg[1], arg[2], arg[3], 00335 arg[4], arg[5], arg[6], arg[7], 00336 arg[8]); 00337 } 00338 00339 /* ==================================================================== 00340 * 00341 * TI_ASM_Set_Bundle_Comp 00342 * 00343 * See interface description 00344 * 00345 * ==================================================================== 00346 */ 00347 void TI_ASM_Set_Bundle_Comp( 00348 ISA_BUNDLE *bundle, 00349 ISA_BUNDLE_PACK_COMP comp, 00350 UINT64 val 00351 ) 00352 { 00353 const ISA_BUNDLE_PACK_INFO *pinfo = ISA_BUNDLE_Pack_Info(); 00354 INT i = ISA_BUNDLE_Pack_Info_Index(comp); 00355 for (pinfo = pinfo + i; ISA_BUNDLE_PACK_INFO_Comp(pinfo) == comp; ++pinfo) { 00356 UINT64 mask = ISA_BUNDLE_PACK_INFO_Mask(pinfo); 00357 INT comp_pos = ISA_BUNDLE_PACK_INFO_CompPos(pinfo); 00358 INT bundle_pos = ISA_BUNDLE_PACK_INFO_BundlePos(pinfo); 00359 INT index = ISA_BUNDLE_PACK_INFO_Index(pinfo); 00360 bundle->word[index] = (bundle->word[index] & ~mask) 00361 | (((val >> comp_pos) << bundle_pos) & mask); 00362 } 00363 } 00364 00365 00366 /* ==================================================================== 00367 * 00368 * TI_ASM_Get_Bundle_Comp 00369 * 00370 * See interface description 00371 * 00372 * ==================================================================== 00373 */ 00374 UINT64 TI_ASM_Get_Bundle_Comp( 00375 const ISA_BUNDLE *bundle, 00376 ISA_BUNDLE_PACK_COMP comp 00377 ) 00378 { 00379 UINT64 val = 0; 00380 const ISA_BUNDLE_PACK_INFO *pinfo = ISA_BUNDLE_Pack_Info(); 00381 INT i = ISA_BUNDLE_Pack_Info_Index(comp); 00382 for (pinfo = pinfo + i; ISA_BUNDLE_PACK_INFO_Comp(pinfo) == comp; ++pinfo) { 00383 UINT64 mask = ISA_BUNDLE_PACK_INFO_Mask(pinfo); 00384 INT comp_pos = ISA_BUNDLE_PACK_INFO_CompPos(pinfo); 00385 INT bundle_pos = ISA_BUNDLE_PACK_INFO_BundlePos(pinfo); 00386 INT index = ISA_BUNDLE_PACK_INFO_Index(pinfo); 00387 val |= ((bundle->word[index] & mask) >> bundle_pos) << comp_pos; 00388 } 00389 return val; 00390 } 00391 00392 /* ==================================================================== 00393 * 00394 * TI_ASM_Set_Bundle_Reloc_Value 00395 * 00396 * See interface description 00397 * 00398 * ==================================================================== 00399 */ 00400 void TI_ASM_Set_Bundle_Reloc_Value( 00401 ISA_BUNDLE *bundle, 00402 INT slot, 00403 UINT64 val 00404 ) 00405 { 00406 INT opnd; 00407 INT words; 00408 const ISA_PACK_INFO *pinfo; 00409 INT comp; 00410 INT i; 00411 ISA_PACK_INST inst[ISA_MAX_SLOTS]; 00412 TOP topcode; 00413 INT template_bits = TI_ASM_Get_Bundle_Comp(bundle, 00414 ISA_BUNDLE_PACK_COMP_template); 00415 ISA_EXEC_UNIT ex_unit = ISA_EXEC_Unit(template_bits, slot); 00416 00417 for (i = 0; i < ISA_MAX_SLOTS; ++i) { 00418 ISA_BUNDLE_PACK_COMP slot_comp = 00419 (ISA_BUNDLE_PACK_COMP)(ISA_BUNDLE_PACK_COMP_slot + i); 00420 inst[i] = TI_ASM_Get_Bundle_Comp(bundle, slot_comp); 00421 } 00422 topcode = ISA_Decode_Inst(inst + slot, ex_unit); 00423 00424 /* What should we really do if a bad topcode? 00425 */ 00426 if (topcode == TOP_UNDEFINED) { 00427 fprintf(stderr, "TI_ASM_Set_Bundle_Reloc_Value: couldn't decode instruction\n"); 00428 assert(FALSE); 00429 } 00430 00431 opnd = TOP_Relocatable_Operand(topcode, NULL); 00432 if (opnd < 0) { 00433 fprintf(stderr, "TI_ASM_Set_Bundle_Reloc_Value: %s does not have a relocatable field\n", 00434 TOP_Name(topcode)); 00435 assert(FALSE); 00436 } 00437 00438 words = ISA_PACK_Inst_Words(topcode); 00439 if (words <= 0) { 00440 fprintf(stderr, "TI_ASM_Set_Bundle_Reloc_Value: bad number of inst words (%d) for %s\n", 00441 words, TOP_Name(topcode)); 00442 assert(FALSE); 00443 } 00444 00445 pinfo = ISA_PACK_Info(topcode); 00446 for (;;) { 00447 ISA_BUNDLE_PACK_COMP slot_comp; 00448 do { 00449 comp = ISA_PACK_INFO_Comp(pinfo); 00450 if (comp == ISA_PACK_COMP_opnd + opnd) { 00451 UINT64 mask = ISA_PACK_INFO_Mask(pinfo); 00452 UINT32 opndpos = ISA_PACK_INFO_OpndPos(pinfo); 00453 UINT32 instpos = ISA_PACK_INFO_InstPos(pinfo); 00454 inst[slot] = (inst[slot] & ~(mask << instpos)) 00455 | (((val >> opndpos) & mask) << instpos); 00456 } 00457 } while (++pinfo, comp != ISA_PACK_COMP_end); 00458 00459 slot_comp = (ISA_BUNDLE_PACK_COMP)(ISA_BUNDLE_PACK_COMP_slot + slot); 00460 TI_ASM_Set_Bundle_Comp(bundle, slot_comp, inst[slot]); 00461 00462 if (--words == 0) break; 00463 00464 ++slot; 00465 if (slot >= ISA_MAX_SLOTS) { 00466 fprintf(stderr, "TI_ASM_Set_Bundle_Reloc_Value: can't handle cross bundle reloc for %s\n", 00467 TOP_Name(topcode)); 00468 assert(FALSE); 00469 } 00470 } 00471 } 00472 00473 00474 /* ==================================================================== 00475 * 00476 * TI_ASM_Get_Bundle_Reloc_Value 00477 * 00478 * See interface description 00479 * 00480 * ==================================================================== 00481 */ 00482 UINT64 TI_ASM_Get_Bundle_Reloc_Value( 00483 const ISA_BUNDLE *bundle, 00484 INT slot 00485 ) 00486 { 00487 INT opnd; 00488 const ISA_PACK_INFO *pinfo; 00489 INT comp; 00490 UINT64 val; 00491 INT words; 00492 INT i; 00493 const ISA_OPERAND_INFO *oinfo; 00494 const ISA_OPERAND_VALTYP *vtype; 00495 ISA_PACK_INST inst[ISA_MAX_SLOTS]; 00496 TOP topcode; 00497 INT template_bits = TI_ASM_Get_Bundle_Comp(bundle, 00498 ISA_BUNDLE_PACK_COMP_template); 00499 ISA_EXEC_UNIT ex_unit = ISA_EXEC_Unit(template_bits, slot); 00500 00501 for (i = 0; i < ISA_MAX_SLOTS; ++i) { 00502 ISA_BUNDLE_PACK_COMP slot_comp = 00503 (ISA_BUNDLE_PACK_COMP)(ISA_BUNDLE_PACK_COMP_slot + i); 00504 inst[i] = TI_ASM_Get_Bundle_Comp(bundle, slot_comp); 00505 } 00506 topcode = ISA_Decode_Inst(inst + slot, ex_unit); 00507 00508 /* What should we really do if a bad topcode? 00509 */ 00510 if (topcode == TOP_UNDEFINED) { 00511 fprintf(stderr, "TI_ASM_Get_Bundle_Reloc_Value: couldn't decode instruction\n"); 00512 assert(FALSE); 00513 } 00514 00515 opnd = TOP_Relocatable_Operand(topcode, NULL); 00516 if (opnd < 0) { 00517 fprintf(stderr, "TI_ASM_Get_Bundle_Reloc_Value: %s does not have a relocatable field\n", 00518 TOP_Name(topcode)); 00519 assert(FALSE); 00520 } 00521 00522 words = ISA_PACK_Inst_Words(topcode); 00523 if (words <= 0) { 00524 fprintf(stderr, "TI_ASM_Get_Bundle_Reloc_Value: bad number of inst words (%d) for %s\n", 00525 words, TOP_Name(topcode)); 00526 assert(FALSE); 00527 } 00528 00529 pinfo = ISA_PACK_Info(topcode); 00530 val = 0; 00531 for (;;) { 00532 do { 00533 comp = ISA_PACK_INFO_Comp(pinfo); 00534 if (comp == ISA_PACK_COMP_opnd + opnd) { 00535 UINT64 mask = ISA_PACK_INFO_Mask(pinfo); 00536 UINT32 opndpos = ISA_PACK_INFO_OpndPos(pinfo); 00537 UINT32 instpos = ISA_PACK_INFO_InstPos(pinfo); 00538 val |= ((inst[slot] >> instpos) & mask) << opndpos; 00539 } 00540 } while (++pinfo, comp != ISA_PACK_COMP_end); 00541 00542 if (--words == 0) break; 00543 00544 ++slot; 00545 if (slot >= ISA_MAX_SLOTS) { 00546 fprintf(stderr, "TI_ASM_Get_Bundle_Reloc_Value: can't handle cross bundle reloc for %s\n", 00547 TOP_Name(topcode)); 00548 assert(FALSE); 00549 } 00550 } 00551 00552 oinfo = ISA_OPERAND_Info(topcode); 00553 vtype = ISA_OPERAND_INFO_Operand(oinfo, opnd); 00554 if (ISA_OPERAND_VALTYP_Is_Signed(vtype)) { 00555 INT size = ISA_OPERAND_VALTYP_Size(vtype); 00556 INT shift = 64 - size; 00557 val = ((INT64)val << shift) >> shift; 00558 } 00559 00560 return val; 00561 } 00562 00563 /* ==================================================================== 00564 * 00565 * TI_ASM_Unpack_Inst 00566 * 00567 * See interface description 00568 * 00569 * ==================================================================== 00570 */ 00571 TOP TI_ASM_Unpack_Inst( 00572 const ISA_PACK_INST *pinst, 00573 ISA_EXEC_UNIT ex_unit, 00574 INT64 *result, 00575 INT64 *opnd, 00576 BOOL xlate_pseudo) 00577 { 00578 INT comp; 00579 INT i; 00580 INT j; 00581 INT words; 00582 const ISA_PACK_INFO *pinfo; 00583 const ISA_PACK_ADJ_INFO *ainfo; 00584 const ISA_OPERAND_INFO *oinfo; 00585 TOP topcode; 00586 00587 /* Decode the instruction opcode. 00588 */ 00589 topcode = ISA_Decode_Inst(pinst, ex_unit); 00590 if (topcode == TOP_UNDEFINED) return topcode; 00591 00592 /* Unpack the raw operands and results. 00593 */ 00594 bzero(result, sizeof(*result) * ISA_OPERAND_max_results); 00595 bzero(opnd, sizeof(*opnd) * ISA_OPERAND_max_operands); 00596 pinfo = ISA_PACK_Info(topcode); 00597 words = ISA_PACK_Inst_Words(topcode); 00598 for (j = 0; j < words; ++j) { 00599 ISA_PACK_INST inst = pinst[j]; 00600 do { 00601 UINT64 mask = ISA_PACK_INFO_Mask(pinfo); 00602 UINT32 opndpos = ISA_PACK_INFO_OpndPos(pinfo); 00603 UINT32 instpos = ISA_PACK_INFO_InstPos(pinfo); 00604 INT64 val = ((inst >> instpos) & mask) << opndpos; 00605 00606 comp = ISA_PACK_INFO_Comp(pinfo); 00607 switch (comp) { 00608 case ISA_PACK_COMP_opnd: 00609 case ISA_PACK_COMP_opnd+1: 00610 case ISA_PACK_COMP_opnd+2: 00611 case ISA_PACK_COMP_opnd+3: 00612 case ISA_PACK_COMP_opnd+4: 00613 case ISA_PACK_COMP_opnd+5: 00614 { 00615 INT n = comp - ISA_PACK_COMP_opnd; 00616 opnd[n] |= val; 00617 } 00618 break; 00619 00620 case ISA_PACK_COMP_result: 00621 case ISA_PACK_COMP_result+1: 00622 { 00623 INT n = comp - ISA_PACK_COMP_result; 00624 result[n] |= val; 00625 } 00626 break; 00627 00628 case ISA_PACK_COMP_end: 00629 break; 00630 00631 default: 00632 assert(0); 00633 /*NOTREACHED*/ 00634 } 00635 } while (++pinfo, comp != ISA_PACK_COMP_end); 00636 } 00637 00638 /* Provide any adjustments for the operands between packed and assembly 00639 * language forms. 00640 */ 00641 ainfo = ISA_PACK_Adj_Info(topcode); 00642 if (ainfo) ISA_PACK_Adjust_Operands(ainfo, opnd, TRUE); 00643 00644 /* If desired, translated pseudo instructions. 00645 */ 00646 if (xlate_pseudo) { 00647 topcode = ISA_PSEUDO_Translate(topcode, result, opnd, ISA_PSEUDO_to_pseudo); 00648 } 00649 00650 /* Provide any normalization to any operands: convert enums to their 00651 * 'biased' form and sign-extend signed literals. 00652 */ 00653 oinfo = ISA_OPERAND_Info(topcode); 00654 for (i = 0; i < ISA_OPERAND_INFO_Operands(oinfo); ++i) { 00655 const ISA_OPERAND_VALTYP *vtype = ISA_OPERAND_INFO_Operand(oinfo, i); 00656 UINT64 val = opnd[i]; 00657 00658 if (ISA_OPERAND_VALTYP_Is_Enum(vtype)) { 00659 ISA_ENUM_CLASS_VALUE e; 00660 ISA_ENUM_CLASS_VALUE ecv = ECV_UNDEFINED; 00661 ISA_ENUM_CLASS ec = ISA_OPERAND_VALTYP_Enum_Class(vtype); 00662 00663 for (e = ISA_EC_First_Value(ec); 00664 e <= ISA_EC_Last_Value(ec); 00665 e = (ISA_ENUM_CLASS_VALUE)(e + 1)) 00666 { 00667 if (ISA_ECV_Intval(e) == val) { 00668 ecv = e; 00669 break; 00670 } 00671 } 00672 opnd[i] = ecv; 00673 } else if (ISA_OPERAND_VALTYP_Is_Signed(vtype)) { 00674 INT size = ISA_OPERAND_VALTYP_Size(vtype); 00675 INT shift = 64 - size; 00676 opnd[i] = ((INT64)val << shift) >> shift; 00677 } 00678 } 00679 00680 return topcode; 00681 }