123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- /* OpenRISC 1000 opcode support. -*- C -*-
- Copyright 2000-2014 Free Software Foundation, Inc.
- Originally ontributed for OR32 by Red Hat Inc;
- This file is part of the GNU Binutils.
- This program 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 of the License, or
- (at your option) any later version.
- This program 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, see <http://www.gnu.org/licenses/>. */
- /* This file is an addendum to or1k.cpu. Heavy use of C code isn't
- appropriate in .cpu files, so it resides here. This especially applies
- to assembly/disassembly where parsing/printing can be quite involved.
- Such things aren't really part of the specification of the cpu, per se,
- so .cpu files provide the general framework and .opc files handle the
- nitty-gritty details as necessary.
- Each section is delimited with start and end markers.
- <arch>-opc.h additions use: "-- opc.h"
- <arch>-opc.c additions use: "-- opc.c"
- <arch>-asm.c additions use: "-- asm.c"
- <arch>-dis.c additions use: "-- dis.c"
- <arch>-ibd.h additions use: "-- ibd.h" */
- /* -- opc.h */
- #undef CGEN_DIS_HASH_SIZE
- #define CGEN_DIS_HASH_SIZE 256
- #undef CGEN_DIS_HASH
- #define CGEN_DIS_HASH(buffer, value) (((unsigned char *) (buffer))[0] >> 2)
- /* -- */
- /* -- opc.c */
- /* -- */
- /* -- asm.c */
- static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'");
- #define CGEN_VERBOSE_ASSEMBLER_ERRORS
- static const char *
- parse_disp26 (CGEN_CPU_DESC cd,
- const char ** strp,
- int opindex,
- int opinfo,
- enum cgen_parse_operand_result * resultp,
- bfd_vma * valuep)
- {
- const char *errmsg = NULL;
- enum cgen_parse_operand_result result_type;
- if (strncasecmp (*strp, "plt(", 4) == 0)
- {
- bfd_vma value;
- *strp += 4;
- errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_OR1K_PLT26,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 2) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- return cgen_parse_address (cd, strp, opindex, opinfo, resultp, valuep);
- }
- static const char *
- parse_simm16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, long * valuep)
- {
- const char *errmsg;
- enum cgen_parse_operand_result result_type;
- long ret;
- if (**strp == '#')
- ++*strp;
- if (strncasecmp (*strp, "hi(", 3) == 0)
- {
- bfd_vma value;
- *strp += 3;
- errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
- & result_type, & value);
- if (**strp != ')')
- errmsg = MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- ret = value;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- {
- ret >>= 16;
- ret &= 0xffff;
- ret = (ret ^ 0x8000) - 0x8000;
- }
- }
- else if (strncasecmp (*strp, "lo(", 3) == 0)
- {
- bfd_vma value;
- *strp += 3;
- errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- ret = value;
- if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- {
- ret &= 0xffff;
- ret = (ret ^ 0x8000) - 0x8000;
- }
- }
- else if (strncasecmp (*strp, "got(", 4) == 0)
- {
- bfd_vma value;
- *strp += 4;
- errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_OR1K_GOT16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "gotpchi(", 8) == 0)
- {
- bfd_vma value;
- *strp += 8;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_GOTPC_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "gotpclo(", 8) == 0)
- {
- bfd_vma value;
- *strp += 8;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_GOTPC_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "gotoffhi(", 9) == 0)
- {
- bfd_vma value;
- *strp += 9;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_GOTOFF_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "gotofflo(", 9) == 0)
- {
- bfd_vma value;
- *strp += 9;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_GOTOFF_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "tlsgdhi(", 8) == 0)
- {
- bfd_vma value;
- *strp += 8;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_GD_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "tlsgdlo(", 8) == 0)
- {
- bfd_vma value;
- *strp += 8;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_GD_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "tlsldmhi(", 9) == 0)
- {
- bfd_vma value;
- *strp += 9;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_LDM_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "tlsldmlo(", 9) == 0)
- {
- bfd_vma value;
- *strp += 9;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_LDM_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "dtpoffhi(", 9) == 0)
- {
- bfd_vma value;
- *strp += 9;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_LDO_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "dtpofflo(", 9) == 0)
- {
- bfd_vma value;
- *strp += 9;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_LDO_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "gottpoffhi(", 11) == 0)
- {
- bfd_vma value;
- *strp += 11;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_IE_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "gottpofflo(", 11) == 0)
- {
- bfd_vma value;
- *strp += 11;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_IE_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "tpoffhi(", 8) == 0)
- {
- bfd_vma value;
- *strp += 8;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_LE_HI16,
- & result_type, & value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value = (value >> 16) & 0xffff;
- *valuep = value;
- return errmsg;
- }
- else if (strncasecmp (*strp, "tpofflo(", 8) == 0)
- {
- bfd_vma value;
- *strp += 8;
- errmsg = cgen_parse_address (cd, strp, opindex,
- BFD_RELOC_OR1K_TLS_LE_LO16,
- &result_type, &value);
- if (**strp != ')')
- return MISSING_CLOSING_PARENTHESIS;
- ++*strp;
- if (errmsg == NULL
- && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
- value &= 0xffff;
- *valuep = value;
- return errmsg;
- }
- else
- {
- long value;
- errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
- ret = value;
- }
- if (errmsg == NULL)
- *valuep = ret;
- return errmsg;
- }
- static const char *
- parse_uimm16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, unsigned long * valuep)
- {
- const char *errmsg = parse_simm16(cd, strp, opindex, (long *) valuep);
- if (errmsg == NULL)
- *valuep &= 0xffff;
- return errmsg;
- }
- /* -- */
- /* -- ibd.h */
- /* -- */
|