# hstatus.rs - source
Source of the Rust file `/home/runner/.cargo/git/checkouts/riscv-ab2abd16c438337b/11d43cf/src/register/hypervisorx64/hstatus.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160

    //! HStatus Register.

    use bit_field::BitField;

    #[derive(Copy, Clone, Debug)]
    pub struct Hstatus {
        bits: usize,
    }
    impl Hstatus {
        #[inline]
        pub fn bits(&self) -> usize {
            return self.bits;
        }
        #[inline]
        pub fn from_bits(x: usize) -> Self {
            return Hstatus { bits: x };
        }
        #[inline]
        pub unsafe fn write(&self) {
            _write(self.bits);
        }
        /// Effective XLEN for VM.
        #[inline]
        pub fn vsxl(&self) -> VsxlValues {
            VsxlValues::from(self.bits.get_bits(32..34))
        }
        #[inline]
        pub fn set_vsxl(&mut self, val: VsxlValues) {
            self.bits.set_bits(32..34, val as usize);
        }
        /// TSR for VM.
        #[inline]
        pub fn vtsr(&self) -> bool {
            self.bits.get_bit(22)
        }
        #[inline]
        pub fn set_vtsr(&mut self, val: bool) {
            self.bits.set_bit(22, val);
        }
        /// TW for VM.
        #[inline]
        pub fn vtw(&self) -> bool {
            self.bits.get_bit(21)
        }
        #[inline]
        pub fn set_vtw(&mut self, val: bool) {
            self.bits.set_bit(21, val);
        }
        /// TVM for VM.
        #[inline]
        pub fn vtvm(&self) -> bool {
            self.bits.get_bit(20)
        }
        #[inline]
        pub fn set_vtvm(&mut self, val: bool) {
            self.bits.set_bit(20, val);
        }
        /// Virtual Guest External Interrupt Number.
        #[inline]
        pub fn vgein(&self) -> usize {
            self.bits.get_bits(12..18)
        }
        #[inline]
        pub fn set_vgein(&mut self, val: usize) {
            self.bits.set_bits(12..18, val);
        }
        /// Hypervisor User mode.
        #[inline]
        pub fn hu(&self) -> bool {
            self.bits.get_bit(9)
        }
        #[inline]
        pub fn set_hu(&mut self, val: bool) {
            self.bits.set_bit(9, val);
        }
        /// Supervisor Previous Virtual Privilege.
        #[inline]
        pub fn spvp(&self) -> bool {
            self.bits.get_bit(8)
        }
        #[inline]
        pub fn set_spvp(&mut self, val: bool) {
            self.bits.set_bit(8, val);
        }
        /// Supervisor Previous Virtualization mode.
        #[inline]
        pub fn spv(&self) -> bool {
            self.bits.get_bit(7)
        }
        #[inline]
        pub fn set_spv(&mut self, val: bool) {
            self.bits.set_bit(7, val);
        }
        /// Guest Virtual Address.
        #[inline]
        pub fn gva(&self) -> bool {
            self.bits.get_bit(6)
        }
        #[inline]
        pub fn set_gva(&mut self, val: bool) {
            self.bits.set_bit(6, val);
        }
        /// VS access endianness.
        #[inline]
        pub fn vsbe(&self) -> bool {
            self.bits.get_bit(5)
        }
        #[inline]
        pub fn set_vsbe(&mut self, val: bool) {
            self.bits.set_bit(5, val);
        }
    }
    read_csr_as!(Hstatus, 1536, __read_hstatus);
    write_csr!(1536, __write_hstatus);
    set!(1536, __set_hstatus);
    clear!(1536, __clear_hstatus);
    // bit ops
    set_clear_csr!(
        ///TSR for VM.
        , set_vtsr, clear_vtsr, 1 << 22);
    set_clear_csr!(
        ///TW for VM.
        , set_vtw, clear_vtw, 1 << 21);
    set_clear_csr!(
        ///TVM for VM.
        , set_vtvm, clear_vtvm, 1 << 20);
    set_clear_csr!(
        ///Hypervisor User mode.
        , set_hu, clear_hu, 1 << 9);
    set_clear_csr!(
        ///Supervisor Previous Virtual Privilege.
        , set_spvp, clear_spvp, 1 << 8);
    set_clear_csr!(
        ///Supervisor Previous Virtualization mode.
        , set_spv, clear_spv, 1 << 7);
    set_clear_csr!(
        ///Guest Virtual Address.
        , set_gva, clear_gva, 1 << 6);
    set_clear_csr!(
        ///VS access endianness.
        , set_vsbe, clear_vsbe, 1 << 5);

    // enums
    #[derive(Copy, Clone, Debug)]
    #[repr(usize)]
    pub enum VsxlValues {
        Vsxl32 = 1,
        Vsxl64 = 2,
        Vsxl128 = 3,
    }
    impl VsxlValues {
        fn from(x: usize) -> Self {
            match x {
                1 => Self::Vsxl32,
                2 => Self::Vsxl64,
                3 => Self::Vsxl128,
                _ => unreachable!(),
            }
        }
    }