Lecture 12 Input/Output (programmer view)

Slides:



Advertisements
Similar presentations
Dr. Rabie A. Ramadan Al-Azhar University Lecture 3
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
CS-334: Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
1 Computer System Overview OS-1 Course AA
Chapter 7 Interupts DMA Channels Context Switching.
Basic Input/Output Operations
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Embedded Systems 7763B Mt Druitt College of TAFE
System Calls 1.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Overview of Hardware.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Computer Architecture Lecture10: Input/output devices Piotr Bilski.
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
OPERATING SYSTEMS Goals of the course Definitions of operating systems Operating system goals What is not an operating system Computer architecture O/S.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Computer System Structures Interrupts
Chapter 8 I/O.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and exceptions
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Computer Architecture
CS 3305 System Calls Lecture 7.
Dr. Michael Nasief Lecture 2
Chapter 8 I/O.
Computer Architecture
Chapter 10 The Stack.
The slides must be understood in Lecture 5
Chapter 8 I/O.
Operating Systems Chapter 5: Input/Output Management
Chapter 8 I/O.
Architectural Support for OS
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
MIPS I/O and Interrupt.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Lecture 6 CdM-8 CPU overview
Lecture 13 Harvard architecture Coccone OS demonstrator
Lecture 7 System architecture Input-output
COMP3221: Microprocessors and Embedded Systems
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Lecture 12 Input/Output (programmer view) Computing platforms Novosibirsk State University University of Hertfordshire D. Irtegov, A.Shafarenko 2018

Memory-mapped input/output Device can be mapped to memory address In next semester we will see what “mapping” actually means For now, let’s imagine that memory cell 0xf3 is not a memory cell But a register of external device When you read or write this register, device can perform some action Or vice versa, when a device performs some action, data are written to the register (and you can read it later)

Simple device – a keyboard Actually, not so simple (schematics is present in CdM-8 book) When you press the key, 7-bit ASCII code is written to latch register And 8-th bit of the register is set to 1 (strobe bit). When you (CPU) read the register (cell at 0xf3), strobe bit is cleared This way you can know if the new key was pressed Or the same key was pressed several times

Things to consider For memory-mapped I/O, CdM-8 reserves upper 16 bits of memory This allows for 16 devices, or, more specifically, 16 I/O registers Single device can have several I/O registers Or two devices can share one address for their registers (e.q. one device maps register for write operations and another for reading) We must move stack below i/o page before doing any push and pop Use addsp, not 16 push commands!

How to actually input the data? ldi r0, 0xf3 while ld r1, r0 tst r1 stays gt wend This is called busy wait

Why busy wait is good? It works even for simplest hardware (better ways require special hardware support) It is simple to program and debug It is fast

Why busy wait is bad? You cannot do anything else when busy waiting for a single event You must adapt your code when you wait for several events You cannot stop CPU while busy waiting For CdM-8, this is not a problem For real CPU, it leads to high power consumption and heating If all CPU cores of typical modern smartphone will busy wait, they will eat all the battery in < than a hour

Interrupt Interrupt is a hardware mechanism implemented in CdM-8 and most ”real” modern CPU Interrupts allow hardware devices to call software routines Typically, interrupt signals that device has some data for you For example, keyboard has a new key pressed Or network interface has a new data packet received This is different from pure software call, but also very similar Details are different between CPUs and systems Let’s discuss CdM-8 interrupts

Interrupts from software point of view Every interrupt-capable device has unique number on range 0 to 7 Every possible value of device numbers selects a byte pair, called interrupt vector By default, interrupt vectors are mapped to upper 16 bytes of memory In Manchester architecture, these are same bytes as used for memory mapped I/O, so you cannot use all 7 interrupts and all 16 register addresses In Harvard architecture, I/O is mapped to data memory, and vectors to program memory

But what happens when interrupt occurs? Device sets IRQ request on CPU input line When CPU finishes every instruction, it polls IRQ request line If interrupts are enabled (we will discuss this later), it retrieves device number Then, instead of next instruction at mem[PC], ioi instruction is executed In some sence, ioi is “normal” instruction: it has an opcode, it can be inserted in a machine code and executed like any other command This is called “software interrupt” But during interrupt, no ioi instruction is present at mem[PC] But CPU behaves like it fetched this instruction

Ioi instruction Phase 1 decrement SP for stack push Phase 2 store PC on stack; decrement SP for stack push Phase 3 store PS on stack Phase 4 fetch new PC value from vector’s first cell (0xf0 + 2R) Phase 5 fetch new PS value from vector’s second cell (0xf1 + 2R) It is similar to jsr, but two registers are saved (PC and PS) You need to use rti instruction to return from ioi routine And call target depends on hardware (device number R) So you can write separate handler routine for every device

What you can do in interrupt handler? Typically, interrupt signals that device has some data for you So you must retrieve the data Some devices require further instructions, what to do next For example, when you read data from the disk, you must tell the disk what sector to read or write next (or not tell anything and disk will be idle) Then you must set some flags so main program will know the data are ready Then you must return to main program (execute an rti instruction) Or you can do something else (we will discuss it in Operating Systems course)

Why interrupts are bad? They are asynchronous They can occur in any moment of program execution It is very easy to write a handler that can break a main program (damage its data) And it is very hard to catch this condition by testing So, there is a mechanism to disable interrupts (a flag in PS register) Interrupt handling is a simplest (and historically first) form of parallel programming, and parallel programming has many pitfalls And most of these pitfalls are hard to avoid There will be courses on concurrency and parallel programming further in our curriculum

Why interrupts are good? You can handle several event sources at same time You do not need to rewrite your program to add another event source You can do something useful when waiting for an event Operating systems use interrupts to implement multithreading and multitasking

Ring buffer A simple technique which helps to avoid many pitfalls of parallel (asynchronous) programming We will hear about ring buffers and queues in Operating Systems course Ring buffer is very easy to implement in assembler In C course you’ve seen queue and stack on linked lists In our course, we’ve seen stack implementation on array Ring buffer is queue implemented on the array

Ring buffer (continued)

How it works? When interrupt handler retrieves the data, it advances end pointer and stores the data. When array ends, it wraps over (this is why it’s called a ring buffer) When main program processed the data, it advances head pointer (probably wrapping over) and retrieves the data When head pointer meets end pointer, queue is considered empty (main program must wait using busy wait or wait instruction) Instead of busy wait, main program can tell OS not to schedule it (but again this is topic of another course. We have no OS in our course) When end pointer meets head pointer, queue is considered full (interrupt handler cannot store data and must drop new data)

Ring buffers and queues are everywhere Many smart peripherial devices have internal buffers or queues, so they can send interrupts not so often, and CPU can process their data in batches Many things you will see in networks and operating systems (disc caches, pipes, sockets, network switches and routers) are ring buffers or queues or something built around a ring buffer or queue