* frv.opc (parse_uhi16): Fix handling of %hi operator on 64-bit
[deliverable/binutils-gdb.git] / cpu / openrisc.opc
CommitLineData
dc15e575
NC
1/* OpenRISC opcode support. -*- C -*-
2 Copyright 2000, 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
3
4 Contributed by Red Hat Inc;
5
6 This file is part of the GNU Binutils.
7
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.
12
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.
17
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. */
22
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.
29
30 Each section is delimited with start and end markers.
31
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" */
37
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)
43
44extern long openrisc_sign_extend_16bit (long);
45/* -- */
46
47/* -- opc.c */
48/* -- */
49
50/* -- asm.c */
51
52static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'");
53
54#define CGEN_VERBOSE_ASSEMBLER_ERRORS
55
56long
57openrisc_sign_extend_16bit (long value)
58{
59 return ((value & 0xffff) ^ 0x8000) - 0x8000;
60}
61
62/* Handle hi(). */
63
64static const char *
65parse_hi16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, long * valuep)
66{
67 const char *errmsg;
68 enum cgen_parse_operand_result result_type;
69 unsigned long ret;
70
71 if (**strp == '#')
72 ++*strp;
73
74 if (strncasecmp (*strp, "hi(", 3) == 0)
75 {
76 bfd_vma value;
77
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;
83
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;
95
96 errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
97 ret = value;
98 }
99 else
100 {
101 unsigned long value;
102
103 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, &value);
104 ret = value;
105 }
106 }
107
108 *valuep = ((ret & 0xffff) ^ 0x8000) - 0x8000;
109 return errmsg;
110}
111
112/* Handle lo(). */
113
114static const char *
115parse_lo16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, long * valuep)
116{
117 const char *errmsg;
118 enum cgen_parse_operand_result result_type;
119 unsigned long ret;
120
121 if (**strp == '#')
122 ++*strp;
123
124 if (strncasecmp (*strp, "lo(", 3) == 0)
125 {
126 bfd_vma value;
127
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;
133
134 ++*strp;
135 ret = value;
136 }
137 else
138 {
139 if (**strp == '-')
140 {
141 long value;
142
143 errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
144 ret = value;
145 }
146 else
147 {
148 unsigned long value;
149
150 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, &value);
151 ret = value;
152 }
153 }
154
155 *valuep = ((ret & 0xffff) ^ 0x8000) - 0x8000;
156 return errmsg;
157}
158
159/* -- */
160
161/* -- ibd.h */
162extern long openrisc_sign_extend_16bit (long);
163
164/* -- */
This page took 0.03795 seconds and 4 git commands to generate.