return 0;
}
-/* immediate operand */
+/* Immediate operand.
+ If EXP_O is non-null, then a symbolic expression is permitted,
+ in which case, EXP_O will be populated with the parsed expression.
+ */
static int
-lex_imm (long *v)
+lex_imm (long *v, expressionS *exp_o)
{
char *ilp = input_line_pointer;
goto fail;
if (exp.X_op != O_constant)
- goto fail;
+ {
+ if (!exp_o)
+ as_bad (_("A non-constant expression is not permitted here"));
+ else
+ *exp_o = exp;
+ }
*v = exp.X_add_number;
return 1;
lex_imm_e4 (long *val)
{
char *ilp = input_line_pointer;
- if ((lex_imm (val)))
+ if ((lex_imm (val, NULL)))
{
if ((*val == -1) || (*val > 0 && *val <= 15))
{
return 1;
}
-/* Emit the code for an OPR address mode operand */
-static char *
-emit_opr (char *f, const uint8_t *buffer, int n_bytes, expressionS *exp)
+
+static void
+emit_reloc (expressionS *exp, char *f, int size, enum bfd_reloc_code_real reloc)
{
- int i;
- number_to_chars_bigendian (f++, buffer[0], 1);
if (exp->X_op != O_absent && exp->X_op != O_constant)
{
fixS *fix = fix_new_exp (frag_now,
f - frag_now->fr_literal,
- 3,
+ size,
exp,
FALSE,
- BFD_RELOC_S12Z_OPR);
+ reloc);
/* Some third party tools seem to use the lower bits
- of this addend for flags. They don't get added
- to the final location. The purpose of these flags
- is not known. We simply set it to zero. */
+ of this addend for flags. They don't get added
+ to the final location. The purpose of these flags
+ is not known. We simply set it to zero. */
fix->fx_addnumber = 0x00;
}
+}
+
+/* Emit the code for an OPR address mode operand */
+static char *
+emit_opr (char *f, const uint8_t *buffer, int n_bytes, expressionS *exp)
+{
+ int i;
+ number_to_chars_bigendian (f++, buffer[0], 1);
+
+ emit_reloc (exp, f, 3, BFD_RELOC_S12Z_OPR);
+
for (i = 1; i < n_bytes; ++i)
number_to_chars_bigendian (f++, buffer[i], 1);
goto fail;
long imm;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
imm8 (const struct instruction *insn)
{
long imm;
- if (! lex_imm (&imm))
+ if (! lex_imm (&imm, NULL))
return 0;
if (imm > 127 || imm < -128)
{
if (!lex_force_match (','))
goto fail;
long imm;
- if (! lex_imm (&imm))
+ if (! lex_imm (&imm, NULL))
goto fail;
short size = registers[reg].bytes;
trap_imm (const struct instruction *insn ATTRIBUTE_UNUSED)
{
long imm = -1;
- if (! lex_imm (&imm))
+ if (! lex_imm (&imm, NULL))
goto fail;
if (imm < 0x92 || imm > 0xFF ||
{
char *ilp = input_line_pointer;
long imm;
- if (!lex_imm (&imm))
+ expressionS exp0;
+ int size = size_from_suffix (insn, 0);
+ exp0.X_op = O_absent;
+
+ /* Note: The ternary expression below means that "MOV.x #symbol,
+ mem-expr" is accepted when x is a member of {'w', 'p', 'l'} but
+ not when it is 'b'.
+ The Freescale assembler accepts "MOV.b #symbol, mem-expr" but
+ produces obviously incorrect code. Since such an instruction
+ would require an 8-bit reloc (which we don't have) and some
+ non-optimal kludges in the OPR encoding, it seems sensible that
+ such instructions should be rejected. */
+ if (!lex_imm (&imm, size > 1 ? &exp0 : NULL))
goto fail;
if (!lex_match (','))
uint8_t buffer[4];
int n_bytes;
- expressionS exp;
- if (!lex_opr (buffer, &n_bytes, &exp, false))
+ expressionS exp1;
+ if (!lex_opr (buffer, &n_bytes, &exp1, false))
goto fail;
- int size = size_from_suffix (insn, 0);
char *f = s12z_new_insn (1 + n_bytes + size);
number_to_chars_bigendian (f++, insn->opc, 1);
+ emit_reloc (&exp0, f, size, size == 4 ? BFD_RELOC_32 : BFD_RELOC_S12Z_OPR);
+
int i;
for (i = 0; i < size; ++i)
number_to_chars_bigendian (f++, imm >> (CHAR_BIT * (size - i - 1)), 1);
- emit_opr (f, buffer, n_bytes, &exp);
+ emit_opr (f, buffer, n_bytes, &exp1);
return 1;
goto fail;
long imm = -1;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
if (imm != 1 && imm != 2)
return 1;
}
- else if (lex_imm (&imm))
+ else if (lex_imm (&imm, NULL))
{
if (imm < 0 || imm > 31)
{
goto fail;
long imm = -1;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
if (imm != 1 && imm != 2)
expressionS exp2;
long imm;
bool immediate = false;
- if (lex_imm (&imm))
+ if (lex_imm (&imm, NULL))
{
immediate = true;
}
goto fail;
long imm;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
long imm;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
int size = size_from_suffix (insn, 0);
goto fail;
long width;
- if (!lex_imm (&width))
+ if (!lex_imm (&width, NULL))
goto fail;
if (width < 0 || width > 31)
goto fail;
long width;
- if (!lex_imm (&width))
+ if (!lex_imm (&width, NULL))
goto fail;
if (width < 0 || width > 31)
goto fail;
long width;
- if (!lex_imm (&width))
+ if (!lex_imm (&width, NULL))
goto fail;
if (width < 0 || width > 31)
goto fail;
long imm;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
if (imm < 0 || imm > 31)
goto fail;
long imm;
- if (!lex_imm (&imm))
+ if (!lex_imm (&imm, NULL))
goto fail;
if (imm < 0 || imm > 31)
bfd_putb16 ((bfd_vma) value, (unsigned char *) where);
break;
case BFD_RELOC_24:
- case BFD_RELOC_S12Z_OPR:
bfd_putb24 ((bfd_vma) value, (unsigned char *) where);
break;
+ case BFD_RELOC_S12Z_OPR:
+ {
+ switch (fixP->fx_size)
+ {
+ case 3:
+ bfd_putb24 ((bfd_vma) value, (unsigned char *) where);
+ break;
+ case 2:
+ bfd_putb16 ((bfd_vma) value, (unsigned char *) where);
+ break;
+ default:
+ abort ();
+ }
+ }
+ break;
case BFD_RELOC_32:
bfd_putb32 ((bfd_vma) value, (unsigned char *) where);
break;