[PATCH] OS-independent __clear_cache for AARCH64

Joerg Sonnenberger joerg at NetBSD.org
Tue Jan 28 04:58:27 PST 2014


  Register content is log2.

Hi t.p.northover,

http://llvm-reviews.chandlerc.com/D2631

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2631?vs=6690&id=6710#toc

Files:
  clear_cache.c

Index: clear_cache.c
===================================================================
--- clear_cache.c
+++ clear_cache.c
@@ -38,6 +38,27 @@
   arg.len = (uintptr_t)end - (uintptr_t)start;
 
   sysarch(ARM_SYNC_ICACHE, &arg);
+#elif defined(__aarch64__)
+  uint64_t xstart = (uint64_t)(uintptr_t) start;
+  uint64_t xend = (uint64_t)(uintptr_t) end;
+
+  // Get Cache Type Info
+  uint64_t ctr_el0;
+  __asm __volatile("mrs %0, ctr_el0" : "=r"(ctr_el0));
+
+  /*
+   * dc & ic instructions must use 64bit registers so we don't use
+   * uintptr_t in case this runs in an IPL32 environment.
+   */
+  const size_t dcache_line_size = 4 << ((ctr_el0 >> 16) & 15);
+  for (uint64_t addr = xstart; addr < xend; addr += dcache_line_size)
+    __asm __volatile("dc cvau, %0" :: "r"(addr));
+  __asm __volatile("dsb ish");
+
+  const size_t icache_line_size = 4 << ((ctr_el0 >> 0) & 15);
+  for (uint64_t addr = xstart; addr < xend; addr += icache_line_size)
+    __asm __volatile("ic ivau, %0" :: "r"(addr));
+  __asm __volatile("isb sy");
 #else
     #if __APPLE__
         /* On Darwin, sys_icache_invalidate() provides this functionality */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2631.2.patch
Type: text/x-patch
Size: 1140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140128/af9176c8/attachment.bin>


More information about the llvm-commits mailing list