liveBook · Manning

Control and status register

As explained in Embedded Software with Rust

A system register is a processor register in the architectural system-register file that controls or reports execution state and core configuration.

A control and status register holds processor execution state or configuration. Unlike a memory-mapped peripheral register, a Cortex-M system register resides in the processor’s system-register file and is accessed with instructions such as MRS and MSR. section 5.5.3

Register access depends on the target architecture:

  • On Cortex-M, registers such as MSP, PSP, CONTROL, and PRIMASK can be read or written with inline assembly. Some operations require privilege; changes to execution context may also require DSB followed by ISB. section 5.5.3
  • On RISC-V, the riscv crate provides interaction with control and status registers (CSRs) and interrupt management. section 3.5.1
use core::arch::asm;

// asm!(): Writes 1 to PRIMASK via MSR, which masks all exceptions except NMI
// and HardFault.
#[inline(always)]
fn disable_interrupts() {
    unsafe {
        core::arch::asm!(
            "msr PRIMASK, {reg}",
            reg = in(reg) 1u32,
            options(nomem, nostack),
        );
    }
}

This Rust asm! example writes 1 to PRIMASK with MSR, masking exceptions other than NMI and HardFault. section 5.5.3

How Embedded Software with Rust covers it

How deep it goes
Explains Cortex-M MRS/MSR access, privilege faults, and DSB/ISB synchronization, but does not detail individual register fields.
Examples
Uses MSP, PSP, CONTROL, and PRIMASK as Cortex-M examples, including a Rust listing that writes PRIMASK.
What you can do after
Operate processor state by writing PRIMASK with Rust asm!, while accounting for privilege and synchronization constraints.
How it connects
Connects system registers to inline assembly, privilege levels, architectural synchronization, and RISC-V control and status registers.

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.