Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
tc-xstormy16.c File Reference
#include "as.h"
#include "subsegs.h"
#include "symcat.h"
#include "opcodes/xstormy16-desc.h"
#include "opcodes/xstormy16-opc.h"
#include "cgen.h"

Go to the source code of this file.

Classes

struct  xstormy16_insn

Defines

#define INSN_VALUE(buf)   (buf)
#define O_fptr_symbol   (O_max + 1)
#define XSTORMY16_SHORTOPTS   ""
#define MAX_LITTLENUMS   6

Functions

int md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
void md_show_usage (FILE *stream)
void md_begin (void)
void md_assemble (char *str)
void md_operand (expressionS *e)
void xstormy16_cons_fix_new (fragS *f, int where, int nbytes, expressionS *exp)
fixS * xstormy16_cgen_record_fixup_exp (fragS *frag, int where, const CGEN_INSN *insn, int length, const CGEN_OPERAND *operand, int opinfo, expressionS *exp)
valueT md_section_align (segT segment, valueT size)
symbolS * md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
int md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED, segT segment ATTRIBUTE_UNUSED)
void md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED, fragS *fragP ATTRIBUTE_UNUSED)
long md_pcrel_from_section (fixS *fixP, segT sec)
bfd_reloc_code_real_type md_cgen_lookup_reloc (const CGEN_INSN *insn ATTRIBUTE_UNUSED, const CGEN_OPERAND *operand, fixS *fixP)
int xstormy16_force_relocation (fixS *fix)
bfd_boolean xstormy16_fix_adjustable (fixS *fixP)
void xstormy16_md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
void md_number_to_chars (char *buf, valueT val, int n)
char * md_atof (int type, char *litP, int *sizeP)

Variables

const char comment_chars [] = ";"
const char line_comment_chars [] = "#"
const char line_separator_chars [] = "|"
const char EXP_CHARS [] = "eE"
const char FLT_CHARS [] = "dD"
const char * md_shortopts = XSTORMY16_SHORTOPTS
size_t md_longopts_size = sizeof (md_longopts)
const pseudo_typeS md_pseudo_table []
static bfd_boolean skipping_fptr = FALSE

Class Documentation

struct xstormy16_insn

Definition at line 31 of file tc-xstormy16.c.

Class Members
char * addr
unsigned char buffer
CGEN_FIELDS fields
fixS * fixups
fragS * frag
int indices
const CGEN_INSN * insn
int num_fixups
const CGEN_INSN * orig_insn

Define Documentation

#define INSN_VALUE (   buf)    (buf)

Definition at line 41 of file tc-xstormy16.c.

#define MAX_LITTLENUMS   6

Definition at line 605 of file tc-xstormy16.c.

#define O_fptr_symbol   (O_max + 1)

Definition at line 57 of file tc-xstormy16.c.

#define XSTORMY16_SHORTOPTS   ""

Definition at line 59 of file tc-xstormy16.c.


Function Documentation

void md_assemble ( char *  str)

Definition at line 108 of file tc-xstormy16.c.

{
  xstormy16_insn insn;
  char *    errmsg;

  /* Make sure that if we had an erroneous input line which triggered
     the skipping_fptr boolean that it does not affect following lines.  */
  skipping_fptr = FALSE;

  /* Initialize GAS's cgen interface for a new instruction.  */
  gas_cgen_init_parse ();

  insn.insn = xstormy16_cgen_assemble_insn
    (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg);

  if (!insn.insn)
    {
      as_bad (errmsg);
      return;
    }

  /* Doesn't really matter what we pass for RELAX_P here.  */
  gas_cgen_finish_insn (insn.insn, insn.buffer,
                     CGEN_FIELDS_BITSIZE (& insn.fields), 0, NULL);
}

Here is the call graph for this function:

char* md_atof ( int type  ,
char *  litP,
int sizeP 
)

Definition at line 608 of file tc-xstormy16.c.

{
  int              prec;
  LITTLENUM_TYPE   words [MAX_LITTLENUMS];
  LITTLENUM_TYPE   *wordP;
  char *           t;

  switch (type)
    {
    case 'f':
    case 'F':
      prec = 2;
      break;

    case 'd':
    case 'D':
      prec = 4;
      break;

   /* FIXME: Some targets allow other format chars for bigger sizes here.  */

    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 * sizeof (LITTLENUM_TYPE);

  *sizeP = prec * sizeof (LITTLENUM_TYPE);
  /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
     the littleendianness of the processor.  */
  for (wordP = words + prec - 1; prec--;)
    {
      md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
      litP += sizeof (LITTLENUM_TYPE);
    }

  return 0;
}

Here is the call graph for this function:

void md_begin ( void  )

Definition at line 90 of file tc-xstormy16.c.

{
  /* Initialize the `cgen' interface.  */

  /* Set the machine number and endian.  */
  gas_cgen_cpu_desc = xstormy16_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
                                     CGEN_CPU_OPEN_ENDIAN,
                                     CGEN_ENDIAN_LITTLE,
                                     CGEN_CPU_OPEN_END);
  xstormy16_cgen_init_asm (gas_cgen_cpu_desc);

  /* This is a callback from cgen to gas to parse operands.  */
  cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);
}

Here is the call graph for this function:

bfd_reloc_code_real_type md_cgen_lookup_reloc ( const CGEN_INSN *insn  ATTRIBUTE_UNUSED,
const CGEN_OPERAND operand,
fixS *  fixP 
)

Definition at line 355 of file tc-xstormy16.c.

{
  switch (operand->type)
    {
    case XSTORMY16_OPERAND_IMM2:
    case XSTORMY16_OPERAND_IMM3:
    case XSTORMY16_OPERAND_IMM3B:
    case XSTORMY16_OPERAND_IMM4:
    case XSTORMY16_OPERAND_HMEM8:
      return BFD_RELOC_NONE;

    case XSTORMY16_OPERAND_IMM12:
      fixP->fx_where += 2;
      return BFD_RELOC_XSTORMY16_12;

    case XSTORMY16_OPERAND_IMM8:
    case XSTORMY16_OPERAND_LMEM8:
      return fixP->fx_pcrel ? BFD_RELOC_8_PCREL : BFD_RELOC_8;

    case XSTORMY16_OPERAND_IMM16:
      /* This might have been processed at parse time.  */
      fixP->fx_where += 2;
      if (fixP->fx_cgen.opinfo && fixP->fx_cgen.opinfo != BFD_RELOC_NONE)
       return fixP->fx_cgen.opinfo;
      return fixP->fx_pcrel ? BFD_RELOC_16_PCREL : BFD_RELOC_16;

    case XSTORMY16_OPERAND_ABS24:
      return BFD_RELOC_XSTORMY16_24;

    case XSTORMY16_OPERAND_REL8_4:
      fixP->fx_addnumber -= 2;
    case XSTORMY16_OPERAND_REL8_2:
      fixP->fx_addnumber -= 2;
      fixP->fx_pcrel = 1;
      return BFD_RELOC_8_PCREL;

    case XSTORMY16_OPERAND_REL12:
      fixP->fx_where += 2;
      /* Fall through...  */
    case XSTORMY16_OPERAND_REL12A:
      fixP->fx_addnumber -= 2;
      fixP->fx_pcrel = 1;
      return BFD_RELOC_XSTORMY16_REL_12;

    default : /* avoid -Wall warning */
      abort ();
    }
}
void md_convert_frag ( bfd *abfd  ATTRIBUTE_UNUSED,
segT sec  ATTRIBUTE_UNUSED,
fragS *fragP  ATTRIBUTE_UNUSED 
)

Definition at line 321 of file tc-xstormy16.c.

{
  /* No assembler relaxation is defined (or necessary) for this port.  */
  abort ();
}
int md_estimate_size_before_relax ( fragS *fragP  ATTRIBUTE_UNUSED,
segT segment  ATTRIBUTE_UNUSED 
)

Definition at line 306 of file tc-xstormy16.c.

{
  /* No assembler relaxation is defined (or necessary) for this port.  */
  abort ();
}
void md_number_to_chars ( char *  buf,
valueT  val,
int  n 
)

Definition at line 594 of file tc-xstormy16.c.

Here is the call graph for this function:

void md_operand ( expressionS e)

Definition at line 135 of file tc-xstormy16.c.

{
  if (*input_line_pointer != '@')
    return;

  if (strncmp (input_line_pointer + 1, "fptr", 4) == 0)
    {
      input_line_pointer += 5;
      SKIP_WHITESPACE ();
      if (*input_line_pointer != '(')
       {
         as_bad ("Expected '('");
         goto err;
       }
      input_line_pointer++;

      expression (e);

      if (*input_line_pointer != ')')
       {
         as_bad ("Missing ')'");
         goto err;
       }
      input_line_pointer++;
      SKIP_WHITESPACE ();

      if (e->X_op != O_symbol)
       as_bad ("Not a symbolic expression");
      else if (* input_line_pointer == '-')
       /* We are computing the difference of two function pointers
          like this:

           .hword  @fptr (foo) - @fptr (bar)

         In this situation we do not want to generate O_fptr_symbol
         operands because the result is an absolute value, not a
         function pointer.

         We need to make the check here, rather than when the fixup
         is generated as the function names (foo & bar in the above
         example) might be local symbols and we want the expression
         to be evaluated now.  This kind of thing can happen when
         gcc is generating computed gotos.  */
       skipping_fptr = TRUE;
      else if (skipping_fptr)
       skipping_fptr = FALSE;
      else
        e->X_op = O_fptr_symbol;
    }

  return;
 err:
  ignore_rest_of_line ();
}

Here is the call graph for this function:

int md_parse_option ( int c  ATTRIBUTE_UNUSED,
char *arg  ATTRIBUTE_UNUSED 
)

Definition at line 69 of file tc-xstormy16.c.

{
  return 0;
}
long md_pcrel_from_section ( fixS *  fixP,
segT sec   
)

Definition at line 335 of file tc-xstormy16.c.

{
  if ((fixP->fx_addsy != (symbolS *) NULL
       && (! S_IS_DEFINED (fixP->fx_addsy)
          || S_GET_SEGMENT (fixP->fx_addsy) != sec))
      || xstormy16_force_relocation (fixP))
    /* The symbol is undefined,
       or it is defined but not in this section,
       or the relocation will be relative to this symbol not the section symbol.     
       Let the linker figure it out.  */
    return 0;

  return fixP->fx_frag->fr_address + fixP->fx_where;
}

Here is the call graph for this function:

valueT md_section_align ( segT segment  ,
valueT size   
)

Definition at line 281 of file tc-xstormy16.c.

{
  int align = bfd_get_section_alignment (stdoutput, segment);

  return ((size + (1 << align) - 1) & (-1 << align));
}

Here is the call graph for this function:

void md_show_usage ( FILE *  stream)

Definition at line 76 of file tc-xstormy16.c.

{
  fprintf (stream, _(" XSTORMY16 specific command line options:\n"));
}

Here is the call graph for this function:

symbolS* md_undefined_symbol ( char *name  ATTRIBUTE_UNUSED)

Definition at line 289 of file tc-xstormy16.c.

{
  return 0;
}
fixS* xstormy16_cgen_record_fixup_exp ( fragS *  frag,
int  where,
const CGEN_INSN *  insn,
int  length,
const CGEN_OPERAND operand,
int  opinfo,
expressionS exp 
)

Definition at line 249 of file tc-xstormy16.c.

{
  fixS *fixP;
  operatorT op = exp->X_op;

  if (op == O_fptr_symbol)
    exp->X_op = O_symbol;

  fixP = gas_cgen_record_fixup_exp (frag, where, insn, length,
                                operand, opinfo, exp);

  if (op == O_fptr_symbol)
    {
      if (operand->type != XSTORMY16_OPERAND_IMM16)
       as_bad ("unsupported fptr fixup");
      else
       {
         fixP->fx_r_type = BFD_RELOC_XSTORMY16_FPTR16;
         fixP->fx_where += 2;
       }
    }

  return fixP;
}

Here is the call graph for this function:

void xstormy16_cons_fix_new ( fragS *  f,
int  where,
int  nbytes,
expressionS exp 
)

Definition at line 194 of file tc-xstormy16.c.

{
  bfd_reloc_code_real_type code;
  fixS *fix;

  if (exp->X_op == O_fptr_symbol)
    {
      switch (nbytes)
       {
       case 4:
         /* This can happen when gcc is generating debug output.
            For example it can create a stab with the address of
            a function:
            
              .stabs "foo:F(0,21)",36,0,0,@fptr(foo)
 
            Since this does not involve switching code pages, we
            just allow the reloc to be generated without any
            @fptr behaviour.  */
         exp->X_op = O_symbol;
         code = BFD_RELOC_32;
         break;

       case 2:
         exp->X_op = O_symbol;
         code = BFD_RELOC_XSTORMY16_FPTR16;
         break;

       default:
         as_bad ("unsupported fptr fixup size %d", nbytes);
         return;
       }
    }
  else if (nbytes == 1)
    code = BFD_RELOC_8;
  else if (nbytes == 2)
    code = BFD_RELOC_16;
  else if (nbytes == 4)
    code = BFD_RELOC_32;
  else
    {
      as_bad ("unsupported fixup size %d", nbytes);
      return;
    }

  fix = fix_new_exp (f, where, nbytes, exp, 0, code);
}

Here is the call graph for this function:

Definition at line 423 of file tc-xstormy16.c.

{
  /* We need the symbol name for the VTABLE entries.  */
  if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
      || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
    return FALSE;

  if (fixP->fx_r_type == BFD_RELOC_XSTORMY16_FPTR16)
    return FALSE;

  return TRUE;
}

Definition at line 411 of file tc-xstormy16.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void xstormy16_md_apply_fix ( fixS *  fixP,
valueT valueP,
segT seg  ATTRIBUTE_UNUSED 
)

Definition at line 440 of file tc-xstormy16.c.

{
  char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
  valueT value = *valueP;
  /* Canonical name, since used a lot.  */
  CGEN_CPU_DESC cd = gas_cgen_cpu_desc;

  /* md_cgen_lookup_reloc() will adjust this to compensate for where
     in the opcode the relocation happens, for pcrel relocations.  We
     have no other way of keeping track of what this offset needs to
     be.  */
  fixP->fx_addnumber = 0;

  /* This port has pc-relative relocs and DIFF_EXPR_OK defined, so
     it must deal with turning a BFD_RELOC_{8,16,32,64} into a
     BFD_RELOC_*_PCREL for the case of

       .word something-.  */
  if (fixP->fx_pcrel)
    switch (fixP->fx_r_type)
      {
      case BFD_RELOC_8:
       fixP->fx_r_type = BFD_RELOC_8_PCREL;
       break;
      case BFD_RELOC_16:
       fixP->fx_r_type = BFD_RELOC_16_PCREL;
       break;
      case BFD_RELOC_32:
       fixP->fx_r_type = BFD_RELOC_32_PCREL;
       break;
      case BFD_RELOC_64:
       fixP->fx_r_type = BFD_RELOC_64_PCREL;
       break;
      default:
       break;
      }

  if (fixP->fx_addsy == (symbolS *) NULL)
    fixP->fx_done = 1;

  /* We don't actually support subtracting a symbol.  */
  if (fixP->fx_subsy != (symbolS *) NULL)
    as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));

  if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
    {
      int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
      const CGEN_OPERAND *operand = cgen_operand_lookup_by_num (cd, opindex);
      const char *errmsg;
      bfd_reloc_code_real_type reloc_type;
      CGEN_FIELDS *fields = alloca (CGEN_CPU_SIZEOF_FIELDS (cd));
      const CGEN_INSN *insn = fixP->fx_cgen.insn;

      /* If the reloc has been fully resolved finish the operand here.  */
      /* FIXME: This duplicates the capabilities of code in BFD.  */
      if (fixP->fx_done)
       {
         CGEN_CPU_SET_FIELDS_BITSIZE (cd) (fields, CGEN_INSN_BITSIZE (insn));
         CGEN_CPU_SET_VMA_OPERAND (cd) (cd, opindex, fields, (bfd_vma) value);

#if CGEN_INT_INSN_P
         {
           CGEN_INSN_INT insn_value =
             cgen_get_insn_value (cd, (unsigned char *) where,
                               CGEN_INSN_BITSIZE (insn));

           /* ??? 0 is passed for `pc'.  */
           errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields,
                                             &insn_value, (bfd_vma) 0);
           cgen_put_insn_value (cd, (unsigned char *) where,
                             CGEN_INSN_BITSIZE (insn), insn_value);
         }
#else
         /* ??? 0 is passed for `pc'.  */
         errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields,
                                           (unsigned char *) where,
                                           (bfd_vma) 0);
#endif
         if (errmsg)
           as_bad_where (fixP->fx_file, fixP->fx_line, "%s", errmsg);
       }

      if (fixP->fx_done)
       return;

      /* The operand isn't fully resolved.  Determine a BFD reloc value
        based on the operand information and leave it to
        bfd_install_relocation.  Note that this doesn't work when
        !partial_inplace.  */

      reloc_type = md_cgen_lookup_reloc (insn, operand, fixP);
      if (reloc_type != BFD_RELOC_NONE)
       fixP->fx_r_type = reloc_type;
      else
       {
         as_bad_where (fixP->fx_file, fixP->fx_line,
                     _("unresolved expression that must be resolved"));
         fixP->fx_done = 1;
         return;
       }
    }
  else if (fixP->fx_done)
    {
      /* We're finished with this fixup.  Install it because
        bfd_install_relocation won't be called to do it.  */
      switch (fixP->fx_r_type)
       {
       case BFD_RELOC_8:
         md_number_to_chars (where, value, 1);
         break;
       case BFD_RELOC_16:
         md_number_to_chars (where, value, 2);
         break;
       case BFD_RELOC_32:
         md_number_to_chars (where, value, 4);
         break;
       case BFD_RELOC_64:
         md_number_to_chars (where, value, 8);
         break;
       default:
         as_bad_where (fixP->fx_file, fixP->fx_line,
                     _("internal error: can't install fix for reloc type %d (`%s')"),
                     fixP->fx_r_type, bfd_get_reloc_code_name (fixP->fx_r_type));
         break;
       }
    }
  else
    {
      /* bfd_install_relocation will be called to finish things up.  */
    }

  /* This is a RELA port.  Thus, it does not need to store a
     value if it is going to make a reloc.  What's more, when
     assembling a line like

     .byte global-0x7f00

     we'll get a spurious error message if we try to stuff 0x7f00 into
     the byte.  */
  if (! fixP->fx_done)
    *valueP = 0;

  /* Tuck `value' away for use by tc_gen_reloc.
     See the comment describing fx_addnumber in write.h.
     This field is misnamed (or misused :-).  */
  fixP->fx_addnumber += value;
}

Here is the call graph for this function:


Variable Documentation

const char comment_chars[] = ";"

Definition at line 51 of file tc-xstormy16.c.

const char EXP_CHARS[] = "eE"

Definition at line 54 of file tc-xstormy16.c.

const char FLT_CHARS[] = "dD"

Definition at line 55 of file tc-xstormy16.c.

const char line_comment_chars[] = "#"

Definition at line 52 of file tc-xstormy16.c.

Definition at line 53 of file tc-xstormy16.c.

size_t md_longopts_size = sizeof (md_longopts)

Definition at line 66 of file tc-xstormy16.c.

const pseudo_typeS md_pseudo_table[]
Initial value:
{
  { "word",   cons,         4 },
  { NULL,     NULL,         0 }
}

Definition at line 82 of file tc-xstormy16.c.

Definition at line 60 of file tc-xstormy16.c.

Definition at line 105 of file tc-xstormy16.c.