1 /* 2 * Copyright © 2020 Google, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24 /* This file should not be included directly. Instead, it is included as part 25 * of the header file generated by isaspec/decode.py 26 */ 27 28 #include <stdbool.h> 29 #include <stdint.h> 30 31 /* 32 * Defines the tables which are generated from xml for disassembly 33 */ 34 35 struct decode_scope; 36 struct isa_bitset; 37 38 /** 39 * Table of enum values 40 */ 41 struct isa_enum { 42 unsigned num_values; 43 struct { 44 unsigned val; 45 const char *display; 46 } values[]; 47 }; 48 49 /** 50 * An expression used to for conditional overrides, derived fields, etc 51 */ 52 typedef uint64_t (*isa_expr_t)(struct decode_scope *scope); 53 54 /** 55 * Used by generated expr functions 56 */ 57 uint64_t isa_decode_field(struct decode_scope *scope, const char *field_name); 58 59 void isa_decode_bitset(void *out, const struct isa_bitset **bitsets, struct decode_scope *scope, bitmask_t val); 60 61 /** 62 * Used by generated decode functions 63 */ 64 uint32_t isa_get_gpu_id(struct decode_scope *scope); 65 66 /** 67 * Allows to use gpu_id in expr functions 68 */ 69 #define ISA_GPU_ID() isa_get_gpu_id(scope) 70 71 /** 72 * For bitset fields, there are some cases where we want to "remap" field 73 * names, essentially allowing one to parameterize a nested bitset when 74 * it resolves fields in an enclosing bitset. 75 */ 76 struct isa_field_params { 77 unsigned num_params; 78 struct { 79 const char *name; 80 const char *as; 81 } params[]; 82 }; 83 84 struct decode_scope; 85 86 /** 87 * Description of a single field within a bitset case. 88 */ 89 struct isa_field { 90 const char *name; 91 isa_expr_t expr; /* for virtual "derived" fields */ 92 unsigned low; 93 unsigned high; 94 enum { 95 /* Basic types: */ 96 TYPE_BRANCH, /* relative branch target, like INT but optional labeling*/ 97 TYPE_ABSBRANCH, /* absolute branch target */ 98 TYPE_INT, 99 TYPE_UINT, 100 TYPE_HEX, 101 TYPE_OFFSET, /* Like INT but formated with +/- or omitted if ==0 */ 102 TYPE_UOFFSET, /* Like UINT but formated with + or omitted if ==0 */ 103 TYPE_FLOAT, 104 TYPE_BOOL, 105 TYPE_BOOL_INV, /* Like BOOL but inverted */ 106 TYPE_ENUM, 107 108 /* For fields that must be printed via a user-provided callback */ 109 TYPE_CUSTOM, 110 111 /* To assert a certain value in a given range of bits.. not 112 * used for pattern matching, but allows an override to specify 113 * that a certain bitpattern in some "unused" bits is expected 114 */ 115 TYPE_ASSERT, 116 117 /* For fields that are decoded with another bitset hierarchy: */ 118 TYPE_BITSET, 119 } type; 120 union { 121 const struct isa_bitset **bitsets; /* if type==BITSET */ 122 bitmask_t val; /* if type==ASSERT */ 123 const struct isa_enum *enums; /* if type==ENUM */ 124 const char *display; /* if type==BOOL */ 125 bool call; /* if type==(BRANCH|ABSBRANCH) */ 126 }; 127 128 /** 129 * type==BITSET fields can also optionally provide remapping for 130 * field names 131 */ 132 const struct isa_field_params *params; 133 }; 134 135 /** 136 * A bitset consists of N "cases", with the last one (with case->expr==NULL) 137 * being the default. 138 * 139 * When resolving a field, display template string, etc, all the cases with 140 * an expression that evaluates to non-zero are consider, falling back to 141 * the last (default) case. 142 */ 143 struct isa_case { 144 isa_expr_t expr; 145 const char *display; 146 unsigned num_fields; 147 struct isa_field fields[]; 148 }; 149 150 struct isa_field_decode { 151 const char *name; 152 void (*decode)(void *out, struct decode_scope *scope, uint64_t val); 153 }; 154 155 /** 156 * An individual bitset, the leaves of a bitset inheritance hiearchy will 157 * have the match and mask to match a single instruction (or arbitrary 158 * bit-pattern) against. 159 */ 160 struct isa_bitset { 161 const struct isa_bitset *parent; 162 const char *name; 163 struct { 164 unsigned min; 165 unsigned max; 166 } gen; 167 bitmask_t match; 168 bitmask_t dontcare; 169 bitmask_t mask; 170 void (*decode)(void *out, struct decode_scope *scope); 171 unsigned num_decode_fields; 172 const struct isa_field_decode *decode_fields; 173 unsigned num_cases; 174 const struct isa_case *cases[]; 175 }; 176