Initial commit
[savezelda.git] / loader / sync.c
1 // Copyright 2008-2009  Segher Boessenkool  <segher@kernel.crashing.org>
2 // This code is licensed to you under the terms of the GNU GPL, version 2;
3 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
4
5 #include "loader.h"
6
7 void sync_before_read(void *p, u32 len)
8 {
9         u32 a, b;
10
11         a = (u32)p & ~0x1f;
12         b = ((u32)p + len + 0x1f) & ~0x1f;
13
14         for ( ; a < b; a += 32)
15                 asm("dcbi 0,%0" : : "b"(a) : "memory");
16
17         asm("sync ; isync");
18 }
19
20 void sync_after_write(const void *p, u32 len)
21 {
22         u32 a, b;
23
24         a = (u32)p & ~0x1f;
25         b = ((u32)p + len + 0x1f) & ~0x1f;
26
27         for ( ; a < b; a += 32)
28                 asm("dcbst 0,%0" : : "b"(a));
29
30         asm("sync ; isync");
31 }
32
33 void sync_before_exec(const void *p, u32 len)
34 {
35         u32 a, b;
36
37         a = (u32)p & ~0x1f;
38         b = ((u32)p + len + 0x1f) & ~0x1f;
39
40         for ( ; a < b; a += 32)
41                 asm("dcbst 0,%0 ; sync ; icbi 0,%0" : : "b"(a));
42
43         asm("sync ; isync");
44 }