riscvemu/cmd/riscvrun/main.go

44 lines
675 B
Go
Raw Normal View History

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.MemoryWorld{
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)
}
}
}