xref: /freebsd/sys/dev/aic7xxx/aicasm/aicasm_symbol.h (revision 069ac184)
1 /*-
2  * Aic7xxx SCSI host adapter firmware asssembler symbol table definitions
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (c) 1997 Justin T. Gibbs.
7  * Copyright (c) 2002 Adaptec Inc.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions, and the following disclaimer,
15  *    without modification.
16  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
17  *    substantially similar to the "NO WARRANTY" disclaimer below
18  *    ("Disclaimer") and any redistribution must be conditioned upon
19  *    including a substantially similar Disclaimer requirement for further
20  *    binary redistribution.
21  * 3. Neither the names of the above-listed copyright holders nor the names
22  *    of any contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * Alternatively, this software may be distributed under the terms of the
26  * GNU General Public License ("GPL") version 2 as published by the Free
27  * Software Foundation.
28  *
29  * NO WARRANTY
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
33  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  * POSSIBILITY OF SUCH DAMAGES.
41  *
42  * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.h#17 $
43  */
44 
45 #include <sys/queue.h>
46 
47 typedef enum {
48 	UNINITIALIZED,
49 	REGISTER,
50 	ALIAS,
51 	SCBLOC,
52 	SRAMLOC,
53 	ENUM_ENTRY,
54 	FIELD,
55 	MASK,
56 	ENUM,
57 	CONST,
58 	DOWNLOAD_CONST,
59 	LABEL,
60 	CONDITIONAL,
61 	MACRO
62 } symtype;
63 
64 typedef enum {
65 	RO = 0x01,
66 	WO = 0x02,
67 	RW = 0x03
68 }amode_t;
69 
70 typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
71 
72 struct reg_info {
73 	u_int	  address;
74 	int	  size;
75 	amode_t	  mode;
76 	symlist_t fields;
77 	uint8_t	  valid_bitmask;
78 	uint8_t	  modes;
79 	int	  typecheck_masks;
80 };
81 
82 struct field_info {
83 	symlist_t symrefs;
84 	uint8_t	  value;
85 	uint8_t	  mask;
86 };
87 
88 struct const_info {
89 	u_int	value;
90 	int	define;
91 };
92 
93 struct alias_info {
94 	struct symbol *parent;
95 };
96 
97 struct label_info {
98 	int	address;
99 	int	exported;
100 };
101 
102 struct cond_info {
103 	int	func_num;
104 };
105 
106 struct macro_arg {
107 	STAILQ_ENTRY(macro_arg)	links;
108 	regex_t	arg_regex;
109 	char   *replacement_text;
110 };
111 STAILQ_HEAD(macro_arg_list, macro_arg);
112 
113 struct macro_info {
114 	struct macro_arg_list args;
115 	int   narg;
116 	const char* body;
117 };
118 
119 typedef struct expression_info {
120         symlist_t       referenced_syms;
121         int             value;
122 } expression_t;
123 
124 typedef struct symbol {
125 	char	*name;
126 	symtype	type;
127 	union	{
128 		struct reg_info	  *rinfo;
129 		struct field_info *finfo;
130 		struct const_info *cinfo;
131 		struct alias_info *ainfo;
132 		struct label_info *linfo;
133 		struct cond_info  *condinfo;
134 		struct macro_info *macroinfo;
135 	}info;
136 } symbol_t;
137 
138 typedef struct symbol_ref {
139 	symbol_t *symbol;
140 	int	 offset;
141 } symbol_ref_t;
142 
143 typedef struct symbol_node {
144 	SLIST_ENTRY(symbol_node) links;
145 	symbol_t *symbol;
146 } symbol_node_t;
147 
148 typedef struct critical_section {
149 	TAILQ_ENTRY(critical_section) links;
150 	int begin_addr;
151 	int end_addr;
152 } critical_section_t;
153 
154 typedef enum {
155 	SCOPE_ROOT,
156 	SCOPE_IF,
157 	SCOPE_ELSE_IF,
158 	SCOPE_ELSE
159 } scope_type;
160 
161 typedef struct patch_info {
162 	int skip_patch;
163 	int skip_instr;
164 } patch_info_t;
165 
166 typedef struct scope {
167 	SLIST_ENTRY(scope) scope_stack_links;
168 	TAILQ_ENTRY(scope) scope_links;
169 	TAILQ_HEAD(, scope) inner_scope;
170 	scope_type type;
171 	int inner_scope_patches;
172 	int begin_addr;
173         int end_addr;
174 	patch_info_t patches[2];
175 	int func_num;
176 } scope_t;
177 
178 TAILQ_HEAD(cs_tailq, critical_section);
179 SLIST_HEAD(scope_list, scope);
180 TAILQ_HEAD(scope_tailq, scope);
181 
182 void	symbol_delete(symbol_t *symbol);
183 
184 void	symtable_open(void);
185 
186 void	symtable_close(void);
187 
188 symbol_t *
189 	symtable_get(const char *name);
190 
191 symbol_node_t *
192 	symlist_search(symlist_t *symlist, char *symname);
193 
194 void
195 	symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
196 #define SYMLIST_INSERT_HEAD	0x00
197 #define SYMLIST_SORT		0x01
198 
199 void	symlist_free(symlist_t *symlist);
200 
201 void	symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
202 		      symlist_t *symlist_src2);
203 void	symtable_dump(FILE *ofile, FILE *dfile);
204