xref: /netbsd-src/external/gpl3/gdb/dist/sim/igen/gen.h (revision 71f621822dbfd5073a314948bec169b7bb05f7be)
1 /* The IGEN simulator generator for GDB, the GNU Debugger.
2 
3    Copyright 2002-2024 Free Software Foundation, Inc.
4 
5    Contributed by Andrew Cagney.
6 
7    This file is part of GDB.
8 
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21 
22 #ifndef IGEN_GEN_H
23 #define IGEN_GEN_H
24 
25 typedef struct _opcode_field opcode_field;
26 struct _opcode_field
27 {
28   int word_nr;
29   int first;
30   int last;
31   int is_boolean;
32   int nr_opcodes;
33   unsigned boolean_constant;
34   opcode_field *parent;
35 };
36 
37 typedef struct _opcode_bits opcode_bits;
38 struct _opcode_bits
39 {
40   int value;
41   int first;
42   int last;
43   insn_field_entry *field;
44   opcode_field *opcode;
45   opcode_bits *next;
46 };
47 
48 typedef struct _insn_opcodes insn_opcodes;
49 struct _insn_opcodes
50 {
51   opcode_field *opcode;
52   insn_opcodes *next;
53 };
54 
55 typedef struct _insn_list insn_list;
56 struct _insn_list
57 {
58   /* the instruction */
59   insn_entry *insn;
60   /* list of non constant bits that have been made constant */
61   opcode_bits *expanded_bits;
62   /* list of the various opcode field paths used to reach this
63      instruction */
64   insn_opcodes *opcodes;
65   /* number of prefetched words for this instruction */
66   int nr_prefetched_words;
67   /* The semantic function list_entry corresponding to this insn */
68   insn_list *semantic;
69   /* linked list */
70   insn_list *next;
71 };
72 
73 /* forward */
74 typedef struct _gen_list gen_list;
75 
76 typedef struct _gen_entry gen_entry;
77 struct _gen_entry
78 {
79 
80   /* as an entry in a table */
81   int word_nr;
82   int opcode_nr;
83   gen_entry *sibling;
84   opcode_bits *expanded_bits;
85   gen_entry *parent;		/* parent has the opcode* data */
86 
87   /* as a table containing entries */
88   const decode_table *opcode_rule;
89   opcode_field *opcode;
90   int nr_prefetched_words;
91   int nr_entries;
92   gen_entry *entries;
93 
94   /* as both an entry and a table */
95   int nr_insns;
96   insn_list *insns;
97 
98   /* if siblings are being combined */
99   gen_entry *combined_next;
100   gen_entry *combined_parent;
101 
102   /* our top-of-tree */
103   gen_list *top;
104 };
105 
106 
107 struct _gen_list
108 {
109   const model_entry *model;
110   const insn_table *isa;
111   gen_entry *table;
112   gen_list *next;
113 };
114 
115 
116 typedef struct _gen_table gen_table;
117 struct _gen_table
118 {
119   /* list of all the instructions */
120   const insn_table *isa;
121   /* list of all the semantic functions */
122   const decode_table *rules;
123   /* list of all the generated instruction tables */
124   gen_list *tables;
125   /* list of all the semantic functions */
126   int nr_semantics;
127   insn_list *semantics;
128 };
129 
130 
131 extern gen_table *make_gen_tables
132   (const insn_table *isa, const decode_table *rules);
133 
134 
135 extern void gen_tables_expand_insns (gen_table *gen);
136 
137 extern void gen_tables_expand_semantics (gen_table *gen);
138 
139 extern int gen_entry_depth (const gen_entry *table);
140 
141 
142 
143 /* Traverse the created data structure */
144 
145 typedef void gen_entry_handler
146   (lf *file, const gen_entry *entry, int depth, void *data);
147 
148 extern void gen_entry_traverse_tree
149   (lf *file,
150    const gen_entry *table,
151    int depth,
152    gen_entry_handler * start,
153    gen_entry_handler * leaf, gen_entry_handler * end, void *data);
154 
155 
156 
157 /* Misc functions - actually in igen.c */
158 
159 
160 /* Cache functions: */
161 
162 extern int print_icache_function_formal (lf *file, int nr_prefetched_words);
163 
164 extern int print_icache_function_actual (lf *file, int nr_prefetched_words);
165 
166 extern int print_icache_function_type (lf *file);
167 
168 extern int print_semantic_function_formal (lf *file, int nr_prefetched_words);
169 
170 extern int print_semantic_function_actual (lf *file, int nr_prefetched_words);
171 
172 extern int print_semantic_function_type (lf *file);
173 
174 extern int print_idecode_function_formal (lf *file, int nr_prefetched_words);
175 
176 extern int print_idecode_function_actual (lf *file, int nr_prefetched_words);
177 
178 typedef enum
179 {
180   function_name_prefix_semantics,
181   function_name_prefix_idecode,
182   function_name_prefix_itable,
183   function_name_prefix_icache,
184   function_name_prefix_engine,
185   function_name_prefix_none
186 }
187 lf_function_name_prefixes;
188 
189 typedef enum
190 {
191   is_function_declaration = 0,
192   is_function_definition = 1,
193   is_function_variable,
194 }
195 function_decl_type;
196 
197 extern int print_function_name
198   (lf *file,
199    const char *basename,
200    const char *format_name,
201    const char *model_name,
202    const opcode_bits *expanded_bits,
203    lf_function_name_prefixes prefix);
204 
205 extern void print_my_defines
206   (lf *file,
207    const char *basename,
208    const char *format_name,
209    const opcode_bits *expanded_bits);
210 
211 extern void print_itrace (lf *file, const insn_entry *insn, int idecode);
212 
213 extern void print_sim_engine_abort (lf *file, const char *message);
214 
215 
216 extern void print_include (lf *file, igen_module module);
217 extern void print_include_inline (lf *file, igen_module module);
218 extern void print_includes (lf *file);
219 
220 #endif /* IGEN_GEN_H */
221