Lec9-Interrupt.Pdf

Total Page:16

File Type:pdf, Size:1020Kb

Lec9-Interrupt.Pdf CSC501 Operating SystemsPrinciples Interrupts 1 Last Lecture q Deadlock Q Necessary Conditions Q Solutions q Today Question: Q Interrupts Why do we need interrupts? 2 Introduction q Interrupts provide an efficient way to handle unanticipated events and improve processor utilization q Interrupts alter a program’s flow of control Q Interrupt causes transfer of control to an interrupt service routine (ISR) v ISR is also called a handler Q When the ISR is completed, the original program resumes execution Q Behavior is similar to a procedure call v Some significant differences between the two 3 Interrupts vs. Procedures Interrupts Procedures q Initiated by both software q Can only be initiated by and hardware software q Can handle anticipated and q Can handle anticipated events that are coded into unanticipated internal as well the program as external events q Typically loaded along with q ISRs or interrupt handlers the program are memory resident q Use meaningful names to q Use numbers to identify an indicate their function interrupt service q Do not save the eflags q eflags register is saved register automatically A Taxonomy of Pentium Interrupts Difference: q Depending on the way they are reported q Whether or not the interrupted instruction is restarted Interrupt Taxonomy q Exceptions Q Faults, Traps, and Aborts q Software Interrupts q Hardware Interrupts 6 Exceptions: Faults, Traps, and Aborts q Faults Q Instruction boundary before the instruction during which the exception was detected Q Restarts the instruction q Examples: Q Page fault Q Segment-not-found fault Exceptions: Faults, Traps, and Aborts q Traps Q Instruction boundary immediately after the instruction during which the exception was detected Q No instruction restart q Examples: Q Overflow exception (interrupt 4) is a trap Q User defined interrupts are also examples of traps Exceptions: Faults, Traps, and Aborts q Aborts Q No precise location of the instruction that caused the exception Q No instruction restarting Q Reporting severe errors such as hardware errors and inconsistent values in system tables qExamples: QMachine check QDouble fault 9 Dedicated Interrupts q Several Pentium predefined interrupts --- called dedicated interrupts q These include the first five interrupts: interrupt typePurpose 0 Divide error 1 Single-step 2 Non-maskableinterrupt (NMI) 3 Breakpoint 4 Overflow Dedicated Interrupts (cont’d) q Single-Step Interrupt QUseful in debugging QTo single step, Trap Flag (TF) should be set QCPU automatically generates a type 1 interrupt after executing each instruction if TF is set QType 1 ISR can be used to present the system state to the user Dedicated Interrupts (cont’d) q Breakpoint Interrupt QUseful in debugging QCPU generates a type 3 interrupt QGenerated by executing a special single-byte version of int3instruction (opcodeCCH) Interrupt Taxonomy q Exceptions q Software Interrupts q Hardware Interrupts 13 Software Interrupts q Initiated by executing an int instruction, where the interrupt number is an integer between 0 and 255 q Each interrupt can be parameterized to provide several services. Q For example, Linux interrupt service int0x80 provides a large number of services (more than 330 system calls!) vEAX register is used to identify the required service under int0x80 Hardware Interrupts q Software interrupts are synchronous events Q Caused by executing the int instruction q Hardware interrupts are asynchronous in nature Q Typically caused by applying an electrical signal to the processor chip q Hardware interrupts can be Q Maskable Q Non-maskable How Are Hardware Interrupts Triggered? q Maskableinterrupt is triggered by applying an electrical signal to the INTR (INTerruptRequest) pin of Pentium Q Processor recognizes this interrupt only if IF (interrupt enable flag) is set Q Interrupts can be masked or disabled by clearing IF q Non-maskableinterrupt is triggered by applying an electrical signal to the NMI pin of processor Q Processor always responds to this signal Q Cannot be disabled under program control How Does the CPU Know the Interrupt Type? q Interrupt invocation process is common to all interrupts QWhether originated in software or hardware q For hardware interrupts, processor initiates an interrupt acknowledge sequence Qprocessor sends out interrupt acknowledge (INTA) signal QIn response, interrupting device places interrupt vector on the data bus QProcessor uses this number to invoke the ISR that should service the device (as in software interrupts) How Can More Than One Device Interrupt? q Processor has only one INTR pin to receive interrupt signal q Typical system has more than one device that can interrupt ---keyboard, hard disk, floppy, etc. q Use a special chip to prioritize the interrupts and forward only one interrupt to the CPU Q 8259 Programmable Interrupt Controller chip performs this function Interrupt Processing q How many interrupts can be supported? Q Up to 256 interrupts q Interrupt number is used as an index into the Interrupt Descriptor Table (IDT) Q This table stores the addresses of all ISRs Q Each descriptor entry is 8 bytes long v Interrupt number is multiplied by 8 to get byte offset into IDT Q Location: v Protected mode: anywhere in memory IDTR Detailed Steps in Interrupt Processing q Step 1: Save the current machine state q Step 2: Load the machine state for interrupt handling q Step 3: Invoke the corresponding ISR q Step 4: Resume the program execution Question: Why do we need to save the current machine states? 20 Step 1: Save the Current Machine State q Push the EFLAGS register onto the stack q Clear interrupt enable and trap flags Q This disables further interrupts Q Use sti to enable interrupts q Push CS and EIP registers onto the stack Question: Where are these states saved? Step 2: Load the Machine State for Interrupt Handling q Load CS with the 16-bit segment selector from the interrupt gate q Load EIP with the 32-bit offset value from the interrupt gate Question: How to locate and load the machine states for interrupt handling? Protected Mode Interrupt Processing IDTR Organization of the IDT Protected Mode Interrupt Processing q IDTR contains the memory location of IDT q IDTR is a 48-bit register Q 32 bits for IDT base address Q 16 bits for IDT limit value v IDT requires only 2048 (11 bits) v A system may have smaller number of descriptors n Set the IDT limit to indicate the size in bytes q Two special instructions to load (lidt) and store (sidt) IDT Q Both take the address of a 6-byte memory as the operand Protected Mode Interrupt Processing Interrupt descriptor Protected Mode Interrupt Processing Interrupt invocation Step 3: Invoke the ISR q ISR: Interrupt-specific service routine q Examples: Q Single-step Q Breakpoint Q Timer Q Page fault Q … 27 Step 4: Resume the Program Execution q What is the last instruction in an ISR: Q iret q The actions taken on iret are: Q pop the 32-bit value on top of the stack into EIP Q pop the 16-bit value on top of the stack into CS Q pop the 32-bit value on top of the stack into the EFLAGS register q As in procedures, make sure that your ISR does not leave any data on the stack Q Match your push and pop operations within the ISR An Example: q Timer interrupt handler Q Related files: sys/clkint.Ssys/clkinit.c Q Interrupt rate –based on clock timer v ctr1000: 1ms Q Scheduling rate: v Interrupt rate * QUANTUM q You will be familiar with page fault handler in Lab 3! q Others: sys/evec.c 29 Next Lecture q Midterm Review 30.
Recommended publications
  • Allgemeines Abkürzungsverzeichnis
    Allgemeines Abkürzungsverzeichnis L.
    [Show full text]
  • Understanding the Microsoft Office 2013 Protected-View Sandbox
    MWRI PUBLIC UNDERSTANDING THE MICROSOFT OFFICE 2013 PROTECTED-VIEW SANDBOX Yong Chuan, Koh (@yongchuank) 2015/07/09 mwrinfosecurity.com | © MWR InfoSecurity MWRI PUBLIC MWRI PUBLIC Table of Contents 1. Introduction .................................................................................................................... 3 2. Sandbox Internals ............................................................................................................. 4 2.1 Architecture .............................................................................................................. 4 2.1.1 Interception Component ......................................................................................... 4 2.1.2 Elevation Policy Manager ........................................................................................ 4 2.1.3 Inter-Process Communication ................................................................................... 5 2.2 Sandbox Restrictions.................................................................................................... 6 2.2.1 Sandbox Initialization ............................................................................................ 6 2.2.2 File Locations .................................................................................................... 12 2.2.3 Registry Keys ..................................................................................................... 12 2.2.4 Network Connections ..........................................................................................
    [Show full text]
  • Protected Mode - Wikipedia
    2/12/2019 Protected mode - Wikipedia Protected mode In computing, protected mode, also called protected virtual address mode,[1] is an operational mode of x86- compatible central processing units (CPUs). It allows system software to use features such as virtual memory, paging and safe multi-tasking designed to increase an operating system's control over application software.[2][3] When a processor that supports x86 protected mode is powered on, it begins executing instructions in real mode, in order to maintain backward compatibility with earlier x86 processors.[4] Protected mode may only be entered after the system software sets up one descriptor table and enables the Protection Enable (PE) bit in the control register 0 (CR0).[5] Protected mode was first added to the x86 architecture in 1982,[6] with the release of Intel's 80286 (286) processor, and later extended with the release of the 80386 (386) in 1985.[7] Due to the enhancements added by protected mode, it has become widely adopted and has become the foundation for all subsequent enhancements to the x86 architecture,[8] although many of those enhancements, such as added instructions and new registers, also brought benefits to the real mode. Contents History The 286 The 386 386 additions to protected mode Entering and exiting protected mode Features Privilege levels Real mode application compatibility Virtual 8086 mode Segment addressing Protected mode 286 386 Structure of segment descriptor entry Paging Multitasking Operating systems See also References External links History https://en.wikipedia.org/wiki/Protected_mode
    [Show full text]
  • A+ Certification for Dummies, 2Nd Edition.Pdf
    A+ Certification for Dummies, Second Edition by Ron Gilster ISBN: 0764508121 | Hungry Minds © 2001 , 567 pages Your fun and easy guide to Exams 220-201 and 220-202! A+ Certification For Dummies by Ron Gilster Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com www.dummies.com Copyright © 2001 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. Library of Congress Control Number: 2001086260 ISBN: 0-7645-0812-1 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 2O/RY/QU/QR/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc.
    [Show full text]
  • Chapter 3 Protected-Mode Memory Management
    CHAPTER 3 PROTECTED-MODE MEMORY MANAGEMENT This chapter describes the Intel 64 and IA-32 architecture’s protected-mode memory management facilities, including the physical memory requirements, segmentation mechanism, and paging mechanism. See also: Chapter 5, “Protection” (for a description of the processor’s protection mechanism) and Chapter 20, “8086 Emulation” (for a description of memory addressing protection in real-address and virtual-8086 modes). 3.1 MEMORY MANAGEMENT OVERVIEW The memory management facilities of the IA-32 architecture are divided into two parts: segmentation and paging. Segmentation provides a mechanism of isolating individual code, data, and stack modules so that multiple programs (or tasks) can run on the same processor without interfering with one another. Paging provides a mech- anism for implementing a conventional demand-paged, virtual-memory system where sections of a program’s execution environment are mapped into physical memory as needed. Paging can also be used to provide isolation between multiple tasks. When operating in protected mode, some form of segmentation must be used. There is no mode bit to disable segmentation. The use of paging, however, is optional. These two mechanisms (segmentation and paging) can be configured to support simple single-program (or single- task) systems, multitasking systems, or multiple-processor systems that used shared memory. As shown in Figure 3-1, segmentation provides a mechanism for dividing the processor’s addressable memory space (called the linear address space) into smaller protected address spaces called segments. Segments can be used to hold the code, data, and stack for a program or to hold system data structures (such as a TSS or LDT).
    [Show full text]
  • Paging and Segmentation Memory Addressing Memory Paging
    Systems Design & Programming Paging and Segmentation CMPE 310 Memory Addressing Memory Paging: Available in the 80386 and up. Allows a linear address (virtual address) of a program to be located in any portion of physical memory. The paging unit is controlled by the microprocessors control registers: 31 12 11 0 CR4(Pentium and up) DE PVI PSE TSD MCE VME Page Directory Base Address CR3 PCD PWT Most recent Page Faulting Linear Address CR2 Reserved CR1 CR0 ET PE TS PG AM WP NE MP NW CD EM 1 Systems Design & Programming Paging and Segmentation CMPE 310 Memory Addressing Memory Paging: The paging system operates in both real and protected mode. It is enabled by setting the PG bit to 1 (left most bit in CR0). (If set to 0, linear addresses are physical addresses). CR3 contains the page directory 'physical' base address. The value in this register is one of the few 'physical' addresses you will ever refer to in a running system. The page directory can reside at any 4K boundary since the low order 12 bits of the address are set to zero. The page directory contains 1024 directory entries of 4 bytes each. Each page directory entry addresses a page table that contains up to 1024 entries. 2 Systems Design & Programming Paging and Segmentation CMPE 310 Memory Addressing Memory Paging: 31 22 21 12 11 0 Directory Page Table Offset Linear or Virtual Address 31 12 Physical Address P A U W D PCD PWT Page Directory or Page Table Entry Present Writable User defined Write through Cache disable Accessed Dirty (0 in page dir) The virtual address is broken into three pieces: P Directory: Each page directory addresses a 4MB section of main mem.
    [Show full text]
  • Segmentation, Protected Mode
    Copyright Notice CS 410/510 • These slides are distributed under the Creative Commons Languages & Low-Level Programming Attribution 3.0 License • You are free: Mark P Jones • to share—to copy, distribute and transmit the work Portland State University • to remix—to adapt the work • under the following conditions: Fall 2018 • Attribution: You must attribute the work (but not in any way that suggests that the author endorses you or your use of the work) as follows: “Courtesy of Mark P. Jones, Portland State University” Week 3: Segmentation, Protected Mode, Interrupts, and Exceptions The complete license text can be found at http://creativecommons.org/licenses/by/3.0/legalcode !1 2 General theme for the next two weeks Diagrams and Code • In a complex system … • There are a lot of diagrams on these slides • Many of these are taken directly from the “Intel® 64 and App App App App App IA-32 Architectures Software Developer’s Manual”, Operating System Operating System particularly Volume 3 Microkernel • There is a link to the full pdf file in the Reference section Hardware • There is also a lot of code on these slides • Remember that you can study these more carefully later if • Question: how can we protect individual programs from you need to! interference with themselves, or with one another, either directly or by subverting lower layers? • General approach: leverage programmable hardware features! 3 4 Taking stock: Code samples ... so far vram video RAM simulation vram.tar.gz hello boot and say hello on bare metal, via hello.tar.gz GRUB simpleio a simple library for video RAM I/O Segmentation bootinfo display basic boot information from (or: where do “seg faults” come from?) GRUB baremetal.tar.gz mimg memory image bootloader & make tool example-mimg display basic boot information from mimgload example-gdt basic demo using protected mode segments (via a Global Descriptor Table) prot.tar.gz example-idt context switching to user mode (via an Interrupt Descriptor Table) 5 6 BASIC EXECUTION ENVIRONMENT • General-purpose registers.
    [Show full text]
  • Diving Into Ie10'
    DIVING INTO IE 10’S ENHANCED PROTECTED MODE SANDBOX Mark Vincent Yason IBM X-Force Advanced Research yasonm[at]ph[dot]ibm[dot]com @MarkYason (v3) ABSTRACT With the release of Internet Explorer 10 in Windows 8, an improved version of IE’s Protected Mode sandbox, called Enhanced Protected Mode (EPM), was introduced. With the use of the new AppContainer process isolation mechanism introduced in Windows 8, EPM aims to further limit the impact of a successful IE compromise by limiting both read and write access and limiting the capabilities of the sandboxed IE process. As with other new security features integrated in widely-deployed software, it is just prudent to look at how EPM works internally and also evaluate its effectiveness. This presentation aims to provide both by delving deep into the internals and assessing the security of IE 10’s Enhanced Protected Mode sandbox. The first part of this presentation will focus on the inner workings of the EPM sandbox where topics such as the sandbox restrictions in place, the inter-process communication mechanism in use, the services exposed by the higher-privileged broker process, and more are discussed. The second part of this presentation will cover the security aspect of the EPM sandbox where its limitations are assessed and potential avenues for sandbox escape are discussed. Finally, in the end of the presentation, an EPM sandbox escape exploit will be demonstrated. The details of the underlying vulnerability, including the thought process that went through in discovering it will also be discussed. IBM Security Systems | © 2014 IBM Corporation DIVING INTO IE 10’S ENHANCED PROTECTED MODE SANDBOX > CONTENTS |2 CONTENTS Contents ...............................................................................................................................................................
    [Show full text]
  • Optimization Techniques for Memory Virtualization-Based Resource Management
    SSStttooonnnyyy BBBrrrooooookkk UUUnnniiivvveeerrrsssiiitttyyy The official electronic file of this thesis or dissertation is maintained by the University Libraries on behalf of The Graduate School at Stony Brook University. ©©© AAAllllll RRRiiiggghhhtttsss RRReeessseeerrrvvveeeddd bbbyyy AAAuuuttthhhooorrr... Optimization Techniques for Memory Virtualization-based Resource Management A Dissertation Presented by Jui-Hao Chiang to The Graduate School in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy in Computer Science Stony Brook University December 2012 Stony Brook University The Graduate School Jui-Hao Chiang We, the dissertation committee for the above candidate for the Doctor of Philosophy degree, hereby recommend acceptance of this dissertation. Tzi-cker Chiueh { Dissertation Advisor Professor, Department of Computer Science Jie Gao { Chairperson of Defense Associate Professor, Department of Computer Science Rob Johnson Assistant Professor, Department of Computer Science Ted Teng Professor, Department of Technology and Society This dissertation is accepted by the Graduate School. Charles Taber Interim Dean of the Graduate School ii Abstract of the Dissertation Optimization Techniques for Memory Virtualization-based Resource Management by Jui-Hao Chiang Doctor of Philosophy in Computer Science Stony Brook University 2012 Memory virtualization abstracts the physical memory resources in a virtualized server in such a way that offers many resource man- agement advantages, such as consolidation, sharing,
    [Show full text]
  • CIS 3207 - Operating Systems CPU Mode
    CIS 3207 - Operating Systems CPU Mode Professor Qiang Zeng Spring 2018 CPU Modes • Two common modes – Kernel mode • The CPU has to be in this mode to execute the kernel code – User mode • The CPU has to be in this mode to execute the user code CIS 3207 – Operating Systems 2 Important questions • How are CPU modes implemented? • Why are CPU modes needed? • Difference between Kernel mode and User mode • How are system calls implemented? • Advanced topic: Virtualization CIS 3207 – Operating Systems 3 How CPU Modes are implemented • Implemented through protection rings – A modern CPU typical provides different protection rings, which represent different privilege levels • A ring with a lower number has higher privileges – Introduced by Multics in 60’s – E.g., an X86 CPU usually provides four rings, and a Linux/Unix/Windows OS uses Ring 0 for the kernel mode and Ring 3 for the user mode CIS 3207 – Operating Systems 4 Why are Protection Rings needed? • Fault isolation: a fault (e.g., divided by 0) in the code running in a less-privileged ring can be captured and handled by code in a more-privileged ring • Privileged instructions: certain instructions can only be issued in a privileged ring; thus an OS can implement resource management and isolation here • Privileged memory space: certain memory can only be accessed in a privileged ring All these are demonstrated in the difference between the kernel mode and the user mode CIS 3207 – Operating Systems 5 Kernel Mode vs. User Mode? • A fault in the user space (e.g., divided by zero, invalid access,
    [Show full text]
  • CY 2550 Foundations of Cybersecurity Systems Security
    CY 2550 Foundations of Cybersecurity Systems Security Alina Oprea Associate Professor, Khoury College Northeastern University March 26 2020 Announcements • Social engineering and ethics projects are due today • Forensics project will be released today, due on April 4 • Exploit project is the last one, due on April 17 • Final exam • Take home • Released on April 13 at 11:45am EST, due on April 14 at noon • Submitted through Gradescope • Questions on the material to test general understanding • Might include questions from the “Countdown to Zero Day” book 2 Systems Security Threat Model Intro to Computer Architecture Hardware Support for Isolation Security Technologies Principles 3 Memory 128 MB Memory Unsafety Ethernet/Wifi Hard Drive OS Infect the OS code with malicious code Problem: any process can read/write any memory Scan memory to find usernames, passwords, saved credit card numbers, etc. 0 4 Memory 128 MB Device Unsafety Ethernet/Wifi Hard Drive OS Problem: any process can access any hardware device directly Access control is enforced by the OS, but OS APIs can be bypassed Send stolen data to the thief, Read/write/delete attack other computers, etc. any file 0 5 Old systems did not protect memory or devices • Any process could access any memory • Any process could access any device Problems • No way to enforce access controls on Review users or devices • Processes can steal from or destroy each other • Processes can modify or destroy the OS On old computers, systems security was literally impossible How do we fix these in modern architectures? ISOLATION 7 Systems Security Threat Model Intro to Computer Architecture Hardware Support for Isolation Security Technologies Principles 8 Modern Architecture To achieve systems security, we need process isolation • Processes cannot read/write memory arbitrarily • Processes cannot access devices directly How do we achieve this? Hardware support for isolation 1.
    [Show full text]
  • Western Region Technical Attachment DOS COMPATIBILITY UNDER OS/2
    Western Region Technical Attachment No. 92-11 March 17, 1992 DOS COMPATIBILITY UNDER OS/2 A DOS compatibility feature is included in OS/2 version 1.21 which was implemented on MicroSWIS. Many sites have found that this feature does not properly run many DOS programs and, in some cases, can even crash the system. This Technical Attachment examines the technical issues surrounding DOS compatibility under OS/2; how it works, and why it doesn't always work. The 80286 Modes of Operation OS/2 Version l.x is written for an Intel 80286 processor. The 80286 processor has two modes of operation: real mode and protected mode. These processing modes can be thought of as two different computers packaged into one chip. The real mode computer assumes that one program is controlling the entire system and that no other programs exist. Thus, real mode programs are concerned only with their task and as.sume that the computer is entirely theirs to accomplish this task; a single task machine. Conceptually, the real mode of operation is any PC running a DOS program. The protected mode of operation was developed by Intel to execute multiple tasks. As the protected mode name implies, each task or program is isolated (protected) from every other program running on the system. Thus, if one program crashes, all other programs can continue executing with no ill effects. The operating system must implement these features of the 80286 chip. OS/2 Version l.x implements the full 80286 capabilities. (DOS provides a minimal implementation of protected mode with extended memory (above 1 MB) addressing.) The concept that real mode and protected mode are two distinct computer systems reflects the actual design philosophy behind the 80286 chip.
    [Show full text]