riscvemu/cmd/riscvrun/main.go
2022-12-28 13:59:35 +13:00

44 lines
674 B
Go

package main
import (
"flag"
"io/ioutil"
"os"
"riscvemu"
)
func main() {
memorySize := flag.Int("MemorySize", 4096, "Memory size (bytes)")
loadAddress := flag.Int("LoadAddress", 0, "Load address and initial progRam counter")
flag.Parse()
files := flag.Args()
if len(files) != 1 {
flag.Usage()
os.Exit(1)
}
sw := riscvemu.VirtualEEI{
Ram: make([]byte, *memorySize),
}
// Copy file into working memory
fb, err := ioutil.ReadFile(files[0])
if err != nil {
panic(err)
}
copy(sw.Ram[*loadAddress:*loadAddress+len(fb)], fb)
c := riscvemu.NewCPU(&sw)
c.Pc = uint32(*loadAddress)
for {
err := c.Step()
if err != nil {
panic(err)
}
}
}