14e98e3e1Schristos /* The IGEN simulator generator for GDB, the GNU Debugger. 24e98e3e1Schristos 3*71f62182Schristos Copyright 2002-2024 Free Software Foundation, Inc. 44e98e3e1Schristos 54e98e3e1Schristos Contributed by Andrew Cagney. 64e98e3e1Schristos 74e98e3e1Schristos This file is part of GDB. 84e98e3e1Schristos 94e98e3e1Schristos This program is free software; you can redistribute it and/or modify 104e98e3e1Schristos it under the terms of the GNU General Public License as published by 114e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 124e98e3e1Schristos (at your option) any later version. 134e98e3e1Schristos 144e98e3e1Schristos This program is distributed in the hope that it will be useful, 154e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 164e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 174e98e3e1Schristos GNU General Public License for more details. 184e98e3e1Schristos 194e98e3e1Schristos You should have received a copy of the GNU General Public License 204e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 214e98e3e1Schristos 22*71f62182Schristos #ifndef IGEN_GEN_H 23*71f62182Schristos #define IGEN_GEN_H 244e98e3e1Schristos 254e98e3e1Schristos typedef struct _opcode_field opcode_field; 264e98e3e1Schristos struct _opcode_field 274e98e3e1Schristos { 284e98e3e1Schristos int word_nr; 294e98e3e1Schristos int first; 304e98e3e1Schristos int last; 314e98e3e1Schristos int is_boolean; 324e98e3e1Schristos int nr_opcodes; 334e98e3e1Schristos unsigned boolean_constant; 344e98e3e1Schristos opcode_field *parent; 354e98e3e1Schristos }; 364e98e3e1Schristos 374e98e3e1Schristos typedef struct _opcode_bits opcode_bits; 384e98e3e1Schristos struct _opcode_bits 394e98e3e1Schristos { 404e98e3e1Schristos int value; 414e98e3e1Schristos int first; 424e98e3e1Schristos int last; 434e98e3e1Schristos insn_field_entry *field; 444e98e3e1Schristos opcode_field *opcode; 454e98e3e1Schristos opcode_bits *next; 464e98e3e1Schristos }; 474e98e3e1Schristos 484e98e3e1Schristos typedef struct _insn_opcodes insn_opcodes; 494e98e3e1Schristos struct _insn_opcodes 504e98e3e1Schristos { 514e98e3e1Schristos opcode_field *opcode; 524e98e3e1Schristos insn_opcodes *next; 534e98e3e1Schristos }; 544e98e3e1Schristos 554e98e3e1Schristos typedef struct _insn_list insn_list; 564e98e3e1Schristos struct _insn_list 574e98e3e1Schristos { 584e98e3e1Schristos /* the instruction */ 594e98e3e1Schristos insn_entry *insn; 604e98e3e1Schristos /* list of non constant bits that have been made constant */ 614e98e3e1Schristos opcode_bits *expanded_bits; 624e98e3e1Schristos /* list of the various opcode field paths used to reach this 634e98e3e1Schristos instruction */ 644e98e3e1Schristos insn_opcodes *opcodes; 654e98e3e1Schristos /* number of prefetched words for this instruction */ 664e98e3e1Schristos int nr_prefetched_words; 674e98e3e1Schristos /* The semantic function list_entry corresponding to this insn */ 684e98e3e1Schristos insn_list *semantic; 694e98e3e1Schristos /* linked list */ 704e98e3e1Schristos insn_list *next; 714e98e3e1Schristos }; 724e98e3e1Schristos 734e98e3e1Schristos /* forward */ 744e98e3e1Schristos typedef struct _gen_list gen_list; 754e98e3e1Schristos 764e98e3e1Schristos typedef struct _gen_entry gen_entry; 774e98e3e1Schristos struct _gen_entry 784e98e3e1Schristos { 794e98e3e1Schristos 804e98e3e1Schristos /* as an entry in a table */ 814e98e3e1Schristos int word_nr; 824e98e3e1Schristos int opcode_nr; 834e98e3e1Schristos gen_entry *sibling; 844e98e3e1Schristos opcode_bits *expanded_bits; 854e98e3e1Schristos gen_entry *parent; /* parent has the opcode* data */ 864e98e3e1Schristos 874e98e3e1Schristos /* as a table containing entries */ 884b169a6bSchristos const decode_table *opcode_rule; 894e98e3e1Schristos opcode_field *opcode; 904e98e3e1Schristos int nr_prefetched_words; 914e98e3e1Schristos int nr_entries; 924e98e3e1Schristos gen_entry *entries; 934e98e3e1Schristos 944e98e3e1Schristos /* as both an entry and a table */ 954e98e3e1Schristos int nr_insns; 964e98e3e1Schristos insn_list *insns; 974e98e3e1Schristos 984e98e3e1Schristos /* if siblings are being combined */ 994e98e3e1Schristos gen_entry *combined_next; 1004e98e3e1Schristos gen_entry *combined_parent; 1014e98e3e1Schristos 1024e98e3e1Schristos /* our top-of-tree */ 1034e98e3e1Schristos gen_list *top; 1044e98e3e1Schristos }; 1054e98e3e1Schristos 1064e98e3e1Schristos 1074e98e3e1Schristos struct _gen_list 1084e98e3e1Schristos { 1094b169a6bSchristos const model_entry *model; 1104b169a6bSchristos const insn_table *isa; 1114e98e3e1Schristos gen_entry *table; 1124e98e3e1Schristos gen_list *next; 1134e98e3e1Schristos }; 1144e98e3e1Schristos 1154e98e3e1Schristos 1164e98e3e1Schristos typedef struct _gen_table gen_table; 1174e98e3e1Schristos struct _gen_table 1184e98e3e1Schristos { 1194e98e3e1Schristos /* list of all the instructions */ 1204b169a6bSchristos const insn_table *isa; 1214e98e3e1Schristos /* list of all the semantic functions */ 1224b169a6bSchristos const decode_table *rules; 1234e98e3e1Schristos /* list of all the generated instruction tables */ 1244e98e3e1Schristos gen_list *tables; 1254e98e3e1Schristos /* list of all the semantic functions */ 1264e98e3e1Schristos int nr_semantics; 1274e98e3e1Schristos insn_list *semantics; 1284e98e3e1Schristos }; 1294e98e3e1Schristos 1304e98e3e1Schristos 1314b169a6bSchristos extern gen_table *make_gen_tables 1324b169a6bSchristos (const insn_table *isa, const decode_table *rules); 1334e98e3e1Schristos 1344e98e3e1Schristos 1354e98e3e1Schristos extern void gen_tables_expand_insns (gen_table *gen); 1364e98e3e1Schristos 1374e98e3e1Schristos extern void gen_tables_expand_semantics (gen_table *gen); 1384e98e3e1Schristos 1394b169a6bSchristos extern int gen_entry_depth (const gen_entry *table); 1404e98e3e1Schristos 1414e98e3e1Schristos 1424e98e3e1Schristos 1434e98e3e1Schristos /* Traverse the created data structure */ 1444e98e3e1Schristos 1454e98e3e1Schristos typedef void gen_entry_handler 1464b169a6bSchristos (lf *file, const gen_entry *entry, int depth, void *data); 1474e98e3e1Schristos 1484e98e3e1Schristos extern void gen_entry_traverse_tree 1494e98e3e1Schristos (lf *file, 1504b169a6bSchristos const gen_entry *table, 1514e98e3e1Schristos int depth, 1524e98e3e1Schristos gen_entry_handler * start, 1534e98e3e1Schristos gen_entry_handler * leaf, gen_entry_handler * end, void *data); 1544e98e3e1Schristos 1554e98e3e1Schristos 1564e98e3e1Schristos 1574e98e3e1Schristos /* Misc functions - actually in igen.c */ 1584e98e3e1Schristos 1594e98e3e1Schristos 1604e98e3e1Schristos /* Cache functions: */ 1614e98e3e1Schristos 1624e98e3e1Schristos extern int print_icache_function_formal (lf *file, int nr_prefetched_words); 1634e98e3e1Schristos 1644e98e3e1Schristos extern int print_icache_function_actual (lf *file, int nr_prefetched_words); 1654e98e3e1Schristos 1664e98e3e1Schristos extern int print_icache_function_type (lf *file); 1674e98e3e1Schristos 1684e98e3e1Schristos extern int print_semantic_function_formal (lf *file, int nr_prefetched_words); 1694e98e3e1Schristos 1704e98e3e1Schristos extern int print_semantic_function_actual (lf *file, int nr_prefetched_words); 1714e98e3e1Schristos 1724e98e3e1Schristos extern int print_semantic_function_type (lf *file); 1734e98e3e1Schristos 1744e98e3e1Schristos extern int print_idecode_function_formal (lf *file, int nr_prefetched_words); 1754e98e3e1Schristos 1764e98e3e1Schristos extern int print_idecode_function_actual (lf *file, int nr_prefetched_words); 1774e98e3e1Schristos 1784e98e3e1Schristos typedef enum 1794e98e3e1Schristos { 1804e98e3e1Schristos function_name_prefix_semantics, 1814e98e3e1Schristos function_name_prefix_idecode, 1824e98e3e1Schristos function_name_prefix_itable, 1834e98e3e1Schristos function_name_prefix_icache, 1844e98e3e1Schristos function_name_prefix_engine, 1854e98e3e1Schristos function_name_prefix_none 1864e98e3e1Schristos } 1874e98e3e1Schristos lf_function_name_prefixes; 1884e98e3e1Schristos 1894e98e3e1Schristos typedef enum 1904e98e3e1Schristos { 1914e98e3e1Schristos is_function_declaration = 0, 1924e98e3e1Schristos is_function_definition = 1, 1934e98e3e1Schristos is_function_variable, 1944e98e3e1Schristos } 1954e98e3e1Schristos function_decl_type; 1964e98e3e1Schristos 1974e98e3e1Schristos extern int print_function_name 1984e98e3e1Schristos (lf *file, 1994e98e3e1Schristos const char *basename, 2004e98e3e1Schristos const char *format_name, 2014e98e3e1Schristos const char *model_name, 2024b169a6bSchristos const opcode_bits *expanded_bits, 2034b169a6bSchristos lf_function_name_prefixes prefix); 2044e98e3e1Schristos 2054e98e3e1Schristos extern void print_my_defines 2064e98e3e1Schristos (lf *file, 2074b169a6bSchristos const char *basename, 2084b169a6bSchristos const char *format_name, 2094b169a6bSchristos const opcode_bits *expanded_bits); 2104e98e3e1Schristos 2114b169a6bSchristos extern void print_itrace (lf *file, const insn_entry *insn, int idecode); 2124e98e3e1Schristos 2134e98e3e1Schristos extern void print_sim_engine_abort (lf *file, const char *message); 2144e98e3e1Schristos 2154e98e3e1Schristos 2164e98e3e1Schristos extern void print_include (lf *file, igen_module module); 2174e98e3e1Schristos extern void print_include_inline (lf *file, igen_module module); 2184e98e3e1Schristos extern void print_includes (lf *file); 219*71f62182Schristos 220*71f62182Schristos #endif /* IGEN_GEN_H */ 221