1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00
Achilleas Anagnostopoulos 8dfc5d4e92 Use pwd as a workspace; move sources to src/gopheros and rewrite imports
By setting up pwd as a Go workspace, we can trim import paths from
something like "github.com/achilleasa/gopher-os/kernel" to just
"kernel".

These changes make forking easier and also allows us to move the code to
a different git hosting provider without having to rewrite the imports.
2017-07-01 20:37:09 +01:00

50 lines
1.1 KiB
Go

package mem
import (
"reflect"
"unsafe"
)
// Memset sets size bytes at the given address to the supplied value. The implementation
// is based on bytes.Repeat; instead of using a for loop, this function uses
// log2(size) copy calls which should give us a speed boost as page addresses
// are always aligned.
func Memset(addr uintptr, value byte, size Size) {
if size == 0 {
return
}
// overlay a slice on top of this address region
target := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Len: int(size),
Cap: int(size),
Data: addr,
}))
// Set first element and make log2(size) optimized copies
target[0] = value
for index := Size(1); index < size; index *= 2 {
copy(target[index:], target[:index])
}
}
// Memcopy copies size bytes from src to dst.
func Memcopy(src, dst uintptr, size Size) {
if size == 0 {
return
}
srcSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Len: int(size),
Cap: int(size),
Data: src,
}))
dstSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Len: int(size),
Cap: int(size),
Data: dst,
}))
copy(dstSlice, srcSlice)
}