* as/link/lkar.h: sgetl and sputl are independent of endianness
[fw/sdcc] / as / z80 / asdata.c
1 /* asdata.c */
2
3 /*
4  * (C) Copyright 1989-1995
5  * All Rights Reserved
6  *
7  * Alan R. Baldwin
8  * 721 Berkeley St.
9  * Kent, Ohio  44240
10  */
11
12 #include <stdio.h>
13 #include <setjmp.h>
14 #include <string.h>
15
16 #include "asm.h"
17
18 /*)Module       asdata.c
19  *
20  *      The module asdata.c contains the global constants,
21  *      structures, and variables used in the assembler.
22  */
23
24 int     aserr;          /*      ASxxxx error counter
25                          */
26 jmp_buf jump_env;       /*      compiler dependent structure
27                          *      used by setjmp() and longjmp()
28                          */
29 int     inpfil;         /*      count of assembler
30                          *      input files specified
31                          */
32 int     incfil;         /*      current file handle index
33                          *      for include files
34                          */
35 int     cfile;          /*      current file handle index
36                          *      of input assembly files
37                          */
38 int     flevel;         /*      IF-ELSE-ENDIF flag will be non
39                          *      zero for false conditional case
40                          */
41 int     tlevel;         /*      current conditional level
42                          */
43 int     ifcnd[MAXIF+1]; /*      array of IF statement condition
44                          *      values (0 = FALSE) indexed by tlevel
45                          */
46 int     iflvl[MAXIF+1]; /*      array of IF-ELSE-ENDIF flevel
47                          *      values indexed by tlevel
48                          */
49
50 char    afn[FILSPC];            /*      afile temporary file name
51                                  */
52 char    srcfn[MAXFIL][FILSPC];  /*      array of source file names
53                                  */
54 int     srcline[MAXFIL];        /*      source line number
55                                  */
56 char    incfn[MAXINC][FILSPC];  /*      array of include file names
57                                  */
58 int     incline[MAXINC];        /*      include line number
59                                  */
60
61 int     radix;          /*      current number conversion radix:
62                          *      2 (binary), 8 (octal), 10 (decimal),
63                          *      16 (hexadecimal)
64                          */
65 int     line;           /*      current assembler source
66                          *      line number
67                          */
68 int     page;           /*      current page number
69                          */
70 int     lop;            /*      current line number on page
71                          */
72 int     pass;           /*      assembler pass number
73                          */
74 int     lflag;          /*      -l, generate listing flag
75                          */
76 int     cflag;          /*      -c, generate sdcdb debug info
77                          */
78 int     gflag;          /*      -g, make undefined symbols global flag
79                          */
80 int     aflag;          /*      -a, make all symbols global flag
81                          */
82 int     jflag;          /*      -j, generate debug information flag
83                          */
84 int     oflag;          /*      -o, generate relocatable output flag
85                          */
86 int     sflag;          /*      -s, generate symbol table flag
87                          */
88 int     pflag;          /*      -p, enable listing pagination
89                          */
90 int     xflag;          /*      -x, listing radix flag
91                          */
92 int     fflag;          /*      -f(f), relocations flagged flag
93                          */
94 Addr_T  laddr;          /*      address of current assembler line
95                          *      or value of .if argument
96                          */
97 Addr_T  fuzz;           /*      tracks pass to pass changes in the
98                          *      address of symbols caused by
99                          *      variable length instruction formats
100                          */
101 int     lmode;          /*      listing mode
102                          */
103 char    *ep;            /*      pointer into error list
104                          *      array eb[NERR]
105                          */
106 char    eb[NERR];       /*      array of generated error codes
107                          */
108 const char *ip;         /*      pointer into the assembler-source
109                          *      text line in ib[]
110                          */
111 const char *ib;         /*      assembler-source text line
112                          */
113 char    *cp;            /*      pointer to assembler output
114                          *      array cb[]
115                          */
116 char    cb[NCODE];      /*      array of assembler output values
117                          */
118 int     *cpt;           /*      pointer to assembler relocation type
119                          *      output array cbt[]
120                          */
121 int     cbt[NCODE];     /*      array of assembler relocation types
122                          *      describing the data in cb[]
123                          */
124 char    tb[NTITL];      /*      Title string buffer
125                          */
126 char    stb[NSBTL];     /*      Subtitle string buffer
127                          */
128 char    optsdcc[NINPUT];        /*      sdcc compile options
129                          */
130
131 char    symtbl[] = { "Symbol Table" };
132 char    aretbl[] = { "Area Table" };
133
134 char    module[NCPS];   /*      module name string
135                          */
136
137 /*
138  *      The mne structure is a linked list of the assembler
139  *      mnemonics and directives.  The list of mnemonics and
140  *      directives contained in the device dependent file
141  *      xxxpst.c are hashed and linked into NHASH lists in
142  *      module assym.c by syminit().  The structure contains
143  *      the mnemonic/directive name, a subtype which directs
144  *      the evaluation of this mnemonic/directive, a flag which
145  *      is used to detect the end of the mnemonic/directive
146  *      list in xxxpst.c, and a value which is normally
147  *      associated with the assembler mnemonic base instruction
148  *      value.
149  *
150  *      struct  mne
151  *      {
152  *              struct  mne *m_mp;      Hash link
153  *              char    *m_id;          Mnemonic
154  *              char    m_type;         Mnemonic subtype
155  *              char    m_flag;         Mnemonic flags
156  *              Addr_T  m_valu;         Value
157  *      };
158  */
159 struct  mne     *mnehash[NHASH];
160
161 /*
162  *      The sym structure is a linked list of symbols defined
163  *      in the assembler source files.  The first symbol is "."
164  *      defined here.  The entry 'struct tsym *s_tsym'
165  *      links any temporary symbols following this symbol and
166  *      preceeding the next normal symbol.  The structure also
167  *      contains the symbol's name, type (USER or NEW), flag
168  *      (global, assigned, and multiply defined), a pointer
169  *      to the area structure defining where the symbol is
170  *      located, a reference number assigned by outgsd() in
171  *      asout.c, and the symbols address relative to the base
172  *      address of the area where the symbol is located.
173  *
174  *      struct  sym
175  *      {
176  *              struct  sym  *s_sp;     Hash link
177  *              struct  tsym *s_tsym;   Temporary symbol link
178  *              char    *s_id;          Symbol
179  *              char    s_type;         Symbol subtype
180  *              char    s_flag;         Symbol flags
181  *              struct  area *s_area;   Area line, 0 if absolute
182  *              int     s_ref;          Ref. number
183  *              Addr_T  s_addr;         Address
184  *      };
185  */
186 struct  sym     sym[] = {
187     { NULL,     NULL,   ".",    S_USER, S_END,  NULL,   0, }
188 };
189
190 struct  sym     *symp;          /*      pointer to a symbol structure
191                                  */
192 struct  sym *symhash[NHASH];    /*      array of pointers to NHASH
193                                  *      linked symbol lists
194                                  */
195
196 /*
197  *      The area structure contains the parameter values for a
198  *      specific program or data section.  The area structure
199  *      is a linked list of areas.  The initial default area
200  *      is "_CODE" defined here, the next area structure
201  *      will be linked to this structure through the structure
202  *      element 'struct area *a_ep'.  The structure contains the
203  *      area name, area reference number ("_CODE" is 0) determined
204  *      by the order of .area directives, area size determined
205  *      from the total code and/or data in an area, area fuzz is
206  *      an variable used to track pass to pass changes in the
207  *      area size caused by variable length instruction formats,
208  *      and area flags which specify the area's relocation type.
209  *
210  *      struct  area
211  *      {
212  *              struct  area *a_ap;     Area link
213  *              char    *a_id;          Area Name
214  *              int     a_ref;          Reference number
215  *              Addr_T  a_size;         Area size
216  *              Addr_T  a_fuzz;         Area fuzz
217  *              int     a_flag;         Area flags
218  *      };
219  */
220 struct  area    area[] = {
221     { NULL,     "_CODE",        0,      0,      0,      A_CON|A_REL }
222 };
223
224 struct  area    *areap; /*      pointer to an area structure
225                          */
226
227 FILE    *lfp;           /*      list output file handle
228                          */
229 FILE    *ofp;           /*      relocation output file handle
230                          */
231 FILE    *tfp;           /*      symbol table output file handle
232                          */
233 FILE    *sfp[MAXFIL];   /*      array of assembler-source file handles
234                          */
235 FILE    *ifp[MAXINC];   /*      array of include-file file handles
236                          */
237
238 /*
239  *      array of character types, one per
240  *      ASCII character
241  */
242 unsigned char   ctype[128] = {
243 /*NUL*/ ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,
244 /*BS*/  ILL,    SPACE,  ILL,    ILL,    SPACE,  ILL,    ILL,    ILL,
245 /*DLE*/ ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,
246 /*CAN*/ ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,    ILL,
247 /*SPC*/ SPACE,  ETC,    ETC,    ETC,    LETTER, BINOP,  BINOP,  ETC,
248 /*(*/   ETC,    ETC,    BINOP,  BINOP,  ETC,    BINOP,  LETTER, BINOP,
249 /*0*/   DGT2,   DGT2,   DGT8,   DGT8,   DGT8,   DGT8,   DGT8,   DGT8,
250 /*8*/   DGT10,  DGT10,  ETC,    ETC,    BINOP,  ETC,    BINOP,  ETC,
251 /*@*/   ETC,    LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LETTER,
252 /*H*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
253 /*P*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
254 /*X*/   LETTER, LETTER, LETTER, ETC,    ETC,    ETC,    BINOP,  LETTER,
255 /*`*/   ETC,    LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LTR16,  LETTER,
256 /*h*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
257 /*p*/   LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
258 /*x*/   LETTER, LETTER, LETTER, ETC,    BINOP,  ETC,    ETC,    ETC
259 };
260
261 /*
262  *      an array of characters which
263  *      perform the case translation function
264  */
265 char    ccase[128] = {
266 /*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
267 /*BS*/  '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
268 /*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
269 /*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
270 /*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
271 /*(*/   '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
272 /*0*/   '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
273 /*8*/   '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
274 /*@*/   '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
275 /*H*/   '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
276 /*P*/   '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
277 /*X*/   '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
278 /*`*/   '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
279 /*h*/   '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
280 /*p*/   '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
281 /*x*/   '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'
282 };