rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.58k stars 12.48k forks source link

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

Open iankronquist opened 2 years ago

iankronquist commented 2 years ago

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 commented 2 years ago

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)

x1tan commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

Awesome thanks for the update! I believe the bug can be closed now.Ian KronquistOn Sep 23, 2022, at 03:38, Adam Gemmell @.***> wrote: 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

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

oToToT commented 1 year ago

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