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
7702cf72
Commit
7702cf72
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor bds cleanup
parent
5de98f4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
13 deletions
+11
-13
MIPS.sol
contracts/MIPS.sol
+11
-13
No files found.
contracts/MIPS.sol
View file @
7702cf72
...
...
@@ -27,7 +27,7 @@ contract MIPS {
uint32 constant public REG_HEAP = REG_OFFSET + 0x23*4;
uint32 constant public REG_PENDPC = REG_OFFSET + 0x24*4;
uint32 constant public PC_
FLAG
= 0x80000000;
uint32 constant public PC_
PEND
= 0x80000000;
uint32 constant public PC_MASK = 0x7FFFFFFF;
uint32 constant public HEAP_START = 0x20000000;
...
...
@@ -101,9 +101,12 @@ contract MIPS {
return stateHash;
}
function branchDelay(bytes32 stateHash, uint32 pc, uint32 nextPC) internal returns (bytes32) {
function branchDelay(bytes32 stateHash, uint32 pc, uint32 nextPC, bool link) internal returns (bytes32) {
if (link) {
stateHash = WriteMemory(stateHash, REG_LR, pc+4);
}
stateHash = WriteMemory(stateHash, REG_PENDPC, nextPC);
stateHash = WriteMemory(stateHash, REG_PC, PC_
FLAG
| pc);
stateHash = WriteMemory(stateHash, REG_PC, PC_
PEND
| pc);
return stateHash;
}
...
...
@@ -116,7 +119,7 @@ contract MIPS {
}
uint32 nextPC;
if (pc & PC_
FLAG
== 0) {
if (pc & PC_
PEND
== 0) {
nextPC = pc + 4;
} else {
pc = pc & PC_MASK;
...
...
@@ -131,7 +134,7 @@ contract MIPS {
// j-type j/jal
if (opcode == 2 || opcode == 3) {
return branchDelay(stateHash, nextPC,
(SE(insn&0x03FFFFFF, 26) << 2) | (opcode == 3 ? PC_FLAG : 0)
);
SE(insn&0x03FFFFFF, 26) << 2, opcode == 3
);
}
// register fetch
...
...
@@ -197,10 +200,10 @@ contract MIPS {
if (shouldBranch) {
uint32 val = pc + 4 + (SE(insn&0xFFFF, 16)<<2);
return branchDelay(stateHash, nextPC, val);
return branchDelay(stateHash, nextPC, val
, false
);
} else {
// branch not taken
return branchDelay(stateHash, nextPC, nextPC+4);
return branchDelay(stateHash, nextPC, nextPC+4
, false
);
}
}
...
...
@@ -214,7 +217,7 @@ contract MIPS {
if (opcode == 0 && func >= 8 && func < 0x1c) {
if (func == 8 || func == 9) {
// jr/jalr
return branchDelay(stateHash, nextPC, rs
| (func == 9 ? PC_FLAG : 0)
);
return branchDelay(stateHash, nextPC, rs
, func == 9
);
}
// handle movz and movn when they don't write back
...
...
@@ -275,11 +278,6 @@ contract MIPS {
stateHash = WriteMemory(stateHash, storeAddr, val);
}
if (nextPC & PC_FLAG != 0 && nextPC != 0xDEAD0000) {
stateHash = WriteMemory(stateHash, REG_LR, pc+4);
nextPC &= PC_MASK;
}
stateHash = WriteMemory(stateHash, REG_PC, nextPC);
return stateHash;
...
...
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