Appendix EE.1 MS-DOS - .EXE FILE HEADER STRUCTUREThe Microsoft linker outputs .EXE files in a relocatable format, suitable for quick loading into memory and relocation to any paragraph (16-byte) boundary. EXE files consist of the following parts:
EXE files are loaded in the following manner:
The resulting relocated program is then executable. Typically, programs using the PL/M small memory model have little or no relocation; programs using larger memory models have relocation for long calls, jumps, static long pointers, etc. The following is a detailed description of the format of an EXE file: Microsoft .EXE File Main Header
Byte Name Function
0+1 wSignature Must contain 4D5Ahex, this is the MS-
LINK signature to mark the file as
a valid .EXE file.
2+3 cbLastp Number of bytes in the memory image
modulo 512. If this is 0 then the last
page is full, else it is the number of
bytes in the last page. This is useful
in reading overlays.
4+5 cpnRes Size of the file in 512-byte pages
including the end of the EXE file
header.
6+7 irleMax Number of relocation entries in the
table.
8+9 cparDirectory Number of paragraphs in EXE file
header, used to locate the beginning
of the memory image in the field.
A+B cparMinAlloc Minimum number of 16-byte paragraphs
required above the end of the loaded
program.
C+D cparMaxAlloc High/low loader switch, maximum number
of 16-byte paragraphs required above
the end of the loaded program. 0FFFFh
means that the program is located as
low as possible into memory.
E+F saStack Initial value to be loaded into SS
before starting program execution.
10+11 raStackInit Initial value to be loaded into SP
before starting program execution.
12+13 wchksum Negative of the sum of all the words
in the run file, ignoring overflow.
14+15 raStart Initial value to be loaded into IP
before starting program execution.
16+17 saStart Initial value to be loaded into CS
before starting program execution.
18+19 rbrgrle Relative byte offset from beginning of
run file to the relocation table.
1A+1B iov Number of the overlay as generated by
LINK-86. The resident part of a
program will have iov = 0.
The relocation table follows the fixed portion of the run file header and contains irleMax entries of type rleType, defined by: rleType bytes 0+1 ra
bytes 2+3 sa
Taken together, the ra and sa fields are an 8086/8088 long pointer to a word in the EXE file to which the relocation factor is to be added. The relocation factor is expressed as the physical address of the first byte of the resident divided by 16. Note that the sa portion of an rle must first be relocated by the relocation factor before it in turn points to the actual word requiring relocation. For overlays, the rle is a long pointer from the beginning of the resident into the overlay area. The format of the EXE file is: __________________________________
| |
| 28 byte Header |
|__________________________________|
| |
| Relocation Table |
~ ~
~ ~
|__________________________________|
| |
| Padding ( <200h bytes ) |
|__________________________________|
| |
| Memory Image |
~ ~
~ ~
|__________________________________|
The Memory Image begins at the first 512-byte boundary following the end of the Relocation table.
All contents of this website (including text, images, design, and presentation) are Copyright � 1999-2004, |