Commit 45e8662e authored by protolambda's avatar protolambda

mipigo: remove legacy startup.s in favor of minimal Go ELF loading

parent baa42d51
__pycache__
go-ethereum
sysroot
test/test
minigeth
/minigeth.bin
Compiler for minigeth in MIPS
`./build.sh` will build minigeth for MIPS.
startup -- a startup stub which functions as an ELF loader
test -- contains Go hello world for MIPS
#!/usr/bin/env bash
set -e
cd ../minigeth
export GOOS=linux
export GOARCH=mips
export GOMIPS=softfloat
go build -o ../mipigo/minigeth
cd ../mipigo
file minigeth
if [[ ! -d venv ]]; then
python3 -m venv venv
fi
source venv/bin/activate
pip3 install -r requirements.txt
./compile.py
deactivate
#!/usr/bin/env python3
import os
import sys
import struct
import hashlib
from rangetree import RangeTree
from elftools.elf.elffile import ELFFile
def load_minigeth(fn="minigeth"):
elf = open(fn, "rb")
data = elf.read()
elf.seek(0)
elffile = ELFFile(elf)
end_addr = 0
for seg in elffile.iter_segments():
end_addr = max(end_addr, seg.header.p_vaddr + seg.header.p_memsz)
# program memory (16 MB)
prog_size = (end_addr+0xFFF) & ~0xFFF
prog_dat = bytearray(prog_size)
print("malloced 0x%x for program" % prog_size)
for seg in elffile.iter_segments():
print(seg.header, hex(seg.header.p_vaddr))
prog_dat[seg.header.p_vaddr:seg.header.p_vaddr+len(seg.data())] = seg.data()
entry = elffile.header.e_entry
print("entrypoint: 0x%x" % entry)
# moved to MIPS
sf = os.path.join(os.path.dirname(os.path.abspath(__file__)), "startup", "startup.bin")
start = open(sf, "rb").read() + struct.pack(">I", entry)
prog_dat[:len(start)] = start
entry = 0
r = RangeTree()
found = 0
for section in elffile.iter_sections():
try:
for nsym, symbol in enumerate(section.iter_symbols()):
ss = symbol['st_value']
se = ss+symbol['st_size']
if ss != se:
try:
r[ss:se] = symbol.name
except KeyError:
continue
#print(nsym, symbol.name, symbol['st_value'], symbol['st_size'])
if symbol.name == "runtime.gcenable":
print(nsym, symbol.name)
# nop gcenable
prog_dat[symbol['st_value']:symbol['st_value']+8] = b"\x03\xe0\x00\x08\x00\x00\x00\x00"
found += 1
except Exception:
#traceback.print_exc()
pass
#assert(found == 2)
return prog_dat, prog_size, r
if __name__ == "__main__":
fn = "minigeth"
if len(sys.argv) > 1:
fn = sys.argv[1]
prog_dat, prog_size, _ = load_minigeth(fn)
print("compiled %d bytes with md5 %s" % (prog_size, hashlib.md5(prog_dat).hexdigest()))
with open(fn+".bin", "wb") as f:
f.write(prog_dat)
\ No newline at end of file
pyelftools==0.27
hexdump==3.3
termcolor==1.1.0
capstone==4.0.2
rangetree==1.0
\ No newline at end of file
.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $sp, 0x7fff
ori $sp, 0xd000
# http://articles.manugarg.com/aboutelfauxiliaryvectors.html
# _AT_PAGESZ = 6
ori $t0, $0, 6
sw $t0, 0xC($sp)
ori $t0, $0, 0x1000
sw $t0, 0x10($sp)
lw $ra, dat($0)
jr $ra
nop
dat:
.end test
#!/usr/bin/env bash
set -e
../../mipsevm/maketests.py startup.s startup.bin
package main
import (
"fmt"
)
func main() {
fmt.Println("hello world")
panic("test panic")
}
#!/usr/bin/env bash
set -e
export GOOS=linux
export GOARCH=mips
export GOMIPS=softfloat
go build test.go
../compile.py 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