Rust reported "expected writable system register or pstate" when processing inline asm

Hi,
Now I am going to build RTOS system program running on Raspberry-Pi Pico (RP2040)
by using Embedded Rust environment.

I have got following error messages from Rust compiler on inline asm statements which
access to control registers of RP2040 such as primask, ipsr.

---error message

error: expected writable system register or pstate
--> src/syslib.rs:48:15
|
48 | asm!("msr primask, {}", in(reg) pm);
| ^^^^^^^^^^^^^^^
|
note: instantiated into assembly here
--> :1:6
|
1 | msr primask, x0
|

Strangely, other inline asm statements not access to control registers were compiled successfully.
(for example, asm!("wfe"); , asm!("sev"); )

It seems that inline assembler of Rust does not know about name of special registers
for cortex-m0 like "primask".

Do you know what occurs this problem ?

the inline assember is the same the llvm codegen backend, the rust frontend just treat the assembly code as black box. there's no reason the assember cannot recognize the special register name.

without more details the most likely reason I would guess is you probably passed the wrong --target triplet to cargo or rustc.

Thanks for your quick reply.

As a result, I can compile inline asm by adding parameter --target=thumbv6m-none-eabi
after cargo build command.

I made .cargo/config file in my project folder and wrote
[target.thumbv6m-none-eabi]
but probably above statement is something wrong.

Anyway, I can solve problem.
I appreciate your good advice!

that's just an empty section (i.e. "table" in TOML terms) where target specific configurations should go under. the equivalent to the --target TRIPLE command line option is:

# .cargo/config.toml
[build]
target = "TRIPLE"
# can also be an array
target = [ "TRIPLE1", "TRIPLE2" ]

see:

https://doc.rust-lang.org/stable/cargo/reference/config.html#buildtarget

1 Like

I made config.toml file and wrote following statement

[build]
target = "thumbv6m-none-eabi"

After that, Rust compiler can compile inline asm successfully without --target option.
Thanks!

1 Like