Skip to content

Commit 5a1ab83

Browse files
bors[bot]Disasm
andcommitted
Merge #28
28: Add marchid, mhartid and mimpid registers r=laanwj a=Disasm Co-authored-by: Vadim Kaushan <[email protected]>
2 parents 1e51464 + 2965734 commit 5a1ab83

10 files changed

+65
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "riscv"
3-
version = "0.5.2"
3+
version = "0.5.3"
44
repository = "https://github.com/rust-embedded/riscv"
55
authors = ["The RISC-V Team <[email protected]>"]
66
categories = ["embedded", "hardware-support", "no-std"]

asm.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ REG_READ_WRITE(mstatus, 0x300)
4040
REG_SET_CLEAR(mstatus, 0x300)
4141
REG_READ_WRITE(mtvec, 0x305)
4242
REG_READ(mvendorid, 0xF11)
43+
REG_READ(marchid, 0xF12)
44+
REG_READ(mimpid, 0xF13)
45+
REG_READ(mhartid, 0xF14)
4346

4447
// S-mode registers
4548
REG_READ_WRITE(satp, 0x180)

bin/riscv32imac-unknown-none-elf.a

624 Bytes
Binary file not shown.

bin/riscv32imc-unknown-none-elf.a

624 Bytes
Binary file not shown.

bin/riscv64gc-unknown-none-elf.a

664 Bytes
Binary file not shown.

bin/riscv64imac-unknown-none-elf.a

664 Bytes
Binary file not shown.

src/register/marchid.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! marchid register
2+
3+
use core::num::NonZeroUsize;
4+
5+
/// marchid register
6+
#[derive(Clone, Copy, Debug)]
7+
pub struct Marchid {
8+
bits: NonZeroUsize,
9+
}
10+
11+
impl Marchid {
12+
/// Returns the contents of the register as raw bits
13+
pub fn bits(&self) -> usize {
14+
self.bits.get()
15+
}
16+
}
17+
18+
read_csr!(0xF11, __read_marchid);
19+
20+
/// Reads the CSR
21+
#[inline]
22+
pub fn read() -> Option<Marchid> {
23+
let r = unsafe{ _read() };
24+
// When marchid is hardwired to zero it means that the marchid
25+
// csr isn't implemented.
26+
NonZeroUsize::new(r).map(|bits| Marchid { bits })
27+
}

src/register/mhartid.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! mhartid register
2+
3+
read_csr_as_usize!(0xf14, __read_mhartid);

src/register/mimpid.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! mimpid register
2+
3+
use core::num::NonZeroUsize;
4+
5+
/// mimpid register
6+
#[derive(Clone, Copy, Debug)]
7+
pub struct Mimpid {
8+
bits: NonZeroUsize,
9+
}
10+
11+
impl Mimpid {
12+
/// Returns the contents of the register as raw bits
13+
pub fn bits(&self) -> usize {
14+
self.bits.get()
15+
}
16+
}
17+
18+
read_csr!(0xF11, __read_mimpid);
19+
20+
/// Reads the CSR
21+
#[inline]
22+
pub fn read() -> Option<Mimpid> {
23+
let r = unsafe{ _read() };
24+
// When mimpid is hardwired to zero it means that the mimpid
25+
// csr isn't implemented.
26+
NonZeroUsize::new(r).map(|bits| Mimpid { bits })
27+
}

src/register/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ mod macros;
1515

1616
pub mod fcsr;
1717

18+
pub mod marchid;
1819
pub mod mcause;
1920
pub mod mcycle;
2021
pub mod mcycleh;
2122
pub mod mepc;
23+
pub mod mhartid;
2224
pub mod mie;
23-
pub mod mip;
25+
pub mod mimpid;
2426
pub mod minstret;
2527
pub mod minstreth;
28+
pub mod mip;
2629
pub mod misa;
2730
pub mod mstatus;
2831
pub mod mtvec;

0 commit comments

Comments
 (0)