1 /****************************************************************************
2 *
3 *                            Open Watcom Project
4 *
5 *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6 *
7 *  ========================================================================
8 *
9 *    This file contains Original Code and/or Modifications of Original
10 *    Code as defined in and that are subject to the Sybase Open Watcom
11 *    Public License version 1.0 (the 'License'). You may not use this file
12 *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13 *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14 *    provided with the Original Code and Modifications, and is also
15 *    available at www.sybase.com/developer/opensource.
16 *
17 *    The Original Code and all software distributed under the License are
18 *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20 *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22 *    NON-INFRINGEMENT. Please see the License for the specific language
23 *    governing rights and limitations under the License.
24 *
25 *  ========================================================================
26 *
27 * Description:  JWasm globals and limits.
28 *
29 ****************************************************************************/
30 
31 
32 #ifndef _GLOBALS_H_INCLUDED
33 #define _GLOBALS_H_INCLUDED
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <errno.h> /* needed for errno declaration ( "sometimes" it's defined in stdlib.h ) */
39 
40 #if defined(__UNIX__) || defined(__CYGWIN__) || defined(__DJGPP__) /* avoid for MinGW! */
41 
42 #define _stricmp strcasecmp
43 #ifndef __WATCOMC__
44 #define _memicmp strncasecmp
45 #endif
46 #define _ltoa   ltoa
47 #define _strupr strupr
48 char *strupr(char *);
49 
50 #elif defined(__POCC__)
51 
52 #pragma warn(disable:2030) /* disable '=' used in a conditional expression */
53 #pragma warn(disable:2229) /* disable 'local x is potentially used without ...' */
54 #pragma warn(disable:2231) /* disable 'enum value x not handled in switch statement' */
55 
56 #elif defined(__BORLANDC__) || defined(__OCC__)
57 
58 #define _stricmp  stricmp
59 #define _strnicmp strnicmp
60 #define _strupr   strupr
61 #define _memicmp  memicmp
62 
63 #endif
64 
65 #define MAX_LINE_LEN            600  /* no restriction for this number */
66 #define MAX_TOKEN  MAX_LINE_LEN / 4  /* max tokens in one line */
67 #define MAX_STRING_LEN          MAX_LINE_LEN - 32 /* must be < MAX_LINE_LEN */
68 #define MAX_ID_LEN              247  /* must be < MAX_LINE_LEN */
69 #define MAX_STRUCT_ALIGN        32
70 /* v2.06: obsolete */
71 //#define MAX_RESW_LEN            31 /* max length of a reserved word */
72 
73 #define MAX_IF_NESTING          20 /* IFxx block nesting. Must be <=32, see condasm.c */
74 //#define MAX_TEXTMACRO_NESTING   20
75 #define MAX_SEG_NESTING         20 /* limit for segment nesting  */
76 #ifdef __I86__
77 #define MAX_MACRO_NESTING       20
78 #else
79 #define MAX_MACRO_NESTING       40 /* macro call nesting  */
80 #endif
81 #define MAX_STRUCT_NESTING      32 /* limit for "anonymous structs" only */
82 
83 #define MAX_LNAME              255 /* OMF lnames - length must fit in 1 byte */
84 #define LNAME_NULL             0   /* OMF first entry in lnames array */
85 
86 /* output format switches */
87 #ifndef BIN_SUPPORT
88 #define BIN_SUPPORT  1 /* support BIN output format              */
89 #endif
90 #if BIN_SUPPORT
91 #ifndef MZ_SUPPORT
92 #define MZ_SUPPORT   1 /* support DOS MZ binary format           */
93 #endif
94 #ifndef PE_SUPPORT
95 #define PE_SUPPORT   1 /* support PE32 + PE64 binary format      */
96 #endif
97 #else
98 #define MZ_SUPPORT 0 /* both MZ and PE need BIN==1 */
99 #define PE_SUPPORT 0
100 #endif
101 
102 #ifndef COFF_SUPPORT
103 #define COFF_SUPPORT 1 /* support COFF output format             */
104 #endif
105 #ifndef DJGPP_SUPPORT
106 #define DJGPP_SUPPORT 0 /* support for Djgpp COFF variant        */
107 #endif
108 #ifndef ELF_SUPPORT
109 #define ELF_SUPPORT  1 /* support ELF output format              */
110 #endif
111 
112 /* instruction set switches */
113 #define K3DSUPP      1 /* support K3D instruction set            */
114 #define SSE3SUPP     1 /* support SSE3 instruction set           */
115 #ifndef AMD64_SUPPORT
116 #define AMD64_SUPPORT 1 /* 1=support 64bit */
117 #endif
118 #ifndef VMXSUPP
119 #define VMXSUPP      1 /* support VMX extensions                 */
120 #endif
121 #ifndef SVMSUPP
122 #define SVMSUPP      0 /* support SVM (=AMD-V) extensions        */
123 #endif
124 #ifndef SSSE3SUPP
125 #define SSSE3SUPP    1 /* support SSSE3 instruction set          */
126 #endif
127 #ifndef SSE4SUPP
128 #define SSE4SUPP     1 /* support SSE4 instruction set           */
129 #endif
130 #ifndef AVXSUPP
131 #define AVXSUPP      1 /* support AVX extensions                 */
132 #endif
133 #ifndef COMDATSUPP
134 #define COMDATSUPP   1 /* support COMDAT segment attribute       */
135 #endif
136 
137 /* other extension switches */
138 #define IMAGERELSUPP 1 /* support IMAGEREL operator (not for OMF) */
139 #define SECTIONRELSUPP 1 /* support SECTIONREL operator (not for OMF) */
140 #define FIELDALIGN   1 /* support OPTION FIELDALIGN:<const>      */
141 #define PROCALIGN    1 /* support OPTION PROCALIGN:<const>       */
142 #define LOHI32       1 /* support LOW32/HIGH32 operators         */
143 #define XMMWORD      1 /* support MMWORD and XMMWORD types       */
144 #define RENAMEKEY    1 /* support OPTION RENAMEKEYWORD:<old>,new */
145 #define MACROLABEL   1 /* support LABEL qualifier for macro arg  */
146 #define BACKQUOTES   1 /* allow IDs enclosed in `                */
147 #define FPIMMEDIATE  1 /* allow float immediates: mov eax,1.0    */
148 #define INCBINSUPP   1 /* support INCBIN directive               */
149 #define INTELMOVQ    0 /* 1=MOVQ moves to/from 64-bit registers  */
150 #ifndef OWFC_SUPPORT
151 #define OWFC_SUPPORT 1 /* support OW fastcall flavor             */
152 #endif
153 #ifndef DLLIMPORT
154 #define DLLIMPORT    1 /* support OPTION DLLIMPORT               */
155 #endif
156 #ifndef CVOSUPP
157 #define CVOSUPP      1 /* support OPTION CODEVIEW                */
158 #endif
159 #define MASM_SSE_MEMX 1 /* support 2 mem types for mmx/xmm       */
160 #define PERCENT_OUT 1  /* 1=support %OUT directive               */
161 #ifndef STACKBASESUPP
162 #define STACKBASESUPP 1 /* support OPTION STACKBASE              */
163 #endif
164 #define VARARGML 1    /* multi line vararg for macros */
165 
166 /* old Wasm extensions */
167 #define PAGE4K       0 /* support 4kB-page OMF segment alignment */
168 #define BUILD_TARGET 0 /* support "build target" (obsolete)   */
169 #define COCTALS      0 /* allow C form of octals              */
170 #define CHEXPREFIX   0 /* accept "0x" as hex number prefix    */
171 #define MANGLERSUPP  0 /* support Wasm's "mangler" extension  */
172 
173 /* internal assembler optimizations */
174 #ifndef FASTPASS
175 #define FASTPASS     1 /* don't scan full source if pass > 1  */
176 #endif
177 #ifndef FASTMEM
178 #define FASTMEM      1 /* fast memory allocation              */
179 #endif
180 
181 #include "inttype.h"
182 #include "bool.h"
183 #include "errmsg.h"  /* must be located AFTER #defines lines */
184 #include "queue.h"
185 
186 /* JWasm version info */
187 #define _JWASM_VERSION_STR_ "2.14"
188 #define _JWASM_VERSION_INT_ 214
189 #define _JWASM_VERSION_SUFFIX_ ""
190 #define _JWASM_VERSION_ _JWASM_VERSION_STR_ _JWASM_VERSION_SUFFIX_
191 
192 #define NULLC  '\0'
193 //#define NULLS  ""
194 
195 #define is_valid_id_char( ch )  ( isalnum(ch) || ch=='_' || ch=='@' || ch=='$' || ch=='?' )
196 #define is_valid_id_first_char( ch )  ( isalpha(ch) || ch=='_' || ch=='@' || ch=='$' || ch=='?' || (ch == '.' && ModuleInfo.dotname == TRUE ))
197 
198 /* function return values */
199 
200 typedef enum {
201  EMPTY = -2,
202  ERROR = -1,
203  NOT_ERROR = 0,
204  STRING_EXPANDED = 1
205 } ret_code;
206 
207 enum {
208     PASS_1 = 0,
209     PASS_2
210 };
211 
212 /* enumerations */
213 
214 /* output formats. Order must match formatoptions[] in assemble.c */
215 enum oformat {
216 #if BIN_SUPPORT
217     OFORMAT_BIN, /* used by -bin, -mz and -pe */
218 #endif
219     OFORMAT_OMF,
220 #if COFF_SUPPORT
221     OFORMAT_COFF,/* used by -coff, -djgpp and -win64 */
222 #endif
223 #if ELF_SUPPORT
224     OFORMAT_ELF, /* used by -elf and elf64 */
225 #endif
226 };
227 
228 enum sformat {
229     SFORMAT_NONE,
230 #if MZ_SUPPORT
231     SFORMAT_MZ,    /* MZ binary */
232 #endif
233 #if PE_SUPPORT
234     SFORMAT_PE,    /* PE (32- or 64-bit) binary */
235 #endif
236 #if COFF_SUPPORT
237  #if DJGPP_SUPPORT
238     SFORMAT_DJGPP, /* Djgpp variant of COFF */
239  #endif
240 #endif
241 #if COFF_SUPPORT || ELF_SUPPORT
242  #if AMD64_SUPPORT
243     SFORMAT_64BIT, /* 64bit COFF or ELF */
244  #endif
245 #endif
246 };
247 
248 enum fpo {
249     FPO_NO_EMULATION,  /* -FPi87 (default) */
250     FPO_EMULATION      /* -FPi */
251 };
252 
253 /* language vaules.
254  * the order cannot be changed, it's
255  * returned by OPATTR and used in user-defined prologue/epilogue.
256  */
257 enum lang_type {
258     LANG_NONE     = 0,
259     LANG_C        = 1,
260     LANG_SYSCALL  = 2,
261     LANG_STDCALL  = 3,
262     LANG_PASCAL   = 4,
263     LANG_FORTRAN  = 5,
264     LANG_BASIC    = 6,
265     LANG_FASTCALL = 7
266 };
267 
268 /* Memory model type.
269  * the order cannot be changed, it's
270  * the value of the predefined @Model symbol.
271  */
272 enum model_type {
273     MODEL_NONE    = 0,
274     MODEL_TINY    = 1,
275     MODEL_SMALL   = 2,
276     MODEL_COMPACT = 3,
277     MODEL_MEDIUM  = 4,
278     MODEL_LARGE   = 5,
279     MODEL_HUGE    = 6,
280     MODEL_FLAT    = 7,
281 };
282 
283 #define SIZE_DATAPTR 0x68 /* far for COMPACT, LARGE, HUGE */
284 #define SIZE_CODEPTR 0x70 /* far for MEDIUM, LARGE, HUGE  */
285 
286 enum seg_order {
287     SEGORDER_SEQ = 0,  /* .SEQ (default) */
288     SEGORDER_DOSSEG,   /* .DOSSEG */
289     SEGORDER_ALPHA     /* .ALPHA */
290 };
291 
292 /* .NOLISTMACRO, .LISTMACRO and .LISTMACROALL directives setting */
293 enum listmacro {
294     LM_NOLISTMACRO,
295     LM_LISTMACRO,
296     LM_LISTMACROALL
297 };
298 
299 /* assume values are used as index in codegen.c / invoke.c.
300  * Order must match the one in special.h. Don't change!
301  */
302 enum assume_segreg {
303     ASSUME_NOTHING = EMPTY,
304     ASSUME_ES = 0,
305     ASSUME_CS,
306     ASSUME_SS,
307     ASSUME_DS,
308     ASSUME_FS,
309     ASSUME_GS
310 };
311 
312 enum cpu_info {
313     /* bit count from left:
314      * bit 0-2:   Math coprocessor
315      * bit 3:     privileged?
316      * bit 4-7:   cpu type
317      * bit 8-15;  extension set
318      */
319     P_NO87  = 0x0001,         /* no FPU */
320     P_87    = 0x0002,         /* 8087 */
321     P_287   = 0x0003,         /* 80287 */
322     P_387   = 0x0004,         /* 80387 */
323 
324     P_PM    = 0x0008,         /* privileged opcode */
325 
326     P_86    = 0x0000,         /* 8086, default */
327     P_186   = 0x0010,         /* 80186 */
328     P_286   = 0x0020,         /* 80286 */
329     P_386   = 0x0030,         /* 80386 */
330     P_486   = 0x0040,         /* 80486 */
331     P_586   = 0x0050,         /* pentium */
332     P_686   = 0x0060,         /* ppro */
333 #if AMD64_SUPPORT
334     P_64    = 0x0070,         /* x64 cpu */
335 #endif
336 
337     P_286p  = P_286 | P_PM,   /* 286, priv mode */
338     P_386p  = P_386 | P_PM,   /* 386, priv mode */
339     P_486p  = P_486 | P_PM,   /* 486, priv mode */
340     P_586p  = P_586 | P_PM,   /* 586, priv mode */
341     P_686p  = P_686 | P_PM,   /* 686, priv mode */
342 #if AMD64_SUPPORT
343     P_64p   = P_64 | P_PM,    /* x64, priv mode */
344 #endif
345 
346     P_MMX   = 0x0100,         /* MMX extension instructions */
347 #if K3DSUPP
348     P_K3D   = 0x0200,         /* 3DNow extension instructions */
349 #endif
350     P_SSE1  = 0x0400,         /* SSE1 extension instructions */
351     P_SSE2  = 0x0800,         /* SSE2 extension instructions */
352     P_SSE3  = 0x1000,         /* SSE3 extension instructions */
353 #if SSSE3SUPP
354     P_SSSE3 = 0x2000,         /* SSSE3 extension instructions */
355 #if SSE4SUPP
356     P_SSE4  = 0x4000,         /* SSE4 extension instructions */
357 #if AVXSUPP
358     P_AVX   = 0x8000,         /* AVX extension instructions */
359 #endif
360 #endif
361 #endif
362     /* all SSE extension instructions */
363 #if SSSE3SUPP
364  #if SSE4SUPP
365   #if AVXSUPP
366     P_SSEALL = P_SSE1 | P_SSE2 | P_SSE3 | P_SSSE3 | P_SSE4 | P_AVX,
367   #else
368     P_SSEALL = P_SSE1 | P_SSE2 | P_SSE3 | P_SSSE3 | P_SSE4,
369   #endif
370  #else
371     P_SSEALL = P_SSE1 | P_SSE2 | P_SSE3 | P_SSSE3,
372  #endif
373 #else
374     P_SSEALL = P_SSE1 | P_SSE2 | P_SSE3,
375 #endif
376     NO_OPPRFX = P_MMX | P_SSEALL,
377 
378     P_FPU_MASK = 0x0007,
379     P_CPU_MASK = 0x00F0,
380 
381 #if K3DSUPP
382     P_EXT_MASK = P_MMX | P_K3D | P_SSEALL,
383     P_EXT_ALL  = P_MMX | P_K3D | P_SSEALL
384 #else
385     P_EXT_MASK = P_MMX | P_SSEALL,
386     P_EXT_ALL  = P_MMX | P_SSEALL
387 #endif
388 };
389 
390 /* the MASM compatible @CPU value flags: */
391 enum masm_cpu {
392     M_8086 = 0x0001, /* 8086 */
393     M_186  = 0x0002, /* 186 */
394     M_286  = 0x0004, /* 286 */
395     M_386  = 0x0008, /* 386 */
396     M_486  = 0x0010, /* 486 */
397     M_586  = 0x0020, /* Pentium */
398     M_686  = 0x0040, /* PPro */
399     M_CPUMSK = 0x007F,
400     M_PROT = 0x0080, /* protected instructions ok */
401     M_8087 = 0x0100, /* 8087 */
402     M_287  = 0x0400, /* 287 */
403     M_387  = 0x0800  /* 387 */
404 };
405 
406 #if MANGLERSUPP
407 enum naming_types {
408     NC_DO_NOTHING,
409     /*  put uscores on the front of labels & the back of procedures.
410      * this is what the OW compiler does with /3r
411      */
412     NC_ADD_USCORES,
413     /* assume that the user manually put uscores as described above
414      * into the assembly file and take them off
415      */
416     NC_REMOVE_USCORES
417 };
418 #endif
419 
420 enum segofssize {
421     USE_EMPTY = 0xFE,
422     USE16 = 0, /* don't change values of USE16,USE32,USE64! */
423     USE32 = 1,
424 #if AMD64_SUPPORT
425     USE64 = 2
426 #endif
427 };
428 
429 /* fastcall types. if order is to be changed or entries
430  * added, also adjust tables in proc.c, mangle.c and probably invoke.c!
431  */
432 enum fastcall_type {
433     FCT_MSC,        /* MS 16-/32-bit fastcall (ax,dx,cx / ecx,edx) */
434 #if OWFC_SUPPORT
435     FCT_WATCOMC,    /* OW register calling convention (eax, ebx, ecx, edx) */
436 #endif
437 #if AMD64_SUPPORT
438     FCT_WIN64       /* Win64 fastcall convention (rcx, rdx, r8, r9) */
439 #endif
440 };
441 
442 enum stdcall_decoration {
443     STDCALL_FULL,
444     STDCALL_NONE,
445     STDCALL_HALF
446 };
447 
448 struct qitem {
449     void *next;
450     char value[1];
451 };
452 
453 /* file extensions. Order must match first entries in enum opt_names! */
454 enum file_extensions {
455     ASM, /* must be first; see SetFilenames() in assembly.c */
456     OBJ,
457     LST,
458     ERR,
459     NUM_FILE_TYPES
460 };
461 
462 /* first 4 entries must match enum file_extensions! */
463 enum opt_names {
464     OPTN_ASM_FN,
465     OPTN_OBJ_FN,              /* -Fo option */
466     OPTN_LST_FN,              /* -Fl option */
467     OPTN_ERR_FN,              /* -Fr option */
468 #if DLLIMPORT
469     OPTN_LNKDEF_FN,           /* -Fd option */
470 #endif
471     OPTN_MODULE_NAME,         /* -nm option */
472     OPTN_TEXT_SEG,            /* -nt option */
473     OPTN_DATA_SEG,            /* -nd option */
474     OPTN_CODE_CLASS,          /* -nc option */
475 #if BUILD_TARGET
476     OPTN_BUILD_TARGET,        /* -bt option */
477 #endif
478 #if MANGLERSUPP
479     OPTN_DEFNAME_MANGLER,
480 #endif
481     OPTN_LAST
482 };
483 
484 /* queues to store multiple cmdline switch values */
485 enum opt_queues {
486     OPTQ_FINCLUDE, /* -Fi option values */
487     OPTQ_MACRO,    /* -D option values */
488     OPTQ_INCPATH,  /* -I option values */
489     OPTQ_LAST
490 };
491 
492 enum prologue_epilogue_mode {
493     PEM_DEFAULT, /* must be value 0 */
494     PEM_MACRO,
495     PEM_NONE
496 };
497 
498 /* Stack distance */
499 enum dist_type {
500     //STACK_NONE,
501     STACK_NEAR,
502     STACK_FAR,
503 };
504 
505 /* Type of operating system */
506 enum os_type {
507     OPSYS_DOS,
508     OPSYS_OS2,
509 };
510 
511 enum offset_type {
512     OT_GROUP = 0,  /* OFFSET:GROUP (default, must be 0) */
513     OT_FLAT,       /* OFFSET:FLAT    */
514     OT_SEGMENT     /* OFFSET:SEGMENT */
515 };
516 
517 enum line_output_flags {
518     LOF_LISTED = 1, /* line written to .LST file */
519 #if FASTPASS
520     LOF_SKIPPOS  = 2, /* suppress setting list_pos */
521     //LOF_STORED = 2  /* line stored in line buffer for FASTPASS */
522 #endif
523 };
524 
525 /* flags for win64_flags */
526 enum win64_flag_values {
527     W64F_SAVEREGPARAMS = 0x01, /* 1=save register params in shadow space on proc entry */
528     W64F_AUTOSTACKSP   = 0x02, /* 1=calculate required stack space for arguments of INVOKE */
529     W64F_STACKALIGN16  = 0x04, /* 1=stack variables are 16-byte aligned; added in v2.12 */
530     W64F_ALL = W64F_SAVEREGPARAMS | W64F_AUTOSTACKSP | W64F_STACKALIGN16, /* all valid flags */
531 };
532 
533 /* codeview debug info extend */
534 enum cvex_values {
535     CVEX_MIN     = 0, /* globals */
536     CVEX_REDUCED = 1, /* globals and locals */
537     CVEX_NORMAL  = 2, /* globals, locals and types */
538     CVEX_MAX     = 3, /* globals, locals, types and constants */
539 };
540 
541 /* codeview debug info option flags */
542 enum cvoption_flags {
543     CVO_STATICTLS = 1, /* handle static tls */
544 };
545 
546 enum seg_type {
547     SEGTYPE_UNDEF,
548     SEGTYPE_CODE,
549     SEGTYPE_DATA,
550     SEGTYPE_BSS,
551     SEGTYPE_STACK,
552     SEGTYPE_ABS,
553 #if PE_SUPPORT
554     SEGTYPE_HDR,   /* only used in bin.c for better sorting */
555     SEGTYPE_CDATA, /* only used in bin.c for better sorting */
556     SEGTYPE_RELOC, /* only used in bin.c for better sorting */
557     SEGTYPE_RSRC,  /* only used in bin.c for better sorting */
558     SEGTYPE_ERROR, /* must be last - an "impossible" segment type */
559 #endif
560 };
561 
562 struct global_options {
563     bool        quiet;                 /* -q option */
564     bool        line_numbers;          /* -Zd option */
565     uint_8      debug_symbols;         /* -Zi option */
566     uint_8      debug_ext;             /* -Zi option numeric argument */
567     enum fpo    floating_point;        /* -FPi, -FPi87 */
568 
569     /* error handling stuff */
570     int         error_limit;             /* -e option  */
571     uint_8      no_error_disp;           /* -eq option */
572     uint_8      warning_level;           /* -Wn option */
573     bool        warning_error;           /* -WX option */
574 #ifdef DEBUG_OUT
575     bool        debug;                   /* -dt option */
576     bool        nobackpatch;             /* -nbp option */
577 #if FASTPASS
578     bool        nofastpass;              /* -nfp option */
579     bool        print_linestore;         /* -ls option */
580 #endif
581     uint_16     max_passes;              /* -pm option */
582     bool        skip_preprocessor;       /* -sp option */
583     bool        log_all_files;           /* -af option */
584     bool        dump_reswords;           /* -dr option */
585     bool        dump_reswords_hash;      /* -drh option */
586     bool        dump_symbols;            /* -ds option */
587     bool        dump_symbols_hash;       /* -dsh option */
588 #endif
589     char        *names[OPTN_LAST];
590     struct qitem *queues[OPTQ_LAST];
591 #if COCTALS
592     bool        allow_c_octals;          /* -o option */
593 #endif
594     bool        no_comment_data_in_code_records; /* -zlc option */
595     bool        no_opt_farcall;          /* -zld option */
596 //    bool        no_dependencies;         /* -zld option */
597 #if COFF_SUPPORT
598     bool        no_file_entry;           /* -zlf option */
599     bool        no_static_procs;         /* -zlp option */
600     bool        no_section_aux_entry;    /* -zls option  */
601 #endif
602     bool        no_cdecl_decoration;     /* -zcw & -zcm option */
603     uint_8      stdcall_decoration;      /* -zt<0|1|2> option */
604     bool        no_export_decoration;    /* -zze option */
605     bool        entry_decorated;         /* -zzs option  */
606     bool        write_listing;           /* -Fl option  */
607     bool        write_impdef;            /* -Fd option  */
608     bool        case_sensitive;          /* -C<p|x|u> options */
609     bool        convert_uppercase;       /* -C<p|x|u> options */
610     bool        preprocessor_stdout;     /* -EP option  */
611     bool        masm51_compat;           /* -Zm option  */
612     bool        strict_masm_compat;      /* -Zne option  */
613     bool        masm_compat_gencode;     /* -Zg option  */
614     bool        masm8_proc_visibility;   /* -Zv8 option  */
615     bool        listif;                  /* -Sx, -Sa option  */
616     bool        list_generated_code;     /* -Sg, -Sa option  */
617     enum listmacro list_macro;           /* -Sa option  */
618     bool        no_symbol_listing;       /* -Sn option  */
619     bool        first_pass_listing;      /* -Sf option  */
620     bool        no_final_msg_listing;    /* -Sz option (v2.13) */
621     bool        all_symbols_public;      /* -Zf option  */
622     bool        safeseh;                 /* -safeseh option */
623     uint_8      ignore_include;          /* -X option */
624     enum oformat output_format;          /* -bin, -omf, -coff, -elf options */
625     enum sformat sub_format;             /* -mz, -pe, -win64, -elf64 options */
626     uint_8      fieldalign;              /* -Zp option  */
627     enum lang_type langtype;             /* -Gc|d|z option */
628     enum model_type model;               /* -mt|s|m|c|l|h|f option */
629     enum cpu_info cpu;                   /* -0|1|2|3|4|5|6 & -fp{0|2|3|5|6|c} option */
630     enum fastcall_type fctype;           /* -zf0 & -zf1 option */
631     bool        syntax_check_only;       /* -Zs option */
632 #if MANGLERSUPP
633     enum naming_types naming_convention; /* OW naming peculiarities */
634 #endif
635 };
636 
637 #if MZ_SUPPORT
638 /* if the structure changes, option.c, SetMZ() might need adjustment! */
639 struct MZDATA {
640     uint_16 ofs_fixups; /* offset start fixups */
641     uint_16 alignment; /* header alignment: 16,32,64,128,256,512 */
642     uint_16 heapmin;
643     uint_16 heapmax;
644 };
645 #endif
646 
647 #if DLLIMPORT
648 struct dll_desc {
649     struct dll_desc *next;
650     int cnt;     /* a function of this dll was used by INVOKE */
651     char name[1];
652 };
653 #endif
654 
655 /* Information about the module */
656 
657 struct src_item;
658 struct hll_item;
659 struct context;
660 
661 struct fname_item {
662     char    *fname;
663     //char    *fullname; /* v2.11: removed */
664     //time_t  mtime; /* v2.11: removed */
665 #ifdef DEBUG_OUT
666     unsigned included;
667     uint_32  lines;
668 #endif
669 };
670 
671 struct module_info;
672 
673 struct module_vars {
674     unsigned            error_count;     /* total of errors so far */
675     unsigned            warning_count;   /* total of warnings so far */
676     unsigned            num_segs;        /* number of segments in module */
677     /* v2.07: GlobalQueue is obsolete */
678     //struct qdesc        GlobalQueue;     /* GLOBAL items ( =externdefs ) */
679     struct qdesc        PubQueue;        /* PUBLIC items */
680     struct qdesc        LnameQueue;      /* LNAME items (segments, groups and classes) */
681 #if COFF_SUPPORT
682     struct qdesc        SafeSEHQueue;    /* list of safeseh handlers */
683 #endif
684     struct qdesc        LibQueue;        /* includelibs */
685     /* v2.11: AltQueue is obsolete */
686     //struct symbol_queue AltQueue;        /* weak externals */
687     //struct qdesc        AltQueue;        /* weak externals */
688 #if DLLIMPORT
689     struct dll_desc     *DllQueue;       /* dlls of OPTION DLLIMPORT */
690 #endif
691 #if PE_SUPPORT || DLLIMPORT
692     char                *imp_prefix;
693 #endif
694     FILE                *curr_file[NUM_FILE_TYPES];  /* ASM, ERR, OBJ and LST */
695     char                *curr_fname[NUM_FILE_TYPES];
696     struct fname_item   *FNames;         /* array of input files */
697     unsigned            cnt_fnames;      /* items in FNames array */
698     char                *IncludePath;
699     struct qdesc        line_queue;      /* line queue */
700     struct src_item     *src_stack;      /* source item (files & macros) stack */
701     union {
702         struct fixup    *start_fixup;    /* OMF only */
703         struct asym     *start_label;    /* non-OMF only: start label */
704     };
705     uint_32             start_displ;     /* OMF only, optional displ for start label */
706     struct hll_item     *HllStack;       /* for .WHILE, .IF, .REPEAT */
707     struct hll_item     *HllFree;        /* v2.06: stack of free <struct hll>-items */
708     struct context      *ContextStack;
709     struct context      *ContextFree;    /* v2.10: "free items" heap implemented. */
710 #if FASTPASS
711     struct context      *SavedContexts;
712     int                 cntSavedContexts;
713 #endif
714     /* v2.10: moved here from module_info due to problems if @@: occured on the very first line */
715     unsigned            anonymous_label; /* "anonymous label" counter */
716 #if STACKBASESUPP
717     struct asym         *StackBase;
718     struct asym         *ProcStatus;
719 #endif
720     ret_code (* WriteModule)( struct module_info * );
721     ret_code (* EndDirHook)( struct module_info * );
722     ret_code (* Pass1Checks)( struct module_info * );
723 #if PE_SUPPORT
724     uint_8              pe_flags;        /* for PE */
725 #endif
726 };
727 
728 struct format_options;
729 
730 struct module_info {
731     struct module_vars  g;
732     char                *proc_prologue;  /* prologue macro if PEM_MACRO */
733     char                *proc_epilogue;  /* epilogue macro if PEM_MACRO */
734 #if DLLIMPORT
735     struct dll_desc     *CurrDll;        /* OPTION DLLIMPORT dll */
736 #endif
737     const struct format_options *fmtopt; /* v2.07: added */
738     unsigned            hll_label;       /* hll directive label counter */
739     enum dist_type      distance;        /* stack distance */
740     enum model_type     model;           /* memory model */
741     enum lang_type      langtype;        /* language */
742     enum os_type        ostype;          /* operating system */
743     enum sformat        sub_format;      /* sub-output format */
744     enum fastcall_type  fctype;          /* fastcall type */
745     enum seg_order      segorder;        /* .alpha, .seq, .dosseg */
746     enum offset_type    offsettype;      /* OFFSET:GROUP|FLAT|SEGMENT */
747     short               cpu;             /* cpu setting (value @cpu symbol); */
748     enum cpu_info       curr_cpu;        /* cpu setting (OW stylex); */
749     unsigned char       radix;           /* current .RADIX setting */
750     unsigned char       fieldalign;      /* -Zp, OPTION:FIELDALIGN setting */
751     unsigned char       line_flags;      /* current line has been printed */
752 #if PROCALIGN
753     unsigned char       procalign;       /* current OPTION:PROCALIGN setting */
754 #endif
755     enum listmacro      list_macro;      /* current .LISTMACRO setting */
756     unsigned char       Ofssize;         /* current offset size (USE16,USE32,USE64) */
757     unsigned char       defOfssize;      /* default segment offset size (16,32 [,64]-bit) */
758     unsigned char       wordsize;        /* current word size (2,4,8) */
759     unsigned char       inside_comment;  /* v2.10: moved from tokenize.c */
760 
761     unsigned            case_sensitive:1;     /* option casemap */
762     unsigned            convert_uppercase:1;  /* option casemap */
763     unsigned            procs_private:1; /* option proc:private */
764     unsigned            procs_export:1;  /* option proc:export */
765     unsigned            dotname:1;       /* option dotname */
766     unsigned            ljmp:1;          /* option ljmp */
767     unsigned            m510:1;          /* option m510 */
768     unsigned            scoped:1;        /* option scoped */
769     unsigned            oldstructs:1;    /* option oldstructs */
770     unsigned            emulator:1;      /* option emulator */
771     unsigned            setif2:1;        /* option setif2 */
772     unsigned            list:1;          /* .list/.nolist */
773     unsigned            cref:1;          /* .cref/.nocref */
774     unsigned            listif:1;        /* .listif/.nolistif */
775     unsigned            list_generated_code:1; /* .listall, -Sa, -Sg */
776     unsigned            StartupDirectiveFound:1;
777     unsigned            EndDirFound:1;
778 #if AMD64_SUPPORT
779     unsigned            frame_auto:1;    /* win64 only */
780 #endif
781     unsigned            NoSignExtend:1;  /* option nosignextend */
782 #if ELF_SUPPORT || AMD64_SUPPORT || MZ_SUPPORT
783     union {
784 #if ELF_SUPPORT || AMD64_SUPPORT
785         struct {
786 #if ELF_SUPPORT
787         uint_8          elf_osabi;       /* for ELF */
788 #endif
789 #if AMD64_SUPPORT
790         uint_8          win64_flags;     /* for WIN64 + PE(32+) */
791 #endif
792         };
793 #endif
794 #if MZ_SUPPORT
795         struct MZDATA   mz_data;         /* for MZ */
796 #endif
797     };
798 #endif
799     unsigned char       simseg_init;     /* simplified segm dir flags */
800     unsigned char       simseg_defd;     /* v2.09: flag if seg was defined before simseg dir */
801     unsigned char       PhaseError;      /* phase error flag */
802     unsigned char       CommentDataInCode;/* OMF: emit coment records about data in code segs */
803     unsigned char       prologuemode;    /* current PEM_ enum value for OPTION PROLOGUE */
804     unsigned char       epiloguemode;    /* current PEM_ enum value for OPTION EPILOGUE */
805     unsigned char       invoke_exprparm; /* flag: forward refs for INVOKE params ok? */
806 #if CVOSUPP
807     unsigned char       cv_opt;          /* option codeview */
808 #endif
809     unsigned            srcfile;         /* main source file - is an index for FNames[] */
810     struct dsym         *currseg;        /* currently active segment */
811     struct dsym         *flat_grp;       /* magic FLAT group */
812     uint_8              *pCodeBuff;
813     unsigned int        GeneratedCode;   /* nesting level generated code */
814     /* input members */
815     char                *currsource;     /* current source line */
816     char                *CurrComment;    /* current comment */
817     struct asm_tok      *tokenarray;     /* start token buffer */
818     char                *stringbufferend;/* start free space in string buffer */
819     int                 token_count;     /* number of tokens in curr line */
820 #if STACKBASESUPP
821     unsigned            basereg[3];      /* stack base register (16-, 32-, 64-bit */
822 #endif
823     char                name[FILENAME_MAX];/* name of module */
824 };
825 
826 #define CurrSource      ModuleInfo.currsource
827 #define Token_Count     ModuleInfo.token_count
828 #define StringBufferEnd ModuleInfo.stringbufferend
829 #define CurrFile        ModuleInfo.g.curr_file
830 #define CurrFName       ModuleInfo.g.curr_fname
831 #define CurrSeg         ModuleInfo.currseg
832 #define CurrWordSize    ModuleInfo.wordsize
833 
834 struct format_options {
835     void (*init)( struct module_info * );
836     short invalid_fixup_type;
837     const char formatname[6];
838 };
839 
840 /* global variables */
841 
842 extern struct global_options Options;
843 extern struct module_info    ModuleInfo;
844 extern unsigned int          Parse_Pass;    /* assembly pass */
845 //extern unsigned int          GeneratedCode;  /* v2.10: moved to struct module_info */
846 extern uint_8                MacroLevel;    /* macro nesting level */
847 extern bool                  write_to_file; /* 1=write the object module */
848 
849 /* Information about source, object, listing and error files */
850 //extern FILE                  *CurrFile[];   /* ASM, ERR, OBJ and LST */
851 //extern char                  *CurrFName[];  /* ASM, ERR, OBJ and LST */
852 
853 /* functions in assemble.c */
854 
855 struct fixup;
856 
857 extern void             OutputByte( unsigned char );
858 //extern void             OutputCodeByte( unsigned char );
859 extern void             FillDataBytes( unsigned char, int len );
860 extern void             OutputBytes( const unsigned char *, int len, struct fixup * );
861 #ifdef __SW_BD
862 extern int  __stdcall   AssembleModule( const char * );
863 #else
864 extern int              AssembleModule( const char * );
865 #endif
866 extern void             AddLinnumDataRef( unsigned, uint_32 );
867 extern void             SetMasm510( bool );
868 extern void             close_files( void );
869 extern char             *myltoa( uint_32 value, char *buffer, unsigned radix, bool sign, bool addzero );
870 #if COFF_SUPPORT || PE_SUPPORT
871 extern char             *ConvertSectionName( const struct asym *, enum seg_type *pst, char *buffer );
872 #endif
873 
874 #endif
875