CSR address for debug scontext and hcontext
You may be aware that the RISC-V Debug Specification 0.13 defines two CSRs, mcontext and scontext, that can be used to qualify hardware breakpoints in a particular OS process or thread. A modified S-mode OS kernel writes the process ID to scontext when switching processes. Breakpoint hardware can be set to trigger only when the process ID in scontext matches the desired process.
Using ASID instead of scontext to qualify breakpoints has been suggested. However, many systems do not implement ASID or only implement a narrow field, forcing the OS to recycle ASID values. This makes ASID useless for breakpoint qualification.
For those familiar with ARM, the equivalent registers in that architecture are CONTEXTIDR_EL1 and CONTEXTIDR_EL2.
Scontext is defined in the ratified Debug Spec at CSR 0x7aa which is in the "Machine Standard read/write debug CSR" region and so is, by convention, inaccessible from S-mode.
The Debug Spec was ratified before work on the hypervisor had gotten very far, so Debug Spec 0.13 does not provide full support for hypervisor-based systems. Among the missing items is a definition for an "hcontext" register to qualify breakpoints in a particular virtual machine. An argument could be made to use VMID for this, but the discussion above about ASID qualification would also apply to VMID.
The Debug Task Group would like to suggest allocating a range of CSR addresses in one of the Supervisor Standard read/write regions and in one of the Hypervisor Standard read/write regions to use for debug registers. Our suggestion is 0x5A0-0x5AF for S-mode and 0x6A0-0x6AF for HS-mode, complementing the 0x7A0-0x7AF already defined for M-mode debug registers. Allocating more than just one address gives the Debug TG flexibility for the future.
RISC-V Debug Task Group