Skip to content

Commit

Permalink
Split modesw into cap and int versions
Browse files Browse the repository at this point in the history
As per more recent spec
This also deprecates the compressed version
  • Loading branch information
PeterRugg committed Jan 29, 2025
1 parent 9641751 commit aaefc44
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
53 changes: 37 additions & 16 deletions src/cheri_insts.sail
Original file line number Diff line number Diff line change
Expand Up @@ -309,31 +309,49 @@ function clause execute(SCMODE(cd, cs1, rs2)) = {
RETIRE_SUCCESS
}

union clause ast = MODESW : unit
union clause ast = MODESWCAP : unit
/*!
* insnref: modesw_32bit
* Switch CHERI execution mode
* insnref: modeswcap_32bit
* Switch to CHERI capability execution mode
*
* modesw
* modeswcap
*
* Toggle the hart's current CHERI execution mode in pcc.
* Set the hart's current CHERI execution mode in pcc to capmode.
*
* * If the current mode in pcc is _Integer Pointer Mode_ (1), then the
* M-bit in pcc is set to _Capability Pointer Mode_ (0).
* * If the current mode is _Capability Pointer Mode_ (0), then the M-bit
* in pcc is set to _Integer Pointer Mode_ (1).
* The M-bit in pcc is set to _Capability Pointer Mode_ (0).
*
* Executing MODESW from the program buffer in debug mode updates the M-bit
* of dinfc. The M-bit of dinfc sets the CHERI execution mode for the
* execution of the next instruction from the program buffer, and is used
* to control which CHERI execution mode to enter next time debug mode is entered.
* The CHERI execution mode is only controlled by the M-bit of dinfc in debug mode.
*/
function clause execute(MODESW()) = {
let mode : ExecutionMode = match effective_cheri_mode() {
IntPtrMode => CapPtrMode,
CapPtrMode => IntPtrMode,
};
function clause execute(MODESWCAP()) = {
let mode : ExecutionMode = CapPtrMode;
if debug_mode_active then dinfc = setCapMode(infinite_cap, mode);
set_next_pcc(setCapMode(PCC, mode));
RETIRE_SUCCESS
}

union clause ast = MODESWINT : unit
/*!
* insnref: modeswint_32bit
* Switch to CHERI integer execution mode
*
* modeswint
*
* Set the hart's current CHERI execution mode in pcc to intmode.
*
* The M-bit in pcc is set to _Integer Pointer Mode_ (1).
*
* Executing MODESW from the program buffer in debug mode updates the M-bit
* of dinfc. The M-bit of dinfc sets the CHERI execution mode for the
* execution of the next instruction from the program buffer, and is used
* to control which CHERI execution mode to enter next time debug mode is entered.
* The CHERI execution mode is only controlled by the M-bit of dinfc in debug mode.
*/
function clause execute(MODESWINT()) = {
let mode : ExecutionMode = IntPtrMode;
if debug_mode_active then dinfc = setCapMode(infinite_cap, mode);
set_next_pcc(setCapMode(PCC, mode));
RETIRE_SUCCESS
Expand Down Expand Up @@ -1027,10 +1045,13 @@ function clause execute AMOSwapCap(cd, cs2, rs1_cs1, aq, rl) = {

/* Zero arg */

mapping clause encdec = MODESW() if cheri_registers_enabled()
mapping clause encdec = MODESWCAP() if cheri_registers_enabled()
<-> 0b0001001 @ 0b00000 @ 0b00000 @ 0b001 @ 0b00000 @ 0b0110011 if cheri_registers_enabled()
mapping clause encdec = MODESWINT() if cheri_registers_enabled()
<-> 0b0001010 @ 0b00000 @ 0b00000 @ 0b001 @ 0b00000 @ 0b0110011 if cheri_registers_enabled()

mapping clause assembly = MODESW() <-> "modesw"
mapping clause assembly = MODESWCAP() <-> "modeswcap"
mapping clause assembly = MODESWINT() <-> "modeswint"

/* Two arg */

Expand Down
18 changes: 9 additions & 9 deletions src/cheri_insts_cext.sail
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ mapping clause assembly = C_MV_capmode(cd, cs2)
<-> "c.mv" ^ spc() ^ cap_reg_name(cd) ^ sep() ^ cap_reg_name(cs2)
if cd != zreg & cs2 != zreg

union clause ast = C_MODESW : unit
//union clause ast = C_MODESW : unit
//
//// C.MODESW is valid in capability and integer pointer modes.
//mapping clause encdec_compressed = C_MODESW() if cheri_registers_enabled()
// <-> 0b100 @ 0b111 @ 0b000 @ 0b11 @ 0b111 @ 0b01 if cheri_registers_enabled()
//
//mapping clause assembly = C_MODESW() <-> "c.modesw"

// C.MODESW is valid in capability and integer pointer modes.
mapping clause encdec_compressed = C_MODESW() if cheri_registers_enabled()
<-> 0b100 @ 0b111 @ 0b000 @ 0b11 @ 0b111 @ 0b01 if cheri_registers_enabled()

mapping clause assembly = C_MODESW() <-> "c.modesw"

/*!
/*
* insnref: modesw_16bit
* Capability/_Integer Pointer Mode_ switching (C.MODESW), 16-bit
* encoding
Expand All @@ -317,4 +317,4 @@ mapping clause assembly = C_MODESW() <-> "c.modesw"
* * If the current mode is _Capability Pointer Mode_ (0), then the M-bit
* in pcc is set to _Integer Pointer Mode_ (1).
*/
function clause execute(C_MODESW()) = execute(MODESW())
//function clause execute(C_MODESW()) = execute(MODESW())

0 comments on commit aaefc44

Please sign in to comment.