The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Fetch Execute Cycle – In Detail -
Procedures 2 Intructions Supporting Procedures Making Use of a Stack.
CSCI 4717/5717 Computer Architecture
Chapter 6 Limited Direct Execution
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Exception Processing ECE511: Digital System & Microprocessor.
Scheduler Activations Effective Kernel Support for the User-Level Management of Parallelism.
Chapter 7 Interupts DMA Channels Context Switching.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
Digression: the “Stack” 1 CS502 Spring 2006 Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
MicroC/OS-II Embedded Systems Design and Implementation.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Introduction to Embedded Systems
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
80386DX.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Interrupt I/O (again!) Arithmetic using a stack.
MIPS Subroutines Subroutine Call – jal subname Saves RA in $31 and jumps to subroutine entry label subname Subroutine Return – jr $31 Loads PC with return.
Processes 2 Introduction to Operating Systems: Module 4.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
WORKING OF SCHEDULER IN OS
Interrupts and exceptions
Processes and threads.
Computer Science 210 Computer Organization
Mechanism: Limited Direct Execution
CS 3305 System Calls Lecture 7.
Chapter 10 And, Finally... The Stack
Functions and Procedures
Chapter 10 The Stack.
Arithmetic using a stack
Computer System Overview
Processor Fundamentals
MIPS Functions.
BIC 10503: COMPUTER ARCHITECTURE
Chapter 10 And, Finally... The Stack
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Embedded System Development Lecture 7 2/21/2007
Computer System Overview
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
A Top-Level View Of Computer Function And Interconnection
Presentation transcript:

The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places items on the stack New items will be placed on top of old ones. –Pop: Removes items from the stack. Removes most recently placed item from the stack and returns it. Cannot pop a specific item from the stack without popping items pushed after it.

The Process Context Programs running in memory are called “processes” A process would make use of registers, while the processor will use the Program Counter to keep track of which instruction in the program is to be executed next. The contents of the registers and the Program Counter is called the “context” of the process.

Saving the Process Context When an interrupt occurs, the currently executing process must be suspended so that the interrupt handler can handle the interrupt. –We must save the address of the next instruction of the process to be executed so that we can resume the process at the point it was interrupted. –The handler may modify register values, and the original values must be saved. The suspended process must be able to resume after the handler has finished handling the interrupt, and it must continue as though the interrupt never occurred. To achieve this it is vital to save the context of the process.

Using the Stack The stack is a natural tool for saving process contexts. We can modify the interrupt handling procedure thus: –Suppose a process P with context Cp is running when an interrupt I occurs. –Save the context of P into the stack: push(Cp). –The result is that the address of the next instruction to be executed is saved together with the current register values. –Place the address of the interrupt handler into the program counter (you can obtain the address from an interrupt vector table, or from a fixed location. E.g. in MIPS the interrupt handler is always at address 0x ). This will cause the interrupt handler to be executed.

Using the Stack –When the interrupt handler finishes, do a pop() to restore the context of Process P. –The PC is now restored to the address of the next instruction to be executed in Process P, the registers are restored to their former values –This causes the process P to continue executing at the point where it left off.

Nested Interrupts As an interrupt handler is executing, it is possible that a higher priority interrupt occurs. In this case, the interrupt handler is treated like any other process –The context of the interrupt handler is pushed onto the stack. –The new interrupt handler is executed. –When it ends, the context of the previous handler is restored, and the previous handler executes to completion.

Nested Interrupts –When the previous interrupt handler ends, it restores the context of the interrupted process, and the process continues where it left off.