Add TLBI (TLB Invalidate) instruction wrappers with typed operands
Summary
Add Rust wrappers for AArch64 TLBI system instructions at EL1, with typed operand encoding that prevents callers from having to manually shift and mask bit fields.
Operand types
tlbi::Addr— encodes VA (bits [43:0]) and ASID (bits [63:48]) for VA-based instructionstlbi::Asid— encodes ASID only foraside1/aside1is
Both types provide new() for structured construction and from_raw() for pre-encoded values.
Instructions covered
| Category | Instructions |
|---|---|
| No operand | vmalle1, vmalle1is |
VA + ASID (Addr) |
vae1, vale1, vaae1, vaale1 + IS variants |
ASID only (Asid) |
aside1, aside1is |
Motivation
The crate already wraps DSB/ISB barrier instructions but has no TLBI support, forcing downstream users to write inline assembly for TLB maintenance. For example, SimpleKernel currently uses raw asm!("tlbi vmalle1", "dsb sy", "isb") in its memory management code because no wrapper is available.
Design
- Typed operands over raw
u64: Inspired by howbarrier.rsuses type-level dispatch.AddrandAsidare#[repr(transparent)]newtypes — zero runtime cost, compile-time misuse prevention. - Two types, not three: VA+ASID and VA-only share the same
Addrtype (passasid = 0for all-ASID variants likevaae1). The ASID field is RES0/ignored by hardware for these instructions, so a separate type would add API surface without meaningful safety benefit. - Macro-generated wrappers:
tlbi_no_arg!/tlbi_arg!eliminate repetition across 12 instruction wrappers, following thedmb_dsb!pattern inbarrier.rs. - Safe functions: Consistent with existing wrappers (
nop,wfi,dsb, etc.). Theunsafescope is limited to theasm!call. - VA mask (44-bit): Uses
0x0000_0FFF_FFFF_FFFFmatching bits [43:0] per Arm ARM, ensuring RES0 bits [47:44] are always zero. This is important for kernel (TTBR1) addresses where upper VA bits are all-ones. - Type names:
AddrandAsidinstead ofTlbiAddr/TlbiAsid— avoids redundancy with thetlbi::module path, followingbarrier.rsconvention (e.g.barrier::SY, notbarrier::BarrierSY). Types are not EL-specific, so they can be reused when EL2/EL3 instructions are added later.
Future work (documented in module docs)
- FEAT_TTL (ARMv8.4): TTL hint in bits [47:44]
- FEAT_TLBIRANGE (ARMv8.4): Range-based TLBI (
RVAE1,RVALE1, etc.) - Outer Shareable variants (ARMv8.4):
VMALLE1OS,VAE1OS, etc.
Verification
All 12 instructions verified via cross-compilation + disassembly:
| Instruction | Opcode | Operand |
|---|---|---|
tlbi vmalle1 |
d508871f |
none (xzr) |
tlbi vmalle1is |
d508831f |
none (xzr) |
tlbi vae1, x0 |
d5088720 |
register |
tlbi vae1is, x0 |
d5088320 |
register |
tlbi vale1, x0 |
d50887a0 |
register |
tlbi vale1is, x0 |
d50883a0 |
register |
tlbi vaae1, x0 |
d5088760 |
register |
tlbi vaae1is, x0 |
d5088360 |
register |
tlbi vaale1, x0 |
d50887e0 |
register |
tlbi vaale1is, x0 |
d50883e0 |
register |
tlbi aside1, x0 |
d5088740 |
register |
tlbi aside1is, x0 |
d5088340 |
register |
Test plan
- [x]
cargo build --target aarch64-unknown-none-softfloat— compiles - [x]
cargo build(host target) — compiles - [x]
cargo fmt --check— passes - [x]
cargo clippy --target aarch64-unknown-none-softfloat— no warnings - [x] Cross-compiled test crate +
objdump— all 12 opcodes match ARM ARM encoding
Code review
No issues found. Checked for bugs and CLAUDE.md compliance.
🤖 Generated with Claude Code
- If this code review was useful, please react with 👍. Otherwise, react with 👎.
As per https://github.com/rust-embedded/wg/blob/master/CODE_OF_CONDUCT.md#ai-tool-use-policy, please can you confirm that as the author you have reviewed and tested this contribution before submission and that you understand the contents of your submission?
As per https://github.com/rust-embedded/wg/blob/master/CODE_OF_CONDUCT.md#ai-tool-use-policy, please can you confirm that as the author you have reviewed and tested this contribution before submission and that you understand the contents of your submission?
I confirm that I have reviewed the content. AI participated in the design discussions, but I made the final decisions and manually verified the code.
Verified assembly output on godbolt QEMU tests via SimpleKernel