Tutorial Week 9

Questions

    Assignment 3 Exercises

    By now you should be familiar enough with navigating the kernel source that you can find the answers to the questions below by yourself (Hint: use a source code browser or the grep utility). You may also find the MIPS r3000 reference useful.

  1. What is the difference between the different MIPS address space segments? What is the use of each segment?

  2. What functions exist to help you manage the TLB? Describe their use. (Hint: look in kern/arch/mips/include/tlb.h)

  3. What macros are used to convert from a physical address to a kernel virtual address?

  4. What address should the initial user stack pointer be?

  5. What are the entryhi and entrylo co-processor registers? Describe their contents.

  6. What do the as_* functions do? Why do we need as_prepare_load() and as_complete_load()?

  7. What does vm_fault() do? When is it called?

  8. Assume a 2-level hierarchical page table with 4k pages, with 10 bits resolved at each level, i.e. both the first and second-level page tables are arrays of entries of size 1024.

    The page table is initially empty, with a top-level table filled with invalid entries and no level-two tables. Assume that a frame allocator is set up to return frames in the sequence 1, 2, 3, 4 etc. Virtual addresses are now accessed in this order:

    • 0x100008
    • 0x101008
    • 0x1000f0
    • 0x41000
    • 0x41b00
    • 0x410000

    For each of these virtual address accesses, what is:

    1. The page number and offset?
    2. The translated address (after a frame allocation if needed)?
    3. The contents of the page table after the access?
  9. C bitwise operations refresher

    Given the following constants from the source code:

    #define TLBHI_VPAGE   0xfffff000
    #define TLBLO_PPAGE   0xfffff000
    #define TLBLO_NOCACHE 0x00000800
    #define TLBLO_DIRTY   0x00000400
    #define TLBLO_VALID   0x00000200
      
    And a 32-bit page table entry and 32-bit virtual address is defined as
        uint32_t pte;
        vaddr_t vaddr;
      
  10. What C expressions would you use to set or reset the valid bit in a page table entry?
  11. What C expression would you use to test if the valid bit is set?
  12. How would you extract the 12-bit offset (bits 0 - 11) from the virtual address?
  13. How would you convert the 10 most significant bits (22-31) of a virtual address into an index?
  14. How would you convert the next 10 most significant bits (12-21) into an index?
  15. How would you round down a virtual address to the base of the page?