From bb16abdc0d21ca064ba01ead9bae40e3979c8fc3 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Sun, 1 Dec 2024 23:30:50 +0000 Subject: [PATCH] refactor: supplemental page table helper functions follow code style --- src/vm/page.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/vm/page.c b/src/vm/page.c index 01eeda7..6a3bb1a 100644 --- a/src/vm/page.c +++ b/src/vm/page.c @@ -12,17 +12,16 @@ void page_set_swap (struct thread *owner, void *upage, size_t swap_slot) { 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 - - //shifts the swap slot addr to take up bits 31 to 12 - //uses bitwise & to make sure it does not affect flags - //then applies it to pte - *pte |= (1 << SWAP_FLAG_BIT); // sets the 9th bit + /* Store the provided swap slot in the address bits of the page table + entry, truncating excess bits. */ + *pte |= (1 << SWAP_FLAG_BIT); uint32_t swap_slot_bits = (swap_slot << ADDR_START_BIT) & PTE_ADDR; *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 @@ -33,11 +32,10 @@ page_get_swap (struct thread *owner, void *upage) { 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 & (1 << 9)) == 1); + ASSERT ((*pte & (1 << SWAP_FLAG_BIT)) != 0); - //masks address bits and returns truncated value - return ((*pte & PTE_ADDR) >> 12); + /* Masks the address bits and returns truncated value. */ + return ((*pte & PTE_ADDR) >> ADDR_START_BIT); }