1 /* SPARC opcode support. -*- C -*-
2 Copyright (C) 2000 Red Hat, Inc.
3 This file is part of CGEN.
4 This file is copyrighted with the GNU General Public License.
5 See file COPYING for details. */
7 /* This file is an addendum to sparc.cpu. Heavy use of C code isn't
8 appropriate in .cpu files, so it resides here. This especially applies
9 to assembly/disassembly where parsing/printing can be quite involved.
10 Such things aren't really part of the specification of the cpu, per se,
11 so .cpu files provide the general framework and .opc files handle the
12 nitty-gritty details as necessary.
14 Each section is delimited with start and end markers.
16 <cpu>-opc.h additions use: "-- opc.h"
17 <cpu>-opc.c additions use: "-- opc.c"
18 <cpu>-asm.c additions use: "-- asm.c"
19 <cpu>-dis.c additions use: "-- dis.c"
24 #undef CGEN_DIS_HASH_SIZE
25 #define CGEN_DIS_HASH_SIZE 256
27 extern const unsigned int sparc_cgen_opcode_bits[];
28 #define CGEN_DIS_HASH(buffer, insn) \
29 ((((insn) >> 24) & 0xc0) \
30 | (((insn) & sparc_cgen_opcode_bits[((insn) >> 30) & 3]) >> 19))
36 /* It is important that we only look at insn code bits as that is how the
37 opcode table is hashed. OPCODE_BITS is a table of valid bits for each
38 of the main types (0,1,2,3). */
39 const unsigned int sparc_cgen_opcode_bits[4] = {
40 0x01c00000, 0x0, 0x01f80000, 0x01f80000
46 parse_lo10 (cd, strp, opindex, valuep)
53 enum cgen_parse_operand_result result_type;
56 if (strncasecmp (*strp, "%lo(", 4) == 0)
59 errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_LO10,
60 &result_type, &value);
69 return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
73 parse_lo13 (cd, strp, opindex, valuep)
80 enum cgen_parse_operand_result result_type;
83 if (strncasecmp (*strp, "%lo(", 4) == 0)
86 errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_LO10,
87 &result_type, &value);
96 return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
102 parse_hi22 (cd, strp, opindex, valuep)
106 unsigned long *valuep;
109 enum cgen_parse_operand_result result_type;
112 if (strncasecmp (*strp, "%hi(", 4) == 0)
115 errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_HI22,
116 &result_type, &value);
118 return "missing `)'";
120 if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
126 return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
133 /* Include "%hi(foo)" in sethi output. */
136 print_hi22 (cd, dis_info, value, attrs, pc, length)
144 disassemble_info *info = (disassemble_info *) dis_info;
145 (*info->fprintf_func) (info->stream, "%%hi(0x%lx)", value << 10);
148 #undef CGEN_PRINT_INSN
149 #define CGEN_PRINT_INSN my_print_insn
152 my_print_insn (cd, pc, info)
155 disassemble_info *info;
157 char buffer[CGEN_MAX_INSN_SIZE];
160 unsigned long insn_value;
163 /* Read the base part of the insn. */
165 status = (*info->read_memory_func) (pc, buf, 4, info);
168 (*info->memory_error_func) (status, pc, info);
172 len = print_insn (od, pc, info, buf, 4);
176 /* CGEN doesn't handle this insn yet. Fall back on old way. */
177 return old_print_insn_sparc (pc, info);