Skip to content

Commit

Permalink
(pagetable) updated method 'clear'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxXSoft committed May 3, 2020
1 parent 025cf5d commit c1d39b8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/arch/riscv/pagetable.yu
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ inline def getFlag(this: PageTableEntry&, flag: USize): bool {
(this.getFlags() & flag) != 0 as USize
}

inline def isLeaf(this: PageTableEntry&): bool {
let flag_vad = PTE_FLAG_V | PTE_FLAG_A | PTE_FLAG_D
(this.getFlags() & ~flag_vad) != 0 as USize
}

inline def setFlags(this: PageTableEntry var&, flags: USize) {
this.data = (this.data & ~(0xff as USize)) | flags
}
Expand Down Expand Up @@ -81,15 +86,16 @@ inline def zero(this: PageTable var*) {
}
}

// deallocate all avaliable PTE frames before `index` and clear page table
// deallocate & clear all avaliable non-leaf PTEs frames before `index`
inline def clear(this: PageTable var*, index: USize,
dealloc: FrameDeallocator var*) {
var i = 0
while i as USize < index {
if !(*this).ptes[i].isUnused() {
let frame = (*this).ptes[i].getFrame()
var pte: PageTableEntry var& = this.getPte(i as USize)
if !pte.isUnused() && !pte.isLeaf() {
let frame = pte.getFrame()
dealloc.dealloc(frame)
(*this).ptes[i].setUnused()
pte.setUnused()
}
i += 1
}
Expand Down

0 comments on commit c1d39b8

Please sign in to comment.