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