1 | /************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (c) 2013 Alcatel-Lucent |
---|
4 | * |
---|
5 | * Alcatel Lucent licenses this file to You under the Apache License, |
---|
6 | * Version 2.0 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. A copy of the License is contained the |
---|
8 | * file LICENSE at the top level of this repository. |
---|
9 | * You may also obtain a copy of the License at: |
---|
10 | * |
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
12 | * |
---|
13 | * Unless required by applicable law or agreed to in writing, software |
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
16 | * See the License for the specific language governing permissions and |
---|
17 | * limitations under the License. |
---|
18 | * |
---|
19 | ************************************************************************** |
---|
20 | * |
---|
21 | * cache_arm.c |
---|
22 | * |
---|
23 | * ARM's definition of "flush" and "clean" (as taken from the |
---|
24 | * "ARM System Developer's Guide") ... |
---|
25 | * |
---|
26 | * To "flush a cache" is to clear it of any stored data. Flushing clears |
---|
27 | * the valid bit in the affected cache line... The term "invalidate" |
---|
28 | * is sometimes used in place of the term "flush". |
---|
29 | * |
---|
30 | * To "clean a cache" is to force a write of the dirty cache lines |
---|
31 | * from the cache out to main memory and clear the dirty bits in the |
---|
32 | * cache line. |
---|
33 | * |
---|
34 | * This conflicts with uMon's general use of the terms "flush" and |
---|
35 | * "invalidate". For uMon, "flush" refers to what ARM calls "clean" |
---|
36 | * and "invalidate" refers to what ARM calls "flush". ARRGGHH!! |
---|
37 | * |
---|
38 | * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) |
---|
39 | * |
---|
40 | */ |
---|
41 | #include "cache.h" |
---|
42 | |
---|
43 | int |
---|
44 | arm_cleanDcache(char *base, int size) |
---|
45 | { |
---|
46 | return(0); |
---|
47 | } |
---|
48 | |
---|
49 | int |
---|
50 | arm_flushIcache(char *base, int size) |
---|
51 | { |
---|
52 | /* Flush (i.e. "invlidate in uMon terminology) entire instruction |
---|
53 | * cache (ignore incoming args). |
---|
54 | */ |
---|
55 | asm(" MOV r0, #0"); |
---|
56 | asm(" MCR p15, 0, r0, c7, c5, 0"); |
---|
57 | return(0); |
---|
58 | } |
---|
59 | |
---|
60 | /* cacheInitForTarget(): |
---|
61 | Enable instruction cache only... |
---|
62 | */ |
---|
63 | void |
---|
64 | cacheInitForTarget() |
---|
65 | { |
---|
66 | asm(" MRC p15, 0, r0, c1, c0, 0"); |
---|
67 | asm(" ORR r0, r0, #0x1000"); /* bit 12 is ICACHE enable*/ |
---|
68 | asm(" MCR p15, 0, r0, c1, c0, 0"); |
---|
69 | |
---|
70 | /* Flush instruction cache */ |
---|
71 | arm_flushIcache(0,0); |
---|
72 | |
---|
73 | dcacheFlush = arm_cleanDcache; |
---|
74 | icacheInvalidate = arm_flushIcache; |
---|
75 | } |
---|
76 | |
---|
77 | /* MRC/MCR assembler syntax (for ARM general): |
---|
78 | * |
---|
79 | * <MCR|MRC>{cond} p#,<expression1>,Rd,cn,cm{,<expression2>} |
---|
80 | * |
---|
81 | * Where: |
---|
82 | * - MRC move from coprocessor to ARM register (L=1) |
---|
83 | * - MCR move from ARM register to coprocessor (L=0) |
---|
84 | * - {cond} two character condition mnemonic (see list below) |
---|
85 | * - p# the unique number of the required coprocessor |
---|
86 | * - <expression1> evaluated to a constant and placed in the CP Opc field |
---|
87 | * - Rd is an expression evaluating to a valid ARM processor register |
---|
88 | * number |
---|
89 | * - cn and cm are expressions evaluating to the valid coprocessor register |
---|
90 | * numbers CRn and CRm respectively |
---|
91 | * - <expression2> where present is evaluated to a constant and placed in |
---|
92 | * the CP field |
---|
93 | * |
---|
94 | * Examples |
---|
95 | * - MRC 2,5,R3,c5,c6 ;request coproc 2 to perform operation 5 |
---|
96 | * ;on c5 and c6, and transfer the (single |
---|
97 | * ;32-bit word) result back to R3 |
---|
98 | * - MCR 6,0,R4,c6 ;request coproc 6 to perform operation 0 |
---|
99 | * ;on R4 and place the result in c6 |
---|
100 | * - MRCEQ 3,9,R3,c5,c6,2 ;conditionally request coproc 2 to |
---|
101 | * ;perform |
---|
102 | * ;operation 9 (type 2) on c5 and c6, and |
---|
103 | * ;transfer the result back to R3 |
---|
104 | * |
---|
105 | * Condition codes: |
---|
106 | * EQ (equal) - Z set |
---|
107 | * NE (not equal) - Z clear |
---|
108 | * CS (unsigned higher or same) - C set |
---|
109 | * CC (unsigned lower) - C clear |
---|
110 | * MI (negative) - N set |
---|
111 | * PL (positive or zero) - N clear |
---|
112 | * VS (overflow) - V set |
---|
113 | * VC (no overflow) - V clear |
---|
114 | * HI (unsigned higher) - C set and Z clear |
---|
115 | * LS (unsigned lower or same) - C clear or Z set |
---|
116 | * GE (greater or equal) - N set and V set, or N clear and V clear |
---|
117 | * LT (less than) - N set and V clear, or N clear and V set |
---|
118 | * GT (greater than) - Z clear, and either N set and Vset, |
---|
119 | * or N clear and V clear |
---|
120 | * LE (less than or equal) - Z set, or N set and V clear, |
---|
121 | * or N clear and V set |
---|
122 | * AL - always |
---|
123 | * NV - never |
---|
124 | */ |
---|