Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
5d012a1f
Commit
5d012a1f
authored
Oct 07, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ugh branch delay slots are the worst
parent
9ec6fca3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
compare_test.go
mipsevm/compare_test.go
+29
-9
unicorn.go
mipsevm/unicorn.go
+2
-2
No files found.
mipsevm/compare_test.go
View file @
5d012a1f
...
@@ -6,8 +6,27 @@ import (
...
@@ -6,8 +6,27 @@ import (
"testing"
"testing"
)
)
func
WriteRam
(
ram
map
[
uint32
](
uint32
),
addr
uint32
,
value
uint32
)
{
if
value
!=
0
{
ram
[
addr
]
=
value
}
else
{
delete
(
ram
,
addr
)
}
}
func
RegSerialize
(
ram
map
[
uint32
](
uint32
))
[]
uint32
{
// len(ram) is still failing, need nextpc
//ret := []uint32{ram[0xc0000080] & 0x7FFFFFFF, uint32(len(ram))}
ret
:=
[]
uint32
{
ram
[
0xc0000080
]
&
0x7FFFFFFF
}
for
i
:=
uint32
(
0xc0000000
);
i
<
0xc0000000
+
32
*
4
;
i
+=
4
{
ret
=
append
(
ret
,
ram
[
i
])
}
return
ret
}
func
TestCompare
(
t
*
testing
.
T
)
{
func
TestCompare
(
t
*
testing
.
T
)
{
fn
:=
"../mipigeth/test.bin"
fn
:=
"../mipigeth/test.bin"
//fn := "../mipigeth/minigeth.bin"
steps
:=
10000000
steps
:=
10000000
...
@@ -16,24 +35,25 @@ func TestCompare(t *testing.T) {
...
@@ -16,24 +35,25 @@ func TestCompare(t *testing.T) {
ram
:=
make
(
map
[
uint32
](
uint32
))
ram
:=
make
(
map
[
uint32
](
uint32
))
LoadMappedFile
(
fn
,
ram
,
0
)
LoadMappedFile
(
fn
,
ram
,
0
)
inputFile
:=
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
)
LoadMappedFile
(
inputFile
,
ram
,
0x30000000
)
go
RunWithRam
(
ram
,
steps
,
0
,
func
(
step
int
,
ram
map
[
uint32
](
uint32
))
{
go
RunWithRam
(
ram
,
steps
,
0
,
func
(
step
int
,
ram
map
[
uint32
](
uint32
))
{
//fmt.Printf("%d evm %x\n", step, ram[0xc0000080])
//fmt.Printf("%d evm %x\n", step, ram[0xc0000080])
ret
:=
[]
uint32
{
ram
[
0xc0000080
]
&
0x7FFFFFFF
}
cevm
<-
RegSerialize
(
ram
)
for
i
:=
uint32
(
0xc0000000
);
i
<
0xc0000000
+
32
*
4
;
i
+=
4
{
ret
=
append
(
ret
,
ram
[
i
])
}
cevm
<-
ret
})
})
go
RunUnicorn
(
fn
,
steps
,
func
(
step
int
,
mu
uc
.
Unicorn
)
{
go
RunUnicorn
(
fn
,
steps
,
func
(
step
int
,
mu
uc
.
Unicorn
,
ram
map
[
uint32
](
uint32
)
)
{
pc
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_PC
)
pc
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_PC
)
//fmt.Printf("%d uni %x\n", step, pc)
//fmt.Printf("%d uni %x\n", step, pc)
ret
:=
[]
uint32
{
uint32
(
pc
)}
addr
:=
uint32
(
0xc0000000
)
for
i
:=
uc
.
MIPS_REG_ZERO
;
i
<
uc
.
MIPS_REG_ZERO
+
32
;
i
++
{
for
i
:=
uc
.
MIPS_REG_ZERO
;
i
<
uc
.
MIPS_REG_ZERO
+
32
;
i
++
{
reg
,
_
:=
mu
.
RegRead
(
i
)
reg
,
_
:=
mu
.
RegRead
(
i
)
ret
=
append
(
ret
,
uint32
(
reg
))
WriteRam
(
ram
,
addr
,
uint32
(
reg
))
addr
+=
4
}
}
cuni
<-
ret
WriteRam
(
ram
,
0xc0000080
,
uint32
(
pc
))
cuni
<-
RegSerialize
(
ram
)
})
})
for
i
:=
0
;
i
<
steps
;
i
++
{
for
i
:=
0
;
i
<
steps
;
i
++
{
...
...
mipsevm/unicorn.go
View file @
5d012a1f
...
@@ -33,7 +33,7 @@ func WriteBytes(fd int, bytes []byte) {
...
@@ -33,7 +33,7 @@ func WriteBytes(fd int, bytes []byte) {
}
}
// reimplement simple.py in go
// reimplement simple.py in go
func
RunUnicorn
(
fn
string
,
totalSteps
int
,
callback
func
(
int
,
uc
.
Unicorn
))
{
func
RunUnicorn
(
fn
string
,
totalSteps
int
,
callback
func
(
int
,
uc
.
Unicorn
,
map
[
uint32
](
uint32
)
))
{
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
check
(
err
)
check
(
err
)
...
@@ -102,7 +102,7 @@ func RunUnicorn(fn string, totalSteps int, callback func(int, uc.Unicorn)) {
...
@@ -102,7 +102,7 @@ func RunUnicorn(fn string, totalSteps int, callback func(int, uc.Unicorn)) {
fmt
.
Printf
(
"%10d pc: %x steps per s %f ram entries %d
\n
"
,
steps
,
addr
,
steps_per_sec
,
len
(
ram
))
fmt
.
Printf
(
"%10d pc: %x steps per s %f ram entries %d
\n
"
,
steps
,
addr
,
steps_per_sec
,
len
(
ram
))
}
}
if
callback
!=
nil
{
if
callback
!=
nil
{
callback
(
steps
,
mu
)
callback
(
steps
,
mu
,
ram
)
}
}
steps
+=
1
steps
+=
1
if
totalSteps
==
steps
{
if
totalSteps
==
steps
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment