Wolfgang Thallergcc16 merge934c3885 months agoHistory
921 lines · 24.2 KB · C
RawDownload
/* DO NOT EDIT!  -*- buffer-read-only: t -*- vi:set ro:  *//* Assembler interface for targets using CGEN. -*- C -*-   CGEN: Cpu tools GENerator    THIS FILE IS MACHINE GENERATED WITH CGEN.   - the resultant file is machine generated, cgen-asm.in isn't    Copyright (C) 1996-2026 Free Software Foundation, Inc.    This file is part of libopcodes.    This library 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.    It 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 this program; if not, write to the Free Software Foundation, Inc.,   51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */  /* ??? Eventually more and more of this stuff can go to cpu-independent files.   Keep that in mind.  */ #include "sysdep.h"#include <stdio.h>#include "ansidecl.h"#include "bfd.h"#include "symcat.h"#include "ip2k-desc.h"#include "ip2k-opc.h"#include "opintl.h"#include "xregex.h"#include "libiberty.h"#include "safe-ctype.h" #undef  min#define min(a,b) ((a) < (b) ? (a) : (b))#undef  max#define max(a,b) ((a) > (b) ? (a) : (b)) static const char * parse_insn_normal  (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);/* -- assembler routines inserted here.  */ /* -- asm.c */ static const char *parse_fr (CGEN_CPU_DESC cd,	  const char **strp,	  int opindex,	  unsigned long *valuep){  const char *errmsg;  const char *old_strp;  char *afteroffset;  enum cgen_parse_operand_result result_type;  bfd_vma value;  extern CGEN_KEYWORD ip2k_cgen_opval_register_names;  bfd_vma tempvalue;   old_strp = *strp;  afteroffset = NULL;   /* Check here to see if you're about to try parsing a w as the first arg     and return an error if you are.  */  if ((strncmp (*strp, "w", 1) == 0) || (strncmp (*strp, "W", 1) == 0))    {      (*strp)++;       if ((strncmp (*strp, ",", 1) == 0) || ISSPACE (**strp))	{	  /* We've been passed a w.  Return with an error message so that	     cgen will try the next parsing option.  */	  errmsg = _("W keyword invalid in FR operand slot.");	  return errmsg;	}      *strp = old_strp;    }   /* Attempt parse as register keyword. */  errmsg = cgen_parse_keyword (cd, strp, & ip2k_cgen_opval_register_names,			       (long *) valuep);  if (*strp != NULL      && errmsg == NULL)    return errmsg;   /* Attempt to parse for "(IP)".  */  afteroffset = strstr (*strp, "(IP)");   if (afteroffset == NULL)    /* Make sure it's not in lower case.  */    afteroffset = strstr (*strp, "(ip)");   if (afteroffset != NULL)    {      if (afteroffset != *strp)	{	  /* Invalid offset present.  */	  errmsg = _("offset(IP) is not a valid form");	  return errmsg;	}      else	{	  *strp += 4;	  *valuep = 0;	  errmsg = NULL;	  return errmsg;	}    }   /* Attempt to parse for DP. ex: mov w, offset(DP)                                  mov offset(DP),w   */   /* Try parsing it as an address and see what comes back.  */  afteroffset = strstr (*strp, "(DP)");   if (afteroffset == NULL)    /* Maybe it's in lower case.  */    afteroffset = strstr (*strp, "(dp)");   if (afteroffset != NULL)    {      if (afteroffset == *strp)	{	  /* No offset present. Use 0 by default.  */	  tempvalue = 0;	  errmsg = NULL;	}      else	errmsg = cgen_parse_address (cd, strp, opindex,				     BFD_RELOC_IP2K_FR_OFFSET,				     & result_type, & tempvalue);       if (errmsg == NULL)	{	  if (tempvalue <= 127)	    {	      /* Value is ok.  Fix up the first 2 bits and return.  */	      *valuep = 0x0100 | tempvalue;	      *strp += 4; /* Skip over the (DP) in *strp.  */	      return errmsg;	    }	  else	    {	      /* Found something there in front of (DP) but it's out		 of range.  */	      errmsg = _("(DP) offset out of range.");	      return errmsg;	    }	}    }    /* Attempt to parse for SP. ex: mov w, offset(SP)                                  mov offset(SP), w.  */  afteroffset = strstr (*strp, "(SP)");   if (afteroffset == NULL)    /* Maybe it's in lower case.  */    afteroffset = strstr (*strp, "(sp)");   if (afteroffset != NULL)    {      if (afteroffset == *strp)	{	  /* No offset present. Use 0 by default.  */	  tempvalue = 0;	  errmsg = NULL;	}      else	errmsg = cgen_parse_address (cd, strp, opindex,				     BFD_RELOC_IP2K_FR_OFFSET,				     & result_type, & tempvalue);       if (errmsg == NULL)	{	  if (tempvalue <= 127)	    {	      /* Value is ok.  Fix up the first 2 bits and return.  */	      *valuep = 0x0180 | tempvalue;	      *strp += 4; /* Skip over the (SP) in *strp.  */	      return errmsg;	    }	  else	    {	      /* Found something there in front of (SP) but it's out		 of range.  */	      errmsg = _("(SP) offset out of range.");	      return errmsg;	    }	}    }   /* Attempt to parse as an address.  */  *strp = old_strp;  errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_IP2K_FR9,			       & result_type, & value);  if (errmsg == NULL)    {      *valuep = value;       /* If a parenthesis is found, warn about invalid form.  */      if (**strp == '(')	errmsg = _("illegal use of parentheses");       /* If a numeric value is specified, ensure that it is between	 1 and 255.  */      else if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)	{	  if (value < 0x1 || value > 0xff)	    errmsg = _("operand out of range (not between 1 and 255)");	}    }  return errmsg;} static const char *parse_addr16 (CGEN_CPU_DESC cd,	      const char **strp,	      int opindex,	      unsigned long *valuep){  const char *errmsg;  enum cgen_parse_operand_result result_type;  bfd_reloc_code_real_type code = BFD_RELOC_NONE;  bfd_vma value;   if (opindex == (CGEN_OPERAND_TYPE) IP2K_OPERAND_ADDR16H)    code = BFD_RELOC_IP2K_HI8DATA;  else if (opindex == (CGEN_OPERAND_TYPE) IP2K_OPERAND_ADDR16L)    code = BFD_RELOC_IP2K_LO8DATA;  else    {      /* Something is very wrong. opindex has to be one of the above.  */      errmsg = _("parse_addr16: invalid opindex.");      return errmsg;    }   errmsg = cgen_parse_address (cd, strp, opindex, code,			       & result_type, & value);  if (errmsg == NULL)    {      /* We either have a relocation or a number now.  */      if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)	{	  /* We got a number back.  */	  if (code == BFD_RELOC_IP2K_HI8DATA)            value >>= 8;	  else	    /* code = BFD_RELOC_IP2K_LOW8DATA.  */	    value &= 0x00FF;	}      *valuep = value;    }   return errmsg;} static const char *parse_addr16_cjp (CGEN_CPU_DESC cd,		  const char **strp,		  int opindex,		  unsigned long *valuep){  const char *errmsg;  enum cgen_parse_operand_result result_type;  bfd_reloc_code_real_type code = BFD_RELOC_NONE;  bfd_vma value;   if (opindex == (CGEN_OPERAND_TYPE) IP2K_OPERAND_ADDR16CJP)    code = BFD_RELOC_IP2K_ADDR16CJP;  else if (opindex == (CGEN_OPERAND_TYPE) IP2K_OPERAND_ADDR16P)    code = BFD_RELOC_IP2K_PAGE3;   errmsg = cgen_parse_address (cd, strp, opindex, code,			       & result_type, & value);  if (errmsg == NULL)    {      if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)	{	  if ((value & 0x1) == 0)  /* If the address is even .... */	    {	      if (opindex == (CGEN_OPERAND_TYPE) IP2K_OPERAND_ADDR16CJP)                *valuep = (value >> 1) & 0x1FFF;  /* Should mask be 1FFF?  */	      else if (opindex == (CGEN_OPERAND_TYPE) IP2K_OPERAND_ADDR16P)                *valuep = (value >> 14) & 0x7;	    }          else 	    errmsg = _("Byte address required. - must be even.");	}      else if (result_type == CGEN_PARSE_OPERAND_RESULT_QUEUED)	{	  /* This will happen for things like (s2-s1) where s2 and s1	     are labels.  */	  *valuep = value;	}      else        errmsg = _("cgen_parse_address returned a symbol. Literal required.");    }  return errmsg;} static const char *parse_lit8 (CGEN_CPU_DESC cd,	    const char **strp,	    int opindex,	    long *valuep){  const char *errmsg;  enum cgen_parse_operand_result result_type;  bfd_reloc_code_real_type code = BFD_RELOC_NONE;  bfd_vma value;   /* Parse %OP relocating operators.  */  if (strncmp (*strp, "%bank", 5) == 0)    {      *strp += 5;      code = BFD_RELOC_IP2K_BANK;    }  else if (strncmp (*strp, "%lo8data", 8) == 0)    {      *strp += 8;      code = BFD_RELOC_IP2K_LO8DATA;    }  else if (strncmp (*strp, "%hi8data", 8) == 0)    {      *strp += 8;      code = BFD_RELOC_IP2K_HI8DATA;    }  else if (strncmp (*strp, "%ex8data", 8) == 0)    {      *strp += 8;      code = BFD_RELOC_IP2K_EX8DATA;    }  else if (strncmp (*strp, "%lo8insn", 8) == 0)    {      *strp += 8;      code = BFD_RELOC_IP2K_LO8INSN;    }  else if (strncmp (*strp, "%hi8insn", 8) == 0)    {      *strp += 8;      code = BFD_RELOC_IP2K_HI8INSN;    }   /* Parse %op operand.  */  if (code != BFD_RELOC_NONE)    {      errmsg = cgen_parse_address (cd, strp, opindex, code,				   & result_type, & value);      if ((errmsg == NULL) &&	  (result_type != CGEN_PARSE_OPERAND_RESULT_QUEUED))	errmsg = _("percent-operator operand is not a symbol");       *valuep = value;    }  /* Parse as a number.  */  else    {      errmsg = cgen_parse_signed_integer (cd, strp, opindex, valuep);       /* Truncate to eight bits to accept both signed and unsigned input.  */      if (errmsg == NULL)	*valuep &= 0xFF;    }   return errmsg;} static const char *parse_bit3 (CGEN_CPU_DESC cd,	    const char **strp,	    int opindex,	    unsigned long *valuep){  const char *errmsg;  char mode = 0;  long count = 0;  unsigned long value;   if (strncmp (*strp, "%bit", 4) == 0)    {      *strp += 4;      mode = 1;    }  else if (strncmp (*strp, "%msbbit", 7) == 0)    {      *strp += 7;      mode = 1;    }  else if (strncmp (*strp, "%lsbbit", 7) == 0)    {      *strp += 7;      mode = 2;    }   errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);  if (errmsg)    return errmsg;   if (mode)    {      value = * valuep;      if (value == 0)	{	  errmsg = _("Attempt to find bit index of 0");	  return errmsg;	}       if (mode == 1)	{	  count = 31;	  while ((value & 0x80000000) == 0)	    {	      count--;	      value <<= 1;	    }	}      else if (mode == 2)	{	  count = 0;	  while ((value & 0x00000001) == 0)	    {	      count++;	      value >>= 1;	    }	}       *valuep = count;    }   return errmsg;} /* -- dis.c */ const char * ip2k_cgen_parse_operand  (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *); /* Main entry point for operand parsing.    This function is basically just a big switch statement.  Earlier versions   used tables to look up the function to use, but   - if the table contains both assembler and disassembler functions then     the disassembler contains much of the assembler and vice-versa,   - there's a lot of inlining possibilities as things grow,   - using a switch statement avoids the function call overhead.    This function could be moved into `parse_insn_normal', but keeping it   separate makes clear the interface between `parse_insn_normal' and each of   the handlers.  */ const char *ip2k_cgen_parse_operand (CGEN_CPU_DESC cd,			   int opindex,			   const char ** strp,			   CGEN_FIELDS * fields){  const char * errmsg = NULL;  /* Used by scalar operands that still need to be parsed.  */  long junk ATTRIBUTE_UNUSED;   switch (opindex)    {    case IP2K_OPERAND_ADDR16CJP :      errmsg = parse_addr16_cjp (cd, strp, IP2K_OPERAND_ADDR16CJP, (unsigned long *) (& fields->f_addr16cjp));      break;    case IP2K_OPERAND_ADDR16H :      errmsg = parse_addr16 (cd, strp, IP2K_OPERAND_ADDR16H, (unsigned long *) (& fields->f_imm8));      break;    case IP2K_OPERAND_ADDR16L :      errmsg = parse_addr16 (cd, strp, IP2K_OPERAND_ADDR16L, (unsigned long *) (& fields->f_imm8));      break;    case IP2K_OPERAND_ADDR16P :      errmsg = parse_addr16_cjp (cd, strp, IP2K_OPERAND_ADDR16P, (unsigned long *) (& fields->f_page3));      break;    case IP2K_OPERAND_BITNO :      errmsg = parse_bit3 (cd, strp, IP2K_OPERAND_BITNO, (unsigned long *) (& fields->f_bitno));      break;    case IP2K_OPERAND_CBIT :      errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_CBIT, (unsigned long *) (& junk));      break;    case IP2K_OPERAND_DCBIT :      errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_DCBIT, (unsigned long *) (& junk));      break;    case IP2K_OPERAND_FR :      errmsg = parse_fr (cd, strp, IP2K_OPERAND_FR, (unsigned long *) (& fields->f_reg));      break;    case IP2K_OPERAND_LIT8 :      errmsg = parse_lit8 (cd, strp, IP2K_OPERAND_LIT8, (long *) (& fields->f_imm8));      break;    case IP2K_OPERAND_PABITS :      errmsg = cgen_parse_unsigned_integer (cd, strp, IP2K_OPERAND_PABITS, (unsigned long *) (& junk));

Lines 1–500 of 921.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t