aicasm_symbol.h revision 60833
1139749Simp/*
2103285Sikob * Aic7xxx SCSI host adapter firmware asssembler symbol table definitions
3103285Sikob *
4103285Sikob * Copyright (c) 1997 Justin T. Gibbs.
5103285Sikob * All rights reserved.
6103285Sikob *
7103285Sikob * Redistribution and use in source and binary forms, with or without
8103285Sikob * modification, are permitted provided that the following conditions
9103285Sikob * are met:
10103285Sikob * 1. Redistributions of source code must retain the above copyright
11103285Sikob *    notice, this list of conditions, and the following disclaimer,
12103285Sikob *    without modification.
13103285Sikob * 2. The name of the author may not be used to endorse or promote products
14103285Sikob *    derived from this software without specific prior written permission.
15103285Sikob *
16103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17103285Sikob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18103285Sikob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19103285Sikob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20103285Sikob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21103285Sikob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22103285Sikob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24103285Sikob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25103285Sikob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26103285Sikob * SUCH DAMAGE.
27103285Sikob *
28103285Sikob * $FreeBSD: head/sys/dev/aic7xxx/aicasm/aicasm_symbol.h 60833 2000-05-23 20:41:01Z jake $
29103285Sikob */
30103285Sikob
31103285Sikob#include <sys/queue.h>
32103285Sikob
33103285Sikobtypedef enum {
34103285Sikob	UNINITIALIZED,
35103285Sikob	REGISTER,
36103285Sikob	ALIAS,
37103285Sikob	SCBLOC,
38103285Sikob	SRAMLOC,
39103285Sikob	MASK,
40103285Sikob	BIT,
41103285Sikob	CONST,
42103285Sikob	DOWNLOAD_CONST,
43103285Sikob	LABEL,
44103285Sikob	CONDITIONAL
45103285Sikob}symtype;
46103285Sikob
47103285Sikobtypedef enum {
48103285Sikob	RO = 0x01,
49103285Sikob	WO = 0x02,
50103285Sikob	RW = 0x03
51103285Sikob}amode_t;
52103285Sikob
53103285Sikobstruct reg_info {
54103285Sikob	u_int8_t address;
55103285Sikob	int	 size;
56103285Sikob	amode_t	 mode;
57103285Sikob	u_int8_t valid_bitmask;
58103285Sikob	int	 typecheck_masks;
59103285Sikob};
60103285Sikob
61103285Sikobtypedef SLIST_HEAD(symlist, struct symbol_node) symlist_t;
62103285Sikob
63103285Sikobstruct mask_info {
64103285Sikob	symlist_t symrefs;
65103285Sikob	u_int8_t mask;
66103285Sikob};
67103285Sikob
68103285Sikobstruct const_info {
69103285Sikob	u_int8_t value;
70103285Sikob	int	 define;
71103285Sikob};
72103285Sikob
73103285Sikobstruct alias_info {
74103285Sikob	struct symbol *parent;
75103285Sikob};
76103285Sikob
77103285Sikobstruct label_info {
78103285Sikob	int	address;
79103285Sikob};
80103285Sikob
81103285Sikobstruct cond_info {
82103285Sikob	int	func_num;
83103285Sikob};
84103285Sikob
85103285Sikobtypedef struct expression_info {
86        symlist_t       referenced_syms;
87        int             value;
88} expression_t;
89
90typedef struct symbol {
91	char	*name;
92	symtype	type;
93	union	{
94		struct reg_info *rinfo;
95		struct mask_info *minfo;
96		struct const_info *cinfo;
97		struct alias_info *ainfo;
98		struct label_info *linfo;
99		struct cond_info *condinfo;
100	}info;
101} symbol_t;
102
103typedef struct symbol_ref {
104	symbol_t *symbol;
105	int	 offset;
106} symbol_ref_t;
107
108typedef struct symbol_node {
109	SLIST_ENTRY(struct symbol_node) links;
110	symbol_t *symbol;
111}symbol_node_t;
112
113typedef enum {
114	SCOPE_ROOT,
115	SCOPE_IF,
116	SCOPE_ELSE_IF,
117	SCOPE_ELSE
118} scope_type;
119
120typedef struct patch_info {
121	int skip_patch;
122	int skip_instr;
123} patch_info_t;
124
125typedef struct scope {
126	SLIST_ENTRY(struct scope) scope_stack_links;
127	TAILQ_ENTRY(struct scope) scope_links;
128	TAILQ_HEAD(, struct scope) inner_scope;
129	scope_type type;
130	int inner_scope_patches;
131	int begin_addr;
132        int end_addr;
133	patch_info_t patches[2];
134	int func_num;
135} scope_t;
136
137SLIST_HEAD(scope_list, struct scope);
138TAILQ_HEAD(scope_tailq, struct scope);
139
140void	symbol_delete __P((symbol_t *symbol));
141
142void	symtable_open __P((void));
143
144void	symtable_close __P((void));
145
146symbol_t *
147	symtable_get __P((char *name));
148
149symbol_node_t *
150	symlist_search __P((symlist_t *symlist, char *symname));
151
152void
153	symlist_add __P((symlist_t *symlist, symbol_t *symbol, int how));
154#define SYMLIST_INSERT_HEAD	0x00
155#define SYMLIST_SORT		0x01
156
157void	symlist_free __P((symlist_t *symlist));
158
159void	symlist_merge __P((symlist_t *symlist_dest, symlist_t *symlist_src1,
160			   symlist_t *symlist_src2));
161void	symtable_dump __P((FILE *ofile));
162