mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
Change the Frame type to uintptr and remove Size/Order methods
To keep the implementation portable, the Frame type had to be changed from uint64 to uintptr. Using uintptr ensures that the frame will always match the pointer size of the platform.
This commit is contained in:
@@ -49,14 +49,6 @@ func TestBootMemoryAllocator(t *testing.T) {
|
||||
if !frame.IsValid() {
|
||||
t.Errorf("[frame %d] expected IsValid() to return true", allocFrameCount)
|
||||
}
|
||||
|
||||
if got := frame.PageOrder(); got != mem.PageOrder(0) {
|
||||
t.Errorf("[frame %d] expected allocated frame page order to be 0; got %d", allocFrameCount, got)
|
||||
}
|
||||
|
||||
if got := frame.Size(); got != mem.PageSize {
|
||||
t.Errorf("[frame %d] expected allocated frame size to be %d; got %d", allocFrameCount, mem.PageSize, got)
|
||||
}
|
||||
}
|
||||
|
||||
if allocFrameCount != totalFreeFrames {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// Frame describes a physical memory page index.
|
||||
type Frame uint64
|
||||
type Frame uintptr
|
||||
|
||||
const (
|
||||
// InvalidFrame is returned by page allocators when
|
||||
@@ -25,14 +25,3 @@ func (f Frame) IsValid() bool {
|
||||
func (f Frame) Address() uintptr {
|
||||
return uintptr(f << mem.PageShift)
|
||||
}
|
||||
|
||||
// PageOrder returns the page order of this frame. The page order is encoded in the
|
||||
// 8 MSB of the frame number.
|
||||
func (f Frame) PageOrder() mem.PageOrder {
|
||||
return mem.PageOrder((f >> 56) & 0xFF)
|
||||
}
|
||||
|
||||
// Size returns the size of this frame.
|
||||
func (f Frame) Size() mem.Size {
|
||||
return mem.PageSize << ((f >> 56) & 0xFF)
|
||||
}
|
||||
|
||||
@@ -15,17 +15,9 @@ func TestFrameMethods(t *testing.T) {
|
||||
t.Errorf("[order %d] expected frame %d to be valid", order, frameIndex)
|
||||
}
|
||||
|
||||
if got := frame.PageOrder(); got != order {
|
||||
t.Errorf("[order %d] expected frame (%d, index: %d) call to PageOrder() to return %d; got %d", order, frame, frameIndex, order, got)
|
||||
}
|
||||
|
||||
if exp, got := uintptr(frameIndex<<mem.PageShift), frame.Address(); got != exp {
|
||||
t.Errorf("[order %d] expected frame (%d, index: %d) call to Address() to return %x; got %x", order, frame, frameIndex, exp, got)
|
||||
}
|
||||
|
||||
if exp, got := mem.Size(mem.PageSize<<order), frame.Size(); got != exp {
|
||||
t.Errorf("[order %d] expected frame (%d, index: %d) call to Size() to return %d; got %d", order, frame, frameIndex, exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user