S. Barua – CPSC 240 CHAPTER 9 TRAP ROUTINES AND SUBROUTINES The TRAP mechanism allows the user program.

Slides:



Advertisements
Similar presentations
Computer Science 210 Computer Organization Strings, I/O, and Trap Service Routines.
Advertisements

Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
1 System Calls (TRAPS) and Subroutines Patt and Patel Ch. 9.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
Computer Science 210 Computer Organization Recursive Subroutines System Stack Management.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Overview The Operate Instructions - ADD, AND, NOT The Data Movement Instructions - Load, Load Address, Store Example Using Operate & Data Movement The.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter 7 Interupts DMA Channels Context Switching.
Chapter 6 Programming in Machine Language The LC-3 Simulator
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 System Calls.
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
CSS 372 Oct 2 nd - Lecture 2 Review of CSS 371: Simple Computer Architecture Chapter 3 – Connecting Computer Components with Buses Typical Bus Structure.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Computer Science 210 s1c Computer Systems Semester 1 Lecture Notes James Goodman (revised by Robert Sheehan) Credits: Slides prepared by Gregory.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 2: Computer-System Structures Computer System Operation I/O Structure.
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Computer Science 210 Computer Organization Introduction to Subroutines.
Chapter 5 The LC Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Chapter 9 Chapter 9 Subroutines and TRAPs l Privileged Instructions l TRAP Routines l Subroutines.
Introduction to Computer Engineering CS/ECE 252, Spring 2010 Prof. Guri Sohi Computer Sciences Department University of Wisconsin – Madison.
Chapter 9 TRAP Routines and Subroutines. 9-2 System Calls Certain operations require specialized knowledge and protection: specific knowledge of I/O device.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 JSR Instruction Jumps to a location (like.
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
Chapter 14 Functions.
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Chapter 7 & 9.2 Assembly Language
Computer Science 210 Computer Organization
COSC121: Computer Systems: LC3 Traps and Subroutines
Computer Science 210 Computer Organization
Chapter 9 TRAP Routines and Subroutines
Chapter 5 The LC-3.
The LC-3 Instruction Set Architecture Data Movement instructions
LC-3 Details and Examples
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Module 2: Computer-System Structures
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
TRAP Routines Subroutines Privileged Instructions
Chapter 9 TRAP Routines and Subroutines
by Richard P. Paul, 2nd edition, 2000.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
TRAP Routines Privileged Instructions Subroutines
Chapter 9 TRAP Routines and Subroutines
Module 2: Computer-System Structures
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Module 2: Computer-System Structures
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Module 2: Computer-System Structures
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Presentation transcript:

S. Barua – CPSC CHAPTER 9 TRAP ROUTINES AND SUBROUTINES The TRAP mechanism allows the user program to request the operating system to perform certain tasks on behalf of the user program. The request made by the user program is often referred to as a service call or a system call.

S. Barua – CPSC LC-3 TRAP Mechanism 1. A set of service routines Part of operating system Routines start at arbitrary addresses Up to 256 routines 2. Table of starting addresses – Trap Vector Table Stored at x0000 through x00FF in memory Called System Control Block in some architectures 3. TRAP instruction Used by program to transfer control to operating system 8-bit trap vector names one of the 256 service routines 4. A linkage back to the user program Want execution to resume immediately after the TRAP instruction

S. Barua – CPSC TRAP Instruction Trap vector Identifies which system call to invoke 8-bit trap vector is zero-extended to 16 bits to form a memory address. The address points to an entry in the Trap Vector Table In LC-3, this table is stored in memory at 0x0000 – 0x00FF Where to go Lookup starting address from the Trap Vector Table Load the address into PC How to get back Save the return address (address of next instruction) in R7. The RET or JMP R7 instruction of LC-3 allows us to do this.

S. Barua – CPSC TRAP Routines and their Assembler Names vectorsymbolroutine x20GETC read a single character (no echo) x21OUT output a character to the monitor x22PUTS write a string to the console x23IN print prompt to console, read and echo character from keyboard x25HALT halt the program

S. Barua – CPSC The Trap Vector Table x0020x0400 x0021x0430 x0022x0450 x0023x04A0 x0024X04E0 x0025XFD70

S. Barua – CPSC TRAP Mechanism Operation 1.Get starting address from the Trap vector table. 2.Transfer to service routine. 3.Return (JMP R7 or RET) to user program.

S. Barua – CPSC Subroutines A subroutine is a program fragment that: Part of user space Performs a well-defined task Is invoked (called) by another user program Returns control to the calling program when finished Like a service routine, but not part of the OS Reasons for subroutines: Reuse useful (and debugged!) code without having to keep typing it in Divide task among multiple programmers Use vendor-supplied library of useful routines

S. Barua – CPSC Subroutine Call - JSR Instruction Saves current PC (address of next instruction) in R7 and jumps to the location specified by the target address. Saving the return address is called “linking” Bit 11 specifies addressing mode If Bit 11=1, then PC-relative addressing Target address = PC + Sext(IR[10:0]) If Bit 11=0, then register addressing Target address = contents of register specified by IR[8:6]

S. Barua – CPSC Returning from a Subroutine The LC-3 instruction RET (JMP R7) gets us back to the calling routine.

S. Barua – CPSC Passing Information to/from Subroutines Arguments A value passed into a subroutine is called an argument. This is a value needed by the subroutine to do its job. Return Values A value passed out of a subroutine is called a return value. This is the value that the subroutine computes.

S. Barua – CPSC Saving and Restoring Registers In subroutines and service routines, we need to save and restore registers, if needed. Subroutines generally use “callee-save” strategy, except for return values. Save anything that the subroutine will alter internally that shouldn’t be visible when the subroutine returns. It’s good practice to restore incoming arguments to their original values (unless overwritten by return value). Remember: We MUST save R7 if we call any other subroutine or service routine (TRAP). Otherwise, we won’t be able to return to the calling program.