Basic Input-Output Services and the System Bus

Basic Input-Output Services and the System Bus

A key concept for this discussion is the bus. So, just what is a bus? In computer terms, it has a similar meaning as your local county public transit, as it is used to move something from one place to another. The county transit bus moves people; a computer bus moves information.

The information is transmitted along the bus as electric signals. If you have ever opened up a computer, you probably saw that there is one central printed circuit board with the CPU, the expansion cards, and several chips sticking out of it. The electronic connections between these parts is referred to as a bus.

The signals that move along a computer bus comes in two basic forms: control and data. Control signals do just that: they control things. Data signals are just that: data. I will get to how this happens and what each part does as we move along.

In todays PC computer market, there are several buses, many of which have the same functions but approach things quite differently. In this section, I am going to talk about the different bus types, what goes on between the different devices on the bus, and what the main components are that communicate along the bus.

Despite differences in bus types, certain aspects of the hardware are common among all PCs. The Basic Input Output System (BIOS), interrupts, Direct Memory Access channels, and base addresses are just a few. Although once the kernel is loaded, Linux almost never needs the system BIOS. However, understanding the function and purpose of the BIOS is useful in understanding the process that the computer goes through when booting. That is, from the time you hit the power switch to when Linux has full control of the hardware.

The BIOS is the mechanism DOS uses to access the hardware. DOS (or a DOS application) makes BIOS calls that then transfer the data to and from the devices. Except for the first few moments of the boot process and the last moment of a shutdown, Linux may never use it again.

Because the BIOS can actually perform certains functions and does not simply provide information, it is common to think of the BIOS as a set of small programs which carry out the necessary functions. Although very limited in scope, one might also consider it sort of a “mini” operating system. It is important to note that in modern computers, you will find a BIOS in places other than just on the motherboard. For example, it is very common to have disk controllers and even graphic cards with their own BIOS.

When PCs first started becoming commonplace, users typically had to set the BIOS clock when the computer was first set up. Often there was was battery that powered an internal clock which kept track of time when the computer was turned off. Still, it was occassionally necessary to reset the system time on this “real-time” clock when the system rebooted.

When Linux first boots, it checks the time of the hardware clock and then calls an internal function at regular intervals which updates the system time accordingly. It is interesting to note that the system clock update mechanism has a very low priority. Therefore, it is common on busy system, that updates are skipped in favor of processes with a high priority. The result is that the time might “drift” by a few minutes. This means that the system clock and hardware clock differ. Eventually Linux started included the hwclock command, which is used to query and change the hardware clock. One addtional problem is the fact that the BIOS cannot handle changes due to daylight savings time or differences in time zone.

To overcome both the drift and differences with the hardward clock. you can implement the Network Time Protocol (NTP). This allows you to synchronize your system time with a more accurate clock. This can be a specific machine within your own network or you can update from public servers connected to the internet.

The standard BIOS for PCs is the IBM BIOS, but that’s simply because “PC” is an IBM standard. However, “standard” does not mean “most common,” as there are several other BIOS vendors, such as Phoenix and AMI.

DOS or a DOS application makes device independent calls to the BIOS to transfer data. The BIOS then translates this into device dependent instructions. For example, DOS (or the application) requests that the hard disk read a certain block of data. The application does not care what kind of hard disk hardware there is, nor should it. It is the BIOS’s job to make that translation to something the specific hard disk can understand.

In Linux, on the other hand, a special program called a device driver handles the functions of the BIOS. As we talked about in the section on the kernel, device drivers are sets of routines that directly access the hardware, just as the BIOS does.

The fact that Linux by-passes the BIOS and goes directly to the hardware is one reason why some hardware will work under DOS but not under Linux. In some instances, the BIOS has been specially designed for the machine on which it runs. Because of this, it can speak the same dialect of “machine language” that the rest of the hardware speaks. However, because UNIX does not speak the same dialect, things get lost in the translation.

The Intel 80×86 family of processors has an I/O space that is distinct from memory space. What this means is that memory (or RAM) is treated differently than I/O. Other machine architectures, such as the Motorola 68000 family, see accessing memory and I/O as the same thing. Although the addresses for I/O devices appears as “normal” memory addresses and the CPU is performing a read or write as it would to RAM, the result is completely different.

When accessing memory, either for a read or write, the CPU utilizes the same address and data lines as it does when accessing RAM. The difference lies in the M/IO# line on the CPU. For those not familiar with digital electronics, this can also be described as the “Memory/Not IO” line. That is, if the line is high (there is a signal on the line), the CPU addresses memory. If it is low (no signal), it addresses an I/O device.

Although the Linux operating system is much different from DOS, it still must access the hardware in the same fashion. There are assembly language instructions that allow an operating system (or any program for that matter) to access the hardware correctly. By passing these commands the base address of the I/O device, the CPU knows to keep the M/IO# line low and therefore access the device and not memory.

You can often see the base address of each device on the system when you boot. The hardware screen shows you the devices it recognizes along with certain values such as the base address, the interrupt vector, and the DMA channel. You can also see this same information by looking in the /var/log/messages and several files in the /proc file system.

If your motherboard only uses 10 address lines, devices on the motherboard that have an I/O address (such as the DMA controller and PIC) will appear at their normal address, as well as at “image” addresses. This is because the higher 6 bits are ignored, so any 16-bit address in which the lower 10 bits match will show up as an “image” address. Because 6 bits are ignored, there are 63 possible “image” addresses (64 minus the one for the “real” address).

These image addresses may cause conflicts with hardware that have I/O addresses higher than 0x3FF (1023), which is the highest possible with only 10 address lines. Therefore, if your motherboard only has 10 bits of I/O addresses, you shouldn’t put devices at addresses higher than 0x3FF.

When you install, it is vital that no two devices have overlapping (or identical) base addresses. Though you can share interrupts and DMA channels on some machines, you can never share base addresses. If you attempt to read a device that has an overlapping base address, you may get information from both devices.

If you are installing a board whose default base address is the same as the one already on the system, you must change one address before they both will work. Additionally, you are almost always asked for the base address of a card when you install it. Therefore, you will need to keep track of address. See the section on troubleshooting for tips on maintaining a notebook with this kind of information.

Note that with current (2009) hardware most of these issues with interrupts, DMA channels and base addresses is becoming moot. Most cards today are either PCI or something even more advanced so it is no longer necessary to set anything on the cards yourself. The system does it all for you!

The table below contains a list of the more common devices and the base address ranges that they use.

Table – Common Hex Addresses

HexRange

Device

000-0ff

Motherboard devices (DMA Controller, PIC, timer chip, etc.)

1f0-1f8

Fixed disk controller (WD10xx)

278-27f

Parallel port 2

2f8-2ff

Serial port 2

378-37f

Parallel port 1

3bc-3bf

Monochrome display and parallel port 2

3c0-3cf

EGA or VGA adapter

3d0-3df

CGA, EGA, or VGA adapter

3f0-3f7

Floppy disk controller

3f8-3ff

Serial port 1

One common BIOS feature is the ability to set one or more passwords. For example, you can set a user password which prevents the sytem from booting if the correct password is not provided. You can also set a system or admin password, which prevents unauthorized users from changing the configuration. When my kids were growing up I would set a BIOS password to keep them from playing too many video games. However, in my experience restricting physical access to the machine provides more security than a BIOS password as anyone who manages to walk away with the computer can find all sorts of information on the Internet for overcoming BIOS passwords.

Although universal, some new computers can detect configuration changes, including adding or removing hardware. When the system detects new hardware during the boot processes, the BIOS may prompt the user to acknowledge the addition or removal of the hardware. For example, by pressing the the F1 or some other key. In some cases, if the BIOS is password protected, the user must input the appropriate password to continue.

The BIOS is also responsible for the Power-On Self Test (POST). As the name implies, a test is carried out when the system is powered on . Various type of hardware are checked to see if they exiss and if so, a diagnostic test is carried out. By default the extent of such tests is limited, but modern BIOSes typically have more detailed diagnostic tests, but these need to be enabled manually. Generally, these are only necessary if you suspect a hardware problem and can take several minutes to complete. Should either type of test find an error this is referred to an “Irregular POST Condition“, which may be displayed on the screen or the BIOS will genereate a series of beeps. What the pattern of beeps mean is found in the manual for the respective motherboard. Note that these patterns will differer even among motherboards from the same manufacturer. Therefore, if you are relying on these to diagnose a problem, be sure you have interpreted them correctly for your specific motherboard.

In addition to the POST, the BIOS also serves as an interface to a special memory that stores various hardware settings. This memory is call the Complementary Metal Oxide Semiconductor) memory or simply CMOS. Although the CMOS is volatile memory, your motherboad is provided with a battery that allows the CMOS to keeps its settings for years. However, like all batteries, it will eventually die and will need to be replaced. The most common symptom is that hardware settings are lost when the system is powered down. I have also seen some cases where the settings are different but not the default.

Among the information the CMOS may contain is the date, whether specific on-board hardware is enabled or not, and the boot order of various devices. This last one I feel is very important to keep track of. It is possible that your system allows you boot from floppy, hard disk, CD/DVD, USB, and even from a network device. If you have multiple devices of the same type, you may have even more options. One common configuration is first floppy, then CD/DVD then the first hard disk. If there is no floppy, this might appear at the end of the list of be disabled entirely. If you are trying to boot from a CD/DVD, but your hard disk comes first in the boot order, the system logically will always attempt to boot from the hard disk first and if there is a bootable operating system, that is what is booted. If you have multiple hard disks it is possible that only the second one is bootable, but appears lower in the list. You then get an error when your try to boot from the first hard disk (for example “No oerating system found”). Some more modern BIOSes have an option whereby you press a certain button at boot-time (e.g. F12) and you are brought to a boot menu where you can select the boot device. This only applies for the current boot processes and the order is not stored in the CMOS.

Using the same battery as the one which keeps the configuration Information, a so-called “real-time” clock runs continually and is ofter used to set and maintain the clock the operating system uses. On the other hand, many operating systems like Linux and other UNIX-variants maintain the system time using >interrupts. For example, there are 100 clock interrupts per second and the system clock is incremented by 1 second after 100 such interrupts. The problem here is that the clock interrupt has a low priority and on a busy system, it is possible that clock interrupts are ingored until the next one. If for example, this happens 10 times a second, it will actually take 110/100 second to count 100 interrupts and thus add 1 second to the systme clock. This means that over time, the system clock is behind the real time. To address this problem, many operating systems (including Linux) use the Network Time Protocol (NTP) which reads the currents from a central server at regular intervals. Although the time can still drift, it is regularly corrected and is usually not noticed by normal users.

In recent years, Intel along with a number of other hardware manufacturer developed a new standard called the Extensible Firmware Interface (EFI). The EFI provides the same kind of functions as the BIOS, but does so in a completely different manner, as well as addresses limitation of the BIOS (e.g. 16-bit processor mode, 1 MB address space, and so forth.)

Most of the information stored in the system BIOS and well as other hardware can be found in the /proc directory. (/sys on newer systems) You can get details about this in the section Finding Out About Your System.

Hard disks:

Originally the BIOS used Interrupt (INT) 13h as the interface to the hard disk. This mechanism had a limitation of 1024 cylinders, 256 heads and 64 sectors per track for a total of 8 GB. However, the original IDE specification has different limits: 65536 cylinders, 16 heads and 255 sectors per track. Since the smallest maximum value needs to be used, this works out to a maximum disk size of 504 MB. Because this depends on the cylinders, heads and sector, it is referred as the CHS specification and diskspace is calculated so:

cylinders * heads * sectors per track * 512 bytes per sector = capacity

The first method to get around this was problem was called Extended Cylinders Heads Sectors (ECHS). Typically you will see this in the BIOS as “Large Mode”, and is essentially a translation between the BIOS and INT13h. When activated, Large Mode takes the number of cylinders on the drive and calculates a “best fit” into the 1024 cylinders of INT13h by dividing the number of cylinders by a mulitple of 2 in order to get below 1024 cylinders. The number of heads is then mulitple by that same number. For example, if our disk has 4680 cylinders. In order to get this under 1024, we need to divide by 8, which gives us 585 cylinders which is then what the BIOS sees. Assuming the drive has 16 heades, we multiple 16 by 8 to get 128 heads.

One interesting and important aspect is that the IDE specification only supports up to 16 heads. This is not problem because the translation passes corrected geometry to the drive.

Eventually drives grew beyond the 8.4GB limitation of INT13h, so there was no way to define a translation that worked. The solution was Logical Block Addressing (LBA) which has actually become the most common way of getting around the 528MB limitation of IDE/ATA drives. This is another type of transation and works by simply assigning each block a number starting a 0.

Modern operating system are no longer bothered with this problem anymore because the bypass the BIOS completely. Instead, they access the hardware directly and are not restricted by a limitaiton in the BIOS.

Much (if not most) of how your hardware is configured can be found by looking through the files in /proc directpry.

    /proc/devices – Major number /proc/dma – DMA Channels /proc/interrupts – Interrupts /proc/ioports – IO Ports