Skip to content

Commit

Permalink
replace sizeof(xlen) with xlen
Browse files Browse the repository at this point in the history
  • Loading branch information
YazanHussnain-10x committed Oct 4, 2024
1 parent 9fcaa74 commit e272dfe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
37 changes: 21 additions & 16 deletions model/riscv_sys_control.sail
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function TriggerFireMatch(cur_priv : Privilege) -> bool = {
function icount_trigger_match(cur_priv : Privilege) -> unit = {
/* Traverse through all the triggers */
foreach (i from 0 to (sizeof(N_TRIGGERS) - 1)) {
let trigger_type : bits(4) = tdata1_x.tdata1[i][(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)];
let trigger_type : bits(4) = tdata1_x.tdata1[i][(xlen - 1) .. (xlen - 4)];
/* If Instruction Count trigger is found */
if (trigger_type == triggerType_to_bits(TRIG_ICOUNT)) then {
var InstrCount : InstructionCount = Mk_InstructionCount(tdata1_x.tdata1[i][26 .. 0]);
Expand All @@ -387,7 +387,7 @@ function icount_trigger_match(cur_priv : Privilege) -> unit = {
function IEtrigger_match(cur_priv : Privilege, idx : {'n, (0 <= 'n < xlen). int('n)}) -> unit = {
/* Traverse through all the triggers */
foreach (i from 0 to (sizeof(N_TRIGGERS) - 1)) {
let trigger_type : bits(4) = tdata1_x.tdata1[i][(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)];
let trigger_type : bits(4) = tdata1_x.tdata1[i][(xlen - 1) .. (xlen - 4)];
/* If Interrupt / Exception trigger found */
if ((trigger_type == triggerType_to_bits(TRIG_ETRIGGER)) |
(trigger_type == triggerType_to_bits(TRIG_ITRIGGER))) then {
Expand Down Expand Up @@ -565,7 +565,7 @@ function handle_interrupt(i : InterruptType, del_priv : Privilege) -> unit = {
}

function find_first_zero(v: xlenbits) -> {'n, (1 <= 'n < xlen). int('n)} = {
foreach (i from 1 to (sizeof(xlen) - 1)) {
foreach (i from 1 to (xlen - 1)) {
if v[i .. i] == 0b0 then return i;
};
return 1;
Expand All @@ -574,9 +574,10 @@ function find_first_zero(v: xlenbits) -> {'n, (1 <= 'n < xlen). int('n)} = {
/* Match Control Type 6 Trigger Match */
function instrDataMatch(cur_priv : Privilege, addr : xlenbits, data : xlenbits, match_size : matchSize, match_type : MatchType) -> bool = {
var raise_exception : bool = false;
let half_xlen = sizeof(half_xlen);
/* Traverse through all tirggers */
foreach (i from 0 to (sizeof(N_TRIGGERS) - 1)) {
let trigger_type : bits(4) = tdata1_x.tdata1[i][(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)];
let trigger_type : bits(4) = tdata1_x.tdata1[i][(xlen - 1) .. (xlen - 4)];
var data_matched : bool = false;
var size_matched : bool = false;
/* Match Control Type 6 Trigger found */
Expand All @@ -601,24 +602,28 @@ function instrDataMatch(cur_priv : Privilege, addr : xlenbits, data : xlenbits,
let idx : {'n, (1 <= 'n < xlen). int('n)} = find_first_zero(tdata2_content);
tdata2_x.tdata2[i][(xlen - 1) .. (xlen - idx)] == tdata2_content[(xlen - 1) .. (xlen - idx)]
},
MOPT_GE => { (tdata2_content >=_u tdata2_x.tdata2[i][(sizeof(xlen) - 1) .. 0]) },
MOPT_LT => { (tdata2_content <_u tdata2_x.tdata2[i][(sizeof(xlen) - 1) .. 0]) },
MOPT_GE => { (tdata2_content >=_u tdata2_x.tdata2[i][(xlen - 1) .. 0]) },
MOPT_LT => { (tdata2_content <_u tdata2_x.tdata2[i][(xlen - 1) .. 0]) },
MOPT_MASK_LOW => {
let intemrd_cmpr_val : half_xlenbits = tdata2_content[((sizeof(xlen) / 2) - 1) .. 0] & tdata2_x.tdata2[i][(sizeof(xlen) - 1) .. (sizeof(xlen) / 2)];
intemrd_cmpr_val == tdata2_x.tdata2[i][((sizeof(xlen) / 2) - 1) .. 0]
let intemrd_cmpr_val : half_xlenbits = tdata2_content[(half_xlen - 1) .. 0] & tdata2_x.tdata2[i][(xlen - 1) .. half_xlen];
intemrd_cmpr_val == tdata2_x.tdata2[i][(half_xlen - 1) .. 0]
},
MOPT_MASK_HIGH => {
let intemrd_cmpr_val : half_xlenbits = tdata2_content[(sizeof(xlen) - 1) .. (sizeof(xlen) / 2)] & tdata2_x.tdata2[i][(sizeof(xlen) - 1) .. (sizeof(xlen) / 2)];
intemrd_cmpr_val == tdata2_x.tdata2[i][((sizeof(xlen) / 2) - 1) .. 0]
let intemrd_cmpr_val : half_xlenbits = tdata2_content[(xlen - 1) .. half_xlen] & tdata2_x.tdata2[i][(xlen - 1) .. half_xlen];
intemrd_cmpr_val == tdata2_x.tdata2[i][(half_xlen - 1) .. 0]
},
MOPT_NOT_EQUAL => { (tdata2_x.tdata2[i] != tdata2_content) },
MOPT_NOT_NAPOT => {
let idx : {'n, (1 <= 'n < xlen). int('n)} = find_first_zero(tdata2_content);
tdata2_x.tdata2[i][(xlen - 1) .. (xlen - idx)] != tdata2_content[(xlen - 1) .. (xlen - idx)]
},
MOPT_NOT_MASK_LOW => {
let intemrd_cmpr_val : half_xlenbits = tdata2_content[((sizeof(xlen) / 2) - 1) .. 0] & tdata2_x.tdata2[i][(sizeof(xlen) - 1) .. (sizeof(xlen) / 2)];
intemrd_cmpr_val != tdata2_x.tdata2[i][((sizeof(xlen) / 2) - 1) .. 0]
let intemrd_cmpr_val : half_xlenbits = tdata2_content[(half_xlen - 1) .. 0] & tdata2_x.tdata2[i][(xlen - 1) .. half_xlen];
intemrd_cmpr_val != tdata2_x.tdata2[i][(half_xlen - 1) .. 0]
},
MOPT_NOT_MASK_HIGH => {
let intemrd_cmpr_val : half_xlenbits = tdata2_content[(sizeof(xlen) - 1) .. (sizeof(xlen) / 2)] & tdata2_x.tdata2[i][(sizeof(xlen) - 1) .. (sizeof(xlen) / 2)];
intemrd_cmpr_val != tdata2_x.tdata2[i][((sizeof(xlen) / 2) - 1) .. 0]
let intemrd_cmpr_val : half_xlenbits = tdata2_content[(xlen - 1) .. half_xlen] & tdata2_x.tdata2[i][(xlen - 1) .. half_xlen];
intemrd_cmpr_val != tdata2_x.tdata2[i][(half_xlen - 1) .. 0]
},
_ => false
};
Expand Down Expand Up @@ -697,7 +702,7 @@ function check_trigger_firing(cur_priv : Privilege) -> bool = {
InstrCount = Mk_InstructionCount(tdata1_x.tdata1[i][26 .. 0]);
IEtrigger = Mk_InterruptTrigger(tdata1_x.tdata1[i]);
MCtrl6 = Mk_MatchControlType6(tdata1_x.tdata1[i][26 .. 0]);
let trigger_type : bits(4) = tdata1_x.tdata1[i][(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)];
let trigger_type : bits(4) = tdata1_x.tdata1[i][(xlen - 1) .. (xlen - 4)];
match triggerType_of_bits(trigger_type) {
/* Check Exception Trigger Firing */
TRIG_ETRIGGER => {
Expand Down Expand Up @@ -822,7 +827,7 @@ function init_sys() -> unit = {
vtype[vlmul] = 0b000;

foreach (i from 0 to 6) {
tdata1_x.tdata1[i][(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)] = 0xf;
tdata1_x.tdata1[i][(xlen - 1) .. (xlen - 4)] = 0xf;
};

// PMP's L and A fields are set to 0 on reset.
Expand Down
14 changes: 7 additions & 7 deletions model/riscv_sys_regs.sail
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ bitfield InterruptTrigger : xlenbits = {

/* Legalize Tdata1 */
function legalize_tdata1(o : xlenbits, v : xlenbits) -> xlenbits = {
let trigger_type : bits(4) = v[(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)];
let trigger_dmode : bits(1) = v[(sizeof(xlen) - 5) .. (sizeof(xlen) - 5)];
let trigger_type : bits(4) = v[(xlen - 1) .. (xlen - 4)];
let trigger_dmode : bits(1) = v[(xlen - 5) .. (xlen - 5)];
/* TODO: Update trigger action when remaining trigger action option will add */
let trigger_action : bits(6) = (0b00 @ 0x0);
let MCtrl6 : MatchControlType6 = Mk_MatchControlType6(v[26 .. 0]);
Expand All @@ -881,8 +881,8 @@ function legalize_tdata1(o : xlenbits, v : xlenbits) -> xlenbits = {
let ExcepTrigger : InterruptTrigger = Mk_InterruptTrigger(v);
var new_value : xlenbits = o;

new_value[(sizeof(xlen) - 1) .. (sizeof(xlen) - 4)] = trigger_type;
new_value[(sizeof(xlen) - 5) .. (sizeof(xlen) - 5)] = trigger_dmode;
new_value[(xlen - 1) .. (xlen - 4)] = trigger_type;
new_value[(xlen - 5) .. (xlen - 5)] = trigger_dmode;
match triggerType_of_bits(trigger_type){
TRIG_ICOUNT => {
/* Trigger action */
Expand All @@ -899,7 +899,7 @@ function legalize_tdata1(o : xlenbits, v : xlenbits) -> xlenbits = {
/* nmi | m */
new_value[10 .. 9] = (IntrptTrigger[nmi] @ IntrptTrigger[m]);
/* hit */
new_value[(sizeof(xlen) - 6) .. (sizeof(xlen) - 6)] = IntrptTrigger[hit];
new_value[(xlen - 6) .. (xlen - 6)] = IntrptTrigger[hit];
new_value
},
TRIG_ETRIGGER => {
Expand All @@ -910,15 +910,15 @@ function legalize_tdata1(o : xlenbits, v : xlenbits) -> xlenbits = {
/* m */
new_value[9 .. 9] = IntrptTrigger[m];
/* hit */
new_value[(sizeof(xlen) - 6) .. (sizeof(xlen) - 6)] = IntrptTrigger[hit];
new_value[(xlen - 6) .. (xlen - 6)] = IntrptTrigger[hit];
new_value
},
TRIG_MCONTROL6 => {
let match_option : MATCH_OPTIONS = matchOpt_of_bits(v[10 .. 7]);
/* m | uncertainen | s | u | execute | store | load */
new_value[6 .. 0] = MCtrl6.bits[6 .. 0];
/* match */
new_value[10 .. 7] = v[10 .. 7];
new_value[10 .. 7] = match matchOpt_of_bits(v[10 .. 7]) { RSVD => { o[10 .. 7]}, _ => { v[10 .. 7] } };
/* size | action | chain */
new_value[18 .. 11] = (MCtrl6[size] @ trigger_action[3 .. 0] @ MCtrl6[chain]);
/* hit0 | select */
Expand Down
11 changes: 9 additions & 2 deletions model/riscv_types.sail
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ enum MATCH_OPTIONS = {
MOPT_NOT_EQUAL,
MOPT_NOT_NAPOT,
MOPT_NOT_MASK_LOW,
MOPT_NOT_MASK_HIGH
MOPT_NOT_MASK_HIGH,
RSVD
}

mapping matchOpt_of_bits : bits(4) <-> MATCH_OPTIONS = {
Expand All @@ -347,10 +348,16 @@ mapping matchOpt_of_bits : bits(4) <-> MATCH_OPTIONS = {
0x3 <-> MOPT_LT,
0x4 <-> MOPT_MASK_LOW,
0x5 <-> MOPT_MASK_HIGH,
0x6 <-> RSVD,
0x7 <-> RSVD,
0x8 <-> MOPT_NOT_EQUAL,
0x9 <-> MOPT_NOT_NAPOT,
0xA <-> RSVD,
0xB <-> RSVD,
0xC <-> MOPT_NOT_MASK_LOW,
0xD <-> MOPT_NOT_MASK_HIGH
0xD <-> MOPT_NOT_MASK_HIGH,
0xE <-> RSVD,
0xF <-> RSVD,
}

enum MatchType = {
Expand Down

0 comments on commit e272dfe

Please sign in to comment.