Skip to content

Rustc does not recognize ttbr0_el2 as a valid armv8 system register #97724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iankronquist opened this issue Jun 4, 2022 · 5 comments
Open
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. O-AArch64 Armv8-A or later processors in AArch64 mode T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@iankronquist
Copy link

iankronquist commented Jun 4, 2022

Rustc does not recognize ttbr0_el2 as a valid armv8 system register.
ttbr0_el2 is used by hypervisors to configure page tables for the lower half of memory, typically used for userspace.

#![no_std]
use core::arch::asm;

static PT: [u64; 512] = [0; 512];
pub fn main() {
    unsafe {
        asm!("msr {pt}, ttbr0_el2", pt = in(reg) &PT as *const _ );
    }
}

This fails to compile with the error:

error: expected writable system register or pstate
 --> <source>:8:15
  |
8 |         asm!("msr {pt}, ttbr0_el2", pt = in(reg) &PT as *const _ );
  |               ^
  |
note: instantiated into assembly here
 --> <inline asm>:1:6
  |
1 |     msr x8, ttbr0_el2
  |         ^

error: aborting due to previous error

Compiler returned: 1

Here is a live example on godbolt:
https://godbolt.org/z/3jsGEd59a

My rustc version is:

$ rustc --version
rustc 1.63.0-nightly (e71440575 2022-06-02)
@asquared31415
Copy link
Contributor

asquared31415 commented Jun 4, 2022

That is an assembler error, nothing to do directly with Rust.

I think your arguments are backwards. To move from PT into that register, it would me msr ttbr0_el2, {pt}.

Edit: upon further inspection, even with that fix, LLVM doesn't seem to recognize the ttbr0_el2 register specifically (1 and 3 work)

@nagisa nagisa added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-inline-assembly Area: Inline assembly (`asm!(…)`) O-AArch64 Armv8-A or later processors in AArch64 mode labels Jun 6, 2022
@x1tan
Copy link

x1tan commented Jun 29, 2022

Running the latest nightly build (rustc 1.64.0-nightly (830880640 2022-06-28)) still produces the same error. Possible (temporary) workaround: creating a custom aarch64 target and adding +v8.1a to its features.

@adamgemmell
Copy link
Contributor

As the above issue says it's locked behind the el2vmsa LLVM feature, which Rust doesn't directly expose. You can turn it on with the unstable v8.1a feature for now: https://godbolt.org/z/6vcd3aYEM

@iankronquist
Copy link
Author

iankronquist commented Oct 11, 2022 via email

oToToT added a commit to oToToT/rust that referenced this issue Nov 29, 2022
After llvm/llvm-project@8689f5e landed, LLVM takes the intersection of v8a and v8r as default.
This commit brings back v8a support by explicitly specifying v8a in the feature list.

This should solve rust-lang#97724.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 2, 2022
v8a as default aarch64 target

After llvm/llvm-project@8689f5e landed, LLVM takes the intersection of v8a and v8r as default. This commit brings back v8a support by explicitly specifying v8a in the feature list.

This should solve rust-lang#97724.

p.s. a bit more context can also be found in llvm/llvm-project#57904 (comment).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 2, 2022
v8a as default aarch64 target

After llvm/llvm-project@8689f5e landed, LLVM takes the intersection of v8a and v8r as default. This commit brings back v8a support by explicitly specifying v8a in the feature list.

This should solve rust-lang#97724.

p.s. a bit more context can also be found in llvm/llvm-project#57904 (comment).
@oToToT
Copy link
Contributor

oToToT commented Jan 30, 2023

I believe the code now compiles in the latest stable (1.67.0)

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@workingjubilee workingjubilee added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. O-AArch64 Armv8-A or later processors in AArch64 mode T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants