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_LD_DECODE_H 23 #define IGEN_LD_DECODE_H 24 25 /* Instruction decode table: 26 27 <decode-rule> ::= 28 { <option> } 29 ":" [ <first> ] 30 ":" [ <last> ] 31 ":" [ <force-first> ] 32 ":" [ <force-last> ] 33 ":" [ <constant-field-names> ] 34 ":" [ <word-nr> ] 35 ":" [ <format-names> ] 36 ":" [ <model-names> ] 37 ":" [ <constant> ] 38 ":" [ <path> { "," <path> } ] 39 { ":" <special-mask> 40 ":" [ "!" ] <special-value> 41 ":" <word-nr> } 42 <nl> 43 ; 44 45 46 <path> ::= <int> "," <int> ;; 47 48 <option> ::= 49 <reserved-options> 50 | <code-options> 51 | <optimize-options> 52 | <decode-options> 53 | <constant> 54 | <search-options> 55 ; 56 57 <reserved-options> ::= "zero-reserved" ; 58 <gen-options> ::= "array" | "switch" | "padded-switch" | "goto-switch" ; 59 <optimize-options> ::= "duplicate" | "combine" 60 <decode-options> ::= "normal" | "boolean" ; 61 <search-options> ::= "constants" | "variables" | "mixed" 62 63 Ignore the below: 64 65 66 The instruction decode table contains rules that dictate how igen 67 is going to firstly break down the opcode table and secondly 68 69 The table that follows is used by gen to construct a decision tree 70 that can identify each possible instruction. Gen then outputs this 71 decision tree as (according to config) a table or switch statement 72 as the function idecode. 73 74 In parallel to this, as mentioned above, WITH_EXPANDED_SEMANTICS 75 determines of the semantic functions themselves should be expanded 76 in a similar way. 77 78 <first> 79 <last> 80 81 Range of bits (within the instruction) that should be searched for 82 an instruction field. Within such ranges, gen looks for opcodes 83 (constants), registers (strings) and reserved bits (slash) and 84 according to the rules that follows includes or excludes them from 85 a possible instruction field. 86 87 <force_first> 88 <force_last> 89 90 If an instruction field was found, enlarge the field size so that 91 it is forced to at least include bits starting from <force_first> 92 (<force_last>). To stop this occuring, use <force_first> = <last> 93 + 1 and <force_last> = <first> - 1. 94 95 <force_reserved> 96 97 Treat `/' (reserved) fields as a constant (zero) instead of 98 variable when looking for an instruction field. 99 100 <force_expansion> 101 102 Treat any contained register (string) fields as constant when 103 determining the instruction field. For the instruction decode (and 104 controled by IDECODE_EXPAND_SEMANTICS) this forces the expansion of 105 what would otherwize be non constant bits of an instruction. 106 107 <use_switch> 108 109 Should this table be expanded using a switch statement (val 1) and 110 if so, should it be padded with entries so as to force the compiler 111 to generate a jump table (val 2). Or a branch table (val 3). 112 113 <special_mask> 114 <special_value> 115 <special_rule> 116 <special_constant> 117 118 Special rule to fine tune how specific (or groups) of instructions 119 are expanded. The applicability of the rule is determined by 120 121 <special_mask> != 0 && (instruction> & <special_mask>) == <special_value> 122 123 Where <instruction> is obtained by looking only at constant fields 124 with in an instructions spec. When determining an expansion, the 125 rule is only considered when a node contains a single instruction. 126 <special_rule> can be any of: 127 128 0: for this instruction, expand by earlier rules 129 1: expand bits <force_low> .. <force_hi> only 130 2: boolean expansion of only zero/non-zero cases 131 3: boolean expansion of equality of special constant 132 133 */ 134 135 136 typedef enum 137 { 138 normal_decode_rule, 139 boolean_rule, 140 } 141 decode_special_type; 142 143 144 typedef enum 145 { 146 invalid_gen, 147 array_gen, 148 switch_gen, 149 padded_switch_gen, 150 goto_switch_gen, 151 } 152 decode_gen_type; 153 154 155 enum 156 { 157 decode_cond_mask_field, 158 decode_cond_value_field, 159 decode_cond_word_nr_field, 160 nr_decode_cond_fields, 161 }; 162 163 typedef struct _decode_path decode_path; 164 struct _decode_path 165 { 166 int opcode_nr; 167 decode_path *parent; 168 }; 169 170 typedef struct _decode_path_list decode_path_list; 171 struct _decode_path_list 172 { 173 decode_path *path; 174 decode_path_list *next; 175 }; 176 177 178 typedef struct _decode_cond decode_cond; 179 struct _decode_cond 180 { 181 int word_nr; 182 int mask[max_insn_bit_size]; 183 int value[max_insn_bit_size]; 184 int is_equal; 185 decode_cond *next; 186 }; 187 188 typedef enum 189 { 190 decode_find_mixed, 191 decode_find_constants, 192 decode_find_strings, 193 } 194 decode_search_type; 195 196 enum 197 { 198 decode_options_field, 199 decode_first_field, 200 decode_last_field, 201 decode_force_first_field, 202 decode_force_last_field, 203 decode_constant_field_names_field, 204 decode_word_nr_field, 205 decode_format_names_field, 206 decode_model_names_field, 207 decode_paths_field, 208 nr_decode_fields, 209 min_nr_decode_fields = decode_last_field + 1, 210 }; 211 212 213 typedef struct _decode_table decode_table; 214 struct _decode_table 215 { 216 line_ref *line; 217 decode_special_type type; 218 decode_gen_type gen; 219 decode_search_type search; 220 int first; 221 int last; 222 int force_first; 223 int force_last; 224 filter *constant_field_names; 225 int word_nr; 226 /* if a boolean */ 227 unsigned constant; 228 /* options */ 229 int with_zero_reserved; 230 int with_duplicates; 231 int with_combine; 232 /* conditions on the rule being applied */ 233 decode_path_list *paths; 234 filter *format_names; 235 filter *model_names; 236 decode_cond *conditions; 237 decode_table *next; 238 }; 239 240 241 extern decode_table *load_decode_table (const char *file_name); 242 243 extern int decode_table_max_word_nr (const decode_table *rule); 244 245 extern void dump_decode_rule 246 (lf *file, const char *prefix, const decode_table *rule, const char *suffix); 247 248 #endif /* IGEN_LD_DECODE_H */ 249