Exploring The ROM BIOS

Source: PC Magazine, 25 Jun 1991. Original HERE.
Author: Jeff Prosise
Converted to HTML by Louis Ohland. Edited by Major Tom.

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:

  • Video services (interrupt 10h)
  • Disk services (interrupt 13h)
  • Serial port services (interrupt 14h)
  • System services (interrupt 15h)
  • Keyboard services (interrupt 16h)
  • Parallel printer service. (interrupt 17h)
  • Time and date services (interrupt 1Ah)

Fn. 00hSet video mode
Fn. 01hSet cursor type
Fn. 02hSet cursor position
Fn. 03hRead cursor position
Fn. 04hRead light pen position
Fn. 05hSelect active video page
Fn. 06hScroll active video page up
Fn. 07hScroll active video page down
Fn. 08hRead character and attribute
Fn. 09hWrite character and attribute
Fn. 0AhWrite character only
Fn. 0BhSet color palette
Fn. 0ChWrite dot (pixel)
Fn. 0DhRead dot (pixel)
Fn. 0EhWrite teletype
Fn. 0FhGet video parameters
Fn. 10hSet palette registers
Fn. 11hProgram character generator
Fn. 12hAlternate select (misc. EGA(MCGANGA video services)
Fn. 13hWrite string

Fn. 00hReset disk
Fn. 01hRead status of last operation
Fn. 02hRead sector or sectors
Fn. 03hWrite sector or sectors
Fn. 04hVerity sector or sectors
Fn. 05hFormat track or cylinder
Fn. 06hFormat track or cylinder and set bad sector flags
Fn. 07hFormat disk
Fn. 08hRead drive parameters
Fn. 09hInitialize drive pair characteristics
Fn. 0ChSeek to track or cylinder
Fn. 0DhReset disk (alternate)
Fn. 10hTest for drive ready
Fn. 11hRecalibrate drive
Fn. 15hGet drive type
Fn. 19hPark heads

Fn. 00hInitialize serial port
Fn. 01hTransmit character
Fn. 02hReceive character
Fn. 03hGet serial port status
Fn. 04hInitialize serial port (extended)
Fn. 05hGet or set modern status register
Fn. 00hTurn cassette motor on
Fn. 01hTurn cassette motor off
Fn. 02hRead blocks from cassette
Fn. 03hWrite blocks to cassette
Fn. 4FhIntercept keyboard data
Fn. 85hSysRq key pressed
Fn. 86hPause for specified length of time
Fn. 87hMove a block of data from one location in memory to another in protected mode
Fn. 88hGet size of extended memory
Fn. 89hSwitch CPU to protected mode
Fn. C0hGet system configuration parameters
Fn. C1hGet address of extended BIOS data area
Fn. C2hPS/2 mouse interface
Fn. C3hEnable or disable watchdog time-out
Fn. C4hPS/2 Programmable Option Select interface

Fn. 00hRead keyboard
Fn. 01hGet keyboard buffer status
Fn. 02hGet shift status
Fn. 03hSet typematic and delay rates
Fn. 05hWrite character to keyboard buffer
Fn. 10hRead Enhanced keyboard
Fn. 11hGet Enhanced-keyboard buffer status
Fn. 12hGet Enhanced-keyboard shift status

Fn. 00hPrint character
Fn. 01hInitialize parallel port
Fn. 02hGet parallel port status

Fn. 00hRead system timer
Fn. 01hSet system timer
Fn. 02hRead time
Fn. 03hSet time
Fn. 04hRead date
Fn. 05hSet date
Fn. 06hSet alarm
Fn. 07hReset alarm

Figure 2: Summary of BIOS Services. Routines in the BIOS are accessed via software interrupts - CPU instructions that pass control from the program currently executing to an interrupt hander.

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

400h4 wordsBase I/O address for COM1 through COM4
408h4 wordsBase I/O address for LPT1 through LPT4

410hWordEquipment flags
413hWordMemory size in kilobytes

417hByteKeyboard shift state flags 1
418hByteKeyboard shift state flags 2
419hByteAlternate keypad entry
41AhWordAddress of keyboard buffer head
41ChWordAddress of keyboard buffer tail
41Eh32 bytesKeyboard buffer

43EhByteRecalibrate status
43FhByteMotor status
440hByteMotor off counter
441hByteStatus of last operation
442h7 bytesController status bytes

449hByteCurrent video mode
44AhWordNumber of columns of text displayed
44ChWordLength of regen buffer in bytes
44EhWordOffset address of active display page
450h8 wordsCursor position (video page 0-7)
460hWordCursor type (beginning and ending scan lines)
462hByteActive video page
463hWordCRT controller base address
465hByteCurrent setting of 3x8 register
466hByteCurrent setting of 3x9 register

46ChWordLow word of timer count
46EhWordHigh word of timer count
470hByteTimer rollover indicator

471hByteBreak-key state
472hWordReset flag

474hByteStatus of last operation
475hByteNumber of hard disks attached

478h4 bytesTime-out value for LPT1 through LPT4
47Ch4 bytesTime-out value for COM1 through COM4

480hWordAddress of start of keyboard buffer
482hWordAddress of end of keyboard buffer

484hByteNumber of rows of text displayed minus 1
485hWordHeight of character in scan lines
487hByteMiscellaneous video information
488hByteMiscellaneous video information

Figure 3: The BIOS Data Area. The BIOS Data Area comprises a 256K area of RAM stretching from absolute address 400h to 4FFh.

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 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!

Content created and/or collected by:
Louis Ohland, Peter Wendt, William Walsh, Kevin Bowling, Jim Shorney, Tim Clarke, David Beem, Tatsuo Sunagawa, Tomáš Slavotínek, and many others.

Ardent Tool of Capitalism - MAD Edition! is maintained by Tomáš Slavotínek.
Last update: 12 Jun 2021 - Changes & Credits | Legal Info & Contact