Add marchid, mhartid and mimpid registers

This commit is contained in:
Vadim Kaushan 2019-04-29 10:43:51 +02:00
parent 1e514648fd
commit cf9008492a
No known key found for this signature in database
GPG Key ID: A501C5DF67C05C4E
5 changed files with 64 additions and 1 deletions

3
asm.S
View File

@ -40,6 +40,9 @@ REG_READ_WRITE(mstatus, 0x300)
REG_SET_CLEAR(mstatus, 0x300)
REG_READ_WRITE(mtvec, 0x305)
REG_READ(mvendorid, 0xF11)
REG_READ(marchid, 0xF12)
REG_READ(mimpid, 0xF13)
REG_READ(mhartid, 0xF14)
// S-mode registers
REG_READ_WRITE(satp, 0x180)

27
src/register/marchid.rs Normal file
View File

@ -0,0 +1,27 @@
//! marchid register
use core::num::NonZeroUsize;
/// marchid register
#[derive(Clone, Copy, Debug)]
pub struct Marchid {
bits: NonZeroUsize,
}
impl Marchid {
/// Returns the contents of the register as raw bits
pub fn bits(&self) -> usize {
self.bits.get()
}
}
read_csr!(0xF11, __read_marchid);
/// Reads the CSR
#[inline]
pub fn read() -> Option<Marchid> {
let r = unsafe{ _read() };
// When marchid is hardwired to zero it means that the marchid
// csr isn't implemented.
NonZeroUsize::new(r).map(|bits| Marchid { bits })
}

3
src/register/mhartid.rs Normal file
View File

@ -0,0 +1,3 @@
//! mhartid register
read_csr_as_usize!(0xf14, __read_mhartid);

27
src/register/mimpid.rs Normal file
View File

@ -0,0 +1,27 @@
//! mimpid register
use core::num::NonZeroUsize;
/// mimpid register
#[derive(Clone, Copy, Debug)]
pub struct Mimpid {
bits: NonZeroUsize,
}
impl Mimpid {
/// Returns the contents of the register as raw bits
pub fn bits(&self) -> usize {
self.bits.get()
}
}
read_csr!(0xF11, __read_mimpid);
/// Reads the CSR
#[inline]
pub fn read() -> Option<Mimpid> {
let r = unsafe{ _read() };
// When mimpid is hardwired to zero it means that the mimpid
// csr isn't implemented.
NonZeroUsize::new(r).map(|bits| Mimpid { bits })
}

View File

@ -15,14 +15,17 @@ mod macros;
pub mod fcsr;
pub mod marchid;
pub mod mcause;
pub mod mcycle;
pub mod mcycleh;
pub mod mepc;
pub mod mhartid;
pub mod mie;
pub mod mip;
pub mod mimpid;
pub mod minstret;
pub mod minstreth;
pub mod mip;
pub mod misa;
pub mod mstatus;
pub mod mtvec;