Skip to content

Commit f23adeb

Browse files
split MODESW into MODESW.CAP and MODESW.INT (riscv#406)
MODESW is difficult to implement in higher performance implementations as it causes a lot of uncertainty in pre-decode and decode about which mode is currently being entered. It also causes a long sequential path through a wide-issue decode packet, compared with entering a specific mode which makes it much easier to determine the mode for each instruction. Therefore it is split into two which directly enter the named mode MODESW.CAP for cap mode and MODESW.INT for int mode, so that instructions can be decoded much more easily. It was only a single encoding before to try and reduced the 16-bit encoding space for C.MODESW. This is guaranteed not to be accepted without showing significant code-size reduction or performance improvement as part of the standardisation process. Only using 32-bit encodings means we can add a second encoding, and so be specific about which mode to enter. --------- Co-authored-by: Andrés Amaya Garcia <andres.amaya@codasip.com>
1 parent bea1aee commit f23adeb

12 files changed

+38
-88
lines changed

src/csv/CHERI_ISA.csv

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"GCTYPE","✔","✔","","","","✔","✔","Both","","","","","","","","","","","","","","","","","OP","1-src 1-dst","","","Get capability type","","","","","","","",""
5353
"SCMODE","✔","✔","","","","✔","","Both","","","","","","","","","","","","","","","","","OP","1-src 1-dst","","","Set the mode bit of a capability, no permissions required","","","","","","","",""
5454
"GCMODE","✔","✔","","","","✔","","Both","","","","","","","","","","","","","","","","","OP","1-src 1-dst","","","Get the mode bit of a capability, no permissions required","","","","","","","",""
55-
"MODESW","✔","✔","","","","✔","","Both","","","","","","","","","","","","","","","","","OP","no operands","","","Directly switch mode ({cheri_int_mode_name}/ {cheri_cap_mode_name})","mode==D (optional)","","","","","","",""
56-
"C.MODESW","✔","✔","","","","✔","","Both","","","","","","","","","","","","","","","","","C1","no operands","","","Directly switch mode ({cheri_int_mode_name}/ {cheri_cap_mode_name})","mode==D (optional)","","","","","","",""
55+
"MODESW.CAP","✔","✔","","","","✔","","Both","","","","","","","","","","","","","","","","","OP","no operands","","","Directly switch mode into {cheri_cap_mode_name}","mode==D (optional)","","","","","","",""
56+
"MODESW.INT","✔","✔","","","","✔","","Both","","","","","","","","","","","","","","","","","OP","no operands","","","Directly switch mode into {cheri_int_mode_name}","mode==D (optional)","","","","","","",""
5757
"C.ADDI16SP","✔","✔","","","","✔","✔","Both","","","","✔","","","","","","","","","","","","","C0","","","","ADD immediate to stack pointer, CADD in Capability Mode","","","","","","","",""
5858
"C.ADDI4SPN","✔","✔","","","","✔","✔","Both","","","","✔","","","","","","","","","","","","","C0","","","","ADD immediate to stack pointer, CADDI in Capability Mode","","","","","","","",""
5959
"C.MV","✔","✔","","","","✔","✔","Both","","","","✔","","","","","","","","","","","","","C2","","","","Register Move, cap reg move in Capability Mode","","","","","","","",""

src/debug-integration.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ include::img/dpccreg.edn[]
108108
Upon entry to debug mode, cite:[riscv-debug-spec], does not specify how to
109109
update the PC, and says PC relative instructions may be illegal. This concept
110110
is extended to include any instruction which reads or updates <<pcc>>, which refers to
111-
all jumps, conditional branches and <<AUIPC>>. The exception is <<MODESW>>
112-
which _is_ supported if {cheri_default_ext_name} is implemented, see <<dinfc>>
111+
all jumps, conditional branches and <<AUIPC>>. The exceptions are <<MODESW_CAP>> and <<MODESW_INT>>
112+
which _are_ supported if {cheri_default_ext_name} is implemented, see <<dinfc>>
113113
for details.
114114

115115
As a result, the value of <<pcc>> is UNSPECIFIED in debug mode according
@@ -180,8 +180,8 @@ The reset value is the <<infinite-cap>> capability.
180180
If {cheri_default_ext_name} is implemented:
181181

182182
* The <<m_bit>> is reset to {cheri_int_mode_name} ({INT_MODE_VALUE}).
183-
* The debugger can set the <<m_bit>> to {cheri_cap_mode_name} ({CAP_MODE_VALUE}) by executing <<MODESW>> from the program buffer
184-
** if <<MODESW>> is not supported in debug mode then the same can be done by reading the CSR, using <<SCMODE>> and then writing the CSR.
183+
* The debugger can set the <<m_bit>> to {cheri_cap_mode_name} ({CAP_MODE_VALUE}) by executing <<MODESW_CAP>> from the program buffer
184+
** if <<MODESW_CAP>> is not supported in debug mode then the same can be done by reading the CSR, using <<SCMODE>> and then writing the CSR.
185185
** This only needs doing once after resetting the core.
186186
* The <<m_bit>> is used on debug mode entry to determine which CHERI execution mode to enter.
187187

src/insns/modesw_16bit.adoc

-32
This file was deleted.

src/insns/modesw_32bit.adoc

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
<<<
22

3-
[#MODESW,reftext="MODESW"]
4-
==== MODESW
3+
[#MODESW_INT,reftext="MODESW.INT"]
4+
==== MODESW.INT
5+
See <<MODESW_CAP>>.
56

6-
include::new_encoding_note.adoc[]
7+
[#MODESW_CAP,reftext="MODESW.CAP"]
8+
==== MODESW.CAP
79

810
Synopsis::
9-
{cheri_cap_mode_name}/{cheri_int_mode_name} switching (MODESW), 32-bit encoding
11+
Switch execution mode to {cheri_cap_mode_name} (MODESW.CAP), or {cheri_int_mode_name} (MODESW.INT), 32-bit encodings
1012

1113
Mnemonic::
12-
`modesw`
14+
`modesw.cap` +
15+
`modesw.int`
1316

1417
Encoding::
1518
include::wavedrom/modesw_32bit.adoc[]
1619

17-
include::modesw_common.adoc[]
20+
Description::
21+
Set the hart's current CHERI execution mode in <<pcc>>.
22+
+
23+
* MODESW.CAP: If the current mode in <<pcc>> is {cheri_int_mode_name} ({INT_MODE_VALUE}), then the <<m_bit>> in <<pcc>> is set to {cheri_cap_mode_name} ({CAP_MODE_VALUE}). Otherwise no effect.
24+
* MODESW.INT: If the current mode in <<pcc>> is {cheri_cap_mode_name} ({CAP_MODE_VALUE}), then the <<m_bit>> in <<pcc>> is set to {cheri_int_mode_name} ({INT_MODE_VALUE}). Otherwise no effect.
25+
26+
NOTE: Implementations may optionally support executing <<MODESW_CAP>> and <<MODESW_INT>> from the
27+
program buffer while in debug mode. If supported them the <<m_bit>> in
28+
<<dinfc>> is set accordingly and used to control which mode to enter next time debug
29+
mode is entered. The CHERI execution mode is only controlled by the <<m_bit>>
30+
of <<dinfc>> in debug mode.
1831

1932
Exceptions::
2033
include::require_cre.adoc[]

src/insns/modesw_common.adoc

-17
This file was deleted.

src/insns/wavedrom/modesw_16bit.adoc

-13
This file was deleted.

src/insns/wavedrom/modesw_32bit.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
{bits: 3, name: 'funct3', attr: ['3', 'MSW=001'], type: 8},
88
{bits: 5, name: 'funct5', attr: ['5', 'MSW=00000'], type: 4},
99
{bits: 5, name: 'funct5', attr: ['5', 'MSW=00000'], type: 3},
10-
{bits: 7, name: 'funct7', attr: ['7', 'MSW=0001001'], type: 3},
10+
{bits: 7, name: 'funct7', attr: ['7', 'MSW.CAP=0001001', 'MSW.INT=0001010'], type: 3},
1111
]}
1212
....

src/insns/zcmt_cmjalt.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Encoding::
2525

2626
[NOTE]
2727

28-
For this encoding to decode as <<<CM.JALT>>, _index>=32_, otherwise it decodes as <<CM.JT>>.
28+
For this encoding to decode as <<CM.JALT>>, _index&#8805;32_, otherwise it decodes as <<CM.JT>>.
2929

3030
{cheri_cap_mode_name} Description::
3131
Redirect instruction fetch via the jump table defined by the indexing via `jvtc.address+ index*XLEN/8`, checking every byte of the jump table access against <<jvtc>> bounds (not against <<pcc>>) and requiring <<x_perm>>. Link to `cra`.

src/instructions.adoc

-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ include::insns/addi16sp_16bit.adoc[]
212212

213213
include::insns/addi4spn_16bit.adoc[]
214214

215-
include::insns/modesw_16bit.adoc[]
216-
217215
include::insns/jalr_16bit.adoc[]
218216

219217
include::insns/jr_16bit.adoc[]

src/riscv-hybrid-integration.adoc

+9-8
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ unprivileged *x* register.
151151

152152
==== Mode Change Instructions
153153

154-
A new CHERI execution mode switch (<<MODESW>>) instruction allows software
155-
to toggle the hart's current CHERI execution mode. If the current mode in the
156-
<<pcc>> is {cheri_int_mode_name}, then the mode after executing <<MODESW>> is {cheri_cap_mode_name}
157-
and vice-versa. This instruction effectively writes the CHERI execution mode
158-
bit M of the capability currently installed in the <<pcc>>.
154+
New CHERI execution mode switch instructions, <<MODESW_CAP>> and
155+
<<MODESW_INT>>, allow software
156+
to change the hart's current <<m_bit>> in <<pcc>>. If the current mode in the
157+
<<pcc>> is {cheri_int_mode_name}, then the mode after executing <<MODESW_CAP>> is {cheri_cap_mode_name}
158+
and similarly for <<MODESW_INT>> when in {cheri_cap_mode_name}. This instruction effectively writes the CHERI execution mode
159+
<<m_bit>> of the capability currently installed in the <<pcc>>.
159160

160161
=== Existing RISC-V Instructions
161162

@@ -277,17 +278,17 @@ All CSR instructions cause CHERI exceptions if the <<pcc>> does not grant
277278
A new debug default data capability (<<dddc>>) CSR is added at the CSR number
278279
shown in xref:default-csrnames-added[xrefstyle=short].
279280

280-
{cheri_default_ext_name} optionally allows <<MODESW>> to execute in debug mode.
281+
{cheri_default_ext_name} optionally allows <<MODESW_CAP>> and <<MODESW_INT>> to execute in debug mode.
281282

282283
When entering debug mode, whether the core enters {cheri_int_mode_name} or
283284
{cheri_cap_mode_name} is controlled by the <<m_bit>> in <<dinfc>>.
284285
Implementations may optionally support switching CHERI execution mode by
285-
executing <<MODESW>> from the program buffer.
286+
executing <<MODESW_CAP>> or <<MODESW_INT>> from the program buffer.
286287

287288
The current mode can be read from <<dinfc>>.
288289

289290
ifdef::cheri_v9_annotations[]
290-
NOTE: *CHERI v9 Note:* The mode change instruction <<MODESW>> is new
291+
NOTE: *CHERI v9 Note:* The mode change instructions <<MODESW_CAP>> and <<MODESW_INT>> are new
291292
and the requirement to optionally support it in debug mode is also new.
292293
endif::[]
293294

src/summary.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Instruction fetch is also authorised by a capability: the program counter capabi
5555
This allows code fetch to be bounded, preventing a wide range of attacks that subvert control flow with integer data.
5656
Where {cheri_default_ext_name} is supported, the <<pcc>> also contains the <<m_bit,mode bit>> indicating whether the processor is running in integer or capability pointer mode.
5757
Changing the bounds used for instruction fetch or the pointer mode can be as easy as performing a capability-based jump (<<JALR>> in capability pointer mode).
58-
A <<MODESW>> instruction and compressed version is also added to allow cheap mode switching.
58+
<<MODESW_CAP>> and <<MODESW_INT>> instructions are also added to allow cheap mode switching.
5959

6060
Exception codes are added for CHERI-specific exceptions on fetch, jumps, and memory access.
6161
No other exception paths are added: in particular, capability manipulations do not trap, but may clear the tag on the result capability if the operation is not permitted.

src/tables.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ include::generated/legacy_mnemonic_insns_table_body.adoc[]
171171
include::generated/xlen_dependent_encoding_insns_table_body.adoc[]
172172
|==============================================================================
173173

174-
NOTE: <<MODESW>> and <<SCMODE>> only exist in {cheri_cap_mode_name} if
174+
NOTE: <<MODESW_CAP>>, <<MODESW_INT>> and <<SCMODE>> only exist in {cheri_cap_mode_name} if
175175
{cheri_int_mode_name} is _also_ present. A hart does not support the <<m_bit>>
176176
if it does not implement the {cheri_default_ext_name} extension.
177177

0 commit comments

Comments
 (0)