+
+
+/* Given a machine instruction, return its format. */
+
+static inline unsigned ATTRIBUTE_UNUSED
+bfd_hppa_insn2fmt (bfd *abfd, unsigned insn)
+{
+ enum hppa_opcode_type op = (enum hppa_opcode_type) get_opcode (insn);
+
+ switch (op)
+ {
+ case OP_COMICLR:
+ case OP_SUBI:
+ case OP_ADDIT:
+ case OP_ADDI:
+ return 11;
+
+ case OP_COMBT:
+ case OP_COMIBT:
+ case OP_COMBF:
+ case OP_COMIBF:
+ case OP_CMPBDT:
+ case OP_ADDBT:
+ case OP_ADDIBT:
+ case OP_ADDBF:
+ case OP_ADDIBF:
+ case OP_CMPBDF:
+ case OP_BVB:
+ case OP_BB:
+ case OP_MOVB:
+ case OP_MOVIB:
+ case OP_CMPIBD:
+ return 12;
+
+ case OP_LDO:
+ case OP_LDB:
+ case OP_LDH:
+ case OP_LDW:
+ case OP_LDWM:
+ case OP_STB:
+ case OP_STH:
+ case OP_STW:
+ case OP_STWM:
+ if (abfd->arch_info->mach >= 25)
+ return 16; /* Wide mode, format 16. */
+ return 14;
+
+ case OP_FLDW:
+ case OP_LDWL:
+ case OP_FSTW:
+ case OP_STWL:
+ /* This is a hack. Unfortunately, format 11 is already taken
+ and we're using integers rather than an enum, so it's hard
+ to describe the 11a format. */
+ if (abfd->arch_info->mach >= 25)
+ return -16; /* Wide mode, format 16a. */
+ return -11;
+
+ case OP_LDD:
+ case OP_STD:
+ if (abfd->arch_info->mach >= 25)
+ return -10; /* Wide mode, format 10a. */
+ return 10;
+
+ case OP_BL:
+ if ((insn & 0x8000) != 0)
+ return 22;
+ /* fall thru */
+ case OP_BE:
+ case OP_BLE:
+ return 17;
+
+ case OP_LDIL:
+ case OP_ADDIL:
+ return 21;
+
+ default:
+ break;
+ }
+ return 32;
+}
+
+
+/* Insert VALUE into INSN using R_FORMAT to determine exactly what
+ bits to change. */
+
+static inline unsigned ATTRIBUTE_UNUSED
+hppa_rebuild_insn (unsigned insn, unsigned value, int r_format)
+{
+ switch (r_format)
+ {
+ case 11:
+ return (insn & ~ 0x7ff) | low_sign_unext (value, 11);
+
+ case 12:
+ return (insn & ~ 0x1ffd) | re_assemble_12 (value);
+
+
+ case 10:
+ return (insn & ~ 0x3ff1) | re_assemble_14 (value & -8);
+
+ case -11:
+ return (insn & ~ 0x3ff9) | re_assemble_14 (value & -4);
+
+ case 14:
+ return (insn & ~ 0x3fff) | re_assemble_14 (value);
+
+
+ case -10:
+ return (insn & ~ 0xfff1) | re_assemble_16 (value & -8);
+
+ case -16:
+ return (insn & ~ 0xfff9) | re_assemble_16 (value & -4);
+
+ case 16:
+ return (insn & ~ 0xffff) | re_assemble_16 (value);
+
+
+ case 17:
+ return (insn & ~ 0x1f1ffd) | re_assemble_17 (value);
+
+ case 21:
+ return (insn & ~ 0x1fffff) | re_assemble_21 (value);
+
+ case 22:
+ return (insn & ~ 0x3ff1ffd) | re_assemble_22 (value);
+
+ case 32:
+ return value;
+
+ default:
+ abort ();
+ }
+ return insn;
+}
+
+#endif /* _LIBHPPA_H */