-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path4_CTRLB.A
393 lines (249 loc) · 10.8 KB
/
4_CTRLB.A
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
_ _ | | _ _
MS-DOS Control Blocks and Work Areas
_ ______________________________________________
4.1 Introduction
This chapter describes a typical MS-DOS memory map and explains how a
program is loaded into memory. It also describes the structure of an
MS-DOS program segment and the contents of register segments for .exe
and .com program files.
4.2 Typical Contents of an MS-DOS Memory
Map
A typical MS-DOS memory map contains the following information:
+-----------------------------------------------------+
| ROM and Video Buffers |
+-----------------------------------------------------+
| Transient Part of COMMAND.COM |
+-----------------------------------------------------+
| |
| |
| |
| |
| Transient Program Area |
|- - - - - - - - - - - - - - - - - - - - - - - - - - -|
| |
| |
| |
| |
| External Commands and Utilities |
| |
+-----------------------------------------------------+
| Resident Part of COMMAND.COM |
+-----------------------------------------------------+
| MS-DOS buffers, control areas, & installed drivers |
+-----------------------------------------------------+
| |
| MSDOS.SYS |
+-----------------------------------------------------+
| IO.SYS and resident device drivers |
+-----------------------------------------------------+
| Interrupt Vectors |
0 +-----------------------------------------------------+
During system initialization, MS-DOS loads the io.sys and msdos.sys files
into low memory (Note that in MS-DOS 3.3, these files are not required to
be written contiguously to the disk). The io.sys system file is the MS-DOS
interface to hardware. The msdos.sys system file includes MS-DOS inter-
rupt handlers, service routines (Interrupt 21H functions).
3
_ _ | | _ _
_ _ | | _ _
_ ______________
Next, the system initialization routine loads the resident and installable
device drivers. Above the installable device drivers, MS-DOS writes the
resident part of command.com. This part includes interrupt handlers for
Interrupts 22H (Terminate Process Exit Address), 23H (CONTROL-C
Handler Address), 24H (Critical-Error-Handler Address) and code to reload
the transient part. The transient part of command.com is reloaded into
high memory. It includes the command interpreter, the internal MS-DOS
commands, and the batch processor.
External command and utility (.com and .exe) files are loaded into the
transient program area. MS-DOS also allocates 256 bytes for user stack
used with .com files. User memory is allocated from the lowest end of
available memory that fulfills the allocation request.
4.3 MS-DOS Program Segment
When you type an external command or execute a program through Func-
tion 4BH (Load and Execute Program, also called EXEC), MS-DOS deter-
mines the lowest available free memory address to use as the start of the
program. The memory starting at this address is called the Program Seg-
ment.
The EXEC system call sets up the first 256 bytes of the Program Segment
for the program being loaded into memory. The program is then loaded
following this block. An .exe file with minalloc and maxalloc both set to
zero is loaded as high as possible.
At offset 0 within the Program Segment, MS-DOS builds the Program Seg-
ment Prefix control block. The program returns from EXEC by one of five
methods:
o By issuing an Interrupt 21H with AH=4CH
o By issuing an Interrupt 21H with AH=31H (Keep Process)
o By a long jump to offset 0 in the Program Segment Prefix
o By issuing an Interrupt 20H with CS:0 pointing at the PSP
o By issuing an Interrupt 21H with register AH=0 and with CS:0
pointing at the PSP
_ ________________________________________________________________
Note
The first two methods are preferred for functionality, compatibility,
and efficiency in future versions of MS-DOS.
_ ________________________________________________________________
4
_ _ | | _ _
_ _ | | _ _
MS-DOS Control Blocks and Work Areas
_ ______________________________________________
All five methods transfer control to the program that issued the EXEC
call. The first two methods return a completion code. They also restore
the addresses of Interrupts 22H, 23H, and 24H (Terminate Process Exit
Address, CONTROL-C Handler Address, and Critical-Error-Handler Address)
from the values saved in the Program Segment Prefix of the terminating
program. Control then passes to the terminate address.
If a program returns to command.com, control transfers to the resident
portion. If the program is a batch file (in process), it continues. Other-
wise, command.com performs a checksum on the transient part, reloads it
if necessary, issues the system prompt, and waits for you to type another
command.
When a program receives control, the following conditions are in effect:
For all programs:
o The segment address of the passed environment is at offset 2CH in
the Program Segment Prefix.
o The environment is a series of ASCII strings (totaling less than 32K)
in the form:
NAME=parameter
o A byte of zeros terminates each string, and another byte of zeros
terminates the set of strings.
Following the last byte of zeros is a set of initial arguments that
the operating system passes to a program. This set of arguments
contains a word count followed by an ASCII string. If the file is in
the current directory, the ASCII string contains the drive and path-
name of the executable program as passed to the EXEC function
call. If the file is not in the current directory, EXEC concatenates
the name of the file with the name of the path. Programs may use
this area to determine where the program was loaded.
o The environment built by the command processor contains at least
a comspec= string (the parameters on comspec define the path
that MS-DOS uses to locate command.com on disk). The last path
and prompt commands issued are also in the environment, along
with any environment strings you have defined with the MS-DOS
set command.
o EXEC passes a copy of the invoking process environment. If your
application uses a "keep process" concept, you should be aware
that the copy of the environment passed to you is static. That is,
it will not change even if you issue subsequent set, path, or
prompt commands. Conversely, any modification of the passed
environment by the application is not reflected in the parent pro-
cess environment. For instance, a program cannot change the
MS-DOS environment values as the set command does.
5
_ _ | | _ _
_ _ | | _ _
_ ______________
o The Disk Transfer Address (DTA) is set to 80H (default DTA in the
Program Segment Prefix). The Program Segment Prefix contains
file control blocks at 5CH and 6CH. MS-DOS formats these blocks
using the first two parameters that you typed when entering the
command. If either parameter contained a pathname, then the
corresponding FCB contains only the valid drive number. The
filename field is not valid.
o An unformatted parameter area at 81H contains all the characters
typed after the command (including leading and embedded delim-
iters), with the byte at 80H set to the number of characters. If you
type <, >, or parameters on the command line, they do not
appear in this area (nor the filenames associated with them).
Redirection of standard input and output is transparent to appli-
cations.
o Offset 6 (one word) contains the number of bytes available in the
segment.
o Register AX indicates whether the drive specifiers (entered with the
first two parameters) are valid, as follows:
AL=FF if the first parameter contained an invalid drive specifier
(otherwise AL=00)
AH=FF if the second parameter contained an invalid drive
specifier (otherwise AH=00)
o Offset 2 (one word) contains the segment address of the first byte
of unavailable memory. Programs must not modify addresses
beyond this point unless these addresses were obtained by allocat-
ing memory via Function 48H (Allocate Memory).
For Executable (.exe) Programs:
o DS and ES registers point to the Program Segment Prefix.
o CS,IP,SS, and SP registers contain the values that Microsoft link
sets in the .exe image.
For Executable (.com) Programs:
o All four segment registers contain the segment address of the ini-
tial allocation block that starts with the Program Segment Prefix
control block.
o .com programs allocate all of user memory. If the program invokes
another program through Function 4BH (EXEC), it must first free
some memory through Function 4AH (Set Block) to provide space
for the program being executed.
6
_ _ | | _ _
_ _ | | _ _
MS-DOS Control Blocks and Work Areas
_ ______________________________________________
o The Instruction Pointer (IP) is set to 100H.
o The Stack Pointer register is set to the end of the program's seg-
ment. The segment size at offset 6 is reduced by 100H to allow for
a stack of that size.
o A .com program places a word of zeros on top of the stack. Then
by doing a RET instruction last, your program can exit to
command.com. This method assumes, however, that you have
maintained your stack and code segments.
Figure 4.1 illustrates the format of the Program Segment Prefix. All
offsets are in hexadecimal.
(Offsets in Hex)
0 -----------------------------------------------------------
| | End of | |
| INT 20H | alloc. | Reserved |
| | block | 04H |
8 -----------------------------------------------------------
| | Terminate address | CONTROL-C exit |
| Reserved | (IP, CS) | address (IP) |
| | | |
10-----------------------------------------------------------
|CONTROL-C | Hard error exit address | |
|exit | (IP, CS) | |
|address (CS)| | |
---------------------------------------- |
| |
| Used by MS-DOS |
| |
| 5CH |
| |
-----------------------------------------------------------
| |
| Formatted Parameter Area 1 formatted as standard |
| unopened FCB 6CH |
-----------------------------------------------------------
| |
| Formatted Parameter Area 2 formatted as standard |
| unopened FCB (overlaid if FCB at 5CH is opened) |
80-----------------------------------------------------------
| Unformatted Parameter Area |
| (default Disk Transfer Area) |
| Initially contains command invocation line. |
-----------------------------------------------------------
100
Figure 4.1 Program Segment Prefix
_ ________________________________________________________________
Important
7
_ _ | | _ _
_ _ | | _ _
_ ______________
Programs must not alter any part of the Program Segment Prefix
below offset 5CH.
_ ________________________________________________________________
8
_ _ | | _ _
_ _ | | _ _
_ ______________
Chapter 4
MS-DOS Control Blocks
and Work Areas
_ ________________________________________________________________
4.1 Introduction 3
4.2 Typical Contents of an MS-DOS Memory Map 3
4.3 MS-DOS Program Segment 4
1
_ _ | | _ _
_ _ | | _ _
_ ______________
8
_ _ | | _ _