* elf32-spu.c (build_stub): Fix malloc under-allocation.
[binutils.git] / cpu / openrisc.opc
blob291be5102116577fa259745caa77456049dc2cc5
1 /* OpenRISC opcode support.  -*- C -*-
2    Copyright 2000, 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
4    Contributed by Red Hat Inc;
6    This file is part of the GNU Binutils.
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21    MA 02110-1301, USA.  */
23 /* This file is an addendum to or32.cpu.  Heavy use of C code isn't
24    appropriate in .cpu files, so it resides here.  This especially applies
25    to assembly/disassembly where parsing/printing can be quite involved.
26    Such things aren't really part of the specification of the cpu, per se,
27    so .cpu files provide the general framework and .opc files handle the
28    nitty-gritty details as necessary.
30    Each section is delimited with start and end markers.
32    <arch>-opc.h additions use: "-- opc.h"
33    <arch>-opc.c additions use: "-- opc.c"
34    <arch>-asm.c additions use: "-- asm.c"
35    <arch>-dis.c additions use: "-- dis.c"
36    <arch>-ibd.h additions use: "-- ibd.h"  */
38 /* -- opc.h */
39 #undef  CGEN_DIS_HASH_SIZE
40 #define CGEN_DIS_HASH_SIZE 64
41 #undef  CGEN_DIS_HASH
42 #define CGEN_DIS_HASH(buffer, value) (((unsigned char *) (buffer))[0] >> 2)
44 extern long openrisc_sign_extend_16bit (long);
45 /* -- */
47 /* -- opc.c */
48 /* -- */
50 /* -- asm.c */
52 static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'");
54 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
56 long
57 openrisc_sign_extend_16bit (long value)
59   return ((value & 0xffff) ^ 0x8000) - 0x8000;
62 /* Handle hi().  */
64 static const char *
65 parse_hi16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, long * valuep)
67   const char *errmsg;
68   enum cgen_parse_operand_result result_type;
69   unsigned long ret;
71   if (**strp == '#')
72     ++*strp;
74   if (strncasecmp (*strp, "hi(", 3) == 0)
75     {
76       bfd_vma value;
78       *strp += 3;
79       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
80                                    & result_type, & value);
81       if (**strp != ')')
82         return MISSING_CLOSING_PARENTHESIS;
84       ++*strp;
85       if (errmsg == NULL
86           && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
87         value >>= 16;
88       ret = value;
89     }
90   else
91     {
92       if (**strp == '-')
93         {
94           long value;
96           errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
97           ret = value;
98         }
99       else
100         {
101           unsigned long value;
103           errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, &value);
104           ret = value;
105         }
106     }
108   *valuep = ((ret & 0xffff) ^ 0x8000) - 0x8000;
109   return errmsg;
112 /* Handle lo().  */
114 static const char *
115 parse_lo16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, long * valuep)
117   const char *errmsg;
118   enum cgen_parse_operand_result result_type;
119   unsigned long ret;
121   if (**strp == '#')
122     ++*strp;
124   if (strncasecmp (*strp, "lo(", 3) == 0)
125     {
126       bfd_vma value;
128       *strp += 3;
129       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
130                                    & result_type, & value);
131       if (**strp != ')')
132         return MISSING_CLOSING_PARENTHESIS;
134       ++*strp;
135       ret = value;
136     }
137   else
138     {
139       if (**strp == '-')
140         {
141           long value;
143           errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
144           ret = value;
145         }
146       else
147         {
148           unsigned long value;
150           errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, &value);
151           ret = value;
152         }
153     }
155   *valuep = ((ret & 0xffff) ^ 0x8000) - 0x8000;
156   return errmsg;
159 /* -- */
161 /* -- ibd.h */
162 extern long openrisc_sign_extend_16bit (long);
164 /* -- */