<!-- SPDX-License-Identifier: BSD-2-Clause OR CC-BY-4.0 -->

<!--
This file is dual-licensed. You may choose to use this file under the terms of
either of the above licenses.

Note: This dual licensing does not apply to other files that may be part of the
same project unless stated otherwise.
-->

<registers name="Virtual Core Debug Registers" prefix="VIRT_" label="virtual">
    A virtual register is one that doesn't exist directly in the hardware, but
    that the debugger exposes as if it does. Debug software should implement
    them, but hardware can skip this section. Virtual registers exist to give
    users access to functionality that's not part of standard debuggers without
    requiring them to carefully modify debug registers while the debugger is
    also accessing those same registers.

     <register name="Privilege Mode" short="priv" address="virtual">
        Users can read this register to inspect the privilege mode that
        the hart was running in when the hart halted.
        Users can write this register to change the privilege mode that
        the hart will run in when it resumes.

        This register contains {dcsr-prv} and {dcsr-v} from {csr-dcsr}, but in a place that the user
        is expected to access. The user should not access {csr-dcsr} directly,
        because doing so might interfere with the debugger.

        [[tab:privmode]]
        .Privilege Mode and Virtualization Mode Encoding
        [%autowidth,align="center",float="center",cols="^,^,^,&lt;,&lt;",options="header"]
        |===
        | H extension supported |v |prv |Abbreviation |Name
        | No | 0 | 0 | U-mode | User mode
        | No | 0 | 1 | S-mode | Supervisor mode
        | No | 0 | 3 | M-mode | Machine mode
        | Yes | 0 | 0 | U-mode | User mode
        | Yes | 0 | 1 | HS-mode | Hypervisor-enabled supervisor mode
        | Yes | 0 | 3 | M-mode | Machine mode
        | Yes | 1 | 0 | VU-mode | Virtual user mode
        | Yes | 1 | 1 | VS-mode | Virtual supervisor mode
        |===

        <field name="v" bits="2" access="WARL" reset="0">
          Contains the virtualization mode the hart was operating in when Debug
          Mode was entered. The encoding is described in &lt;&lt;tab:privmode&gt;&gt;,
          and matches the virtualization mode encoding from the Privileged Spec.
          A user can write this value to change the hart's virtualization mode
          when exiting Debug Mode.
        </field>
        <field name="prv" bits="1:0" access="R/W" reset="0">
            Contains the privilege mode the hart was operating in when Debug
            Mode was entered. The encoding is described in &lt;&lt;tab:privmode&gt;&gt;, and matches the privilege mode encoding from
            the Privileged Spec. A user can write this
            value to change the hart's privilege mode when exiting Debug Mode.
        </field>
    </register>
</registers>
