162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Aic7xxx SCSI host adapter firmware assembler symbol table definitions
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 1997 Justin T. Gibbs.
562306a36Sopenharmony_ci * Copyright (c) 2002 Adaptec Inc.
662306a36Sopenharmony_ci * All rights reserved.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
962306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
1062306a36Sopenharmony_ci * are met:
1162306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1262306a36Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
1362306a36Sopenharmony_ci *    without modification.
1462306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1562306a36Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
1662306a36Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
1762306a36Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
1862306a36Sopenharmony_ci *    binary redistribution.
1962306a36Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
2062306a36Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
2162306a36Sopenharmony_ci *    from this software without specific prior written permission.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2462306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2562306a36Sopenharmony_ci * Software Foundation.
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * NO WARRANTY
2862306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2962306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3062306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3162306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3262306a36Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3362306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3462306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3562306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3662306a36Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3762306a36Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3862306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.h#17 $
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * $FreeBSD$
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#include "../queue.h"
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_citypedef enum {
4862306a36Sopenharmony_ci	UNINITIALIZED,
4962306a36Sopenharmony_ci	REGISTER,
5062306a36Sopenharmony_ci	ALIAS,
5162306a36Sopenharmony_ci	SCBLOC,
5262306a36Sopenharmony_ci	SRAMLOC,
5362306a36Sopenharmony_ci	ENUM_ENTRY,
5462306a36Sopenharmony_ci	FIELD,
5562306a36Sopenharmony_ci	MASK,
5662306a36Sopenharmony_ci	ENUM,
5762306a36Sopenharmony_ci	CONST,
5862306a36Sopenharmony_ci	DOWNLOAD_CONST,
5962306a36Sopenharmony_ci	LABEL,
6062306a36Sopenharmony_ci	CONDITIONAL,
6162306a36Sopenharmony_ci	MACRO
6262306a36Sopenharmony_ci} symtype;
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_citypedef enum {
6562306a36Sopenharmony_ci	RO = 0x01,
6662306a36Sopenharmony_ci	WO = 0x02,
6762306a36Sopenharmony_ci	RW = 0x03
6862306a36Sopenharmony_ci}amode_t;
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_citypedef SLIST_HEAD(symlist, symbol_node) symlist_t;
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_cistruct reg_info {
7362306a36Sopenharmony_ci	u_int	  address;
7462306a36Sopenharmony_ci	int	  size;
7562306a36Sopenharmony_ci	amode_t	  mode;
7662306a36Sopenharmony_ci	symlist_t fields;
7762306a36Sopenharmony_ci	uint8_t	  valid_bitmask;
7862306a36Sopenharmony_ci	uint8_t	  modes;
7962306a36Sopenharmony_ci	int	  typecheck_masks;
8062306a36Sopenharmony_ci};
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistruct field_info {
8362306a36Sopenharmony_ci	symlist_t symrefs;
8462306a36Sopenharmony_ci	uint8_t	  value;
8562306a36Sopenharmony_ci	uint8_t	  mask;
8662306a36Sopenharmony_ci};
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_cistruct const_info {
8962306a36Sopenharmony_ci	u_int	value;
9062306a36Sopenharmony_ci	int	define;
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cistruct alias_info {
9462306a36Sopenharmony_ci	struct symbol *parent;
9562306a36Sopenharmony_ci};
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_cistruct label_info {
9862306a36Sopenharmony_ci	int	address;
9962306a36Sopenharmony_ci	int	exported;
10062306a36Sopenharmony_ci};
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistruct cond_info {
10362306a36Sopenharmony_ci	int	func_num;
10462306a36Sopenharmony_ci};
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistruct macro_arg {
10762306a36Sopenharmony_ci	STAILQ_ENTRY(macro_arg)	links;
10862306a36Sopenharmony_ci	regex_t	arg_regex;
10962306a36Sopenharmony_ci	char   *replacement_text;
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ciSTAILQ_HEAD(macro_arg_list, macro_arg);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_cistruct macro_info {
11462306a36Sopenharmony_ci	struct macro_arg_list args;
11562306a36Sopenharmony_ci	int   narg;
11662306a36Sopenharmony_ci	const char* body;
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_citypedef struct expression_info {
12062306a36Sopenharmony_ci        symlist_t       referenced_syms;
12162306a36Sopenharmony_ci        int             value;
12262306a36Sopenharmony_ci} expression_t;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_citypedef struct symbol {
12562306a36Sopenharmony_ci	char	*name;
12662306a36Sopenharmony_ci	symtype	type;
12762306a36Sopenharmony_ci	int	count;
12862306a36Sopenharmony_ci	union	{
12962306a36Sopenharmony_ci		struct reg_info	  *rinfo;
13062306a36Sopenharmony_ci		struct field_info *finfo;
13162306a36Sopenharmony_ci		struct const_info *cinfo;
13262306a36Sopenharmony_ci		struct alias_info *ainfo;
13362306a36Sopenharmony_ci		struct label_info *linfo;
13462306a36Sopenharmony_ci		struct cond_info  *condinfo;
13562306a36Sopenharmony_ci		struct macro_info *macroinfo;
13662306a36Sopenharmony_ci	} info;
13762306a36Sopenharmony_ci	int	dont_generate_debug_code;
13862306a36Sopenharmony_ci} symbol_t;
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_citypedef struct symbol_ref {
14162306a36Sopenharmony_ci	symbol_t *symbol;
14262306a36Sopenharmony_ci	int	 offset;
14362306a36Sopenharmony_ci} symbol_ref_t;
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_citypedef struct symbol_node {
14662306a36Sopenharmony_ci	SLIST_ENTRY(symbol_node) links;
14762306a36Sopenharmony_ci	symbol_t *symbol;
14862306a36Sopenharmony_ci} symbol_node_t;
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_citypedef struct critical_section {
15162306a36Sopenharmony_ci	TAILQ_ENTRY(critical_section) links;
15262306a36Sopenharmony_ci	int begin_addr;
15362306a36Sopenharmony_ci	int end_addr;
15462306a36Sopenharmony_ci} critical_section_t;
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_citypedef enum {
15762306a36Sopenharmony_ci	SCOPE_ROOT,
15862306a36Sopenharmony_ci	SCOPE_IF,
15962306a36Sopenharmony_ci	SCOPE_ELSE_IF,
16062306a36Sopenharmony_ci	SCOPE_ELSE
16162306a36Sopenharmony_ci} scope_type;
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_citypedef struct patch_info {
16462306a36Sopenharmony_ci	int skip_patch;
16562306a36Sopenharmony_ci	int skip_instr;
16662306a36Sopenharmony_ci} patch_info_t;
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_citypedef struct scope {
16962306a36Sopenharmony_ci	SLIST_ENTRY(scope) scope_stack_links;
17062306a36Sopenharmony_ci	TAILQ_ENTRY(scope) scope_links;
17162306a36Sopenharmony_ci	TAILQ_HEAD(, scope) inner_scope;
17262306a36Sopenharmony_ci	scope_type type;
17362306a36Sopenharmony_ci	int inner_scope_patches;
17462306a36Sopenharmony_ci	int begin_addr;
17562306a36Sopenharmony_ci        int end_addr;
17662306a36Sopenharmony_ci	patch_info_t patches[2];
17762306a36Sopenharmony_ci	int func_num;
17862306a36Sopenharmony_ci} scope_t;
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ciTAILQ_HEAD(cs_tailq, critical_section);
18162306a36Sopenharmony_ciSLIST_HEAD(scope_list, scope);
18262306a36Sopenharmony_ciTAILQ_HEAD(scope_tailq, scope);
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_civoid	symbol_delete(symbol_t *symbol);
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_civoid	symtable_open(void);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_civoid	symtable_close(void);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_cisymbol_t *
19162306a36Sopenharmony_ci	symtable_get(char *name);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cisymbol_node_t *
19462306a36Sopenharmony_ci	symlist_search(symlist_t *symlist, char *symname);
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_civoid
19762306a36Sopenharmony_ci	symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
19862306a36Sopenharmony_ci#define SYMLIST_INSERT_HEAD	0x00
19962306a36Sopenharmony_ci#define SYMLIST_SORT		0x01
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_civoid	symlist_free(symlist_t *symlist);
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_civoid	symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
20462306a36Sopenharmony_ci		      symlist_t *symlist_src2);
20562306a36Sopenharmony_civoid	symtable_dump(FILE *ofile, FILE *dfile);
206