mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
pmm: implement FrameFromAddress
This is equivalent to vmm.PageFromAddress but returns back a pmm.Frame
This commit is contained in:
parent
324022187d
commit
0a271b206b
@ -24,3 +24,12 @@ func (f Frame) Valid() bool {
|
|||||||
func (f Frame) Address() uintptr {
|
func (f Frame) Address() uintptr {
|
||||||
return uintptr(f << mem.PageShift)
|
return uintptr(f << mem.PageShift)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FrameFromAddress returns a Frame that corresponds to
|
||||||
|
// the given physical address. This function can handle
|
||||||
|
// both page-aligned and not aligned addresses. in the
|
||||||
|
// latter case, the input address will be rounded down
|
||||||
|
// to the frame that contains it.
|
||||||
|
func FrameFromAddress(physAddr uintptr) Frame {
|
||||||
|
return Frame((physAddr & ^(uintptr(mem.PageSize - 1))) >> mem.PageShift)
|
||||||
|
}
|
||||||
|
@ -23,3 +23,21 @@ func TestFrameMethods(t *testing.T) {
|
|||||||
t.Error("expected InvalidFrame.Valid() to return false")
|
t.Error("expected InvalidFrame.Valid() to return false")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFrameFromAddress(t *testing.T) {
|
||||||
|
specs := []struct {
|
||||||
|
input uintptr
|
||||||
|
expFrame Frame
|
||||||
|
}{
|
||||||
|
{0, Frame(0)},
|
||||||
|
{4095, Frame(0)},
|
||||||
|
{4096, Frame(1)},
|
||||||
|
{4123, Frame(1)},
|
||||||
|
}
|
||||||
|
|
||||||
|
for specIndex, spec := range specs {
|
||||||
|
if got := FrameFromAddress(spec.input); got != spec.expFrame {
|
||||||
|
t.Errorf("[spec %d] expected returned frame to be %v; got %v", specIndex, spec.expFrame, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user