Because of the lack of standards for device driver and TSR
initialization, it is virtually impossible to determine the memory
needed in any other manner than trial and error. Load size can be
determined; however, initialization and final sizes will vary from
program to program.
For .COM files and device drivers that follow standard conventions
(.SYS), the load size will be the file size on disk rounded up to
the nearest paragraph (16 bytes). Note that some .SYS files will
actually be .EXE files. To determine this, look at the first two bytes
of the file. If these bytes are MZ in ASCII or 4D and 5A in hex, it is
an executable file.
Executable files (.EXE) files contain the load size information in the
program header (.EXE file header). The .EXE file load size does not
necessarily relate to the file size on disk. At an offset of 10 and 12
bytes respectively reside the minimum and maximum number of pages
(16 bytes) needed by the executable file in addition to the file size.
EXEHDR.EXE included with many programming products (including Microsoft
C Compiler) will allow you to look at the .EXE file header information.
From this information you will be able to approximate the load size of
an .EXE program.
For example, by running EXEHDR.EXE included with Microsoft C version
6.0a on EMM386.EXE, the following information will be displayed:
Microsoft (R) EXE File Header Utility Version 2.01
Copyright (C) Microsoft Corp 1985-1990. All rights reserved.
Description: Win386 LoadHi Device (Version 1.0)
Module type: Dynamic link library; initialization
NO external fixups in executable image
Number of memory pages: 00000005 (5)
Initial CS:EIP: object 3 offset 00000000
Initial SS:ESP: object 0 offset 00000000
Automatic data object: 0
no. virtual virtual page file flags
address size map pages
0001 00000000 00001a08 00000001 00000002 EXECUTABLE, READABLE,
0002 00002000 00001218 00000003 00000002 EXECUTABLE, READABLE,
0003 00004000 0000002a 00000005 00000001 EXECUTABLE, READABLE,
ord obj offset name
1 1 000012e4 LoadHi_DDB exported, shared data
By totaling the virtual sizes of 1a08H, 1218H, and 02AH you can
determine the load size to be a total of 11338 decimal. Note that this
is not necessarily the ending memory used by EMM386.EXE, but the
initial load size.
Many device drivers undergo an initialization process that normally
requires more memory than the ending size of the driver. Frequently
the initialization memory is placed after the device driver and
subsequently freed upon completion of the initialization process. The
method for doing so is not standardized, and therefore not consistent.
For this reason, there is no way of knowing what method a driver
developer will use, and therefore no way of determining how much
memory will be used, other than by actually disassembling the code and
working through the program.
The final quantity, the Break address of the driver, is returned
during the INIT procedure of a device driver or the termination
call of a TSR.
When loading a device driver, DOS will pass the device driver a
command code 0 for initialization. It is the device driver's
responsibility to fill the Request Header (a DOS data structure) with
the break address (ending address) of the device driver. When and
where the code is located that the device driver uses to accomplish
this task is completely up to the programmer. For this reason, the
only way of determining the break address is to debug the device
A TSR program will make a DOS function call to one of the following
Int 21h function 00h
Int 21h function 31h
Int 21h function 4Ch
The program will provide DOS with the break address of the TSR via
different methods depending upon the function used.