Path: blob/21.2-virgl/src/freedreno/isa/decode.h
4564 views
/*1* Copyright © 2020 Google, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#ifndef _DECODE_H_24#define _DECODE_H_2526#include <stdbool.h>27#include <stdint.h>2829/*30* Defines the tables which are generated from xml for disassembly31*/3233struct decode_scope;3435/* TODO we could maybe make this a uint8_t array, with some helpers, to36* support arbitrary sized patterns.. or add AND/OR/SHIFT support to37* util/bitset.h?38*/39typedef uint64_t bitmask_t;4041struct isa_bitset;4243/**44* Table of enum values45*/46struct isa_enum {47unsigned num_values;48struct {49unsigned val;50const char *display;51} values[];52};5354/**55* An expression used to for conditional overrides, derived fields, etc56*/57typedef uint64_t (*isa_expr_t)(struct decode_scope *scope);5859/**60* Used by generated expr functions61*/62uint64_t isa_decode_field(struct decode_scope *scope, const char *field_name);6364/**65* For bitset fields, there are some cases where we want to "remap" field66* names, essentially allowing one to parameterize a nested bitset when67* it resolves fields in an enclosing bitset.68*/69struct isa_field_params {70unsigned num_params;71struct {72const char *name;73const char *as;74} params[];75};7677/**78* Description of a single field within a bitset case.79*/80struct isa_field {81const char *name;82isa_expr_t expr; /* for virtual "derived" fields */83unsigned low;84unsigned high;85enum {86/* Basic types: */87TYPE_BRANCH, /* branch target, like INT but optional labeling*/88TYPE_INT,89TYPE_UINT,90TYPE_HEX,91TYPE_OFFSET, /* Like INT but formated with +/- or omitted if ==0 */92TYPE_UOFFSET, /* Like UINT but formated with + or omitted if ==0 */93TYPE_FLOAT,94TYPE_BOOL,95TYPE_ENUM,9697/* To assert a certain value in a given range of bits.. not98* used for pattern matching, but allows an override to specify99* that a certain bitpattern in some "unused" bits is expected100*/101TYPE_ASSERT,102103/* For fields that are decoded with another bitset hierarchy: */104TYPE_BITSET,105} type;106union {107const struct isa_bitset **bitsets; /* if type==BITSET */108uint64_t val; /* if type==ASSERT */109const struct isa_enum *enums; /* if type==ENUM */110const char *display; /* if type==BOOL */111};112113/**114* type==BITSET fields can also optionally provide remapping for115* field names116*/117const struct isa_field_params *params;118};119120/**121* A bitset consists of N "cases", with the last one (with case->expr==NULL)122* being the default.123*124* When resolving a field, display template string, etc, all the cases with125* an expression that evaluates to non-zero are consider, falling back to126* the last (default) case.127*/128struct isa_case {129isa_expr_t expr;130const char *display;131unsigned num_fields;132struct isa_field fields[];133};134135/**136* An individual bitset, the leaves of a bitset inheritance hiearchy will137* have the match and mask to match a single instruction (or arbitrary138* bit-pattern) against.139*/140struct isa_bitset {141const struct isa_bitset *parent;142const char *name;143struct {144unsigned min;145unsigned max;146} gen;147bitmask_t match;148bitmask_t dontcare;149bitmask_t mask;150unsigned num_cases;151const struct isa_case *cases[];152};153154#endif /* _DECODE_H_ */155156157