Commit 5d012a1f authored by George Hotz's avatar George Hotz

ugh branch delay slots are the worst

parent 9ec6fca3
......@@ -6,8 +6,27 @@ import (
"testing"
)
func WriteRam(ram map[uint32](uint32), addr uint32, value uint32) {
if value != 0 {
ram[addr] = value
} else {
delete(ram, addr)
}
}
func RegSerialize(ram map[uint32](uint32)) []uint32 {
// len(ram) is still failing, need nextpc
//ret := []uint32{ram[0xc0000080] & 0x7FFFFFFF, uint32(len(ram))}
ret := []uint32{ram[0xc0000080] & 0x7FFFFFFF}
for i := uint32(0xc0000000); i < 0xc0000000+32*4; i += 4 {
ret = append(ret, ram[i])
}
return ret
}
func TestCompare(t *testing.T) {
fn := "../mipigeth/test.bin"
//fn := "../mipigeth/minigeth.bin"
steps := 10000000
......@@ -16,24 +35,25 @@ func TestCompare(t *testing.T) {
ram := make(map[uint32](uint32))
LoadMappedFile(fn, ram, 0)
inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469)
LoadMappedFile(inputFile, ram, 0x30000000)
go RunWithRam(ram, steps, 0, func(step int, ram map[uint32](uint32)) {
//fmt.Printf("%d evm %x\n", step, ram[0xc0000080])
ret := []uint32{ram[0xc0000080] & 0x7FFFFFFF}
for i := uint32(0xc0000000); i < 0xc0000000+32*4; i += 4 {
ret = append(ret, ram[i])
}
cevm <- ret
cevm <- RegSerialize(ram)
})
go RunUnicorn(fn, steps, func(step int, mu uc.Unicorn) {
go RunUnicorn(fn, steps, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) {
pc, _ := mu.RegRead(uc.MIPS_REG_PC)
//fmt.Printf("%d uni %x\n", step, pc)
ret := []uint32{uint32(pc)}
addr := uint32(0xc0000000)
for i := uc.MIPS_REG_ZERO; i < uc.MIPS_REG_ZERO+32; i++ {
reg, _ := mu.RegRead(i)
ret = append(ret, uint32(reg))
WriteRam(ram, addr, uint32(reg))
addr += 4
}
cuni <- ret
WriteRam(ram, 0xc0000080, uint32(pc))
cuni <- RegSerialize(ram)
})
for i := 0; i < steps; i++ {
......
......@@ -33,7 +33,7 @@ func WriteBytes(fd int, bytes []byte) {
}
// reimplement simple.py in go
func RunUnicorn(fn string, totalSteps int, callback func(int, uc.Unicorn)) {
func RunUnicorn(fn string, totalSteps int, callback func(int, uc.Unicorn, map[uint32](uint32))) {
mu, err := uc.NewUnicorn(uc.ARCH_MIPS, uc.MODE_32|uc.MODE_BIG_ENDIAN)
check(err)
......@@ -102,7 +102,7 @@ func RunUnicorn(fn string, totalSteps int, callback func(int, uc.Unicorn)) {
fmt.Printf("%10d pc: %x steps per s %f ram entries %d\n", steps, addr, steps_per_sec, len(ram))
}
if callback != nil {
callback(steps, mu)
callback(steps, mu, ram)
}
steps += 1
if totalSteps == steps {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment