eei/virtualeei: implement io.WriterAt

This commit is contained in:
mappu 2022-12-28 14:11:23 +13:00
parent 453e8b39e4
commit 49b78a4b75
2 changed files with 23 additions and 1 deletions

View File

@ -26,7 +26,10 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
copy(sw.Ram[*loadAddress:*loadAddress+len(fb)], fb) _, err = sw.WriteAt(fb, *loadAddress)
if err != nil {
panic(err)
}
c := riscvemu.NewCPU(&sw) c := riscvemu.NewCPU(&sw)
c.Pc = uint32(*loadAddress) c.Pc = uint32(*loadAddress)

View File

@ -63,6 +63,25 @@ func (ve *VirtualEEI) Write32(addr, value uint32) error {
return nil return nil
} }
// WriteAt implements the io.WriterAt interface on top of the EEI's virtual memory.
func (ve *VirtualEEI) WriteAt(p []byte, off int64) (n int, err error) {
if off < 0 || off >= math.MaxUint32 {
return 0, os.ErrInvalid
}
addr := uint32(off) // bounds-checked
// TODO do something more optimized
for i, bb := range p {
err := ve.WriteByte(addr+uint32(i), bb)
if err != nil {
return i, err
}
}
return len(p), nil
}
func (ve *VirtualEEI) Syscall() { func (ve *VirtualEEI) Syscall() {
panic("syscall") panic("syscall")
} }