home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
DOSREF20.ZIP
/
CHAPTER.006
< prev
next >
Wrap
Text File
|
1991-06-17
|
34KB
|
602 lines
** Programmer's Technical Reference for MSDOS and the IBM PC **
┌─────────────────────────────┐
│ Shareware Version, 06/17/91 │
│ Please Register Your Copy │
└─────────────────────────────┘
Copyright (c) 1987, 1991 Dave Williams
USA copyright TXG 392-616 ALL RIGHTS RESERVED
ISBN 1-878830-02-3 (disk-based text)
C H A P T E R S I X
DOS CONTROL BLOCKS AND WORK AREAS
Contrary to popular belief, DOS is not limited to 640k of work space. This
constraint is enforced by the mapping of ROM and video RAM into the default 1
megabyte CPU address space. Some MSDOS compatible machines, such as the Sanyo
55x series, can have as much as 768k of contiguous DOS workspace with the
appropriate option boards. Since DOS has no real memory management, it cannot
deal with a fragmented workspace. Fragmented RAM (such as RAM mapped into the
option ROM address space) can be dealt with as a RAMdisk or other storage area
by using a device driver or other software.
The 80386 CPU and appropriate control software can create a DOS workspace of
more than one megabyte. Certain add-on boards can also add more than a
megabyte of workspace, but only for specially written software. Since these
are all proprietary schemes, little information is availible at present.
When DOS loads a program, it first sets aside a section of memory for the
program called the program segment, or code segment. Then it constructs a
control block called the program segment prefix, or PSP, in the first 256
(100h) bytes. Usually, the program is loaded directly after the PSP at 100h.
The PSP contains various information used by DOS to help run the program.
The PSP is always located at offset 0 within the code segment. When a program
recieves control certain registers are set to point to the PSP. For a COM
file, all registers are set to point to the beginning of the PSP and the
program begins at 100h. For the more complex EXE file structures, only DS and
ES registers are set to point to the PSP. The linker passes the settings for
the DS, IP, SS, and SP registers and may set the starting location in CS:IP to
a location other than 100h.
IBMBIO provides an IRET instruction at absolute address 847h for use as a
dummy routine for interrupts that are not used by DOS. This lets the interrupts
do nothing until their vectors are rerouted to their appropriate handlers.
A storage block is used by DOS to record the amount and location of allocated
memory within the machine's address space.
A storage block, a Program Segment Prefix, and an environment area are built
by DOS for each program currently resident in the address space. The storage
block is used by DOS to record the address range of memory allocated to a
program. It is used by DOS to find the next availible area to load a program
and to determine if there is enough memory to run that porogram. When a
memory area is in use, it is said to be allocated. Then the program ends, or
releases memory, it is said to be deallocated.
A storage block contains a pointer to the Program Segment Prefix associated
with each program. This control block is constructed by IBMDOS for the purpose
of providing standardized areas for DOS/program communication. Within the
PSP are areas which are used to save interrupt vectors, pass parameters to
the program, record disk directory information, and to buffer disk reads and
writes. This control block is 100h bytes in length and is followed by the
program module loaded by DOS.
The PSP contains a pointer to the environment area for that program. This
area contains a copy of the current DOS SET, PROMPT, COMSPEC, and PATH values
as well as any user-set variables. The program may examine and modify this
information as desired.
Each storage block is 10h bytes long, although only 5 bytes are currently
used by DOS. The first byte contains 4Dh (a capital M) to indicate that it
contains a pointer to the next storage block. A 5Ah (a capital Z) in the
first byte of a storage block indicatres there are no more storage blocks
following this one (it is the end of the chain). The identifier byte is
followed by a 2 byte segment number for the associated PSP for that program.
The next 2 bytes contain the number of segments what are allocated to the
program. If this is not the last storage block, then another storage block
follows the allocated memory area.
When the storage block contains zero for the number of allocated segments,
then no storage is allocated to this block and the next storage block
immediately follows this one. This can happen when memory is allocated and
then deallocated repeatedly.
IBMDOS constructs a storage block and PSP before loading the command
interpreter (default is COMMAND.COM).
If the copy of COMMAND.COM is a secondary copy, it will lack an environment
address at PSP+2Ch.
THE DISK TRANSFER AREA (DTA)├──────────────────────────────────────────────────
DOS uses an area in memory to contain the data for all file reads and writes
that are performed with FCB function calls. This are is known as the disk
transfer area. This disk transfer area (DTA) is sometimes called a buffer.
It can be located anywhere in the data area of your application program and
should be set by your program.
Only one DTA can be in effect at a time, so your program must tell DOS what
memory location to use before using any disk read or write functions. Use
function call 1Ah (Set Disk Transfer Address) to set the disk transfer address.
Use function call 2Fh (Get Disk Transfer Address) to get the disk transfer
address. Once set, DOS continues to use that area for all disk operations until
another function call 1Ah is issued to define a new DTA. When a program is given
control by COMMAND.COM, a default DTA large enough to hold 128 bytes is
established at 80h into the program's Program Segment Prefix.
For file reads and writes that are performed with the extended function calls,
there is no need to set a DTA address. Instead, specify a buffer address when
you issue the read or write call.
DOS PROGRAM SEGMENT├───────────────────────────────────────────────────────────
When you enter an external command or call a program through the EXEC function
call, DOS determines the lowest availible address space to use as the start of
available memory for the program being started. This area is called the Program
Segment.
At offset 0 within the program segment, DOS builds the Program Segment Prefix
control block. EXEC loads the program after the Program Segment Prefix (at
offset 100h) and gives it control.
The program returns from EXEC by a jump to offset 0 in the Program Segment
Prefix, by issuing an int 20h, or by issuing an int 21h with register AH=00h or
4Ch, or by calling location 50h in the PSP with AH=00h or 4Ch.
It is the responsibility of all programs to ensure that the CS register
contains the segment address of the Program Segment Prefix when terminating by
any of these methods except call 4Ch.
All of these methods result in returning to the program that issued the EXEC.
During this returning process, interrupt vectors 22h, 23h, and 24h (Terminate,
Ctrl-Break, and Critical Error Exit addresses) are restored from the values
saved in the PSP of the terminating program. Control is then given to the
terminate address.
When a program receives control, the following conditions are in effect:
For all programs:
1) The segment address of the passed environment is contained at offset 2Ch in
the Program Segment Prefix.
2) The environment is a series of ASCII strings totalling less than 32k bytes
in the form: NAME=value The default environment is 160 bytes.
Each string is a maximum of 127 bytes terminated by a byte of zeroes for a
total of 128 bytes, and the entire set