Assignment 7, due Mar. 25

Part of the homework for 22C:112, Spring 2011
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name and the course number legibly. Exceptions will be by advance arrangement unless there is what insurance companies call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the teaching assistant's mailbox. Never push late work under someone's door!

  1. Background: Consider a memory management unit that operates using the following data structures, all defined in C:
    /* virtual addresses have 12 bits for the byte-in-page field */
    #define BYTE_IN_PAGE 12
    /* masks derived from above */
    #define BYTE_MASK ((1 << BYTE_IN_PAGE) - 1)
    #define PAGE_MASK (~BYTEMASK)
    /* access right bit names and the maximum number of rights bits */
    #define R_VALID 0
    #define R_EXEC  1
    #define R_WRITE 2
    #define R_READ  3
    #define R_CACHE 4
    #define R_DIRTY 5
    #define R_MAX   6
    /* access rights bit mask for a single right */
    #define RM(R) (1 << (R))
    /* masks for page-table fields */
    #define R_MASK      ((1 << R_MAX)-1)
    #define FRAME_MASK  (~BYTEMASK)
    #define UNUSED_MASK (~(R_MASK | FRAME_MASK))
    /* the page-table is an array of pointers to page frames */
    char * pagetable;
    /* access to fields of page table entries */
    #define FRAME(pt)  (void *)(((uintptr_t) pagetable[pt]) & FRAME_MASK)
    #define RIGHTS(pt) ((uintptr_t pagetable[pt]) & RIGHTS_MASK)
    #define EXTRA(pt)  ((((uintptr_t) pagetalbe[pt]) & EXTRA_MASK) >> R_MAX)
    /* page table entry constructor */
    #define MAKE_PT_ENTRY(f,e,r) ((void *)(((uintptr_t)f) | (e << R_MAX) | r))

    a) Write a C function that conforms to the following:

    void * convert( void * va );

    This function should take a virtual address as a parameter parameter and return the corresponding physical address, assuming that the global variable pagetable points to the current page table. (1.0 points)

    b) Write a C function that conforms to the following:

    bool checkrights( void * va, int rm );

    This function should return true if the virtual address allows the indicated set of access rights rm (the or of the masks for the individual rights desired). Assume that the global variable pagetable points to the current page table. (0.5 points)

    c) Explain why the above two functions are likely to be needed within the operating system despite the fact that the MMU must be able to do both functions in hardware. (0.5 points)

  2. Background: Assume that the MMU does not have access to the entire page table. Instead, it contains a translation lookaside buffer -- a cache, where each entry in the TLB contains, on one side, the virtual address of a page va (eqivalent to a page number shifted over to accomodate a byte-in-page field that is all zero), and on the other side, the page table entry for that address pt. Code to manipulate the MMU uses the following software interface to the MMU hardware:
    void mmu_settlb( void * va, void * pt );
    /* replaces one of the less-recently used TLB entries with [va,pt];
       it is up to the hardware to decide which entry to replace */
    void * mmu_getva();
    /* get the virtual address that caused the most recent page fault */
    int * mmu_getcause();
    /* get the cause of the most recent page fault;
       returns zero if cause was a TLB miss, otherwise returns a rights mask
       with one bit set for each access right that was violated */

    The Problem Flesh out this page fault handler so that it handles "soft page faults", that is, those associated with TLB misses.

    void page_fault_handler() {
            if --- missing code ---- {
                    --- missing code to handle soft page faults ---
            } else {
                    --- code you dont't need to write for real page faults ---
    (1 point)


Finish Machine Problem 2! Due Monday Mar. 27.