Function 00H (0): Driver Initialization

MS-DOS requests the driver's initialization function (init) only once, when the driver is first loaded. This function performs any necessary device hardware initialization, setup of interrupt vectors, and so forth. The initialization routine must return the address of the position where free memory begins after the driver code (the break address), so that MS-DOS knows where it can build certain control structures and then load the next installable driver. If this is a block-device driver, init must also return the number of units and the address of a BPB pointer array.

MS-DOS uses the number of units returned by a block driver in the request header to assign drive identifiers. For example, if the current maximum drive is D and the driver being initialized supports four units, MS-DOS will assign it the drive letters E, F, G, and H. Although the device-driver header also has a field for number of units, MS-DOS does not inspect it.

The BPB pointer array is an array of word offsets to BIOS parameter blocks (Figure 14-7). Each unit defined by the driver must have one entry in the array, although the entries can all point to the same BPB to conserve memory. During the operating-system boot sequence, MS-DOS scans all the BPBs defined by all the units in all the block-device drivers to determine the largest sector size that exists on any device in the system and uses this information to set its cache buffer size.

The operating-system services that the initialization code can invoke at load time are very limited only Int 21H Functions 01H through 0CH and 30H. These are just adequate to check the MS-DOS version number and display a driver-identification or error message.

Many programmers position the initialization code at the end of the driver and return that address as the location of the first free memory, so that MS-DOS will reclaim the memory occupied by the initialization routine after the routine is finished with its work. If the initialization routine finds that the device is missing or defective and wants to abort the installation of the driver completely so that it does not occupy any memory, it should return number of units as zero and set the free memory address to CS:0000H. (A character-device driver that wants to abort its installation should clear bit 15 of the attribute word in the driver header and then set the units field and free memory address as though it were a block-device driver.)

Byte(s) Contents

00—01H Bytes per sector

02H Sectors per allocation unit (power of 2)

03H—04H Number of reserved sectors (starting at sector 0)

05H Number of file allocation tables

06H—07H Maximum number of root-directory entries

08H—09H Total number of sectors in medium

0AH Media descriptor byte

0BH—0CH Number of sectors occupied by a single FAT

0DH—0EH Sectors per track (versions 3.0 and later)

0FH—10H Number of heads (versions 3.0 and later)

11H—12H Number of hidden sectors (versions 3.0 and later)

13H—14H High-order word of number of hidden sectors

(version 4.0)

15H—18H If bytes 8—9 are zero, total number of sectors in

medium (version 4.0)

19H—1EH Reserved, should be zero (version 4.0)

Figure 14-7. Structure of a BIOS parameter block (BPB). Every formatted disk contains a copy of its BPB in the boot sector. (See Chapter 10.)

The initialization function is called with

RH + 2 BYTE Command code = 0

RH + 18 DWORD Pointer to character after equal sign

on CONFIG.SYS line that loaded driver

(this information is read-only)

RH + 22 BYTE Drive number for first unit of this

block driver (0 = A, 1 = B, and so

forth) (MS-DOS version 3 only)

It returns:

RH + 3 WORD Status

RH + 13 BYTE Number of units (block devices only)

RH + 14 DWORD Address of first free memory above

driver (break address)

RH + 18 DWORD BPB pointer array (block devices

only)