blob: b934fd4bdf6942cdfc6fd238b337fd5d482f1fbe [file] [log] [blame]
Edward O'Callaghan2bf62722009-08-05 04:02:56 +00001/* ===-- clear_cache.c - Implement __clear_cache ---------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan2bf62722009-08-05 04:02:56 +00007 *
8 * ===----------------------------------------------------------------------===
9 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000010
Bob Wilsona98b7cb2012-01-03 18:59:25 +000011#include "int_lib.h"
12
Daniel Dunbarb3a69012009-06-26 16:47:03 +000013#if __APPLE__
14 #include <libkern/OSCacheControl.h>
15#endif
16
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000017/*
18 * The compiler generates calls to __clear_cache() when creating
19 * trampoline functions on the stack for use with nested functions.
20 * It is expected to invalidate the instruction cache for the
21 * specified range.
22 */
23
Daniel Dunbarb3a69012009-06-26 16:47:03 +000024void __clear_cache(void* start, void* end)
25{
26#if __i386__ || __x86_64__
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000027/*
28 * Intel processors have a unified instruction and data cache
29 * so there is nothing to do
30 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000031#else
32 #if __APPLE__
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000033 /* On Darwin, sys_icache_invalidate() provides this functionality */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000034 sys_icache_invalidate(start, end-start);
35 #else
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000036 compilerrt_abort();
Daniel Dunbarb3a69012009-06-26 16:47:03 +000037 #endif
38#endif
39}
40