1 /* OpenRISC 1000 opcode support. -*- C -*-
2 Copyright 2000-2014 Free Software Foundation, Inc.
4 Originally ontributed for OR32 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, see <http://www.gnu.org/licenses/>. */
21 /* This file is an addendum to or1k.cpu. Heavy use of C code isn't
22 appropriate in .cpu files, so it resides here. This especially applies
23 to assembly/disassembly where parsing/printing can be quite involved.
24 Such things aren't really part of the specification of the cpu, per se,
25 so .cpu files provide the general framework and .opc files handle the
26 nitty-gritty details as necessary.
28 Each section is delimited with start and end markers.
30 <arch>-opc.h additions use: "-- opc.h"
31 <arch>-opc.c additions use: "-- opc.c"
32 <arch>-asm.c additions use: "-- asm.c"
33 <arch>-dis.c additions use: "-- dis.c"
34 <arch>-ibd.h additions use: "-- ibd.h" */
38 #undef CGEN_DIS_HASH_SIZE
39 #define CGEN_DIS_HASH_SIZE 256
41 #define CGEN_DIS_HASH(buffer, value) (((unsigned char *) (buffer))[0] >> 2)
50 static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'");
52 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
55 parse_disp26 (CGEN_CPU_DESC cd,
59 enum cgen_parse_operand_result * resultp,
62 const char *errmsg = NULL;
63 enum cgen_parse_operand_result result_type;
65 if (strncasecmp (*strp, "plt(", 4) == 0)
70 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_OR1K_PLT26,
71 & result_type, & value);
73 return MISSING_CLOSING_PARENTHESIS;
76 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
77 value = (value >> 2) & 0xffff;
81 return cgen_parse_address (cd, strp, opindex, opinfo, resultp, valuep);
85 parse_simm16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, long * valuep)
88 enum cgen_parse_operand_result result_type;
94 if (strncasecmp (*strp, "hi(", 3) == 0)
99 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
100 & result_type, & value);
102 errmsg = MISSING_CLOSING_PARENTHESIS;
108 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
112 ret = (ret ^ 0x8000) - 0x8000;
115 else if (strncasecmp (*strp, "lo(", 3) == 0)
120 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
121 & result_type, & value);
123 return MISSING_CLOSING_PARENTHESIS;
128 if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
131 ret = (ret ^ 0x8000) - 0x8000;
134 else if (strncasecmp (*strp, "got(", 4) == 0)
139 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_OR1K_GOT16,
140 & result_type, & value);
142 return MISSING_CLOSING_PARENTHESIS;
145 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
150 else if (strncasecmp (*strp, "gotpchi(", 8) == 0)
155 errmsg = cgen_parse_address (cd, strp, opindex,
156 BFD_RELOC_OR1K_GOTPC_HI16,
157 & result_type, & value);
159 return MISSING_CLOSING_PARENTHESIS;
162 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
163 value = (value >> 16) & 0xffff;
167 else if (strncasecmp (*strp, "gotpclo(", 8) == 0)
172 errmsg = cgen_parse_address (cd, strp, opindex,
173 BFD_RELOC_OR1K_GOTPC_LO16,
174 &result_type, &value);
176 return MISSING_CLOSING_PARENTHESIS;
179 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
184 else if (strncasecmp (*strp, "gotoffhi(", 9) == 0)
189 errmsg = cgen_parse_address (cd, strp, opindex,
190 BFD_RELOC_OR1K_GOTOFF_HI16,
191 & result_type, & value);
194 return MISSING_CLOSING_PARENTHESIS;
197 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
198 value = (value >> 16) & 0xffff;
202 else if (strncasecmp (*strp, "gotofflo(", 9) == 0)
207 errmsg = cgen_parse_address (cd, strp, opindex,
208 BFD_RELOC_OR1K_GOTOFF_LO16,
209 &result_type, &value);
211 return MISSING_CLOSING_PARENTHESIS;
214 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
219 else if (strncasecmp (*strp, "tlsgdhi(", 8) == 0)
224 errmsg = cgen_parse_address (cd, strp, opindex,
225 BFD_RELOC_OR1K_TLS_GD_HI16,
226 & result_type, & value);
229 return MISSING_CLOSING_PARENTHESIS;
232 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
233 value = (value >> 16) & 0xffff;
237 else if (strncasecmp (*strp, "tlsgdlo(", 8) == 0)
242 errmsg = cgen_parse_address (cd, strp, opindex,
243 BFD_RELOC_OR1K_TLS_GD_LO16,
244 &result_type, &value);
246 return MISSING_CLOSING_PARENTHESIS;
249 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
254 else if (strncasecmp (*strp, "tlsldmhi(", 9) == 0)
259 errmsg = cgen_parse_address (cd, strp, opindex,
260 BFD_RELOC_OR1K_TLS_LDM_HI16,
261 & result_type, & value);
264 return MISSING_CLOSING_PARENTHESIS;
267 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
268 value = (value >> 16) & 0xffff;
272 else if (strncasecmp (*strp, "tlsldmlo(", 9) == 0)
277 errmsg = cgen_parse_address (cd, strp, opindex,
278 BFD_RELOC_OR1K_TLS_LDM_LO16,
279 &result_type, &value);
281 return MISSING_CLOSING_PARENTHESIS;
284 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
289 else if (strncasecmp (*strp, "dtpoffhi(", 9) == 0)
294 errmsg = cgen_parse_address (cd, strp, opindex,
295 BFD_RELOC_OR1K_TLS_LDO_HI16,
296 & result_type, & value);
299 return MISSING_CLOSING_PARENTHESIS;
302 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
303 value = (value >> 16) & 0xffff;
307 else if (strncasecmp (*strp, "dtpofflo(", 9) == 0)
312 errmsg = cgen_parse_address (cd, strp, opindex,
313 BFD_RELOC_OR1K_TLS_LDO_LO16,
314 &result_type, &value);
316 return MISSING_CLOSING_PARENTHESIS;
319 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
324 else if (strncasecmp (*strp, "gottpoffhi(", 11) == 0)
329 errmsg = cgen_parse_address (cd, strp, opindex,
330 BFD_RELOC_OR1K_TLS_IE_HI16,
331 & result_type, & value);
334 return MISSING_CLOSING_PARENTHESIS;
337 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
338 value = (value >> 16) & 0xffff;
342 else if (strncasecmp (*strp, "gottpofflo(", 11) == 0)
347 errmsg = cgen_parse_address (cd, strp, opindex,
348 BFD_RELOC_OR1K_TLS_IE_LO16,
349 &result_type, &value);
351 return MISSING_CLOSING_PARENTHESIS;
354 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
359 else if (strncasecmp (*strp, "tpoffhi(", 8) == 0)
364 errmsg = cgen_parse_address (cd, strp, opindex,
365 BFD_RELOC_OR1K_TLS_LE_HI16,
366 & result_type, & value);
369 return MISSING_CLOSING_PARENTHESIS;
372 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
373 value = (value >> 16) & 0xffff;
377 else if (strncasecmp (*strp, "tpofflo(", 8) == 0)
382 errmsg = cgen_parse_address (cd, strp, opindex,
383 BFD_RELOC_OR1K_TLS_LE_LO16,
384 &result_type, &value);
386 return MISSING_CLOSING_PARENTHESIS;
389 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
397 errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
408 parse_uimm16 (CGEN_CPU_DESC cd, const char ** strp, int opindex, unsigned long * valuep)
410 const char *errmsg = parse_simm16(cd, strp, opindex, (long *) valuep);