Skip to content

Commit

Permalink
lab detect which pages have been accessed finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowherechan committed Mar 8, 2023
1 parent 6ad90d2 commit d2497df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions kernel/riscv.h
Expand Up @@ -343,6 +343,7 @@ typedef uint64 *pagetable_t; // 512 PTEs
#define PTE_W (1L << 2)
#define PTE_X (1L << 3)
#define PTE_U (1L << 4) // user can access
#define PTE_A (1L << 6) // accessed, for pgtbl-lab 3

// shift a physical address to the right place for a PTE.
#define PA2PTE(pa) ((((uint64)pa) >> 12) << 10)
Expand Down
23 changes: 23 additions & 0 deletions kernel/sysproc.c
Expand Up @@ -75,6 +75,29 @@ int
sys_pgaccess(void)
{
// lab pgtbl: your code here.
uint64 va, buf;
int num;
unsigned int kbuf = 0;
argaddr(0, &va);
argint(1, &num);
argaddr(2, &buf);
pagetable_t pagetable = myproc()->pagetable;
va = PGROUNDDOWN(va);

if (num > 32) { // limit
return -1;
}

for (int i = 0; i < num; i++) {
pte_t *pte = walk(pagetable, va, 0);
va += PGSIZE;
if ((*pte) & PTE_A) {
kbuf |= (1L << i);
}
(*pte) &= ~PTE_A;
}

copyout(pagetable, buf, (char*)&kbuf, 4);
return 0;
}
#endif
Expand Down

0 comments on commit d2497df

Please sign in to comment.