Tutorial Week 9
Questions
What is the difference between the different MIPS address space segments? What is the use of each segment?
What functions exist to help you manage the TLB? Describe their use. (Hint: look in kern/arch/mips/include/tlb.h)
What macros are used to convert from a physical address to a kernel virtual address?
What address should the initial user stack pointer be?
What are the entryhi and entrylo co-processor registers? Describe their contents.
What do the as_* functions do? Why do we need as_prepare_load() and as_complete_load()?
What does vm_fault() do? When is it called?
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:
- The page number and offset?
- The translated address (after a frame allocation if needed)?
- The contents of the page table after the access?
- What C expressions would you use to set or reset the valid bit in a page table entry?
- What C expression would you use to test if the valid bit is set?
- How would you extract the 12-bit offset (bits 0 - 11) from the virtual address?
- How would you convert the 10 most significant bits (22-31) of a virtual address into an index?
- How would you convert the next 10 most significant bits (12-21) into an index?
- How would you round down a virtual address to the base of the page?
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.
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 0x00000200And a 32-bit page table entry and 32-bit virtual address is defined as
uint32_t pte; vaddr_t vaddr;