Commit 362a0e0c authored by George Hotz's avatar George Hotz

softfloat and other block

parent f8f93972
...@@ -16,7 +16,9 @@ jobs: ...@@ -16,7 +16,9 @@ jobs:
- name: Install Python deps - name: Install Python deps
run: pip3 install -r risc/requirements.txt run: pip3 install -r risc/requirements.txt
- name: Build minigeth and run default block (cache) - name: Build minigeth and run default block (cache)
run: ./run.sh run: |
./run.sh
minigeth/go-ethereum 13284491
- name: Test in the embedded world - name: Test in the embedded world
run: | run: |
cd risc cd risc
......
#!/bin/bash #!/bin/bash -e
cd ../minigeth cd ../minigeth
GOOS=linux GOARCH=mips go build export GOOS=linux
export GOARCH=mips
export GOMIPS=softfloat
go build
cp go-ethereum ../risc/go-ethereum cp go-ethereum ../risc/go-ethereum
cd ../risc cd ../risc
file go-ethereum file go-ethereum
......
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys import sys
import math
import struct import struct
import traceback import traceback
from elftools.elf.elffile import ELFFile from elftools.elf.elffile import ELFFile
...@@ -15,6 +16,9 @@ from rangetree import RangeTree ...@@ -15,6 +16,9 @@ from rangetree import RangeTree
mu = Uc(UC_ARCH_MIPS, UC_MODE_32 + UC_MODE_BIG_ENDIAN) mu = Uc(UC_ARCH_MIPS, UC_MODE_32 + UC_MODE_BIG_ENDIAN)
# memory trie
# register trie
mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3] mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3]
regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"] regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
...@@ -27,14 +31,20 @@ brk_start = 0x40000000 # 0x40000000-0x80000000 ...@@ -27,14 +31,20 @@ brk_start = 0x40000000 # 0x40000000-0x80000000
icount = 0 icount = 0
bcount = 0 bcount = 0
instrumenting = False
instrumenting_all = False
def hook_code_simple(uc, address, size, user_data): def hook_code_simple(uc, address, size, user_data):
global icount, bcount global icount, bcount
#assert size == 4 #assert size == 4
try: try:
if bcount%100000 == 0: newicount = size//4
dat = next(md.disasm(uc.mem_read(address, size), address)) if bcount%10000 == 0 or instrumenting_all:
print("%10d: %s %s" % (icount, r[address], dat)) if size > 0:
icount += size//4 dat = next(md.disasm(uc.mem_read(address, size), address))
else:
dat = "EMPTY BASIC BLOCK?!?"
print("%10d(%2d): %8x %-80s %s" % (icount, newicount, address, r[address], dat))
icount += newicount
bcount += 1 bcount += 1
return True return True
except Exception as e: except Exception as e:
...@@ -42,14 +52,17 @@ def hook_code_simple(uc, address, size, user_data): ...@@ -42,14 +52,17 @@ def hook_code_simple(uc, address, size, user_data):
except: except:
raise Exception raise Exception
started = False
def start_instrumenting(): def start_instrumenting():
global started global instrumenting, instrumenting_all
if not started: if not instrumenting:
#mu.hook_add(UC_HOOK_CODE, hook_code_simple, user_data=mu) tracelevel = int(os.getenv("TRACE", 0))
if os.getenv("TRACE") != "0": if tracelevel >= 2:
mu.hook_add(UC_HOOK_CODE, hook_code_simple, user_data=mu)
elif tracelevel == 1:
mu.hook_add(UC_HOOK_BLOCK, hook_code_simple, user_data=mu) mu.hook_add(UC_HOOK_BLOCK, hook_code_simple, user_data=mu)
started = True if tracelevel >= 3:
instrumenting_all = True
instrumenting = True
tfd = 10 tfd = 10
files = {} files = {}
...@@ -171,7 +184,10 @@ def hook_interrupt(uc, intno, user_data): ...@@ -171,7 +184,10 @@ def hook_interrupt(uc, intno, user_data):
uc.reg_write(UC_MIPS_REG_V0, len(ret)) uc.reg_write(UC_MIPS_REG_V0, len(ret))
elif syscall_no == 4246: elif syscall_no == 4246:
a0 = uc.reg_read(UC_MIPS_REG_A0) a0 = uc.reg_read(UC_MIPS_REG_A0)
print("exit(%d) ran %.2f million instructions" % (a0, icount/1_000_000)) if icount > 0:
print("exit(%d) ran %.2f million instructions, %d binary searches" % (a0, icount/1_000_000, math.ceil(math.log2(icount))))
else:
print("exit(%d)" % a0)
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
os._exit(a0) os._exit(a0)
...@@ -270,8 +286,9 @@ mu.mem_write(SIZE-0x2000, struct.pack(">IIIIIIIII", ...@@ -270,8 +286,9 @@ mu.mem_write(SIZE-0x2000, struct.pack(">IIIIIIIII",
_AT_PAGESZ, 0x1000, 0)) # auxv _AT_PAGESZ, 0x1000, 0)) # auxv
# block # block
#mu.mem_write(SIZE-0x800, b"13284491\x00") mu.mem_write(SIZE-0x800, b"13284491\x00")
mu.mem_write(SIZE-0x800, b"13284469\x00") #mu.mem_write(SIZE-0x800, b"13284469\x00")
mu.mem_write(SIZE-0x400, b"GOGC=off\x00") mu.mem_write(SIZE-0x400, b"GOGC=off\x00")
#hexdump(mu.mem_read(SIZE-0x2000, 0x100)) #hexdump(mu.mem_read(SIZE-0x2000, 0x100))
......
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