TRAP Routines Subroutines Privileged Instructions

Slides:



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

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.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
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 I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
Chapter 9 Overview Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter 6 Programming in Machine Language The LC-3 Simulator
S. Barua – CPSC 240 CHAPTER 9 TRAP ROUTINES AND SUBROUTINES The TRAP mechanism allows the user program.
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
Chapter 9 Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET.
Overview Projects The Assembly Process Programmed I/O Interrupt Driven I/O.
Chapter 8 Overview Programmed I/O Introduction to Interrupt Driven I/O Project 3.
Chapter 8 I/O Programming Chapter 9 Trap Service Routines Programmed I/O Interrupts Interrupt Driven I/O Trap Service Routines.
Chapter 9 Trap Routines TRAP number (go to service routine) & RET (return from service routine) Subroutines (or Functions) JSR offset or JSRR rn (go to.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Chapter 8 Overview Programmed I/O Interrupt Driven I/O.
Overview von Neumann Model Components of a Computer Some Computer Organization Models The Computer Bus An Example Organization: The LC-3.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 8 Input/Output Basic organization Keyboard input Monitor output Interrupts DMA.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-2 Instruction Set Architecture Operate instructions Data Movement instructions.
Computer Science 210 Computer Organization Introduction to Subroutines.
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.
Chapter 9 TRAP Routines and Subroutines. 9-2 System Calls Certain operations require specialized knowledge and protection: specific knowledge of I/O device.
Introduction to Computing Systems and Programming The LC-2.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
Introduction to Computer Engineering
Chapter 7 Assembly Language
Chapter 9 TRAP Routines and Subroutines
Chapter 7 & 9.2 Assembly Language
Computer Science 210 Computer Organization
HKN ECE 220: Fall 2017 Midterm 1 AJ Schroeder, Evan Lissoos, Utsav Kawrani 23rd September, 2017.
Computer Science 210 Computer Organization
COSC121: Computer Systems: LC3 Traps and Subroutines
Chapter 7 Assembly Language
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Chapter 9 TRAP Routines and Subroutines
The LC-3 Instruction Set Architecture Data Movement instructions
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
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
HKN ECE 220: Spring 2018 Midterm 1
Chapter 7 Assembly Language
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Chapter 7 Assembly Language
Chapter 9 TRAP Routines and Subroutines
Chapter 7 Assembly Language
TRAP Routines Privileged Instructions Subroutines
Chapter 9 TRAP Routines and Subroutines
School of Computer Science and Technology
Computer Science 210 Computer Organization
Introduction to Computer Engineering
HKN ECE 220: Fall 2018 Midterm 1 Andrew Fortunat, Jeff Chang, Srijan Chakraborty, Kanad Sarkar February 16, 2019.
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Midterm 2 Review Chapters 4-16 LC-3
Chapter 9 TRAP Routines and Subroutines
Presentation transcript:

TRAP Routines Subroutines Privileged Instructions Chapter 9 TRAP Routines Subroutines Privileged Instructions

Subroutines Used for Can be either Frequently executed code segments: written only once. Hides the implementation details. Passing of parameters and return values, in registers or memory. Is called from within a program; control is returned to the same point it was called from. Can be either Procedures, or Functions

Jump to Sub - 1: JSR/JMP JSR/JMP: jump subroutine (direct) JSR: IR[11] = 1, and R7  (PC) i.e. PC is saved in R7 JMP: IR[11] = 0, PC is not saved. PC  PC[15:9] @ IR[8:0] 0 0 0 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 JSR L x 0 0 pageoffset9

Jump to Sub - 2: JSRR/JMPR JSRR/JMPR: jump subroutine (base + offset) JSRR: IR[11] = 1, and R7  (PC) i.e. PC is saved in R7 JMPR: IR[11] = 0, PC is not saved. PC  (BaseReg) + Zext(IR[5:0]) 0 0 0 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 JSR L x 0 0 x x x index6 BaseReg

Privileged Instructions There are several instructions that are best executed by a supervisor program (OS) rather than a user program: IO instructions Loading of memory mapping registers Resetting the clock Halt i.e. instructions where one program can affect the behavior of another. Hardware enforces two modes of operation User Mode Privileged Mode (aka. supervisor, kernel, monitor mode) Only the supervisor program can execute privileged instructions.

TRAP Instructions TRAP: A special instruction RET – return instruction A subroutine call used to invoke a specific supervisor routine. It switches the execution to privileged mode, and reverts back to user mode when the routine completes. PC  Mem[Zext(IR[7:0])] RET – return instruction Return the execution to the last calling point. PC  (R7) 1 1 1 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 trapvector8 TRAP 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0

TRAP Example System Control Block TRAP & Interrupts Or Interrupt Vector Table In LC-2 8 bits specify one of 256 locations (x0000 to x00FF) The location contains the address of the TRAP service routine. TRAP & Interrupts Exact same mechanisms A TRAP is an instruction (event internal to a program). An interrupt is external to a program (from an I/O device) Both invoke a supervisor service routine. = x04A0 x300B R7 Service routine Address x300A

LC-2 TRAP Routines GETC (TRAP x20) OUT (TRAP x21) PUTS (TRAP x22) Read a single character from KBD. ASCII copied in R0, R0[15:8] cleared. OUT (TRAP x21) Write R0[7:0] to CRT. PUTS (TRAP x22) Write a string to CRT. String address in R0. IN (TRAP x23) Print a prompt on the screen and read a single character from KBD. Character is echoed to CRT. ASCII copied to R0[7:0] and R0[15:8] cleared. HALT (TRAP x25) Prints message on CRT & halts execution. : x0430 x0450 x04A0 x04E0 xFD70 x0000 x0020 x0021 x0022 x0023 x0024 x0025 x00FF The LC-2 System Control Block

Character Input Service Routine (IN) Figure 9.4 p.177

IN (continued)

OUT Figure 9.2 p. 178

HALT Figure 9.6 p. 181

PUTS ;puts.asm (TRAP x22) ;R0 points to null-terminated string ;R0, R1 & R3 saved; R7 is lost. .ORIG x0450 ST R7,SaveR7 ST R0,SaveR0 ST R1,SaveR1 ST R3,SaveR3 ; LOOP LDR R1,R0,#0 BRz RETURN L2 LDI R3,CRTSR BRzp L2 STI R1,CRTDR ADD R0,R0,#1 BR LOOP RETURN LD R3,SaveR3 LD R1,SaveR1 LD R0,SaveR0 LD R7,SaveR7 RET ; CRTSR .FILL xF3FC CRTDR .FILL xF3FF SaveR0 .FILL x0000 SaveR1 .FILL x0000 SaveR3 .FILL x0000 SaveR7 .FILL x0000 .END

Subroutine call examples ;Calling program .ORIG $3000 ld r1,num1 ld r2,num2 jsr multi st r3,prod HALT ; ;Input Data & Result num1 .fill x0006 num2 .fill x0003 prod .blkw 1 ;Subroutine multi ;Multiply 2 positive numbers ;Parameters: ; In: R1,R2; Out: R3 ; multi and r3,r3,#0 add r4,r1,#0 brz zero loop add r3,r2,r3 add r1,r1,#-1 brp loop zero ret .end

Library Routines Library Library routine invocation A set of routines for a specific domain application. Example: math, graphics, GUI, etc. Defined outside a program. Library routine invocation Labels for the routines are defined as external. In LC-2: .External Label Each library routine contains its own symbol table. A linker resolves the external addresses before creating the executable image.