patch: sync caches on powerpc
"Sean O'Rourke" <[email protected]>
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
This should fix the problem that some people have reported on powerpc -- the instruction and data caches weren't being sync'd, so the old, bogus memory contents were being executed (or fixups weren't happening). Tested on Linux-PPC with binutils 2.12, but it should work with older versions as well. The diff is against 0.97_1. /s
dldbfd.c.diff
(text/plain, 1.4 KB)
--- 0.97-dldbfd.c Sun Apr 13 14:46:16 2003
+++ dldbfd.c Sun Apr 13 13:33:19 2003
@@ -50,6 +50,10 @@
#if HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
+#include <limits.h>
+#ifndef CACHELINESIZE
+# define CACHELINESIZE 0x10
+#endif
/* ---------------------------------------- */
/* GCC OPTIMISATIONS */
@@ -1657,7 +1658,24 @@ resolve_newly_defined_symbols(module_ent
/* ---------------------------------------- */
/* PERFORM RELOCATION */
+/* ppc_sync_cache -- sync instruction and data caches (_after_ reloc) */
+static void
+ppc_sync_cache(void *_start, void *_end)
+{
+ char *start = (char*)(((int)_start) &~(CACHELINESIZE - 1));
+ char *end = (char *)((((int)_end)+CACHELINESIZE-1) &~(CACHELINESIZE - 1));
+ char *_sync;
+ for (_sync = start; _sync < end; _sync += CACHELINESIZE)
+ {
+ __asm__ __volatile__ (
+ "dcbf 0,%0"
+ :
+ : "r" ((long)_sync)
+ );
+ }
+ __asm__ __volatile__ ("sync");
+}
/* apply_relocations -- perform relocation on a fully linked module */
@@ -1751,6 +1769,11 @@ apply_relocations(module_entry *module,
THROW("Corrupted relocation table");
}
}
+#ifdef __PPC__
+ ppc_sync_cache((void *)p->vma,
+ (char *)p->vma + bfd_section_size(abfd, p));
+#endif /* __PPC__ */
+
}
/* Mark module as relocated */
if (externalp)