aicasm_symbol.h revision 23925
1178825Sdfr/*
2233294Sstas * Aic7xxx SCSI host adapter firmware asssembler symbol table definitions
3233294Sstas *
4233294Sstas * Copyright (c) 1997 Justin T. Gibbs.
5178825Sdfr * All rights reserved.
6233294Sstas *
7233294Sstas * Redistribution and use in source and binary forms, with or without
8233294Sstas * modification, are permitted provided that the following conditions
9178825Sdfr * are met:
10233294Sstas * 1. Redistributions of source code must retain the above copyright
11233294Sstas *    notice immediately at the beginning of the file, without modification,
12178825Sdfr *    this list of conditions, and the following disclaimer.
13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
14233294Sstas *    notice, this list of conditions and the following disclaimer in the
15233294Sstas *    documentation and/or other materials provided with the distribution.
16178825Sdfr * 3. The name of the author may not be used to endorse or promote products
17233294Sstas *    derived from this software without specific prior written permission.
18233294Sstas *
19233294Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20178825Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22233294Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23233294Sstas * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29233294Sstas * SUCH DAMAGE.
30233294Sstas *
31233294Sstas *      $Id$
32178825Sdfr */
33178825Sdfr
34178825Sdfr#include <sys/queue.h>
35178825Sdfr
36178825Sdfrtypedef enum {
37178825Sdfr	UNINITIALIZED,
38178825Sdfr	REGISTER,
39178825Sdfr	ALIAS,
40233294Sstas	SCBLOC,
41178825Sdfr	SRAMLOC,
42178825Sdfr	MASK,
43178825Sdfr	BIT,
44178825Sdfr	CONST,
45233294Sstas	LABEL,
46178825Sdfr	CONDITIONAL
47178825Sdfr}symtype;
48178825Sdfr
49178825Sdfrtypedef enum {
50233294Sstas	RO = 0x01,
51178825Sdfr	WO = 0x02,
52178825Sdfr	RW = 0x03
53178825Sdfr}amode_t;
54233294Sstas
55233294Sstasstruct reg_info {
56233294Sstas	u_int8_t address;
57178825Sdfr	int	 size;
58178825Sdfr	amode_t	 mode;
59178825Sdfr	u_int8_t valid_bitmask;
60178825Sdfr	int	 typecheck_masks;
61178825Sdfr};
62178825Sdfr
63178825Sdfrtypedef SLIST_HEAD(symlist, symbol_node) symlist_t;
64178825Sdfr
65178825Sdfrstruct mask_info {
66233294Sstas	symlist_t symrefs;
67178825Sdfr	u_int8_t mask;
68178825Sdfr};
69178825Sdfr
70178825Sdfrstruct const_info {
71178825Sdfr	u_int8_t value;
72233294Sstas	int	 define;
73178825Sdfr};
74178825Sdfr
75178825Sdfrstruct alias_info {
76178825Sdfr	struct symbol *parent;
77178825Sdfr};
78178825Sdfr
79178825Sdfrstruct label_info {
80178825Sdfr	int	address;
81178825Sdfr};
82178825Sdfr
83178825Sdfrstruct cond_info {
84233294Sstas	int	value;
85233294Sstas};
86178825Sdfr
87178825Sdfrtypedef struct expression_info {
88178825Sdfr        symlist_t       referenced_syms;
89178825Sdfr        int             value;
90178825Sdfr} expression_t;
91178825Sdfr
92178825Sdfrtypedef struct symbol {
93178825Sdfr	char	*name;
94178825Sdfr	symtype	type;
95178825Sdfr	union	{
96178825Sdfr		struct reg_info *rinfo;
97233294Sstas		struct mask_info *minfo;
98178825Sdfr		struct const_info *cinfo;
99178825Sdfr		struct alias_info *ainfo;
100178825Sdfr		struct label_info *linfo;
101178825Sdfr		struct cond_info *condinfo;
102178825Sdfr	}info;
103233294Sstas} symbol_t;
104178825Sdfr
105178825Sdfrtypedef struct symbol_ref {
106178825Sdfr	symbol_t *symbol;
107178825Sdfr	int	 offset;
108178825Sdfr} symbol_ref_t;
109178825Sdfr
110178825Sdfrtypedef struct symbol_node {
111178825Sdfr	SLIST_ENTRY(symbol_node) links;
112178825Sdfr	symbol_t *symbol;
113178825Sdfr}symbol_node_t;
114178825Sdfr
115233294Sstastypedef struct patch {
116178825Sdfr        STAILQ_ENTRY(patch) links;
117178825Sdfr	int	  negative;
118178825Sdfr	int	  begin;
119178825Sdfr        int	  end;
120178825Sdfr	int	  options;
121178825Sdfr} patch_t;
122233294Sstas
123233294Sstasvoid	symbol_delete __P((symbol_t *symbol));
124178825Sdfr
125178825Sdfrvoid	symtable_open __P((void));
126178825Sdfr
127178825Sdfrvoid	symtable_close __P((void));
128178825Sdfr
129178825Sdfrsymbol_t *
130178825Sdfr	symtable_get __P((char *name));
131178825Sdfr
132178825Sdfrsymbol_node_t *
133178825Sdfr	symlist_search __P((symlist_t *symlist, char *symname));
134178825Sdfr
135178825Sdfrvoid
136178825Sdfr	symlist_add __P((symlist_t *symlist, symbol_t *symbol, int how));
137178825Sdfr#define SYMLIST_INSERT_HEAD	0x00
138233294Sstas#define SYMLIST_SORT		0x01
139233294Sstas
140178825Sdfrvoid	symlist_free __P((symlist_t *symlist));
141178825Sdfr
142178825Sdfrvoid	symlist_merge __P((symlist_t *symlist_dest, symlist_t *symlist_src1,
143178825Sdfr			   symlist_t *symlist_src2));
144178825Sdfrvoid	symtable_dump __P((FILE *ofile));
145178825Sdfr