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:  OMF basics
28 *
29 ****************************************************************************/
30 
31 #ifndef OMFSPEC_H
32 #define OMFSPEC_H 1
33 
34 #if 0
35 /*
36  *  INTEL Segment Alignment Specifiers - A field
37  */
38 enum segment_alignment_specifiers {
39     ALIGN_ABS           = 0,        /* absolute segment - no alignment  */
40     ALIGN_BYTE          = 1,        /* relocatable seg - byte aligned   */
41     ALIGN_WORD          = 2,        /* relocatable seg - word aligned   */
42     ALIGN_PARA          = 3,        /* relocatable seg - para aligned   */
43     ALIGN_PAGE          = 4,        /* relocatable seg - page aligned   */
44     ALIGN_DWORD         = 5,        /* relocatable seg - dword aligned  */
45     ALIGN_LTRELOC       = 6,        /* load-time relocatable segment    */
46 #if PAGE4K /* PharLab Easy OMF */
47     ALIGN_4KPAGE        = 6,        /* relocatable seg - 4k page aligned*/
48     ALIGN_PAGE4K        = 6,        /* relocatable seg - 4k page aligned*/
49 #endif
50    /* this currently not supported by the linker. */
51     //ALIGN_UNABS         = 5,        /* unnamed absolute segment         */
52 };
53 #endif
54 
55 enum segdef_align_values {
56     SEGDEF_ALIGN_ABS        = 0,/* absolute segment - no alignment          */
57     SEGDEF_ALIGN_BYTE       = 1,/* relocatable seg  - byte aligned          */
58     SEGDEF_ALIGN_WORD       = 2,/*                  - word aligned          */
59     SEGDEF_ALIGN_PARA       = 3,/*                  - para aligned          */
60     SEGDEF_ALIGN_PAGE       = 4,/*                  - page aligned          */
61     SEGDEF_ALIGN_DWORD      = 5,/*                  - dword aligned         */
62 #if PAGE4K
63     SEGDEF_ALIGN_4KPAGE     = 6 /*                  - 4k page aligned       */
64 #endif
65 };
66 
67 /*
68  *  INTEL Segment Combination Attributes - C field
69  *  JWasm uses COMB_INVALID, COMB_ADDOFF, COMB_STACK & COMB_COMMON
70  */
71 
72 enum combine_attributes {
73     COMB_INVALID        = 0,  /* PRIVATE attribute */
74     COMB_ABOVEALL       = 1,  /* marked as "reserved" */
75     COMB_ADDOFF         = 2,  /* PUBLIC attribute */
76     COMB_BAD            = 3,  /* marked as "reserved" */
77     COMB_FOUR           = 4,  /* comment: same as 2 */
78     COMB_STACK          = 5,  /* STACK attribute */
79     COMB_COMMON         = 6,  /* COMMON attribute */
80     COMB_ALIGNTOP       = 7,  /* comment: same as 2 */
81 };
82 
83 #if 0
84 #define SEGATTR_A( a )  (ALIGN_##a << 5)
85 #define SEGATTR_C( a )  (COMB_##a << 2)
86 enum {
87     SEGATTR_BIG  =   1<< 1,   /* exactly 64k or 2**32 */
88     SEGATTR_P    =   1,       /* use 32 */
89 };
90 #endif
91 
92 /*
93  *  INTEL Frame Specifiers
94  *  FRAME_ABS[WD] not supported according to TIS OMF docs.
95  *  FRAME_NONE should never appear in object modules, it's just
96  *  a void used by jwasm internally.
97  */
98 enum frame_methods {
99     FRAME_SEG           = 0,        /* segment index                    */
100     FRAME_GRP           = 1,        /* group index                      */
101     FRAME_EXT           = 2,        /* external index                   */
102     //FRAME_ABS           = 3,        /* absolute frame number            */
103     FRAME_LOC           = 4,        /* segment index of last LEDATA     */
104     FRAME_TARG          = 5,        /* frame same as target             */
105     FRAME_NONE          = 6,        /* no frame                         */
106 };
107 
108 /*
109  *  INTEL Target Specifiers
110  *  TARGET_ABS[WD] is supported for THREAD sub-records only, according to TIS OMF docs;
111  *  Since JWasm won't write THREAD sub-records, those methods are invalid.
112  */
113 enum target_methods {
114     TARGET_SEGWD        = 0,        /* segment index with displacement  */
115     TARGET_GRPWD        = 1,        /* group index with displacement    */
116     TARGET_EXTWD        = 2,        /* external index with displacement */
117     //TARGET_ABSWD        = 3,        /* abs frame num with displacement  */
118 
119     TARGET_SEG          = 4,        /* segment index, no displacement   */
120     TARGET_GRP          = 5,        /* group index, no displacement     */
121     TARGET_EXT          = 6,        /* external index, no displacement  */
122     //TARGET_ABS          = 7,        /* abs frame num, no displacement   */
123 
124     TARGET_WITH_DISPL   = ~4,       /* frame with displacement          */
125 };
126 
127 /*  Bits in FIXUPP records */
128 
129 enum {
130     FIXUPP_FIXUP        = 0x80,
131 
132     FIXDAT_FTHREAD      = 0x80,
133     FIXDAT_TTHREAD      = 8,
134     FIXDAT_PBIT         = 4,
135     FIXDAT_MBIT         = 0x40,
136     TRDDAT_DBIT         = 0x40,
137 
138 /*
139  *  INTEL Group Specifiers
140  */
141 
142     GRP_SEGIDX          = 0xff,     /* group segment index              */
143     GRP_EXTIDX          = 0xfe,     /* group external index             */
144     GRP_FULLNAME        = 0xfd,     /* full name indices                */
145     GRP_LTLDATA         = 0xfb,     /* load time data info              */
146     GRP_ADDR            = 0xfa,     /* load time addr for the group     */
147 };
148 
149 /*
150  *  INTEL Object Record Types
151  */
152 
153 enum cmd_omf {
154 #if 0 /* these cmds aren't used (and ignored by MS link) */
155     CMD_MIN_CMD         = 0x6e,     /* minimum cmd enum                  */
156     CMD_RHEADR          = 0x6e,     /* R-Module Header                   */
157     CMD_REGINT          = 0x70,     /* Register Initialization           */
158     CMD_REDATA          = 0x72,     /* Relocatable Enumerated Data       */
159     CMD_RIDATA          = 0x74,     /* Relocatable Iterated Data         */
160     CMD_OVLDEF          = 0x76,     /* Overlay Definition                */
161     CMD_ENDREC          = 0x78,     /* End                               */
162     CMD_BLKDEF          = 0x7a,     /* block definition                  */
163     //CMD_BLKD32          = 0x7b,     /* weird extension for QNX MAX assembler */
164     CMD_BLKEND          = 0x7c,     /* block end                         */
165     //CMD_BLKE32          = 0x7d,     /* _might_ be used by QNX MAX assembler */
166     CMD_DEBSYM          = 0x7e,     /* Debug Symbols                     */
167 #else
168     CMD_MIN_CMD         = 0x80,     /* minimum cmd enum                 */
169 #endif
170     CMD_THEADR          = 0x80,     /* translator header                */
171     CMD_LHEADR          = 0x82,     /* library header                   */
172 //  CMD_PEDATA          = 0x84,     /* physical enumerated data         */
173 //  CMD_PIDATA          = 0x86,     /* physical iterated data           */
174     CMD_COMENT          = 0x88,     /* comment record                   */
175     CMD_MODEND          = 0x8a,     /* end of module record             */
176     CMD_EXTDEF          = 0x8c,     /* import names record              */
177     CMD_TYPDEF          = 0x8e,     /* type definition record           */
178     CMD_PUBDEF          = 0x90,     /* public names record              */
179 //  CMD_LOCSYM          = 0x92,     /* local symbols                    */
180     CMD_LINNUM          = 0x94,     /* line number record               */
181     CMD_LNAMES          = 0x96,     /* list of names record             */
182     CMD_SEGDEF          = 0x98,     /* segment definition record        */
183     CMD_GRPDEF          = 0x9a,     /* group definition record          */
184     CMD_FIXUPP          = 0x9c,     /* relocation record                */
185     CMD_LEDATA          = 0xa0,     /* logical enumerated data          */
186     CMD_LIDATA          = 0xa2,     /* logical iterated data            */
187 //  CMD_LIBHED          = 0xa4,     /* library header                   */
188 //  CMD_LIBNAM          = 0xa6,     /* library module names             */
189 //  CMD_LIBLOC          = 0xa8,     /* library module locations         */
190 //  CMD_LIBDIC          = 0xaa,     /* library dictionary               */
191     CMD_COMDEF          = 0xb0,     /* communal definition              */
192     CMD_BAKPAT          = 0xb2,     /* backpatch record (for Quick C)   */
193 
194     /* the following types are used to make local names known to the linker */
195     CMD_LEXTDEF         = 0xb4,     /* local import names record        */
196     CMD_STATIC_EXTDEF   = 0xb4,
197     CMD_LPUBDEF         = 0xb6,     /* local public names def record    */
198     CMD_LCOMDEF         = 0xb8,     /* local communal names def record  */
199     CMD_STATIC_COMDEF   = 0xb8,
200 
201     CMD_CEXTDEF         = 0xbc,     /* external reference to a COMDAT   */
202     CMD_COMDAT          = 0xc2,     /* initialized communal data record */
203     CMD_LINSYM          = 0xc4,     /* symbol line numbers              */
204     CMD_ALIAS           = 0xc6,     /* alias definition record          */
205     CMD_NBKPAT          = 0xc8,     /* named backpatch record (quick c?) */
206     CMD_LLNAMES         = 0xca,     /* a "local" lnames                 */
207     CMD_MAX_CMD         = 0xca,     /* maximum cmd enum                 */
208 #if 0
209     CMD_VERNUM          = 0xcc,     /* TIS version number record        */
210     CMD_VENDEXT         = 0xce,     /* TIS vendor extension record      */
211     CMD_MAX_CMD         = 0xce,     /* maximum cmd enum                 */
212 #endif
213 #if 0 /* 32-bit versions */
214     CMD_MODE32          = CMD_MODEND+1,
215     CMD_PUBD32          = CMD_PUBDEF+1,
216     CMD_LINN32          = CMD_LINNUM+1,
217     CMD_SEGD32          = CMD_SEGDEF+1,
218     CMD_FIXU32          = CMD_FIXUP+1,
219     CMD_LEDA32          = CMD_LEDATA+1,
220     CMD_LIDA32          = CMD_LIDATA+1,
221     CMD_BAKP32          = CMD_BAKPAT+1,
222     CMD_LEXTDEF32       = CMD_LEXTDEF+1,
223     CMD_STATIC_EXTD32   = CMD_STATIC_EXTDEF+1,
224     CMD_LPUBDEF32       = CMD_LPUBDEF+1,
225     CMD_COMD32          = CMD_COMDAT+1,
226     CMD_LINS32          = CMD_LINSYM+1,
227     CMD_NBKP32          = CMD_NBKPAT+1,
228 #endif
229 };
230 
231 /* OMF fixup types; 4-bit-"location"-field in FIXUP sub-records; see omffixup.c.
232  */
233 enum omf_fixup_types {
234     LOC_OFFSET_LO       = 0,    /* 8-bit (lowbyte) offset             */
235     LOC_OFFSET          = 1,    /* 16-bit offset                      */
236     LOC_BASE            = 2,    /* segment (always 16-bit)            */
237     LOC_BASE_OFFSET     = 3,    /* 16-bit offset & 16-bit segment     */
238     LOC_OFFSET_HI       = 4,    /* 8-bit (hibyte) offset              */
239 #if 0
240     LOC_PL_OFFSET_32      = 5,  /* 32-bit offset (PharLab)                  */
241     LOC_PL_BASE_OFFSET_32 = 6,  /* 32-bit offset & 16-bit segment (PharLab) */
242 #endif
243     LOC_MS_LINK_OFFSET   =  5,  /* 16-bit "loader-resolved" offset (MS) */
244     LOC_MS_OFFSET_32     =  9,  /* 32-bit offset (MS)                   */
245     LOC_MS_BASE_OFFSET_32= 11,  /* 32-bit offset & 16-bit segment (MS)  */
246     LOC_MS_LINK_OFFSET_32= 13   /* 32-bit "loader-resolved" offset (MS) */
247 };
248 
249 /* Comment Type */
250 
251 enum {
252     CMT_TNP = 0x80,   /* no purge bit */
253     CMT_TNL = 0x40,   /* no list bit */
254 };
255 /*
256  * Comment classes. JWasm uses:
257  * - CMT_DOSSEG           : dosseg directive
258  * - CMT_DEFAULT_LIBRARY  : includelib directive
259  * - CMT_OMF_EXT          : PROC's EXPORT attribute
260  * - CMT_MS_OMF           : codeview debug info version
261  * - CMT_MS_END_PASS_1    : end of pass one
262  * - CMT_WKEXT            : extern directive with altname
263  * - CMT_DEPENDENCY       : include directive, Borland specific
264  * - CMT_DISASM_DIRECTIVE : wdis special
265  * - CMT_LINKER_DIRECTIVE : wlink specials
266  */
267 enum omf_comment_classes {
268     //CMT_LANGUAGE_TRANS  = 0x00, /* Language translator comment          */
269     //CMT_INTEL_COPYRIGHT = 0x01, /* INTEL Copyright record               */
270     //CMT_MS_PADDING      = 0x01, /* Microsoft uses this for padding      */
271     //CMT_WAT_PROC_MODEL  = 0x9b, /* Watcom processor & model info        */
272     //CMT_MS_DOS_VERSION  = 0x9c, /* obsolete                             */
273     //CMT_MS_PROC_MODEL   = 0x9d, /* Microsoft processor & model info     */
274     CMT_DOSSEG          = 0x9e, /* DOSSEG directive                     */
275     CMT_DEFAULT_LIBRARY = 0x9f, /* Default library cmd                  */
276     CMT_OMF_EXT         = 0xa0, /* OMF extension                        */
277     CMT_MS_OMF          = 0xa1, /* MS codeview debug info included      */
278     CMT_MS_END_PASS_1   = 0xa2, /* MS end of linker pass 1              */
279     //CMT_LIBMOD          = 0xa3, /* Record specifying name of object     */
280     //CMT_EXESTR          = 0xa4, /* Executable string                    */
281     //CMT_INCERR          = 0xa6, /* Incremental Compilation Error        */
282     //CMT_NOPAD           = 0xa7, /* No segment padding                   */
283     CMT_WKEXT           = 0xa8, /* Weak external record                 */
284     //CMT_LZEXT           = 0xa9, /* Lazy external record                 */
285     //CMT_EASY_OMF        = 0xaa, /* Easy OMF signature record            */
286     CMT_SRCFILE         = 0xe8, /* Borland source file record           */
287     CMT_DEPENDENCY      = 0xe9, /* Borland dependency record            */
288     CMT_DISASM_DIRECTIVE= 0xfd, /* Directive to disassemblers           */
289     CMT_LINKER_DIRECTIVE= 0xfe, /* Linker directive                     */
290     //CMT_COMPILER_OPTIONS= 0xff, /* Microsoft: incremental compiler opts */
291     //CMT_SOURCE_NAME     = 0xff  /* name of the source file              */
292 };
293 
294 /*
295  * Comment Class Subtype for CMT_OMF_EXT
296  */
297 enum omf_ext_subtype {
298     CMT_EXT_IMPDEF  = 0x01, /* Subtype IMPDEF of OMF extension class    */
299     CMT_EXT_EXPDEF  = 0x02, /* Subtype EXPDEF of OMF extension class    */
300     CMT_EXT_INCDEF  = 0x03, /* Subtype INCDEF of OMF extension class    */
301     CMT_EXT_PMLIB   = 0x04, /* Protected Memory Library (OMF extension) */
302     CMT_EXT_LNKDIR  = 0x05, /* Subtype LNKDIR of OMF extension class    */
303     CMT_EXT_BIGEND  = 0x06,
304     CMT_EXT_PRECOMP = 0x07,
305 };
306 
307 //#define EASY_OMF_SIGNATURE  "80386"
308 
309 /*
310  *  Linker directives ( CMT_LINKER_DIRECTIVE - mostly WLINK directives )
311  *  JWasm uses LDIR_OPT_FAR_CALLS only
312  */
313 enum linker_directives {
314     LDIR_SOURCE_LANGUAGE= 'D',  /* dbg maj/min and source language      */
315     LDIR_DEFAULT_LIBRARY= 'L',  /* default library cmd                  */
316     LDIR_OPT_FAR_CALLS  = 'O',  /* optimize far calls/jmps for this seg */
317     //LDIR_OPT_UNSAFE     = 'U',  /* far call optimization unsafe for fixup*/
318     //LDIR_VF_TABLE_DEF   = 'V',  /* virtual function table lazy extdef   */
319     //LDIR_VF_PURE_DEF    = 'P',  /* as above for pure functions */
320     //LDIR_VF_REFERENCE   = 'R',  /* virtual function reference */
321     //LDIR_PACKDATA       = '7',  /* amount to pack far data */
322     //LDIR_FLAT_ADDRS     = 'F',  /* debug addresses are flat */
323     //LDIR_OBJ_TIMESTAMP  = 'T'   /* file timestamp of object in a library */
324 };
325 
326 /*
327  *  Disasm directives ( CMT_DISASM_DIRECTIVE )
328  *  this is a feature supported by OW WDis.
329  */
330 enum disasm_directives {
331 /*
332  *  DDIR_SCAN_TABLE is used by the code generator to indicate data in a
333  *  code segment.  i.e., scan tables generated for switch()s, floating point
334  *  constants and string constants.  The 'S' is followed by a segment index,
335  *  then the start and end+1 offsets into the segment which are 16-bit in
336  *  regular object files, and 32-bit in EasyOMF and Microsoft 386.
337  *  If the segment index is zero, then it is followed by a LNAME index which
338  *  identifies the COMDAT symbol that the scan table belongs to.
339  */
340     DDIR_SCAN_TABLE_32  = 'S',
341     DDIR_SCAN_TABLE     = 's'
342 };
343 
344 /*
345  *  COMDEF types
346  */
347 enum comdef_types {
348     COMDEF_FAR          = 0x61, /* FAR variable                         */
349     COMDEF_NEAR         = 0x62, /* NEAR variable                        */
350     COMDEF_LEAF_SIZE    = 0x80, /* bit set if size > 0x7f               */
351     COMDEF_LEAF_2       = 0x81, /* 2 byte size field                    */
352     COMDEF_LEAF_3       = 0x84, /* 3 byte size field                    */
353     COMDEF_LEAF_4       = 0x88  /* 4 byte size field                    */
354 };
355 
356 /* COMDAT (initialized communal data);
357  * record type 0xC2/0xC3;
358  * MS extension introduced for MSC 7.
359  */
360 enum comdat_flags {
361 /*
362  *  COMDAT flags
363  */
364     COMDAT_CONTINUE     = 0x01, /* continuation of previous COMDAT */
365     COMDAT_ITERATED     = 0x02, /* LIDATA form of COMDAT */
366     COMDAT_LOCAL        = 0x04, /* COMDAT is local to this module */
367     COMDAT_DATAINCODE   = 0x08, /* data in code segment */
368 /*
369  *  COMDAT allocation type ( low-order 4 bits of attributes field )
370  */
371     COMDAT_ALLOC_MASK   = 0x0f,
372     COMDAT_EXPLICIT     = 0x00, /* in given segment ( base grp, seg and frame ) */
373     COMDAT_FAR_CODE     = 0x01, /* allocate CODE use16 segment */
374     COMDAT_FAR_DATA     = 0x02, /* allocate DATA use16 segment */
375     COMDAT_CODE32       = 0x03, /* allocate CODE use32 segment */
376     COMDAT_DATA32       = 0x04, /* allocate DATA use32 segment */
377 /*
378  *  COMDAT selection criteria ( high-order 4 bits of attributes field )
379  */
380     COMDAT_MATCH_MASK   = 0xf0,
381     COMDAT_MATCH_NONE   = 0x00, /* don't match anyone - only 1 instance allowed */
382     COMDAT_MATCH_ANY    = 0x10, /* pick any instance */
383     COMDAT_MATCH_SAME   = 0x20, /* must be same size - or linker will emit an error */
384     COMDAT_MATCH_EXACT  = 0x30, /* pick any instance - but checksums must match */
385 /*
386  *  COMDAT alignment
387  */
388     COMDAT_ALIGN_SEG    = 0x00, /* align from SEGDEF */
389     COMDAT_ALIGN_BYTE   = 0x01,
390     COMDAT_ALIGN_WORD   = 0x02,
391     COMDAT_ALIGN_PARA   = 0x03,
392     COMDAT_ALIGN_4K     = 0x04,
393     COMDAT_ALIGN_DWORD  = 0x05
394 };
395 
396 #endif
397