home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / toolkt21 / c / os2h / newexe.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-12  |  20.1 KB  |  488 lines

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