vmbase: Abstract CPU arch in write_volatile_u8()

Move write_volatile_u8() to the arch-agnostic import vmbase::arch, using
cfg_if to conditionally select the body of the function. Future
functions moved to this submodule will follow the same pattern, allowing
client code (including the rest of this crate) to become arch agnostic.

Test: m pvmfw_bin
Bug: 377276983
Change-Id: I52afb6642e494d6f0d1bf54a5b9712c460ca30d0
diff --git a/libs/libvmbase/Android.bp b/libs/libvmbase/Android.bp
index 206c4cb..c4e8385 100644
--- a/libs/libvmbase/Android.bp
+++ b/libs/libvmbase/Android.bp
@@ -79,6 +79,7 @@
     rustlibs: [
         "libaarch64_paging",
         "libbuddy_system_allocator",
+        "libcfg_if",
         "libcstr",
         "liblibfdt_nostd",
         "liblog_rust_nostd",
diff --git a/libs/libvmbase/src/arch.rs b/libs/libvmbase/src/arch.rs
index a79ecf1..ded66f2 100644
--- a/libs/libvmbase/src/arch.rs
+++ b/libs/libvmbase/src/arch.rs
@@ -14,6 +14,24 @@
 
 //! Low-level CPU-specific operations.
 
+#[cfg(target_arch = "aarch64")]
 pub mod aarch64;
 
-pub use aarch64::write_volatile_u8;
+/// Write with well-defined compiled behavior.
+///
+/// See https://github.com/rust-lang/rust/issues/131894
+///
+/// # Safety
+///
+/// `dst` must be valid for writes.
+#[inline]
+pub unsafe fn write_volatile_u8(dst: *mut u8, src: u8) {
+    cfg_if::cfg_if! {
+        if #[cfg(target_arch = "aarch64")] {
+            // SAFETY: `dst` is valid for writes.
+            unsafe { aarch64::strb(dst, src) }
+        } else {
+            compile_error!("Unsupported target_arch")
+        }
+    }
+}
diff --git a/libs/libvmbase/src/arch/aarch64.rs b/libs/libvmbase/src/arch/aarch64.rs
index 992ab27..d8bb2f5 100644
--- a/libs/libvmbase/src/arch/aarch64.rs
+++ b/libs/libvmbase/src/arch/aarch64.rs
@@ -92,14 +92,15 @@
     }};
 }
 
-/// Write with well-defined compiled behavior.
+/// STRB intrinsics.
 ///
 /// See https://github.com/rust-lang/rust/issues/131894
 ///
 /// # Safety
 ///
 /// `dst` must be valid for writes.
-pub unsafe fn write_volatile_u8(dst: *mut u8, src: u8) {
+#[inline]
+pub unsafe fn strb(dst: *mut u8, src: u8) {
     // SAFETY: strb only modifies *dst, which must be valid for writes.
     unsafe {
         core::arch::asm!(