{  OS/2 Executable Header Definitions   }

Unit ExeHdr;

Interface

{----[ EXE ]----}

type
  bbmask    = Word;

  exe = record
    eid        : Word;                  { contains EXEID, below }
    elast      : Word;                  { # of Bytes in last page }
    epagsiz    : Word;                  { # of pages in whole file }
    erelcnt    : Word;                  { # of relocation entrys }
    ehdrsiz    : Word;                  { size of header, in paragraphs }
    eminfre    : Word;                  { min # of free paragraphs needed }
    emaxfre    : Word;                  { max # of free paragraphs needed }
    eiSS       : Word;                  { initial SS value }
    eiSP       : Word;                  { initial SP value }
    enegsum    : Word;                  { negative sum of entire file }
    eiIP       : Word;                  { initial IP value }
    eiCS       : Word;                  { initial CS value }
    ereloff    : Word;                  { offset in file of relocation table }
    eovlnum    : Word;                  { number of the overlay }

{      the following fields may not be present.
 *              ereloff = 28            not present
 *                      = 30            exe.ever present and valid
 *                      = 32            exe.ever field contains garbage
 *              ereloff > 32            exe.ever present and valid
 *                                              = 0 if "don't know"
 }

    ever       : Word;                  { version # of producing linker }
    dumy       : Word;                  { unused }

{      the following fields may not be present - if the exe.ereloff
 *      value encompasses the fields then they are present and valid.
 }

    ebb        : bbmask;                { behavior bits }
    dumy2      : Array[0..6] of Word;   { must be 0 until defined }
  end;

Const
  ExeId = $5A4D;                        { Magic ID value }


{----[ EXE386 ]----}

{ Data structure definitions for the OS/2 executable file format (flat model) }

Const
  BitPerWord    = 16;
  BitPerByte    = 8;
  ObjPageLen    = 4096;
  E32Magic1     = 'L';       { New Magic number  "LX" }
  E32Magic2     = 'X';       { New Magic number  "LX" }
  E32Magic      = $584c;     { New Magic number  "LX" }
  E32ResByteS1  = 0;         { First Bytes reserved }
  E32ResByteS2  = 0;         { Second Bytes reserved }
  E32ResByteS3  = 20;        { Third Bytes reserved }
  E32LEBO       = $00;       { Little Endian Byte Order }
  E32BEBO       = $01;       { Big Endian Byte Order }
  E32LEWO       = $00;       { Little Endian Word Order }
  E32BEWO       = $01;       { Big Endian Word Order }
  E32Level      = 0;         { 32-bit EXE format Level }
  E32CPU286     = $001;      { Intel 80286 or upwardly compatibile }
  E32CPU386     = $002;      { Intel 80386 or upwardly compatibile }
  E32CPU486     = $003;      { Intel 80486 or upwardly compatibile }

Type
  e32_exe = Record             { New 32-bit .EXE header }
    e32_Magic         : Array[0..1] of Byte;  { Magic number E32_Magic }
    e32_border        : Byte;       { The Byte ordering for the .EXE }
    e32_Worder        : Byte;       { The Word ordering for the .EXE }
    e32_Level         : Longint;    { The EXE format Level for now = 0 }
    e32_cpu           : Word;       { The CPU type }
    e32_os            : Word;       { The OS type }
    e32_ver           : Longint;    { Module version }
    e32_mflags        : Longint;    { Module flags }
    e32_mpages        : Longint;    { Module # pages }
    e32_startobj      : Longint;    { Object # for instruction pointer }
    e32_eip           : Longint;    { Extended instruction pointer }
    e32_stackobj      : Longint;    { Object # for stack pointer }
    e32_esp           : Longint;    { Extended stack pointer }
    e32_pagesize      : Longint;    { .EXE page size }
    e32_pageshift     : Longint;    { Page alignment shift in .EXE }
    e32_fixupsize     : Longint;    { Fixup section size }
    e32_fixupsum      : Longint;    { Fixup section checksum }
    e32_ldrsize       : Longint;    { Loader section size }
    e32_ldrsum        : Longint;    { Loader section checksum }
    e32_objtab        : Longint;    { Object table offset }
    e32_objcnt        : Longint;    { Number of objects in module }
    e32_objmap        : Longint;    { Object page map offset }
    e32_itermap       : Longint;    { Object iterated data map offset }
    e32_rsrctab       : Longint;    { Offset of Resource Table }
    e32_rsrccnt       : Longint;    { Number of resource entries }
    e32_restab        : Longint;    { Offset of resident name table }
    e32_enttab        : Longint;    { Offset of Entry Table }
    e32_dirtab        : Longint;    { Offset of Module Directive Table }
    e32_dircnt        : Longint;    { Number of module directives }
    e32_fpagetab      : Longint;    { Offset of Fixup Page Table }
    e32_frectab       : Longint;    { Offset of Fixup Record Table }
    e32_impmod        : Longint;    { Offset of Import Module Name Table }
    e32_impmodcnt     : Longint;    { Number of entries in Import Module Name
                                      Table }
    e32_impproc       : Longint;    { Offset of Import Procedure Name Table }
    e32_pagesum       : Longint;    { Offset of Per-Page Checksum Table }
    e32_datapage      : Longint;    { Offset of Enumerated Data Pages }
    e32_preload       : Longint;    { Number of preload pages }
    e32_nrestab       : Longint;    { Offset of Non-resident Names Table }
    e32_cbnrestab     : Longint;    { Size of Non-resident Name Table }
    e32_nressum       : Longint;    { Non-resident Name Table Checksum }
    e32_autodata      : Longint;    { Object # for automatic data object }
    e32_debuginfo     : Longint;    { Offset of the debugging information }
    e32_debuglen      : Longint;    { The length of the debugging info. in Bytes }
    e32_instpreload   : Longint;    { Number of instance pages in preload section
                                      of .EXE file }
    e32_instdemand    : Longint;    { Number of instance pages in demand load
                                      section of .EXE file }
    e32_heapsize      : Longint;    { Size of heap - for 16-bit apps }
    e32_stacksize     : Longint;    { Size of stack }
    e32_res3 : Array[ 0..E32RESByteS3-1 ] of Byte; { Pad structure to 196 Bytes }
  end;

{
 *  Format of E32_MFLAGS(x):
 *
 *  Low Word has the following format:
 *
 *  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
 *   |     |          | |     | | | |
 *   |     |          | |     | | | +--- Per-Process Library Initialization
 *   |     |          | |     | | +----- SystemDLL (internal fixups discarded)
 *   |     |          | |     | +------- No Internal Fixups for Module in .EXE
 *   |     |          | |     +--------- No External Fixups for Module in .EXE
 *   |     |          | +--------------- Incompatible with PM Windowing
 *   |     |          +----------------- Compatible with PM Windowing
 *   |     |                             Uses PM Windowing API
 *   |     +---------------------------- Module not Loadable
 *   +---------------------------------- Library Module
 }

Const
  E32NotP           = $8000;     { Library Module - used as NENOTP }
  E32NoLoad         = $2000;     { Module not Loadable }
  E32PMAPI          = $0300;     { Uses PM Windowing API }
  E32PMW            = $0200;     { Compatible with PM Windowing }
  E32NoPMW          = $0100;     { Incompatible with PM Windowing }
  E32NoExtFix       = $0020;     { NO External Fixups in .EXE }
  E32NoIntFix       = $0010;     { NO Internal Fixups in .EXE }
  E32SysDll         = $0008;     { System DLL, Internal Fixups discarded}
  E32LibInit        = $0004;     { Per-Process Library Initialization }
  E32LibTerm        = $40000000; { Per-Process Library Termination }
  E32AppMask        = $0300;     { Application Type Mask }

{
 *  Format of E32_MFLAGS(x):
 *
 *  High Word has the following format:
 *
 *  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
 *                                    | |
 *                                    | +--- Protected memory library module
 *                                    +----- Device driver
 }

  E32ProtDll        = $10000;   { Protected memory library module }
  E32Device         = $20000;   { Device driver                   }
  E32ModExe         = $00000;   { .EXE module                     }
  E32ModDll         = $08000;   { .DLL module                     }
  E32ModProtDll     = $18000;   { Protected memory library module }
  E32ModPdev        = $20000;   { Physical device driver          }
  E32ModVdev        = $28000;   { Virtual device driver           }
  E32ModMask        = $38000;   { Module type mask                }

{ RELOCATION DEFINITIONS - RUN-TIME FIXUPS }

Type
  Offset = Record
    Offset16 : Word;
    Offset32 : Longint;
  end;                                 { 16-bit or 32-bit offset }

  {**ET+ r32_rlc - Relocation item }

  r32_rlc = Record                     { Relocation item }
    nr_stype    : Byte;        { Source type - field shared with new_rlc }
    nr_flags    : Byte;        { Flag Byte - field shared with new_rlc }
    r32_soff    : Integer;     { Source offset }
    r32_objmod  : Word;        { Target object number or Module ordinal }

    r23_target : Record
      Case Byte of
        0 : ( IntRef : Longint );                { Internal fixup }

        1 : ( ExtRef : Record
                Case Boolean of
                  True  : ( Proc : Longint );    { Procedure name offset }
                  False : ( Ord  : Longint );    { Procedure ordinal }
              end );

        2 : ( Addfix : Record
                Entry   : Word;               { Entry ordinal }
                Addval  : Longint;            { Value added to the address }
              end );
    end;

    r32_srccount : Word;       { Number of chained fixup records }
    r32_chain    : Word;       { Chain head }
  end;

{
 *  In 32-bit .EXE file run-time relocations are written as varying size
 *  records, so we need many size definitions.
 }

Const
  RIntSize16      = 8;
  RIntSize32      = 10;
  ROrdSize        = 8;
  RNamSize16      = 8;
  RNamSize32      = 10;
  RAddSize16      = 10;
  RAddSize32      = 12;

{
 *  Format of NR_SType(x)
 *
 *       7 6 5 4 3 2 1 0  - bit no
 *           | | | | | |
 *           | | +-+-+-+--- Source type
 *           | +----------- Fixup to 16:16 alias
 *           +------------- List of source offset follows fixup recOrd
 }

 NRSrcMask       = $0f;            { Source type mask }
 NRAlias         = $10;            { Fixup to alias }
 NRChain         = $20;            { List of source offset follows }
                                   { fixup recOrd, source offset field }
                                   { in fixup recOrd contains number }
                                   { of elements in list }

{
 *  Format of NR_Flags(x) and R32_Flags(x):
 *
 *       7 6 5 4 3 2 1 0  - bit no
 *       | | | |   | | |
 *       | | | |   | +-+--- Reference type
 *       | | | |   +------- Additive fixup
 *       | | | +----------- 32-bit Target Offset Flag (1 - 32-bit; 0 - 16-bit)
 *       | | +------------- 32-bit Additive Flag (1 - 32-bit; 0 - 16-bit)
 *       | +--------------- 16-bit Object/Module Ordinal (1 - 16-bit; 0-8-bit)
 *       +----------------- 8-bit import Ordinal (1 - 8-bit;
 *                                                0 - NR32BitOff toggles
 *                                                    between 16 and 32 bit
 *                                                    Ordinal)
 }

  NRREnt          = $03;           { Internal entry table fixup }
  NR32BitOff      = $10;           { 32-bit Target Offset }
  NR32BitAdd      = $20;           { 32-bit Additive fixup }
  NR16ObjMod      = $40;           { 16-bit Object/Module Ordinal }
  NR8BitOrd       = $80;           { 8-bit import Ordinal }

{
 *  Data structures for storing run-time fixups in linker virtual memory.
 *
 *  Each object has a list of Object Page Directories which specify
 *  fixups for given page. Each page has its own hash table which is
 *  used to detect fixups to the same target.
 }

  PagePerDir      = 62;
  LG2Dir          = 7;


Type
  ObjPageDir = Record
    Next : Longint;                { Virtual poInter to next dir on list }
    Ht: Array[ 0..PagePerDir-1 ] of Word; {Pointers to individual hash tables}
  end;

{ OBJECT TABLE }

{**ET+ o32_obj Object Table Entry }

  o32_obj = Record                { Flat .Exe object table entry }
    o32_Size       : LongInt;     { Object virtual Size }
    o32_base       : LongInt;     { Object base virtual Address }
    o32_flags      : LongInt;     { Attribute flags }
    o32_pagemap    : LongInt;     { Object page map index }
    o32_mapSize    : LongInt;     { Number of entries in object page map }
    o32_reserved   : LongInt;     { Reserved }
  end;

{
 *  Format of O32_Flags(x)
 *
 *  High Word of dWord flag field is not used for now.
 *  Low Word has the following format:
 *
 *  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
 *   |  |  |  |     | | | | | | | | | | |
 *   |  |  |  |     | | | | | | | | | | +- Readable Object
 *   |  |  |  |     | | | | | | | | | +--- Writeable Object
 *   |  |  |  |     | | | | | | | | +----- Executable Object
 *   |  |  |  |     | | | | | | | +------- Resource Object
 *   |  |  |  |     | | | | | | +--------- Object is Discardable
 *   |  |  |  |     | | | | | +----------- Object is Shared
 *   |  |  |  |     | | | | +------------- Object has preload pages
 *   |  |  |  |     | | | +--------------- Object has invalid pages
 *   |  |  |  |     | | +----------------- Object is permanent and swappable
 *   |  |  |  |     | +------------------- Object is permanent and resident
 *   |  |  |  |     +--------------------- Object is permanent and long lockable
 *   |  |  |  +--------------------------- 16:16 alias required (80x86 specific)
 *   |  |  +------------------------------ Big/Default bit setting (80x86
     |                                     specific)
 *   |  +--------------------------------- Object is conforming for code (80x86
     |                                     specific)
 *   +------------------------------------ Object I/O privilege Level (80x86
                                           specific)
 *
 }

Const
  ObjRead         = $0001;  { Readable Object   }
  ObjWrite        = $0002;  { Writeable Object  }
  ObjRsrc         = $0008;  { Resource Object   }
  ObjInvalid      = $0080;  { Object has invalid pages  }
  LNKNonperm      = $0600;  { Object is nonpermanent - should be }
  ObjNonperm      = $0000;  { zero in the .Exe but LINK386 uses 6 }
  ObjPerm         = $0100;  { Object is permanent and swappable }
  ObjResident     = $0200;  { Object is permanent and resident }
  ObjContig       = $0300;  { Object is resident and contiguous }
  ObjDynamic      = $0400;  { Object is permanent and long locable }
  ObjTypeMask     = $0700;  { Object type mask }
  ObjAlias16      = $1000;  { 16:16 alias required (80x86 specific)       }
  ObjBigDef       = $2000;  { Big/Default bit setting (80x86 specific)    }
  ObjIOPL         = $8000;  { Object I/O privilege Level (80x86 specific) }

{$IFDEF For_ExeHdr}
{Name these flags differently for ExeHdr.Exe-avoid conflicts with 286 version}
  ObjDiscard       = $0010; { Object is Discardable }
  ObjShared        = $0020; { Object is Shared }
  ObjPreLoad       = $0040; { Object has preload pages  }
  ObjExeC          = $0004; { Executable Object }
  ObjCONFORM       = $4000; { Object is conforming for code (80x86 specific)}
{$ELSE}
  { Life will be easier, if we keep the same names for the following flags: }
  NSDiscard        = $0010;  { Object is Discardable }
  NSMove           = NSDiscard; { Moveable object is for sure Discardable }
  NSShared         = $0020;  { Object is Shared }
  NSPreLoad        = $0040;  { Object has preload pages  }
  NSExRD           = $0004;  { Executable Object }
  NSConform        = $4000;  { Object is conforming for code (80x86 specific)}
{$ENDIF}

{**ET+ o32_map - Object Page Map entry }

Type
  o32_map = Record                 { Object Page Table entry }
    o32_pagedataoffset  : Longint; { file offset of page }
    o32_pageSize        : Word;    { # Bytes of page data }
    o32_pageflags       : Word;    { Per-Page attributes }
  end;

Const
  Valid            = $0000;  { Valid Physical Page in .Exe }
  IterData         = $0001;  { Iterated Data Page }
  Invalid          = $0002;  { Invalid Page }
  Zeroed           = $0003;  { Zero Filled Page }
  Range            = $0004;  { Range of pages }
  IterData2        = $0005;  { Iterated Data Page Type II }

{ RESOURCE TABLE }

{**ET+ rsrc32 - Resource Table Entry }

Type
  rsrc32 = Record                  { Resource Table Entry }
    rType  : Word;                 { Resource type }
    Name   : Word;                 { Resource name }
    cb     : LongInt;              { Resource Size }
    Obj    : Word;                 { Object number }
    Offset : LongInt;              { Offset within object }
  end;

  { Iteration RecOrd format for 'ExePACK'ed pages. }
  LX_Iter = Record
    LX_nIter    : Word;            { number of iterations }
    LX_nBytes   : Word;            { number of Bytes }
    LX_Iterdata : Byte;            { iterated data Byte(s) }
  end;


{ ENTRY TABLE DEFINITIONS }

{**ET+ b32_bundle - Entry Table }

  b32_bundle = Record
    b32_cnt  :  Byte;              { Number of entries in this bundle }
    b32_type :  Byte;              { Bundle type }
    b32_obj  :  Word;              { Object number }
  end;                             { Follows entry types }

  e32_entry = Record
    e32_flags : Byte;              { Entry point flags }

    e32_variant  : Record
      Case Byte of
        0 : ( e32_offset : Longint );     { 16-bit/32-bit offset entry }
        1 : ( e32_callgate : Record       { 286 (16-bit) call gate }
                Offset : Longint;         { Offset in segment }
                callgate : Longint
              end );     { Callgate selector }
        2 : ( e32_fwd : Record            { Forwarder }
                ModOrd : Word;            { Module Ordinal number }
                Value  : LongInt;         { Proc name offset or Ordinal }
             end );
    end;
  end;

Const
  FixEnt16        = 3;
  FixEnt32        = 5;
  GateEnt16       = 5;
  FwdEnt          = 7;

{ BUNDLE TYPES }

  Empty        = $00;             { Empty bundle }
  Entry16      = $01;             { 16-bit offset entry poInt }
  Gate16       = $02;             { 286 call gate (16-bit IOPL) }
  Entry32      = $03;             { 32-bit offset entry poInt }
  EntryFWD     = $04;             { Forwarder entry poInt }
  TypeInfo     = $80;             { Typing information present flag }

{
 *  Format for E32_EFlags(x)
 *
 *       7 6 5 4 3 2 1 0  - bit no
 *       | | | | | | | |
 *       | | | | | | | +--- exported entry
 *       | | | | | | +----- uses shared data
 *       +-+-+-+-+-+------- parameter Word count
 }

  E32Export       = $01;          { Exported entry }
  E32Shared       = $02;          { Uses shared data }
  E32Params       = $f8;          { Parameter Word count mask }

{ Flags for forwarders only: }

  Fwd_Ordinal     = $01;          { Imported by Ordinal }


{----[ NEWEXE ]----}

{ Data structure definitions for the DOS 4.0/Windows 2.0/OS-2 }
{ executable file format.  Includes WLO definitions. }

{ DOS 3 EXE HEADER }

Const
  EMagic          = $5A4D;          { Old magic number }
                                    { Value of E_LFARLC for new .Exes }
  ENewHdr         = $003C;          { Offset in old hdr. of ptr. to new }
  EResWds         = $0010;          { No. of reserved wOrds (OLD) }
  ERes1Wds        = $0004;          { No. of reserved wOrds in e_res }
  ERes2Wds        = $000A;          { No. of reserved wOrds in e_res2 }
  ECp             = $0004;          { Offset in struct of E_CP }
  ECBLP           = $0002;          { Offset in struct of E_CBLP }
  EMinAlloc       = $000A;          { Offset in struct of E_MINAlloc }

Type
  exe_hdr = Record                          { DOS 1, 2, 3 .Exe header }
    e_magic         : Word;      { Magic number }
    e_cblp          : Word;      { Bytes on last page of file }
    e_cp            : Word;      { Pages in file }
    e_crlc          : Word;      { Relocations }
    e_cparhdr       : Word;      { Size of header in paragraphs }
    e_minalloc      : Word;      { Minimum extra paragraphs needed }
    e_maxalloc      : Word;      { Maximum extra paragraphs needed }
    e_ss            : Word;      { Initial (relative) SS value }
    e_sp            : Word;      { Initial SP value }
    e_csum          : Word;      { Checksum }
    e_ip            : Word;      { Initial IP value }
    e_cs            : Word;      { Initial (relative) CS value }
    e_lfarlc        : Word;      { File Address of relocation table }
    e_ovno          : Word;      { Overlay number }
    e_res : Array[ 1..ERes1Wds ] of Word;  { Reserved wOrds }
    e_oemid         : Word;      { OEM identifier (for e_oeminfo) }
    e_oeminfo       : Word;      { OEM information; e_oemid specific }
    e_res2 : Array[ 1..ERes2Wds ] of Word; { Reserved wOrds }
    e_lfanew        : Longint;       { File Address of new exe header }
  end;

Const
  ENewExe         = Sizeof(exe_hdr);

  {  OS/2 & WINDOWS .Exe FILE HEADER DEFINITION - 286 version      }

  NEMagic         = $454E;          { New magic number }
  NEResBytes      = 8;              { Eight bytes reserved (now) }
  NECrc           = 8;              { Offset Into new header of NE_CRC }

Type
  new_exe  = Record                 { New .Exe header }
    ne_magic            : Word;     { Magic number NE_Magic }
    ne_ver              : Byte;     { Version number }
    ne_rev              : Byte;     { Revision number }
    ne_enttab           : Word;     { Offset of Entry Table }
    ne_cbenttab         : Word;     { Number of bytes in Entry Table }
    ne_crc              : LongInt;  { Checksum of whole file }
    ne_flags            : Word;     { Flag wOrd }
    ne_autodata         : Word;     { Automatic data segment number }
    ne_heap             : Word;     { Initial heap allocation }
    ne_stack            : Word;     { Initial stack allocation }
    ne_csip             : LongInt;  { Initial CS:IP setting }
    ne_sssp             : LongInt;  { Initial SS:SP setting }
    ne_cseg             : Word;     { Count of file segments }
    ne_cmod             : Word;     { Entries in Module Reference Table }
    ne_cbnrestab        : Word;     { Size of non-resident name table }
    ne_segtab           : Word;     { Offset of Segment Table }
    ne_rsrctab          : Word;     { Offset of Resource Table }
    ne_restab           : Word;     { Offset of resident name table }
    ne_modtab           : Word;     { Offset of Module Reference Table }
    ne_imptab           : Word;     { Offset of Imported Names Table }
    ne_nrestab          : LongInt;  { Offset of Non-resident Names Table }
    ne_cmovent          : Word;     { Count of movable entries }
    ne_align            : Word;     { Segment alignment shift count }
    ne_cres             : Word;     { Count of resource entries }
    ne_exetyp           : Byte;     { Target operating system }
    ne_flagsothers      : Byte;     { Other .Exe flags }
    ne_res              : Array[1..NERESBytes] of Byte; { Pad structure to 64
                                                          bytes}
  end;

{ Target operating systems }
Const
  NE_Unknown    = $0;            { Unknown (any "new-format" OS) }
  NE_Os2        = $1;            { OS/2 (default)  }
  NE_Windows    = $2;            { Windows }
  NE_Dos4       = $3;            { DOS 4.x }
  NE_Dev386     = $4;            { Windows 386 }


{
 *  Format of NE_Flags(x):
 *
 *  p                                   Not-a-process
 *   x                                  Unused
 *    e                                 Errors in image
 *     x                                Unused
 *      b                               Bound Family/API
 *       ttt                            Application type
 *          f                           Floating-poInt instructions
 *           3                          386 instructions
 *            2                         286 instructions
 *             0                        8086 instructions
 *              P                       Protected mode only
 *               p                      Per-process library initialization
 *                i                     Instance data
 *                 s                    Solo data
 }
  NENotP         = $8000;         { Not a process }
  NEIErr         = $2000;         { Errors in image }
  NEBound        = $0800;         { Bound Family/API }
  NEAppTyp       = $0700;         { Application type mask }
  NENotWinCompat = $0100;         { Not compatible with P.M. Windowing }
  NEWincompat    = $0200;         { Compatible with P.M. Windowing }
  NEWinApi       = $0300;         { Uses P.M. Windowing API }
  NEFltP         = $0080;         { Floating-poInt instructions }
  NEi386         = $0040;         { 386 instructions }
  NEi286         = $0020;         { 286 instructions }
  NEi086         = $0010;         { 8086 instructions }
  NEProt         = $0008;         { Runs in Protected mode only }
  NEPpli         = $0004;         { Per-Process Library Initialization }
  NEInst         = $0002;         { Instance data }
  NESolo         = $0001;         { Solo data }

{
 *  Format of NE_FlagsOTHERS(x):
 *
 *      7 6 5 4 3 2 1 0  - bit no
 *      |         | | |
 *      |         | | +---------------- Support for long file names
 *      |         | +------------------ Windows 2.x app runs in Prot mode
 *      |         +-------------------- Windows 2.x app gets prop. font
 *      +------------------------------ WLO appl on OS/2 (markwlo.exe)
 *
 }

  NELongNames     = $01;
  NewInisProt     = $02;
  NewInGetPropFon = $04;
  NewLoAppl       = $80;


Type
  new_seg = Record             { New .Exe segment table entry }
    ns_sector   : Word;        { File sector of start of segment }
    ns_cbseg    : Word;        { Number of bytes in file }
    ns_flags    : Word;        { Attribute flags }
    ns_minalloc : Word;        { Minimum allocation in bytes }
  end;

{
 *  Format of NS_Flags(x)
 *
 *  Flag wOrd has the following format:
 *
 *      15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
 *          |  |  |  |  | | | | | | | | | | |
 *          |  |  |  |  | | | | | | | | +-+-+- Segment type Data/Code
 *          |  |  |  |  | | | | | | | +------- Iterated segment
 *          |  |  |  |  | | | | | | +--------- Movable segment
 *          |  |  |  |  | | | | | +----------- Segment can be shared
 *          |  |  |  |  | | | | +------------- Preload segment
 *          |  |  |  |  | | | +--------------- Execute/read-only for code/data
            |  |  |  |  | | |                  segment
 *          |  |  |  |  | | +----------------- Segment has relocations
 *          |  |  |  |  | +------------------- Code conforming/Data is expand
            |  |  |  |  |                      down
 *          |  |  |  +--+--------------------- I/O privilege level
 *          |  |  +--------------------------- Discardable segment
 *          |  +------------------------------ 32-bit code segment
 *          +--------------------------------- Huge segment/GDT allocation
                                               requested
 *
 }

Const
  NSType         = $0007;         { Segment type mask }

{$IFDEF Exe386}
  NSCode         = $0000;         { Code segment }
  NSData         = $0001;         { Data segment }
  NSIter         = $0008;         { Iterated segment flag }
  NSMove         = $0010;         { Movable segment flag }
  NSShared       = $0020;         { Shared segment flag }
  NSPreLoad      = $0040;         { Preload segment flag }
  NSExRD         = $0080;         { Execute-only (code segment), or
                                        *  read-only (data segment)
                                        }
  NSReloc        = $0100;         { Segment has relocations }
  NSConform      = $0200;         { Conforming segment }
  NSExpDown      = $0200;         { Data segment is expand down }
  NSDPL          = $0C00;         { I/O privilege level (286 DPL bits) }
  ShiftDpl       = 10;            { Left shift count for SegDPL field }
  NSDiscard      = $1000;         { Segment is discardable }
  NS32Bit        = $2000;         { 32-bit code segment }
  NSHuge         = $4000;         { Huge memory segment, length of
                                         * segment and minimum allocation
                                         * Size are in segment sector units
                                         }
  NSGDT          = $8000;         { GDT allocation requested }

  NSPure         = NSShared;      { For compatibility }

  NSAlign        = 9;           { Segment data aligned on 512 byte boundaries}

  NSLOADED       = $0004;            { ns_sector field contains memory Addr }
{$endif Exe386}

Type
  new_segdata = Record               { Segment data }
    Case Boolean of
      True : ( ns_iter : Record
                 ns_niter    : Word; { number of iterations }
                 ns_nbytes   : Word; { number of bytes }
                 ns_iterdata : char; { iterated data bytes }
               end );
      False: ( ns_noniter : Record
                ns_data      : char; { data bytes }
               end );
  end;

  new_rlcinfo = Record               { Relocation info }
    nr_nreloc : Word;                { number of relocation items that }
  end;                               { follow }

  new_rlc = Record                   { Relocation item }
    nr_stype   : char;               { Source type }
    nr_flags   : char;               { Flag byte }
    nr_soff    : Word;               { Source offset }
    nr_union   : Record
      Case Byte of
        0 : ( nr_Intref : Record     { Internal reference }
                nr_segno  : char;    { Target segment number }
                nr_res    : char;    { Reserved }
                nr_entry  : Word;    { Target Entry Table offset }

        1 : ( nr_import : Record     { Import }
                nr_mod    : Word;    { Index Into Module Reference Table }
                nr_proc   : Word;    { Procedure Ordinal or name offset }
              end );
        2 : ( nr_osfix : Record      { Operating system fixup }
                nr_ostype : Word;    { OSFixUP type }
                nr_osres  : Word;    { reserved }
              end );
      end;
   end;

Const
{
 *  Format of NR_SType(x) and R32_SType(x):
 *
 *       7 6 5 4 3 2 1 0  - bit no
 *               | | | |
 *               +-+-+-+--- source type
 *
 }

  NRSTyp         = $0f;           { Source type mask }
  NRSByt         = $00;           { lo byte (8-bits)}
  NRSSeg         = $02;           { 16-bit segment (16-bits) }
  NRSPtr         = $03;           { 16:16 poInter (32-bits) }
  NRSOff         = $05;           { 16-bit offset (16-bits) }
  NRPtr48        = $06;           { 16:32 poInter (48-bits) }
  NROff32        = $07;           { 32-bit offset (32-bits) }
  NRSOff32       = $08;           { 32-bit self-relative offset (32-bits) }


{
 *  Format of NR_Flags(x) and R32_Flags(x):
 *
 *       7 6 5 4 3 2 1 0  - bit no
 *                 | | |
 *                 | +-+--- Reference type
 *                 +------- Additive fixup
 }

  NRAdd          = $04;           { Additive fixup }
  NRRTyp         = $03;           { Reference type mask }
  NRRInt         = $00;           { Internal reference }
  NRROrd         = $01;           { Import by Ordinal }
  NRRNam         = $02;           { Import by name }
  NRROSF         = $03;           { Operating system fixup }


{$IFDEF Exe386}

Type
  { Resource type or name string }
  rsrc_string = Record
    rs_len      : Char;            { number of bytes in string }
    rs_string   : Array[ 1..1 ] of Char;    { text of string }
  end;

  { Resource type information block }
  rsrc_typeinfo = Record
    rt_id   : Word;
    rt_nres : Word;
    rt_proc : LongInt;
  end;

  { Resource name information block }
  rsrc_nameinfo = Record
    { The following two fields must be shifted left by the value of  }
    { the rs_align field to compute their actual value.  This allows }
    { resources to be larger than 64k, but they do not need to be    }
    { aligned on 512 byte boundaries, the way segments are           }
    rn_offset : Word; { file offset to resource data }
    rn_length : Word; { length of resource data }
    rn_flags  : Word; { resource flags }
    rn_id     : Word; { resource name id }
    rn_handle : Word; { If loaded, then global handle }
    rn_usage  : Word; { Initially zero.  Number of times }
                      { the handle for this resource has }
                      { been given out }
  end;

Const
  RSOrdID    = $8000;     { if high bit of ID set then Integer id }
                          { otherwise ID is offset of string from
                          the beginning of the resource table }

                          { Ideally these are the same as the }
                          { corresponding segment flags }
  RNMove     = $0010;     { Moveable resource }
  RNPURE     = $0020;     { Pure (read-only) resource }
  RNPreLoad  = $0040;     { Preloaded resource }
  RNDiscard  = $F000;     { Discard priority level for resource }

Type
  { Resource table }
  new_rsrc = Record
    rs_align    : Word;   { alignment shift count for resources }
    rs_TypeInfo : rsrc_typeinfo;
  end;

{$ENDIF Exe386}

Implementation

end.