Repository navigation
io_sys.md
IO.SYS is formed by concatenating two binaries, compiled separately as MSLOAD.COM and MSBIO.BIN. The source code is in v4.0/src/BIOS.
The system boot record loads the first three sectors of IO.SYS to 0070:0000 and jumps to it, with the registers set as follows:
- DL = INT 13 drive number we booted from.
- CH = media descriptor byte.
- AX:BX = First data sector on disk. If the BIOS Parameter Block does not have the extended signature, only BX is used.
- DS:SI = Original disk parameter table from ROM (vector 0x13)
MSLOAD.COM is built from v4.0/src/BIOS/MSLOAD.ASM.
MSLOAD.COM copies the relevant parameters from the BIOS Parameter Block (BPB). It then copies itself to the end of main memory, leaving enough for one sector to read the FAT, and jumps to the copy. It then reads the rest of IO.SYS, copies the part that comes from MSBIO.BIN to 0070:0000, and jumps to that address.
IO.SYS has to start at cluster 2 (that is, the start of the data area) and the first three sectors have to be contiguous. This is a problem for creating a bootable disk under Linux, because the FAT file system driver starts the first file at cluster 3.
The calculation to determine whether the volume is FAT12 or FAT16 assumes 512 byte sectors and two FATs, regardless of what's in the BPB.
MSBIO.BIN is built from these sources in v4.0/src/BOOT:
- MSBIO1.ASM
- MSCON.ASM
- MSAUX.ASM
- MSLPT.ASM
- MSCLOCK.ASM
- MSDISK.ASM
- MSBIO2.ASM
- MSHARD.ASM
- MSINIT.ASM
- SYSINIT1.ASM
- SYSCONF.ASM
- SYSINIT2.ASM
- SYSIMES.ASM
MSBIO.BIN initializes hardware, establishes handlers for some interrupt vectors, establishes a core set of device drivers, interprets CONFIG.SYS and then loads MSDOS.SYS.
The drivers and interrupt vectors handled in MSBIO.BIN are listed below.
Vector 0x13 has two chained interrupt handlers.
The first is INT13, defined in MS96TPI.INC. This one calls the next handler and then sets a flag in MSBIO.BIN data structures if a disk change has been indicated.
The second is BLOCK13, defined in MSDISK.ASM. This one recovers from errors caused by a DMA transfer crossing a 64K boundary, provides more tracking of disk changes and patches around a bug in the BIOS for the PS/2 Model 30.
The handler is INT19, defined in MSBIO2.ASM. According to comments preceding the handler, the BIOS does not reset the interrupt vectors when vector 0x19 is called. The handler resets the vectors and then chains to the BIOS.
The handler is CBREAK, defined in MSCON.ASM. This is called from the BIOS when the user presses CTRL-C. The handler sets a flag (ALTAH set to 3) and returns.
The handler is OUTCHR, defined in MSBIO1.ASM. This passes a character meant for standard output to the BIOS. It is meant to be overridden to redirect standard output.
This is the "multiplex interrupt", meant for various drivers to provide their interfaces. MSBIO.BIN provides two such interfaces.
If AH == 0x13, this allows a caller to replace the underlying INT 0x13 handler, initially pointing to the BIOS. The variable ORIG13 is exchanged with DS:DX, and the variable OLD13 is exchanged with ES:BX. ORIG13 is the handler that the INT 0x13 wrappers call, and OLD13 is the handler restored on INT 0x19.
If AH == 0x08, then the following services are available:
- AL == 0: This is an installation check. AL is set to 0xFF.
- AL == 1: DS:SI points to a Block Directory Structure, which is added to the end of the list to define a new block device.
- AL == 3: Return the pointer to the first Block Directory Structure in DS:SI.
AL == 2 is meant to provide an alternate interface to the DSK$ driver. This doesn't work as expected: it returns with a RETF instruction instead of the correct IRET. This interface can be called safely at least on DOS 3.21 through 6.22 with these instructions:
mov bx,offset buf
mov es,seg buf
mov cx,sp
int 2Fh
mov sp,cx
This interface locks up on DOS 2.11. It is not implemented on DOS 3.0, DOS 3.1 or FreeDOS, but saving the stack pointer as shown above keeps the system running.
These are hardware interrupts, defined by a macro in STKINIT.INC. These switch to a dedicated stack and chain to the BIOS.
0x02 is the non-maskable interrupt. This one also works around a hardware bug in some early PCs.