MIPS I/O and Interrupt

Similar documents
Writing an Embedded Controller

Recitation 5: Recitation 5: MIPS Interrupts and Floating Point

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

Section 3.1: Sequences and Series

This Unit: Processor Design. What Is Control? Example: Control for sw. Example: Control for add

CS201 Discussion 10 DRAWTREE + TRIES

Section 10.4 Hyperbolas

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

Functor (1A) Young Won Lim 8/2/17

ECE 468/573 Midterm 1 September 28, 2012

Engineer To Engineer Note

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

Allocator Basics. Dynamic Memory Allocation in the Heap (malloc and free) Allocator Goals: malloc/free. Internal Fragmentation

Small Business Networking

Small Business Networking

Functor (1A) Young Won Lim 10/5/17

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

cisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:

Outline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers

Small Business Networking

Geometric transformations

Today s Lecture. Basics of Logic Design: Boolean Algebra, Logic Gates. Recursive Example. Review: The C / C++ code. Recursive Example (Continued)

UT1553B BCRT True Dual-port Memory Interface

Small Business Networking

12-B FRACTIONS AND DECIMALS

Small Business Networking

Enginner To Engineer Note

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

Small Business Networking

Small Business Networking

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe

Questions About Numbers. Number Systems and Arithmetic. Introduction to Binary Numbers. Negative Numbers?

Engineer-to-Engineer Note

Data sharing in OpenMP

Outline CS 412/413. Function calls. Stack layout. Tiling a call. Two translations

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

Lists in Lisp and Scheme

10.5 Graphing Quadratic Functions

EasyMP Multi PC Projection Operation Guide

EasyMP Multi PC Projection Operation Guide

EasyMP Network Projection Operation Guide

Address/Data Control. Port latch. Multiplexer

LCI/USB LonWorks Commissioning Interface

Fig.25: the Role of LEX

PNC NC code PROGRAMMER'S MANUAL

Small Business Networking

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

SIMPLIFYING ALGEBRA PASSPORT.

pdfapilot Server 2 Manual

EasyMP Multi PC Projection Operation Guide

Epson iprojection Operation Guide (Windows/Mac)

Small Business Networking

Midterm 2 Sample solution

EECS 281: Homework #4 Due: Thursday, October 7, 2004

COMP 423 lecture 11 Jan. 28, 2008

Epson Projector Content Manager Operation Guide

Compilers Spring 2013 PRACTICE Midterm Exam

Basics of Logic Design Arithmetic Logic Unit (ALU)

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

4452 Mathematical Modeling Lecture 4: Lagrange Multipliers

Example: 2:1 Multiplexer

Engineer-to-Engineer Note

OPERATION MANUAL. DIGIFORCE 9307 PROFINET Integration into TIA Portal

How to Design REST API? Written Date : March 23, 2015

Unit 5 Vocabulary. A function is a special relationship where each input has a single output.

McAfee Network Security Platform

Beginner s Guide to the Environment

vcloud Director Service Provider Admin Portal Guide vcloud Director 9.1

box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:

EasyMP Network Projection Operation Guide

Physics 208: Electricity and Magnetism Exam 1, Secs Feb IMPORTANT. Read these directions carefully:

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

Passwords Passwords Changing Passwords... <New Passwords> 130 Setting UIM PIN... <UIM PIN/UIM PIN2> 130 Unlocking a Locked UIM...

ITEC2620 Introduction to Data Structures

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

- 2 U NIX FILES 1. Explin different file types vilble in UNIX or P OSIX s ystem. ( 08 mrks) ( My-08/Dec-08/My-10/My- 12) 2. Wht is n API? How is it di

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

Computer Arithmetic Logical, Integer Addition & Subtraction Chapter

2 Computing all Intersections of a Set of Segments Line Segment Intersection

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

1 Quad-Edge Construction Operators

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

a Technical Notes on using Analog Devices' DSP components and development tools

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables

Using Ontrol MpBus Driver for Sedona on R-ION

Stack. A list whose end points are pointed by top and bottom

NOTES. Figure 1 illustrates typical hardware component connections required when using the JCM ICB Asset Ticket Generator software application.

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong

Reducing a DFA to a Minimal DFA

Caches I. CSE 351 Autumn Instructor: Justin Hsia

Migrating vrealize Automation to 7.3 or March 2018 vrealize Automation 7.3

Virtual Machine (Part I)

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

Caches I. CSE 351 Spring Instructor: Ruth Anderson

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

Transcription:

MIPS I/O nd Interrupt

Review Floting point instructions re crried out on seprte chip clled coprocessor 1 You hve to move dt to/from coprocessor 1 to do most common opertions such s printing, clling functions, converting number, etc There re 32 floting point registers, $f0 - $f31 You cn ccess ll 32 with single precision instructions You cn only ccess even numbered registers with double precision instructions

Review Floting point instructions use the following bbrevitions: s single precision d double precision w integer (word) c1 coprocessor 1 mt/mf move to / move from cvt convert bc1t / bc1f brnch if true/flse c compre

Review Questions tht were sked lst clss: Wht delimiter is used to construct n rry of double precision numbers?.double Also,.byte nd.hlf construct rrys of 8bit nd 16bit vlues respectively Cn you move double precision number to word in the min processor? Yes. There is psudo instruction tht moves the vlues from two floting point registers ( double) to two min registers. The first prmeter is min register nd the floting point number is stored here nd in the min register immeditely following it. E.g if you specify $t0, it will store into $t0 nd $t1 mfc1.d $v0, $f0 Other choices vilble: Convert to single precision then move cvt.s.d $f9, $f0 mtc1 $v0, $f9 Sme s the psudo instruction, but cn pick the registers you wnt mtc1 $s0, $f0 mtc1 $t0, $f1 Are there other flgs you cn use in coprocessor 1? Yes, there re 8 flgs you cn use from 0 to 7 Ex. c.le.s 4 $f0, $f1

SPIM I/O nd MIPS Interrupts The mterils of this lecture cn be found in A7-A8 (3 rd Edition) nd B7-B8 (4 th Edition). The mteril covered here will only mke brief ppernce on the midterm nd won t be on the finl nor ny exercises / homeworks It is minly used to give you bckground for future clsses such s Computer Orgniztion II nd Operting Systems

The MIPS memory Actully, everything bove 0x7fffffff is used by the system.

Wht is in there? Specil operting system functions I/O registers mpped to memory ddresses Kernel dt

SPIM Input SPIM llows you to red from the keybord (which is similr to reding something from the true I/O register)

min: witloop: done:.text.globl min li $s0, 'q' lui $t0, 0xFFFF lw $t1, 0($t0) ndi $t1, $t1, 0x0001 beq $t1, $zero, witloop lw $0, 4($t0) beq $0, $s0, done li $v0,1 syscll li $v0,4 l $0, new_line syscll j witloop li $v0, 10 syscll # q key # $t0 = 0xFFFF0000 # lod control byte # check to see if new dt is there # loop if not # lod dt byte # exit if 'q' is typed # print integer # print string # exit Remember to select ``mpped I/O in PCSpim settings. To set it, select ``Simultor then ``Settings.dt new_line:.sciiz "\n"

SPIM output Similr to the input, SPIM hs two memory loctions for output 0xffff0008: Trnsmitter control. Bit 1: interrupt enble Bit 0: redy 0xffff000c: Trnsmitter dt. Bit 0-7: dt byte

SPIM output If you need to show something on the console, do the following: 1. Check if redy bit is 1. If yes, proceed. Otherwise, wit. 2. Write to the dt. The redy bit will be reset to 0, nd will be set to 1 fter the byte is trnsmitted.

question Is this the most efficient wy to do it? Remember tht the processor usully hs lot of things to do simultneously

Interrupt The key problem is tht the time when the input occurs cnnot be predicted by your progrm Wouldn t it be nice if you could focus on wht you re doing while be interrupted if some inputs come?

MIPS interrupt With externl interrupt, if n event hppens tht must be processed, the following things will hppen: The ddress of the instruction tht is bout to be executed is sved into specil register clled EPC PC is set to be 0x80000180, the strting ddress of the interrupt hndler which tkes the processor to the interrupt hndler The lst instruction of the interrupt should be eret which sets the vlue of the PC to the vlue stored in EPC 0x80000180: EPC=0x00000128 something 0x00000128: dd $t0, $t1, $t0 sub $t2, $t1, $t0 sub $t0 $s0, $0 sll $t0, $t0, 2 dd $k0, $k1, $k0 sub $k1, $k0, $k1 eret...

MIPS Interrupt Is it oky to use $t0 in the interrupt? Note the difference between n interrupt nd function cll. For function cll, the cller is wre of the function cll, so, it is not expecting the vlue of $t0 to be the sme fter the cll. For n interrupt, the user progrm is running nd gets interrupted. The user progrm does not know bout the interruption t ll. So, if you chnged $t0 inside n interrupt, fter the interrupt returns, the user progrm will not even be wre of the fct tht it hs been interrupted, nd will use the wrong vlue of $t0. 0x80000180: EPC=0x00000128 something 0x00000128: dd $t0, $t1, $t0 sub $t2, $t1, $t0 sub $t0 $s0, $0 sll $t0, $t0, 2 dd $k0, $k1, $k0 sub $t0, $k0, $k1 eret... t0= 10 something 3000

MIPS Interrupt $k0 nd $k1 re both used s temporry vribles in interrupt servicing routines.

Interrupt Interrupt hndlers should be short. Usully should just use the interrupt to set some flgs, nd let the min progrm to check the flgs Flgs cn be registers nd cn be checked much fster thn reding the vlue of n externl pin or reding dt from other chips

.kdt # kernel dt s1:.word 10 s2:.word 11 new_line:.sciiz "\n".text.globl min min: mfc0 $0, $12 ori $0, 0xff11 mtc0 $0, $12 # red from the sttus register # enble ll interrupts # write bck to the sttus register mfc0 $k0, $13 srl $0, $k0, 2 ndi $0, $0, 0x1f bne $0, $zero, kdone lui $v0, 0xFFFF lw $0, 4($v0) li $v0,1 syscll # Cuse register # Extrct ExcCode Field # Get the exception code # Exception Code 0 is I/O. Only processing I/O here # $t0 = 0xFFFF0000 # get the input key # print it here. # Note: interrupt routine should return very fst, so # doing something like print is NOT good prctice! lui $t0, 0xFFFF # $t0 = 0xFFFF0000 li $v0,4 # print the new line ori $0, $0, 2 sw $0, 0($t0) # enble keybord interrupt # write bck to 0xFFFF0000; l $0, new_line syscll here: j here li $v0, 10 syscll.ktext 0x80000180 sw $v0, s1 sw $0, s2 # sty here forever # exit,if it ever comes here # kernel code strts here # We need to use these registers # not using the stck becuse the interrupt # might be triggered by memory reference # using bd vlue of the stck pointer kdone: lw $v0, s1 lw $0, s2 mtc0 $0, $13 mfc0 $k0, $12 ndi $k0, 0xfffd ori $k0, 0x11 mtc0 $k0, $12 eret # Restore other registers # Cler Cuse register # Set Sttus register # cler EXL bit # Interrupts enbled # write bck to sttus # return to EPC

MIPS interrupt Coprocessor 0 is prt of the CPU to hndle interrupts. In SPIM, Coprocessor 0 contins the BdVAddr (8), storing the memory ddress cusing the exception Count (9), increment by 1 every 10ms by defult Compre (11), if equls to Count, trigger n interrupt of level 5 Sttus (12), Bit 8-15: interrupt msk. A bit being ``1 mens tht this interrupt is enbled. Bit 4: user mode. With SPIM, lwys 1. Bit 1: exception level (EXL). Normlly ``0, set to ``1 if n exception occurred. When ``1, no further interrupt is enbled nd EPC is not updted. Bit 0: interrupt enble. Enble (``1 ) or disble (``0 ) ll interrupts. Cuse (13) Bit 8-15: pending interrupts. A bit being ``1 mens tht this interrupt sitution occurred, even if it is not enbled. Bit 2-6: Exception code. ``0 is hrdwre interrupt. EPC (14) Config (16), config the mchine These registers cn be red nd modified using the instructions mfc0 (move from coprocessor 0) nd mtc0 (move to coprocessor 0).