Operating System Concepts and Techniques Lecture 1 Background

Operating System Concepts and Techniques Lecture 1 Background: hardware concepts review M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, i. Universe publisher, first ed. 2011. To order: www. iuniverse. com, www. amazon. com, or www. amazon. com

Introduction Computer: a device which runs programs Program: a set of instructions to do a specific task Operating system: an essential program which sits on top of the computer hardware; acts as an interface between the running program and the computer hardware to: n n n Provide basic software modules to be used by programs Facilitate efficient use of computer resources Prevent running programs undesirable interferences 2

Computer Hardware Organization Essential Units are: n n n Control unit, Arithmetic-logic unit, Cache memory, Main memory Other devices w Input/Output devices w Network connectivity n Figure 1 shows essential logical interconnections 3

Logical interconnctions of devices CPU Control Unit Arithmetic-Logic Unit Input Unit Main Memory Output Unit Figure 1: Computer organization model 4

Bus-base connection vs point to point Bus-based reduces interconnection wiring n Similar to a highway via which different parts of a city are connected. There at least three busses, address bus, data bus and control bus Some computer devices are not directly connected to the computer’s internal bus In a 32 -bit computer, for example, the address bus and data bus are each 32 bits wide There are mechanisms for possessing the address and data buses, otherwise data and addresses from different devices could become mixed up A model of the bus-based computer organization is shown in Figure 2. 5

Essential Physical interconnctions of a computer’s devices Central Processing Unit (CPU) Main Memory (MM) Monitor Mouse Control bus Address bus Data bus Hard Disk (HD) Internet Connection . . . Figure 2: A bus-based Computer organization model 6

The Fetch-Execute Cycle Reading an instruction from main memory (RAM) and moving it to the CPU n n Program counter (PC) points to the instruction to be fetched The instruction is moved to Instruction Register (IR) in the Central Processing Unit (CPU) Finding out what has to be done with respect to this instruction and perform the actions, i. e. , microinstructions Repeats this cycle of moving an instruction from the main memory to the CPU and executing it, over and over again. This is called Fetch-Execute Cycle See Figure 3 7

The Details of Fetch-Execute Cycle Fetch cycle Read the instruction pointed out by the Program Counter (PC) register from main memory and move it to the CPU Find out what this instruction is Execute cycle Move the data upon which the instruction has to be executed from main memory to the CPU. Execute the instruction, i. e. , perform what is requested by the instruction. Perhaps this may readjust the PC. Adjust PC for the next instruction Figure 3: A simplified functional model of a computer 8

Program Counter (PC) update How is PC filled? When the computer is started or restarted, it is automatically filled with an initial value by the hardware n The operating system will fill the PC with the first executable instruction of the new program n Otherwise, it is updated through fetch-execute cycle The next instruction to be fetched is most likely the one immediately following this instruction n n However, this is not always the case. Look at the piece of program below that is written in a pseudo code format. 1. If A > B 2. then print A 3. else print B 4. endif Most of the time, the PC update during the fetch cycle suffices n Sometimes, its content is modified by the execution of the instruction 9

How is fetch-excute cycle Brocken? Will find out in Lecture 2 10

BIOS boot process The need for BIOS n n n Main memory, cache, and internal registers are volatile Upon turned on, the computer starts the fetch-execute cycle With volatile memories, at start, there is no instruction in RAM Therefore, BIOS is stored in a Read Only Memory (ROM) n This program is called Basic Input Output System At start or restart, the BIOS address is automatically loaded into the PC thus facilitating its being run BIOSs are produced by many factories, but perform the same basic functions. 11

BIOS Actions at start/restart Power-On Self Test n checks to make sure every immediately required device is connected and functional BIOS manufacturer’s logo display n Compaq, Phoenix, Intel, IBM, Award plus, or any other manufactures CMOS and setup modifications n The Complementary Metal Oxide Semiconductor memory is a battery-supported memory which keeps modifiable information like date, time, computer password… Loading boot strap of the operating system 12

Operating System installation OS is giant and cannot be stored in a ROM In addition, we would like computers to be flexible to run any operating system Therefore, the OS has to be installed after the computer is manufactured During installation, it is transferred from say DVD to the fastest disk drive During the transfer other functions such as decompression and initialization is performed. This process is called OS installation 13

Booting the operating system At any start/restart begin the process of loading the operating system BIOS transfers one block of data from the first valid bootable device to the main memory. n n The block is taken from a fixed place of the (block one of track zero) and is put in a specific and fixed place of main memory (0 x. FC 00) The size of the block of data is usually 512 bytes The block contains General data about the device + the bootstrap program After loading the bootstrap, PC is filled with start of bootstrap This little program will complete the boot process, perhaps by initiating other phases 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, especially for interacting with input/output devices 14

Kernel Eventually, essential parts of the operating system will be loaded in main memory n n n This includes the Operating system Kernel is the essential part, or the inner part, of the seed of an operating system Other parts are usually loaded on demand Kernel is composed of: n n many routines for doing activities that are not be performed by any single machine instruction In addition, kernel is composed of many essential processes (threads or agents), each designed to carry out a responsibility of the operating system Kernel routines are built using machine instructions and/or BIOS functions Kernel is protected 15

Our computer looks like Other layers of the OS OS Kernel System BIOS … Computer Hardware (Bare Machine) “Layer 0” … “Layer 1” “Layer 2” Figure 4: A four-layer machine with system BIOS, kernel, and processes 16

An actual hierarchical OS System Services/User Applications: Service Controller, Remote Procedure Call, C++ Compiler, Environmental Subsystems (Posix, OS/2, Win 32), etc. Input/ Output Manager Virtual Memory Manager Device Drivers Process/ Thread Manager Security Reference Manager Cache Manager 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. Figure 5: The structure of Windows 2000 17

Modes of operations Every computer has at least two modes of operation: n n 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 18

Making Your Own Operating System With our current knowledge, it is impossible to write an actual operating system n However, by thinking of making a little operating system tremendous knowledge is learned Follow the following steps in writing your own little, do nothing useful, operating system 19

Making Your Own Operating System… 1. Using a running computer, write a mini program to do something over and over again 1. 2. 3. I would prefer this program to repeatedly display the word “Hello” on computer monitor Make the size less than 512 bytes. This program will be your operating system Use any language but compile it and produce the executable file 2. An executable file has two sections: 1. 2. The file header, i. e. , metadata, say 512 bytes The actual machine language instructions, say 512 bytes, i. e. , a “com” file 3. Write a program to transfer the “com” file to sector one of track zero of a diskette 20

Making Your Own Operating System… 4. 5. Prepare a simple bootable device such as diskette Transfer the “com” file to sector one of track zero of the diskette 1. 6. 7. 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 21

Summary The following subjects were discussed: Computer, Program, and operating system Logical Computer organization, physical organization, functional organization model and the Fetch-Execute Cycle The need for BIOS, BIOS actions, Installing the OS, Booting the OS Operating system Kernel, hierarchical structure, modes of operation How to make your own small OS 22

Find out Your computer’s instruction categories based on their length The benefits of adjusting the PC register during the fetch cycle even though we have to readjust it during the execute cycle for some instructions For a 32 -bit computer, the maximum memory size that the CPU can directly address (without using a base register) Your computer’s speed in terms of MIPS The company which built your computer’s BIOS The source code of a BIOS from the Internet A source code for a small OS from the Internet How to make the above source code actually work 23

Any Question? 24
- Slides: 24