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