An Assignment On BIOS & CMOS

You have probably already heard about the BIOS and it surely told you that it was something that was used to start your computer? Well, it is now time to move on to the serious stuff: this tutorial will explain and detail a bit more the role of the BIOS in a computer and its operation. Surely, you know that in a computer, there are several components (processor, RAM memory…). These components are all installed on an electronic card that is responsible to communicate with each other and called the motherboard. Among all these essential components, each computer contains at least a memory ROM on a program (a computer without a program would be really unnecessary): BIOS.

This is a small program that launches at startup of the computer and whose role is to :

  • dealing with the management of certain devices
  • do what it takes to turn on the computer
  • to start an operating system on a mass memory
  • Formerly, the BIOS was stored in a ROM memory placed on the motherboard. Nowadays, we prefer to use EEPROM (often of flash) memory to store it. We can replace the programme contained in the BIOS EEPROM memory by another: this is called Flash BIOS.

    A bit of computer archaeology
    Our BIOS has as its primary function to support part of the materiel management and to provide some minimum hardware abstractions to the operating system and the user. For simplicity, small programs has been incorporated in our BIOS whose role was to manage a portion of the material present on the motherboard. These programs have been standardized so as to ensure the compatibility of programs using these routines on all existing BIOS. It is not for nothing that “BIOS” stands for Basic Input Output Software, which means “basic entry program output −.

    Reminder on interruptions
    To communicate with the hardware, the BIOS uses features of our processor called interrupts. This is a feature of our processor which allows to temporarily stop the execution of a program to run another. Using interrupts in some specific cases, which require treatment cannot wait too long: communicate with one or more devices, for example. Thus, to communicate with a graphics card, hard drive, or keyboard, our BIOS must use traps. These are designed to interrupt the execution of a program in response to an external event (hardware, fatal error to run a program…) and to treat in a timely manner, before hand to the interrupted program. Our interruption will therefore do little processing (here, communicating with a device). This processing is performed by a small program which was given a technical name: interrupt routine.

    When a processor needs to execute an interrupt, it:

  • stops the execution of the current program
  • executes the interrupt routine
  • resumes execution of the suspended program where she was
  • There are three ways to trigger an interruption:

  • a special statement of the processor
  • exceptions, which occur automatically when the processor encounters an error (e.g. a division by zero)
  • interrupt requests, that are triggered by an event of material origin
  • As you can see, the interrupts can not only be called by a program, thanks to the statement int, but they also allow to respond to purely material events, such as the support of a key on the keyboard. As has been said, a break is designed to react to an event, but it is before a whole program, which can be run like any other program. In our case, these interruptions will be simply regarded as simplistic programs to act on a device. Of course, to the multiplicity of devices, one suspects well that there is no interruption to do everything: it goes without saying that a program sending an order to the hard disk will be different from a program acting on a graphics card. In each case, we will need a different treatment, it must therefore have several interrupt routines. In the case of our BIOS, it provides many basic routines to communicate with devices on our computer.

    Interrupt vector
    However, it must decide what is the interruption to run depending on the situation. For example, run the keyboard handling interruption while we wish to communicate with our hard drive would produce a rather comical outcome. : p therefore, must store many of these routines in his memory. But how to find them? Like other data! To explain this properly, will have to do a little reminder. Our computer’s memory is a vulgar cluster of memory cells, each capable of holding bits; We remind that a bit is information that can take two values: 0 or 1. These cells are grouped in packages of 8, known as memory boxes. These boxes contain no data (or pieces of data: a whole number is often several boxes). To know in which memory box is stored our data, our computer identifies each box by a single number: the memory address. Each routine is then placed in memory at some location, localizable by address, which indicates its location in memory.

    To find the position of our routine and find out which run, some computers use a part of their memory for storing the addresses of all the interrupt routines early. Basically, this portion of memory contains the addresses to locate each routine. This amount of memory is called the interrupt vector. For each interruption, a fixed portion of memory contains the beginning address of the interruption to perform. For those who know a little programming, you can see this interrupt vector as an array of pointers to function, functions are routines to run. The BIOS initializes the interrupt at startup of the computer vector and provides some basic materiel management interruptions. However, the operating system can provide its own routines. So that they are carried out, just to the OS to divert the interruption. This is to replace the address of abortion contained in the interrupt vector by the address of the routine that the OS has loaded in memory (of course, the old address is saved).
    Clearly, the interrupt vector would contain the address used to locate the BIOS routine, but that locating the OS routine.

    BIOS interrupt routines
    The BIOS provides basis a large number of pre-programmed interrupt routines. For example, these routines can be executed when you press a key on the keyboard, or when information from the mouse is available on PS/2 port. Nowadays (from Windows 95), once the operating system has been loaded, these routines can be used by operating systems kernels, and a few pilots. For those who don’t know, once loaded operating system, the memory of a computer x 86 (architecture 32 bits, which means that we can load 32 bits of data at the same time) is cut into at least two servings, two main:

  • a party in which any program that appears can manage devices and perform advanced on memory manipulations: space kernel
  • another for programs that must not manipulate devices or make advanced memory manipulations: user space
  • Our routines are then accessed by a program located in user space. Only programs located in kernel space have the right to access the hardware. Only a part of the operating system, named core containing a few drivers, is placed into kernel space and so can run BIOS routines if necessary. But be careful: This applies once the operating system is loaded (in fact, once the processor spends real mode where everything is permitted in protected mode where some operations are restricted). Before, memory is managed otherwise, and there is no distinction between kernel space and user space, which allows the BIOS to run freely.

    The BIOS routines, or even the entirety of its content, were sometimes copied in the RAM in order to make their faster performance, at the time where they were used again (MS-DOS). The RAM is much faster than the ROM (EEP) in which the BIOS is stored. Some options of BIOS, often named BIOS memory shadowing (or other similar names), can precisely copy the BIOS in a part of the RAM memory in order to accelerate the execution of its routines. Be aware that this kind of thing is unnecessary since the BIOS is more than used to turn on the computer. We will list some important routines. In what follows, the address will be the address stored in the said routine interrupt vector (reread several times if necessary). It will however be vigilant: the vast majority of these interruptions is hijacked by our operating system, and is used only when the turn on the computer. In fact, as soon as there is a driver for a device, you should be aware that the BIOS routines are completely diverted by your OS. A large part of these routines require that they be provided settings, information for them to do what they need to do. For example, a routine to display a letter on the screen will require they give him input the letter to display. For each routine, simply copy these settings from memory to small high-speed memory embedded in the processor called registers. Each of these has a name that allows to identify it: AX, AH, AL… For each routine, each register will contain a data with a specific meaning for our routine. This will often be registers AH or AL of the processor. In what follows, we’ll list a few routines to show a little usefulness. It will appoint these routines.

    Each routine is identified by:

  • id INT, which is used to specify you want to run a break
  • registers, used to configure our routine
  • a number that identifies the routine to run
  • Indeed, our routines are numbered. But be careful: this number is a hexadecimal number! Clearly, INT 10 is not the tenth interrupt, but the sixteenth. For those who know not the hexadecimal, worry, you will be able to understand the suite without problem.

    INT 10 h: display
    Our current graphics cards all contain a ROM memory (or EEPROM) containing itself the heap routines able to display text and monochrome graphics or 256 colors on the screen. In the graphic cards compatible with VGA/ESA, this firmware formats (program embedded in the component – BIOS is a firmware), mistakenly called BIOS video, is located in the address space to addresses 000b 0000 or 1,000th 0000. When start the computer, it is these routines that are used to manage the display until the operating system launches the graphics drivers. These functions are extremely Basic, what makes the graphics displayed on the screen have this aspect so characteristic, ugly, reminiscent of the computer of the 1950s…

    But be careful: Once the pilot started graphics card, these basic functions are; the operating system, the video driver and launched programs manage themselves such things and divert shamelessly interruptions they want.

    If no video ROM is detected, the BIOS can still communicate directly with the graphics card through a routine that he owns. This routine has many different functions, and can as well send a character to the screen that return the position of the cursor. To specify the processing to be carried out, must place a certain value in register AH processor: the routine is programmed to deduce the treatment only to be based on the value of the register AH.

    INT 11 h
    This routine returns a 16-bit number containing information on some devices on the computer.

    INT 12 h
    This routine takes no parameters and returns the size of the memory in kilobytes in the AX register.

    INT 13 h: mass storage
    A routine of the BIOS allows to read or write to the disk on a floppy disk or hard. This routine helps him read the first bytes of a hard disk in order to load the operating system, but we’ll see this in the following chapter. As the routine INT 10, it is versatile and should specify the processing to be carried out by putting the register AH to a unique value for each treatment. This routine was used by the MS-DOS style operating systems to read or write to the hard disk. But this belongs in the history, and the current OS no longer hesitate to divert these interruptions to provide much more effective methods of disk management.

    INT 14 h: serial port
    This interruption was used to communicate with our computer RS232 serial port. Like the others, it is configured with a value in the registry AH.

    INT 15 h: advanced system functions
    This interruption has functions and varied, all more or less attached to the equipment management. The BIOS was once in charge of the management of our computer’s power: he transferred the sleep, reduce the frequency of the processor, turn off unused devices. To do this, the routine INT 15 was used. Its energy management functions were still used until the creation of Windows 95. Today, with the arrival of the ACPI standard, the operating system handles all alone our computer energy management and this routine is therefore obsolete. Any rule must be an exception: this routine is used by modern operating systems at startup in order to obtain a correct description and precise of the Organization of the computer’s memory. To do this, our bones configure this routine by placing the 0x0000e820 value in the EAX register. It is one of very rare exceptions to the rule: the BIOS routines are obsolete.

    INT 16 h: keyboard
    Our keyboard communicates with our computer by sending three kinds of signals, that determine what the user did with his keyboard. Each of these signals generates an interruption, which will be performed by the appropriate routine.

    Three main messages are used:

  • KeyDown: signal specifying that pressed a button
  • KeyUp: signal specifying that it has released a touch
  • And Repeated key, which specifies that the key on the keyboard is remained inserted since the last message is sent
  • This message is used when you continuously press a button without releasing it. Each of these specifies the key in question, obviously. This routine allows to manage a part of the keyboard, and often to configure. As the routine INT 10, it is very versatile and can perform many treatments: specify adequate treatment by putting the register AH at a certain value. This routine is used so that the operating system has not started, that is why you can use the keyboard to navigate in your BIOS Setup screen. On the other hand, no standard routine allows communication with the mouse: it is impossible to use the mouse in most BIOS. Some BIOS have nevertheless routines can handle the mouse, but they are very rare. Yet once, these routines were diverted by the operating system to its launch.

    INT 17 h: parallel port
    This routine to communicate with a printer to the parallel port of the computer. Like the others, it configures it with the register AH.

    As you can see, the BIOS provides many routines that were initially intended to facilitate the management of materiel. Long ago, this simplified the design of operating systems and multiple bones, such as MS-DOS, using these functions. But nowadays, knowing these things is more synonymous with experimental archaeology than anything else.

    Start a computer x 86
    As I said above, the BIOS is used also to turn on the computer and configure it properly before leaving the hand in the operating system. This phase is called the Power On Self Test, commonly called POST. During this phase, the devices are detected, tested and configured to ensure their functioning. The first element verified during the POST (Power On Self Test) is the stability of the computer’s power supply. The BIOS tests voltages 12 volt, 5 volt and 3.3 volt, and continues execution only if they are stable and good value. If the supply voltages are not stable or are not good value, BIOS stops immediately starts, to avoid damaging the processor and other components of the computer. Then, the BIOS checks the stability of the clock and some other components: the first 64 kilobytes of memory, for example.

    Next step: Initialize interrupt vector of our computer with its default values, provided by the BIOS. If the interrupt vector is written without error in RAM, BIOS beeps small, to indicate that all is well. Indeed, a buzzer is placed on the motherboard and is directly controllable by the processor. At the slightest problem in the ignition, the processor asked this beep buzzer. Depending on the error, the series of beeps emitted will be different, in order to identify the error easily. Attention, however: the series of beeps has not been standardized by BIOS manufacturers. Each manufacturer has its own way to beep the buzzer in case of error. Then, the keyboard and the video card will be configured by the routines above. To detect the presence of a video VGA/ESA card, BIOS viewing memory 0x000C 0000 and 0000 0x000E addresses: these are the addresses of a ROM memory, integrated graphics card, which contains all the basic functions used to display graphics on the screen. If everything works well, the BIOS will then request the display of a message on the screen. If a problem occurs during this test phase, the BIOS will beep. As a result of the POST and after detected devices communicating with different bus system, our BIOS will look for which may contain an operating system that it can load.

    It fell on a bone!
    In older computers, the only program that could run the computer was a simple program stored in a ROM But with the emergence of more sophisticated computers, it has made possible exploitation by a computer of different programs that placed in its ROM The invention of operating systems was a step more in this direction, but it was necessary to find a way to boot the computer to load an operating system from one memory other than the ROM on the motherboard. In all computers, the operating system is placed on the hard disk, the motherboard has then no way to load the operating system directly from the harddisk in RAM so it can run. To resolve this problem, let the BIOS.

    Reminders on the hard disk
    As you all know, a hard disk is a device used to store data on a permanent basis: the data on a hard disk do not go away when cutting the power. This hard drive is composed of several trays, manufactured in a magnetic material and on which data is recorded. Our hard disk is divided into small blocks of data, each able to hold a bit, on aimantera in one direction to store a 1 and the other way to store a 0.

    Cylinders, heads and sectors
    A hard disk contains many of these plates. But we must know a little how each tray is organized before continuing. I spoke earlier of these cells capable of storing one bit. well, be aware that many of these bits, belonging to different trays, are stacked one above the other. That forms what is called a cylinder. For possessing hard drive n cylinders, these are numbered from 0 to n−1. The same stage cells are grouped into packages of hundreds of bits which follow the next to each other: the sectors. To simplify the work of the HDD electronics, we prefer to use packets with a size of the form 2n. On current hard drives, a sector has a size of 512 bytes, or 4096 bits. These sectors are numbered starting at 1. Our hard disk also contains small mobile devices able to read or write data on the hard disk: read heads − writing, with a head of reading per tray. A hard drive has several. For a disk hard containing n − write heads, on numbers them from 0 to n−1.

    CHS addressing
    To locate a sector on a hard disk, simply specify the number of the cylinder, the sector and the playhead (to clarify the good plateau). This way to a sector of the hard disk is called the CHS addressing. The only problem with this address, it is that the BIOS uses 10 bits to encode the cylinder number, 8 bits for the head (sometimes 4) number and 6 bits for the sector number, which limit the size maximum possible from the hard drive to about 500 megabytes. To counter this limit and so the BIOS detects the drives with the right size at startup, we have invented various tricks. One of these tricks is to transform the CHS coordinates encoded 24 bit (10 bits for the cylinder + 8 for head number + number of sector 6) 28-bit coordinates. For this, hard disk management routines have been modified to achieve these translations of coordinates, which pushed the limit of size of approximately 8 gigabytes hard drives. Finally, before the progression of the size of the hard drives were invented LBA addressing. The numbers simply every sector of the hard disk by number, without worrying about its head and cylinder number or sector. It is therefore identified by a single number: the logical address, which can be translated by the BIOS or the integrated electronics in the hard disk in an encrypted mode CHS address on enough bits. Our BIOS can use different types of address depending on the motherboard and some can use several (also although CHS than LBA, for example). In fact, the standard INT 13 routine manipulates CHS coordinates, but one can perfectly find other additional routines that work with coordinates LBA. Some are not standardized, but others are: these include the Enhanced Disk Drive.

    The MBR, short for Master Boot Record, is the name given to the first sector of the hard disk (as well in addressing LBA and CHS addressing). Its CHS coordinates are (0, 0, 1). It is in this MBR that all information necessary for the start-up of an operating system are placed. This MBR is pretty well organized and contains three major parts to different uses.

    Executable code
    The first bytes of the MBR are completed by a program used to load the operating system. These are loaded at the end of the POST, by the routine INT 19 h, which copies the first sector in the RAM memory at address 0x7C00. This routine then configures the CPU by placing the base address of the code in memory (our famous 0x7C00) in the instruction pointer (IP) E of the registry, which allows to run this program and so launching the OS. However, there is still a condition to this: at the end of the MBR, the last two bytes must be a specific value for the BIOS allows the implementation of this programme. This value, called the magic number is worth 0xAA55, which equals 43 605 in decimal. But the result is still prettier in binary: 1010101001010101. ;). This program is followed by some optional, often empty bytes, followed by the partition table. The program itself is 440 bytes.

    Partition table
    The partition table contains information about the various partitions installed on the hard disk: their ‘name’, their size and their location on the hard disk. Each row in a partition table contains the beginning of a partition and its size CHS address. You can create four rows in this table, it is therefore limited to four primary partitions. It must be said that this table is only 64 bytes (it was designed like this).

    Error messages
    There is finally an area containing error messages to display in case the launch of the operating system would fail. For example, the missing NTDLR error message is stored in this area.

    CMOS RAM and other
    You must have noticed that our computer is able to retain the date, and even unplugged? Well our BIOS has a small report with that!

    In a computer, and everything electronic component capable to retain a time or a date, there is a memory capable of holding the date and time. But this is not enough: should that time do not shifts, and for this, we must continue to count, even when the computer is unplugged. Therefore need us a circuit capable of starting, which is incremented cyclically whenever a specific time has elapsed. Finally, also need us a source of energy which replaces the AC power when the computer is unplugged, for these circuits. This energy source is almost always a lithium battery installed on the motherboard.

    To recap, therefore need us to:

  • a clock to synchronize components
  • a counter, which is a circuit with one one to each clock ICT (or several tics clock, it is according to)
  • a memory capable of storing the date and time, which are updated as required (date, time…)
    and a battery to power the whole.