home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / lxlt121s.zip / lxLite_src / exe286.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-09  |  14KB  |  271 lines

  1. (****************************************************************************)
  2. (*  Title:       exe286.pas                                                 *)
  3. (*  Description: Data structure definitions for the OS/2 old executable     *)
  4. (*               file format (segmented model)                              *)
  5. (****************************************************************************)
  6. (*                  (C) Copyright IBM Corp 1984-1992                        *)
  7. (*               (C) Copyright Microsoft Corp 1984-1987                     *)
  8. (*            C->Pascal conversion (c) FRIENDS software, 1996               *)
  9. (****************************************************************************)
  10. {$AlignCode-,AlignData-,AlignRec-,G3+,Speed-,Frame-}
  11. Unit exe286;
  12.  
  13. Interface uses use32;
  14.  
  15. { DOS EXE file header structure }
  16. type
  17.  pEXEheader = ^tEXEheader;
  18.  tEXEheader = record
  19.   exeMagic    : Word16;             { Magic number }
  20.   exeCbLP     : Word16;             { Bytes on last page of file }
  21.   exeCp       : Word16;             { Pages in file }
  22.   exeCrlc     : Word16;             { Relocations }
  23.   exeCparhdr  : Word16;             { Size of header in paragraphs }
  24.   exeMinAlloc : Word16;             { Minimum extra paragraphs needed }
  25.   exeMaxAlloc : Word16;             { Maximum extra paragraphs needed }
  26.   exeSS       : Word16;             { Initial (relative) SS value }
  27.   exeSP       : Word16;             { Initial SP value }
  28.   exeCRC      : Word16;             { Checksum }
  29.   exeIP       : Word16;             { Initial IP value }
  30.   exeCS       : Word16;             { Initial (relative) CS value }
  31.   exeLfarlc   : Word16;             { File address of relocation table }
  32.   exeOvNo     : Word16;             { Overlay number }
  33.   exeRes      : array[1..4] of Word16;{ Reserved words }
  34.   exeOEMid    : Word16;             { OEM identifier (for exeOEMinfo) }
  35.   exeOEMinfo  : Word16;             { OEM information; exeOEMid specific }
  36.   exeRes2     : array[1..10] of Word16;{ Reserved words }
  37.   exeLFAnew   : Longint;            { File address of new exe header }
  38.  end;
  39.  
  40. (*-----------------------------------------------------------------*)
  41. (*  OS/2 & WINDOWS .EXE FILE HEADER DEFINITION - 286 version       *)
  42. (*-----------------------------------------------------------------*)
  43.  
  44. const
  45.  neMagic          = $454E;          { `New` magic number }
  46.  neDebugMagic     = $424E;          { 'NB', codeview debug-info signature }
  47.  neResBytes       = 8;              { Eight bytes reserved (now) }
  48.  neCRC            = 8;              { Offset into new header of neCRC }
  49.  
  50. type
  51.  pNEheader = ^tNEheader;
  52.  tNEheader = record                 { `New` .EXE header }
  53.   neMagic       : Word16;           { Magic number neMAGIC }
  54.   neVer         : Byte;             { Version number }
  55.   neRev         : Byte;             { Revision number }
  56.   neEntTab      : Word16;           { Offset of Entry Table }
  57.   neCbEntTab    : Word16;           { Number of bytes in Entry Table }
  58.   neCRC         : Longint;          { Checksum of whole file }
  59.   neFlags       : Word16;           { Flag word }
  60.   neAutoData    : Word16;           { Automatic data segment number }
  61.   neHeap        : Word16;           { Initial heap allocation }
  62.   neStack       : Word16;           { Initial stack allocation }
  63.   neCSIP        : Longint;          { Initial CS:IP setting }
  64.   neSSSP        : Longint;          { Initial SS:SP setting }
  65.   neCSeg        : Word16;           { Count of file segments }
  66.   neCMod        : Word16;           { Entries in Module Reference Table }
  67.   neCbNResTab   : Word16;           { Size of non-resident name table }
  68.   neSegTab      : Word16;           { Offset of Segment Table }
  69.   neRsrcTab     : Word16;           { Offset of Resource Table }
  70.   neResTab      : Word16;           { Offset of resident name table }
  71.   neModTab      : Word16;           { Offset of Module Reference Table }
  72.   neImpTab      : Word16;           { Offset of Imported Names Table }
  73.   neNResTab     : Longint;          { Offset of Non-resident Names Table }
  74.   neCMovEnt     : Word16;           { Count of movable entries }
  75.   neAlign       : Word16;           { Segment alignment shift count }
  76.   neCRes        : Word16;           { Count of resource entries }
  77.   neExeTyp      : Byte;             { Target operating system }
  78.   neFlagsOthers : Byte;             { Other .EXE flags }
  79.   neReserved    : array[1..neResBytes] of byte;{ Pad structure to 64 bytes }
  80.  end;
  81.  
  82. {* Target operating systems *}
  83. const
  84.  neUnknown = $0;                    { Unknown (any "new-format" OS) }
  85.  neOS2     = $1;                    { OS/2 (default)  }
  86.  neWindows = $2;                    { Windows }
  87.  neDos4    = $3;                    { DOS 4.x }
  88.  neDev386  = $4;                    { Windows 386 }
  89.  
  90. {*  Format of NE_FLAGS(x):                                                  *}
  91. {*  p                                   Not-a-process                       *}
  92. {*   x                                  Unused                              *}
  93. {*    e                                 Errors in image                     *}
  94. {*     x                                Unused                              *}
  95. {*      b                               Bound Family/API                    *}
  96. {*       ttt                            Application type                    *}
  97. {*          f                           Floating-point instructions         *}
  98. {*           3                          386 instructions                    *}
  99. {*            2                         286 instructions                    *}
  100. {*             0                        8086 instructions                   *}
  101. {*              P                       Protected mode only                 *}
  102. {*               p                      Per-process library initialization  *}
  103. {*                i                     Instance data                       *}
  104. {*                 s                    Solo data                           *}
  105. const
  106.  neNotP         = $8000;            { Not a process }
  107.  neIerr         = $2000;            { Errors in image }
  108.  neBound        = $0800;            { Bound Family/API }
  109.  neAppTyp       = $0700;            { Application type mask }
  110.  neNotWinCompat = $0100;            { Not compatible with P.M. Windowing }
  111.  neWinCompat    = $0200;            { Compatible with P.M. Windowing }
  112.  neWinAPI       = $0300;            { Uses P.M. Windowing API }
  113.  neFltP         = $0080;            { Floating-point instructions }
  114.  neI386         = $0040;            { 386 instructions }
  115.  neI286         = $0020;            { 286 instructions }
  116.  neI086         = $0010;            { 8086 instructions }
  117.  neProt         = $0008;            { Runs in protected mode only }
  118.  nePPLI         = $0004;            { Per-Process Library Initialization }
  119.  neInst         = $0002;            { Instance data }
  120.  neSolo         = $0001;            { Solo data }
  121.  
  122. {*  Format of NE_FLAGSOTHERS(x):                                            *}
  123. {*                                                                          *}
  124. {*      7 6 5 4 3 2 1 0  - bit no                                           *}
  125. {*      |         | | |                                                     *}
  126. {*      |         | | +---------------- Support for long file names         *}
  127. {*      |         | +------------------ Windows 2.x app runs in prot mode   *}
  128. {*      |         +-------------------- Windows 2.x app gets prop. font     *}
  129. {*      +------------------------------ WLO appl on OS/2 (markwlo.exe)      *}
  130. const
  131.  neLongFileNames = $01;
  132.  neWinIsProt     = $02;
  133.  neWinGetPropFon = $04;
  134.  neWLoAppl       = $80;
  135.  
  136. type
  137.  pNEseg = ^tNEseg;
  138.  tNEseg = record                    { New .EXE segment table entry }
  139.   Sector   : Word16;                { File sector of start of segment }
  140.   CbSeg    : Word16;                { Number of bytes in file }
  141.   Flags    : Word16;                { Attribute flags }
  142.   MinAlloc : Word16;                { Minimum allocation in bytes }
  143.  end;
  144.  
  145. {*  Format of NS_FLAGS(x)                                                   *}
  146. {*                                                                          *}
  147. {*  Flag word has the following format:                                     *}
  148. {*                                                                          *}
  149. {*      15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no                     *}
  150. {*          |  |  |  |  | | | | | | | | | | |                               *}
  151. {*          |  |  |  |  | | | | | | | | +-+-+--- Segment type DATA/CODE     *}
  152. {*          |  |  |  |  | | | | | | | +--------- Iterated segment           *}
  153. {*          |  |  |  |  | | | | | | +----------- Movable segment            *}
  154. {*          |  |  |  |  | | | | | +------------- Segment can be shared      *}
  155. {*          |  |  |  |  | | | | +--------------- Preload segment            *}
  156. {*          |  |  |  |  | | | +----------------- Execute/read-only for code/data segment*}
  157. {*          |  |  |  |  | | +------------------- Segment has relocations    *}
  158. {*          |  |  |  |  | +--------------------- Code conforming/Data is expand down*}
  159. {*          |  |  |  +--+----------------------- I/O privilege level        *}
  160. {*          |  |  +----------------------------- Discardable segment        *}
  161. {*          |  +-------------------------------- 32-bit code segment        *}
  162. {*          +----------------------------------- Huge segment/GDT allocation requested *}
  163. const
  164.  nesType     = $0007;               { Segment type mask }
  165.  
  166.  nesCode     = $0000;               { Code segment }
  167.  nesData     = $0001;               { Data segment }
  168.  nesIter     = $0008;               { Iterated segment flag }
  169.  nesMove     = $0010;               { Movable segment flag }
  170.  nesShared   = $0020;               { Shared segment flag }
  171.  nesPreload  = $0040;               { Preload segment flag }
  172.  nesExRdOnly = $0080;               { Execute-only (code segment), or read-only (data segment) }
  173.  nesReloc    = $0100;               { Segment has relocations }
  174.  nesConform  = $0200;               { Conforming segment }
  175.  nesExpDown  = $0200;               { Data segment is expand down }
  176.  nesDPL      = $0C00;               { I/O privilege level (286 DPL bits) }
  177.  nesDiscard  = $1000;               { Segment is discardable }
  178.  nes32bit    = $2000;               { 32-bit code segment }
  179.  nesHuge     = $4000;               { Huge memory segment, length of   }
  180.                                     { segment and minimum allocation   }
  181.                                     { size are in segment sector units }
  182.  nesGDT      = $8000;               { GDT allocation requested }
  183.  nesPure     = nesShared;           { For compatibility }
  184.  nesAlign    = 9;                   { Segment data aligned on 512 byte boundaries }
  185.  nesLoaded   = $0004;               { nesSector field contains memory addr }
  186.  
  187. type
  188.  tNEsegData = record
  189.   case boolean of
  190.    TRUE  : (Iter : record
  191.                     nIter  : Word16;      { number of iterations }
  192.                     nBytes : Word16;      { number of bytes }
  193.                     Data   : array[0..0] of Byte;{ iterated data bytes }
  194.                    end);
  195.    FALSE : (Data : array[0..0] of Byte);
  196.   end;
  197.  
  198.  tNErelocInfo = record              { Relocation info }
  199.   nReloc : Word16;                  { number of relocation items that follow }
  200.  end;
  201.  
  202.  pNEreloc = ^tNEreloc;
  203.  tNEreloc = record
  204.   sType : Byte;                     { Source type }
  205.   flags : Byte;                     { Flag byte }
  206.   soff  : Word16;                   { Source offset }
  207.   rel   : record case byte of
  208.   { Internal reference }
  209.    0 : (segNo   : Byte;            { Target segment number }
  210.         Resvd   : Byte;            { Reserved }
  211.         Entry   : Word16);         { Target Entry Table offset }
  212.   { Import }
  213.    1 : (modIndx : Word16;          { Index into Module Reference Table }
  214.         Proc    : Word16);         { Procedure ordinal or name offset }
  215.   { Operating system fixup }
  216.    2 : (osType  : Word16;          { OSFIXUP type }
  217.         osRes   : Word16);         { reserved }
  218.   end;
  219.  end;
  220.  
  221. {*  Format of NR_STYPE(x) and R32_STYPE(x):   *}
  222. {*                                            *}
  223. {*       7 6 5 4 3 2 1 0  - bit no            *}
  224. {*               | | | |                      *}
  225. {*               +-+-+-+--- source type       *}
  226. const
  227.  nerSType  = $0F;                   { Source type mask }
  228.  nerSByte  = $00;                   { lo byte (8-bits)}
  229.  nerSSeg   = $02;                   { 16-bit segment (16-bits) }
  230.  nerSPtr   = $03;                   { 16:16 pointer (32-bits) }
  231.  nerSoff   = $05;                   { 16-bit offset (16-bits) }
  232.  nerPtr48  = $06;                   { 16:32 pointer (48-bits) }
  233.  nerOff32  = $07;                   { 32-bit offset (32-bits) }
  234.  nerSOff32 = $08;                   { 32-bit self-relative offset (32-bits) }
  235.  
  236. {*  Format of NR_FLAGS(x) and R32_FLAGS(x):   *}
  237. {*                                            *}
  238. {*       7 6 5 4 3 2 1 0  - bit no            *}
  239. {*                 | | |                      *}
  240. {*                 | +-+--- Reference type    *}
  241. {*                 +------- Additive fixup    *}
  242. const
  243.  nerRTyp = $03;                     { Reference type mask }
  244.  nerRInt = $00;                     { Internal reference }
  245.  nerROrd = $01;                     { Import by ordinal }
  246.  nerRNam = $02;                     { Import by name }
  247.  nerROsf = $03;                     { Operating system fixup }
  248.  nerAdd  = $04;                     { Additive fixup }
  249.  
  250. type
  251.  pNEentryBundle = ^tNEentryBundle;
  252.  tNEentryBundle = record
  253.   Flags : Byte;
  254.   Ref   : record case byte of
  255.    0 : (fixOfs : Word16);
  256.    1 : (movInt3F : Word16; movSegNo : Byte; movOfs : Word16);
  257.   end;
  258.  end;
  259.  
  260. {Type definition for resource description blocks}
  261. {(REAL ONE, NOT FROM WINDOWS EXECUTABLES!)}
  262. type
  263.  tNEresource = record
  264.   resType : Word16;
  265.   resID   : Word16;
  266.  end;
  267.  
  268. Implementation
  269.  
  270. end.
  271.