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