home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / borhead.zip / NEWEXE.H < prev    next >
C/C++ Source or Header  |  1994-11-09  |  21KB  |  495 lines

  1. /*
  2.  *      SCCSID = @(#)newexe.h    6.3 92/03/15
  3.  *
  4.  *  Title
  5.  *
  6.  *      newexe.h
  7.  *      (C) Copyright IBM Corp 1984-1992
  8.  *      (C) Copyright Microsoft Corp 1984-1987
  9.  *
  10.  *  Description
  11.  *
  12.  *      Data structure definitions for the DOS 4.0/Windows 2.0/OS-2
  13.  *      executable file format.  Includes WLO definitions.
  14.  *
  15.  */
  16.  
  17. #if defined(__IBMC__)
  18. #pragma info( none )
  19.    #ifndef __CHKHDR__
  20.       #pragma info( none )
  21.    #endif
  22. #pragma info( restore )
  23. #endif    /* __IBMC__ */
  24.  
  25. #ifdef __cplusplus
  26.       extern "C" {
  27. #endif
  28.  
  29. #ifndef __NEWEXE__
  30. #define __NEWEXE__
  31.  
  32.  
  33.     /*_________________________________________________________________*
  34.      |                                                                 |
  35.      |                                                                 |
  36.      |  DOS3 .EXE FILE HEADER DEFINITION                               |
  37.      |                                                                 |
  38.      |_________________________________________________________________|
  39.      *                                                                 */
  40.  
  41.  
  42. #define EMAGIC          0x5A4D          /* Old magic number */
  43. #define ENEWEXE         sizeof(struct exe_hdr)
  44.                                         /* Value of E_LFARLC for new .EXEs */
  45. #define ENEWHDR         0x003C          /* Offset in old hdr. of ptr. to new */
  46. #define ERESWDS         0x0010          /* No. of reserved words (OLD) */
  47. #define ERES1WDS        0x0004          /* No. of reserved words in e_res */
  48. #define ERES2WDS        0x000A          /* No. of reserved words in e_res2 */
  49. #define ECP             0x0004          /* Offset in struct of E_CP */
  50. #define ECBLP           0x0002          /* Offset in struct of E_CBLP */
  51. #define EMINALLOC       0x000A          /* Offset in struct of E_MINALLOC */
  52.  
  53. struct exe_hdr                          /* DOS 1, 2, 3 .EXE header */
  54.   {
  55.     unsigned short      e_magic;        /* Magic number */
  56.     unsigned short      e_cblp;         /* Bytes on last page of file */
  57.     unsigned short      e_cp;           /* Pages in file */
  58.     unsigned short      e_crlc;         /* Relocations */
  59.     unsigned short      e_cparhdr;      /* Size of header in paragraphs */
  60.     unsigned short      e_minalloc;     /* Minimum extra paragraphs needed */
  61.     unsigned short      e_maxalloc;     /* Maximum extra paragraphs needed */
  62.     unsigned short      e_ss;           /* Initial (relative) SS value */
  63.     unsigned short      e_sp;           /* Initial SP value */
  64.     unsigned short      e_csum;         /* Checksum */
  65.     unsigned short      e_ip;           /* Initial IP value */
  66.     unsigned short      e_cs;           /* Initial (relative) CS value */
  67.     unsigned short      e_lfarlc;       /* File address of relocation table */
  68.     unsigned short      e_ovno;         /* Overlay number */
  69.     unsigned short      e_res[ERES1WDS];/* Reserved words */
  70.     unsigned short      e_oemid;        /* OEM identifier (for e_oeminfo) */
  71.     unsigned short      e_oeminfo;      /* OEM information; e_oemid specific */
  72.     unsigned short      e_res2[ERES2WDS];/* Reserved words */
  73.     long                e_lfanew;       /* File address of new exe header */
  74.   };
  75.  
  76. #define E_MAGIC(x)      (x).e_magic
  77. #define E_CBLP(x)       (x).e_cblp
  78. #define E_CP(x)         (x).e_cp
  79. #define E_CRLC(x)       (x).e_crlc
  80. #define E_CPARHDR(x)    (x).e_cparhdr
  81. #define E_MINALLOC(x)   (x).e_minalloc
  82. #define E_MAXALLOC(x)   (x).e_maxalloc
  83. #define E_SS(x)         (x).e_ss
  84. #define E_SP(x)         (x).e_sp
  85. #define E_CSUM(x)       (x).e_csum
  86. #define E_IP(x)         (x).e_ip
  87. #define E_CS(x)         (x).e_cs
  88. #define E_LFARLC(x)     (x).e_lfarlc
  89. #define E_OVNO(x)       (x).e_ovno
  90. #define E_RES(x)        (x).e_res
  91. #define E_OEMID(x)      (x).e_oemid
  92. #define E_OEMINFO(x)    (x).e_oeminfo
  93. #define E_RES2(x)       (x).e_res2
  94. #define E_LFANEW(x)     (x).e_lfanew
  95.  
  96.  
  97.     /*_________________________________________________________________*
  98.      |                                                                 |
  99.      |                                                                 |
  100.      |  OS/2 & WINDOWS .EXE FILE HEADER DEFINITION - 286 version       |
  101.      |                                                                 |
  102.      |_________________________________________________________________|
  103.      *                                                                 */
  104.  
  105. #define NEMAGIC         0x454E          /* New magic number */
  106. #define NERESBYTES      8               /* Eight bytes reserved (now) */
  107. #define NECRC           8               /* Offset into new header of NE_CRC */
  108.  
  109. struct new_exe                          /* New .EXE header */
  110.   {
  111.     unsigned short      ne_magic;       /* Magic number NE_MAGIC */
  112.     unsigned char       ne_ver;         /* Version number */
  113.     unsigned char       ne_rev;         /* Revision number */
  114.     unsigned short      ne_enttab;      /* Offset of Entry Table */
  115.     unsigned short      ne_cbenttab;    /* Number of bytes in Entry Table */
  116.     long                ne_crc;         /* Checksum of whole file */
  117.     unsigned short      ne_flags;       /* Flag word */
  118.     unsigned short      ne_autodata;    /* Automatic data segment number */
  119.     unsigned short      ne_heap;        /* Initial heap allocation */
  120.     unsigned short      ne_stack;       /* Initial stack allocation */
  121.     long                ne_csip;        /* Initial CS:IP setting */
  122.     long                ne_sssp;        /* Initial SS:SP setting */
  123.     unsigned short      ne_cseg;        /* Count of file segments */
  124.     unsigned short      ne_cmod;        /* Entries in Module Reference Table */
  125.     unsigned short      ne_cbnrestab;   /* Size of non-resident name table */
  126.     unsigned short      ne_segtab;      /* Offset of Segment Table */
  127.     unsigned short      ne_rsrctab;     /* Offset of Resource Table */
  128.     unsigned short      ne_restab;      /* Offset of resident name table */
  129.     unsigned short      ne_modtab;      /* Offset of Module Reference Table */
  130.     unsigned short      ne_imptab;      /* Offset of Imported Names Table */
  131.     long                ne_nrestab;     /* Offset of Non-resident Names Table */
  132.     unsigned short      ne_cmovent;     /* Count of movable entries */
  133.     unsigned short      ne_align;       /* Segment alignment shift count */
  134.     unsigned short      ne_cres;        /* Count of resource entries */
  135.     unsigned char       ne_exetyp;      /* Target operating system */
  136.     unsigned char       ne_flagsothers; /* Other .EXE flags */
  137.     char                ne_res[NERESBYTES];
  138.                                         /* Pad structure to 64 bytes */
  139.   };
  140.  
  141. #define NE_MAGIC(x)         (x).ne_magic
  142. #define NE_VER(x)           (x).ne_ver
  143. #define NE_REV(x)           (x).ne_rev
  144. #define NE_ENTTAB(x)        (x).ne_enttab
  145. #define NE_CBENTTAB(x)      (x).ne_cbenttab
  146. #define NE_CRC(x)           (x).ne_crc
  147. #define NE_FLAGS(x)         (x).ne_flags
  148. #define NE_AUTODATA(x)      (x).ne_autodata
  149. #define NE_HEAP(x)          (x).ne_heap
  150. #define NE_STACK(x)         (x).ne_stack
  151. #define NE_CSIP(x)          (x).ne_csip
  152. #define NE_SSSP(x)          (x).ne_sssp
  153. #define NE_CSEG(x)          (x).ne_cseg
  154. #define NE_CMOD(x)          (x).ne_cmod
  155. #define NE_CBNRESTAB(x)     (x).ne_cbnrestab
  156. #define NE_SEGTAB(x)        (x).ne_segtab
  157. #define NE_RSRCTAB(x)       (x).ne_rsrctab
  158. #define NE_RESTAB(x)        (x).ne_restab
  159. #define NE_MODTAB(x)        (x).ne_modtab
  160. #define NE_IMPTAB(x)        (x).ne_imptab
  161. #define NE_NRESTAB(x)       (x).ne_nrestab
  162. #define NE_CMOVENT(x)       (x).ne_cmovent
  163. #define NE_ALIGN(x)         (x).ne_align
  164. #define NE_CRES(x)          (x).ne_cres
  165. #define NE_RES(x)           (x).ne_res
  166. #define NE_EXETYP(x)        (x).ne_exetyp
  167. #define NE_FLAGSOTHERS(x)   (x).ne_flagsothers
  168.  
  169. #define NE_USAGE(x)     (WORD)*((WORD *)(x)+1)
  170. #define NE_PNEXTEXE(x)  (WORD)(x).ne_cbenttab
  171. #define NE_ONEWEXE(x)   (WORD)(x).ne_crc
  172. #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
  173.  
  174.  
  175. /*
  176.  *  Target operating systems
  177.  */
  178.  
  179. #define NE_UNKNOWN      0x0             /* Unknown (any "new-format" OS) */
  180. #define NE_OS2          0x1             /* OS/2 (default)  */
  181. #define NE_WINDOWS      0x2             /* Windows */
  182. #define NE_DOS4         0x3             /* DOS 4.x */
  183. #define NE_DEV386       0x4             /* Windows 386 */
  184.  
  185.  
  186. /*
  187.  *  Format of NE_FLAGS(x):
  188.  *
  189.  *  p                                   Not-a-process
  190.  *   x                                  Unused
  191.  *    e                                 Errors in image
  192.  *     x                                Unused
  193.  *      b                               Bound Family/API
  194.  *       ttt                            Application type
  195.  *          f                           Floating-point instructions
  196.  *           3                          386 instructions
  197.  *            2                         286 instructions
  198.  *             0                        8086 instructions
  199.  *              P                       Protected mode only
  200.  *               p                      Per-process library initialization
  201.  *                i                     Instance data
  202.  *                 s                    Solo data
  203.  */
  204. #define NENOTP          0x8000          /* Not a process */
  205. #define NEIERR          0x2000          /* Errors in image */
  206. #define NEBOUND         0x0800          /* Bound Family/API */
  207. #define NEAPPTYP        0x0700          /* Application type mask */
  208. #define NENOTWINCOMPAT  0x0100          /* Not compatible with P.M. Windowing */
  209. #define NEWINCOMPAT     0x0200          /* Compatible with P.M. Windowing */
  210. #define NEWINAPI        0x0300          /* Uses P.M. Windowing API */
  211. #define NEFLTP          0x0080          /* Floating-point instructions */
  212. #define NEI386          0x0040          /* 386 instructions */
  213. #define NEI286          0x0020          /* 286 instructions */
  214. #define NEI086          0x0010          /* 8086 instructions */
  215. #define NEPROT          0x0008          /* Runs in protected mode only */
  216. #define NEPPLI          0x0004          /* Per-Process Library Initialization */
  217. #define NEINST          0x0002          /* Instance data */
  218. #define NESOLO          0x0001          /* Solo data */
  219.  
  220. /*
  221.  *  Format of NE_FLAGSOTHERS(x):
  222.  *
  223.  *      7 6 5 4 3 2 1 0  - bit no
  224.  *      |         | | |
  225.  *      |         | | +---------------- Support for long file names
  226.  *      |         | +------------------ Windows 2.x app runs in prot mode
  227.  *      |         +-------------------- Windows 2.x app gets prop. font
  228.  *      +------------------------------ WLO appl on OS/2 (markwlo.exe)
  229.  *
  230.  */
  231.  
  232. #define NELONGNAMES     0x01
  233. #define NEWINISPROT     0x02
  234. #define NEWINGETPROPFON 0x04
  235. #define NEWLOAPPL       0x80
  236.  
  237.  
  238.  
  239. struct new_seg                          /* New .EXE segment table entry */
  240.   {
  241.     unsigned short      ns_sector;      /* File sector of start of segment */
  242.     unsigned short      ns_cbseg;       /* Number of bytes in file */
  243.     unsigned short      ns_flags;       /* Attribute flags */
  244.     unsigned short      ns_minalloc;    /* Minimum allocation in bytes */
  245.   };
  246.  
  247. #define NS_SECTOR(x)    (x).ns_sector
  248. #define NS_CBSEG(x)     (x).ns_cbseg
  249. #define NS_FLAGS(x)     (x).ns_flags
  250. #define NS_MINALLOC(x)  (x).ns_minalloc
  251.  
  252.  
  253. /*
  254.  *  Format of NS_FLAGS(x)
  255.  *
  256.  *  Flag word has the following format:
  257.  *
  258.  *      15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
  259.  *          |  |  |  |  | | | | | | | | | | |
  260.  *          |  |  |  |  | | | | | | | | +-+-+--- Segment type DATA/CODE
  261.  *          |  |  |  |  | | | | | | | +--------- Iterated segment
  262.  *          |  |  |  |  | | | | | | +----------- Movable segment
  263.  *          |  |  |  |  | | | | | +------------- Segment can be shared
  264.  *          |  |  |  |  | | | | +--------------- Preload segment
  265.  *          |  |  |  |  | | | +----------------- Execute/read-only for code/data segment
  266.  *          |  |  |  |  | | +------------------- Segment has relocations
  267.  *          |  |  |  |  | +--------------------- Code conforming/Data is expand down
  268.  *          |  |  |  +--+----------------------- I/O privilege level
  269.  *          |  |  +----------------------------- Discardable segment
  270.  *          |  +-------------------------------- 32-bit code segment
  271.  *          +----------------------------------- Huge segment/GDT allocation requested
  272.  *
  273.  */
  274.  
  275. #define NSTYPE          0x0007          /* Segment type mask */
  276.  
  277. #if (EXE386 == 0)
  278. #define NSCODE          0x0000          /* Code segment */
  279. #define NSDATA          0x0001          /* Data segment */
  280. #define NSITER          0x0008          /* Iterated segment flag */
  281. #define NSMOVE          0x0010          /* Movable segment flag */
  282. #define NSSHARED        0x0020          /* Shared segment flag */
  283. #define NSPRELOAD       0x0040          /* Preload segment flag */
  284. #define NSEXRD          0x0080          /* Execute-only (code segment), or
  285.                                         *  read-only (data segment)
  286.                                         */
  287. #define NSRELOC         0x0100          /* Segment has relocations */
  288. #define NSCONFORM       0x0200          /* Conforming segment */
  289. #define NSEXPDOWN       0x0200          /* Data segment is expand down */
  290. #define NSDPL           0x0C00          /* I/O privilege level (286 DPL bits) */
  291. #define SHIFTDPL        10              /* Left shift count for SEGDPL field */
  292. #define NSDISCARD       0x1000          /* Segment is discardable */
  293. #define NS32BIT         0x2000          /* 32-bit code segment */
  294. #define NSHUGE          0x4000          /* Huge memory segment, length of
  295.                                          * segment and minimum allocation
  296.                                          * size are in segment sector units
  297.                                          */
  298. #define NSGDT           0x8000          /* GDT allocation requested */
  299.  
  300. #define NSPURE          NSSHARED        /* For compatibility */
  301.  
  302. #define NSALIGN 9       /* Segment data aligned on 512 byte boundaries */
  303.  
  304. #define NSLOADED    0x0004      /* ns_sector field contains memory addr */
  305. #endif
  306.  
  307.  
  308. struct new_segdata                      /* Segment data */
  309.   {
  310.     union
  311.       {
  312.         struct
  313.           {
  314.             unsigned short      ns_niter;       /* number of iterations */
  315.             unsigned short      ns_nbytes;      /* number of bytes */
  316.             char                ns_iterdata;    /* iterated data bytes */
  317.           } ns_iter;
  318.         struct
  319.           {
  320.             char                ns_data;        /* data bytes */
  321.           } ns_noniter;
  322.       } ns_union;
  323.   };
  324.  
  325. struct new_rlcinfo                      /* Relocation info */
  326.   {
  327.     unsigned short      nr_nreloc;      /* number of relocation items that */
  328.   };                                    /* follow */
  329.  
  330. #pragma pack(1)
  331.  
  332.  
  333. struct new_rlc                          /* Relocation item */
  334.   {
  335.     char                nr_stype;       /* Source type */
  336.     char                nr_flags;       /* Flag byte */
  337.     unsigned short      nr_soff;        /* Source offset */
  338.     union
  339.       {
  340.         struct
  341.           {
  342.             char        nr_segno;       /* Target segment number */
  343.             char        nr_res;         /* Reserved */
  344.             unsigned short nr_entry;    /* Target Entry Table offset */
  345.           }             nr_intref;      /* Internal reference */
  346.         struct
  347.           {
  348.             unsigned short nr_mod;      /* Index into Module Reference Table */
  349.             unsigned short nr_proc;     /* Procedure ordinal or name offset */
  350.           }             nr_import;      /* Import */
  351.         struct
  352.           {
  353.             unsigned short nr_ostype;   /* OSFIXUP type */
  354.             unsigned short nr_osres;    /* reserved */
  355.           }             nr_osfix;       /* Operating system fixup */
  356.       }                 nr_union;       /* Union */
  357.   };
  358.  
  359. #pragma pack()
  360.  
  361.  
  362. #define NR_STYPE(x)     (x).nr_stype
  363. #define NR_FLAGS(x)     (x).nr_flags
  364. #define NR_SOFF(x)      (x).nr_soff
  365. #define NR_SEGNO(x)     (x).nr_union.nr_intref.nr_segno
  366. #define NR_RES(x)       (x).nr_union.nr_intref.nr_res
  367. #define NR_ENTRY(x)     (x).nr_union.nr_intref.nr_entry
  368. #define NR_MOD(x)       (x).nr_union.nr_import.nr_mod
  369. #define NR_PROC(x)      (x).nr_union.nr_import.nr_proc
  370. #define NR_OSTYPE(x)    (x).nr_union.nr_osfix.nr_ostype
  371. #define NR_OSRES(x)     (x).nr_union.nr_osfix.nr_osres
  372.  
  373.  
  374.  
  375. /*
  376.  *  Format of NR_STYPE(x) and R32_STYPE(x):
  377.  *
  378.  *       7 6 5 4 3 2 1 0  - bit no
  379.  *               | | | |
  380.  *               +-+-+-+--- source type
  381.  *
  382.  */
  383.  
  384. #define NRSTYP          0x0f            /* Source type mask */
  385. #define NRSBYT          0x00            /* lo byte (8-bits)*/
  386. #define NRSSEG          0x02            /* 16-bit segment (16-bits) */
  387. #define NRSPTR          0x03            /* 16:16 pointer (32-bits) */
  388. #define NRSOFF          0x05            /* 16-bit offset (16-bits) */
  389. #define NRPTR48         0x06            /* 16:32 pointer (48-bits) */
  390. #define NROFF32         0x07            /* 32-bit offset (32-bits) */
  391. #define NRSOFF32        0x08            /* 32-bit self-relative offset (32-bits) */
  392.  
  393.  
  394. /*
  395.  *  Format of NR_FLAGS(x) and R32_FLAGS(x):
  396.  *
  397.  *       7 6 5 4 3 2 1 0  - bit no
  398.  *                 | | |
  399.  *                 | +-+--- Reference type
  400.  *                 +------- Additive fixup
  401.  */
  402.  
  403. #define NRADD           0x04            /* Additive fixup */
  404. #define NRRTYP          0x03            /* Reference type mask */
  405. #define NRRINT          0x00            /* Internal reference */
  406. #define NRRORD          0x01            /* Import by ordinal */
  407. #define NRRNAM          0x02            /* Import by name */
  408. #define NRROSF          0x03            /* Operating system fixup */
  409.  
  410.  
  411. #if (EXE386 == 0)
  412.  
  413. /* Resource type or name string */
  414. struct rsrc_string
  415.     {
  416.     char rs_len;            /* number of bytes in string */
  417.     char rs_string[ 1 ];    /* text of string */
  418.     };
  419.  
  420. #define RS_LEN( x )    (x).rs_len
  421. #define RS_STRING( x ) (x).rs_string
  422.  
  423. /* Resource type information block */
  424. struct rsrc_typeinfo
  425.     {
  426.     unsigned short rt_id;
  427.     unsigned short rt_nres;
  428.     long rt_proc;
  429.     };
  430.  
  431. #define RT_ID( x )   (x).rt_id
  432. #define RT_NRES( x ) (x).rt_nres
  433. #define RT_PROC( x ) (x).rt_proc
  434.  
  435. /* Resource name information block */
  436. struct rsrc_nameinfo
  437.     {
  438.     /* The following two fields must be shifted left by the value of  */
  439.     /* the rs_align field to compute their actual value.  This allows */
  440.     /* resources to be larger than 64k, but they do not need to be    */
  441.     /* aligned on 512 byte boundaries, the way segments are           */
  442.     unsigned short rn_offset;   /* file offset to resource data */
  443.     unsigned short rn_length;   /* length of resource data */
  444.     unsigned short rn_flags;    /* resource flags */
  445.     unsigned short rn_id;       /* resource name id */
  446.     unsigned short rn_handle;   /* If loaded, then global handle */
  447.     unsigned short rn_usage;    /* Initially zero.  Number of times */
  448.                                 /* the handle for this resource has */
  449.                                 /* been given out */
  450.     };
  451.  
  452. #define RN_OFFSET( x ) (x).rn_offset
  453. #define RN_LENGTH( x ) (x).rn_length
  454. #define RN_FLAGS( x )  (x).rn_flags
  455. #define RN_ID( x )     (x).rn_id
  456. #define RN_HANDLE( x ) (x).rn_handle
  457. #define RN_USAGE( x )  (x).rn_usage
  458.  
  459. #define RSORDID     0x8000      /* if high bit of ID set then integer id */
  460.                                 /* otherwise ID is offset of string from
  461.                                    the beginning of the resource table */
  462.  
  463.                                 /* Ideally these are the same as the */
  464.                                 /* corresponding segment flags */
  465. #define RNMOVE      0x0010      /* Moveable resource */
  466. #define RNPURE      0x0020      /* Pure (read-only) resource */
  467. #define RNPRELOAD   0x0040      /* Preloaded resource */
  468. #define RNDISCARD   0xF000      /* Discard priority level for resource */
  469.  
  470. /* Resource table */
  471. struct new_rsrc
  472.     {
  473.     unsigned short rs_align;    /* alignment shift count for resources */
  474.     struct rsrc_typeinfo rs_typeinfo;
  475.     };
  476.  
  477. #define RS_ALIGN( x ) (x).rs_align
  478.  
  479.  
  480. #endif /* NOT EXE386 */
  481.  
  482. #endif /* __NEWEXE__ */
  483.  
  484. #ifdef __cplusplus
  485.         }
  486. #endif
  487.  
  488. #if defined(__IBMC__)
  489. #pragma info( none )
  490.    #ifndef __CHKHDR__
  491.       #pragma info( restore )
  492.    #endif
  493. #pragma info( restore )
  494. #endif    /* __IBMC__ */
  495.