Implement VM #63
@@ -12,17 +12,16 @@ void
|
|||||||
page_set_swap (struct thread *owner, void *upage, size_t swap_slot)
|
page_set_swap (struct thread *owner, void *upage, size_t swap_slot)
|
||||||
{
|
{
|
||||||
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
||||||
*pte &= ~PTE_P; //clears the first bit (present bit) to be 0
|
|
||||||
|
|
||||||
//ASSERT (swap_slot < (1 << 20)); //not sure if this is needed
|
/* Store the provided swap slot in the address bits of the page table
|
||||||
|
entry, truncating excess bits. */
|
||||||
//shifts the swap slot addr to take up bits 31 to 12
|
*pte |= (1 << SWAP_FLAG_BIT);
|
||||||
//uses bitwise & to make sure it does not affect flags
|
|
||||||
//then applies it to pte
|
|
||||||
*pte |= (1 << SWAP_FLAG_BIT); // sets the 9th bit
|
|
||||||
uint32_t swap_slot_bits = (swap_slot << ADDR_START_BIT) & PTE_ADDR;
|
uint32_t swap_slot_bits = (swap_slot << ADDR_START_BIT) & PTE_ADDR;
|
||||||
*pte = (*pte & PTE_FLAGS) | swap_slot_bits;
|
*pte = (*pte & PTE_FLAGS) | swap_slot_bits;
|
||||||
|
|
||||||
|
/* Mark page as 'not present' and flag the page directory as having
|
||||||
|
been modified. */
|
||||||
|
pagedir_clear_page (owner->pagedir, upage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given that the page with user address 'upage' owned by 'owner' is flagged
|
/* Given that the page with user address 'upage' owned by 'owner' is flagged
|
||||||
@@ -33,11 +32,10 @@ page_get_swap (struct thread *owner, void *upage)
|
|||||||
{
|
{
|
||||||
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
||||||
|
|
||||||
//these should always be checked and true before using this func
|
|
||||||
ASSERT ((*pte & PTE_P) == 0);
|
ASSERT ((*pte & PTE_P) == 0);
|
||||||
ASSERT ((*pte & (1 << 9)) == 1);
|
ASSERT ((*pte & (1 << SWAP_FLAG_BIT)) != 0);
|
||||||
|
|
||||||
//masks address bits and returns truncated value
|
/* Masks the address bits and returns truncated value. */
|
||||||
return ((*pte & PTE_ADDR) >> 12);
|
return ((*pte & PTE_ADDR) >> ADDR_START_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user