Replace enums-for-constants with structs wrapping a plain Bit#(n)

BSC does not play nicely with enums whose labels do not start at 0 and
increase linearly. Instead, in such cases, it generates a whole bunch of
conditions to "legalise" any read values, which causes an explosion of
logic in places like the ROB. Thus, use this ugly (but still typed)
alternative that, other than naming conventions enforced by BSC, looks
almost the same as an enum.
This commit is contained in:
Jessica Clarke
2020-07-15 02:43:50 +01:00
parent b65576b112
commit 7eff218288
20 changed files with 590 additions and 497 deletions

View File

@@ -0,0 +1,26 @@
`CHERIException(None, 5'd0)
`CHERIException(LengthViolation, 5'd1)
`CHERIException(TagViolation, 5'd2)
`CHERIException(SealViolation, 5'd3)
`CHERIException(TypeViolation, 5'd4)
`CHERIException(CallTrap, 5'd5)
`CHERIException(ReturnTrap, 5'd6)
`CHERIException(StackUnderflow, 5'd7)
`CHERIException(SoftwarePermViolation, 5'd8)
`CHERIException(MMUStoreCapProhibit, 5'd9)
`CHERIException(RepresentViolation, 5'd10)
`CHERIException(UnalignedBase, 5'd11)
// 5'd12 - 5'd15 reserved
`CHERIException(GlobalViolation, 5'd16)
`CHERIException(PermitXViolation, 5'd17)
`CHERIException(PermitRViolation, 5'd18)
`CHERIException(PermitWViolation, 5'd19)
`CHERIException(PermitRCapViolation, 5'd20)
`CHERIException(PermitWCapViolation, 5'd21)
`CHERIException(PermitWLocalCapViolation, 5'd22)
`CHERIException(PermitSealViolation, 5'd23)
`CHERIException(PermitASRViolation, 5'd24)
`CHERIException(PermitCCallViolation, 5'd25)
`CHERIException(PermitUnsealViolation, 5'd26)
`CHERIException(PermitSetCIDViolation, 5'd27)
// 5'd28 - 5'd31 reserved

View File

@@ -36,41 +36,29 @@ typedef TMul#(XLEN, 2) CLEN;
// Exception codes
typedef enum {
None = 5'd0,
LengthViolation = 5'd1,
TagViolation = 5'd2,
SealViolation = 5'd3,
TypeViolation = 5'd4,
CallTrap = 5'd5,
ReturnTrap = 5'd6,
StackUnderflow = 5'd7,
SoftwarePermViolation = 5'd8,
MMUStoreCapProhibit = 5'd9,
RepresentViolation = 5'd10,
UnalignedBase = 5'd11,
// 5'd12 - 5'd15 reserved
GlobalViolation = 5'd16,
PermitXViolation = 5'd17,
PermitRViolation = 5'd18,
PermitWViolation = 5'd19,
PermitRCapViolation = 5'd20,
PermitWCapViolation = 5'd21,
PermitWLocalCapViolation = 5'd22,
PermitSealViolation = 5'd23,
PermitASRViolation = 5'd24,
PermitCCallViolation = 5'd25,
PermitUnsealViolation = 5'd26,
PermitSetCIDViolation = 5'd27
// 5'd28 - 5'd31 reserved
} CHERIException deriving(Bits, Eq, FShow);
typedef struct { Bit#(5) code; } CHERIException deriving(Bits, Eq);
`define CHERIException(n, v) CHERIException cheriExc``n = CHERIException { code: v };
`include "CHERIExceptions.bsvi"
`undef CHERIException
instance FShow#(CHERIException);
function Fmt fshow(CHERIException exc);
return (case(exc.code)
`define CHERIException(n, v) v: $format(`"``cheriExc``n```");
`include "CHERIExceptions.bsvi"
`undef CHERIException
default: $format("cheriExcUnknown");
endcase);
endfunction
endinstance
typedef struct {
Bit #(6) cheri_exc_reg;
CHERIException cheri_exc_code;
} CSR_XCapCause deriving(Bits, Eq, FShow);
CSR_XCapCause noCapCause = CSR_XCapCause {cheri_exc_code: None,
CSR_XCapCause noCapCause = CSR_XCapCause {cheri_exc_code: cheriExcNone,
cheri_exc_reg: unpack(0)};
function Bit#(64) xccsr_to_word(CSR_XCapCause xccsr);
@@ -87,20 +75,31 @@ endfunction
// SCR map
typedef enum {
`define SCR(s,v) s = v,
`include "SCRs.bsvi"
`undef SCR
// As with CSRs, SCR that catches all unimplemented SCRs
SCR_None = 5'd10
} SCR deriving(Bits, Eq, FShow, Bounded);
typedef struct { Bit#(5) addr; } SCR deriving(Bits, Eq);
function SCR unpackSCR(Bit#(5) x);
return (case(x)
`define SCR(s,v) pack(SCR'(s)): (s);
`define SCR(n, v) SCR scrAddr``n = SCR { addr: v };
`include "SCRs.bsvi"
// As with CSRs, SCR that catches all unimplemented SCRs
`SCR(None, 5'd10)
`undef SCR
instance FShow#(SCR);
function Fmt fshow(SCR scr);
return (case(scr.addr)
`define SCR(n, v) v: $format(`"``scrAddr``n```");
`include "SCRs.bsvi"
`undef SCR
default : (SCR_None);
default: $format("scrAddrNone");
endcase);
endfunction
endinstance
function SCR unpackSCR(Bit#(5) addr);
return (case(addr)
`define SCR(n, v) v: scrAddr``n;
`include "SCRs.bsvi"
`undef SCR
default: scrAddrNone;
endcase);
endfunction

View File

@@ -1,17 +1,17 @@
`SCR(SCR_PCC , 5'd00)
`SCR(SCR_DDC , 5'd01)
`SCR(PCC, 5'd00)
`SCR(DDC, 5'd01)
//`SCR(SCR_UTCC , 5'd0)
//`SCR(SCR_UTDC , 5'd05)
//`SCR(SCR_UScratchC , 5'd06)
//`SCR(SCR_UEPCC , 5'd07)
//`SCR(UTCC, 5'd0)
//`SCR(UTDC, 5'd05)
//`SCR(UScratchC, 5'd06)
//`SCR(UEPCC, 5'd07)
`SCR(SCR_STCC , 5'd12)
`SCR(SCR_STDC , 5'd13)
`SCR(SCR_SScratchC , 5'd14)
`SCR(SCR_SEPCC , 5'd15)
`SCR(STCC, 5'd12)
`SCR(STDC, 5'd13)
`SCR(SScratchC, 5'd14)
`SCR(SEPCC, 5'd15)
`SCR(SCR_MTCC , 5'd28)
`SCR(SCR_MTDC , 5'd29)
`SCR(SCR_MScratchC , 5'd30)
`SCR(SCR_MEPCC , 5'd31)
`SCR(MTCC, 5'd28)
`SCR(MTDC, 5'd29)
`SCR(MScratchC, 5'd30)
`SCR(MEPCC, 5'd31)