aarch64-cpu-ext
A Rust library providing extended AArch64 CPU utilities and cache management operations.
Overview
This library extends the functionality of the aarch64-cpu crate by providing additional utilities for:
- Cache management operations (invalidate, clean, flush)
- Cache line size detection
- Low-level assembly operations for cache and TLB management
- Register access through re-exported
aarch64-cpuregisters
Features
- Cache Operations: Comprehensive cache management including clean, invalidate, and flush operations
- Cache Line Size Detection: Runtime detection of cache line sizes using CTR_EL0 register
- Translation Table Entries: Complete TTE64 implementation supporting 4KB/16KB/64KB granules and 48/52-bit addresses
- Assembly Wrappers: Low-level assembly instruction wrappers for cache and TLB operations
- No Standard Library:
#![no_std]compatible for embedded and bare-metal environments - Register Access: Full access to AArch64 system registers through re-exported functionality
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Cache Operations
use ;
// Flush instruction cache
icache_flush_all;
// Get cache line size
let line_size = cache_line_size;
// Perform cache operations on memory ranges
let buffer = &mut ;
dcache_range;
dcache_range;
dcache_range;
Register Access
use *;
// Access system registers (re-exported from aarch64-cpu)
let current_el = CurrentEL.get;
Translation Table Entries (TTE64)
use *;
// Create a 4KB granule, 48-bit address table entry
let table_addr = 0x10_0000; // Must be aligned to granule size
let table_tte = TTE4K48table; // attr_index = 1
// Create a block entry with detailed configuration
let block_addr = 0x20_0000;
let config = BlockConfig ;
let block_tte = TTE4K48new_block;
// Different granule sizes and address widths
let tte_16k_48 = TTE16K48table; // 16KB granule, 48-bit
let tte_64k_52 = TTE64K52table; // 64KB granule, 52-bit
// Address alignment utilities
let aligned_addr = TTE4K48align_up;
let is_aligned = TTE64K48is_aligned;
// Virtual address index calculation for page table walks
let va = 0x1234_5678_9ABC_DEF0;
let level0_index = TTE4K48calculate_index;
Supported Configurations
| Granule | Address Width | Type Alias |
|---|---|---|
| 4KB | 48-bit | TTE4K48 |
| 4KB | 52-bit | TTE4K52 |
| 16KB | 48-bit | TTE16K48 |
| 16KB | 52-bit | TTE16K52 |
| 64KB | 48-bit | TTE64K48 |
| 64KB | 52-bit | TTE64K52 |
Low-level Assembly Operations
use ;
// Direct assembly instruction wrappers
ic; // Instruction cache invalidate all
dc; // Data cache clean by virtual address
Cache Operation Types
- Clean: Write dirty cache lines back to memory without invalidating
- Invalidate: Mark cache lines as invalid without writing back
- CleanAndInvalidate: Write back dirty lines and mark as invalid
Requirements
- AArch64 target architecture
- Rust 2024 edition
- No standard library (
#![no_std])
Dependencies
aarch64-cpuversion 10 - Provides base AArch64 CPU functionalitytock-registersversion 0.9 - Register access and manipulation utilities
Target Architecture
This library is specifically designed for AArch64 (ARM64) architecture and will not compile for other targets.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please ensure that any new features maintain compatibility with #![no_std] environments and follow the existing code patterns.