src/bare-metal/aps/safemmio/driver.md
Now let's use the new Registers struct in our driver.
# // Copyright 2025 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
{{#include ../examples/src/pl011.rs:Uart}}
UniqueMmioPointer is a wrapper around a raw pointer to an MMIO device or
register. The caller of UniqueMmioPointer::new promises that it is valid and
unique for the given lifetime, so it can provide safe methods to read and
write fields.Uart::new is now safe; UniqueMmioPointer::new is unsafe instead.read_volatile and
write_volatile, though on aarch64 they are instead implemented in assembly
to work around a bug where the compiler can emit instructions that prevent
MMIO virtualization.field! and field_shared! macros internally use &raw mut and
&raw const to get pointers to individual fields without creating an
intermediate reference, which would be unsound.field! needs a mutable reference to a UniqueMmioPointer, and returns a
UniqueMmioPointer that allows reads with side effects and writes.field_shared! works with a shared reference to either a UniqueMmioPointer
or a SharedMmioPointer. It returns a SharedMmioPointer that only allows
pure reads.