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