{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

11_Traps_Service_Routines

11_Traps_Service_Routines - System Calls(TRAPS and...

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

View Full Document Right Arrow Icon
CMPE12 Cyrus Bazeghi System Calls (TRAPS) and Subroutines Ch. 9
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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 .
Background image of page 3

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

View Full Document Right Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
CMPE12 Cyrus Bazeghi 6 TRAP NOTE: PC has already been incremented during instruction fetch stage.
Background image of page 6
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 won’t know where to return.
Background image of page 7

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

View Full Document Right Arrow Icon
CMPE12 Cyrus Bazeghi 8 TRAP Mechanism Operation 1. Lookup starting address. 2. Transfer to service routine. 3. Return (JMP R7).
Background image of page 8
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?
Background image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}