From e272dfeb1d8feb6501ea883259ee4538998d4b80 Mon Sep 17 00:00:00 2001 From: YazanHussnain-10x Date: Fri, 4 Oct 2024 15:08:22 +0500 Subject: [PATCH] replace sizeof(xlen) with xlen --- model/riscv_sys_control.sail | 37 ++++++++++++++++++++---------------- model/riscv_sys_regs.sail | 14 +++++++------- model/riscv_types.sail | 11 +++++++++-- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/model/riscv_sys_control.sail b/model/riscv_sys_control.sail index 27280bcb4..743fe6a71 100644 --- a/model/riscv_sys_control.sail +++ b/model/riscv_sys_control.sail @@ -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]); @@ -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 { @@ -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; @@ -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 */ @@ -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 }; @@ -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 => { @@ -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. diff --git a/model/riscv_sys_regs.sail b/model/riscv_sys_regs.sail index 8202f6ee3..24df1c06e 100644 --- a/model/riscv_sys_regs.sail +++ b/model/riscv_sys_regs.sail @@ -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]); @@ -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 */ @@ -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 => { @@ -910,7 +910,7 @@ 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 => { @@ -918,7 +918,7 @@ function legalize_tdata1(o : xlenbits, v : xlenbits) -> xlenbits = { /* 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 */ diff --git a/model/riscv_types.sail b/model/riscv_types.sail index cdefd1366..0bb10fb05 100644 --- a/model/riscv_types.sail +++ b/model/riscv_types.sail @@ -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 = { @@ -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 = {