aicasm_symbol.h revision 63457
1/*
2 * Aic7xxx SCSI host adapter firmware asssembler symbol table definitions
3 *
4 * Copyright (c) 1997 Justin T. Gibbs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions, and the following disclaimer,
12 *    without modification.
13 * 2. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission.
15 *
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU Public License ("GPL").
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * $FreeBSD: head/sys/dev/aic7xxx/aicasm/aicasm_symbol.h 63457 2000-07-18 20:12:14Z gibbs $
32 */
33
34#include <sys/queue.h>
35
36typedef enum {
37	UNINITIALIZED,
38	REGISTER,
39	ALIAS,
40	SCBLOC,
41	SRAMLOC,
42	MASK,
43	BIT,
44	CONST,
45	DOWNLOAD_CONST,
46	LABEL,
47	CONDITIONAL
48}symtype;
49
50typedef enum {
51	RO = 0x01,
52	WO = 0x02,
53	RW = 0x03
54}amode_t;
55
56struct reg_info {
57	uint8_t address;
58	int	 size;
59	amode_t	 mode;
60	uint8_t valid_bitmask;
61	int	 typecheck_masks;
62};
63
64typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
65
66struct mask_info {
67	symlist_t symrefs;
68	uint8_t mask;
69};
70
71struct const_info {
72	uint8_t value;
73	int	 define;
74};
75
76struct alias_info {
77	struct symbol *parent;
78};
79
80struct label_info {
81	int	address;
82};
83
84struct cond_info {
85	int	func_num;
86};
87
88typedef struct expression_info {
89        symlist_t       referenced_syms;
90        int             value;
91} expression_t;
92
93typedef struct symbol {
94	char	*name;
95	symtype	type;
96	union	{
97		struct reg_info *rinfo;
98		struct mask_info *minfo;
99		struct const_info *cinfo;
100		struct alias_info *ainfo;
101		struct label_info *linfo;
102		struct cond_info *condinfo;
103	}info;
104} symbol_t;
105
106typedef struct symbol_ref {
107	symbol_t *symbol;
108	int	 offset;
109} symbol_ref_t;
110
111typedef struct symbol_node {
112	SLIST_ENTRY(symbol_node) links;
113	symbol_t *symbol;
114}symbol_node_t;
115
116typedef enum {
117	SCOPE_ROOT,
118	SCOPE_IF,
119	SCOPE_ELSE_IF,
120	SCOPE_ELSE
121} scope_type;
122
123typedef struct patch_info {
124	int skip_patch;
125	int skip_instr;
126} patch_info_t;
127
128typedef struct scope {
129	SLIST_ENTRY(scope) scope_stack_links;
130	TAILQ_ENTRY(scope) scope_links;
131	TAILQ_HEAD(, scope) inner_scope;
132	scope_type type;
133	int inner_scope_patches;
134	int begin_addr;
135        int end_addr;
136	patch_info_t patches[2];
137	int func_num;
138} scope_t;
139
140SLIST_HEAD(scope_list, scope);
141TAILQ_HEAD(scope_tailq, scope);
142
143void	symbol_delete __P((symbol_t *symbol));
144
145void	symtable_open __P((void));
146
147void	symtable_close __P((void));
148
149symbol_t *
150	symtable_get __P((char *name));
151
152symbol_node_t *
153	symlist_search __P((symlist_t *symlist, char *symname));
154
155void
156	symlist_add __P((symlist_t *symlist, symbol_t *symbol, int how));
157#define SYMLIST_INSERT_HEAD	0x00
158#define SYMLIST_SORT		0x01
159
160void	symlist_free __P((symlist_t *symlist));
161
162void	symlist_merge __P((symlist_t *symlist_dest, symlist_t *symlist_src1,
163			   symlist_t *symlist_src2));
164void	symtable_dump __P((FILE *ofile));
165