2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: CacheClearE() - Clear the caches with extended control.
9 #include <exec/types.h>
10 #include <exec/execbase.h>
11 #include <aros/libcall.h>
13 /*****************************************************************************
16 #include <proto/exec.h>
18 AROS_LH3(void, CacheClearE
,
21 AROS_LHA(APTR
, address
, A0
),
22 AROS_LHA(ULONG
, length
, D0
),
23 AROS_LHA(ULONG
, caches
, D1
),
26 struct ExecBase
*, SysBase
, 107, Exec
)
29 Flush the contents of the CPU instruction or data caches. If some
30 of the cache contains dirty data, push it to memory first.
32 For most systems DMA will not effect processor caches. If *any*
33 external (non-processor) event changes system memory, you MUST
34 clear the cache. For example:
37 Code relocation to run at a different address
39 Loading code from disk
42 address - Address to start the operation. This address may be
43 rounded DOWN due to hardware granularity.
44 length - Length of the memory to flush. This will be rounded
45 up, of $FFFFFFFF to indicate that all addresses
47 caches - Bit flags to indicate which caches should be cleared
49 CACRF_ClearI - Clear the instruction cache
50 CACRF_ClearD - Clear the data cache
52 All other bits are reserved.
55 The caches will be flushed.
58 It is possible that on some systems the entire cache will be
59 even if this was not the specific request.
66 CacheClearU(), CacheControl()
69 This is a rather CPU dependant function. You should replace it
72 ******************************************************************************/
76 char *start
= (char*)((IPTR
)address
& 0xffffffe0);
77 char *end
= (char*)(((IPTR
)address
+ length
+ 31) & 0xffffffe0);
80 /* Flush data caches and mark cacke lines invalid */
81 if (caches
& CACRF_ClearD
)
83 for (ptr
= start
; ptr
< end
; ptr
+=32)
85 asm volatile("dcbf 0,%0"::"r"(ptr
));
90 if (caches
& CACRF_InvalidateD
)
92 register APTR addr
asm ("r4") = address
;
93 register ULONG len
asm ("r5") = length
;
94 asm volatile("li %%r3,%0; sc"::"i"(8 /*SC_INVALIDATED*/),"r"(addr
),"r"(len
):"memory","r3");
97 if (caches
& CACRF_ClearI
) /* Clear ICache with DCache together */
99 for (ptr
= start
; ptr
< end
; ptr
+=32)
101 asm volatile("icbi 0,%0"::"r"(ptr
));
104 asm volatile("sync; isync; ");