* cgen-opc.in: New file.
[deliverable/binutils-gdb.git] / opcodes / cgen-opc.in
1 /* Generic opcode table support for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
3
4 This file is used to generate @arch@-opc.c.
5
6 Copyright (C) 1998 Free Software Foundation, Inc.
7
8 This file is part of the GNU Binutils and GDB, the GNU debugger.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
24 #include "sysdep.h"
25 #include <stdio.h>
26 #include "ansidecl.h"
27 #include "libiberty.h"
28 #include "bfd.h"
29 #include "symcat.h"
30 #include "@arch@-opc.h"
31
32 /* Look up instruction INSN_VALUE and extract its fields.
33 If non-null INSN is the insn table entry.
34 Otherwise INSN_VALUE is examined to compute it.
35 LENGTH is the bit length of INSN_VALUE if known, otherwise 0.
36 The result a pointer to the insn table entry, or NULL if the instruction
37 wasn't recognized. */
38
39 const CGEN_INSN *
40 @arch@_cgen_lookup_insn (insn, insn_value, length, fields)
41 const CGEN_INSN *insn;
42 cgen_insn_t insn_value;
43 int length;
44 CGEN_FIELDS *fields;
45 {
46 char buf[4];
47
48 if (!insn)
49 {
50 const CGEN_INSN_LIST *insn_list;
51
52 #ifdef CGEN_INT_INSN
53 switch (length)
54 {
55 case 8:
56 buf[0] = insn_value;
57 break;
58 case 16:
59 if (cgen_current_endian == CGEN_ENDIAN_BIG)
60 bfd_putb16 (insn_value, buf);
61 else
62 bfd_putl16 (insn_value, buf);
63 break;
64 case 32:
65 if (cgen_current_endian == CGEN_ENDIAN_BIG)
66 bfd_putb32 (insn_value, buf);
67 else
68 bfd_putl32 (insn_value, buf);
69 break;
70 default:
71 abort ();
72 }
73 #else
74 abort (); /* FIXME: unfinished */
75 #endif
76
77 /* The instructions are stored in hash lists.
78 Pick the first one and keep trying until we find the right one. */
79
80 insn_list = CGEN_DIS_LOOKUP_INSN (buf, insn_value);
81 while (insn_list != NULL)
82 {
83 insn = insn_list->insn;
84
85 /* Basic bit mask must be correct. */
86 /* ??? May wish to allow target to defer this check until the extract
87 handler. */
88 if ((insn_value & CGEN_INSN_MASK (insn)) == CGEN_INSN_VALUE (insn))
89 {
90 length = (*CGEN_EXTRACT_FN (insn)) (insn, NULL, insn_value, fields);
91 if (length > 0)
92 return insn;
93 }
94
95 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
96 }
97 }
98 else
99 {
100 length = (*CGEN_EXTRACT_FN (insn)) (insn, NULL, insn_value, fields);
101 if (length > 0)
102 return insn;
103 }
104
105 return NULL;
106 }
107
108 /* Fill in the operand instances used by insn INSN_VALUE.
109 If non-null INS is the insn table entry.
110 Otherwise INSN_VALUE is examined to compute it.
111 LENGTH is the number of bits in INSN_VALUE if known, otherwise 0.
112 INDICES is a pointer to a buffer of MAX_OPERANDS ints to be filled in.
113 The result a pointer to the insn table entry, or NULL if the instruction
114 wasn't recognized. */
115
116 const CGEN_INSN *
117 @arch@_cgen_get_insn_operands (insn, insn_value, length, indices)
118 const CGEN_INSN *insn;
119 cgen_insn_t insn_value;
120 int length;
121 int *indices;
122 {
123 CGEN_FIELDS fields;
124 const CGEN_OPERAND_INSTANCE *opinst;
125 int i;
126
127 insn = @arch@_cgen_lookup_insn (insn, insn_value, length, &fields);
128 if (! insn)
129 return NULL;
130
131 for (i = 0, opinst = CGEN_INSN_OPERANDS (insn);
132 CGEN_OPERAND_INSTANCE_TYPE (opinst) != CGEN_OPERAND_INSTANCE_END;
133 ++i, ++opinst)
134 {
135 const CGEN_OPERAND *op = CGEN_OPERAND_INSTANCE_OPERAND (opinst);
136 if (op == NULL)
137 indices[i] = CGEN_OPERAND_INSTANCE_INDEX (opinst);
138 else
139 indices[i] = @arch@_cgen_get_operand (CGEN_OPERAND_INDEX (op), &fields);
140 }
141
142 return insn;
143 }
This page took 0.042875 seconds and 5 git commands to generate.