Operating SystemsLecture 2 The BIOS and Boot Process M. Naghibzadeh Reference: M. Naghibzadeh, Operating System Concepts and Techniques, iUniverse publisher, 2005. To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com
The need for BIOS • Main memory, cache, and internal registers of the CPU are usually volatile. The information that is stored in these devices is lost when the computer’s power is turned off. • As soon as the computer is turned on, it starts to perform the fetch-execute cycle over and over again (see Lecture 1). • If there are only volatile memories, there could not be any instruction in the main memory when the computer is turned on. • To overcome this problem, a program is designed and stored in a special memory called Read Only Memory (ROM) and it is installed on the computer’s motherboard. • This program is called Basic Input Output System (BIOS). • As the computer starts or restarts the BIOS address is automatically loaded into the PC register and thus the BIOS starts running. • BIOSes are produced by many factories, but perform the same basic functions.
System BIOS Computer Hardware (Bare Machine) “Layer 0” “Layer 1” Computer as a layered device Figure 1: A computer with a BIOS
BIOS Actions at start/restart • Power-On Self Test • checks to make sure every immediately required device is connected and functional. • BIOS manufacturer’s logo display • Compaq, Phoenix, Intel, IBM, Award plus, or any other manufactures. • CMOS and setup modifications • The Complementary Metal Oxide Semiconductor memory is a battery-supported memory which keeps modifiable information like date, time, computer password…. • Initial section of booting the operating system.
Operating System installation • The OS is a giant program that cannot be stored in a small ROM memory. • In addition, we would like computers to be flexible so that we are able to run any operating system from amongst a list of operating systems. • Therefore, the OS has to be installed after the computer is purchased. • The operating system is usually stored on a CD(s) which are first transferred to a hard disk drive in order to become functional because hard disk drives are much faster than CD drives. • During the transfer other functions, for example decompression, is performed. This process is called OS installation.
Booting the operating system • At any start/restart of the computer, one of the functions of the BIOS is to begin the process of loading the operating system. • The BIOS usually transfers only one block of data from the first valid bootable device to the main memory. • This block of data is taken from a specific and fixed place of the bootable device and is put in a specific and fixed place of main memory. • The size of the block of data is usually 512 bytes and is usually taken from block zero of track zero of the bootable device. • The block contains a small program that is sometimes called bootstrap. • After loading the bootstrap, control is transferred to this little program. By doing so, BIOS disqualifies itself from being the internal owner of the computer. • This little program will complete the boot process, perhaps in more than one phase. • The BIOS will then become a passive program which can be used by the operating system to perform many operations. • BIOS contains many other useful procedures (little programs), especially for interacting with input/output devices.
Kernel • Eventually, essential parts of the operating system will be loaded in main memory. • This includes the Operating system Kernel. • Other parts are usually loaded on demand. • The Kernel is the essential part, or the inner part, of the seed of an operating system. • Kernel is a program that is composed of many routines for doing activities that are not performed by any single machine instruction. • Kernel routines are built using machine instructions and/or BIOS functions. • In addition, kernel is composed of many essential processes (threads or agents), each designed to carry out a responsibility of the operating system.
Other layers of the OS … … OS Kernel System BIOS Computer Hardware (Bare Machine) “Layer 0” “Layer 1” “Layer 2” A Four-layer computer Figure 2: A four-layer machine with system BIOS, kernel, and processes
System Services/User Applications: Service Controller, Remote Procedure Call, C++ Compiler, Environmental Subsystems (Posix, OS/2, Win32), etc. Virtual Memory Manager Process/ Thread Manager Security Reference Manager Windows Manager Input/ Output Manager Cache Manager Device Drivers Windows 2000 Kernel Hardware Abstraction Layer (HAL) Hardware and Hardware Interfaces: Buses, CPU, Main Memory, Cache, I/O Devices, Timers, Clock, Direct Memory Access, Interrupts, Cache Controller, etc. An actual hierarchical OS Figure 3: The structure of Windows 2000
Protection • programs cannot directly and freely use the facilities within the lower layers. • The operating system monitors the activities of every running program. • In the absence of any protection mechanism, strange things could happen and the system could become unreliable. • In a multi-user system, one person’s process (program) can change somebody else’s process, making it do something it shouldn’t. • A process can even modify the operating system itself, hence, making it useless and even harmful to other programs. • The existence and propagation of viruses, worms, Trojan horses, etc. in computers is directly related to the existence of weak security points within the operating system. • Protecting the system from crackers and hackers is a tough job. Many operating system and network researchers are exclusively working to make our systems less vulnerable.
Modes of operations • Every computer has at least two modes of operation: • Kernel mode, or supervisor mode. All machine instructions, whether privileged or non-privileged, are executable in this mode of operation. • User mode. Privileged instructions are not usable. • One of the most remarkable features of any operating system is the way mode transfer is made possible. • During the system startup the system is in kernel mode. • Right after the startup the mode changes to user mode. • When a program calls a routine of the kernel the mode automatically changes to kernel and in return from the routine, the mode changes back to user.
Making Your Own Operating System • It should be clear that with the knowledge we have gathered so far, it is impossible to write an actual operating system. • However, by thinking of making a little operating system lots of questions will be raised, some of which we will talk about in the following lectures. • I would suggest the following steps in writing your own little, do nothing useful, operating system.
Making Your Own Operating System… • Using a running computer, write a mini program to do something over and over again. • I would prefer this program to repeatedly display the word “Hello” on computer monitor. The size of the program is important and its actual machine language size must be less than 512 bytes. This program will be your operating system. To write this program you have to know at least one programming language. Assembly language is preferred, but C or C++ is acceptable. Let’s suppose you will choose to write the program with C. After writing the program, compile it and produce an executable file. • An executable file has two sections: (1) the file header and (2) the actual machine language instructions. The header contains information about the file, e.g., size of the file. Suppose the file header is 512 bytes. Write a mini program to change your executable file into a file without a header by removing the first 512 bytes of the executable file. Let’s assume this file is called a “com” file. • Write a program to transfer the “com” file to sector zero of track zero of a diskette.
Making Your Own Operating System… • A com file is a pure machine instruction program without any attribute sector. • There are numerous file formats and every application program works with certain file formats. For example, MS-Word produces and works with document (doc) files, among many others. • Prepare a diskette. • Transfer the “com” file to sector zero of track zero of the diskette. • You have successfully stored your operating system on the diskette. • Reset the computer and enter the BIOS setup/modify program. Make the first floppy drive be the first bootable device. • Insert your own operating system diskette into the first floppy drive of the computer and reset the computer again. Wait until your operating system comes up.
Summary • The following subjects were discussed • The need for BIOS • BIOS actions • Installing the OS • Booting the OS • Operating system Kernel • Computer as a hierarchical device • Protection • Modes of operation • How to make your own small OS
Find out • Which company has build your computer’s BIOS. • The source code of a BIOS from the Internet. • The complete set of privileged instruction of your computer’s CPU. • A source code for a small OS from the Internet. • How to make the above source code actually work.