Source: PC Magazine, 25 Jun 1991. Original HERE. BIOS stands for Basic Input/Output Subsystem. It gets this name because it contains an extensive collection of input/output (I/O) routines, which programs and operating systems can call upon to communicate with devices attached to the PC. The name itself was probably borrowed from the CP/M operating system, which contained a BIOS module in software that provided machine-specific interfaces to the hardware the operating system was run on. The BIOS on the PC is encoded in ROM. so you'll often hear it called the ROM BIOS. Physically, the BIOS is a chip or set of clips that Plugs into your machine’s system board. Some adapters such us EGA and VGA video cards and disk controllers contain their own BIOSes. which supplement the main BIOS. In many cases, the routines stored in these adapter BIOSes replace routines in the system board BIOS. The industry's two preeminent PC manufacturers, IBM and Compaq. write their own BIOS code. Most smaller manufacturers depend on compatible BIOSes from companies such as Phoenix. Award, and AMI. IBM published the commented source code listings for the PC. XT. and AT BIOSes in the technical reference manuals for those computers. If you can lay your hands on one of these documents and aren't intimidated by long assembly language listings, you can get a good idea of what BIOS code looks like and see how the BIOS interfaces with individual devices. Routines in the BIOS are accessed via software interrupts – CPU instructions that pass control from the program currently executing to an interrupt handler that lies elsewhere in memory. At start-up, the BIOS initializes certain interrupt vectors in the PC's interrupt vector table (which occupies the first 400h bytes of memory) to point to interrupt handlers within itself. When DOS or an application program calls a interrupt, the interrupt handler pointed to by that interrupt vector gets called. The interrupt handler execute, a particular function selected by the AH register. This way, the actual address of the routine is irrelevant: all the caller has to do is know the function code and interrupt number for the service it wants to invoke. ![]() Figure 1: The Role of the BIOS. The BIOS offers a broad set of I/O routines that programs and operating systems can use to interface with the hardware they’re run on. Figure 1 illustrates where the BIOS, acting as a low-level interface to the hardware in a PC, fits into the system. DOS uses routines in the BIOS exclusively to interact with devices such as the screen, keyboard, and printer. For example, to throw a character up on the screen, DOS passes an ASCII code to the CON device driver through interrupt 29h, also known as the Fast Console Output Interrupt (see the February 12, 1991, Tutor column for an explanation). CON in turn calls the BIOS Write Teletype function (interrupt 10h function 0Eh) in the video BIOS to display the character. If ANSI.SYS has replaced CON, it does the same thing but uses the BIOS Write Character and Attribute function (interrupt 10h function 09h). Similarly, the PRN device driver uses interrupt 17h, the entry point to the BIOS printer I/O services, to output characters to the printer. And in one of the very few instances when DOS uses the BIOS directly rather than using one of its own device driven, it calls the BIOS Scroll Active Video Page Up function to clear the screen when you type CLS (unless ANSI.SYS is loaded; in this case it clears the screen by transmitting a clear screen escape sequence to ANSI.SYS). Application programs aren't nearly so well behaved. They're liable to use services in the DOS kernel or BIOS or to program the hardware directly, depending on which is the most convenient or the fastest. For direct device I/O, most programs opt for BIOS services rather than DOS services, because the former are generally more powerful and less susceptible to outside influences, like presses of Ctrl-C or redirection operators. In some cases, even the BIOS isn't enough. For example, most applications that use the serial ports program the UART chips that drive the serial ports themselves, because neither DOS nor the BIOS can support communications rates higher than about 1,200 bits per second with the primitive serial port I/O functions built into them. BIOS Services Ignoring some of the less-common BIOS functions, the device I/O services the BIOS provides fall into seven major categories:
These services are summarized by interrupt and function number in Figure 2. Not all the BIOS services are shown. I've omitted some that are rarely used or that appeared only in PCs that are now defunct (for example. the PCjr). Also, not all the services listed are available on all PCs. Whether or not a function is supported by the BIOS depends on several factors, including the type of PC, the hardware that's installed, the brand of BIOS you're using, and the date it was written. It's not unusual for programs to restrict themselves to a narrow range of BIOS calls so that they can run without modification on a wider variety of machines. For example, not many programs call on the video BIOS's Write String function, even though it's a very convenient one to use. This function isn't implemented on video adapter, predating the EGA, so using it modem a program incompatible with systems equipped with CGA and MDA video cards. The list in Figure 2 will give you some idea of the breadth of services the BIOS offers. Unfortunately, it’s not possible to examine them all in the space we have here. For additional information on these services, there are many references available at local bookstores, including Ray Duncan's Advanced MS-DOS, from Microsoft Press. You may also order IBM's official reference to BIOS services, the Personal System/2 and Personal Computer BIOS Interface Technical Reference (part number 68X2341), by calling 800-IBM-PCTB. The cost is (ouch!) $150. A supplement (part number 15F2161) is available for an additional $18. More than I/O In addition to these low-level hardware interface routines, the BIOS contains the code for the Power-On Self Test, or POST, and the bootstrap loader. The POST is the cries of diagnostic routines, executed when you turn your PC on, that ensure the hardware components of the system are working properly. The POST was discussed in the February 19, 1990, Tutor Column. The bootstrap loader is the routine that reads the boot sector from a DOS disk and transfers control to the boot sector's code that loads (bootstraps) the operating system into memory. The BIOS also contains handlers for selected hardware interrupts. For example, every time channel 0 of the PCs system board timer produces a clock pulse (it does so approximately 18 times every second), a hardware interrupt is generated that activates a BIOS interrupt handler. The interrupt handler updates the system's software clock and performs other housekeeping chores. Another example: When a key is pressed or released, the BIOS fields the interrupt generated by the keyboard controller and reads a scan code from the keyboard. After converting the scan code into the equivalent ASCII code based on any other keys depressed at the same time (for example, Ctrl, Alt, or Shift) and the current states of NumLock and CapsLock, the interrupt handler stuffs the key code into the keyboard buffer. The BIOS also houses the code that dumps a screen to the printer when the Print Screen key is pressed. Another element that mustn't he excluded from a survey of the BIOS is the PC's Hard Disk Parameter Table. This ROM-based table defines the characteristics (for example, the number of heads, sectors, and cylinders) of all the different hard disks that can be installed in the PC. Generally, adding a hard disk whose properties do not appear in this table requires that you purchase a BIOS upgrade or install a third parry support utility such as Ontrack's Disk Manager. The BIOS Data Area
The 256-byte region of RAM that immediately follows the Interrupt Vector Table and stretches from absolute address 400h to 4FFh is set aside for use by routines in the BIOS. This area is called the BIOS Data Area. Figure 3 lists some of the information the BIOS places there. Programs can inspect memory locations in this region and obtain valuable information about the state of the system. From the byte at 484h, for example, a program can determine how many lines of text are currently displayed on a system equipped with an EGA, VGA, or XGA video adapter. Sometimes it's useful to manipulate data in this region. You can clear the keyboard buffer by reading the word value at 41Ah and poking it into address 41Ch. These locations hold the head and tail addresses of the keyboard buffer, so setting them equal to each other tricks the BIOS into thinking that there are no more key codes awaiting processing. PS/2s set up an additional data area in RAM for the BIOS's use, called the Extended BIOS Data Area. At start-up, the PS/2 POST determines how much conventional memory is installed and cordons, off an area at the very top for the BIOS to use as a scratch pad. The size of this area is normally 1K. However, the designers of the PS/2 made provisions for more. The address of the Extended BIOS Data Area is obtained by placing a call to interrupt 15h function C1h. The first byte in the data area reveals the size of the area in kilobytes, so theoretically, up to 255K could be reserved this way. The PS/2 hides the RAM it sets aside for the BIOS in such a way that the rest of the system doesn't even know the RAM is installed. The ABIOS The Extended BIOS Data Area wasn't the only wrinkle that PS/2s introduced to the BIOS. Most PS/2s actually contain two BIOSes: the CBIOS, a superset of the original IBM BIOS (the C stands for Compatibility), and the ABIOS, or Advanced BIOS, which supports multitasking operating systems such as OS/2. The ABIOS is the protected-made analog to the CBIOS. When OS/2 is run on an AT-class machine, it bypasses the BIOS and interacts with the hardware directly. On a PS/2, however, it relies on functions in the ABIOS. In this respect, the ABIOS (when it is present) plays exactly the same role in a system running OS/2 that a conventional BIOS does in a system running DOS. In the first IBM PC, the BIOS was a mere 8K in length: the PS/2 BIOS now stands at 128K. With this kind of growth, who knows what the nest ten years of BIOS development will bring! |