aicasm_symbol.h revision 369944
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: stable/11/sys/dev/aic7xxx/aicasm/aicasm_symbol.h 369944 2021-06-04 00:31:43Z jrtc27 $
43 */
44
45#include <sys/queue.h>
46
47typedef 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
64typedef enum {
65	RO = 0x01,
66	WO = 0x02,
67	RW = 0x03
68}amode_t;
69
70typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
71
72struct 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
82struct field_info {
83	symlist_t symrefs;
84	uint8_t	  value;
85	uint8_t	  mask;
86};
87
88struct const_info {
89	u_int	value;
90	int	define;
91};
92
93struct alias_info {
94	struct symbol *parent;
95};
96
97struct label_info {
98	int	address;
99	int	exported;
100};
101
102struct cond_info {
103	int	func_num;
104};
105
106struct macro_arg {
107	STAILQ_ENTRY(macro_arg)	links;
108	regex_t	arg_regex;
109	char   *replacement_text;
110};
111STAILQ_HEAD(macro_arg_list, macro_arg);
112
113struct macro_info {
114	struct macro_arg_list args;
115	int   narg;
116	const char* body;
117};
118
119typedef struct expression_info {
120        symlist_t       referenced_syms;
121        int             value;
122} expression_t;
123
124typedef 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
138typedef struct symbol_ref {
139	symbol_t *symbol;
140	int	 offset;
141} symbol_ref_t;
142
143typedef struct symbol_node {
144	SLIST_ENTRY(symbol_node) links;
145	symbol_t *symbol;
146} symbol_node_t;
147
148typedef struct critical_section {
149	TAILQ_ENTRY(critical_section) links;
150	int begin_addr;
151	int end_addr;
152} critical_section_t;
153
154typedef enum {
155	SCOPE_ROOT,
156	SCOPE_IF,
157	SCOPE_ELSE_IF,
158	SCOPE_ELSE
159} scope_type;
160
161typedef struct patch_info {
162	int skip_patch;
163	int skip_instr;
164} patch_info_t;
165
166typedef 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
178TAILQ_HEAD(cs_tailq, critical_section);
179SLIST_HEAD(scope_list, scope);
180TAILQ_HEAD(scope_tailq, scope);
181
182void	symbol_delete(symbol_t *symbol);
183
184void	symtable_open(void);
185
186void	symtable_close(void);
187
188symbol_t *
189	symtable_get(const char *name);
190
191symbol_node_t *
192	symlist_search(symlist_t *symlist, char *symname);
193
194void
195	symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
196#define SYMLIST_INSERT_HEAD	0x00
197#define SYMLIST_SORT		0x01
198
199void	symlist_free(symlist_t *symlist);
200
201void	symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
202		      symlist_t *symlist_src2);
203void	symtable_dump(FILE *ofile, FILE *dfile);
204