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