11_Traps_Service_Routines

11_Traps_Service_Routines - CMPE12 Cyrus Bazeghi System...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMPE12 Cyrus Bazeghi System Calls (TRAPS) and Subroutines Ch. 9 CMPE12 Cyrus Bazeghi 2 System Calls Certain operations require specialized knowledge and protection : specific knowledge of I/O device registers and the sequence of operations needed to use them I/O resources shared among multiple users/programs; a mistake could affect lots of other users! Not every programmer knows (or wants to know) this level of detail Provide service routines or system calls (part of operating system) to safely and conveniently perform low-level, privileged operations CMPE12 Cyrus Bazeghi 3 System Call (service routines) 1. User program invokes system call. 2. Operating system code performs operation. 3. Returns control to user program. In LC-3, this is done through the TRAP mechanism . CMPE12 Cyrus Bazeghi 4 LC-3 TRAP Mechanism 1. A set of service routines. part of operating system -- routines start at arbitrary addresses System code by convention is typically below address x3000 up to 256 routines 2. Table of starting addresses. stored at x0000 through x00FF in memory called System Control Block or Vector Table in some architectures 3. TRAP instruction. used by user 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 CMPE12 Cyrus Bazeghi 5 TRAP Instruction Trap vector (trapvect8) identifies which system call to invoke 8-bit index into table of service routine addresses in LC-3, this table is stored in memory at 0x0000 0x00FF 8-bit trap vector is zero-extended into 16-bit memory address Where to go lookup starting address from table; place in PC How to get back saves address of next instruction (current PC) in R7 before changing PC CMPE12 Cyrus Bazeghi 6 TRAP NOTE: PC has already been incremented during instruction fetch stage. CMPE12 Cyrus Bazeghi 7 RET (JMP R7) How do we transfer control back to instruction following the TRAP? Save old PC in R7. JMP R7 gets us back to the user program at the right spot. LC-3 assembly language lets us use RET (return) in place of JMP R7. Must make sure that service routine does not change R7, or it wont know where to return. CMPE12 Cyrus Bazeghi 8 TRAP Mechanism Operation 1. Lookup starting address. 2. Transfer to service routine. 3. Return (JMP R7). CMPE12 Cyrus Bazeghi 9 Example: Using the TRAP Instruction ; This code just takes upper case characters and converts ; to lower case and prints them. Terminates with a 7 .ORIG x3000 LD R2, TERM ; Load negative ASCII 7 LD R3, ASCII ; Load ASCII difference AGAIN TRAP x23 ; input character ADD R1, R2, R0 ; Test for terminate: =7?...
View Full Document

Page1 / 32

11_Traps_Service_Routines - CMPE12 Cyrus Bazeghi System...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online