Skip to content

Commit

Permalink
Fix immediates
Browse files Browse the repository at this point in the history
Change-Id: I0d2807b9a96d5fafdaa9fb5e8c3ded8c7e54fda3
  • Loading branch information
hakase56557 committed Sep 19, 2023
1 parent 7366010 commit a725b76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 11 additions & 6 deletions src/arch/riscvcapstone/isa/decoder.isa
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,9 @@ decode QUADRANT default Unknown::unknown() {
return std::make_shared<IllegalInstFault>("Unexpected capability type (26)", machInst);
}

rs1_cap.setCursor(rs1_cap.cursor() + IMM12);
int64_t imm = sext<12>(IMM12);

rs1_cap.setCursor(rs1_cap.cursor() + imm);

ConstTaggedRegVal temp;
temp.getRegVal().rawCapVal() = (uint128_t)rs1_cap;
Expand Down Expand Up @@ -1363,10 +1365,12 @@ decode QUADRANT default Unknown::unknown() {
}

Addr EA;
int64_t imm = sext<12>(IMM12);

if(Rs1_trv.getTag()) {
EA = Rs1_trv.getRegVal().capVal().cursor() + IMM12;
EA = Rs1_trv.getRegVal().capVal().cursor() + imm;
} else {
EA = Rs1_trv.getRegVal().intVal() + IMM12;
EA = Rs1_trv.getRegVal().intVal() + imm;
}

ConstTaggedRegVal temp_regval;
Expand Down Expand Up @@ -1410,8 +1414,8 @@ decode QUADRANT default Unknown::unknown() {
}

Cap rs1_cap = Rs1_trv.getRegVal().capVal();
//signed imm12?
NPC = rs1_cap.cursor() + IMM12;
int64_t imm = sext<12>(IMM12);
NPC = rs1_cap.cursor() + imm;

//write pc to rd
//todo: actually pc + 4
Expand Down Expand Up @@ -1450,7 +1454,8 @@ decode QUADRANT default Unknown::unknown() {
//should I set PC or NPC hmmm
if(Rs1_trv.getRegVal().intVal() != 0) {
Cap rd_cap = Rd_trv.getRegVal().capVal();
rd_cap.setCursor(rd_cap.cursor() + IMM12);
int64_t imm = sext<12>(IMM12);
rd_cap.setCursor(rd_cap.cursor() + imm);

dyn_inst->cpu->getIEWObject().setPCCap(rd_cap, dyn_inst->threadNumber);

Expand Down
11 changes: 5 additions & 6 deletions src/arch/riscvcapstone/isa/formats/rnode.isa
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def template RNodeMemExecute {{
%(op_decl)s;
%(op_rd)s;

int64_t imm = sext<12>(IMM12);

CPU *o3cpu = dynamic_cast<o3::CPU *>(dyn_inst->getCpuPtr());
assert(o3cpu);

Expand Down Expand Up @@ -166,7 +168,7 @@ def template RNodeMemExecute {{

if(cwrld || (!cwrld && emode)) {
Cap rs1_cap = Rs1.getRegVal().capVal();
EA = rs1_cap.cursor() + IMM12;
EA = rs1_cap.cursor() + imm;

if(!capInBoundForMemAcc(rs1_cap, EA, sizeof(Mem))) {
return std::make_shared<IllegalInstFault>(
Expand All @@ -179,7 +181,7 @@ def template RNodeMemExecute {{
NodeID node_id = rs1_cap.nodeId();
dyn_inst->initiateNodeCommand(new NodeQuery(node_id));
} else {
EA = Rs1.getRegVal().intVal() + IMM12;
EA = Rs1.getRegVal().intVal() + imm;

if(dyn_inst->addrInSecRegion(EA, sizeof(Mem))) {
return std::make_shared<IllegalInstFault>(
Expand All @@ -196,9 +198,6 @@ def template RNodeMemExecute {{

initiateMemRead(xc, traceData, EA, Mem, memAccessFlags);

//for integer loads, if Rd already contains a cap
//clear it and update refcount

return NoFault;
}
}};
Expand Down Expand Up @@ -307,7 +306,7 @@ def template RNodeStoreExecute {{
%(check_code)s;

Addr EA;
Addr offset = IMM7 << 5 | IMM5;
int64_t offset = sext<12>(IMM7 << 5 | IMM5);
if(cwrld || (!cwrld && emode)) {
Cap rs1_cap = Rs1.getRegVal().capVal();
EA = rs1_cap.cursor() + offset;
Expand Down

0 comments on commit a725b76

Please sign in to comment.