Commit ac764451 authored by protolambda's avatar protolambda

mipsevm: fix initial heap, set initial PC to entrypoint

parent 3d1052d0
......@@ -9,7 +9,17 @@ import (
)
func LoadELF(f *elf.File) (*State, error) {
s := &State{}
s := &State{
PC: uint32(f.Entry),
Hi: 0,
Lo: 0,
Heap: 1 << 20, // start heap at 1 GiB offset for now
Registers: [32]uint32{},
Memory: nil,
Exit: 0,
Exited: false,
Step: 0,
}
for i, prog := range f.Progs {
if prog.Type == 0x70000003 { // MIPS_ABIFLAGS
......
......@@ -42,7 +42,7 @@ func LoadUnicorn(st *State, mu uc.Unicorn) error {
func HookUnicorn(st *State, mu uc.Unicorn, stdOut, stdErr io.Writer) error {
_, err := mu.HookAdd(uc.HOOK_INTR, func(mu uc.Unicorn, intno uint32) {
if intno != 17 {
log.Fatal("invalid interrupt ", intno, " at step ", steps)
log.Fatal("invalid interrupt ", intno, " at step ", st.Step)
}
syscallNum, _ := mu.RegRead(uc.MIPS_REG_V0)
......@@ -64,7 +64,7 @@ func HookUnicorn(st *State, mu uc.Unicorn, stdOut, stdErr io.Writer) error {
a0, _ := mu.RegRead(uc.MIPS_REG_A0)
sz, _ := mu.RegRead(uc.MIPS_REG_A1)
if a0 == 0 {
v0 = 0x20000000 + heap_start
v0 = uint64(st.Heap)
st.Heap += uint32(sz)
} else {
v0 = a0
......
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