MIPS I/O and Interrupt.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CS/COE0447 Computer Organization & Assembly Language
Lecture 9: MIPS Instruction Set
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
SPIM and MIPS programming
Some Samples of MIPS Assembly Language Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University.
MIPS Function Continued
Input and Output CS 215 Lecture #20.
Writing an Embedded Controller. It usually consists of two parts – Initialization – A main loop Experience: – The main loop usually has to deal with many.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
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.
Interrupts STOP!!! Do this!!!. CMPE12cGabriel Hugh Elkaim 2 Interrupts Have device tell OS/CPU it is ready Requires hardware to support. OS/CPU can then.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Writing an Embedded Controller. It usually consists of two parts – Initialization – A main loop More challenging than HW3 because HW3 is stateless, the.
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
COMP201 Computer Systems Exceptions and Interrupts.
Input and Output Computer Organization and Assembly Language: Module 9.
Writing an Embedded Controller. It usually consists of two parts – Initialization – A main loop More challenging than HW3 because HW3 is stateless, the.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Lecture 4: MIPS Instruction Set
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
HW4. A TV controller Let’s use this lecture to start to develop a simple TV controller together.
Exceptions and Interrputs CS 321 – Introduction to Computer Architecture and Machine-Level Programming Barry Britt, Systems Analyst II Department of Computer.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
MISP Exception Facility Supported by SPIM simulator.
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.
Exceptions and Interrupts ◆ Breakpoints, arithmetic overflow, traps, and interrupts are all classified as exceptions. ◆ An exception is an event that requires.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Computer Organization CS224
MIPS Instruction Set Advantages
Computer System Structures
Writing an Embedded Controller
MIPS I/O and Interrupt.
Timer and Interrupts.
the Operating System (OS)
MIPS Procedures.
Computer Architecture
MIPS I/O and Interrupt.
Assembly Programming using MIPS R3000 CPU
MIPS coding.
MIPS I/O and Interrupt.
MIPS Procedures.
Solutions Chapter 2.
MIPS coding.
MIPS Functions.
Lecture 5: Procedure Calls
MIPS coding.
Review.
MIPS function continued
Interrupts and Exception Handling
MIPS I/O and Interrupt.
Writing an Embedded Controller
Assembly Programming using MIPS R3000 CPU
MIPS Assembly.
MIPS coding.
CS61C - Machine Structures Lecture 14 - Input/Output
MIPS Functions.
Interrupts and Exception Handling
MIPS instructions.
Presentation transcript:

MIPS I/O and Interrupt

SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3rd Edition) and B7-B8 (4th Edition).

The MIPS memory Actually, everything above 0x7fffffff is used by the system.

What is in there? Special operating system functions I/O registers mapped to memory addresses Kernel data …

SPIM Input SPIM allows you to read from the keyboard (which is similar to reading something from the true I/O register)

Remember to select ``mapped I/O’’ in PCSpim settings. .text .globl main main: addi $s0, $0, 113 # q key lui $t0, 0xFFFF # $t0 = 0xFFFF0000; waitloop: lw $t1, 0($t0) andi $t1, $t1, 0x0001 beq $t1, $zero, waitloop lw $a0, 4($t0) beq $a0, $s0, done li $v0,1 syscall li $v0,4 la $a0, new_line j waitloop done: li $v0, 10 # exit .data new_line: .asciiz "\n” Remember to select ``mapped I/O’’ in PCSpim settings. To set it, select ``Simulator’’ then ``Settings…’’

SPIM output Similar to the input, SPIM has two memory locations for output 0xffff0008: Transmitter control. Bit 1: interrupt enable Bit 0: ready 0xffff000c: Transmitter data. Bit 0-7: data byte

SPIM output If you need to show something on the console, do the following: Check if ready bit is 1. If yes, proceed. Otherwise, wait. Write to the data. The ready bit will be reset to 0, and will be set to 1 after the byte is transmitted.

question Is this the most efficient way to do it? Remember that the processor usually has a lot of things to do simultaneously

Interrupt The key problem is that the time when the input occurs cannot be predicted by your program Wouldn’t it be nice if you could “focus on what you are doing” while be “interrupted” if some inputs come?

MIPS interrupt EPC= something EPC=0x00000128 With external interrupt, if an event happens that must be processed, the following things will happen: The address of the instruction that is about to be executed is saved into a special register called EPC PC is set to be 0x80000180, the starting address of the interrupt handler which takes the processor to the interrupt handler The last instruction of the interrupt should be “eret” which sets the value of the PC to the value stored in EPC a a add $t0, $t1, $t0 a a sub $t2, $t1, $t0 a a sub $t0 $s0, $a0 0x00000128: a a sll $t0, $t0, 2 . 0x80000180: a a add $k0, $k1, $k0 a a sub $k1, $k0, $k1 a a eret

MIPS Interrupt Is it okay to use $t0 in the interrupt? EPC= something EPC=0x00000128 t0= something t0= 10 t0= 3000 Is it okay to use $t0 in the interrupt? Note the difference between an interrupt and a function call. For a function call, the caller is aware of the function call, so, it is not expecting the value of $t0 to be the same after the call. For an interrupt, the user program is running and gets interrupted. The user program does not know about the interruption at all. So, if you changed $t0 inside an interrupt, after the interrupt returns, the user program will not even be aware of the fact that it has been interrupted, and will use the wrong value of $t0. a a add $t0, $t1, $t0 a a sub $t2, $t1, $t0 a a sub $t0 $s0, $a0 0x00000128: a a sll $t0, $t0, 2 . 0x80000180: a a add $t0, $k1, $k0 a a sub $t0, $k0, $k1 a a eret

Interrupt Interrupt handlers should be short. Usually should just use the interrupt to set some flags, and let the main program to check the flags Flags can be registers and can be checked much faster than reading from the outside

MIPS interrupt Coprocessor 0 is a part of the CPU to handle interrupts. In SPIM, Coprocessor 0 contains the BadVAddr (8), storing the memory address causing the exception Count (9), increment by 1 every 10ms by default Compare (11), if equals to Count, trigger an interrupt of level 5 Status (12), Bit 8-15: interrupt mask. A bit being ``1’’ means that this interrupt is enabled. Bit 4: user mode. With SPIM, always 1. Bit 1: exception level (EXL). Normally ``0,’’ set to ``1’’ if an exception occurred. When ``1,’’ no further interrupt is enabled and EPC is not updated. Bit 0: interrupt enable. Enable (``1’’) or disable (``0’’) all interrupts. Cause (13) Bit 8-15: pending interrupts . A bit being ``1’’ means that this interrupt situation occurred, even if it is not enabled. Bit 2-6: Exception code. ``0’’ is hardware interrupt. EPC (14) Config (16), config the machine These registers can be read and modified using the instructions mfc0 (move from coprocessor 0) and mtc0 (move to coprocessor 0).

MIPS Interrupt $k0 and $k1 are both used as temporary variables in interrupt servicing routines.

Code we used (Copy and paste it to an editor) .data new_line: .asciiz "\n" .text .globl main main: mfc0 $a0, $12 # read from the status register ori $a0, 0xff11 # enable all interrupts mtc0 $a0, $12 # write back to the status register lui $t0, 0xFFFF # $t0 = 0xFFFF0000; ori $a0, $0, 2 # enable keyboard interrupt sw $a0, 0($t0) # write back to 0xFFFF0000; li $s6, 10000 # $s6 used to pass the ascii code li $s7, 10000 # a large number impossible to be an ascii code loop: beq $s6, $s7, loop ori $a0, $s6, 0 li $v0,1 # print it here. syscall li $v0,4 # print the new line la $a0, new_line mfc0 $t0, $12 # Set Status register andi $t0, 0xfffe # clear ENABLE mtc0 $t0, $12 # write back to status li $s6, 10000 # $s0 used to pass the ascii code ori $t0, 1 # set ENABLE j loop li $v0, 10 # exit,if it ever comes here .kdata # kernel data s1: .word 10 s2: .word 11 .ktext 0x80000180 # kernel code starts here sw $v0, s1 # To show how to save, we use these registers sw $a0, s2 # not using the stack because the interrupt might be # triggered by a memory reference # using a bad value of the stack pointer mfc0 $k0, $13 # Cause register srl $a0, $k0, 2 # Extract ExcCode Field andi $a0, $a0, 0x1f bne $a0, $zero, kdone # Exception Code 0 is I/O. Only processing I/O here lui $v0, 0xFFFF # $v0 = 0xFFFF0000; lw $s6, 4($v0) # get the input key kdone: lw $v0, s1 # Restore other registers lw $a0, s2 mtc0 $0, $13 # Clear Cause register mfc0 $k0, $12 # Set Status register andi $k0, 0xfffd # clear EXL bit ori $k0, 0x11 # Interrupts enabled mtc0 $k0, $12 # write back to status eret # return to EPC

Questions Which of the following statements about the MIPS interrupt mechanism is true? (a) $EPC is created mainly for robustness. The interrupt can actually use $ra to save the return address. (b) It is okay to modify $t0 inside the interrupt because the main program is not expecting $t0 to be unmodified after the interrupt. (c) Both of the above. (d) None of the above. d

Questions Suppose a MIPS interrupt handler modifies $at but forgets to restore it before returning. Suppose the interrupt is invoked only once. After it is invoked, which of the following statements is true? (a) The main program will not run correctly. (b) The main program will not run correctly only if the interrupt is invoked during a function call. (c) The main program will run correctly. (d) None of the above. d