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