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
607e8e52
Commit
607e8e52
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
always branch delay slot on conditionals
parent
4a3565f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
21 deletions
+26
-21
MIPS.sol
contracts/MIPS.sol
+25
-20
simple.py
risc/simple.py
+1
-1
No files found.
contracts/MIPS.sol
View file @
607e8e52
...
@@ -158,31 +158,36 @@ contract MIPS {
...
@@ -158,31 +158,36 @@ contract MIPS {
}
}
}
}
bool shouldBranch = false;
if (opcode == 4 || opcode == 5 || opcode == 6 || opcode == 7 || opcode == 1) {
bool shouldBranch = false;
uint32 val;
if (opcode == 4 || opcode == 5) { // beq/bne
if (opcode == 4 || opcode == 5) { // beq/bne
rt = m.ReadMemory(stateHash, REG_OFFSET + ((insn >> 14) & 0x7C));
rt = m.ReadMemory(stateHash, REG_OFFSET + ((insn >> 14) & 0x7C));
shouldBranch = (rs == rt && opcode == 4) || (rs != rt && opcode == 5);
shouldBranch = (rs == rt && opcode == 4) || (rs != rt && opcode == 5);
} else if (opcode == 6) { shouldBranch = int32(rs) <= 0; // blez
} else if (opcode == 6) { shouldBranch = int32(rs) <= 0; // blez
} else if (opcode == 7) { shouldBranch = int32(rs) > 0; // bgtz
} else if (opcode == 7) { shouldBranch = int32(rs) > 0; // bgtz
} else if (opcode == 1) {
} else if (opcode == 1) {
// regimm
// regimm
uint32 rtv = ((insn >> 16) & 0x1F);
uint32 rtv = ((insn >> 16) & 0x1F);
if (rtv == 0) shouldBranch = int32(rs) < 0; // bltz
if (rtv == 0) shouldBranch = int32(rs) < 0; // bltz
if (rtv == 1) shouldBranch = int32(rs) >= 0; // bgez
if (rtv == 1) shouldBranch = int32(rs) >= 0; // bgez
} else {
}
// ALU
val = execute(insn, rs, rt, mem);
if (shouldBranch) {
uint32 val = pc + 4 + (SE(insn&0xFFFF, 16)<<2);
return stepNextPC(stateHash, uint32(nextPC), val);
} else {
// branch not taken
return stepNextPC(stateHash, uint32(nextPC), uint32(nextPC)+4);
}
}
}
// ALU
uint32 val = execute(insn, rs, rt, mem);
// jumps (with branch delay slot)
// jumps (with branch delay slot)
// nothing is written to the state by this time
// nothing is written to the state by this time
if (shouldBranch) {
val = pc + 4 + (SE(insn&0xFFFF, 16)<<2);
return stepNextPC(stateHash, uint32(nextPC), val);
}
if (opcode == 0 && (func == 8 || func == 9)) {
if (opcode == 0 && (func == 8 || func == 9)) {
// jr/jalr (val is already right)
// jr/jalr (val is already right)
...
...
risc/simple.py
View file @
607e8e52
...
@@ -100,7 +100,7 @@ def hook_code_simple(uc, address, size, user_data):
...
@@ -100,7 +100,7 @@ def hook_code_simple(uc, address, size, user_data):
# check for BDS
# check for BDS
dat
=
next
(
md
.
disasm
(
uc
.
mem_read
(
address
,
size
),
address
))
dat
=
next
(
md
.
disasm
(
uc
.
mem_read
(
address
,
size
),
address
))
if
dat
.
insn_name
()
in
[
'jr'
,
'j'
,
'beqz'
,
'jal'
,
'bnez'
,
'b'
]:
if
dat
.
insn_name
()
in
[
'jr'
,
'j'
,
'beqz'
,
'jal'
,
'bnez'
,
'b'
,
'bltz'
,
'bne'
]:
is_bds
=
True
is_bds
=
True
inst
=
struct
.
unpack
(
">I"
,
uc
.
mem_read
(
pc
,
4
))[
0
]
inst
=
struct
.
unpack
(
">I"
,
uc
.
mem_read
(
pc
,
4
))[
0
]
...
...
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