binutils-gdb/gas/config/tc-moxie.c

850 lines
18 KiB
C
Raw Permalink Normal View History

2009-04-16 17:39:48 +02:00
/* tc-moxie.c -- Assemble code for moxie
Copyright (C) 2009-2020 Free Software Foundation, Inc.
2009-04-16 17:39:48 +02:00
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to
the Free Software Foundation, 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1301, USA. */
/* Contributed by Anthony Green <green@moxielogic.com>. */
#include "as.h"
#include "safe-ctype.h"
#include "opcode/moxie.h"
#include "elf/moxie.h"
extern const moxie_opc_info_t moxie_opc_info[128];
const char comment_chars[] = "#";
const char line_separator_chars[] = ";";
const char line_comment_chars[] = "#";
static int pending_reloc;
static struct hash_control *opcode_hash_control;
const pseudo_typeS md_pseudo_table[] =
{
{0, 0, 0}
};
const char FLT_CHARS[] = "rRsSfFdDxXpP";
const char EXP_CHARS[] = "eE";
2012-09-14 00:24:51 +02:00
static valueT md_chars_to_number (char * buf, int n);
/* Byte order. */
extern int target_big_endian;
2009-04-16 17:39:48 +02:00
void
md_operand (expressionS *op __attribute__((unused)))
{
/* Empty for now. */
}
/* This function is called once, at assembler startup time. It sets
up the hash table with all the opcodes in it, and also initializes
some aliases for compatibility with other assemblers. */
void
md_begin (void)
{
int count;
const moxie_opc_info_t *opcode;
opcode_hash_control = hash_new ();
/* Insert names into hash table. */
for (count = 0, opcode = moxie_form1_opc_info; count++ < 64; opcode++)
hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
for (count = 0, opcode = moxie_form2_opc_info; count++ < 4; opcode++)
hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
for (count = 0, opcode = moxie_form3_opc_info; count++ < 10; opcode++)
2009-04-16 17:39:48 +02:00
hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0);
}
/* Parse an expression and then restore the input line pointer. */
static char *
parse_exp_save_ilp (char *s, expressionS *op)
{
char *save = input_line_pointer;
input_line_pointer = s;
expression (op);
s = input_line_pointer;
input_line_pointer = save;
return s;
}
static int
parse_register_operand (char **ptr)
{
int reg;
char *s = *ptr;
if (*s != '$')
{
as_bad (_("expecting register"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return -1;
}
if (s[1] == 'f' && s[2] == 'p')
{
*ptr += 3;
return 0;
}
if (s[1] == 's' && s[2] == 'p')
{
*ptr += 3;
return 1;
}
if (s[1] == 'r')
{
reg = s[2] - '0';
if ((reg < 0) || (reg > 9))
{
as_bad (_("illegal register number"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return -1;
}
if (reg == 1)
{
int r2 = s[3] - '0';
if ((r2 >= 0) && (r2 <= 3))
{
reg = 10 + r2;
*ptr += 1;
}
}
}
else
{
as_bad (_("illegal register number"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return -1;
}
*ptr += 3;
return reg + 2;
}
/* This is the guts of the machine-dependent assembler. STR points to
a machine dependent instruction. This function is supposed to emit
the frags/bytes it assembles to. */
void
md_assemble (char *str)
{
char *op_start;
char *op_end;
moxie_opc_info_t *opcode;
char *p;
char pend;
unsigned short iword = 0;
int nlen = 0;
/* Drop leading whitespace. */
while (*str == ' ')
str++;
/* Find the op code end. */
op_start = str;
for (op_end = str;
*op_end && !is_end_of_line[*op_end & 0xff] && *op_end != ' ';
op_end++)
nlen++;
pend = *op_end;
*op_end = 0;
if (nlen == 0)
as_bad (_("can't find opcode "));
opcode = (moxie_opc_info_t *) hash_find (opcode_hash_control, op_start);
*op_end = pend;
if (opcode == NULL)
{
as_bad (_("unknown opcode %s"), op_start);
return;
}
p = frag_more (2);
switch (opcode->itype)
{
case MOXIE_F2_A8V:
iword = (1<<15) | (opcode->opcode << 12);
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
int reg;
reg = parse_register_operand (&op_end);
iword += (reg << 8);
if (*op_end != ',')
as_warn (_("expecting comma delimited register operands"));
2009-04-16 17:39:48 +02:00
op_end++;
op_end = parse_exp_save_ilp (op_end, &arg);
fix_new_exp (frag_now,
2012-09-14 00:24:51 +02:00
((p + (target_big_endian ? 1 : 0)) - frag_now->fr_literal),
2009-04-16 17:39:48 +02:00
1,
&arg,
0,
BFD_RELOC_8);
}
break;
case MOXIE_F1_AB:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
int dest, src;
dest = parse_register_operand (&op_end);
if (*op_end != ',')
as_warn (_("expecting comma delimited register operands"));
2009-04-16 17:39:48 +02:00
op_end++;
src = parse_register_operand (&op_end);
iword += (dest << 4) + src;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
}
break;
case MOXIE_F1_A4:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
char *where;
int regnum;
regnum = parse_register_operand (&op_end);
while (ISSPACE (*op_end))
op_end++;
iword += (regnum << 4);
if (*op_end != ',')
{
as_bad (_("expecting comma delimited operands"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
op_end = parse_exp_save_ilp (op_end, &arg);
where = frag_more (4);
fix_new_exp (frag_now,
(where - frag_now->fr_literal),
4,
&arg,
0,
BFD_RELOC_32);
}
break;
2009-06-10 08:07:47 +02:00
case MOXIE_F1_M:
2009-04-16 17:39:48 +02:00
case MOXIE_F1_4:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
char *where;
op_end = parse_exp_save_ilp (op_end, &arg);
where = frag_more (4);
fix_new_exp (frag_now,
(where - frag_now->fr_literal),
4,
&arg,
0,
BFD_RELOC_32);
}
break;
case MOXIE_F1_NARG:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
break;
case MOXIE_F1_A:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
int reg;
reg = parse_register_operand (&op_end);
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
iword += (reg << 4);
}
break;
case MOXIE_F1_ABi:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
int a, b;
a = parse_register_operand (&op_end);
if (*op_end != ',')
as_warn (_("expecting comma delimited register operands"));
2009-04-16 17:39:48 +02:00
op_end++;
if (*op_end != '(')
{
as_bad (_("expecting indirect register `($rA)'"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
b = parse_register_operand (&op_end);
if (*op_end != ')')
{
as_bad (_("missing closing parenthesis"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
iword += (a << 4) + b;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
}
break;
case MOXIE_F1_AiB:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
int a, b;
if (*op_end != '(')
{
as_bad (_("expecting indirect register `($rA)'"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
a = parse_register_operand (&op_end);
if (*op_end != ')')
{
as_bad (_("missing closing parenthesis"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
if (*op_end != ',')
as_warn (_("expecting comma delimited register operands"));
2009-04-16 17:39:48 +02:00
op_end++;
b = parse_register_operand (&op_end);
iword += (a << 4) + b;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
}
break;
case MOXIE_F1_4A:
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
char *where;
int a;
op_end = parse_exp_save_ilp (op_end, &arg);
where = frag_more (4);
fix_new_exp (frag_now,
(where - frag_now->fr_literal),
4,
&arg,
0,
BFD_RELOC_32);
if (*op_end != ',')
{
as_bad (_("expecting comma delimited operands"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
a = parse_register_operand (&op_end);
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
iword += (a << 4);
}
break;
2014-12-27 16:57:04 +01:00
case MOXIE_F1_ABi2:
2009-04-16 17:39:48 +02:00
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
char *offset;
int a, b;
a = parse_register_operand (&op_end);
while (ISSPACE (*op_end))
op_end++;
if (*op_end != ',')
{
as_bad (_("expecting comma delimited operands"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
op_end = parse_exp_save_ilp (op_end, &arg);
2014-12-27 16:57:04 +01:00
offset = frag_more (2);
2009-04-16 17:39:48 +02:00
fix_new_exp (frag_now,
(offset - frag_now->fr_literal),
2014-12-27 16:57:04 +01:00
2,
2009-04-16 17:39:48 +02:00
&arg,
0,
2014-12-27 16:57:04 +01:00
BFD_RELOC_16);
2009-04-16 17:39:48 +02:00
if (*op_end != '(')
{
as_bad (_("expecting indirect register `($rX)'"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
b = parse_register_operand (&op_end);
if (*op_end != ')')
{
as_bad (_("missing closing parenthesis"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
iword += (a << 4) + b;
}
break;
2014-12-27 16:57:04 +01:00
case MOXIE_F1_AiB2:
2009-04-16 17:39:48 +02:00
iword = opcode->opcode << 8;
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
char *offset;
int a, b;
op_end = parse_exp_save_ilp (op_end, &arg);
2014-12-27 16:57:04 +01:00
offset = frag_more (2);
2009-04-16 17:39:48 +02:00
fix_new_exp (frag_now,
(offset - frag_now->fr_literal),
2014-12-27 16:57:04 +01:00
2,
2009-04-16 17:39:48 +02:00
&arg,
0,
2014-12-27 16:57:04 +01:00
BFD_RELOC_16);
2009-04-16 17:39:48 +02:00
if (*op_end != '(')
{
as_bad (_("expecting indirect register `($rX)'"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
a = parse_register_operand (&op_end);
if (*op_end != ')')
{
as_bad (_("missing closing parenthesis"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
if (*op_end != ',')
{
as_bad (_("expecting comma delimited operands"));
2009-04-16 17:39:48 +02:00
ignore_rest_of_line ();
return;
}
op_end++;
b = parse_register_operand (&op_end);
while (ISSPACE (*op_end))
op_end++;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
iword += (a << 4) + b;
}
break;
case MOXIE_F2_NARG:
iword = opcode->opcode << 12;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
break;
case MOXIE_F3_PCREL:
iword = (3<<14) | (opcode->opcode << 10);
while (ISSPACE (*op_end))
op_end++;
{
expressionS arg;
op_end = parse_exp_save_ilp (op_end, &arg);
fix_new_exp (frag_now,
(p - frag_now->fr_literal),
2,
&arg,
TRUE,
BFD_RELOC_MOXIE_10_PCREL);
}
break;
2016-11-13 13:37:02 +01:00
case MOXIE_BAD:
iword = 0;
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
break;
2009-04-16 17:39:48 +02:00
default:
abort ();
2009-04-16 17:39:48 +02:00
}
md_number_to_chars (p, iword, 2);
Fix simple gas testsuite failures. binutils* readelf.c (is_24bit_abs_reloc): Add support for R_FT32_20 reloc. gas * config/tc-ft32.c (md_assemble): Call dwarf2_emit_insn with the instruction size. * config/tc-mcore.c (md_assemble): Likewise. * config/tc-mn10200.c (md_assemble): Likewise. * config/tc-moxie.c (md_assemble): Likewise. * config/tc-pj.c (md_apply_fix): Handle BFD_RELOC_PJ_CODE_REL32. * testsuite/gas/all/gas.exp (diff1 test): Alpha sort list of exception targets. Add alpha, hppa, microblaze and rl78 to list of exceptions. (forward): Add microblaze to list of exceptions. (fwdexp): Add alpha to list of exceptions. (redef2): Add arm-epoc-pe and rl78 to list of exceptions. (redef3): Add rl78 and x86_64 cygwin to list of exceptions. (do_930509a): Alpha sort list of exception targets. Add h8300 and mn10200 to list of exceptions. (align2): Expect to fail for nds32. (cond): Add alpha and rl78 to list of exceptions. * testsuite/gas/all/none.d: Skip for ft32 and hppa. * testsuite/gas/all/string.d: Skip for tic4x. * testsuite/gas/alpha/alpha.exp: Note that the alpha-linuxecoff target does not support ELF. * testsuite/gas/arm/blx-bl-convert.dL Skip for the nto target. * testsuite/gas/cfi/cfi-alpha-2.d: All extended format names. * testsuite/gas/cfi/cfi.exp: Alpha sort list of targets. Skip SH tests for sh-pe and sh-rtemscoff targets. * testsuite/gas/elf/elf.exp (redef): Add rl78, xgate and vax to list of exceptions. (type): Run the noifunc version for alpha-freebsd and visium. * testsuite/gas/elf/warn-2.s: Do not expect to fail on the mcore, mn10200 or moxie targets. * testsuite/gas/ft32/insn.d: Update expected disassembly. * testsuite/gas/i386/i386.exp (x86-64-pcrel): Skip for cygwin targets. * testsuite/gas/lns/lns.exp (lns-common-1): No longer skip for mcore and rx targets. * testsuite/gas/macros/macros.exp (dot): Add exceptions for ns32k, rl78 and vax. (purge): Expect to fail on the ns32k and vax. * testsuite/gas/nds32/alu-2.d: Update expected disassembly. * testsuite/gas/nds32/ls.d: Likewise. * testsuite/gas/nds32/sys-reg.d: Likewise. * testsuite/gas/nds32/usr-spe-reg.d: Likewise. * testsuite/gas/pe/aligncomm-d.d: Skip for the sh. * testsuite/gas/pe/section-align-3.d: Likewise. * testsuite/gas/pe/section-exclude.d: Likewise. * testsuite/gas/ppc/test2xcoff32.d: Pass once all the required data has been seen. * testsuite/gas/ppc/textalign-xcoff-001.d: Fix up regexp to allow for variations in whitespace. * testsuite/gas/tilepro/t_constants.d: Pass once all the required data has been seen. * testsuite/gas/tilepro/t_constants.s (.safe_word): New macro. Installs a 32-bit value without generating warnings on 64-bit hosts. Use the new macro to replace the .word directives. opcodes * nds32-dis.c (nds32_parse_audio_ext): Change printing of integer constants to match expected behaviour. (nds32_parse_opcode): Likewise. Also for whitespace.
2016-06-15 17:25:34 +02:00
dwarf2_emit_insn (2);
2009-04-16 17:39:48 +02:00
while (ISSPACE (*op_end))
op_end++;
if (*op_end != 0)
as_warn (_("extra stuff on line ignored"));
2009-04-16 17:39:48 +02:00
if (pending_reloc)
as_bad (_("Something forgot to clean up\n"));
2009-04-16 17:39:48 +02:00
}
/* Turn a string in input_line_pointer into a floating point constant
of type type, and store the appropriate bytes in *LITP. The number
of LITTLENUMS emitted is stored in *SIZEP . An error message is
returned, or NULL on OK. */
Constify more * cgen.c (weak_operand_overflow_check): Return const char*. * messages.c (as_internal_value_out_of_range): Formatting. (as_warn_value_out_of_range): Consify prefix param. (as_bad_value_out_of_range): Likewise. * read.c (s_errwarn): Constify msg.. (s_float_space, float_cons): ..and err. * as.h (as_warn_value_out_of_range, as_bad_value_out_of_range, ieee_md_atof, vax_md_atof): Update prototypes. * tc.h (md_atof): Update prototype. * config/atof-ieee.c (ieee_md_atof): Return const char*. * config/atof-vax.c (vax_md_atof): Likewise. * config/obj-elf.c (obj_elf_parse_section_letters): Constify bad_msg. * config/tc-aarch64.c (md_atof): Return const char*. * config/tc-alpha.c (s_alpha_section_name): Likewise. (s_alpha_comm): Constify sec_name. (section_name): Constify. (s_alpha_section): Consify name.. (alpha_elf_section_letter): ..and ptr_msg param.. (md_atof): ..and return. * config/tc-alpha.h (alpha_elf_section_letter): Update prototype. * config/tc-arc.c (md_atof): Return const char*. * config/tc-arm.c (md_atof): Likewise. * config/tc-avr.c (md_atof): Likewise. * config/tc-bfin.c (md_atof): Likewise. * config/tc-cr16.c (md_atof): Likewise. * config/tc-cris.c (md_atof): Likewise. * config/tc-crx.c (md_atof): Likewise. * config/tc-d10v.c (md_atof): Likewise. * config/tc-d30v.c (md_atof): Likewise. * config/tc-dlx.c (md_atof): Likewise. * config/tc-epiphany.c (md_atof): Likewise. * config/tc-fr30.c (md_atof): Likewise. * config/tc-frv.c (md_atof): Likewise. * config/tc-ft32.c (md_atof): Likewise. * config/tc-h8300.c (md_atof): Likewise. * config/tc-hppa.c (struct default_subspace_dict): Constify name. (struct default_space_dict): Likewise. (create_new_space): Constify name param. (create_new_subspace): Likewise. (is_defined_space, is_defined_subspace): Likewise. (pa_parse_space_stmt): Constify space_name param. (md_atof): Return const char*. (pa_spaces_begin): Constify name. * config/tc-i370.c (md_atof): Return const char*. * config/tc-i386.c (md_atof): Likewise. (x86_64_section_letter): Constify ptr_msg param. * config/tc-i386.h (x86_64_section_letter): Update prototype. * config/tc-i860.c (struct i860_it): Constify error. (md_atof): Return const char*. * config/tc-i960.c (md_atof): Likewise. * config/tc-ia64.c (md_atof): Likewise. (ia64_elf_section_letter): Constify ptr_msg param. * config/tc-ia64.h (ia64_elf_section_letter): Update prototype. * config/tc-ip2k.c (md_atof): Return const char*. * config/tc-iq2000.c (md_atof): Likewise. * config/tc-lm32.c (md_atof): Likewise. * config/tc-m32c.c (md_atof): Likewise. * config/tc-m32r.c (md_atof): Likewise. * config/tc-m68hc11.c (md_atof): Likewise. * config/tc-m68k.c (md_atof): Likewise. * config/tc-mcore.c (md_atof): Likewise. * config/tc-mep.c (md_atof): Likewise. (mep_elf_section_letter): Constify ptr_msg param. * config/tc-mep.h (mep_elf_section_letter): Update prototype. * config/tc-metag.c (md_atof): Return const char*. * config/tc-microblaze.c (md_atof): Likewise. * config/tc-microblaze.h (md_atof): Delete prototype. * config/tc-mips.c (mips_parse_argument_token): Constify err. (md_atof): Return const char*. * config/tc-mmix.c (md_atof): Likewise. * config/tc-mn10200.c (md_atof): Likewise. * config/tc-mn10300.c (md_atof): Likewise. * config/tc-moxie.c (md_atof): Likewise. * config/tc-msp430.c (md_atof): Likewise. * config/tc-mt.c (md_atof): Likewise. * config/tc-nds32.c (md_atof): Likewise. * config/tc-nios2.c (md_atof): Likewise. (nios2_elf_section_letter): Constify ptr_msg param. * config/tc-nios2.h (nios2_elf_section_letter): Update prototype. * config/tc-ns32k.c (md_atof): Return const char*. * config/tc-or1k.c (md_atof): Likewise. * config/tc-pdp11.c (struct pdp11_code): Constify error. (md_atof): Return const char*. * config/tc-pj.c (md_atof): Likewise. * config/tc-ppc.c (md_atof): Likewise. * config/tc-rl78.c (md_atof): Likewise. * config/tc-rx.c (md_atof): Likewise. * config/tc-s390.c (md_atof): Likewise. * config/tc-score.c (s3_atof, md_atof): Likewise. * config/tc-sh.c (md_atof): Likewise. * config/tc-sparc.c (struct sparc_it): Constify error. (md_atof): Return const char*. * config/tc-spu.c (md_atof): Likewise. * config/tc-tic30.c (md_atof): Likewise. * config/tc-tic4x.c (md_atof): Likewise. * config/tc-tic54x.c (md_atof): Likewise. * config/tc-tic6x.c (md_atof): Likewise. * config/tc-tilegx.c (md_atof): Likewise. * config/tc-tilepro.c (md_atof): Likewise. * config/tc-v850.c (parse_register_list, md_atof): Likewise. * config/tc-vax.c (md_atof): Likewise. * config/tc-visium.c (md_atof): Likewise. * config/tc-xc16x.c (md_atof): Likewise. * config/tc-xgate.c (md_atof): Likewise. * config/tc-xstormy16.c (md_atof): Likewise. * config/tc-xtensa.c (md_atof): Likewise. * config/tc-z80.c (md_atof): Likewise. * config/tc-z8k.c (md_atof): Likewise.
2016-04-01 14:07:50 +02:00
const char *
2009-04-16 17:39:48 +02:00
md_atof (int type, char *litP, int *sizeP)
{
int prec;
LITTLENUM_TYPE words[4];
char *t;
int i;
switch (type)
{
case 'f':
prec = 2;
break;
case 'd':
prec = 4;
break;
default:
*sizeP = 0;
return _("bad call to md_atof");
}
t = atof_ieee (input_line_pointer, type, words);
if (t)
input_line_pointer = t;
*sizeP = prec * 2;
for (i = prec - 1; i >= 0; i--)
{
md_number_to_chars (litP, (valueT) words[i], 2);
litP += 2;
}
return NULL;
}
2012-09-14 00:24:51 +02:00
enum options
{
OPTION_EB = OPTION_MD_BASE,
OPTION_EL,
};
2009-04-16 17:39:48 +02:00
struct option md_longopts[] =
{
2012-09-14 00:24:51 +02:00
{ "EB", no_argument, NULL, OPTION_EB},
{ "EL", no_argument, NULL, OPTION_EL},
{ NULL, no_argument, NULL, 0}
2009-04-16 17:39:48 +02:00
};
2012-09-14 00:24:51 +02:00
2009-04-16 17:39:48 +02:00
size_t md_longopts_size = sizeof (md_longopts);
2012-09-14 00:24:51 +02:00
const char *md_shortopts = "";
2009-04-16 17:39:48 +02:00
int
make md_parse_option () take a const char * This is mostly just adding const in many places, however there are a couple interesting things. We need to add casts in tc-s390.c and tc-cris.c because they have functions that assign to input_line_pointer an argument that sometimes comes from md_parse_option. Presumably this is safe because those targets never pass literals to md_parse_option (), but this code should probably be improved in the future. Also xtensa passes the argument to strtoll which is a rather odd function, it takes a const char * as argument and returns a pointer into that string as a char * through an out argument, but we can work around that by adding more variables. gas/ChangeLog: 2016-03-29 Trevor Saunders <tbsaunde+binutils@tbsaunde.org> * config/tc-aarch64.c (struct aarch64_long_option_table): Ad const qualifier. * config/tc-alpha.c (md_parse_option): Likewise. * config/tc-arc.c (md_parse_option): Likewise. * config/tc-arm.c (struct arm_long_option_table): Likewise. (md_parse_option): Likewise. * config/tc-avr.c (md_parse_option): Likewise. * config/tc-bfin.c (md_parse_option): Likewise. * config/tc-cr16.c (md_parse_option): Likewise. * config/tc-cris.c (s_cris_arch): Likewise. (md_parse_option): Likewise. * config/tc-crx.c (md_parse_option): Likewise. * config/tc-d10v.c (md_parse_option): Likewise. * config/tc-d30v.c (md_parse_option): Likewise. * config/tc-dlx.c (md_parse_option): Likewise. * config/tc-epiphany.c (md_parse_option): Likewise. * config/tc-fr30.c (md_parse_option): Likewise. * config/tc-frv.c (md_parse_option): Likewise. * config/tc-ft32.c (md_parse_option): Likewise. * config/tc-h8300.c (md_parse_option): Likewise. * config/tc-hppa.c (md_parse_option): Likewise. * config/tc-i370.c (md_parse_option): Likewise. * config/tc-i386.c (md_parse_option): Likewise. * config/tc-i860.c (md_parse_option): Likewise. * config/tc-i960.c (md_parse_option): Likewise. * config/tc-ia64.c (md_parse_option): Likewise. * config/tc-ip2k.c (md_parse_option): Likewise. * config/tc-iq2000.c (md_parse_option): Likewise. * config/tc-lm32.c (md_parse_option): Likewise. * config/tc-m32c.c (md_parse_option): Likewise. * config/tc-m32r.c (md_parse_option): Likewise. * config/tc-m68hc11.c (md_parse_option): Likewise. * config/tc-m68k.c (md_parse_option): Likewise. * config/tc-mcore.c (md_parse_option): Likewise. * config/tc-mep.c (md_parse_option): Likewise. * config/tc-metag.c (struct metag_long_option): Likewise. (md_parse_option): Likewise. * config/tc-microblaze.c (md_parse_option): Likewise. * config/tc-microblaze.h (md_parse_option): Remove prototype. * config/tc-mips.c (md_parse_option): Adjust. * config/tc-mmix.c (md_parse_option): Likewise. * config/tc-mn10200.c (md_parse_option): Likewise. * config/tc-mn10300.c (md_parse_option): Likewise. * config/tc-moxie.c (md_parse_option): Likewise. * config/tc-msp430.c (md_parse_option): Likewise. * config/tc-mt.c (md_parse_option): Likewise. * config/tc-nds32.c (md_parse_option): Likewise. * config/tc-nds32.h (nds32_parse_option): Likewise. * config/tc-nios2.c (md_parse_option): Likewise. * config/tc-ns32k.c (md_parse_option): Likewise. * config/tc-or1k.c (md_parse_option): Likewise. * config/tc-pdp11.c (md_parse_option): Likewise. * config/tc-pj.c (md_parse_option): Likewise. * config/tc-ppc.c (md_parse_option): Likewise. * config/tc-rl78.c (md_parse_option): Likewise. * config/tc-rx.c (md_parse_option): Likewise. * config/tc-s390.c (s390_parse_cpu): Likewise. * config/tc-score.c (md_parse_option): Likewise. * config/tc-sh.c (md_parse_option): Likewise. * config/tc-sparc.c (md_parse_option): Likewise. * config/tc-spu.c (md_parse_option): Likewise. * config/tc-tic30.c (md_parse_option): Likewise. * config/tc-tic4x.c (md_parse_option): Likewise. * config/tc-tic54x.c (md_parse_option): Likewise. * config/tc-tic6x.c (md_parse_option): Likewise. * config/tc-tilegx.c (md_parse_option): Likewise. * config/tc-tilepro.c (md_parse_option): Likewise. * config/tc-v850.c (md_parse_option): Likewise. * config/tc-vax.c (md_parse_option): Likewise. * config/tc-visium.c (struct visium_long_option_table): Likewise. * config/tc-xc16x.c (md_parse_option): Likewise. * config/tc-xgate.c (md_parse_option): Likewise. * config/tc-xstormy16.c (md_parse_option): Likewise. * config/tc-xtensa.c (md_parse_option): Likewise. * config/tc-z80.c (md_parse_option): Likewise. * config/tc-z8k.c (md_parse_option): Likewise. * tc.h (md_parse_option): Likewise.
2016-02-27 15:35:32 +01:00
md_parse_option (int c ATTRIBUTE_UNUSED, const char *arg ATTRIBUTE_UNUSED)
2009-04-16 17:39:48 +02:00
{
2012-09-14 00:24:51 +02:00
switch (c)
{
2015-08-12 13:40:42 +02:00
case OPTION_EB:
target_big_endian = 1;
2012-09-14 00:24:51 +02:00
break;
2015-08-12 13:40:42 +02:00
case OPTION_EL:
2012-09-14 00:24:51 +02:00
target_big_endian = 0;
break;
2015-08-12 13:40:42 +02:00
default:
2012-09-14 00:24:51 +02:00
return 0;
}
return 1;
2009-04-16 17:39:48 +02:00
}
void
md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
{
2012-09-14 00:24:51 +02:00
fprintf (stream, _("\
-EB assemble for a big endian system (default)\n\
-EL assemble for a little endian system\n"));
2009-04-16 17:39:48 +02:00
}
/* Apply a fixup to the object file. */
void
2015-08-12 13:40:42 +02:00
md_apply_fix (fixS *fixP ATTRIBUTE_UNUSED,
valueT * valP ATTRIBUTE_UNUSED, segT seg ATTRIBUTE_UNUSED)
2009-04-16 17:39:48 +02:00
{
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
long val = *valP;
long newval;
2009-04-16 17:39:48 +02:00
long max, min;
max = min = 0;
switch (fixP->fx_r_type)
{
case BFD_RELOC_32:
2012-09-14 00:24:51 +02:00
if (target_big_endian)
{
buf[0] = val >> 24;
buf[1] = val >> 16;
buf[2] = val >> 8;
buf[3] = val >> 0;
}
else
{
buf[3] = val >> 24;
buf[2] = val >> 16;
buf[1] = val >> 8;
buf[0] = val >> 0;
}
buf += 4;
2009-04-16 17:39:48 +02:00
break;
case BFD_RELOC_16:
2012-09-14 00:24:51 +02:00
if (target_big_endian)
{
buf[0] = val >> 8;
buf[1] = val >> 0;
}
else
{
buf[1] = val >> 8;
buf[0] = val >> 0;
}
buf += 2;
2009-04-16 17:39:48 +02:00
break;
case BFD_RELOC_8:
*buf++ = val;
break;
case BFD_RELOC_MOXIE_10_PCREL:
if (!val)
break;
if (val < -1024 || val > 1022)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("pcrel too far BFD_RELOC_MOXIE_10"));
/* 11 bit offset even numbered, so we remove right bit. */
val >>= 1;
newval = md_chars_to_number (buf, 2);
newval |= val & 0x03ff;
md_number_to_chars (buf, newval, 2);
break;
2009-04-16 17:39:48 +02:00
default:
abort ();
}
if (max != 0 && (val < min || val > max))
as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
fixP->fx_done = 1;
}
2012-09-14 00:24:51 +02:00
/* Put number into target byte order. */
2009-04-16 17:39:48 +02:00
void
2012-09-14 00:24:51 +02:00
md_number_to_chars (char * ptr, valueT use, int nbytes)
2009-04-16 17:39:48 +02:00
{
2012-09-14 00:24:51 +02:00
if (target_big_endian)
number_to_chars_bigendian (ptr, use, nbytes);
else
number_to_chars_littleendian (ptr, use, nbytes);
2009-04-16 17:39:48 +02:00
}
/* Convert from target byte order to host byte order. */
2012-09-14 00:24:51 +02:00
static valueT
md_chars_to_number (char * buf, int n)
{
2012-09-14 00:24:51 +02:00
valueT result = 0;
unsigned char * where = (unsigned char *) buf;
2012-09-14 00:24:51 +02:00
if (target_big_endian)
{
while (n--)
{
result <<= 8;
result |= (*where++ & 255);
}
}
else
{
2012-09-14 00:24:51 +02:00
while (n--)
{
result <<= 8;
result |= (where[n] & 255);
}
}
2012-09-14 00:24:51 +02:00
return result;
}
2009-04-16 17:39:48 +02:00
/* Generate a machine-dependent relocation. */
arelent *
tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
{
arelent *relP;
bfd_reloc_code_real_type code;
switch (fixP->fx_r_type)
{
case BFD_RELOC_32:
code = fixP->fx_r_type;
break;
case BFD_RELOC_MOXIE_10_PCREL:
code = fixP->fx_r_type;
break;
2009-04-16 17:39:48 +02:00
default:
as_bad_where (fixP->fx_file, fixP->fx_line,
_("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant"));
return 0;
}
use XNEW and related macros more gas/ChangeLog: 2016-04-03 Trevor Saunders <tbsaunde+binutils@tbsaunde.org> * app.c (app_push): use XNEW macro. * as.c: Likewise. * config/obj-elf.c (obj_elf_change_section): Likewise. (elf_copy_symbol_attributes): Likewise. (obj_elf_size): Likewise. (build_group_lists): Likewise. * config/tc-aarch64.c (add_operand_error_record): Likewise. (md_assemble): Likewise. (tc_gen_reloc): Likewise. (get_upper_str): Likewise. (aarch64_parse_features): Likewise. * config/tc-arm.c (insert_reg_alias): Likewise. (insert_neon_reg_alias): Likewise. (find_or_make_literal_pool): Likewise. (s_arm_elf_cons): Likewise. (add_unwind_opcode): Likewise. (arm_parse_extension): Likewise. * config/tc-avr.c (create_record_for_frag): Likewise. * config/tc-crx.c: Likewise. * config/tc-d30v.c: Likewise. * config/tc-dlx.c (s_proc): Likewise. * config/tc-ft32.c: Likewise. * config/tc-h8300.c: Likewise. * config/tc-hppa.c (pa_proc): Likewise. (create_new_space): Likewise. (create_new_subspace): Likewise. * config/tc-i860.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-iq2000.c (iq2000_add_macro): Likewise. (iq2000_record_hi16): Likewise. * config/tc-m32c.c (m32c_indirect_operand): Likewise. * config/tc-m32r.c (debug_sym): Likewise. (m32r_record_hi16): Likewise. * config/tc-m68k.c (m68k_ip): Likewise. (md_begin): Likewise. * config/tc-mcore.c: Likewise. * config/tc-microblaze.c (check_got): Likewise. * config/tc-mips.c (append_insn): Likewise. (s_mipsset): Likewise. (mips_record_label): Likewise. (s_mips_end): Likewise. * config/tc-mmix.c (mmix_frob_file): Likewise. * config/tc-mn10200.c: Likewise. * config/tc-mn10300.c: Likewise. * config/tc-moxie.c: Likewise. * config/tc-msp430.c: Likewise. * config/tc-nds32.c (nds32_elf_save_pseudo_pattern): Likewise. * config/tc-ns32k.c: Likewise. * config/tc-or1k.c: Likewise. * config/tc-pdp11.c: Likewise. * config/tc-pj.c (fake_opcode): Likewise. * config/tc-ppc.c (ppc_apuinfo_section_add): Likewise. (ppc_macro): Likewise. (ppc_dwsect): Likewise. (ppc_machine): Likewise. * config/tc-rl78.c (rl78_frag_init): Likewise. * config/tc-rx.c (rx_frag_init): Likewise. * config/tc-s390.c (s390_lit_suffix): Likewise. (s390_machine): Likewise. (s390_machinemode): Likewise. * config/tc-score.c (s3_insert_reg): Likewise. (s3_gen_reloc): Likewise. * config/tc-score7.c (s7_insert_reg): Likewise. (s7_gen_reloc): Likewise. * config/tc-tic30.c (tic30_operand): Likewise. * config/tc-tic4x.c (tic4x_inst_make): Likewise. * config/tc-tic54x.c (stag_add_field): Likewise. (tic54x_struct): Likewise. (tic54x_space): Likewise. (tic54x_field): Likewise. (tic54x_mlib): Likewise. (subsym_substitute): Likewise. * config/tc-tic6x.c (tic6x_frob_label): Likewise. * config/tc-vax.c: Likewise. * config/tc-xc16x.c: Likewise. * config/tc-xtensa.c (xtensa_add_insn_label): Likewise. (directive_push): Likewise. (xtensa_begin_directive): Likewise. (tokenize_arguments): Likewise. (xtensa_add_literal_sym): Likewise. (new_resource_table): Likewise. (resize_resource_table): Likewise. (emit_single_op): Likewise. (xtensa_create_trampoline_frag): Likewise. (xtensa_maybe_create_literal_pool_frag): Likewise. (xtensa_add_config_info): Likewise. (xtensa_realloc_fixup_cache): Likewise. (add_subseg_info): Likewise. (cache_literal_section): Likewise. (add_xt_block_frags): Likewise. (add_xt_prop_frags): Likewise. (init_op_placement_info_table): Likewise. (build_section_rename): Likewise. * config/tc-z80.c: Likewise. * config/tc-z8k.c: Likewise. * depend.c (register_dependency): Likewise. * dwarf2dbg.c (get_line_subseg): Likewise. (dwarf2_gen_line_info_1): Likewise. (get_filenum): Likewise. * ecoff.c (allocate_scope): Likewise. (allocate_vlinks): Likewise. (allocate_shash): Likewise. (allocate_thash): Likewise. (allocate_tag): Likewise. (allocate_forward): Likewise. (allocate_thead): Likewise. (allocate_lineno_list): Likewise. * expr.c (make_expr_symbol): Likewise. * hash.c (hash_new_sized): Likewise. * input-file.c (input_file_push): Likewise. * listing.c (file_info): Likewise. (listing_newline): Likewise. * macro.c (new_formal): Likewise. (define_macro): Likewise. * remap.c (add_debug_prefix_map): Likewise. * symbols.c (symbol_find_noref): Likewise. (define_dollar_label): Likewise. (fb_label_instance_inc): Likewise. (symbol_relc_make_value): Likewise.
2016-04-01 15:26:30 +02:00
relP = XNEW (arelent);
relP->sym_ptr_ptr = XNEW (asymbol *);
2009-04-16 17:39:48 +02:00
*relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
relP->addend = fixP->fx_offset;
/* This is the standard place for KLUDGEs to work around bugs in
bfd_install_relocation (first such note in the documentation
appears with binutils-2.8).
That function bfd_install_relocation does the wrong thing with
putting stuff into the addend of a reloc (it should stay out) for a
weak symbol. The really bad thing is that it adds the
"segment-relative offset" of the symbol into the reloc. In this
case, the reloc should instead be relative to the symbol with no
other offset than the assembly code shows; and since the symbol is
weak, any local definition should be ignored until link time (or
thereafter).
To wit: weaksym+42 should be weaksym+42 in the reloc,
not weaksym+(offset_from_segment_of_local_weaksym_definition)
To "work around" this, we subtract the segment-relative offset of
"known" weak symbols. This evens out the extra offset.
That happens for a.out but not for ELF, since for ELF,
bfd_install_relocation uses the "special function" field of the
howto, and does not execute the code that needs to be undone. */
if (OUTPUT_FLAVOR == bfd_target_aout_flavour
&& fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
&& ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
{
relP->addend -= S_GET_VALUE (fixP->fx_addsy);
}
relP->howto = bfd_reloc_type_lookup (stdoutput, code);
if (! relP->howto)
{
const char *name;
name = S_GET_NAME (fixP->fx_addsy);
if (name == NULL)
name = _("<unknown>");
as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
name, bfd_get_reloc_code_name (code));
}
return relP;
}
/* Decide from what point a pc-relative relocation is relative to,
relative to the pc-relative fixup. Er, relatively speaking. */
long
md_pcrel_from (fixS *fixP)
{
valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
switch (fixP->fx_r_type)
{
case BFD_RELOC_32:
return addr + 4;
case BFD_RELOC_MOXIE_10_PCREL:
2012-09-08 03:20:28 +02:00
/* Offset is from the end of the instruction. */
return addr + 2;
2009-04-16 17:39:48 +02:00
default:
abort ();
return addr;
}
}