Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit e627b30

Browse files
committed
Switch from register-rs to tock-registers
1 parent 715ea1f commit e627b30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+698
-223
lines changed

.vscode/settings.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"editor.rulers": [
44
100
55
],
6-
"rust-analyzer.checkOnSave.extraArgs": [
7-
"--target=aarch64-unknown-none-softfloat"
8-
],
9-
"rust-analyzer.checkOnSave.allTargets": false
6+
"rust-analyzer.cargo.target": "aarch64-unknown-none-softfloat",
7+
"rust-analyzer.lens.debug": false,
8+
"rust-analyzer.lens.run": false
109
}

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ categories = ["embedded", "hardware-support", "no-std"]
1111
license = "MIT/Apache-2.0"
1212
edition = "2018"
1313
exclude = [
14+
".github",
15+
".gitignore",
16+
".rustfmt.toml",
17+
".vscode",
1418
"Makefile"
1519
]
1620

1721
[dependencies]
18-
register = "1.x.x"
22+
tock-registers = { version = "0.7.x", default-features = false } # Use it as interface-only library.

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ clippy:
88
cargo clippy --target $(TARGET)
99
cargo clippy
1010

11-
check:
12-
cargo check --target $(TARGET)
13-
cargo check
14-
1511
fmt:
1612
cargo fmt
1713

README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,53 @@
55

66
Low level access to Cortex-A processors.
77

8-
## Currently Supported Architectures
8+
## Currently Supported Execution States
99

1010
- [x] AArch64
1111
- [ ] AArch32
1212

1313
## Minimum Supported Rust Version
1414

15-
Requires rustc 1.45.0 or later due to use of the new `asm!()` syntax.
15+
Requires a recent nightly of Rust.
1616

1717
## Usage
1818

19-
Example from https://github.com/rust-embedded/rust-raspi3-OS-tutorials
19+
Please note that for using this crate's [register definitions](src/regs) (as provided by
20+
`cortex_a::regs::*`), you need to also include
21+
[`tock-registers`](https://crates.io/crates/tock-registers) in your project. This is because the
22+
`interface` traits provided by `tock-registers` are implemented by this crate. You should include
23+
the same version of `tock-registers` as is being used by this crate to ensure sane
24+
interoperatbility.
25+
26+
For example, in the following snippet, `X.Y.Z` should be the same version of `tock-registers` that
27+
is mentioned in `cortex-a`'s [`Cargo.toml`](Cargo.toml).
28+
29+
```toml
30+
[package]
31+
name = "Your embedded project"
32+
33+
# Some parts omitted for brevity.
34+
35+
[dependencies]
36+
tock-registers = "X.Y.Z"
37+
cortex-a = "A.B.C" # <-- Includes tock-registers itself.
38+
```
39+
40+
### Example
41+
42+
Check out https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials for usage examples. Listed
43+
below is a snippet of `rust-raspberrypi-OS-tutorials`'s early boot code.
2044

2145
```rust
22-
unsafe fn el2_to_el1_transition() -> ! {
46+
use cortex_a::{asm, regs::*};
47+
use tock_registers::interfaces::Writeable; // <-- Trait needed to use `write()` and `set()`.
48+
49+
// Some parts omitted for brevity.
50+
51+
unsafe fn prepare_el2_to_el1_transition(
52+
virt_boot_core_stack_end_exclusive_addr: u64,
53+
virt_kernel_init_addr: u64,
54+
) {
2355
// Enable timer counter registers for EL1.
2456
CNTHCTL_EL2.write(CNTHCTL_EL2::EL1PCEN::SET + CNTHCTL_EL2::EL1PCTEN::SET);
2557

src/lib.rs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,53 @@
77

88
//! Low level access to Cortex-A processors.
99
//!
10-
//! ## Currently Supported Architectures
10+
//! ## Currently Supported Execution States
1111
//!
1212
//! - [x] AArch64
1313
//! - [ ] AArch32
1414
//!
15+
//! ## Minimum Supported Rust Version
16+
//!
17+
//! Requires a recent nightly of Rust.
18+
//!
1519
//! ## Usage
1620
//!
17-
//! Example from https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials
21+
//! Please note that for using this crate's [register definitions](src/regs) (as provided by
22+
//! `cortex_a::regs::*`), you need to also include
23+
//! [`tock-registers`](https://crates.io/crates/tock-registers) in your project. This is because the
24+
//! `interface` traits provided by `tock-registers` are implemented by this crate. You should
25+
//! include the same version of `tock-registers` as is being used by this crate to ensure sane
26+
//! interoperatbility.
27+
//!
28+
//! For example, in the following snippet, `X.Y.Z` should be the same version of `tock-registers`
29+
//! that is mentioned in `cortex-a`'s [`Cargo.toml`](Cargo.toml).
30+
//!
31+
//! ```toml
32+
//! [package]
33+
//! name = "Your embedded project"
34+
//!
35+
//! # Some parts omitted for brevity.
36+
//!
37+
//! [dependencies]
38+
//! tock-registers = "X.Y.Z"
39+
//! cortex-a = "A.B.C" # <-- Includes tock-registers itself.
40+
//! ```
41+
//!
42+
//! ### Example
43+
//!
44+
//! Check out https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials for usage examples.
45+
//! Listed below is a snippet of `rust-raspberrypi-OS-tutorials`'s early boot code.
1846
//!
1947
//! ```rust
20-
//! unsafe fn el2_to_el1_transition() -> ! {
48+
//! use cortex_a::{asm, regs::*};
49+
//! use tock_registers::interfaces::Writeable; // <-- Trait needed to use `write()` and `set()`.
50+
//!
51+
//! // Some parts omitted for brevity.
52+
//!
53+
//! unsafe fn prepare_el2_to_el1_transition(
54+
//! virt_boot_core_stack_end_exclusive_addr: u64,
55+
//! virt_kernel_init_addr: u64,
56+
//! ) {
2157
//! // Enable timer counter registers for EL1.
2258
//! CNTHCTL_EL2.write(CNTHCTL_EL2::EL1PCEN::SET + CNTHCTL_EL2::EL1PCTEN::SET);
2359
//!
@@ -39,13 +75,13 @@
3975
//!
4076
//! ## Disclaimer
4177
//!
42-
//! Descriptive comments in the source files are taken from the
43-
//! [ARM Architecture Reference Manual ARMv8, for ARMv8-A architecture profile](https://static.docs.arm.com/ddi0487/ca/DDI0487C_a_armv8_arm.pdf?_ga=2.266626254.1122218691.1534883460-1326731866.1530967873).
78+
//! Descriptive comments in the source files are taken from the [ARM Architecture Reference Manual
79+
//! ARMv8, for ARMv8-A architecture
80+
//! profile](https://static.docs.arm.com/ddi0487/ca/DDI0487C_a_armv8_arm.pdf?_ga=2.266626254.1122218691.1534883460-1326731866.1530967873).
4481
45-
#![allow(clippy::clippy::upper_case_acronyms)]
82+
#![feature(asm)]
4683
#![feature(core_intrinsics)]
4784
#![feature(custom_inner_attributes)]
48-
#![feature(asm)]
4985
#![no_std]
5086

5187
pub mod asm;

src/regs/cntfrq_el0.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
//! must be programmed with this value as part of system initialization. The value of the register
1212
//! is not interpreted by hardware.
1313
14-
use register::cpu::RegisterReadOnly;
14+
use tock_registers::interfaces::Readable;
1515

1616
pub struct Reg;
1717

18-
impl RegisterReadOnly<u64, ()> for Reg {
18+
impl Readable for Reg {
19+
type T = u64;
20+
type R = ();
21+
1922
sys_coproc_read_raw!(u64, "CNTFRQ_EL0", "x");
2023
}
2124

22-
pub static CNTFRQ_EL0: Reg = Reg {};
25+
pub const CNTFRQ_EL0: Reg = Reg {};

src/regs/cnthctl_el2.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
//! access from Non-secure EL1 to the physical counter and the Non-secure EL1
1212
//! physical timer.
1313
14-
use register::{cpu::RegisterReadWrite, register_bitfields};
14+
use tock_registers::{
15+
interfaces::{Readable, Writeable},
16+
register_bitfields,
17+
};
1518

1619
// When HCR_EL2.E2H == 0:
1720
// TODO: Figure out how we can differentiate depending on HCR_EL2.E2H state
@@ -53,10 +56,18 @@ register_bitfields! {u64,
5356

5457
pub struct Reg;
5558

56-
impl RegisterReadWrite<u64, CNTHCTL_EL2::Register> for Reg {
59+
impl Readable for Reg {
60+
type T = u64;
61+
type R = CNTHCTL_EL2::Register;
62+
5763
sys_coproc_read_raw!(u64, "CNTHCTL_EL2", "x");
64+
}
65+
66+
impl Writeable for Reg {
67+
type T = u64;
68+
type R = CNTHCTL_EL2::Register;
69+
5870
sys_coproc_write_raw!(u64, "CNTHCTL_EL2", "x");
5971
}
6072

61-
#[allow(non_upper_case_globals)]
62-
pub static CNTHCTL_EL2: Reg = Reg {};
73+
pub const CNTHCTL_EL2: Reg = Reg {};

src/regs/cntp_ctl_el0.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
//!
1010
//! Control register for the EL1 physical timer.
1111
12-
use register::{cpu::RegisterReadWrite, register_bitfields};
12+
use tock_registers::{
13+
interfaces::{Readable, Writeable},
14+
register_bitfields,
15+
};
1316

1417
register_bitfields! {u64,
1518
pub CNTP_CTL_EL0 [
@@ -43,9 +46,18 @@ register_bitfields! {u64,
4346

4447
pub struct Reg;
4548

46-
impl RegisterReadWrite<u64, CNTP_CTL_EL0::Register> for Reg {
49+
impl Readable for Reg {
50+
type T = u64;
51+
type R = CNTP_CTL_EL0::Register;
52+
4753
sys_coproc_read_raw!(u64, "CNTP_CTL_EL0", "x");
54+
}
55+
56+
impl Writeable for Reg {
57+
type T = u64;
58+
type R = CNTP_CTL_EL0::Register;
59+
4860
sys_coproc_write_raw!(u64, "CNTP_CTL_EL0", "x");
4961
}
5062

51-
pub static CNTP_CTL_EL0: Reg = Reg {};
63+
pub const CNTP_CTL_EL0: Reg = Reg {};

src/regs/cntp_tval_el0.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@
99
//!
1010
//! Holds the timer value for the EL1 physical timer.
1111
12-
use register::cpu::RegisterReadWrite;
12+
use tock_registers::interfaces::{Readable, Writeable};
1313

1414
pub struct Reg;
1515

16-
impl RegisterReadWrite<u64, ()> for Reg {
16+
impl Readable for Reg {
17+
type T = u64;
18+
type R = ();
19+
1720
sys_coproc_read_raw!(u64, "CNTP_TVAL_EL0", "x");
21+
}
22+
23+
impl Writeable for Reg {
24+
type T = u64;
25+
type R = ();
26+
1827
sys_coproc_write_raw!(u64, "CNTP_TVAL_EL0", "x");
1928
}
2029

21-
pub static CNTP_TVAL_EL0: Reg = Reg {};
30+
pub const CNTP_TVAL_EL0: Reg = Reg {};

src/regs/cntpct_el0.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
//!
1010
//! Holds the 64-bit physical count value.
1111
12-
use register::cpu::RegisterReadOnly;
12+
use tock_registers::interfaces::Readable;
1313

1414
pub struct Reg;
1515

16-
impl RegisterReadOnly<u64, ()> for Reg {
16+
impl Readable for Reg {
17+
type T = u64;
18+
type R = ();
19+
1720
sys_coproc_read_raw!(u64, "CNTPCT_EL0", "x");
1821
}
1922

20-
pub static CNTPCT_EL0: Reg = Reg {};
23+
pub const CNTPCT_EL0: Reg = Reg {};

0 commit comments

Comments
 (0)