Commit da2f4d88 authored by George Hotz's avatar George Hotz

mips testing framework

parent ede82663
......@@ -37,6 +37,9 @@ contract MIPS {
function Step(bytes32 stateHash) public view returns (bytes32) {
// instruction fetch
uint32 pc = m.ReadMemory(stateHash, REG_PC);
if (pc == 0xdead0000) {
return stateHash;
}
uint32 insn = m.ReadMemory(stateHash, pc);
uint32 opcode = insn >> 26; // 6-bits
......
......@@ -106,9 +106,11 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
// Get arguments from the memory.
args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
addr := common.BytesToHash(args[4:]).Big().Uint64()
//scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
fmt.Println("HOOKED!", returnGas, args)
fmt.Println("HOOKED!", returnGas, fmt.Sprintf("%x", addr))
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
//scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
//return ret
......
#!/usr/bin/env python3
import os
from capstone import *
md = Cs(CS_ARCH_MIPS, CS_MODE_32 + CS_MODE_BIG_ENDIAN)
from elftools.elf.elffile import ELFFile
os.makedirs("/tmp/mips", exist_ok=True)
path = "/Users/kafka/fun/mips/mips-gcc-4.8.1/bin/"
# Tests from:
# https://github.com/grantae/OpenMIPS/blob/master/software/test/macro/tests/addiu/src/os/khi/addiu.asm
for d in os.listdir("test/"):
if not d.endswith(".asm"):
continue
print("building", d)
os.system("%s/mips-elf-as -o /tmp/mips/%s test/%s" % (path, d, d))
elffile = ELFFile(open("/tmp/mips/"+d, "rb"))
#print(elffile)
for sec in elffile.iter_sections():
#print(sec, sec.name, sec.data())
if sec.name == ".test":
with open("test/"+(d.replace(".asm", ".bin")), "wb") as f:
data = sec.data()
for dd in md.disasm(data, 0):
print(dd)
f.write(data)
###############################################################################
# File : add.asm
# Project : MIPS32 MUX
# Author: : Grant Ayers (ayers@cs.stanford.edu)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'add' instruction.
#
###############################################################################
.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status
#### Test code start ####
lui $t0, 0xffff # A = 0xfffffffd (-3)
ori $t0, 0xfffd
ori $t1, $0, 0x3 # B = 0x3
add $t2, $t0, $t1 # C = A + B = 0
sltiu $v0, $t2, 1 # D = 1 if C == 0
#### Test code end ####
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'
$done:
jr $ra
nop
.end test
###############################################################################
# File : addiu.asm
# Project : MIPS32 MUX
# Author : Grant Ayers (ayers@cs.stanford.edu)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'addiu' instruction.
#
###############################################################################
.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status
#### Test code start ####
lui $t0, 0xffff # A = 0xfffffffd (-3)
ori $t0, 0xfffd
addiu $t1, $t0, 5 # B = A + 5 = 2
addiu $t2, $t1, 0xfffe # C = B + -2 = 0
sltiu $v0, $t2, 1 # D = 1 if C == 0
#### Test code end ####
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'
$done:
jr $ra
nop
.end test
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