8f05d29abd493f4b40b7ca1a47ae9b974ac5dd40
[AROS.git] / arch / ppc-all / exec / cachecleare.c
blob8f05d29abd493f4b40b7ca1a47ae9b974ac5dd40
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: CacheClearE() - Clear the caches with extended control.
6 Lang: english
7 */
9 #include <aros/config.h>
10 #include <exec/types.h>
11 #include <exec/execbase.h>
12 #include <aros/libcall.h>
14 #include "kernel_syscall.h"
16 /*****************************************************************************
18 NAME */
19 #include <proto/exec.h>
21 AROS_LH3(void, CacheClearE,
23 /* SYNOPSIS */
24 AROS_LHA(APTR, address, A0),
25 AROS_LHA(ULONG, length, D0),
26 AROS_LHA(ULONG, caches, D1),
28 /* LOCATION */
29 struct ExecBase *, SysBase, 107, Exec)
31 /* FUNCTION
32 Flush the contents of the CPU instruction or data caches. If some
33 of the cache contains dirty data, push it to memory first.
35 For most systems DMA will not effect processor caches. If *any*
36 external (non-processor) event changes system memory, you MUST
37 clear the cache. For example:
39 DMA
40 Code relocation to run at a different address
41 Building jump tables
42 Loading code from disk
44 INPUTS
45 address - Address to start the operation. This address may be
46 rounded DOWN due to hardware granularity.
47 length - Length of the memory to flush. This will be rounded
48 up, of $FFFFFFFF to indicate that all addresses
49 should be cleared.
50 caches - Bit flags to indicate which caches should be cleared
52 CACRF_ClearI - Clear the instruction cache
53 CACRF_ClearD - Clear the data cache
55 All other bits are reserved.
57 RESULT
58 The caches will be flushed.
60 NOTES
61 It is possible that on some systems the entire cache will be
62 even if this was not the specific request.
64 EXAMPLE
66 BUGS
68 SEE ALSO
69 CacheClearU(), CacheControl()
71 INTERNALS
72 This is a rather CPU dependant function. You should replace it
73 in your $(KERNEL).
75 ******************************************************************************/
77 AROS_LIBFUNC_INIT
79 char *start = (char*)((IPTR)address & 0xffffffe0);
80 char *end = (char*)(((IPTR)address + length + 31) & 0xffffffe0);
81 char *ptr;
83 /* Flush data caches and mark cache lines invalid */
84 if (caches & CACRF_ClearD)
86 for (ptr = start; ptr < end; ptr +=32)
88 asm volatile("dcbf 0,%0"::"r"(ptr));
90 asm volatile("sync");
93 #if (AROS_FLAVOUR & AROS_FLAVOUR_STANDALONE)
94 if (caches & CACRF_InvalidateD)
96 register APTR addr asm ("r4") = address;
97 register ULONG len asm ("r5") = length;
98 asm volatile("li %%r3,%0; sc"::"i"(SC_INVALIDATED),"r"(addr),"r"(len):"memory","r3");
100 #endif
102 if (caches & CACRF_ClearI) /* Clear ICache with DCache together */
104 for (ptr = start; ptr < end; ptr +=32)
106 asm volatile("icbi 0,%0"::"r"(ptr));
109 asm volatile("sync; isync; ");
112 AROS_LIBFUNC_EXIT
113 } /* CacheClearE */