Skip to content

Commit

Permalink
remove N extension
Browse files Browse the repository at this point in the history
  • Loading branch information
KotorinMinami committed Sep 14, 2024
1 parent c61351e commit d79e0ba
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 315 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SAIL_VLEN := riscv_vlen.sail

# Instruction sources, depending on target
SAIL_CHECK_SRCS = riscv_addr_checks_common.sail riscv_addr_checks.sail riscv_misa_ext.sail
SAIL_DEFAULT_INST = riscv_insts_base.sail riscv_insts_aext.sail riscv_insts_zca.sail riscv_insts_mext.sail riscv_insts_zicsr.sail riscv_insts_next.sail riscv_insts_hints.sail
SAIL_DEFAULT_INST = riscv_insts_base.sail riscv_insts_aext.sail riscv_insts_zca.sail riscv_insts_mext.sail riscv_insts_zicsr.sail riscv_insts_hints.sail
SAIL_DEFAULT_INST += riscv_insts_fext.sail riscv_insts_zcf.sail
SAIL_DEFAULT_INST += riscv_insts_dext.sail riscv_insts_zcd.sail

Expand Down Expand Up @@ -73,10 +73,8 @@ SAIL_RMEM_INST_SRCS = riscv_insts_begin.sail $(SAIL_RMEM_INST) riscv_insts_end.s
# System and platform sources
SAIL_SYS_SRCS = riscv_csr_map.sail
SAIL_SYS_SRCS += riscv_vext_control.sail # helpers for the 'V' extension
SAIL_SYS_SRCS += riscv_next_regs.sail
SAIL_SYS_SRCS += riscv_sys_exceptions.sail # default basic helpers for exception handling
SAIL_SYS_SRCS += riscv_sync_exception.sail # define the exception structure used in the model
SAIL_SYS_SRCS += riscv_next_control.sail # helpers for the 'N' extension
SAIL_SYS_SRCS += riscv_softfloat_interface.sail riscv_fdext_regs.sail riscv_fdext_control.sail
SAIL_SYS_SRCS += riscv_csr_ext.sail # access to CSR extensions
SAIL_SYS_SRCS += riscv_sys_control.sail # general exception handling
Expand Down
13 changes: 1 addition & 12 deletions model/riscv_csr_map.sail
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ val csr_name_map : csreg <-> string

scattered mapping csr_name_map

/* user trap setup */
mapping clause csr_name_map = 0x000 <-> "ustatus"
mapping clause csr_name_map = 0x004 <-> "uie"
mapping clause csr_name_map = 0x005 <-> "utvec"
/* user trap handling */
mapping clause csr_name_map = 0x040 <-> "uscratch"
mapping clause csr_name_map = 0x041 <-> "uepc"
mapping clause csr_name_map = 0x042 <-> "ucause"
mapping clause csr_name_map = 0x043 <-> "utval"
mapping clause csr_name_map = 0x044 <-> "uip"

/* user floating-point context */
mapping clause csr_name_map = 0x001 <-> "fflags"
mapping clause csr_name_map = 0x002 <-> "frm"
Expand All @@ -38,8 +29,6 @@ mapping clause csr_name_map = 0xC82 <-> "instreth"
/* TODO: other hpm counters */
/* supervisor trap setup */
mapping clause csr_name_map = 0x100 <-> "sstatus"
mapping clause csr_name_map = 0x102 <-> "sedeleg"
mapping clause csr_name_map = 0x103 <-> "sideleg"
mapping clause csr_name_map = 0x104 <-> "sie"
mapping clause csr_name_map = 0x105 <-> "stvec"
mapping clause csr_name_map = 0x106 <-> "scounteren"
Expand Down
26 changes: 0 additions & 26 deletions model/riscv_insts_next.sail

This file was deleted.

4 changes: 0 additions & 4 deletions model/riscv_insts_zicsr.sail
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ function readCSR csr : csreg -> xlenbits = {

/* supervisor mode */
(0x100, _) => lower_mstatus(mstatus).bits,
(0x102, _) => sedeleg.bits,
(0x103, _) => sideleg.bits,
(0x104, _) => lower_mie(mie, mideleg).bits,
(0x105, _) => get_stvec(),
(0x106, _) => zero_extend(scounteren.bits),
Expand Down Expand Up @@ -157,8 +155,6 @@ function writeCSR (csr : csreg, value : xlenbits) -> unit = {

/* supervisor mode */
(0x100, _) => { mstatus = legalize_sstatus(mstatus, value); Some(mstatus.bits) },
(0x102, _) => { sedeleg = legalize_sedeleg(sedeleg, value); Some(sedeleg.bits) },
(0x103, _) => { sideleg.bits = value; Some(sideleg.bits) }, /* TODO: does this need legalization? */
(0x104, _) => { mie = legalize_sie(mie, mideleg, value); Some(mie.bits) },
(0x105, _) => { Some(set_stvec(value)) },
(0x106, _) => { scounteren = legalize_scounteren(scounteren, value); Some(zero_extend(scounteren.bits)) },
Expand Down
40 changes: 0 additions & 40 deletions model/riscv_next_control.sail

This file was deleted.

91 changes: 0 additions & 91 deletions model/riscv_next_regs.sail

This file was deleted.

71 changes: 8 additions & 63 deletions model/riscv_sys_control.sail
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function is_CSR_defined (csr : csreg) -> bool =
/* machine mode: trap setup */
0x300 => true, // mstatus
0x301 => true, // misa
0x302 => extensionEnabled(Ext_S) | extensionEnabled(Ext_N), // medeleg
0x303 => extensionEnabled(Ext_S) | extensionEnabled(Ext_N), // mideleg
0x302 => extensionEnabled(Ext_S) , // medeleg
0x303 => extensionEnabled(Ext_S) , // mideleg
0x304 => true, // mie
0x305 => true, // mtvec
0x306 => extensionEnabled(Ext_U), // mcounteren
Expand Down Expand Up @@ -62,8 +62,6 @@ function is_CSR_defined (csr : csreg) -> bool =

/* supervisor mode: trap setup */
0x100 => extensionEnabled(Ext_S), // sstatus
0x102 => extensionEnabled(Ext_S) & extensionEnabled(Ext_N), // sedeleg
0x103 => extensionEnabled(Ext_S) & extensionEnabled(Ext_N), // sideleg
0x104 => extensionEnabled(Ext_S), // sie
0x105 => extensionEnabled(Ext_S), // stvec
0x106 => extensionEnabled(Ext_S), // scounteren
Expand Down Expand Up @@ -177,12 +175,7 @@ val cancel_reservation = impure {ocaml: "Platform.cancel_reservation", interpret
function exception_delegatee(e : ExceptionType, p : Privilege) -> Privilege = {
let idx = num_of_ExceptionType(e);
let super = bit_to_bool(medeleg.bits[idx]);
/* if S-mode is absent, medeleg delegates to U-mode if 'N' is supported. */
let user = if extensionEnabled(Ext_S)
then super & extensionEnabled(Ext_N) & bit_to_bool(sedeleg.bits[idx])
else super & extensionEnabled(Ext_N);
let deleg = if extensionEnabled(Ext_U) & user then User
else if extensionEnabled(Ext_S) & super then Supervisor
let deleg = if extensionEnabled(Ext_S) & super then Supervisor
else Machine;
/* We cannot transition to a less-privileged mode. */
if privLevel_to_bits(deleg) <_u privLevel_to_bits(p)
Expand All @@ -200,9 +193,6 @@ function findPendingInterrupt(ip : xlenbits) -> option(InterruptType) = {
else if ip[SEI] == 0b1 then Some(I_S_External)
else if ip[SSI] == 0b1 then Some(I_S_Software)
else if ip[STI] == 0b1 then Some(I_S_Timer)
else if ip[UEI] == 0b1 then Some(I_U_External)
else if ip[USI] == 0b1 then Some(I_U_Software)
else if ip[UTI] == 0b1 then Some(I_U_Timer)
else None()
}

Expand Down Expand Up @@ -248,24 +238,12 @@ function getPendingSet(priv : Privilege) -> option((xlenbits, Privilege)) = {
*/
let mIE = priv != Machine | (priv == Machine & mstatus[MIE] == 0b1);
let sIE = extensionEnabled(Ext_S) & (priv == User | (priv == Supervisor & mstatus[SIE] == 0b1));
let uIE = extensionEnabled(Ext_N) & (priv == User & mstatus[UIE] == 0b1);
match processPending(mip, mie, mideleg.bits, mIE) {
Ints_Empty() => None(),
Ints_Pending(p) => let r = (p, Machine) in Some(r),
Ints_Delegated(d) =>
if not(extensionEnabled(Ext_S)) then {
if uIE then let r = (d, User) in Some(r)
else None()
} else {
/* the delegated bits are pending for S-mode */
match processPending(Mk_Minterrupts(d), mie, sideleg.bits, sIE) {
Ints_Empty() => None(),
Ints_Pending(p) => let r = (p, Supervisor) in Some(r),
Ints_Delegated(d) => if uIE
then let r = (d, User) in Some(r)
else None()
}
}
if not(extensionEnabled(Ext_S)) | not(sIE) then None()
else let r = (d, Supervisor) in Some(r)
}
}
}
Expand All @@ -285,7 +263,7 @@ function dispatchInterrupt(priv : Privilege) -> option((InterruptType, Privilege
one that can take interrupts, i.e. when we don't have S-mode and don't have
the N extension
*/
let delegationPossible = extensionEnabled(Ext_S) | extensionEnabled(Ext_N);
let delegationPossible = extensionEnabled(Ext_S);
if multipleModesSupported & delegationPossible then {
match getPendingSet(priv) {
None() => None(),
Expand All @@ -308,8 +286,7 @@ function dispatchInterrupt(priv : Privilege) -> option((InterruptType, Privilege
union ctl_result = {
CTL_TRAP : sync_exception,
CTL_SRET : unit,
CTL_MRET : unit,
CTL_URET : unit
CTL_MRET : unit
}

/* trap value */
Expand Down Expand Up @@ -386,26 +363,7 @@ function trap_handler(del_priv : Privilege, intr : bool, c : exc_code, pc : xlen

prepare_trap_vector(del_priv, scause)
},
User => {
assert(extensionEnabled(Ext_U), "no user mode present for delegation");

ucause[IsInterrupt] = bool_to_bits(intr);
ucause[Cause] = zero_extend(c);

mstatus[UPIE] = mstatus[UIE];
mstatus[UIE] = 0b0;
utval = tval(info);
uepc = pc;

cur_privilege = del_priv;

handle_trap_extension(del_priv, pc, ext);

if get_config_print_reg()
then print_reg("CSR mstatus <- " ^ BitStr(mstatus.bits));

prepare_trap_vector(del_priv, ucause)
}
User => internal_error(__FILE__, __LINE__, "Invalid privilege level")
};
}

Expand Down Expand Up @@ -451,19 +409,6 @@ function exception_handler(cur_priv : Privilege, ctl : ctl_result,
^ " to " ^ to_str(cur_privilege));

prepare_xret_target(Supervisor) & pc_alignment_mask()
},
(_, CTL_URET()) => {
let prev_priv = cur_privilege;
mstatus[UIE] = mstatus[UPIE];
mstatus[UPIE] = 0b1;
cur_privilege = User;

if get_config_print_reg()
then print_reg("CSR mstatus <- " ^ BitStr(mstatus.bits));
if get_config_print_platform()
then print_platform("ret-ing from " ^ to_str(prev_priv) ^ " to " ^ to_str(cur_privilege));

prepare_xret_target(User) & pc_alignment_mask()
}
}
}
Expand Down
Loading

0 comments on commit d79e0ba

Please sign in to comment.