Skip to content

Commit 19b191b

Browse files
authored
Merge pull request riscv#1652 from riscv/dev/beeman/v7_0
first version of Smtdeleg/Sstcfg additions
2 parents 7023c60 + aafa66b commit 19b191b

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

src/priv-csrs.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ Supervisor count overflow.
288288

289289
|`0x5A8` |SRW |`scontext` |Supervisor-mode context register.
290290

291+
|`XXX` |SRW |`stselect` |Supervisor Trigger Select register.
292+
291293
//4+^|Supervisor Resource Management Configuration
292294
//|`0x181` |SRW |`srmcfg` |Supervisor Resource Management Configuration.
293295

src/smtdeleg.adoc

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
[[intro]]
2+
== Introduction
3+
4+
Sdtrig triggers allow both self-hosted and external debuggers to debug target software by transferring control to the debugger at points of interest. However, Sdtrig CSRs are accessible only with M-mode privilege. As a result, a debugger must have M-mode privilege, or be able to invoke M-mode, in order to access them.
5+
6+
For a self-hosted debugger with less than M-mode privilege, this requires an SBI (Supervisor Binary Interface). This results in traps on all trigger accesses, which can add latency to critical context switch flows.
7+
8+
For an external debugger, if Sdsec is implemented and the hart is configured such that Debug Mode has less than M-mode privilege, the debugger is unable to access triggers. There is no SBI that can be called from Debug Mode.
9+
10+
The Smtdeleg extension provides a means for Sdtrig triggers to be accessed from S-mode and VS-mode, using the indirect CSR interface (Sscsrind). It also defines a means to control S-mode and VS-mode access to triggers using the State Enable extensions (Smstateen/Ssstateen). Sstcfg comprises the supervisor components of Smtdeleg.
11+
12+
[[body]]
13+
== CSRs
14+
15+
=== Supervisor Trigger Select (`stselect`)
16+
17+
`stselect` provides read/write access to `tselect` from S-mode and VS-mode.
18+
19+
== Supervisor and Virtual Supervisor Trigger Access
20+
21+
While `siselect` holds XXX, the `sireg*` registers provide supervisor read/write access to register state associated with the trigger selected in `tselect`, the same state accessed by M-mode CSRs `tdata*` and `tinfo`. The register mapping is shown below.
22+
23+
.Indirect Trigger Register Mappings When `siselect` = XXX
24+
[width="70%",options="header"]
25+
|===
26+
| Indirect CSR | State Accessed
27+
| `sireg` | Same as `tdata1`
28+
| `sireg2` | Same as `tdata2`
29+
| `sireg3` | Same as `tdata3`
30+
| `sireg4` | Same as `tinfo`
31+
|===
32+
33+
[WARN]
34+
====
35+
_There was much discussion of the best way to access counters in S-mode. This method requires 1 new CSR (`stselect`), along with 1 `siselect` index._
36+
37+
_Also proposed was to simply allocate a range of `siselect` values that serve to select the trigger, bypassing `tselect` when accessing trigger state through `sireg*`. This adds no new CSRs, but artificially limits the number of triggers accessible in S-mode. `tselect` supports up to 2^MXLEN^ triggers, while `siselect` would likely allocate only enough values to cover practical implementations (256?)._
38+
39+
_Other approaches considered:_
40+
41+
* _Define new `stdata[123]` and `stinfo` registers, which provide S-mode access to `tdata[123]` and `tinfo`. Avoids dependence on Sscsrind altogether, but costs 4 more CSR addresses._
42+
43+
* _Access `tselect` via `sireg5` instead of through a new `stselect` CSR (access to `tdata*` and `tinfo` is the same as spec'd above). While saving a CSR, this approach would require `sireg5` to continue to access `tselect` while the other `sireg*` registers shift the state they acccess based on the `tselect` value. This approach seems more awkward for implementation._
44+
====
45+
46+
Similarly, when `vsiselect` holds XXX, the `vsireg*` registers provide access to trigger register state in the same manner as described above for `sireg*`.
47+
48+
=== Trigger State Access Modifications
49+
50+
`sireg*` and `vsireg*` provide access to a subset of the fields in the native trigger registers, and in some cases fields are relocated. The field modifications that apply when trigger registers are accessed via `sireg*` or `vsireg*` are documented below.
51+
52+
.Delegated Trigger CSR Field Modifications
53+
[options="header", cols="30%,30%,40%"]
54+
|===
55+
| Sdtrig Register(s) | `sireg*` Field Modifications | `vsireg*` Field Modifications
56+
| `mcontrol`, `mcontrol6`, `icount`, `etrigger`, `itrigger`
57+
58+
(accessed by `tdata1`) | M is read-only 0
59+
60+
VS and VU are read-only 0
61+
62+
| M is read-only 0
63+
64+
S accesses `tdata1`.VS
65+
66+
U accesses `tdata1`.VU
67+
68+
VS and VU are read-only 0
69+
| `textra32`, `textra64`
70+
71+
(accessed by `tdata3`) | none | MHVALUE and MHSELECT are read-only 0
72+
|===
73+
74+
[NOTE]
75+
====
76+
_The bit positions for the M, S, U, VS, and VU fields referenced above vary based on the trigger type, specified by `tdata1`.TYPE. See details in the RISC-V Debug Specification, Chapter 5.7._
77+
====
78+
79+
[NOTE]
80+
====
81+
_A hypervisor enabling trigger match in VS-mode or VU-mode must be done through `vsiselect`/`vsireg*`. This simplifies support for nested virtualization. A nested hypervisor (running in VS-mode) that wishes to configure triggers to match in a true guest will attempt to access `vsiselect`/`vsireg*`, which will naturally trap to HS-mode, thereby allowing the L0 hypervisor (running in HS-mode) to emulate the desired behavior._
82+
====
83+
84+
When `tdata1`.DMODE = 1 for the trigger with index _i_, the trigger is reserved for Debug Mode use. In that case, when `tselect` holds _i_ and the hart is not in Debug Mode, `sireg` and `sireg[234]` are read-only 0 while `siselect` holds XXX, and `vsireg` and `vsireg[234]` are read-only 0 while `vsiselect` holds XXX.
85+
86+
== Supervisor and Virtual Supervisor Trigger State Access Control
87+
88+
While the privilege mode is M or S and `siselect` holds XXX, illegal instruction exceptions are raised for attempts to access `sireg5` or `sireg6`. Similarly, while the privilege mode is M or S and `vsiselect` holds XXX, illegal instruction exceptions are raised for attempts to access `vsireg5`, or `vsireg6`.
89+
90+
While the privilege mode is VS and `vsiselect` holds XXX, virtual instruction exceptions are raised for attempts to access `sireg5` (really `vsireg5`) or `sireg6` (really `vsireg6`).
91+
92+
=== State Enable Access Control
93+
94+
When Smstateen is implemented, the `mstateen0`.TR bit controls access to Sdtrig register state from privilege modes less privileged than M-mode. When `mstateen0`.TR=1, accesses to Sdtrig register state behave as described in <<Supervisor and Virtual Supervisor Trigger Access>> above. When `mstateen0`.TR=0 and the privilege mode is less privileged than M-mode, attempts to access `stselect`, `sireg` or `sireg[234]` while `siselect` holds XXX, or `vsireg` or `vsireg[234]` while `vsiselect` holds XXX, raise an illegal-instruction exception.
95+
96+
If the H extension is implemented and `mstateen0`.TR=1, the `hstateen0`.TR bit controls access to Sdtrig state when V=1. `hstateen0`.TR is read-only 0 when `mstateen0`.TR=0.
97+
98+
When `mstateen0`.TR=1 and `hstateen0`.TR=1, VS-mode accesses to supervisor TR state behave as described in <<Supervisor and Virtual Supervisor Trigger Access>> above. When `mstateen0`.TR=1 and `hstateen0`.TR=0, attempts from VS-mode to access `stselect`, or `sireg` (really `vsireg`) or `sireg[234]` (really `vsireg[234]`) while `vsiselect` holds XXX, raise a virtual-instruction exception.
99+
100+
The TR bit is bit YYY in `mstateen0` and `hstateen0`.
101+
102+
[NOTE]
103+
[%unbreakable]
104+
====
105+
_See the Sscsrind spec for how bit 60 in mstateen0 and hstateen0 can also restrict access to `sireg*`/`siselect` and `vsireg*`/`vsiselect` from privilege modes less privileged than M-mode._
106+
====
107+
108+
[WARN]
109+
====
110+
_Utilizing Smstateen to control access to trigger state in S-mode and VS-mode results in an "all or none" delegation mechanism. It is believed that this is sufficient, that software is not accustomed to exposing only select triggers to less privileged modes on other architectures._
111+
112+
_If, in the future, there is a reason to support selective delegation, new `tdelegX` and `htdelegX` registers could be defined, such that each bit enables delegation of the associated trigger. However, this would artificially limit the number of triggers that could be delegated._
113+
====
114+
115+
116+
117+

0 commit comments

Comments
 (0)