-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEXE2COM.DOC
292 lines (229 loc) · 10.9 KB
/
EXE2COM.DOC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
EXE2COM 1.05
By Chris Dunford/Cove Software
| indicates information changed/added in recent versions.
Purpose
-------
EXE2COM is a one-for-one replacement for the EXE2BIN program
that was formerly distributed with DOS. Beginning with DOS 3.3,
EXE2BIN has been moved to the disk that comes with the DOS
Technical Reference and thus is not available without extra
cost.
Usage
-----
Usage is identical to DOS's EXE2BIN except that the output file
extension defaults to COM rather than BIN, and there are two
optional switches.
Complete usage is:
| EXE2COM [/IR] [d:][path]file[ext] [d:][path][file][ext]
The drive and path of the first file default to the current
drive and path, if not specified. The extension of the first
file defaults to EXE, if not specified.
If the second file is completely unspecified, it defaults to the
same drive, path, and filename as the first, except that the
extension will be COM.
If the second file is specified but without an extension, COM
will be assumed (this is different from EXE2BIN).
If /I is specified, information about the EXE file is displayed
and no conversion is performed. The output file name, if
specified, is ignored.
| If /R is specified and the EXE file contains relocatable items,
| the relocation table is displayed (see below).
The simplest (and usual) usage is simply:
EXE2COM file
which will take the named EXE file in the current directory and
convert it to a COM file in the same directory.
Operation
---------
EXE2COM runs the same way as EXE2BIN, with the following
exceptions:
1. The binary fixup option of EXE2BIN (IP=0, segment fixups
required) is not supported.
2. The EXE file checksum is not verified.
3. Error messages are more useful, and a warning is provided
if a COM file is created with an initial IP other than 100H.
4. The default output file extension is COM rather than BIN.
Information display
-------------------
If you use the /I switch, EXE2COM just displays information
about the EXE file and does not attempt to convert it to COM
(therefore, the EXE file need not be a convertible file). Here
is a typical display, resulting from running EXE2COM on itself
(version 1.04) with the /I switch:
exe2com.exe (hex) (dec)
EXE file size 396B 14699
EXE header size (para) 20 32
Program image size (bytes) 376B 14187
Minimum load size (bytes) 8CDB 36059
Min allocation (para) 557 1367
Max allocation (para) FFFF 65535
* Initial CS:IP 0000:072C
* Initial SS:SP 084D:0800 2048 (stack size)
* Relocation count 4 4
Relo table start 001E 30
EXE file checksum 411D 16669
Overlay number 0 0
* = this item prevents conversion to BIN/COM
The fields that may need some explanation:
Program image size: this is the size of the program itself
(i.e., the size of the EXE file less the size of the header
information). This much memory is required to load a copy of
the program's code and pre-allocated data.
Minimum load size: at least this much free memory is required in
order to run the program.
Min/max allocation: the minimum/maximum number of 16-byte
paragraphs that will be needed above the end of the program
image when it is loaded. Minimum load size is the sum of the
program image size and the minimum allocation.
Relocation count: see below.
If an item is starred (*), this prevents the EXE file from being
converted to a COM file.
| Relocatable items
| -----------------
| The most common reason why a file cannot be converted to COM
| or SYS format is that it has "relocatable items."
|
| A relocatable item is a piece of code that must be "fixed up"
| when the program is run because it changes with the program's
| load address. Consider this code fragment:
|
| code segment byte public
| mov ax,code
| ...
|
| What gets moved into AX is CODE's segment address, which is
| not known until runtime. The assembler can't specify the
| value to be loaded into AX because it doesn't know where in
| memory the program will be loaded. Only the EXE file loader
| can perform this operation; hence, it can't be converted into
| a COM or SYS file.
|
| The EXE file header contains one entry for each such relocatable
| item. This entry consists of the segment and offset of the word
| that must be fixed up at runtime. Note that the "segment" is
| relative to the first segment of the program; the first segment
| will be 0000.
|
| If you see the message "EXE contains relocatable items", you can
| ask EXE2COM to find the items by re-running it with the /R
| /R switch:
|
| exe2com /r myprog
|
| EXE2COM might display something like this:
|
| relocation table:
| 0000:00AF 0000:01C3
|
| This shows that there are two relocatable items in the EXE file
| and that they are located at the specified segment:offset
| addresses. The first relocatable item in this case is located
| at offset 00AFh of the program's first segment.
|
| A list (.LST) file can be very helpful in finding your
| relocatable items: for each one (in the opcode column), you will
| see a "----" where a number should be. In the example, it
| might look like:
|
| 00AE B8 ---- R mov ax,code
|
| EXE2COM's relocation table display can be helpful in letting
| you know where to look for the error.
|
| To correct the problem, restate the instruction in a way that
| doesn't require a direct reference to a segment. For example,
| you might recode "mov ax,code" as "mov ax,cs" (assuming that CS
| points to the CODE segment).
Error Messages
--------------
These are EXE2COM's error messages. If one of these is seen,
the EXE file will not be converted and the errorlevel returned
by EXE2COM will be 1.
ERROR READING EXE HEADER
EXE2COM was unable to read the EXE file header from disk.
ERROR WRITING OUTPUT FILE
EXE2COM was unable to write the converted file to disk.
INVALID EXE FILE SIGNATURE
The first two bytes of an EXE file should be ASCII 'M' and
'Z'. This was not the case, and it's probably not an EXE
file.
EXE HAS RELOCATABLE ITEMS
In order to be converted to a COM file, an EXE file cannot
have any direct references to segments. For example, the
assembler instruction "mov ax,code" (where CODE is a segment
name) is a segment reference. One or more segment
references were found in the EXE file. See above.
EXE HAS STACK SEGMENT
In order to be converted to a COM file, an EXE file cannot
have a stack segment.
EXE HAS NONZERO CS
In order to be converted to a COM file, an EXE file must
have a code segment that begins at offset 0 of the code
image in the EXE file.
IP NOT 0 OR 100H
In order to be converted to a binary file, an EXE file must
have an entry point of 0 or 100H within the code segment.
For COM files, the entry point should be 100H. For SYS
files (device drivers), the entry point should be 0.
PROGRAM EXCEEDS 64K
In order to be converted to a binary file, the total size of
the code to be loaded (including the PSP) must not exceed
64K bytes.
UNKNOWN ERROR
Internal error. Notify the author.
Warning message
---------------
EXE2COM has one warning message:
COM FILE, INITIAL IP NOT 100H
The entry point of all COM files should be 100H. If you are
creating a COM file an the entry point is not 100H, EXE2COM will
do the job but let you know that there is a potential problem.
Source
------
Source code should be included with this archive. Users are
encouraged to modify, improve, and/or correct the source for
EXE2COM and submit the new program to the author for
distribution. Please identify clearly any changes made and
stick with portable code to the extent possible (no inline
assembler, PLEASE).
EXE2COM.EXE was compiled with Microsoft C 6.0, but I believe
that it will compile correctly with Borland's Turbo C (I don't
have TC, so can't swear to this). It should be easily portable
to most other compilers.
Public domain
-------------
EXE2COM is hereby donated by the author to the public domain.
History
-------
Version 1.00 04/17/87: Original version by
Christopher J. Dunford
The Cove Software Group
PO Box 1072
Columbia, MD 21044
(301) 992-9371
CompuServe 76703,2002
Version 1.01: port to Turbo C by
Roger Schlafly
Borland International
Scotts Valley, CA 95066
CompuServe 76067,511
Version 1.02 11/22/87: bug fix for even 512-byte file made to
Turbo C port by
Chris Blum ( Consultant )
509 West Main, Front
Ashland, Ohio 44805
CompuServe 76625,1041
Chris Dunford duplicated the fix in the C86 source.
Version 1.03 12/30/87: by Chris Dunford
Ported to Microsoft C 5.0. This is now the "official"
version.
Increased size of I/O buffer to 4K for speed reasons.
EXE2COM 1.03 is twice as fast as 1.02 and slightly
faster than EXE2BIN.
Version 1.04 03/08/88: by Chris Dunford
Cleaned up some old code from the original quickie.
Source should now compile under either MSC or TC.
Added /I switch.
In earlier versions, we defined an error code for nonzero
CS, but didn't actually check; now we do.
Version 1.05 08/23/90: by Chris Dunford
Added /R (relo table) switch