aboutsummaryrefslogtreecommitdiff
path: root/sim/ppc/ld-insn.h
blob: 52baeaa2d846c30e1df1d10138c4b5fc7955ca5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*  This file is part of the program psim.

    Copyright 1994, 1995, 1996, 2003 Andrew Cagney

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 
    */

/*
#   --
#
#
# Fields:
#
#	1	Instruction format as a `start-bit,content' pairs.
#		the content is one of a digit, field name or `/' (aka.0)
#
#	2	Format specifier
#
#	3	Flags:	64 - 64bit only
#			f - floating point enabled required
#
#	4 	short name
#
#	5	Description
#
#
# For flags marked 'model', the fields are interpreted as follows:
#
#	1	Not used
#
#	2	Not used
#
#	3	"macro"
#
#	4	String name for model
#
#	5	Specific CPU model, must be an identifier
#
#	6	Comma separated list of functional units

*/


/* Global constants */

enum {
  max_insn_bit_size = 32,
};


typedef struct _insn_field insn_field;
struct _insn_field {
  int first;
  int last;
  int width;
  int is_int;
  int is_slash;
  int is_string;
  int val_int;
  char *pos_string;
  char *val_string;
  insn_field *next;
  insn_field *prev;
};

typedef struct _insn_fields insn_fields;
struct _insn_fields {
  insn_field *bits[max_insn_bit_size];
  insn_field *first;
  insn_field *last;
  unsigned value;
};


/****************************************************************/

typedef struct _opcode_field opcode_field;
struct _opcode_field {
  int first;
  int last;
  int is_boolean;
  unsigned boolean_constant;
  opcode_field *parent;
};


/****************************************************************/

typedef struct _insn_bits insn_bits;
struct _insn_bits {
  int is_expanded;
  int value;
  insn_field *field;
  opcode_field *opcode;
  insn_bits *last;
};


/****************************************************************/


typedef enum {
  insn_format,
  insn_form,
  insn_flags,
  insn_mnemonic,
  insn_name,
  insn_comment,
  insn_field_6,
  insn_field_7,
  nr_insn_table_fields
} insn_table_fields;

typedef enum {
  function_type = insn_format,
  function_name = insn_name,
  function_param = insn_comment
} function_table_fields;

typedef enum {
  model_name = insn_mnemonic,
  model_identifer = insn_name,
  model_default = insn_comment,
} model_table_fields;

typedef enum {
  include_flags = insn_flags,
  include_path = insn_name,
} model_include_fields;

typedef enum {
  cache_type_def = insn_name,
  cache_derived_name = insn_comment,
  cache_name = insn_field_6,
  cache_expression = insn_field_7,
} cache_fields;

typedef struct _insn insn;
struct _insn {
  table_entry *file_entry;
  insn_fields *fields;
  insn *next;
};

typedef struct _insn_undef insn_undef;
struct _insn_undef {
  insn_undef *next;
  char *name;
};

typedef struct _model model;
struct _model {
  model *next;
  char *name;
  char *printable_name;
  char *insn_default;
  table_model_entry *func_unit_start;
  table_model_entry *func_unit_end;
};
  
typedef struct _insn_table insn_table;
struct _insn_table {
  int opcode_nr;
  insn_bits *expanded_bits;
  int nr_insn;
  insn *insns;
  insn *functions;
  insn *last_function;
  decode_table *opcode_rule;
  opcode_field *opcode;
  int nr_entries;
  insn_table *entries;
  insn_table *sibling;
  insn_table *parent;
};

typedef enum {
  insn_model_name,
  insn_model_fields,
  nr_insn_model_table_fields
} insn_model_table_fields;


extern insn_table *load_insn_table
(const char *file_name,
 decode_table *decode_rules,
 filter *filters,
 table_include *includes,
 cache_table **cache_rules);

extern model *models;

extern insn *model_macros;
extern insn *model_functions;
extern insn *model_internal;
extern insn *model_static;
extern insn *model_data;

extern int max_model_fields_len;

extern void insn_table_insert_insn
(insn_table *table,
 table_entry *file_entry,
 insn_fields *fields);


/****************************************************************/

/****************************************************************/

typedef void leaf_handler
(insn_table *entry,
 lf *file,
 void *data,
 int depth);

typedef void insn_handler
(insn_table *table,
 lf *file,
 void *data,
 insn *instruction,
 int depth);

typedef void padding_handler
(insn_table *table,
 lf *file,
 void *data,
 int depth,
 int opcode_nr);


extern void insn_table_traverse_tree
(insn_table *table,
 lf *file,
 void *data,
 int depth,
 leaf_handler *start,
 insn_handler *handler,
 leaf_handler *end,
 padding_handler *padding);


extern void insn_table_traverse_insn
(insn_table *table,
 lf *file,
 void *data,
 insn_handler *handler);



/****************************************************************/

typedef void function_handler
(insn_table *table,
 lf *file,
 void *data,
 table_entry *function);

extern void
insn_table_traverse_function
(insn_table *table,
 lf *file,
 void *data,
 function_handler *leaf);

/****************************************************************/



extern void insn_table_expand_insns
(insn_table *table);

extern int insn_table_depth
(insn_table *table);