xref: /freebsd/sys/dev/aic7xxx/aicasm/aicasm_symbol.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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  * $FreeBSD$
45  */
46 
47 #include <sys/queue.h>
48 
49 typedef enum {
50 	UNINITIALIZED,
51 	REGISTER,
52 	ALIAS,
53 	SCBLOC,
54 	SRAMLOC,
55 	ENUM_ENTRY,
56 	FIELD,
57 	MASK,
58 	ENUM,
59 	CONST,
60 	DOWNLOAD_CONST,
61 	LABEL,
62 	CONDITIONAL,
63 	MACRO
64 } symtype;
65 
66 typedef enum {
67 	RO = 0x01,
68 	WO = 0x02,
69 	RW = 0x03
70 }amode_t;
71 
72 typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
73 
74 struct reg_info {
75 	u_int	  address;
76 	int	  size;
77 	amode_t	  mode;
78 	symlist_t fields;
79 	uint8_t	  valid_bitmask;
80 	uint8_t	  modes;
81 	int	  typecheck_masks;
82 };
83 
84 struct field_info {
85 	symlist_t symrefs;
86 	uint8_t	  value;
87 	uint8_t	  mask;
88 };
89 
90 struct const_info {
91 	u_int	value;
92 	int	define;
93 };
94 
95 struct alias_info {
96 	struct symbol *parent;
97 };
98 
99 struct label_info {
100 	int	address;
101 	int	exported;
102 };
103 
104 struct cond_info {
105 	int	func_num;
106 };
107 
108 struct macro_arg {
109 	STAILQ_ENTRY(macro_arg)	links;
110 	regex_t	arg_regex;
111 	char   *replacement_text;
112 };
113 STAILQ_HEAD(macro_arg_list, macro_arg);
114 
115 struct macro_info {
116 	struct macro_arg_list args;
117 	int   narg;
118 	const char* body;
119 };
120 
121 typedef struct expression_info {
122         symlist_t       referenced_syms;
123         int             value;
124 } expression_t;
125 
126 typedef struct symbol {
127 	char	*name;
128 	symtype	type;
129 	union	{
130 		struct reg_info	  *rinfo;
131 		struct field_info *finfo;
132 		struct const_info *cinfo;
133 		struct alias_info *ainfo;
134 		struct label_info *linfo;
135 		struct cond_info  *condinfo;
136 		struct macro_info *macroinfo;
137 	}info;
138 } symbol_t;
139 
140 typedef struct symbol_ref {
141 	symbol_t *symbol;
142 	int	 offset;
143 } symbol_ref_t;
144 
145 typedef struct symbol_node {
146 	SLIST_ENTRY(symbol_node) links;
147 	symbol_t *symbol;
148 } symbol_node_t;
149 
150 typedef struct critical_section {
151 	TAILQ_ENTRY(critical_section) links;
152 	int begin_addr;
153 	int end_addr;
154 } critical_section_t;
155 
156 typedef enum {
157 	SCOPE_ROOT,
158 	SCOPE_IF,
159 	SCOPE_ELSE_IF,
160 	SCOPE_ELSE
161 } scope_type;
162 
163 typedef struct patch_info {
164 	int skip_patch;
165 	int skip_instr;
166 } patch_info_t;
167 
168 typedef struct scope {
169 	SLIST_ENTRY(scope) scope_stack_links;
170 	TAILQ_ENTRY(scope) scope_links;
171 	TAILQ_HEAD(, scope) inner_scope;
172 	scope_type type;
173 	int inner_scope_patches;
174 	int begin_addr;
175         int end_addr;
176 	patch_info_t patches[2];
177 	int func_num;
178 } scope_t;
179 
180 TAILQ_HEAD(cs_tailq, critical_section);
181 SLIST_HEAD(scope_list, scope);
182 TAILQ_HEAD(scope_tailq, scope);
183 
184 void	symbol_delete(symbol_t *symbol);
185 
186 void	symtable_open(void);
187 
188 void	symtable_close(void);
189 
190 symbol_t *
191 	symtable_get(const char *name);
192 
193 symbol_node_t *
194 	symlist_search(symlist_t *symlist, char *symname);
195 
196 void
197 	symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
198 #define SYMLIST_INSERT_HEAD	0x00
199 #define SYMLIST_SORT		0x01
200 
201 void	symlist_free(symlist_t *symlist);
202 
203 void	symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
204 		      symlist_t *symlist_src2);
205 void	symtable_dump(FILE *ofile, FILE *dfile);
206