Fix Toooba to use addresses instead of offsets (#32)

* Fixed the Decoding of (C)JAL

* Use CSR addresses instead of offsets

* Fixed offsets correctly

* Fixed all offsets I could spot

* Fix use of modifyOffset function

* Corrected brAddrCalc function

* Preliminary fix for ddc offsetting

* Use setAddr instead of incOffset for DDC

* Deleted unnecessarily added lines in ALU pipeline

* Deleted white space

* Switched off verbosity for ALU pipeline

* Removed unnecessary print import
This commit is contained in:
Franz Fuchs
2025-02-05 11:06:07 +00:00
committed by GitHub
parent 5dea27457a
commit 6ebe612ff8
5 changed files with 25 additions and 22 deletions

View File

@@ -354,10 +354,10 @@ module mkStatsCsr(StatsCsr);
endmodule endmodule
function Reg#(Data) scrToCsr(Reg#(CapReg) scr) = interface Reg function Reg#(Data) scrToCsr(Reg#(CapReg) scr) = interface Reg
method _write (x) = action CapPipe scr_pipe = cast(scr); scr <= cast(setOffset(scr_pipe, x).value); endaction; method _write (x) = action CapPipe scr_pipe = cast(scr); scr <= cast(setAddr(scr_pipe, x).value); endaction;
method Data _read; method Data _read;
CapPipe scr_pipe = cast(scr); CapPipe scr_pipe = cast(scr);
return getOffset(scr_pipe); return getAddr(scr_pipe);
endmethod endmethod
endinterface; endinterface;

View File

@@ -92,7 +92,7 @@ function SCR unpackSCR(Bit#(5) addr);
endfunction endfunction
function CapPipe update_scr_via_csr (CapPipe old_scr, WordXL new_csr, Bool allow_sealed); function CapPipe update_scr_via_csr (CapPipe old_scr, WordXL new_csr, Bool allow_sealed);
let new_scr = setOffset(old_scr, new_csr); let new_scr = setAddr(old_scr, new_csr);
let ret = new_scr.value; let ret = new_scr.value;
if (!new_scr.exact || (getKind(old_scr) != UNSEALED && !allow_sealed)) begin if (!new_scr.exact || (getKind(old_scr) != UNSEALED && !allow_sealed)) begin
ret = setValidCap(ret, False); ret = setValidCap(ret, False);

View File

@@ -530,7 +530,7 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
if(x.regs.src1 matches tagged Valid .src1 &&& src1 != 0) begin if(x.regs.src1 matches tagged Valid .src1 &&& src1 != 0) begin
rVal1 <- readRFBypass(src1, regsReady.src1, inIfc.rf_rd1(src1), bypassWire); rVal1 <- readRFBypass(src1, regsReady.src1, inIfc.rf_rd1(src1), bypassWire);
end end
if (x.ddc_offset) rVal1 = incOffset(ddc, getAddr(rVal1)).value; if (x.ddc_offset) rVal1 = setAddr(ddc, getAddr(rVal1)).value;
// get rVal2 (check bypass) // get rVal2 (check bypass)
CapPipe rVal2 = nullCap; CapPipe rVal2 = nullCap;

View File

@@ -523,14 +523,15 @@ function DecodeResult decode(Instruction inst, Bool cap_mode);
end end
opcJal: begin opcJal: begin
legalInst = True;
if (cap_mode) begin if (cap_mode) begin
dInst.iType = CJAL; dInst.iType = CJAL;
end end
else begin else begin
dInst.iType = J; dInst.iType = J;
end end
legalInst = True;
regs.dst = Valid(tagged Gpr rd); regs.dst = Valid(tagged Gpr rd);
regs.src1 = Invalid; regs.src1 = Invalid;
regs.src2 = Invalid; regs.src2 = Invalid;

View File

@@ -200,19 +200,19 @@ endfunction
(* noinline *) (* noinline *)
function CapPipe specialRWALU(CapPipe cap, CapPipe oldCap, SpecialRWFunc scrType); function CapPipe specialRWALU(CapPipe cap, CapPipe oldCap, SpecialRWFunc scrType);
function csrOp (oldOffset, val, f) = function csrOp (oldAddr, val, f) =
case (f) case (f)
Write: val; Write: val;
Set: (oldOffset | val); Set: (oldAddr | val);
Clear: (oldOffset & ~val); Clear: (oldAddr & ~val);
endcase; endcase;
let offset = getOffset(cap); let addr = getAddr(cap);
let oldOffset = getOffset(oldCap); let oldAddr = getAddr(oldCap);
CapPipe res = (case (scrType) matches CapPipe res = (case (scrType) matches
tagged TVEC .csrf: update_scr_via_csr(oldCap, csrOp(oldOffset, getAddr(cap), csrf) & ~64'h2, False); tagged TVEC .csrf: update_scr_via_csr(oldCap, csrOp(oldAddr, getAddr(cap), csrf) & ~64'h2, False);
tagged EPC .csrf: update_scr_via_csr(oldCap, csrOp(oldOffset, getAddr(cap), csrf) & ~64'h1, False); tagged EPC .csrf: update_scr_via_csr(oldCap, csrOp(oldAddr, getAddr(cap), csrf) & ~64'h1, False);
tagged TCC: update_scr_via_csr(cap, offset & ~64'h2, False); // Mask out bit 1 tagged TCC: update_scr_via_csr(cap, addr & ~64'h2, False); // Mask out bit 1
tagged EPCC: update_scr_via_csr(cap, offset & ~64'h1, offset[0] == 1'b0); // Mask out bit 0 tagged EPCC: update_scr_via_csr(cap, addr & ~64'h1, addr[0] == 1'b0); // Mask out bit 0
tagged Normal: cap; tagged Normal: cap;
endcase); endcase);
return res; return res;
@@ -251,8 +251,8 @@ function CapPipe capModify(CapPipe a, CapPipe b, CapModifyFunc func);
tagged TCC: b; tagged TCC: b;
tagged EPCC: b; tagged EPCC: b;
tagged Normal: b; tagged Normal: b;
tagged TVEC ._: nullWithAddr(getOffset(b)); tagged TVEC ._: nullWithAddr(getAddr(b));
tagged EPC ._: nullWithAddr(getOffset(b)); tagged EPC ._: nullWithAddr(getAddr(b));
endcase endcase
tagged SetAddr .addrSource : tagged SetAddr .addrSource :
clearTagIf(setAddr(b_mut, (addrSource == Src1Type) ? a_type : getAddr(a) ).value, (addrSource == Src1Type) ? a_res : False); clearTagIf(setAddr(b_mut, (addrSource == Src1Type) ? a_type : getAddr(a) ).value, (addrSource == Src1Type) ? a_res : False);
@@ -271,7 +271,7 @@ function CapPipe capModify(CapPipe a, CapPipe b, CapModifyFunc func);
tagged SetFlags : tagged SetFlags :
setFlags(a_mut, truncate(getAddr(b))); setFlags(a_mut, truncate(getAddr(b)));
tagged FromPtr : tagged FromPtr :
(getAddr(a) == 0 ? nullCap : setOffset(b_mut, getAddr(a)).value); (getAddr(a) == 0 ? nullCap : setAddr(b_mut, getAddr(a)).value);
tagged SetHigh: tagged SetHigh:
fromMem(tuple2(False, {getAddr(b), getAddr(a)})); fromMem(tuple2(False, {getAddr(b), getAddr(a)}));
tagged BuildCap : tagged BuildCap :
@@ -367,7 +367,9 @@ function CapPipe brAddrCalc(CapPipe pc, CapPipe val, IType iType, Data imm, Bool
doInc = False; doInc = False;
end end
end end
CapPipe targetAddr = modifyOffset(nextPc, offset, doInc).value; CapPipe targetAddr = ?;
if(doInc) targetAddr = modifyOffset(nextPc, offset, doInc).value;
else targetAddr = setAddr(nextPc, offset).value;
// jumpTarget.address[0] = 1'b0; // jumpTarget.address[0] = 1'b0;
targetAddr = setAddrUnsafe(targetAddr, {truncateLSB(getAddr(targetAddr)), 1'b0}); targetAddr = setAddrUnsafe(targetAddr, {truncateLSB(getAddr(targetAddr)), 1'b0});
targetAddr = setKind(targetAddr, UNSEALED); // It is checked elsewhere that we have an unsealed cap already, or sentry if permitted targetAddr = setKind(targetAddr, UNSEALED); // It is checked elsewhere that we have an unsealed cap already, or sentry if permitted
@@ -434,12 +436,12 @@ function ExecResult basicExec(DecodedInst dInst, CapPipe rVal1, CapPipe rVal2, C
St : rVal2; St : rVal2;
Sc : rVal2; Sc : rVal2;
Amo : rVal2; Amo : rVal2;
J : nullWithAddr(getOffset(link_pcc)); J : nullWithAddr(getAddr(link_pcc));
CJAL : setKind(link_pcc, SENTRY); CJAL : setKind(link_pcc, SENTRY);
CCall : cap_alu_result; CCall : cap_alu_result;
CJALR : setKind(link_pcc, SENTRY); CJALR : setKind(link_pcc, SENTRY);
Jr : nullWithAddr(getOffset(link_pcc)); Jr : nullWithAddr(getAddr(link_pcc));
Auipc : nullWithAddr(getOffset(pcc) + getDInstImm(dInst).Valid); Auipc : nullWithAddr(getAddr(pcc) + getDInstImm(dInst).Valid);
Auipcc : incOffset(pcc, getDInstImm(dInst).Valid).value; // could be computed with alu Auipcc : incOffset(pcc, getDInstImm(dInst).Valid).value; // could be computed with alu
Csr : rVal1; Csr : rVal1;
Scr : cap_alu_result; Scr : cap_alu_result;