xref: /aosp_15_r20/external/mesa3d/src/compiler/isaspec/isaspec.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 #ifndef _ISASPEC_H_
25 #define _ISASPEC_H_
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 
30 #include <stdio.h>
31 #include "util/bitset.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 struct isa_decode_value {
38 	/** for {NAME} */
39 	const char *str;
40 	/** for all other fields */
41 	uint64_t num;
42 };
43 
44 struct isa_entrypoint {
45 	const char *name;
46 	uint32_t offset;
47 };
48 
49 struct isa_print_state {
50 	FILE *out;
51 
52 	/**
53 	 * Column number of current line
54 	 */
55 	unsigned line_column;
56 };
57 
58 void isa_print(struct isa_print_state *state, const char *fmt, ...) PRINTFLIKE(2, 3);
59 
60 struct isa_decode_options {
61 	uint32_t gpu_id;
62 
63 	/** show errors detected in decoding, like unexpected dontcare bits */
64 	bool show_errors;
65 
66 	/**
67 	 * If non-zero, maximum # of instructions that are unmatched before
68 	 * bailing, ie. to trigger stopping if we start trying to decode
69 	 * random garbage.
70 	 */
71 	unsigned max_errors;
72 
73 	/** Generate branch target labels */
74 	bool branch_labels;
75 
76 	/**
77 	 * Flag which can be set, for ex, but decode hook to trigger end of
78 	 * decoding
79 	 */
80 	bool stop;
81 
82 	/**
83 	 * Data passed back to decode hooks
84 	 */
85 	void *cbdata;
86 
87 	/**
88 	 * Callback for field decode
89 	 */
90 	void (*field_cb)(void *data, const char *field_name, struct isa_decode_value *val);
91 
92 	/**
93 	 * Callback for fields that need custom code to print their value.
94 	 */
95 	void (*field_print_cb)(struct isa_print_state *print, const char *field_name, uint64_t val);
96 
97 	/**
98 	 * Callback prior to instruction decode
99 	 */
100 	void (*pre_instr_cb)(void *data, unsigned n, void *instr);
101 
102 	/**
103 	 * Callback after instruction decode
104 	 */
105 	void (*post_instr_cb)(void *data, unsigned n, void *instr);
106 
107 	/**
108 	 * callback for undefined instructions
109 	 */
110 	void (*no_match_cb)(FILE *out, const BITSET_WORD *bitset, size_t size);
111 
112 	/**
113 	 * List of known entrypoints to treat like call targets
114 	 */
115 	unsigned entrypoint_count;
116 	const struct isa_entrypoint *entrypoints;
117 };
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif /* _ISASPEC_H_ */
124