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

  1. (****************************************************************************)
  2. (*  Title:       exe386.pas                                                 *)
  3. (*  Description: Data structure definitions for the OS/2                    *)
  4. (*               executable file format (flat model)                        *)
  5. (****************************************************************************)
  6. (*               Copyright (c) IBM Corporation 1987, 1992                   *)
  7. (*                Copyright (c) Microsoft Corp 1988, 1991                   *)
  8. (*            C->Pascal conversion (c) FRIENDS software, 1996               *)
  9. (****************************************************************************)
  10. {&AlignCode-,AlignData-,AlignRec-,G3+,Speed-,Frame-}
  11. Unit exe386;
  12.  
  13. Interface uses use32, miscUtil;
  14.  
  15. const
  16.  lxMagic         = $584C;             { New magic number  "LX" }
  17.  exeMagic1       = $5A4D;             { EXE file magic number "MZ" }
  18.  exeMagic2       = $4D5A;             { EXE file magic number "ZM" }
  19.  lxResBytes      = 20;                { bytes reserved }
  20.  lxLEBO          = $00;               { Little Endian Byte Order }
  21.  lxBEBO          = $01;               { Big Endian Byte Order }
  22.  lxLEWO          = $00;               { Little Endian Word Order }
  23.  lxBEWO          = $01;               { Big Endian Word Order }
  24.  lxLevel         = 0;                 { 32-bit EXE format level }
  25.  lxCPU286        = $01;               { Intel 80286 or upwardly compatibile }
  26.  lxCPU386        = $02;               { Intel 80386 or upwardly compatibile }
  27.  lxCPU486        = $03;               { Intel 80486 or upwardly compatibile }
  28.  lxCPUP5         = $04;               { Intel P5 or upwardly compatibile }
  29.  lxCPUP6         = $05;               { Intel P6 or upwardly compatibile }
  30.  lxCPUP7         = $06;               { Intel P7 or upwardly compatibile }
  31.  lx386PageSize   = 4096;              { Size of one page in LX file }
  32.  
  33. type
  34.  pLXheader = ^tLXheader;
  35.  tLXheader = record                   { New 32-bit .EXE header }
  36.   lxMagicID    : Word16;              { magic number LXmagic }
  37.   lxBOrder     : Byte;                { The byte ordering for the .EXE }
  38.   lxWOrder     : Byte;                { The word ordering for the .EXE }
  39.   lxLevel      : Longint;             { The EXE format level for now = 0 }
  40.   lxCpu        : Word16;              { The CPU type }
  41.   lxOS         : Word16;              { The OS type }
  42.   lxVer        : Longint;             { Module version }
  43.   lxMflags     : Longint;             { Module flags }
  44.   lxMpages     : Longint;             { Module # pages }
  45.   lxStartObj   : Longint;             { Object # for instruction pointer }
  46.   lxEIP        : Longint;             { Extended instruction pointer }
  47.   lxStackObj   : Longint;             { Object # for stack pointer }
  48.   lxESP        : Longint;             { Extended stack pointer }
  49.   lxPageSize   : Longint;             { .EXE page size }
  50.   lxPageShift  : Longint;             { Page alignment shift in .EXE }
  51.   lxFixupSize  : Longint;             { Fixup section size }
  52.   lxFixupSum   : Longint;             { Fixup section checksum }
  53.   lxLdrSize    : Longint;             { Loader section size }
  54.   lxLdrSum     : Longint;             { Loader section checksum }
  55.   lxObjTabOfs  : Longint;             { Object table offset }
  56.   lxObjCnt     : Longint;             { Number of objects in module }
  57.   lxObjMapOfs  : Longint;             { Object page map offset }
  58.   lxIterMapOfs : Longint;             { Object iterated data map offset }
  59.   lxRsrcTabOfs : Longint;             { Offset of Resource Table }
  60.   lxRsrcCnt    : Longint;             { Number of resource entries }
  61.   lxResTabOfs  : Longint;             { Offset of resident name table }
  62.   lxEntTabOfs  : Longint;             { Offset of Entry Table }
  63.   lxDirTabOfs  : Longint;             { Offset of Module Directive Table }
  64.   lxDirCnt     : Longint;             { Number of module directives }
  65.   lxFPageTabOfs: Longint;             { Offset of Fixup Page Table }
  66.   lxFRecTabOfs : Longint;             { Offset of Fixup Record Table }
  67.   lxImpModOfs  : Longint;             { Offset of Import Module Name Table }
  68.   lxImpModCnt  : Longint;             { Number of entries in Import Module Name Table }
  69.   lxImpProcOfs : Longint;             { Offset of Import Procedure Name Table }
  70.   lxPageSumOfs : Longint;             { Offset of Per-Page Checksum Table }
  71.   lxDataPageOfs: Longint;             { Offset of Enumerated Data Pages }
  72.   lxPreload    : Longint;             { Number of preload pages }
  73.   lxNResTabOfs : Longint;             { Offset of Non-resident Names Table }
  74.   lxCbNResTabOfs:Longint;             { Size of Non-resident Name Table }
  75.   lxNResSum    : Longint;             { Non-resident Name Table Checksum }
  76.   lxAutoData   : Longint;             { Object # for automatic data object }
  77.   lxDebugInfoOfs:Longint;             { Offset of the debugging information }
  78.                                       { RELATIVE TO START OF EXE FILE}
  79.   lxDebugLen   : Longint;             { The length of the debugging info. in bytes }
  80.   lxInstPreload: Longint;             { Number of instance pages in preload section of .EXE file }
  81.   lxInstDemand : Longint;             { Number of instance pages in demand load section of .EXE file }
  82.   lxHeapSize   : Longint;             { Size of heap - for 16-bit apps }
  83.   lxStackSize  : Longint;
  84.   lxReserved   : array[1..lxResBytes] of Byte;
  85.  end;                                 { Pad structure to 196 bytes }
  86.  
  87. { Format of lxMFlags:                                                        }
  88. {                                                                            }
  89. { Low word has the following format:                                         }
  90. {                                                                            }
  91. { 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no                            }
  92. {  |     |          | |     | |   |                                          }
  93. {  |     |          | |     | |   +------- Per-Process Library Initialization}
  94. {  |     |          | |     | +----------- No Internal Fixups for Module in .EXE}
  95. {  |     |          | |     +------------- No External Fixups for Module in .EXE}
  96. {  |     |          | +------------------- Incompatible with PM Windowing    }
  97. {  |     |          +--------------------- Compatible with PM Windowing      }
  98. {  |     |                                 Uses PM Windowing API             }
  99. {  |     +-------------------------------- Module not Loadable               }
  100. {  +-------------------------------------- Library Module                    }
  101. const
  102.  lxLibTerm      = $40000000;          { Per-Process Library Termination }
  103.  lxNotP         = $00008000;          { Library Module - used as neNotP }
  104.  lxNoLoad       = $00002000;          { Module not Loadable }
  105.  lxAppMask      = $00000700;          { Application Type Mask }
  106.  lxNoPMwin      = $00000100;          { Incompatible with PM Windowing }
  107.  lxPMwin        = $00000200;          { Compatible with PM Windowing }
  108.  lxPMapi        = $00000300;          { Uses PM Windowing API }
  109.  lxNoIntFix     = $00000010;          { NO Internal Fixups in .EXE }
  110.  lxNoExtFix     = $00000020;          { NO External Fixups in .EXE }
  111.  lxLibInit      = $00000004;          { Per-Process Library Initialization }
  112.  
  113. { Format of lxMFlags                                                       }
  114. {                                                                          }
  115. { High word has the following format:                                      }
  116. { 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no                          }
  117. {                                   | |                                    }
  118. {                                   | +--- Protected memory library module }
  119. {                                   +----- Device driver                   }
  120. const
  121.  lxEXE          = $00000000;         { .EXE module                     }
  122.  lxDLL          = $00008000;         { Dynamic Link library            }
  123.  lxPMDLL        = $00018000;         { Protected memory library module }
  124.  lxPDD          = $00020000;         { Physical device driver          }
  125.  lxVDD          = $00028000;         { Virtual device driver           }
  126.  lxModType      = $00038000;         { Module type mask                }
  127.  
  128. { RELOCATION DEFINITIONS - RUN-TIME FIXUPS }
  129. type
  130.  pOffset = ^tOffset;
  131.  tOffset = record case byte of
  132.   0 : (offset16 : Word16);
  133.   1 : (offset32 : Longint);
  134.  end;                                 { 16-bit or 32-bit offset }
  135.  
  136. { ET + lxrrlc - Relocation item }
  137.  pLXreloc = ^tLXreloc;
  138.  tLXreloc = record                    { Relocation item }
  139.   sType        : Byte;                { Source type - field shared with new_rlc }
  140.   Flags        : Byte;                { Flag byte - field shared with new_rlc }
  141.   sOffs        : Word16;              { Source offset }
  142.   ObjMod       : Word16;              { Target object number or Module ordinal }
  143.   Target       : record case Byte of
  144.    0 : (intRef : Longint);
  145.    1 : (extRef : record case byte of
  146.          0 : (Proc : Longint);        { Procedure name offset }
  147.          1 : (Ord  : Longint);        { Procedure ordinal }
  148.         end);
  149.   end;
  150.   addFixup     : Longint;             { Additive fixup value }
  151.   targetCount  : Longint;
  152.   targets      : pWord16Array;
  153.  end;
  154.  
  155. { In 32-bit .EXE file run-time relocations are written as varying size }
  156. { records, so we need many size definitions.                           }
  157. const
  158.  rIntSize16    = 8;
  159.  rIntSize32    = 10;
  160.  rOrdSize      = 8;
  161.  rNamSize16    = 8;
  162.  rNamSize32    = 10;
  163.  rAddSize16    = 10;
  164.  rAddSize32    = 12;
  165.  
  166. { Format of NR_STYPE(x)                                         }
  167. { 7 6 5 4 3 2 1 0  - bit no                                     }
  168. {     | | | | | |                                               }
  169. {     | | +-+-+-+--- Source type                                }
  170. {     | +----------- Fixup to 16:16 alias                       }
  171. {     +------------- List of source offset follows fixup record }
  172. const
  173.  nrSType       = $0F;               { Source type mask }
  174.  nrSByte       = $00;               { lo byte (8-bits)}
  175.  nrSSeg        = $02;               { 16-bit segment (16-bits) }
  176.  nrSPtr        = $03;               { 16:16 pointer (32-bits) }
  177.  nrSOff        = $05;               { 16-bit offset (16-bits) }
  178.  nrPtr48       = $06;               { 16:32 pointer (48-bits) }
  179.  nrOff32       = $07;               { 32-bit offset (32-bits) }
  180.  nrSoff32      = $08;               { 32-bit self-relative offset (32-bits) }
  181.  
  182.  nrSrcMask     = $0F;               { Source type mask }
  183.  nrAlias       = $10;               { Fixup to alias }
  184.  nrChain       = $20;               { List of source offset follows }
  185.                                     { fixup record, source offset field }
  186.                                     { in fixup record contains number }
  187.                                     { of elements in list }
  188.  
  189. { Format of NR_FLAGS(x) and lxrFLAGS(x):                                  }
  190. { 7 6 5 4 3 2 1 0  - bit no                                               }
  191. { | | | | | | | |                                                         }
  192. { | | | | | | +-+--- Reference type                                       }
  193. { | | | | | +------- Additive fixup                                       }
  194. { | | | | +--------- New-type chained fixup  (OS/2 v4.0+?)                }
  195. { | | | +----------- 32-bit Target Offset Flag (1 - 32-bit; 0 - 16-bit)   }
  196. { | | +------------- 32-bit Additive Flag (1 - 32-bit; 0 - 16-bit)        }
  197. { | +--------------- 16-bit Object/Module ordinal (1 - 16-bit; 0 - 8-bit) }
  198. { +----------------- 8-bit import ordinal (1 - 8-bit;                     }
  199. {                                          0 - NR32BITOFF toggles         }
  200. {                                              between 16 and 32 bit      }
  201. {                                              ordinal)                   }
  202. const
  203.  nrRtype       = $03;               { Reference type mask }
  204.  nrRint        = $00;               { Internal reference }
  205.  nrRord        = $01;               { Import by ordinal }
  206.  nrRnam        = $02;               { Import by name }
  207.  nrRent        = $03;               { Internal entry table fixup }
  208.  nrAdd         = $04;               { Additive fixup }
  209.  
  210.  nrNewChain    = $08;               { New-type chains introduced in v4.0 }
  211.  nr32bitOff    = $10;               { 32-bit Target Offset }
  212.  nr32bitAdd    = $20;               { 32-bit Additive fixup }
  213.  nr16objMod    = $40;               { 16-bit Object/Module ordinal }
  214.  nr8bitOrd     = $80;               { 8-bit import ordinal }
  215.  
  216. { OBJECT TABLE }
  217.  
  218. { Object Table Entry }
  219. type
  220.  pObjTblRec = ^tObjTblRec;
  221.  tObjTblRec = record                { Flat .EXE object table entry }
  222.   oSize     : Longint;              { Object virtual size }
  223.   oBase     : Longint;              { Object base virtual address }
  224.   oFlags    : Longint;              { Attribute flags }
  225.   oPageMap  : Longint;              { Object page map index }
  226.   oMapSize  : Longint;              { Number of entries in object page map }
  227.   oReserved : Longint;              { Reserved }
  228.  end;
  229.  
  230. { Format of oFlags                                                           }
  231. {                                                                            }
  232. { High word of dword flag field is not used for now.                         }
  233. { Low word has the following format:                                         }
  234. { 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no                            }
  235. {  |  |  |  |     | | | | | | | | | | |                                      }
  236. {  |  |  |  |     | | | | | | | | | | +--- Readable Object                   }
  237. {  |  |  |  |     | | | | | | | | | +----- Writeable Object                  }
  238. {  |  |  |  |     | | | | | | | | +------- Executable Object                 }
  239. {  |  |  |  |     | | | | | | | +--------- Resource Object                   }
  240. {  |  |  |  |     | | | | | | +----------- Object is Discardable             }
  241. {  |  |  |  |     | | | | | +------------- Object is Shared                  }
  242. {  |  |  |  |     | | | | +--------------- Object has preload pages          }
  243. {  |  |  |  |     | | | +----------------- Object has invalid pages          }
  244. {  |  |  |  |     | | +------------------- Object is permanent and swappable }
  245. {  |  |  |  |     | +--------------------- Object is permanent and resident  }
  246. {  |  |  |  |     +----------------------- Object is permanent and long lockable}
  247. {  |  |  |  +----------------------------- 16:16 alias required (80x86 specific)}
  248. {  |  |  +-------------------------------- Big/Default bit setting (80x86 specific)}
  249. {  |  +----------------------------------- Object is conforming for code (80x86 specific)}
  250. {  +-------------------------------------- Object I/O privilege level (80x86 specific)}
  251.  
  252. const
  253.  objRead       = $00000001;         { Readable object   }
  254.  objWrite      = $00000002;         { Writeable object  }
  255.  objExec       = $00000004;         { Executable object }
  256.  objResource   = $00000008;         { Resource object   }
  257.  objDiscard    = $00000010;         { object is Discardable }
  258.  objShared     = $00000020;         { object is Shared }
  259.  objPreload    = $00000040;         { object has preload pages  }
  260.  objInvalid    = $00000080;         { object has invalid pages  }
  261.  lnkNonPerm    = $00000600;         { object is nonpermanent - should be }
  262.  objNonPerm    = $00000000;         { zero in the .EXE but LINK386 uses 6 }
  263.  objPerm       = $00000100;         { object is permanent and swappable }
  264.  objResident   = $00000200;         { object is permanent and resident }
  265.  objContig     = $00000300;         { object is resident and contiguous }
  266.  objDynamic    = $00000400;         { object is permanent and long locable }
  267.  objTypeMask   = $00000700;         { object type mask }
  268.  objAlias16    = $00001000;         { 16:16 alias required (80x86 specific) }
  269.  objBigDef     = $00002000;         { Big/Default bit setting (80x86 specific) }
  270.  objConform    = $00004000;         { object is conforming for code (80x86 specific)  }
  271.  objIOPL       = $00008000;         { object I/O privilege level (80x86 specific) }
  272.  
  273. { object Page Map entry }
  274.  
  275. type
  276.  pObjMapRec = ^tObjMapRec;
  277.  tObjMapRec = record                 { object Page Table entry }
  278.   PageDataOffset : Longint;          { file offset of page }
  279.   PageSize       : Word16;           { # bytes of page data }
  280.   PageFlags      : Word16;           { Per-Page attributes }
  281.  end;
  282.  
  283. const
  284.  pgValid       = $0000;              { Valid Physical Page in .EXE }
  285.  pgIterData    = $0001;              { Iterated Data Page }
  286.  pgInvalid     = $0002;              { Invalid Page }
  287.  pgZeroed      = $0003;              { Zero Filled Page }
  288.  pgRange       = $0004;              { Range of pages }
  289.  pgIterData2   = $0005;              { Iterated Data Page Type II }
  290.  
  291. { RESOURCE TABLE }
  292.  
  293. { tResource - Resource Table Entry }
  294. type
  295.  pResource = ^tResource;
  296.  tResource = record                   { Resource Table Entry }
  297.   resType : Word16;                   { Resource type }
  298.   resName : Word16;                   { Resource name }
  299.   resSize : Longint;                  { Resource size }
  300.   resObj  : Word16;                   { Object number }
  301.   resOffs : Longint;                  { Offset within object }
  302.  end;
  303.  
  304. { Iteration Record format for 'EXEPACK'ed pages. (DCR1346)  }
  305.  pIterRec = ^tIterRec;
  306.  tIterRec = record
  307.   nIter    : Word16;                  { number of iterations }
  308.   nBytes   : Word16;                  { number of bytes }
  309.   IterData : Byte;                    { iterated data byte(s) }
  310.  end;
  311.  
  312. { ENTRY TABLE DEFINITIONS }
  313.  
  314. { Entry Table bundle }
  315.  pEntryTblRec = ^tEntryTblRec;
  316.  tEntryTblRec = record
  317.   Count   : Byte;                     { Number of entries in this bundle }
  318.   BndType : Byte;                     { Bundle type }
  319.   Obj     : Word16;                   { object number }
  320.  end;                                 { Follows entry types }
  321.  
  322.  pEntry = ^tEntry;
  323.  tEntry = record
  324.   Flags   : Byte;                     { Entry point flags }
  325.   Variant : record case byte of       { Entry variant }
  326.    0 : (Offset : tOffset);            { 16-bit/32-bit offset entry }
  327.    1 : (CallGate : record
  328.          Offset   : Word16;           { Offset in segment }
  329.          Selector : Word16;           { Callgate selector }
  330.         end);
  331.    2 : (Fwd : record                  { Forwarder }
  332.          ModOrd : Word16;             { Module ordinal number }
  333.          Value  : Longint;            { Proc name offset or ordinal }
  334.         end);
  335.   end;
  336.  end;
  337.  
  338. { Module format directive table }
  339. type
  340.  pDirTabRec = ^tDirTabRec;
  341.  tDirTabRec = record
  342.   DirN    : Word16;
  343.   DataLen : Word16;
  344.   DataOfs : Longint;
  345.  end;
  346.  
  347. const
  348.  dtResident = $8000;
  349.  dtVerify   = $0001;
  350.  dtLangInfo = $0002;
  351.  dtCoProc   = $0003;
  352.  dtThreadSt = $0004;
  353.  dtCSetBrws = $0005;
  354.  
  355. const
  356.  fixEnt16      = 3;
  357.  fixEnt32      = 5;
  358.  gateEnt16     = 5;
  359.  fwdEnt        = 7;
  360.  
  361. { BUNDLE TYPES }
  362. const
  363.  btEmpty       = $00;                 { Empty bundle }
  364.  btEntry16     = $01;                 { 16-bit offset entry point }
  365.  btGate16      = $02;                 { 286 call gate (16-bit IOPL) }
  366.  btEntry32     = $03;                 { 32-bit offset entry point }
  367.  btEntryFwd    = $04;                 { Forwarder entry point }
  368.  btTypeInfo    = $80;                 { Typing information present flag }
  369.  
  370. { Format for lxEflags                      }
  371. {                                          }
  372. {  7 6 5 4 3 2 1 0  - bit no               }
  373. {  | | | | | | | |                         }
  374. {  | | | | | | | +--- exported entry       }
  375. {  | | | | | | +----- uses shared data     }
  376. {  +-+-+-+-+-+------- parameter word count }
  377. const
  378.  lxExport      = $01;                 { Exported entry }
  379.  lxShared      = $02;                 { Uses shared data }
  380.  lxParams      = $F8;                 { Parameter word count mask }
  381.  lxParamsShft  = 3;                   { Count of times to shift right }
  382.  
  383. { Flags for forwarders only: }
  384. const
  385.  fwd_Ordinal   = $01;                 { Imported by ordinal }
  386.  
  387. {Entry table bundle element structure}
  388. type
  389.  pLXentryPoint = ^tLXentryPoint;
  390.  tLXentryPoint = record case byte of
  391.   btEmpty    : ();
  392.   btEntry16  : (e16Flags : Byte; e16Ofs : Word16);
  393.   btGate16   : (eGate16Flags : Byte; eGate16Ofs, eGate16Sel : Word16);
  394.   btEntry32  : (e32Flags : Byte; e32Ofs : Longint);
  395.   btEntryFwd : (eForwFlags : Byte; eForwModOrd : Word16; eForwOfs : Longint);
  396.  end;
  397.  
  398. {Name table entry record used to keep name table in memory}
  399. type
  400.  pNameTblRec = ^tNameTblRec;
  401.  tNameTblRec = record
  402.   Name : pString;
  403.   Ord  : Word16;
  404.  end;
  405.  
  406. Implementation
  407.  
  408. end.
  409.