OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [binutils-2.20.1/] [gas/] [config/] [tc-moxie.c] - Diff between revs 816 and 818

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 816 Rev 818
/* tc-moxie.c -- Assemble code for moxie
/* tc-moxie.c -- Assemble code for moxie
   Copyright 2009
   Copyright 2009
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
   This file is part of GAS, the GNU Assembler.
   This file is part of GAS, the GNU Assembler.
 
 
   GAS is free software; you can redistribute it and/or modify
   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   any later version.
 
 
   GAS is distributed in the hope that it will be useful,
   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with GAS; see the file COPYING.  If not, write to
   along with GAS; see the file COPYING.  If not, write to
   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
   Boston, MA 02110-1301, USA.  */
   Boston, MA 02110-1301, USA.  */
 
 
/* Contributed by Anthony Green <green@moxielogic.com>.  */
/* Contributed by Anthony Green <green@moxielogic.com>.  */
 
 
#include "as.h"
#include "as.h"
#include "safe-ctype.h"
#include "safe-ctype.h"
#include "opcode/moxie.h"
#include "opcode/moxie.h"
#include "elf/moxie.h"
#include "elf/moxie.h"
 
 
extern const moxie_opc_info_t moxie_opc_info[128];
extern const moxie_opc_info_t moxie_opc_info[128];
 
 
const char comment_chars[]        = "#";
const char comment_chars[]        = "#";
const char line_separator_chars[] = ";";
const char line_separator_chars[] = ";";
const char line_comment_chars[]   = "#";
const char line_comment_chars[]   = "#";
 
 
static int pending_reloc;
static int pending_reloc;
static struct hash_control *opcode_hash_control;
static struct hash_control *opcode_hash_control;
 
 
const pseudo_typeS md_pseudo_table[] =
const pseudo_typeS md_pseudo_table[] =
{
{
  {0, 0, 0}
  {0, 0, 0}
};
};
 
 
const char FLT_CHARS[] = "rRsSfFdDxXpP";
const char FLT_CHARS[] = "rRsSfFdDxXpP";
const char EXP_CHARS[] = "eE";
const char EXP_CHARS[] = "eE";
 
 
static int md_chars_to_number (char *val, int n);
static int md_chars_to_number (char *val, int n);
 
 
void
void
md_operand (expressionS *op __attribute__((unused)))
md_operand (expressionS *op __attribute__((unused)))
{
{
  /* Empty for now. */
  /* Empty for now. */
}
}
 
 
/* This function is called once, at assembler startup time.  It sets
/* This function is called once, at assembler startup time.  It sets
   up the hash table with all the opcodes in it, and also initializes
   up the hash table with all the opcodes in it, and also initializes
   some aliases for compatibility with other assemblers.  */
   some aliases for compatibility with other assemblers.  */
 
 
void
void
md_begin (void)
md_begin (void)
{
{
  int count;
  int count;
  const moxie_opc_info_t *opcode;
  const moxie_opc_info_t *opcode;
  opcode_hash_control = hash_new ();
  opcode_hash_control = hash_new ();
 
 
  /* Insert names into hash table.  */
  /* Insert names into hash table.  */
  for (count = 0, opcode = moxie_form1_opc_info; count++ < 64; opcode++)
  for (count = 0, opcode = moxie_form1_opc_info; count++ < 64; opcode++)
    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
 
 
  for (count = 0, opcode = moxie_form2_opc_info; count++ < 4; opcode++)
  for (count = 0, opcode = moxie_form2_opc_info; count++ < 4; opcode++)
    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
 
 
  for (count = 0, opcode = moxie_form3_opc_info; count++ < 10; opcode++)
  for (count = 0, opcode = moxie_form3_opc_info; count++ < 10; opcode++)
    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
 
 
  bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0);
  bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0);
}
}
 
 
/* Parse an expression and then restore the input line pointer.  */
/* Parse an expression and then restore the input line pointer.  */
 
 
static char *
static char *
parse_exp_save_ilp (char *s, expressionS *op)
parse_exp_save_ilp (char *s, expressionS *op)
{
{
  char *save = input_line_pointer;
  char *save = input_line_pointer;
 
 
  input_line_pointer = s;
  input_line_pointer = s;
  expression (op);
  expression (op);
  s = input_line_pointer;
  s = input_line_pointer;
  input_line_pointer = save;
  input_line_pointer = save;
  return s;
  return s;
}
}
 
 
static int
static int
parse_register_operand (char **ptr)
parse_register_operand (char **ptr)
{
{
  int reg;
  int reg;
  char *s = *ptr;
  char *s = *ptr;
 
 
  if (*s != '$')
  if (*s != '$')
    {
    {
      as_bad (_("expecting register"));
      as_bad (_("expecting register"));
      ignore_rest_of_line ();
      ignore_rest_of_line ();
      return -1;
      return -1;
    }
    }
  if (s[1] == 'f' && s[2] == 'p')
  if (s[1] == 'f' && s[2] == 'p')
    {
    {
      *ptr += 3;
      *ptr += 3;
      return 0;
      return 0;
    }
    }
  if (s[1] == 's' && s[2] == 'p')
  if (s[1] == 's' && s[2] == 'p')
    {
    {
      *ptr += 3;
      *ptr += 3;
      return 1;
      return 1;
    }
    }
  if (s[1] == 'r')
  if (s[1] == 'r')
    {
    {
      reg = s[2] - '0';
      reg = s[2] - '0';
      if ((reg < 0) || (reg > 9))
      if ((reg < 0) || (reg > 9))
        {
        {
          as_bad (_("illegal register number"));
          as_bad (_("illegal register number"));
          ignore_rest_of_line ();
          ignore_rest_of_line ();
          return -1;
          return -1;
        }
        }
      if (reg == 1)
      if (reg == 1)
        {
        {
          int r2 = s[3] - '0';
          int r2 = s[3] - '0';
          if ((r2 >= 0) && (r2 <= 3))
          if ((r2 >= 0) && (r2 <= 3))
            {
            {
              reg = 10 + r2;
              reg = 10 + r2;
              *ptr += 1;
              *ptr += 1;
            }
            }
        }
        }
    }
    }
  else
  else
    {
    {
      as_bad (_("illegal register number"));
      as_bad (_("illegal register number"));
      ignore_rest_of_line ();
      ignore_rest_of_line ();
      return -1;
      return -1;
    }
    }
 
 
  *ptr += 3;
  *ptr += 3;
 
 
  return reg + 2;
  return reg + 2;
}
}
 
 
/* This is the guts of the machine-dependent assembler.  STR points to
/* This is the guts of the machine-dependent assembler.  STR points to
   a machine dependent instruction.  This function is supposed to emit
   a machine dependent instruction.  This function is supposed to emit
   the frags/bytes it assembles to.  */
   the frags/bytes it assembles to.  */
 
 
void
void
md_assemble (char *str)
md_assemble (char *str)
{
{
  char *op_start;
  char *op_start;
  char *op_end;
  char *op_end;
 
 
  moxie_opc_info_t *opcode;
  moxie_opc_info_t *opcode;
  char *p;
  char *p;
  char pend;
  char pend;
 
 
  unsigned short iword = 0;
  unsigned short iword = 0;
 
 
  int nlen = 0;
  int nlen = 0;
 
 
  /* Drop leading whitespace.  */
  /* Drop leading whitespace.  */
  while (*str == ' ')
  while (*str == ' ')
    str++;
    str++;
 
 
  /* Find the op code end.  */
  /* Find the op code end.  */
  op_start = str;
  op_start = str;
  for (op_end = str;
  for (op_end = str;
       *op_end && !is_end_of_line[*op_end & 0xff] && *op_end != ' ';
       *op_end && !is_end_of_line[*op_end & 0xff] && *op_end != ' ';
       op_end++)
       op_end++)
    nlen++;
    nlen++;
 
 
  pend = *op_end;
  pend = *op_end;
  *op_end = 0;
  *op_end = 0;
 
 
  if (nlen == 0)
  if (nlen == 0)
    as_bad (_("can't find opcode "));
    as_bad (_("can't find opcode "));
  opcode = (moxie_opc_info_t *) hash_find (opcode_hash_control, op_start);
  opcode = (moxie_opc_info_t *) hash_find (opcode_hash_control, op_start);
  *op_end = pend;
  *op_end = pend;
 
 
  if (opcode == NULL)
  if (opcode == NULL)
    {
    {
      as_bad (_("unknown opcode %s"), op_start);
      as_bad (_("unknown opcode %s"), op_start);
      return;
      return;
    }
    }
 
 
  p = frag_more (2);
  p = frag_more (2);
 
 
  switch (opcode->itype)
  switch (opcode->itype)
    {
    {
    case MOXIE_F2_A8V:
    case MOXIE_F2_A8V:
      iword = (1<<15) | (opcode->opcode << 12);
      iword = (1<<15) | (opcode->opcode << 12);
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
        int reg;
        int reg;
        reg = parse_register_operand (&op_end);
        reg = parse_register_operand (&op_end);
        iword += (reg << 8);
        iword += (reg << 8);
        if (*op_end != ',')
        if (*op_end != ',')
          as_warn (_("expecting comma delimited register operands"));
          as_warn (_("expecting comma delimited register operands"));
        op_end++;
        op_end++;
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     ((p+1) - frag_now->fr_literal),
                     ((p+1) - frag_now->fr_literal),
                     1,
                     1,
                     &arg,
                     &arg,
                     0,
                     0,
                     BFD_RELOC_8);
                     BFD_RELOC_8);
      }
      }
      break;
      break;
    case MOXIE_F1_AB:
    case MOXIE_F1_AB:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        int dest, src;
        int dest, src;
        dest = parse_register_operand (&op_end);
        dest = parse_register_operand (&op_end);
        if (*op_end != ',')
        if (*op_end != ',')
          as_warn (_("expecting comma delimited register operands"));
          as_warn (_("expecting comma delimited register operands"));
        op_end++;
        op_end++;
        src  = parse_register_operand (&op_end);
        src  = parse_register_operand (&op_end);
        iword += (dest << 4) + src;
        iword += (dest << 4) + src;
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
      }
      }
      break;
      break;
    case MOXIE_F1_A4:
    case MOXIE_F1_A4:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
        char *where;
        char *where;
        int regnum;
        int regnum;
 
 
        regnum = parse_register_operand (&op_end);
        regnum = parse_register_operand (&op_end);
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
 
 
        iword += (regnum << 4);
        iword += (regnum << 4);
 
 
        if (*op_end != ',')
        if (*op_end != ',')
          {
          {
            as_bad (_("expecting comma delimited operands"));
            as_bad (_("expecting comma delimited operands"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
 
 
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        where = frag_more (4);
        where = frag_more (4);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     (where - frag_now->fr_literal),
                     (where - frag_now->fr_literal),
                     4,
                     4,
                     &arg,
                     &arg,
                     0,
                     0,
                     BFD_RELOC_32);
                     BFD_RELOC_32);
      }
      }
      break;
      break;
    case MOXIE_F1_M:
    case MOXIE_F1_M:
    case MOXIE_F1_4:
    case MOXIE_F1_4:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
        char *where;
        char *where;
 
 
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        where = frag_more (4);
        where = frag_more (4);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     (where - frag_now->fr_literal),
                     (where - frag_now->fr_literal),
                     4,
                     4,
                     &arg,
                     &arg,
                     0,
                     0,
                     BFD_RELOC_32);
                     BFD_RELOC_32);
      }
      }
      break;
      break;
    case MOXIE_F1_NARG:
    case MOXIE_F1_NARG:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      if (*op_end != 0)
      if (*op_end != 0)
        as_warn (_("extra stuff on line ignored"));
        as_warn (_("extra stuff on line ignored"));
      break;
      break;
    case MOXIE_F1_A:
    case MOXIE_F1_A:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        int reg;
        int reg;
        reg = parse_register_operand (&op_end);
        reg = parse_register_operand (&op_end);
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
        iword += (reg << 4);
        iword += (reg << 4);
      }
      }
      break;
      break;
    case MOXIE_F1_ABi:
    case MOXIE_F1_ABi:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        int a, b;
        int a, b;
        a = parse_register_operand (&op_end);
        a = parse_register_operand (&op_end);
        if (*op_end != ',')
        if (*op_end != ',')
          as_warn (_("expecting comma delimited register operands"));
          as_warn (_("expecting comma delimited register operands"));
        op_end++;
        op_end++;
        if (*op_end != '(')
        if (*op_end != '(')
          {
          {
            as_bad (_("expecting indirect register `($rA)'"));
            as_bad (_("expecting indirect register `($rA)'"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
        b = parse_register_operand (&op_end);
        b = parse_register_operand (&op_end);
        if (*op_end != ')')
        if (*op_end != ')')
          {
          {
            as_bad (_("missing closing parenthesis"));
            as_bad (_("missing closing parenthesis"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
        iword += (a << 4) + b;
        iword += (a << 4) + b;
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
      }
      }
      break;
      break;
    case MOXIE_F1_AiB:
    case MOXIE_F1_AiB:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        int a, b;
        int a, b;
        if (*op_end != '(')
        if (*op_end != '(')
          {
          {
            as_bad (_("expecting indirect register `($rA)'"));
            as_bad (_("expecting indirect register `($rA)'"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
        a = parse_register_operand (&op_end);
        a = parse_register_operand (&op_end);
        if (*op_end != ')')
        if (*op_end != ')')
          {
          {
            as_bad (_("missing closing parenthesis"));
            as_bad (_("missing closing parenthesis"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
        if (*op_end != ',')
        if (*op_end != ',')
          as_warn (_("expecting comma delimited register operands"));
          as_warn (_("expecting comma delimited register operands"));
        op_end++;
        op_end++;
        b = parse_register_operand (&op_end);
        b = parse_register_operand (&op_end);
        iword += (a << 4) + b;
        iword += (a << 4) + b;
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
      }
      }
      break;
      break;
    case MOXIE_F1_4A:
    case MOXIE_F1_4A:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
        char *where;
        char *where;
        int a;
        int a;
 
 
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        where = frag_more (4);
        where = frag_more (4);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     (where - frag_now->fr_literal),
                     (where - frag_now->fr_literal),
                     4,
                     4,
                     &arg,
                     &arg,
                     0,
                     0,
                     BFD_RELOC_32);
                     BFD_RELOC_32);
 
 
        if (*op_end != ',')
        if (*op_end != ',')
          {
          {
            as_bad (_("expecting comma delimited operands"));
            as_bad (_("expecting comma delimited operands"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
 
 
        a = parse_register_operand (&op_end);
        a = parse_register_operand (&op_end);
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
 
 
        iword += (a << 4);
        iword += (a << 4);
      }
      }
      break;
      break;
    case MOXIE_F1_ABi4:
    case MOXIE_F1_ABi4:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
        char *offset;
        char *offset;
        int a, b;
        int a, b;
 
 
        a = parse_register_operand (&op_end);
        a = parse_register_operand (&op_end);
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
 
 
        if (*op_end != ',')
        if (*op_end != ',')
          {
          {
            as_bad (_("expecting comma delimited operands"));
            as_bad (_("expecting comma delimited operands"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
 
 
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        offset = frag_more (4);
        offset = frag_more (4);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     (offset - frag_now->fr_literal),
                     (offset - frag_now->fr_literal),
                     4,
                     4,
                     &arg,
                     &arg,
                     0,
                     0,
                     BFD_RELOC_32);
                     BFD_RELOC_32);
 
 
        if (*op_end != '(')
        if (*op_end != '(')
          {
          {
            as_bad (_("expecting indirect register `($rX)'"));
            as_bad (_("expecting indirect register `($rX)'"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
        b = parse_register_operand (&op_end);
        b = parse_register_operand (&op_end);
        if (*op_end != ')')
        if (*op_end != ')')
          {
          {
            as_bad (_("missing closing parenthesis"));
            as_bad (_("missing closing parenthesis"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
 
 
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
 
 
        iword += (a << 4) + b;
        iword += (a << 4) + b;
      }
      }
      break;
      break;
    case MOXIE_F1_AiB4:
    case MOXIE_F1_AiB4:
      iword = opcode->opcode << 8;
      iword = opcode->opcode << 8;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
        char *offset;
        char *offset;
        int a, b;
        int a, b;
 
 
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        offset = frag_more (4);
        offset = frag_more (4);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     (offset - frag_now->fr_literal),
                     (offset - frag_now->fr_literal),
                     4,
                     4,
                     &arg,
                     &arg,
                     0,
                     0,
                     BFD_RELOC_32);
                     BFD_RELOC_32);
 
 
        if (*op_end != '(')
        if (*op_end != '(')
          {
          {
            as_bad (_("expecting indirect register `($rX)'"));
            as_bad (_("expecting indirect register `($rX)'"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
        a = parse_register_operand (&op_end);
        a = parse_register_operand (&op_end);
        if (*op_end != ')')
        if (*op_end != ')')
          {
          {
            as_bad (_("missing closing parenthesis"));
            as_bad (_("missing closing parenthesis"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
 
 
        if (*op_end != ',')
        if (*op_end != ',')
          {
          {
            as_bad (_("expecting comma delimited operands"));
            as_bad (_("expecting comma delimited operands"));
            ignore_rest_of_line ();
            ignore_rest_of_line ();
            return;
            return;
          }
          }
        op_end++;
        op_end++;
 
 
        b = parse_register_operand (&op_end);
        b = parse_register_operand (&op_end);
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
 
 
        while (ISSPACE (*op_end))
        while (ISSPACE (*op_end))
          op_end++;
          op_end++;
        if (*op_end != 0)
        if (*op_end != 0)
          as_warn (_("extra stuff on line ignored"));
          as_warn (_("extra stuff on line ignored"));
 
 
        iword += (a << 4) + b;
        iword += (a << 4) + b;
      }
      }
      break;
      break;
    case MOXIE_F2_NARG:
    case MOXIE_F2_NARG:
      iword = opcode->opcode << 12;
      iword = opcode->opcode << 12;
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      if (*op_end != 0)
      if (*op_end != 0)
        as_warn (_("extra stuff on line ignored"));
        as_warn (_("extra stuff on line ignored"));
      break;
      break;
    case MOXIE_F3_PCREL:
    case MOXIE_F3_PCREL:
      iword = (3<<14) | (opcode->opcode << 10);
      iword = (3<<14) | (opcode->opcode << 10);
      while (ISSPACE (*op_end))
      while (ISSPACE (*op_end))
        op_end++;
        op_end++;
      {
      {
        expressionS arg;
        expressionS arg;
 
 
        op_end = parse_exp_save_ilp (op_end, &arg);
        op_end = parse_exp_save_ilp (op_end, &arg);
        fix_new_exp (frag_now,
        fix_new_exp (frag_now,
                     (p - frag_now->fr_literal),
                     (p - frag_now->fr_literal),
                     2,
                     2,
                     &arg,
                     &arg,
                     TRUE,
                     TRUE,
                     BFD_RELOC_MOXIE_10_PCREL);
                     BFD_RELOC_MOXIE_10_PCREL);
      }
      }
      break;
      break;
    default:
    default:
      abort ();
      abort ();
    }
    }
 
 
  md_number_to_chars (p, iword, 2);
  md_number_to_chars (p, iword, 2);
 
 
  while (ISSPACE (*op_end))
  while (ISSPACE (*op_end))
    op_end++;
    op_end++;
 
 
  if (*op_end != 0)
  if (*op_end != 0)
    as_warn (_("extra stuff on line ignored"));
    as_warn (_("extra stuff on line ignored"));
 
 
  if (pending_reloc)
  if (pending_reloc)
    as_bad (_("Something forgot to clean up\n"));
    as_bad (_("Something forgot to clean up\n"));
}
}
 
 
/* Turn a string in input_line_pointer into a floating point constant
/* 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 type type, and store the appropriate bytes in *LITP.  The number
   of LITTLENUMS emitted is stored in *SIZEP .  An error message is
   of LITTLENUMS emitted is stored in *SIZEP .  An error message is
   returned, or NULL on OK.  */
   returned, or NULL on OK.  */
 
 
char *
char *
md_atof (int type, char *litP, int *sizeP)
md_atof (int type, char *litP, int *sizeP)
{
{
  int prec;
  int prec;
  LITTLENUM_TYPE words[4];
  LITTLENUM_TYPE words[4];
  char *t;
  char *t;
  int i;
  int i;
 
 
  switch (type)
  switch (type)
    {
    {
    case 'f':
    case 'f':
      prec = 2;
      prec = 2;
      break;
      break;
 
 
    case 'd':
    case 'd':
      prec = 4;
      prec = 4;
      break;
      break;
 
 
    default:
    default:
      *sizeP = 0;
      *sizeP = 0;
      return _("bad call to md_atof");
      return _("bad call to md_atof");
    }
    }
 
 
  t = atof_ieee (input_line_pointer, type, words);
  t = atof_ieee (input_line_pointer, type, words);
  if (t)
  if (t)
    input_line_pointer = t;
    input_line_pointer = t;
 
 
  *sizeP = prec * 2;
  *sizeP = prec * 2;
 
 
  for (i = prec - 1; i >= 0; i--)
  for (i = prec - 1; i >= 0; i--)
    {
    {
      md_number_to_chars (litP, (valueT) words[i], 2);
      md_number_to_chars (litP, (valueT) words[i], 2);
      litP += 2;
      litP += 2;
    }
    }
 
 
  return NULL;
  return NULL;
}
}


const char *md_shortopts = "";
const char *md_shortopts = "";
 
 
struct option md_longopts[] =
struct option md_longopts[] =
{
{
  {NULL, no_argument, NULL, 0}
  {NULL, no_argument, NULL, 0}
};
};
size_t md_longopts_size = sizeof (md_longopts);
size_t md_longopts_size = sizeof (md_longopts);
 
 
/* We have no target specific options yet, so these next
/* We have no target specific options yet, so these next
   two functions are empty.  */
   two functions are empty.  */
int
int
md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
{
{
  return 0;
  return 0;
}
}
 
 
void
void
md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
{
{
}
}
 
 
/* Apply a fixup to the object file.  */
/* Apply a fixup to the object file.  */
 
 
void
void
md_apply_fix (fixS *fixP ATTRIBUTE_UNUSED,
md_apply_fix (fixS *fixP ATTRIBUTE_UNUSED,
              valueT * valP ATTRIBUTE_UNUSED, segT seg ATTRIBUTE_UNUSED)
              valueT * valP ATTRIBUTE_UNUSED, segT seg ATTRIBUTE_UNUSED)
{
{
  char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  long val = *valP;
  long val = *valP;
  long newval;
  long newval;
  long max, min;
  long max, min;
  int shift;
  int shift;
 
 
  max = min = 0;
  max = min = 0;
  shift = 0;
  shift = 0;
  switch (fixP->fx_r_type)
  switch (fixP->fx_r_type)
    {
    {
    case BFD_RELOC_32:
    case BFD_RELOC_32:
      *buf++ = val >> 24;
      *buf++ = val >> 24;
      *buf++ = val >> 16;
      *buf++ = val >> 16;
      *buf++ = val >> 8;
      *buf++ = val >> 8;
      *buf++ = val >> 0;
      *buf++ = val >> 0;
      break;
      break;
 
 
    case BFD_RELOC_16:
    case BFD_RELOC_16:
      *buf++ = val >> 8;
      *buf++ = val >> 8;
      *buf++ = val >> 0;
      *buf++ = val >> 0;
      break;
      break;
 
 
    case BFD_RELOC_8:
    case BFD_RELOC_8:
      *buf++ = val;
      *buf++ = val;
      break;
      break;
 
 
    case BFD_RELOC_MOXIE_10_PCREL:
    case BFD_RELOC_MOXIE_10_PCREL:
      if (!val)
      if (!val)
        break;
        break;
      if (val < -1024 || val > 1022)
      if (val < -1024 || val > 1022)
        as_bad_where (fixP->fx_file, fixP->fx_line,
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("pcrel too far BFD_RELOC_MOXIE_10"));
                      _("pcrel too far BFD_RELOC_MOXIE_10"));
      /* 11 bit offset even numbered, so we remove right bit.  */
      /* 11 bit offset even numbered, so we remove right bit.  */
      val >>= 1;
      val >>= 1;
      newval = md_chars_to_number (buf, 2);
      newval = md_chars_to_number (buf, 2);
      newval |= val & 0x03ff;
      newval |= val & 0x03ff;
      md_number_to_chars (buf, newval, 2);
      md_number_to_chars (buf, newval, 2);
      break;
      break;
 
 
    default:
    default:
      abort ();
      abort ();
    }
    }
 
 
  if (max != 0 && (val < min || val > max))
  if (max != 0 && (val < min || val > max))
    as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
    as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
 
 
  if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
  if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
    fixP->fx_done = 1;
    fixP->fx_done = 1;
}
}
 
 
/* Put number into target byte order (big endian).  */
/* Put number into target byte order (big endian).  */
 
 
void
void
md_number_to_chars (char *ptr, valueT use, int nbytes)
md_number_to_chars (char *ptr, valueT use, int nbytes)
{
{
  number_to_chars_bigendian (ptr, use, nbytes);
  number_to_chars_bigendian (ptr, use, nbytes);
}
}
 
 
/* Convert from target byte order to host byte order.  */
/* Convert from target byte order to host byte order.  */
 
 
static int
static int
md_chars_to_number (char *val, int n)
md_chars_to_number (char *val, int n)
{
{
  int retval = 0;
  int retval = 0;
 
 
  while (n--)
  while (n--)
    {
    {
      retval <<= 8;
      retval <<= 8;
      retval |= (*val++ & 255);
      retval |= (*val++ & 255);
    }
    }
 
 
  return retval;
  return retval;
}
}
 
 
/* Generate a machine-dependent relocation.  */
/* Generate a machine-dependent relocation.  */
arelent *
arelent *
tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
{
{
  arelent *relP;
  arelent *relP;
  bfd_reloc_code_real_type code;
  bfd_reloc_code_real_type code;
 
 
  switch (fixP->fx_r_type)
  switch (fixP->fx_r_type)
    {
    {
    case BFD_RELOC_32:
    case BFD_RELOC_32:
      code = fixP->fx_r_type;
      code = fixP->fx_r_type;
      break;
      break;
    case BFD_RELOC_MOXIE_10_PCREL:
    case BFD_RELOC_MOXIE_10_PCREL:
      code = fixP->fx_r_type;
      code = fixP->fx_r_type;
      break;
      break;
    default:
    default:
      as_bad_where (fixP->fx_file, fixP->fx_line,
      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"));
                    _("Semantics error.  This type of operand can not be relocated, it must be an assembly-time constant"));
      return 0;
      return 0;
    }
    }
 
 
  relP = xmalloc (sizeof (arelent));
  relP = xmalloc (sizeof (arelent));
  gas_assert (relP != 0);
  gas_assert (relP != 0);
  relP->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  relP->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
  *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
  *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
  relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
  relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
 
 
  relP->addend = fixP->fx_offset;
  relP->addend = fixP->fx_offset;
 
 
  /* This is the standard place for KLUDGEs to work around bugs in
  /* This is the standard place for KLUDGEs to work around bugs in
     bfd_install_relocation (first such note in the documentation
     bfd_install_relocation (first such note in the documentation
     appears with binutils-2.8).
     appears with binutils-2.8).
 
 
     That function bfd_install_relocation does the wrong thing with
     That function bfd_install_relocation does the wrong thing with
     putting stuff into the addend of a reloc (it should stay out) for a
     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
     weak symbol.  The really bad thing is that it adds the
     "segment-relative offset" of the symbol into the reloc.  In this
     "segment-relative offset" of the symbol into the reloc.  In this
     case, the reloc should instead be relative to the symbol with no
     case, the reloc should instead be relative to the symbol with no
     other offset than the assembly code shows; and since the symbol is
     other offset than the assembly code shows; and since the symbol is
     weak, any local definition should be ignored until link time (or
     weak, any local definition should be ignored until link time (or
     thereafter).
     thereafter).
     To wit:  weaksym+42  should be weaksym+42 in the reloc,
     To wit:  weaksym+42  should be weaksym+42 in the reloc,
     not weaksym+(offset_from_segment_of_local_weaksym_definition)
     not weaksym+(offset_from_segment_of_local_weaksym_definition)
 
 
     To "work around" this, we subtract the segment-relative offset of
     To "work around" this, we subtract the segment-relative offset of
     "known" weak symbols.  This evens out the extra offset.
     "known" weak symbols.  This evens out the extra offset.
 
 
     That happens for a.out but not for ELF, since for ELF,
     That happens for a.out but not for ELF, since for ELF,
     bfd_install_relocation uses the "special function" field of the
     bfd_install_relocation uses the "special function" field of the
     howto, and does not execute the code that needs to be undone.  */
     howto, and does not execute the code that needs to be undone.  */
 
 
  if (OUTPUT_FLAVOR == bfd_target_aout_flavour
  if (OUTPUT_FLAVOR == bfd_target_aout_flavour
      && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
      && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy)
      && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
      && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy)))
    {
    {
      relP->addend -= S_GET_VALUE (fixP->fx_addsy);
      relP->addend -= S_GET_VALUE (fixP->fx_addsy);
    }
    }
 
 
  relP->howto = bfd_reloc_type_lookup (stdoutput, code);
  relP->howto = bfd_reloc_type_lookup (stdoutput, code);
  if (! relP->howto)
  if (! relP->howto)
    {
    {
      const char *name;
      const char *name;
 
 
      name = S_GET_NAME (fixP->fx_addsy);
      name = S_GET_NAME (fixP->fx_addsy);
      if (name == NULL)
      if (name == NULL)
        name = _("<unknown>");
        name = _("<unknown>");
      as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
      as_fatal (_("Cannot generate relocation type for symbol %s, code %s"),
                name, bfd_get_reloc_code_name (code));
                name, bfd_get_reloc_code_name (code));
    }
    }
 
 
  return relP;
  return relP;
}
}
 
 
/* Decide from what point a pc-relative relocation is relative to,
/* Decide from what point a pc-relative relocation is relative to,
   relative to the pc-relative fixup.  Er, relatively speaking.  */
   relative to the pc-relative fixup.  Er, relatively speaking.  */
long
long
md_pcrel_from (fixS *fixP)
md_pcrel_from (fixS *fixP)
{
{
  valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
  valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
 
 
  switch (fixP->fx_r_type)
  switch (fixP->fx_r_type)
    {
    {
    case BFD_RELOC_32:
    case BFD_RELOC_32:
      return addr + 4;
      return addr + 4;
    case BFD_RELOC_MOXIE_10_PCREL:
    case BFD_RELOC_MOXIE_10_PCREL:
      return addr;
      return addr;
    default:
    default:
      abort ();
      abort ();
      return addr;
      return addr;
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.