SERIES I ARTICLE

Know Your 3. The Personal Computer System

S K GhoshQI

This article surveys system software organization in per­ sonal computers, using the IBM personal computer soft­ ware. Details of the hierarchical levels of the system soft­ ware organization are explained.

Introduction Siddhartha Kumar Ghoshal works with An overview of the system software organization of a PC is given whatever goes on inside in Figure 1. BIOS ( input output system) is the lowest level of parallel computers. That the . It hides the details ofthe specific includes hardware, system and projects a higher level interface to the physical hardware. software, algorithms and applications. From his MSDOS ( ), the most common early childhood he has operating system of the IBM PC uses it to run application pro­ designed and built grams. These programs can be written in anyone of a number of electronic gadgets. high-level languages (HLL) such as Pascal, , . Each One of the most recent ones is a sixteen HLL presents the programmer with an abstract view of the processor parallel computer. computer with IBM PC . The complex operations supported by a HLL are implemented by a runtime (RTL) specific to that language. The RTL makes calls to the MSDOS operating system so that various tasks may be performed by the IBM PC hardware and BIOS. Figure' System software of computers are organized· Organization of System Software into Levels in layers like an onion.

Appllcotion progrom Organizing system software into many hierarchical levels or Runtime IIbrory MSDOS layers as shown in Figure 1 gives it the following advantages: BIOS II Hordware II Portability: Programs written using a PC can be moved, com­ piled and run on any other computer.

R-E-S-O-N-A-N-C-E--I-A-p-ri-11-9-9-6------~-~------~ SERIES I ARTICLE

• Scalability: The hardware, software and the used Runtime Library to execute an application program can be upgraded to improved versions without having to rewrite or change the A Runtime Ubrary (RTl) program. comes with every high • Modularity: Any reconfiguration, up gradation or replacement level language . of the software any level does not affect its function, overall It is a collection of large performance or organization. number of subroutines • Easy understanding and documentation: The working of each that perform well-defined program level can be understood and explained without get­ but complex operations. ting into details of other levels. These operaHons are needed by every pro­ The major disadvantages of organizing system software in grammer who uses the layers are: computer by program­ ming it in the particular • Speed of operation. It slows down the application program high-level language in . question. She cannot • The full poten tial of the hardware is not used by an application write each and every de­ program. tail of how that complex operation is to be done We will illustrate these points with a simple example. Consider on that given computer. the program in Figure 2 which is written in the C programming This is because she does language. It stores a number as an integer variable and then prints not know all the details its value in the hexadecimal representation. Note that several and does not have all the advantages are gained by organizing the system software in a time needed to under­ hierarchical fashion on IBM PCs as shown in Figure 1. stand them before she writes and runs her first • This program can be run as an application in any general program. So the compiler purpose computer with a C compiler. implementor supplies a • To port the program from one machine to another one must 'library' of canned pro­ recompile it with a C compiler at the destination site and run grams which our pro­ it thereafter. grammer will need. RTl • The programmer need not understand the display hardware of is written by the compiler the machine, the addresses occupied by it and so ·on. implementor. • The output need not always be displayed. It may be redi­ rected to a disk file or any other device, by the operating system. • The programmer need not have any information on the word

32------~~------R-E-S-O-N-A-N-C-E-I-A-p-r-il-19-9-6 SERIES I ARTICLE

Figure 2 A small C pro­ gram to store a value In a main() variable I and display It on a video display. 1* The following statement stores a hexadecimal number in i */ unsigned int i = 0 x 1234ABCD ; printf (. % x \ n·, i); /* The statement prints the value stored in i */

length of the CPU, the storage of the bytes ofa word in physical memory and other details of the CPU-memory subsystem. • The virtual models of the CPU-memory subsystem and dis­ play devices as seen by a C programmer are adequate to write portable programs. • Anyone who knows C can understand what this program does. Enhancing the CPU -memory and the video display subsystems

does not affect the semantics! of the program. 1 The operation intended to • Anyone writing the operating system and other system soft­ be performed by a computer ware knows how to use the basic commands to run the program program is called its seman­ tics. Unlike human languages, correctly. the semantics of languages and On the other hand, such an organization has the following programs can never be ambig­ disad van tages: uous or ill-defined. The seman­ tics of a • Most of the execution time of the program is spent in the printf must be so straightforward that even a computer (which cannot statement. Although only a write operation is needed for the do anything unless told how to output, the overhead of the printf statement is enormous. That do it and does not normally is because the system call for an output operation passes learn by experience or example) through many levels of the system software. The actual write can carry it out. And to all com­ puters in the world, it must operation to the video memory occurs at the lowest level of the mean the same thing . system software. Between any two levels, a unique and elabo­ rate parameter passing protocol must be followed. All these operations consume CPU time and are calledoverheads. • Even though the video graphics hardware displays millions of shades of colours, the output produced will only be in one colour, the one to which that environment has been set. • The program writes only at the current cursor position in one

-R-ES-O-N-A--N-C-E-I-A-p-r-il-19-9-6------~------33- SERIES I ARTICLE

What is Snowing?

A modern video display adapter has its own spots which appear all over the screen. This ap­ memory (video RAM) and processor (caUed dis­ pears like snow on the screen. BIOS knows many play co-processor). If you write directly into the details of the hardware it controls and makes it video memory, you may interfere with the display appear clothed and more sophisticated.than · it co-processor attempting to read it for producing actually is. 09 not try to control the hardware. let the necessary red, green, blue or composite video BIOS handle it. Even MSOOS gets to the hardware signals. Even though the video RAM has two inde­ via BIOS. look at Figure 1 again. MSOOS in tum pendent read/write ports, the CPU gets a higher has its own of idiosyncracies. So do not talk priority when both display processor and CPU try to MSOOS directly. Ask your RTl to do that. Just to simultaneously access it. As a result, the dis­ write your application in C as I have in Figure 2. It play processor does not get the data it needs will work without your having to know anything from the video memory. It thus goes haywire and about the hardware, BIOS, MSDOS and the RTl of sends the beam aimlessly, illuminating bright the C compiler.

given window, giving the programmer no control over its absolute location on the two-dimensional video screen. • The program uses only the default font type and size. This occurs despite the capacity of the display hardware and driver system for supporting various font types and sizes.

The moment one tries to alleviate these difficulties by writing directly into the video memory or directly programming the display controller hardware, the program loses its portability. Thereafter it remains tied to that specific configuration of the video display hardware. One of the advantages of organising system In the context of Figure 1, let us see how the program given in software in a Figure 2 is executed. hierarchical fashion is that the programmer • The application program of Figure 2 calls the function print[. need not understand The program to carry out printf is in the runtime library file the display hardware that comes along with the C compiler. The parameters sup­ of the machine, the plied to printf are the 32-bit integer which is a number(in our address occupied by it case Ox 1234ABCD) and the print format (in our case % x). and so on. • The runtime library converts the data to be printed into an

------~------­ 34 RESONANCE I April1996 SERIES I ARTICLE

Beware of.Turbochorging

Many compilers produce a code that directly modi­ such compilers runs much faster than the ones fies som~ internal .data ' structures of low-level produced by portable compilers but has no guar­ operating systems and writes intc> device control antees. Any upgrade or replacement to the sys­ registers directly. In other words, the runtime tem at any of the levels shown in Figure I may libraries of such compUers. directly call BIOS (the render an old and useful turbocharged code un­ BIOS call·can be nonstandard and undocumented) able to work. Invest your money and ideas on or initialize hardware, bypassing intermediate portable compilers. CPUs rapidly get faster over levels of system software. This is called super­ the years. The temporary gain in speed from charging or turbocharging.The implementors of turbocharging today may be obviated in a couple soch comp:Uers have inside knowledge of the IBM of years by upgrading. You also risk becoming PC architecture an9 BIOS from s.ources that are obsolete in a couple of years if you turbocharge not always open. The produced by your code.

ASCII string. It then calls the operating system to print the string. In the IBM PC and MSDOS environment, it makes

a function call 09 and a system call to the service routine of Instructions to obtain INT 2lR which is part of the code text of the MSDOS services of BIOS and operating system. MSDOS • MSDOS determines how to perform the output operation. At

this stage, it can redirect the output to an open file. In case the MSDOS is accessed output has to be written on the video display device, it calls through the software in­ BIOS by making a system call to the service routine of INT terrupt instruction. There lOR with a function code to display a character at the current are eight different DOS cursor position. Typically, it makes as many BIOS calls as interrupts. One of these, there are characters in the string to be displayed. INT 21H, implements 87 • BIOS knows the type of the display adapter, the memory different functions which addresses of the video RAM and the I/O port addresses of the are referred to as the DOS video controller. Its internal data structure gives the mode in function calls. BIOS is which the video adapter is initialized; so it knows when to also entered using an scroll the display, perform a carriage return and line feed the interrupt. INT 10H is used cursor. Scrolling is done either by physically moving data in to enter video-10 routines the video RAM by using the CPU, or by setting an appropriate and use the display of page register in the video display adapter. BIOS can therefore the IBM PC. handle the ASCII codes of carriage return and line feed char-

R-E-S-O-N-A-N-C-E--I-A-p-ri-11-9-9-6------~------~- SERIES I ARTICLE

Interrupts

Events other than branch and subroutine call rupts, Motorola and the MIPS computer corpora­ instructions which alter the normal sequential tion call them exceptions, and DEC calls interrup­ flow in a program are called interrupts. Four major tions caused by system calls and error conditions types are: requests for attention by I/O devices, traps. Whenever exceptions/interrupts occur the invoking operating system service from a user current program is suspended and the control program ( service call) and errors such as arith­ jumps to service the interrupt. The current state metic overflow/underflow using undefined instruc­ of the CPU is saved so that the program can tion. There is no uniform terminology to describe later resume from the point where it was sus­ these events. IBM and call all of them inter- pended.

acters if they appear in the string to be displayed. • The text of BIOS is in the EPROM. It writes directly into the video memory producing the desired display.

Similar mechanisms exist in other computer architectures and

Address for correspondence operating system organizations. BIOS is simpler to understand S KGhoshal, than some of them. Supercomputer Education and Research Centre, In subsequent articles we will learn more about the system Indian Institute of SCience, Bangalore 560 012, India. software of the IBM PC. Feel free to write to me if you have any questions or comments about this article.

[EJl Optical illusions ...

-36------~------­ RESONANCE I April1996