Annotation of os2sdk/include/newexe.h, revision 1.1.1.2

1.1.1.2 ! root        1: /* SCCSID = @(#)newexe.h       4.5 86/03/12 */
1.1       root        2: /*
                      3:  *  Title
                      4:  *
1.1.1.2 ! root        5:  *     newexe.h
        !             6:  *     Pete Stewart
        !             7:  *     (C) Copyright Microsoft Corp 1984, 1985, 1986
        !             8:  *     17 August 1984
1.1       root        9:  *
                     10:  *  Description
                     11:  *
1.1.1.2 ! root       12:  *     Data structure definitions for the DOS 4.0/Windows 2.0
        !            13:  *     executable file format.
1.1       root       14:  *
1.1.1.2 ! root       15:  *  Modification History
1.1       root       16:  *
1.1.1.2 ! root       17:  *     84/08/17        Pete Stewart    Initial version
        !            18:  *     84/10/17        Pete Stewart    Changed some constants to match OMF
        !            19:  *     84/10/23        Pete Stewart    Updates to match .EXE format revision
        !            20:  *     84/11/20        Pete Stewart    Substantial .EXE format revision
        !            21:  *     85/01/09        Pete Stewart    Added constants ENEWEXE and ENEWHDR
        !            22:  *     85/01/10        Steve Wood      Added resource definitions
        !            23:  *     85/03/04        Vic Heller      Reconciled Windows and DOS 4.0 versions
        !            24:  *     85/03/07        Pete Stewart    Added movable entry count
        !            25:  *     85/04/01        Pete Stewart    Segment alignment field, error bit
        !            26:  *     85/10/03        Reuben Borman   Removed segment discard priority
        !            27:  *     85/10/11        Vic Heller      Added PIF header fields
        !            28:  *     86/03/10        Reuben Borman   Changes for DOS 5.0
1.1       root       29:  */
                     30: 
1.1.1.2 ! root       31: #define EMAGIC         0x5A4D          /* Old magic number */
        !            32: #define        ENEWEXE         sizeof(struct exe_hdr)
        !            33:                                        /* Value of E_LFARLC for new .EXEs */
        !            34: #define        ENEWHDR         0x003C          /* Offset in old hdr. of ptr. to new */
        !            35: #define        ERESWDS         0x0010          /* No. of reserved words (OLD) */
        !            36: #define        ERES1WDS        0x0004          /* No. of reserved words in e_res */
        !            37: #define        ERES2WDS        0x000A          /* No. of reserved words in e_res2 */
        !            38: #define        ECP             0x0004          /* Offset in struct of E_CP */
        !            39: #define        ECBLP           0x0002          /* Offset in struct of E_CBLP */
        !            40: #define        EMINALLOC       0x000A          /* Offset in struct of E_MINALLOC */
1.1       root       41: 
1.1.1.2 ! root       42: struct exe_hdr                         /* DOS 1, 2, 3 .EXE header */
1.1       root       43:   {
1.1.1.2 ! root       44:     unsigned short     e_magic;        /* Magic number */
        !            45:     unsigned short     e_cblp;         /* Bytes on last page of file */
        !            46:     unsigned short     e_cp;           /* Pages in file */
        !            47:     unsigned short     e_crlc;         /* Relocations */
        !            48:     unsigned short     e_cparhdr;      /* Size of header in paragraphs */
        !            49:     unsigned short     e_minalloc;     /* Minimum extra paragraphs needed */
        !            50:     unsigned short     e_maxalloc;     /* Maximum extra paragraphs needed */
        !            51:     unsigned short     e_ss;           /* Initial (relative) SS value */
        !            52:     unsigned short     e_sp;           /* Initial SP value */
        !            53:     unsigned short     e_csum;         /* Checksum */
        !            54:     unsigned short     e_ip;           /* Initial IP value */
        !            55:     unsigned short     e_cs;           /* Initial (relative) CS value */
        !            56:     unsigned short     e_lfarlc;       /* File address of relocation table */
        !            57:     unsigned short     e_ovno;         /* Overlay number */
        !            58:     unsigned short     e_res[ERES1WDS];/* Reserved words */
        !            59:     unsigned short     e_oemid;        /* OEM identifier (for e_oeminfo) */
        !            60:     unsigned short     e_oeminfo;      /* OEM information; e_oemid specific */
        !            61:     unsigned short     e_res2[ERES2WDS];/* Reserved words */
        !            62:     long               e_lfanew;       /* File address of new exe header */
1.1       root       63:   };
                     64: 
1.1.1.2 ! root       65: #define E_MAGIC(x)     (x).e_magic
        !            66: #define E_CBLP(x)      (x).e_cblp
        !            67: #define E_CP(x)        (x).e_cp
        !            68: #define E_CRLC(x)      (x).e_crlc
        !            69: #define E_CPARHDR(x)   (x).e_cparhdr
        !            70: #define E_MINALLOC(x)  (x).e_minalloc
        !            71: #define E_MAXALLOC(x)  (x).e_maxalloc
        !            72: #define E_SS(x)        (x).e_ss
        !            73: #define E_SP(x)        (x).e_sp
        !            74: #define E_CSUM(x)      (x).e_csum
        !            75: #define E_IP(x)        (x).e_ip
        !            76: #define E_CS(x)        (x).e_cs
        !            77: #define E_LFARLC(x)    (x).e_lfarlc
        !            78: #define E_OVNO(x)      (x).e_ovno
        !            79: #define        E_RES(x)        (x).e_res
        !            80: #define E_OEMID(x)     (x).e_oemid
        !            81: #define E_OEMINFO(x)   (x).e_oeminfo
        !            82: #define E_RES2(x)      (x).e_res2
        !            83: #define        E_LFANEW(x)     (x).e_lfanew
        !            84: 
        !            85: #define NEMAGIC        0x454E          /* New magic number */
        !            86: #define        NERESBYTES      8               /* Eight bytes reserved (now) */
        !            87: #define NECRC          8               /* Offset into new header of NE_CRC */
1.1       root       88: 
1.1.1.2 ! root       89: struct new_exe                         /* New .EXE header */
1.1       root       90:   {
1.1.1.2 ! root       91:     unsigned short     ne_magic;       /* Magic number NE_MAGIC */
        !            92:     unsigned char      ne_ver;         /* Version number */
        !            93:     unsigned char      ne_rev;         /* Revision number */
        !            94:     unsigned short     ne_enttab;      /* Offset of Entry Table */
        !            95:     unsigned short     ne_cbenttab;    /* Number of bytes in Entry Table */
        !            96:     long               ne_crc;         /* Checksum of whole file */
        !            97:     unsigned short     ne_flags;       /* Flag word */
        !            98:     unsigned short     ne_autodata;    /* Automatic data segment number */
        !            99:     unsigned short     ne_heap;        /* Initial heap allocation */
        !           100:     unsigned short     ne_stack;       /* Initial stack allocation */
        !           101:     long               ne_csip;        /* Initial CS:IP setting */
        !           102:     long               ne_sssp;        /* Initial SS:SP setting */
        !           103:     unsigned short     ne_cseg;        /* Count of file segments */
        !           104:     unsigned short     ne_cmod;        /* Entries in Module Reference Table */
        !           105:     unsigned short     ne_cbnrestab;   /* Size of non-resident name table */
        !           106:     unsigned short     ne_segtab;      /* Offset of Segment Table */
        !           107:     unsigned short     ne_rsrctab;     /* Offset of Resource Table */
        !           108:     unsigned short     ne_restab;      /* Offset of resident name table */
        !           109:     unsigned short     ne_modtab;      /* Offset of Module Reference Table */
        !           110:     unsigned short     ne_imptab;      /* Offset of Imported Names Table */
        !           111:     long               ne_nrestab;     /* Offset of Non-resident Names Table */
        !           112:     unsigned short     ne_cmovent;     /* Count of movable entries */
        !           113:     unsigned short     ne_align;       /* Segment alignment shift count */
        !           114:     unsigned short     ne_iphi;        /* High word of initial IP */
        !           115:     unsigned short     ne_sphi;        /* High word of initial SP */
        !           116:     char               ne_res[NERESBYTES];
        !           117:                                        /* Pad structure to 64 bytes */
1.1       root      118:   };
                    119: 
1.1.1.2 ! root      120: #define NE_MAGIC(x)    (x).ne_magic
        !           121: #define NE_VER(x)      (x).ne_ver
        !           122: #define NE_REV(x)      (x).ne_rev
        !           123: #define NE_ENTTAB(x)   (x).ne_enttab
        !           124: #define NE_CBENTTAB(x) (x).ne_cbenttab
        !           125: #define NE_CRC(x)      (x).ne_crc
        !           126: #define NE_FLAGS(x)    (x).ne_flags
        !           127: #define NE_AUTODATA(x) (x).ne_autodata
        !           128: #define NE_HEAP(x)     (x).ne_heap
        !           129: #define NE_STACK(x)    (x).ne_stack
        !           130: #define NE_CSIP(x)     (x).ne_csip
        !           131: #define NE_SSSP(x)     (x).ne_sssp
        !           132: #define NE_CSEG(x)     (x).ne_cseg
        !           133: #define NE_CMOD(x)     (x).ne_cmod
1.1       root      134: #define NE_CBNRESTAB(x) (x).ne_cbnrestab
1.1.1.2 ! root      135: #define NE_SEGTAB(x)   (x).ne_segtab
        !           136: #define NE_RSRCTAB(x)  (x).ne_rsrctab
        !           137: #define NE_RESTAB(x)   (x).ne_restab
        !           138: #define NE_MODTAB(x)   (x).ne_modtab
        !           139: #define NE_IMPTAB(x)   (x).ne_imptab
        !           140: #define NE_NRESTAB(x)  (x).ne_nrestab
        !           141: #define        NE_CMOVENT(x)   (x).ne_cmovent
        !           142: #define        NE_ALIGN(x)     (x).ne_align
        !           143: #define NE_IPHI(x)     (x).ne_iphi
        !           144: #define NE_SPHI(x)     (x).ne_sphi
        !           145: #define        NE_RES(x)       (x).ne_res
        !           146: 
        !           147: #define NE_USAGE(x)    (WORD)*((WORD *)(x)+1)
        !           148: #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
        !           149: #define NE_ONEWEXE(x)  (WORD)(x).ne_crc
1.1       root      150: #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
                    151: 
                    152: /*
                    153:  *  Format of NE_FLAGS(x):
                    154:  *
1.1.1.2 ! root      155:  *  p                                  Not-a-process
        !           156:  *   x                                 Unused
        !           157:  *    e                                        Errors in image
        !           158:  *     xxxxx                           Unused
        !           159:  *          f                          Floating-point instructions
        !           160:  *           3                         386 instructions
        !           161:  *            2                                286 instructions
        !           162:  *             0                       8086 instructions
        !           163:  *              P                      Protected mode only
        !           164:  *               x                     Unused
        !           165:  *               i                     Instance data
        !           166:  *                s                    Solo data
1.1       root      167:  */
1.1.1.2 ! root      168: #define NENOTP         0x8000          /* Not a process */
        !           169: #define        NEIERR          0x2000          /* Errors in image */
        !           170: #define NEFLTP         0x0080          /* Floating-point instructions */
        !           171: #define NEI386         0x0040          /* 386 instructions */
        !           172: #define NEI286         0x0020          /* 286 instructions */
        !           173: #define NEI086         0x0010          /* 8086 instructions */
        !           174: #define NEPROT         0x0008          /* Runs in protected mode only */
        !           175: #define NEINST         0x0002          /* Instance data */
        !           176: #define NESOLO         0x0001          /* Solo data */
1.1       root      177: 
1.1.1.2 ! root      178: struct new_seg                         /* New .EXE segment table entry */
1.1       root      179:   {
1.1.1.2 ! root      180:     unsigned short     ns_sector;      /* File sector of start of segment */
        !           181:     unsigned short     ns_cbseg;       /* Number of bytes in file */
        !           182:     unsigned short     ns_flags;       /* Attribute flags */
        !           183:     unsigned short     ns_minalloc;    /* Minimum allocation in bytes */
1.1       root      184:   };
                    185: 
1.1.1.2 ! root      186: #define NS_SECTOR(x)   (x).ns_sector
        !           187: #define NS_CBSEG(x)    (x).ns_cbseg
        !           188: #define NS_FLAGS(x)    (x).ns_flags
        !           189: #define NS_MINALLOC(x) (x).ns_minalloc
1.1       root      190: 
                    191: /*
                    192:  *  Format of NS_FLAGS(x):
                    193:  *
1.1.1.2 ! root      194:  *  x                                  Unused
        !           195:  *   h                                 Huge segment
        !           196:  *    c                                        32-bit code segment
        !           197:  *     d                               Discardable segment
        !           198:  *     DD                              I/O privilege level (286 DPL bits)
        !           199:  *       x                             Unused
        !           200:  *        r                            Segment has relocations
        !           201:  *         e                           Execute/read only
        !           202:  *          p                          Preload segment
        !           203:  *           P                         Pure segment
        !           204:  *            m                        Movable segment
        !           205:  *             i                       Iterated segment
        !           206:  *              ttt                    Segment type
1.1       root      207:  */
1.1.1.2 ! root      208: #define NSTYPE         0x0007          /* Segment type mask */
        !           209: #define NSCODE         0x0000          /* Code segment */
        !           210: #define NSDATA         0x0001          /* Data segment */
        !           211: #define NSITER         0x0008          /* Iterated segment flag */
        !           212: #define NSMOVE         0x0010          /* Movable segment flag */
        !           213: #define NSPURE         0x0020          /* Pure segment flag */
        !           214: #define NSPRELOAD      0x0040          /* Preload segment flag */
        !           215: #define NSEXRD         0x0080          /* Execute-only (code segment), or
        !           216:                                        *  read-only (data segment)
        !           217:                                        */
        !           218: #define NSRELOC        0x0100          /* Segment has relocations */
        !           219: #define NSDPL          0x0C00          /* I/O privilege level (286 DPL bits) */
        !           220: #define SHIFTDPL       10              /* Left shift count for SEGDPL field */
        !           221: #define NSDISCARD      0x1000          /* Segment is discardable */
        !           222: #define NS32BIT                0x2000          /* 32-bit code segment */
        !           223: #define NSHUGE         0x4000          /* Huge memory segment, length of
        !           224:                                         * segment and minimum allocation
        !           225:                                         * size are in segment sector units
        !           226:                                         */
1.1       root      227: 
1.1.1.2 ! root      228: #define NSALIGN        9       /* Segment data aligned on 512 byte boundaries */
1.1       root      229: 
1.1.1.2 ! root      230: #define NSLOADED    0x0004     /* ns_sector field contains memory addr */
1.1       root      231: 
1.1.1.2 ! root      232: struct new_segdata                     /* Segment data */
1.1       root      233:   {
                    234:     union
                    235:       {
1.1.1.2 ! root      236:        struct
        !           237:          {
        !           238:            unsigned short      ns_niter;       /* number of iterations */
        !           239:            unsigned short      ns_nbytes;      /* number of bytes */
        !           240:            char                ns_iterdata;    /* iterated data bytes */
        !           241:          } ns_iter;
        !           242:        struct
        !           243:          {
        !           244:            char                ns_data;        /* data bytes */
        !           245:          } ns_noniter;
1.1       root      246:       } ns_union;
                    247:   };
                    248: 
1.1.1.2 ! root      249: struct new_rlcinfo                     /* Relocation info */
1.1       root      250:   {
1.1.1.2 ! root      251:     unsigned short     nr_nreloc;      /* number of relocation items that */
        !           252:   };                                   /* follow */
1.1       root      253: 
1.1.1.2 ! root      254: struct new_rlc                         /* Relocation item */
1.1       root      255:   {
1.1.1.2 ! root      256:     char               nr_stype;       /* Source type */
        !           257:     char               nr_flags;       /* Flag byte */
        !           258:     unsigned short     nr_soff;        /* Source offset */
1.1       root      259:     union
                    260:       {
1.1.1.2 ! root      261:        struct
        !           262:          {
        !           263:            char        nr_segno;       /* Target segment number */
        !           264:            char        nr_res;         /* Reserved */
        !           265:            unsigned short nr_entry;    /* Target Entry Table offset */
        !           266:          }             nr_intref;      /* Internal reference */
        !           267:        struct
        !           268:          {
        !           269:            unsigned short nr_mod;      /* Index into Module Reference Table */
        !           270:            unsigned short nr_proc;     /* Procedure ordinal or name offset */
        !           271:          }             nr_import;      /* Import */
        !           272:        struct
        !           273:          {
        !           274:            unsigned short nr_ostype;   /* OSFIXUP type */
        !           275:            unsigned short nr_osres;    /* reserved */
        !           276:          }             nr_osfix;       /* Operating system fixup */
        !           277:       }                nr_union;       /* Union */
1.1       root      278:   };
                    279: 
1.1.1.2 ! root      280: #define NR_STYPE(x)    (x).nr_stype
        !           281: #define NR_FLAGS(x)    (x).nr_flags
        !           282: #define NR_SOFF(x)     (x).nr_soff
        !           283: #define NR_SEGNO(x)    (x).nr_union.nr_intref.nr_segno
        !           284: #define NR_RES(x)      (x).nr_union.nr_intref.nr_res
        !           285: #define NR_ENTRY(x)    (x).nr_union.nr_intref.nr_entry
        !           286: #define NR_MOD(x)      (x).nr_union.nr_import.nr_mod
        !           287: #define NR_PROC(x)     (x).nr_union.nr_import.nr_proc
        !           288: #define NR_OSTYPE(x)   (x).nr_union.nr_osfix.nr_ostype
        !           289: #define NR_OSRES(x)    (x).nr_union.nr_osfix.nr_osres
1.1       root      290: 
                    291: /*
                    292:  *  Format of NR_STYPE(x):
                    293:  *
1.1.1.2 ! root      294:  *  xxxxx                              Unused
        !           295:  *      sss                            Source type
1.1       root      296:  */
1.1.1.2 ! root      297: #define NRSTYP         0x0f            /* Source type mask */
        !           298: #define NRSBYT         0x00            /* lo byte */
        !           299: #define NRSSEG         0x02            /* 16-bit segment */
        !           300: #define NRSPTR         0x03            /* 32-bit pointer */
        !           301: #define NRSOFF         0x05            /* 16-bit offset */
        !           302: #define NRSPTR48       0x0B            /* 48-bit pointer */
        !           303: #define NRSOFF32       0x0D            /* 32-bit offset */
1.1       root      304: 
                    305: /*
                    306:  *  Format of NR_FLAGS(x):
                    307:  *
1.1.1.2 ! root      308:  *  xxxxx                              Unused
        !           309:  *      a                              Additive fixup
        !           310:  *       rr                            Reference type
1.1       root      311:  */
1.1.1.2 ! root      312: #define NRADD          0x04            /* Additive fixup */
        !           313: #define NRRTYP         0x03            /* Reference type mask */
        !           314: #define NRRINT         0x00            /* Internal reference */
        !           315: #define NRRORD         0x01            /* Import by ordinal */
        !           316: #define NRRNAM         0x02            /* Import by name */
        !           317: #define NRROSF         0x03            /* Operating system fixup */
1.1       root      318: 
                    319: 
                    320: /* Resource type or name string */
                    321: struct rsrc_string
                    322:     {
1.1.1.2 ! root      323:     char rs_len;           /* number of bytes in string */
1.1       root      324:     char rs_string[ 1 ];    /* text of string */
                    325:     };
                    326: 
                    327: #define RS_LEN( x )    (x).rs_len
                    328: #define RS_STRING( x ) (x).rs_string
                    329: 
                    330: /* Resource type information block */
                    331: struct rsrc_typeinfo
                    332:     {
                    333:     unsigned short rt_id;
                    334:     unsigned short rt_nres;
                    335:     long rt_proc;
                    336:     };
                    337: 
                    338: #define RT_ID( x )   (x).rt_id
                    339: #define RT_NRES( x ) (x).rt_nres
                    340: #define RT_PROC( x ) (x).rt_proc
                    341: 
                    342: /* Resource name information block */
                    343: struct rsrc_nameinfo
                    344:     {
                    345:     /* The following two fields must be shifted left by the value of  */
                    346:     /* the rs_align field to compute their actual value.  This allows */
                    347:     /* resources to be larger than 64k, but they do not need to be    */
1.1.1.2 ! root      348:     /* aligned on 512 byte boundaries, the way segments are          */
        !           349:     unsigned short rn_offset;  /* file offset to resource data */
        !           350:     unsigned short rn_length;  /* length of resource data */
        !           351:     unsigned short rn_flags;   /* resource flags */
        !           352:     unsigned short rn_id;      /* resource name id */
        !           353:     unsigned short rn_handle;  /* If loaded, then global handle */
        !           354:     unsigned short rn_usage;   /* Initially zero.  Number of times */
        !           355:                                /* the handle for this resource has */
        !           356:                                /* been given out */
1.1       root      357:     };
                    358: 
                    359: #define RN_OFFSET( x ) (x).rn_offset
                    360: #define RN_LENGTH( x ) (x).rn_length
                    361: #define RN_FLAGS( x )  (x).rn_flags
                    362: #define RN_ID( x )     (x).rn_id
                    363: #define RN_HANDLE( x ) (x).rn_handle
                    364: #define RN_USAGE( x )  (x).rn_usage
                    365: 
1.1.1.2 ! root      366: #define RSORDID     0x8000     /* if high bit of ID set then integer id */
        !           367:                                /* otherwise ID is offset of string from
        !           368:                                   the beginning of the resource table */
        !           369: 
        !           370:                                /* Ideally these are the same as the */
        !           371:                                /* corresponding segment flags */
        !           372: #define RNMOVE     0x0010      /* Moveable resource */
        !           373: #define RNPURE     0x0020      /* Pure (read-only) resource */
        !           374: #define RNPRELOAD   0x0040     /* Preloaded resource */
        !           375: #define RNDISCARD   0xF000     /* Discard priority level for resource */
1.1       root      376: 
                    377: /* Resource table */
                    378: struct new_rsrc
                    379:     {
1.1.1.2 ! root      380:     unsigned short rs_align;   /* alignment shift count for resources */
1.1       root      381:     struct rsrc_typeinfo rs_typeinfo;
                    382:     };
                    383: 
                    384: #define RS_ALIGN( x ) (x).rs_align
                    385: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.