- /* Here to make main operand frag(s). */
- this_add_number = expP->X_add_number;
- this_add_symbol = expP->X_add_symbol;
- to_seg = *segP;
- is_undefined = (to_seg == SEG_UNKNOWN);
- at = operandP->vop_mode & 1;
- length = (operandP->vop_short == 'b'
- ? 1 : (operandP->vop_short == 'w'
- ? 2 : (operandP->vop_short == 'l'
- ? 4 : 0)));
- nbytes = operandP->vop_nbytes;
- if (operandP->vop_access == 'b')
- {
- if (to_seg == now_seg || is_undefined)
- {
- /* If is_undefined, then it might BECOME now_seg. */
- if (nbytes)
- {
- p = frag_more (nbytes);
- fix_new (frag_now, p - frag_now->fr_literal, nbytes,
- this_add_symbol, this_add_number, 1, NO_RELOC);
- }
- else
- { /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
- /* nbytes==0 */
- length_code = is_undefined ? STATE_UNDF : STATE_BYTE;
- if (opcode_as_number & VIT_OPCODE_SPECIAL)
- {
- if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
- {
- /* br or jsb */
- frag_var (rs_machine_dependent, 5, 1,
- ENCODE_RELAX (STATE_ALWAYS_BRANCH, length_code),
- this_add_symbol, this_add_number,
- opcode_low_byteP);
- }
- else
- {
- if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
- {
- length_code = STATE_WORD;
- /* JF: There is no state_byte for this one! */
- frag_var (rs_machine_dependent, 10, 2,
- ENCODE_RELAX (STATE_COMPLEX_BRANCH, length_code),
- this_add_symbol, this_add_number,
- opcode_low_byteP);
- }
- else
- {
- know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
- frag_var (rs_machine_dependent, 9, 1,
- ENCODE_RELAX (STATE_COMPLEX_HOP, length_code),
- this_add_symbol, this_add_number,
- opcode_low_byteP);
- }
- }
- }
- else
- {
- know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
- frag_var (rs_machine_dependent, 7, 1,
- ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, length_code),
- this_add_symbol, this_add_number,
- opcode_low_byteP);
- }
- }
- }
- else
- {
- /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
- /*
- * --- SEG FLOAT MAY APPEAR HERE ----
- */
- if (to_seg == SEG_ABSOLUTE)
- {
- if (nbytes)
- {
- know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
- p = frag_more (nbytes);
- /* Conventional relocation. */
- fix_new (frag_now, p - frag_now->fr_literal,
- nbytes, &abs_symbol, this_add_number,
- 1, NO_RELOC);
- }
- else
- {
- know (opcode_as_number & VIT_OPCODE_SYNTHETIC);
- if (opcode_as_number & VIT_OPCODE_SPECIAL)
- {
- if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
- {
- /* br or jsb */
- *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
- know (opcode_as_chars[1] == 0);
- p = frag_more (5);
- p[0] = VAX_ABSOLUTE_MODE; /* @#... */
- md_number_to_chars (p + 1, this_add_number, 4);
- /* Now (eg) JMP @#foo or JSB @#foo. */
- }
- else
- {
- if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
- {
- p = frag_more (10);
- p[0] = 2;
- p[1] = 0;
- p[2] = VAX_BRB;
- p[3] = 6;
- p[4] = VAX_JMP;
- p[5] = VAX_ABSOLUTE_MODE; /* @#... */
- md_number_to_chars (p + 6, this_add_number, 4);
- /*
- * Now (eg) ACBx 1f
- * BRB 2f
- * 1: JMP @#foo
- * 2:
- */
- }
- else
- {
- know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
- p = frag_more (9);
- p[0] = 2;
- p[1] = VAX_BRB;
- p[2] = 6;
- p[3] = VAX_JMP;
- p[4] = VAX_PC_RELATIVE_MODE + 1; /* @#... */
- md_number_to_chars (p + 5, this_add_number, 4);
- /*
- * Now (eg) xOBxxx 1f
- * BRB 2f
- * 1: JMP @#foo
- * 2:
- */
- }
- }
- }
- else
- {
- /* b<cond> */
- *opcode_low_byteP ^= 1;
- /* To reverse the condition in a VAX branch,
- complement the lowest order bit. */
- p = frag_more (7);
- p[0] = 6;
- p[1] = VAX_JMP;
- p[2] = VAX_ABSOLUTE_MODE; /* @#... */
- md_number_to_chars (p + 3, this_add_number, 4);
- /*
- * Now (eg) BLEQ 1f
- * JMP @#foo
- * 1:
- */
- }
- }
- }
- else
- {
- /* to_seg != now_seg && to_seg != SEG_UNKNOWN && to_Seg != SEG_ABSOLUTE */
- if (nbytes > 0)
- {
- /* Pc-relative. Conventional relocation. */
- know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
- p = frag_more (nbytes);
- fix_new (frag_now, p - frag_now->fr_literal,
- nbytes, &abs_symbol, this_add_number,
- 1, NO_RELOC);
- }
- else
- {
- know (opcode_as_number & VIT_OPCODE_SYNTHETIC);
- if (opcode_as_number & VIT_OPCODE_SPECIAL)
- {
- if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
- {
- /* br or jsb */
- know (opcode_as_chars[1] == 0);
- *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
- p = frag_more (5);
- p[0] = VAX_PC_RELATIVE_MODE;
- fix_new (frag_now,
- p + 1 - frag_now->fr_literal, 4,
- this_add_symbol,
- this_add_number, 1, NO_RELOC);
- /* Now eg JMP foo or JSB foo. */
- }
- else
- {
- if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
- {
- p = frag_more (10);
- p[0] = 0;
- p[1] = 2;
- p[2] = VAX_BRB;
- p[3] = 6;
- p[4] = VAX_JMP;
- p[5] = VAX_PC_RELATIVE_MODE;
- fix_new (frag_now,
- p + 6 - frag_now->fr_literal, 4,
- this_add_symbol,
- this_add_number, 1, NO_RELOC);
- /*
- * Now (eg) ACBx 1f
- * BRB 2f
- * 1: JMP foo
- * 2:
- */
- }
- else
- {
- know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
- p = frag_more (10);
- p[0] = 2;
- p[1] = VAX_BRB;
- p[2] = 6;
- p[3] = VAX_JMP;
- p[4] = VAX_PC_RELATIVE_MODE;
- fix_new (frag_now,
- p + 5 - frag_now->fr_literal,
- 4, this_add_symbol,
- this_add_number, 1, NO_RELOC);
- /*
- * Now (eg) xOBxxx 1f
- * BRB 2f
- * 1: JMP foo
- * 2:
- */
- }
- }
- }
- else
- {
- know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
- *opcode_low_byteP ^= 1; /* Reverse branch condition. */
- p = frag_more (7);
- p[0] = 6;
- p[1] = VAX_JMP;
- p[2] = VAX_PC_RELATIVE_MODE;
- fix_new (frag_now, p + 3 - frag_now->fr_literal,
- 4, this_add_symbol,
- this_add_number, 1, NO_RELOC);
- }
- }
- }
- }
- }
- else
- {
- know (operandP->vop_access != 'b'); /* So it is ordinary operand. */
- know (operandP->vop_access != ' '); /* ' ' target-independent: elsewhere. */
- know (operandP->vop_access == 'a'
- || operandP->vop_access == 'm'
- || operandP->vop_access == 'r'
- || operandP->vop_access == 'v'
- || operandP->vop_access == 'w');
- if (operandP->vop_short == 's')
- {
- if (to_seg == SEG_ABSOLUTE)
- {
- if (this_add_number >= 64)
- {
- as_warn (_("Short literal overflow(%ld.), immediate mode assumed."),
- (long) this_add_number);
- operandP->vop_short = 'i';
- operandP->vop_mode = 8;
- operandP->vop_reg = 0xF;
- }
- }
- else
- {
- as_warn (_("Forced short literal to immediate mode. now_seg=%s to_seg=%s"),
- segment_name (now_seg), segment_name (to_seg));
- operandP->vop_short = 'i';
- operandP->vop_mode = 8;
- operandP->vop_reg = 0xF;
- }
- }
- if (operandP->vop_reg >= 0 && (operandP->vop_mode < 8
- || (operandP->vop_reg != 0xF && operandP->vop_mode < 10)))
- {
- /* One byte operand. */
- know (operandP->vop_mode > 3);
- FRAG_APPEND_1_CHAR (operandP->vop_mode << 4 | operandP->vop_reg);
- /* All 1-bytes except S^# happen here. */
- }
- else
- {
- /* {@}{q^}foo{(Rn)} or S^#foo */
- if (operandP->vop_reg == -1 && operandP->vop_short != 's')
- {
- /* "{@}{q^}foo" */
- if (to_seg == now_seg)
- {
- if (length == 0)
- {
- know (operandP->vop_short == ' ');
- p = frag_var (rs_machine_dependent, 10, 2,
- ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE),
- this_add_symbol, this_add_number,
- opcode_low_byteP);
- know (operandP->vop_mode == 10 + at);
- *p = at << 4;
- /* At is the only context we need to carry
- to other side of relax() process. Must
- be in the correct bit position of VAX
- operand spec. byte. */
- }
- else
- {
- know (length);
- know (operandP->vop_short != ' ');
- p = frag_more (length + 1);
- p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
- fix_new (frag_now, p + 1 - frag_now->fr_literal,
- length, this_add_symbol,
- this_add_number, 1, NO_RELOC);
- }
- }
- else
- { /* to_seg != now_seg */
- if (this_add_symbol == NULL)
- {
- know (to_seg == SEG_ABSOLUTE);
- /* Do @#foo: simpler relocation than foo-.(pc) anyway. */
- p = frag_more (5);
- p[0] = VAX_ABSOLUTE_MODE; /* @#... */
- md_number_to_chars (p + 1, this_add_number, 4);
- if (length && length != 4)
- {
- as_warn (_("Length specification ignored. Address mode 9F used"));
- }
- }
- else
- {
- /* {@}{q^}other_seg */
- know ((length == 0 && operandP->vop_short == ' ')
- || (length > 0 && operandP->vop_short != ' '));
- if (is_undefined)
- {
- /*
- * We have a SEG_UNKNOWN symbol. It might
- * turn out to be in the same segment as
- * the instruction, permitting relaxation.
- */
- p = frag_var (rs_machine_dependent, 5, 2,
- ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF),
- this_add_symbol, this_add_number,
- 0);
- p[0] = at << 4;
- }
- else
- {
- if (length == 0)
- {
- know (operandP->vop_short == ' ');
- length = 4; /* Longest possible. */
- }
- p = frag_more (length + 1);
- p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
- md_number_to_chars (p + 1, this_add_number, length);
- fix_new (frag_now,
- p + 1 - frag_now->fr_literal,
- length, this_add_symbol,
- this_add_number, 1, NO_RELOC);
- }
- }
- }
- }
- else
- {
- /* {@}{q^}foo(Rn) or S^# or I^# or # */
- if (operandP->vop_mode < 0xA)
- {
- /* # or S^# or I^# */
- if (operandP->vop_access == 'v'
- || operandP->vop_access == 'a')
- {
- if (operandP->vop_access == 'v')
- as_warn (_("Invalid operand: immediate value used as base address."));
- else
- as_warn (_("Invalid operand: immediate value used as address."));
- /* gcc 2.6.3 is known to generate these in at least
- one case. */
- }
- if (length == 0
- && to_seg == SEG_ABSOLUTE && (expP->X_op != O_big)
- && operandP->vop_mode == 8 /* No '@'. */
- && this_add_number < 64)
- {
- operandP->vop_short = 's';
- }
- if (operandP->vop_short == 's')
- {
- FRAG_APPEND_1_CHAR (this_add_number);
- }
- else
- {
- /* I^#... */
- know (nbytes);
- p = frag_more (nbytes + 1);
- know (operandP->vop_reg == 0xF);
- p[0] = (operandP->vop_mode << 4) | 0xF;
- if ((to_seg == SEG_ABSOLUTE) && (expP->X_op != O_big))
- {
- /*
- * If nbytes > 4, then we are scrod. We
- * don't know if the high order bytes
- * are to be 0xFF or 0x00. BSD4.2 & RMS
- * say use 0x00. OK --- but this
- * assembler needs ANOTHER rewrite to
- * cope properly with this bug. */
- md_number_to_chars (p + 1, this_add_number, min (4, nbytes));
- if (nbytes > 4)
- {
- memset (p + 5, '\0', nbytes - 4);
- }
- }
- else
- {
- if (expP->X_op == O_big)
- {
- /*
- * Problem here is to get the bytes
- * in the right order. We stored
- * our constant as LITTLENUMs, not
- * bytes. */
- LITTLENUM_TYPE *lP;