Chapter 8 Input/Output

Similar documents
I/O. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

Chapter 8 I/O. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. But where does data in memory come from?

LC-3 Input and Output

LC-3 Input and Output

Chapter 8 I/O. Computing Layers. I/O: Connecting to Outside World. I/O: Connecting to the Outside World

Introduction to Computer Engineering. CS/ECE 252, Fall 2012 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

Input & Output. Lecture 16. James Goodman (revised by Robert Sheehan) Computer Science 210 s1c Computer Systems 1 Lecture Notes

LC3DataPath ECE2893. Lecture 9a. ECE2893 LC3DataPath Spring / 14

Input/Output Interfaces: Ch

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

COSC121: Computer Systems: Review

CS 2461: Computer Architecture I

11/28/2016. ECE 120: Introduction to Computing. Register Loads Control Updates to Register Values. We Consider Five Groups of LC-3 Control Signals

Special Microarchitecture based on a lecture by Sanjay Rajopadhye modified by Yashwant Malaiya

The LC-3 Instruction Set Architecture. ISA Overview Operate instructions Data Movement instructions Control Instructions LC-3 data path

8.1 I/O Basics Device Registers. chapter

Midterm 2 Review Chapters 4-16 LC-3

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

LC-3 Instruction Processing. (Textbook s Chapter 4)

LC-3 Instruction Processing

Introduction to Computer Engineering. Chapter 5 The LC-3. Instruction Set Architecture

EEL 5722C Field-Programmable Gate Array Design

Computing Layers. Chapter 5 The LC-3

Chapter 4 The Von Neumann Model

The von Neumann Model

Chapter 4 The Von Neumann Model

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

Instruction Set Architecture

Chapter 5 - ISA. 1.The Von Neumann Model. The Stored Program Computer. Von Neumann Model. Memory

COSC121: Computer Systems: Review

Register Files. Single Bus Architecture. Register Files. Single Bus Processor. Term Project: using VHDL. Accumulator based architecture

Chapter 4 The Von Neumann Model

Computer Architecture Lecture 6: Multi-Cycle and Microprogrammed Microarchitectures

Introduction to Computer Engineering. CS/ECE 252 Prof. Mark D. Hill Computer Sciences Department University of Wisconsin Madison

CS 270 Fall 2013 Mock Final

LC-3 Architecture. (Ch4 ish material)

Department of Electrical and Computer Engineering The University of Texas at Austin

Computer Architecture. Lecture 5: Multi-Cycle and Microprogrammed Microarchitectures

appendix a The LC-3 ISA A.1 Overview

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

Trap Vector Table. Interrupt Vector Table. Operating System and Supervisor Stack. Available for User Programs. Device Register Addresses

LC-3 Instruction Set Architecture. Textbook Chapter 5

Lec-memMapIOtrapJSR SYS_BUS

10/31/2016. The LC-3 ISA Has Three Kinds of Opcodes. ECE 120: Introduction to Computing. ADD and AND Have Two Addressing Modes

CIT 593: Intro to Computer Systems Homework #4: Assembly Language Due October 18, 2012, 4:30pm. Name

( input = α output = λ move = L )

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON. Instructor: Rahul Nayar TAs: Mohit Verma, Annie Lin

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Implement useq's FSM's --- Next-state function --- Output function. We know: Any function can be implemented in AND-OR

20/08/14. Computer Systems 1. Instruction Processing: FETCH. Instruction Processing: DECODE

Computer Architecture Review CS 595

Control unit. Input/output devices provide a means for us to make use of a computer system. Computer System. Computer.

Beyond One Core. Multi-Cores. Evolution in Frequency Has Stalled. Source: ISCA 2009 Keynote of Kathy Yelick

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS 2200 Spring 2008 Test 1

ECE331: Hardware Organization and Design

Intro. to Computer Architecture Homework 4 CSE 240 Autumn 2005 DUE: Mon. 10 October 2005

OPERATING SYSTEMS CS136

LC-3 Instruction Set Architecture

컴퓨터개념및실습. 기말고사 review

CPSC 213. Introduction to Computer Systems. I/O Devices, Interrupts and DMA. Unit 2a Oct 27, 29, 31. Winter Session 2014, Term 1

Outcomes. Lecture 13 - Introduction to the Central Processing Unit (CPU) Central Processing UNIT (CPU) or Processor

Microprogrammed Control. ECE 238L μseq 2006 Page 1

Advanced Parallel Architecture Lesson 3. Annalisa Massini /2015

Department of Electrical and Computer Engineering The University of Texas at Austin

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

UNIVERSITY OF WISCONSIN MADISON

I/O and Device Drivers

COSC121: Computer Systems. Exceptions and Interrupts

Design of Digital Circuits Lecture 15: Pipelining. Prof. Onur Mutlu ETH Zurich Spring April 2017

ECE Homework 8

Class Notes. Dr.C.N.Zhang. Department of Computer Science. University of Regina. Regina, SK, Canada, S4S 0A2

PC Interrupt Structure and 8259 DMA Controllers

Our Simulation Equivalent: -- readmemb( "os.bin" ) -- PC <== x0200

Computer Organization

Subroutines & Traps. Announcements. New due date for assignment 2 5pm Wednesday, 5May

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

William Stallings Computer Organization and Architecture. Chapter 11 CPU Structure and Function

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

LC-3 Subroutines and Traps. (Textbook Chapter 9)"

Chapter 5: Computer Systems Organization. Invitation to Computer Science, C++ Version, Third Edition

Chapter 5: Computer Systems Organization

CPU Structure and Function

William Stallings Computer Organization and Architecture

CPU ARCHITECTURE. QUESTION 1 Explain how the width of the data bus and system clock speed affect the performance of a computer system.

Digital System Design Using Verilog. - Processing Unit Design

Computer Architecture 2/26/01 Lecture #

Department of Electrical and Computer Engineering The University of Texas at Austin

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

LC-2 Programmer s Reference and User Guide

Micro-Operations. execution of a sequence of steps, i.e., cycles

LC-3 TRAP Routines. Textbook Chapter 9

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

Anne Bracy CS 3410 Computer Science Cornell University

CPU Structure and Function

EN1640: Design of Computing Systems Topic 07: I/O

Transcription:

Lecture on Introduction to Computing Systems Chapter 8 Input/Output An Hong han@ustc.edu.cn 0 Fall School of Computer Science and Technology 0/11/3 1

Review So far, we ve learned how to: compute with values in registers load data from memory to registers store data from registers to memory MEMORY MAR MDR INPUT Keyboard Mouse Scanner Disk PROCESSING UNIT ALU TEMP OUTPUT Monitor Printer LED Disk CONTROL UNIT PC IR 0/11/3

Review: LC-3 Data Path GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE LD.IR IR [7:0] Control Unit ADDR [10:0] [8:0] [5:0] [4:0] + N Z P LOGIC LD.CC ADDR1 FINITE STATE MACHINE SR SR1 Processing SR SR1 3 OUT OUT 3 ALUK Unit SR A ALU B RUN GateALU GateMDR LD.MDR Memory MDR Unit MEMORY MAR MEM.EN,R,W LD.MAR INPUT OUTPUT 3

Need for I/O But where does data in memory come from? And how does data get out of the system so that humans can use it? Computer systems are useless unless they can process information from outside of the computer and output results outside of the computer I/O is effectively the communication with outside of the computer I/O device itself communicates with outside world E.g., keyboard takes input from user Computer needs to communicate with I/O device E.g., computer takes input from keyboard Communication through shared memory locations Processor and I/O can read/write those memory locations Sometimes, data in memory locations can be set/cleared automatically (by hardware) depending on a read/write 0/11/3 4

I/O: Connecting to the Outside World Examples Keyboard/mouse input, video output on a standard computer Network input/output that enables web surfing Information from an engine of a car that a computer uses to determine how to tune the engine (output from computer tunes the engine) Requests for airline reservations and replies that service those requests Types of I/O devices characterized by: behavior: input, output, storage - input: keyboard, motion detector, network interface - output: display screen(monitor), printer, network interface - storage: disk, CD-ROM data rate: how fast can data be transferred? - keyboard: 100 bytes/sec - disk: 30 MB/s - network: 1 Mb/s - 1 Gb/s 0/11/3 5

I/O Controller Control/Status Registers CPU tells device what to do -- write to control register CPU checks whether task is done -- read status register Data Registers CPU transfers data to/from device Control/Status Graphics Controller CPU Output Data Electronics display Device electronics performs actual operation - pixels to screen, bits to/from disk, characters from keyboard 0/11/3 6

Programming Interface How are device registers identified? Memory-mapped vs. special instructions How is timing of transfer managed? Asynchronous vs. synchronous Who controls transfer? CPU (polling) vs. device (interrupts) 0/11/3 7

Memory-Mapped vs. I/O Instructions Instructions designate opcode(s) for I/O register and operation encoded in instruction Memory-mapped assign a memory address to each device register use data movement instructions (LD/ST) for control and data transfer 0x FE00 0/11/3 8

Transfer Timing I/O events generally happen much slower than CPU cycles. If : CPU 300MHz, 10clocks/character,6characters/word Then: typing speed (1/(300x10 6 ))x10x6=5x10 6 words/s Synchronous data supplied at a fixed, predictable rate CPU reads/writes every X cycles Asynchronous data rate less predictable CPU must synchronize with device, so that it doesn t miss data or write too quickly 0/11/3 9

Transfer Control Who determines when the next data transfer occurs? CPU vs. I/O device Polling is explicitly looking/examining CPU keeps checking status register until new data arrives OR device ready for next data Are you there yet? Are you there yet? Are you there yet? Interrupts is a nudge, knock on the door, loud noise, which forces you to pay attention Device sends a special signal to CPU when new data arrives OR device ready for next data CPU can be performing other tasks instead of polling device. Wake me when you get there. 0/11/3 10

LC-3 Memory-mapped I/O (Table A.1) Location I/O Register Function xfe00 xfe0 xfe04 xfe06 Keyboard Status Reg (KBSR) Keyboard Data Reg (KBDR) Display Status Register (DSR) Display Data Register (DDR) Bit [15] is one when keyboard has received a new character. Bits [7:0] contain the last character typed on keyboard. Bit [15] is one when device ready to display another char on screen. Character written to bits [7:0] will be displayed on screen. Asynchronous devices synchronized through status registers Polling and Interrupts the details of interrupts will be discussed in Chapter 10 0/11/3 11

Memory map of the LC-3 0x0000 0x00FF 0x0100 0x01FF 0x000 0xFFF 0x3000 Trap Vector Table Interrupt Vector Table Operating System and Supervisor Stack Program Text PC Global data section Heap (for dynamically allocated memory) R4(Global pointer) Function1 Function R6 R5 R6 R5 0xFDFF 0xFE00 0xFFFF Run-time stack Device Register Addresses R6 (stack pointer) R5 (frame pointer) Function3 0/11/3 1 R6 R5

Example: Processor Input from Keyboard When a character is typed: its ASCII code is placed in bits [7:0] of KBDR (bits [15:8] are always zero) the ready bit (KBSR[15]) is set to one keyboard is disabled -- any typed characters will be ignored ready bit 15 8 7 0 1514 0 KBDR KBSR keyboard data When KBDR is read: KBSR[15] is set to zero, meaning no keyboard key is pending keyboard is enabled 0/11/3 13

Memory-mapped Operations How do we read ready bit? How do we test whether the bit is one? How do we read keyboard data? 0/11/3 14

Basic Input Routine Polling NO new char? YES read character POLL KBSR KBDR LDI R0, KBSR BRzp POLL LDI R0, KBDR....FILL xfe00.fill xfe0 0/11/3 15

IN Memory-mapped I/O GateMDR MAR LD.MAR MDR LD.MDR MEM.R,W INPUT OUTPUT MEMORY ADDR.CTL LOGIC KBDR KBSR LD.DDR DDR DSR MEM.EN, READ/WRITE 0/11/3

LDI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 17

LDI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 18

RUN LD.CC MEM.EN,R,W MAR LD.MAR PC GatePC 19 ALU A B SR INPUT OUTPUT MEMORY FINITE STATE MACHINE N Z P LOGIC + DR LD.REG SR SR1 ALUK REG FILE SR1 OUT SR OUT GateALU ADDR1 3 3 3 PC +1 MAR [10:0] [8:0] [5:0] [4:0] [7:0] GateMAR LD.PC ADDR LD.IR IR MDR LD.MDR GateMDR LDI (Indirect) EA OP EX S F D

LDI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 0

LDI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 1

LDI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W

IN Memory-mapped I/O: LDI R0, KBSR GateMDR MAR LD.MAR MDR LD.MDR MEM.R,W INPUT OUTPUT MEMORY ADDR.CTL LOGIC KBDR KBSR LD.DDR DDR DSR MEM.EN, READ/WRITE 0/11/3 3

IN Memory-mapped I/O: LDI R0, KBDR GateMDR MAR LD.MAR MDR LD.MDR MEM.R,W INPUT OUTPUT MEMORY ADDR.CTL LOGIC KBDR KBSR LD.DDR DDR DSR MEM.EN, READ/WRITE 0/11/3 4

LD.IR MEM.EN,R,W MAR LD.MAR MEMORY 3 SR1 SR 3 SR [10:0] [8:0] [5:0] [4:0] INPUT PC GatePC 5 OUTPUT + ADDR1 PC +1 MAR [7:0] GateMAR LD.PC ADDR LD.MDR ALU A B ALUK GateALU DR LD.REG REG FILE SR1 OUT SR OUT 3 FINITE STATE MACHINE N Z P RUN LOGIC LD.CC IR MDR GateMDR LDI (Indirect) EA OP S D F EX

Example: Processor Output to Screen When Display device is ready to display another character: the ready bit (DSR[15]) is set to one, indicating that processor can write a character for display ready bit 15 8 7 0 1514 0 DDR DSR output data When data is written to the Display data register: DSR[15] automatically set to 0 character in DDR[7:0] is displayed any other character data written to DDR is ignored (while DSR[15] is zero) 0/11/3 6

Basic Output Routine Polling NO screen ready? YES write character POLL DSR DDR LDI R1, DSR BRzp POLL STI R0, DDR....FILL xfe04.fill xfe06 0/11/3 7

STI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 8

STI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 9

RUN LD.CC MEM.EN,R,W MAR LD.MAR PC GatePC 30 ALU A B SR INPUT OUTPUT MEMORY FINITE STATE MACHINE N Z P LOGIC + DR LD.REG SR SR1 ALUK REG FILE SR1 OUT SR OUT GateALU ADDR1 3 3 3 PC +1 MAR [10:0] [8:0] [5:0] [4:0] [7:0] GateMAR LD.PC ADDR LD.IR IR MDR LD.MDR GateMDR STI (Indirect) EA OP EX S F D

STI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 31

STI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 3

STI (Indirect) F D EA OP EX S GateMAR MAR GatePC LD.PC PC PC +1 DR LD.REG 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 33

STI (Indirect) F D EA OP EX OP GateMAR MAR GatePC LD.PC PC PC +1 LD.REG DR 3 REG FILE [7:0] + SR 3 SR SR1 OUT OUT 3 SR1 ADDR ADDR1 LD.IR [10:0] [8:0] [5:0] [4:0] IR LD.CC N Z P LOGIC FINITE STATE MACHINE SR ALUK A ALU B RUN GateALU GateMDR LD.MDR MDR MAR LD.MAR MEMORY INPUT OUTPUT MEM.EN,R,W 34

IN Memory-mapped I/O: STI R0, DDR? GateMDR MAR LD.MAR MDR LD.MDR MEM.R,W INPUT OUTPUT MEMORY ADDR.CTL LOGIC KBDR KBSR LD.DDR DDR DSR MEM.EN, READ/WRITE 0/11/3 35

Keyboard Echo Routine Usually, input character is also printed to screen. User gets feedback on character typed and knows its ok to type the next character. POLL1 POLL LDI R0, KBSR BRzp POLL1 LDI R0, KBDR LDI R1, DSR BRzp POLL STI R0, DDR NO new char? YES read character KBSR KBDR DSR DDR....FILL xfe00.fill xfe0.fill xfe04.fill xfe06 NO screen ready? YES write character 0/11/3 36

Interrupt-Driven I/O To implement an interrupt mechanism, we need: A way for the I/O device to signal the CPU that an interesting event has occurred. A way for the CPU to test whether the interrupt signal is set. Generating Signal Software sets "interrupt enable(ie)" bit in device register. When ready bit is set and IE bit is set, interrupt is signaled. interrupt enable bit ready bit 151413 0 KBSR interrupt signal to processor 0/11/3 37

Interrupt-Driven I/O Testing for Interrupt Signal CPU looks at signal between STORE and FETCH phases If not set, continues with next instruction If set, transfers control to Interrupt Service Routine(ISR) F NO D Transfer to ISR YES interrupt signal? EA OP EX More details in Chapter 10. S 0/11/3 38

Review Questions What is the danger of not testing the DSR before writing data to the Display screen? What is the danger of not testing the KBSR before reading data from the keyboard? What if the Display were a synchronous device, e.g., we know that it will be ready 1 microsecond after character is written. Can we avoid polling? How? What are advantages and disadvantages? 0/11/3 39

Review Questions Do you think polling is a good approach for other devices, such as a disk or a network interface? What is advantage of using LDI/STI for accessing device registers? 0/11/3 40