riscvemu/cmd/riscvrun/main.go

41 lines
576 B
Go

package main
import (
"flag"
"io/ioutil"
"os"
"riscvemu"
)
func main() {
loadAddress := flag.Int64("LoadAddress", 0, "Load address and initial program counter")
flag.Parse()
files := flag.Args()
if len(files) != 1 {
flag.Usage()
os.Exit(1)
}
sw := riscvemu.NewVirtualEEI()
// 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)
}
}
}