Commit c20dde6b authored by George Hotz's avatar George Hotz

mips is running

parent 854d220a
......@@ -57,6 +57,10 @@ contract MIPS {
// R-type (stores rd)
rt = m.ReadMemory(stateHash, REG_OFFSET + ((insn >> 14) & 0x7C));
storeAddr = REG_OFFSET + ((insn >> 9) & 0x7C);
} else {
// rt is SignExtImm
uint32 SignExtImm = insn&0xFFFF | (insn&0x8000 != 0 ? 0xFFFF0000 : 0);
rt = SignExtImm;
}
}
......@@ -66,7 +70,12 @@ contract MIPS {
if (opcode >= 0x20) {
// M[R[rs]+SignExtImm]
uint32 SignExtImm = insn&0xFFFF | (insn&0x8000 != 0 ? 0xFFFF0000 : 0);
mem = m.ReadMemory(stateHash, (rs + SignExtImm) & 0xFFFFFFFC);
uint32 addr = (rs + SignExtImm) & 0xFFFFFFFC;
mem = m.ReadMemory(stateHash, addr);
if (opcode >= 0x28) {
// store
storeAddr = addr;
}
}
// execute
......@@ -84,6 +93,13 @@ contract MIPS {
uint32 opcode = insn >> 26; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
// TODO: deref the immed into a register
// transform ArithLogI
// TODO: replace with table
if (opcode == 8) { opcode = 0; func = 0x20; }
else if (opcode == 9) { opcode = 0; func = 0x21; }
else if (opcode == 0xc) { opcode = 0; func = 0x24; }
if (opcode == 0) {
uint32 shamt = (insn >> 6) & 0x1f;
// R-type (ArithLog)
......
......@@ -15,9 +15,15 @@ contract MIPSMemory {
state[stateHash][addr] = (1 << 32) | value;
}
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) public pure returns (bytes32) {
// TODO: does the stateHash mutation
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public pure returns (bytes32) {
require(addr & 3 == 0, "write memory must be 32-bit aligned");
// TODO: do the real stateHash mutation
bytes32 newstateHash = keccak256(abi.encodePacked(stateHash));
// no proof required, this is obviously right
//state[newstateHash][addr] = (1 << 32) | value;
return newstateHash;
}
// needed for preimage oracle
......
......@@ -124,6 +124,9 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
dat := common.BytesToHash(args[0x44:0x64]).Big().Uint64()
fmt.Println("HOOKED WRITE!", fmt.Sprintf("%x = %x", addr, dat))
ram[addr] = uint32(dat)
// pass through stateRoot
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), args[0x4:0x24])
}
scope.Contract.Gas += returnGas
......@@ -185,7 +188,7 @@ func main() {
// 0xdb7df598
input := []byte{0xdb, 0x7d, 0xf5, 0x98} // Steps(bytes32, uint256)
input = append(input, common.Hash{}.Bytes()...)
input = append(input, common.BigToHash(common.Big0).Bytes()...)
input = append(input, common.BigToHash(big.NewInt(int64(steps))).Bytes()...)
contract := vm.NewContract(vm.AccountRef(from), vm.AccountRef(to), common.Big0, 20000000)
//fmt.Println(bytecodehash, bytecode)
......
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