Skip to content

Commit 2450868

Browse files
bors[bot]Disasm
andcommitted
Merge #21
21: Add 64-bit targets, reads for composite CSRs, bump version r=dvc94ch a=Disasm Co-authored-by: Vadim Kaushan <[email protected]>
2 parents 70bdf2f + a091d23 commit 2450868

File tree

11 files changed

+61
-20
lines changed

11 files changed

+61
-20
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ matrix:
2424
rust: nightly
2525
if: (branch = staging OR branch = trying OR branch = master) OR (type = pull_request AND branch = master)
2626

27+
- env: TARGET=riscv64imac-unknown-none-elf
28+
rust: nightly
29+
if: (branch = staging OR branch = trying OR branch = master) OR (type = pull_request AND branch = master)
30+
31+
- env: TARGET=riscv64gc-unknown-none-elf
32+
rust: nightly
33+
if: (branch = staging OR branch = trying OR branch = master) OR (type = pull_request AND branch = master)
34+
2735
- env: TARGET=x86_64-unknown-linux-gnu
2836
rust: stable
2937
if: (branch = staging OR branch = trying OR branch = master) OR (type = pull_request AND branch = master)

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.4.0"
3+
version = "0.5.0"
44
repository = "https://github.com/rust-embedded/riscv"
55
authors = ["The RISC-V Team <[email protected]>"]
66
categories = ["embedded", "hardware-support", "no-std"]

assemble.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ rm -f bin/*.a
1010
riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32imac asm.S -o bin/$crate.o
1111
riscv64-unknown-elf-gcc -c -mabi=ilp32 -march=rv32imac asm32.S -o bin/$crate-32.o
1212
ar crs bin/riscv32imac-unknown-none-elf.a bin/$crate.o bin/$crate-32.o
13-
cp bin/riscv32imac-unknown-none-elf.a bin/riscv32imc-unknown-none-elf.a
13+
ar crs bin/riscv32imc-unknown-none-elf.a bin/$crate.o bin/$crate-32.o
14+
15+
riscv64-unknown-elf-gcc -c -mabi=lp64 -march=rv64imac asm.S -o bin/$crate.o
16+
ar crs bin/riscv64imac-unknown-none-elf.a bin/$crate.o
17+
ar crs bin/riscv64gc-unknown-none-elf.a bin/$crate.o
1418

1519
rm bin/$crate.o
1620
rm bin/$crate-32.o

bin/riscv64gc-unknown-none-elf.a

6.82 KB
Binary file not shown.

bin/riscv64imac-unknown-none-elf.a

6.82 KB
Binary file not shown.

src/register/macros.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,25 @@ macro_rules! set_clear_csr {
208208
clear_csr!($(#[$attr])*, $clear_field, $e);
209209
}
210210
}
211+
212+
macro_rules! read_composite_csr {
213+
($hi:expr, $lo:expr) => {
214+
/// Reads the CSR as a 64-bit value
215+
#[inline]
216+
pub fn read64() -> u64 {
217+
match () {
218+
#[cfg(riscv32)]
219+
() => loop {
220+
let hi = $hi;
221+
let lo = $lo;
222+
if hi == $hi {
223+
return ((hi as u64) << 32) | lo as u64;
224+
}
225+
},
226+
227+
#[cfg(not(riscv32))]
228+
() => $lo as u64,
229+
}
230+
}
231+
}
232+
}

src/register/mcycle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//! mcycle register
22
33
read_csr_as_usize!(0xB00, __read_mcycle);
4+
read_composite_csr!(super::mcycleh::read(), read());

src/register/mie.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! mie register
22
3+
use bit_field::BitField;
4+
35
/// mie register
46
#[derive(Clone, Copy, Debug)]
57
pub struct Mie {
@@ -16,55 +18,55 @@ impl Mie {
1618
/// User Software Interrupt Enable
1719
#[inline]
1820
pub fn usoft(&self) -> bool {
19-
self.bits & (1 << 0) == 1 << 0
21+
self.bits.get_bit(0)
2022
}
2123

2224
/// Supervisor Software Interrupt Enable
2325
#[inline]
2426
pub fn ssoft(&self) -> bool {
25-
self.bits & (1 << 1) == 1 << 1
27+
self.bits.get_bit(1)
2628
}
2729

2830
/// Machine Software Interrupt Enable
2931
#[inline]
3032
pub fn msoft(&self) -> bool {
31-
self.bits & (1 << 3) == 1 << 3
33+
self.bits.get_bit(3)
3234
}
3335

3436
/// User Timer Interrupt Enable
3537
#[inline]
3638
pub fn utimer(&self) -> bool {
37-
self.bits & (1 << 4) == 1 << 4
39+
self.bits.get_bit(4)
3840
}
3941

4042
/// Supervisor Timer Interrupt Enable
4143
#[inline]
4244
pub fn stimer(&self) -> bool {
43-
self.bits & (1 << 5) == 1 << 5
45+
self.bits.get_bit(5)
4446
}
4547

4648
/// Machine Timer Interrupt Enable
4749
#[inline]
4850
pub fn mtimer(&self) -> bool {
49-
self.bits & (1 << 7) == 1 << 7
51+
self.bits.get_bit(7)
5052
}
5153

5254
/// User External Interrupt Enable
5355
#[inline]
5456
pub fn uext(&self) -> bool {
55-
self.bits & (1 << 8) == 1 << 8
57+
self.bits.get_bit(8)
5658
}
5759

5860
/// Supervisor External Interrupt Enable
5961
#[inline]
6062
pub fn sext(&self) -> bool {
61-
self.bits & (1 << 9) == 1 << 9
63+
self.bits.get_bit(9)
6264
}
6365

6466
/// Machine External Interrupt Enable
6567
#[inline]
6668
pub fn mext(&self) -> bool {
67-
self.bits & (1 << 11) == 1 << 11
69+
self.bits.get_bit(11)
6870
}
6971
}
7072

src/register/minstret.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//! minstret register
22
33
read_csr_as_usize!(0xB02, __read_minstret);
4+
read_composite_csr!(super::minstreth::read(), read());

src/register/mip.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! mip register
22
3+
use bit_field::BitField;
4+
35
/// mip register
46
#[derive(Clone, Copy, Debug)]
57
pub struct Mip {
@@ -16,55 +18,55 @@ impl Mip {
1618
/// User Software Interrupt Pending
1719
#[inline]
1820
pub fn usoft(&self) -> bool {
19-
self.bits & (1 << 0) == 1 << 0
21+
self.bits.get_bit(0)
2022
}
2123

2224
/// Supervisor Software Interrupt Pending
2325
#[inline]
2426
pub fn ssoft(&self) -> bool {
25-
self.bits & (1 << 1) == 1 << 1
27+
self.bits.get_bit(1)
2628
}
2729

2830
/// Machine Software Interrupt Pending
2931
#[inline]
3032
pub fn msoft(&self) -> bool {
31-
self.bits & (1 << 3) == 1 << 3
33+
self.bits.get_bit(3)
3234
}
3335

3436
/// User Timer Interrupt Pending
3537
#[inline]
3638
pub fn utimer(&self) -> bool {
37-
self.bits & (1 << 4) == 1 << 4
39+
self.bits.get_bit(4)
3840
}
3941

4042
/// Supervisor Timer Interrupt Pending
4143
#[inline]
4244
pub fn stimer(&self) -> bool {
43-
self.bits & (1 << 5) == 1 << 5
45+
self.bits.get_bit(5)
4446
}
4547

4648
/// Machine Timer Interrupt Pending
4749
#[inline]
4850
pub fn mtimer(&self) -> bool {
49-
self.bits & (1 << 7) == 1 << 7
51+
self.bits.get_bit(7)
5052
}
5153

5254
/// User External Interrupt Pending
5355
#[inline]
5456
pub fn uext(&self) -> bool {
55-
self.bits & (1 << 8) == 1 << 8
57+
self.bits.get_bit(8)
5658
}
5759

5860
/// Supervisor External Interrupt Pending
5961
#[inline]
6062
pub fn sext(&self) -> bool {
61-
self.bits & (1 << 9) == 1 << 9
63+
self.bits.get_bit(9)
6264
}
6365

6466
/// Machine External Interrupt Pending
6567
#[inline]
6668
pub fn mext(&self) -> bool {
67-
self.bits & (1 << 11) == 1 << 11
69+
self.bits.get_bit(11)
6870
}
6971
}
7072

0 commit comments

Comments
 (0)