parent
81e8dd1cd9
commit
06a53bf6f4
@ -0,0 +1,30 @@ |
|||||||
|
package hal |
||||||
|
|
||||||
|
type Page struct { |
||||||
|
Referenced bool |
||||||
|
PageNumber uint16 |
||||||
|
} |
||||||
|
|
||||||
|
type PageTable []*Page |
||||||
|
|
||||||
|
type Address uint16 |
||||||
|
|
||||||
|
func (address Address) PageNumber() uint16 { |
||||||
|
return uint16(address) >> 10 |
||||||
|
} |
||||||
|
|
||||||
|
func (address Address) Offset() uint16 { |
||||||
|
return uint16(address) & 0x03FF |
||||||
|
} |
||||||
|
|
||||||
|
func (table *PageTable) Find(address Address) { |
||||||
|
// 10 bit for one register in a page
|
||||||
|
// 6 bit to address the page
|
||||||
|
// 000010 | 0000000011
|
||||||
|
// -> Page 2, offset 3
|
||||||
|
|
||||||
|
// Find the page with that number
|
||||||
|
|
||||||
|
// Check if it is already loaded
|
||||||
|
// Load it if not
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package hal |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/stretchr/testify/assert" |
||||||
|
"testing" |
||||||
|
) |
||||||
|
|
||||||
|
func TestAddress(t *testing.T) { |
||||||
|
// 000010 | 0000000011
|
||||||
|
address := Address(0b0000100000000011) |
||||||
|
|
||||||
|
assert.Equal(t, uint16(0b10), address.PageNumber()) |
||||||
|
assert.Equal(t, uint16(0b11), address.Offset()) |
||||||
|
} |
Loading…
Reference in new issue