CPRE 381: Digital Systems, Logic, Programming

Spring 2006

HW#9

Due Date: Monday, April 3

 

  1. Recall the 3-deep (K/U, I.E.) stack with the status register of MIPS-1 architecture discussed in the class. I had mentioned in the class that if the nested exceptions go more than three deep, these two bits (K/U, I.E.) need to be saved on the stack. Show an exception handler that does such a saving (only the relevant program fragment). Should the exception handler keep track of current nesting depth and only save on nesting depth higher than 3 or should it always save on the stack? The restoration part is bit more tricky. Recall that rfe instruction restores the rightmost two entries (K/U, I.E.). How would the epilog of the exception handler put in the leftmost (K/U, I.E.) pair? The complicating factor is that the moment rfe is executed, you may end up losing kernel privileges (and hence access rights to the status register)!

  2. Why are exception handlers executed in higher privilege levels? Argue both the pros and cons of this design decision.

  3. Write the prioritization part of the exception handler for MIPS for the following priority scheme (in assembly). The priority order (in decreasing priority order) is as follows: SW1, SW0, HW5, HW2, HW4, HW1, HW3, HW0.

  4. Consider the following example of an exception handler (program fragment) from  MIPS manual, Page 25.

    clz  k0, k0             /* find first bit set, IP7..IP0; k0=16..23 */

    xori k0, k0, 0x17 /* 16..23 => 7..0 */

     

    At this point in the program, register k0 contains the pending interrupt bits from eight possible sources (IP0..IP7) in Bits 8..15 (counting LSB as Bit 0) with IP0 at Bit 8, IP1 at Bit 9, and IP7 at Bit 15. The objective is to determine the level number of the pending interrupt with the highest level (multiple IP bits can be 1 at the same time). Explain how these two instructions leave the level number of the highest numbered pending interrupt in k0. Note that clz instruction counts the number of leading 0’s (upto the first one scanning from left to right).