1/* Internal definitions for configurable Xtensa ISA support.
2   Copyright 2003, 2004 Free Software Foundation, Inc.
3
4   This file is part of BFD, the Binary File Descriptor library.
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2 of the License, or
9   (at your option) any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20#ifndef XTENSA_ISA_INTERNAL_H
21#define XTENSA_ISA_INTERNAL_H
22
23/* Flags.  */
24
25#define XTENSA_OPERAND_IS_REGISTER	0x00000001
26#define XTENSA_OPERAND_IS_PCRELATIVE	0x00000002
27#define XTENSA_OPERAND_IS_INVISIBLE	0x00000004
28#define XTENSA_OPERAND_IS_UNKNOWN	0x00000008
29
30#define XTENSA_OPCODE_IS_BRANCH		0x00000001
31#define XTENSA_OPCODE_IS_JUMP		0x00000002
32#define XTENSA_OPCODE_IS_LOOP		0x00000004
33#define XTENSA_OPCODE_IS_CALL		0x00000008
34
35#define XTENSA_STATE_IS_EXPORTED	0x00000001
36
37#define XTENSA_INTERFACE_HAS_SIDE_EFFECT 0x00000001
38
39/* Function pointer typedefs */
40typedef void (*xtensa_format_encode_fn) (xtensa_insnbuf);
41typedef void (*xtensa_get_slot_fn) (const xtensa_insnbuf, xtensa_insnbuf);
42typedef void (*xtensa_set_slot_fn) (xtensa_insnbuf, const xtensa_insnbuf);
43typedef int (*xtensa_opcode_decode_fn) (const xtensa_insnbuf);
44typedef uint32 (*xtensa_get_field_fn) (const xtensa_insnbuf);
45typedef void (*xtensa_set_field_fn) (xtensa_insnbuf, uint32);
46typedef int (*xtensa_immed_decode_fn) (uint32 *);
47typedef int (*xtensa_immed_encode_fn) (uint32 *);
48typedef int (*xtensa_do_reloc_fn) (uint32 *, uint32);
49typedef int (*xtensa_undo_reloc_fn) (uint32 *, uint32);
50typedef void (*xtensa_opcode_encode_fn) (xtensa_insnbuf);
51typedef int (*xtensa_format_decode_fn) (const xtensa_insnbuf);
52typedef int (*xtensa_length_decode_fn) (const char *);
53
54typedef struct xtensa_format_internal_struct
55{
56  const char *name;			/* Instruction format name.  */
57  int length;				/* Instruction length in bytes.  */
58  xtensa_format_encode_fn encode_fn;
59  int num_slots;
60  int *slot_id;				/* Array[num_slots] of slot IDs.  */
61} xtensa_format_internal;
62
63typedef struct xtensa_slot_internal_struct
64{
65  const char *name;			/* Not necessarily unique.  */
66  const char *format;
67  int position;
68  xtensa_get_slot_fn get_fn;
69  xtensa_set_slot_fn set_fn;
70  xtensa_get_field_fn *get_field_fns;	/* Array[field_id].  */
71  xtensa_set_field_fn *set_field_fns;	/* Array[field_id].  */
72  xtensa_opcode_decode_fn opcode_decode_fn;
73  const char *nop_name;
74} xtensa_slot_internal;
75
76typedef struct xtensa_operand_internal_struct
77{
78  const char *name;
79  int field_id;
80  xtensa_regfile regfile;		/* Register file.  */
81  int num_regs;				/* Usually 1; 2 for reg pairs, etc.  */
82  uint32 flags;				/* See XTENSA_OPERAND_* flags.  */
83  xtensa_immed_encode_fn encode;	/* Encode the operand value.  */
84  xtensa_immed_decode_fn decode;	/* Decode the value from the field.  */
85  xtensa_do_reloc_fn do_reloc;		/* Perform a PC-relative reloc.  */
86  xtensa_undo_reloc_fn undo_reloc;	/* Undo a PC-relative relocation.  */
87} xtensa_operand_internal;
88
89typedef struct xtensa_arg_internal_struct
90{
91  union {
92    int operand_id;			/* For normal operands.  */
93    xtensa_state state;			/* For stateOperands.  */
94  } u;
95  char inout;				/* Direction: 'i', 'o', or 'm'.  */
96} xtensa_arg_internal;
97
98typedef struct xtensa_iclass_internal_struct
99{
100  int num_operands;			/* Size of "operands" array.  */
101  xtensa_arg_internal *operands;	/* Array[num_operands].  */
102
103  int num_stateOperands;		/* Size of "stateOperands" array.  */
104  xtensa_arg_internal *stateOperands;	/* Array[num_stateOperands].  */
105
106  int num_interfaceOperands;		/* Size of "interfaceOperands".  */
107  xtensa_interface *interfaceOperands;	/* Array[num_interfaceOperands].  */
108} xtensa_iclass_internal;
109
110typedef struct xtensa_opcode_internal_struct
111{
112  const char *name;			/* Opcode mnemonic.  */
113  int iclass_id;			/* Iclass for this opcode.  */
114  uint32 flags;				/* See XTENSA_OPCODE_* flags.  */
115  xtensa_opcode_encode_fn *encode_fns;	/* Array[slot_id].  */
116  int num_funcUnit_uses;		/* Number of funcUnit_use entries.  */
117  xtensa_funcUnit_use *funcUnit_uses;	/* Array[num_funcUnit_uses].  */
118} xtensa_opcode_internal;
119
120typedef struct xtensa_regfile_internal_struct
121{
122  const char *name;			/* Full name of the regfile.  */
123  const char *shortname;		/* Abbreviated name.  */
124  xtensa_regfile parent;		/* View parent (or identity).  */
125  int num_bits;				/* Width of the registers.  */
126  int num_entries;			/* Number of registers.  */
127} xtensa_regfile_internal;
128
129typedef struct xtensa_interface_internal_struct
130{
131  const char *name;			/* Interface name.  */
132  int num_bits;				/* Width of the interface.  */
133  uint32 flags;				/* See XTENSA_INTERFACE_* flags.  */
134  char inout;				/* "i" or "o".  */
135} xtensa_interface_internal;
136
137typedef struct xtensa_funcUnit_internal_struct
138{
139  const char *name;			/* Functional unit name.  */
140  int num_copies;			/* Number of instances.  */
141} xtensa_funcUnit_internal;
142
143typedef struct xtensa_state_internal_struct
144{
145  const char *name;			/* State name.  */
146  int num_bits;				/* Number of state bits.  */
147  uint32 flags;				/* See XTENSA_STATE_* flags.  */
148} xtensa_state_internal;
149
150typedef struct xtensa_sysreg_internal_struct
151{
152  const char *name;			/* Register name.  */
153  int number;				/* Register number.  */
154  int is_user;				/* Non-zero if a "user register".  */
155} xtensa_sysreg_internal;
156
157typedef struct xtensa_lookup_entry_struct
158{
159  const char *key;
160  union
161  {
162    xtensa_opcode opcode;		/* Internal opcode number.  */
163    xtensa_sysreg sysreg;		/* Internal sysreg number.  */
164    xtensa_state state;			/* Internal state number.  */
165    xtensa_interface intf;		/* Internal interface number.  */
166    xtensa_funcUnit fun;		/* Internal funcUnit number.  */
167  } u;
168} xtensa_lookup_entry;
169
170typedef struct xtensa_isa_internal_struct
171{
172  int is_big_endian;			/* Endianness.  */
173  int insn_size;			/* Maximum length in bytes.  */
174  int insnbuf_size;			/* Number of insnbuf_words.  */
175
176  int num_formats;
177  xtensa_format_internal *formats;
178  xtensa_format_decode_fn format_decode_fn;
179  xtensa_length_decode_fn length_decode_fn;
180
181  int num_slots;
182  xtensa_slot_internal *slots;
183
184  int num_fields;
185
186  int num_operands;
187  xtensa_operand_internal *operands;
188
189  int num_iclasses;
190  xtensa_iclass_internal *iclasses;
191
192  int num_opcodes;
193  xtensa_opcode_internal *opcodes;
194  xtensa_lookup_entry *opname_lookup_table;
195
196  int num_regfiles;
197  xtensa_regfile_internal *regfiles;
198
199  int num_states;
200  xtensa_state_internal *states;
201  xtensa_lookup_entry *state_lookup_table;
202
203  int num_sysregs;
204  xtensa_sysreg_internal *sysregs;
205  xtensa_lookup_entry *sysreg_lookup_table;
206
207  /* The current Xtensa ISA only supports 256 of each kind of sysreg so
208     we can get away with implementing lookups with tables indexed by
209     the register numbers.  If we ever allow larger sysreg numbers, this
210     may have to be reimplemented.  The first entry in the following
211     arrays corresponds to "special" registers and the second to "user"
212     registers.  */
213  int max_sysreg_num[2];
214  xtensa_sysreg *sysreg_table[2];
215
216  int num_interfaces;
217  xtensa_interface_internal *interfaces;
218  xtensa_lookup_entry *interface_lookup_table;
219
220  int num_funcUnits;
221  xtensa_funcUnit_internal *funcUnits;
222  xtensa_lookup_entry *funcUnit_lookup_table;
223
224} xtensa_isa_internal;
225
226extern int xtensa_isa_name_compare (const void *, const void *);
227
228extern xtensa_isa_status xtisa_errno;
229extern char xtisa_error_msg[];
230
231#endif /* !XTENSA_ISA_INTERNAL_H */
232