OPERATING SYSTEM Submitted by MADHU MADHAN VTF in

OPERATING SYSTEM Submitted by: MADHU MADHAN VTF in CSE GP MEHAM

OBJECTIVE OF COMPILER COP 5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007 -2009

OBJECTIVES • Be able to build a compiler for a (simplified) (programming) language • Know how to use compiler construction tools, such as generators of scanners and parsers • Be familiar with virtual machines, such as the JVM and Java bytecode • Be able to define LL(1), LR(1), and LALR(1) grammars • Be familiar with compiler analysis and optimization techniques • … learn how to work on a larger software project!

COMPILER “Compilation” • Translation of a program written in a source language into a semantically equivalent program written in a target language Input Source Program Compiler Error messages Target Program Output

ASSEMBLE R

Assembler: Definition • Translating source code written in assembly language to object code.

LANGUAGE LEVELS High Level Language Assembler Language Machine Language Micro programming Hardware Firmware

MACHINE CODE • Machine code: • Set of commands directly executable via CPU • Commands in numeric code • Lowest semantic level

LOADERS AND LINKERS

INTRODUCTION • To execute an object program, we needs • Relocation, which modifies the object program so that it can be loaded at an address different from the location originally specified • Linking, which combines two or more separate object programs and supplies the information needed to allow references between them (Section 2. 2. 2) • Loading and Allocation, which allocates memory location and brings the object program into memory for execution (Section 2. 3. 5)

OVERVIEW • Type of loaders • assemble-and-go loader • absolute loader (bootstrap loader) • relocating loader (relative loader) • direct linking loader • Design options • linkage editors • dynamic linking • bootstrap loaders

ASSEMBLE-AND-GO LOADER • Characteristic • the object code is stored in memory after assembly • single JUMP instruction • Advantage • simple, developing environment • Disadvantage • whenever the assembly program is to be executed, it has to b assembled again • programs have to be coded in the same language

LINKAGE EDITORS • The essential difference between a linkage editor and a linking loader

OPERATING SYSTEMS 1: Operating Systems Overview

OPERATING SYSTEM OVERVIEW WHAT IS AN OPERATING SYSTEM? • An interface between users and hardware - an environment "architecture” • Allows convenient usage; hides the tedious stuff • Allows efficient usage; parallel activity, avoids wasted cycles • Provides information protection • Gives each user a slice of the resources • Acts as a control program.

OPERATING SYSTEM OVERVIEW Humans Program Interface User Programs O. S. Interface O. S. Hardware Interface/ Disk/Tape/Memory Privileged 1: Operating Systems Overview Instructions The Layers Of A System

OPERATING SYSTEM OVERVIEW Components The CPU is wasted if a job waits for I/O. This leads to: • Multiprogramming ( dynamic switching ). While one job waits for a resource, the CPU can find another job to run. It means that several jobs are ready to run and only need the CPU in order to continue. CPU scheduling is the subject of Chapter 6. All of this leads to: • memory management • resource scheduling • deadlock protection which are the subject of the rest of this course.

OPERATING SYSTEM OVERVIEW These are the devices that make up a typical system. Any of these devices can cause an electrical interrupt that grabs the attention of the CPU. Hardware Support

MICROSOFT DISK OPERATING SYSTEM AND PC DOS

BRIEF HISTORY • 8 -bit processors had been the norm in Personal Computers (PC) • Digital Research’s Control Program for Microcomputers CP/M-80 most popular 8 -bit OS • Intel’s 8086 – first 16 bit processor for PCs • OS developed by Seattle Computer Products (SCP) for their own 8086 based system • IBM to launch 8086 based PC – needed an OS • Digital Research’s CP/M-86 and Softech • Microsoft licenses the software from SCP • The rest is history

LIMITATIONS • Hardware could only address 1 MB • Programs couldn’t be larger than 640 kb • Single user – single processor – no hard drives

MEMORY MAP Reserved for BIOS 1 MB Interrupt vector starts at 0 Unused 640 k I/O System - from manufacturer Command Transient Program memory DOS kernel starts at 1 k Resident portion of COMMAND. COM Command Resident DOS Kernel 1 k I/O System Interrupt Vectors 0 k Above 640 kb is 384 kb of additional system memory – not directly addressable 1 MB upper limit

SYNCHRONIZATION • No true multi-tasking - Re-entrant code not supported by DOS • Interrupt driven – no scheduler or CPU sharing • Three types of interrupts: • Internal, External, Software • CPU senses interrupt • Places Program Status Word, code segment register and instruction pointer on a stack • Disables interrupt system • Starts processing based at 8 -bit address from interrupt table (interrupt vector) • Re-enables interrupt system

PROCESSOR MODES • Real mode – compatible with 8086 limits • Protected mode – selector/table/offset – memory system • Four 16 -bit words used as memory descriptor • First available on the 80286 based systems (required hard reboot to switch modes) • Four privilege levels (0 – 3, with 0 having most privileges) • Additional table indicator to distinguish between local and global memory

CONCLUSION • Revolutionary design – no chance • Revolutionary impact – absolutely • Simple, expandable OS • Standardized user interface and applications • Lasted from 1981 until 1994 as a separate product – still in use by Windows 98 (and in ME though better hidden)

INTRODUCTION TO WINDOWS

EVOLUTION OF WINDOWS • Windows 3. 1 • First widely used successful version of Windows • Replaced MS-DOS • Windows 95 • Introduced Start button, taskbar for multitasking, and My Computer for easier file management • Windows NT • Intended for business computing • Increased reliability and security

THE WINDOWS DESKTOP My Computer Start Button Taskbar (multitasking)

THE DEVICES ON A SYSTEM • • Drive A is always a floppy disk Drive B is a second floppy disk (obsolete) Drive C is always a fixed disk Drives D, E, are variable • CD ROM • Zip drive or removable media • Network drives

FILE MANAGEMENT • My Computer • Simpler and less sophisticated • Can result in multiple open windows at one time • Windows Explorer • Hierarchical view on left • Contents of the selected folder on the right • Multiple views available for both • Small icons, Large icons, List, and Details view

OPERATING SYSTEM FUNCTIONS • File Management • Application Management • Built-in Utility Programs • Control of Computer Hardware

OPERATING SYSTEM TYPES • Multiuser – Two or more users work with the computer at the same time • Multitasking – Two or more processes running at the same time. • Multithreading – Two or more parts of the same process running at the same time.

DOS COMMANDS • Two types – Internal and External • Internal commands are resident in the main kernel file: command. com (or cmd. exe) • External commands are separate little programs. • It's important to learn DOS commands because you can write scripts to execute a set of commands automatically.

DEADLOCK PREVENTION, AVOIDANCE, AND DETECTION

THE DEADLOCK PROBLEM • In a computer system deadlocks arise when members of a group of processes which hold resources are blocked indefinitely from access to resources held by other processes within the group.

DEADLOCK EXAMPLE • Pi requests one I/O controller and the system allocates one. • Pj requests one I/O controller and again the system allocates one. • Pi wants another I/O controller but has to wait since the system ran out of I/O controllers. • Pj wants another I/O controller and waits.

CONDITIONS FOR DEADLOCKS • Mutual exclusion. No resource can be shared by more than one process at a time. • Hold and wait. There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes. • No preemption. A resource cannot be preempted. • Circular wait. There is a cycle in the wait-for graph.

AN EXAMPLE bridge City A bridge river City B City A City B river

GRAPH-THEORETIC MODELS • Wait-for graph. • Resource-allocation graph.

WAIT-FOR GRAPH P 2 P 1 P 3 P 5 P 4

RESOURCE ALLOCATION GRAPH P 1 P 2 r 2 P 3 Resource allocation graph Without deadlock P 3 With deadlock

TWO TYPES OF DEADLOCKS • Resource deadlock: uses AND condition: a process that requires resources for execution can proceed when it has acquired all those resources. • Communication deadlock: uses OR condition: a process that requires resources for execution can proceed when it has acquired at least one of those resources.

• P-out-of –Q condition which means that a process simultaneously requests Q resources and remains blocked until it is granted any P of those resources. • AND-OR model, which may specify any combination of AND and OR models. E. g. a AND (b OR c).

DEADLOCK AVOIDANCE Four resources ABCD. A has 6 instances, B has 3 instances, C Has 4 instances and D has 2 instances. Process Allocation Max ABCD P 1 3011 4111 P 2 0100 0212 P 3 1110 4210 P 4 1101 P 5 0000 2110 Is the current state safe? If P 5 requests for (1, 0, 1, 0), can this be granted?

- Slides: 45