OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [frv/] [arch/] [current/] [include/] [hal_cache.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_CACHE_H
2
#define CYGONCE_HAL_CACHE_H
3
 
4
//=============================================================================
5
//
6
//      hal_cache.h
7
//
8
//      HAL cache control API
9
//
10
//=============================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
12
// -------------------------------------------                              
13
// This file is part of eCos, the Embedded Configurable Operating System.   
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under    
17
// the terms of the GNU General Public License as published by the Free     
18
// Software Foundation; either version 2 or (at your option) any later      
19
// version.                                                                 
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT      
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
24
// for more details.                                                        
25
//
26
// You should have received a copy of the GNU General Public License        
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
29
//
30
// As a special exception, if other files instantiate templates or use      
31
// macros or inline functions from this file, or you compile this file      
32
// and link it with other works to produce a work based on this file,       
33
// this file does not by itself cause the resulting work to be covered by   
34
// the GNU General Public License. However the source code for this file    
35
// must still be made available in accordance with section (3) of the GNU   
36
// General Public License v2.                                               
37
//
38
// This exception does not invalidate any other reasons why a work based    
39
// on this file might be covered by the GNU General Public License.         
40
// -------------------------------------------                              
41
// ####ECOSGPLCOPYRIGHTEND####                                              
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   gthomas
46
// Contributors:hmt
47
// Date:        2000-05-08
48
// Purpose:     Cache control API
49
// Description: The macros defined here provide the HAL APIs for handling
50
//              cache control operations.
51
// Usage:
52
//              #include <cyg/hal/hal_cache.h>
53
//              ...
54
//              
55
//
56
//####DESCRIPTIONEND####
57
//
58
//=============================================================================
59
 
60
#include <cyg/infra/cyg_type.h>
61
#include CYGBLD_HAL_PLF_DEFS_H        
62
#include <cyg/hal/plf_cache.h>      // Platform (model) details
63
 
64
//-----------------------------------------------------------------------------
65
// Global control of Instruction cache
66
 
67
// Enable the instruction cache
68
#define HAL_ICACHE_ENABLE()                     \
69
CYG_MACRO_START                                 \
70
    cyg_uint32 mask = _HSR0_ICE;                \
71
    asm volatile (                              \
72
        "movsg hsr0,gr4\n"                      \
73
        "\tor    gr4,%0,gr4\n"                  \
74
        "\tmovgs gr4,hsr0\n"                    \
75
        :                                       \
76
        : "r"(mask)                             \
77
        : "gr4" /* Clobber list */              \
78
        );                                      \
79
CYG_MACRO_END
80
 
81
// Disable the instruction cache (and invalidate it, required semanitcs)
82
#define HAL_ICACHE_DISABLE()                    \
83
CYG_MACRO_START                                 \
84
    cyg_uint32 mask = ~_HSR0_ICE;               \
85
    asm volatile (                              \
86
        "movsg hsr0,gr4\n"                      \
87
        "\tand   gr4,%0,gr4\n"                  \
88
        "\tmovgs gr4,hsr0\n"                    \
89
        :                                       \
90
        : "r"(mask)                             \
91
        : "gr4" /* Clobber list */              \
92
        );                                      \
93
CYG_MACRO_END
94
 
95
// Query the state of the instruction cache
96
#define HAL_ICACHE_IS_ENABLED(_state_)          \
97
CYG_MACRO_START                                 \
98
    register cyg_uint32 reg;                    \
99
    asm volatile ("movsg hsr0,%0"               \
100
                  : "=r"(reg)                   \
101
                  :                             \
102
        );                                      \
103
    (_state_) = (0 != (_HSR0_ICE & reg));       \
104
CYG_MACRO_END
105
 
106
// Invalidate the entire cache
107
#define HAL_ICACHE_INVALIDATE_ALL()             \
108
CYG_MACRO_START                                 \
109
    asm volatile ("icei @(gr4,gr0),1"           \
110
                  :                             \
111
                  :                             \
112
        );                                      \
113
CYG_MACRO_END
114
 
115
// Synchronize the contents of the cache with memory.
116
// (which includes flushing out pending writes)
117
#define HAL_ICACHE_SYNC()                                       \
118
CYG_MACRO_START                                                 \
119
    HAL_DCACHE_SYNC(); /* ensure data gets to RAM */            \
120
    HAL_ICACHE_INVALIDATE_ALL(); /* forget all we know */       \
121
CYG_MACRO_END
122
 
123
// Set the instruction cache refill burst size
124
//#define HAL_ICACHE_BURST_SIZE(_size_)
125
 
126
// Load the contents of the given address range into the instruction cache
127
// and then lock the cache so that it stays there.
128
//#define HAL_ICACHE_LOCK(_base_, _size_)
129
 
130
// Undo a previous lock operation
131
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
132
 
133
// Unlock entire cache
134
//#define HAL_ICACHE_UNLOCK_ALL()
135
 
136
//-----------------------------------------------------------------------------
137
// Instruction cache line control
138
 
139
// Invalidate cache lines in the given range without writing to memory.
140
#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )        \
141
CYG_MACRO_START                                         \
142
    cyg_uint32 _b = _base_;                             \
143
    cyg_uint32 _s = _size_;                             \
144
    while (_s > HAL_DCACHE_LINE_SIZE) {                 \
145
        asm volatile ("ici @(%0,gr0)"                   \
146
                      :                                 \
147
                      : "r"(_b)                         \
148
            );                                          \
149
        _s -= HAL_DCACHE_LINE_SIZE;                     \
150
        _b += HAL_DCACHE_LINE_SIZE;                     \
151
    }                                                   \
152
CYG_MACRO_END
153
 
154
//-----------------------------------------------------------------------------
155
// Global control of data cache
156
 
157
// Enable the data cache
158
#define HAL_DCACHE_ENABLE()                     \
159
CYG_MACRO_START                                 \
160
    cyg_uint32 mask = _HSR0_DCE;                \
161
    asm volatile (                              \
162
        "movsg hsr0,gr4\n"                      \
163
        "\tor    gr4,%0,gr4\n"                  \
164
        "\tmovgs gr4,hsr0\n"                    \
165
        :                                       \
166
        : "r"(mask)                             \
167
        : "gr4" /* Clobber list */              \
168
        );                                      \
169
CYG_MACRO_END
170
 
171
// Disable the data cache (and invalidate it, required semanitcs)
172
#define HAL_DCACHE_DISABLE()                    \
173
CYG_MACRO_START                                 \
174
    cyg_uint32 mask = ~_HSR0_DCE;               \
175
    asm volatile (                              \
176
        "movsg hsr0,gr4\n"                      \
177
        "\tand   gr4,%0,gr4\n"                  \
178
        "\tmovgs gr4,hsr0\n"                    \
179
        :                                       \
180
        : "r"(mask)                             \
181
        : "gr4" /* Clobber list */              \
182
        );                                      \
183
CYG_MACRO_END
184
 
185
// Query the state of the data cache
186
#define HAL_DCACHE_IS_ENABLED(_state_)          \
187
CYG_MACRO_START                                 \
188
    register cyg_uint32 reg;                    \
189
    asm volatile ("movsg hsr0,%0"               \
190
                  : "=r"(reg)                   \
191
                  :                             \
192
        );                                      \
193
    (_state_) = (0 != (_HSR0_DCE & reg));       \
194
CYG_MACRO_END
195
 
196
// Flush (invalidate) the entire dcache 
197
#define HAL_DCACHE_INVALIDATE_ALL()             \
198
CYG_MACRO_START                                 \
199
    asm volatile ("dcei @(gr4,gr0),1"           \
200
                  :                             \
201
                  :                             \
202
        );                                      \
203
CYG_MACRO_END
204
 
205
// Synchronize the contents of the cache with memory.
206
#define HAL_DCACHE_SYNC()                       \
207
CYG_MACRO_START                                 \
208
    asm volatile ("dcef @(gr4,gr0),1"           \
209
                  :                             \
210
                  :                             \
211
        );                                      \
212
CYG_MACRO_END
213
 
214
// Set the data cache refill burst size
215
//#define HAL_DCACHE_BURST_SIZE(_size_)
216
 
217
// Set the data cache write mode
218
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
219
 
220
#define HAL_DCACHE_WRITETHRU_MODE       0
221
#define HAL_DCACHE_WRITEBACK_MODE       1
222
 
223
// Get the current writeback mode - or only writeback mode if fixed
224
#define HAL_DCACHE_QUERY_WRITE_MODE( _mode_ ) CYG_MACRO_START           \
225
    _mode_ = HAL_DCACHE_WRITETHRU_MODE;                                 \
226
CYG_MACRO_END
227
 
228
// Load the contents of the given address range into the data cache
229
// and then lock the cache so that it stays there.
230
//#define HAL_DCACHE_LOCK(_base_, _size_)
231
 
232
// Undo a previous lock operation
233
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
234
 
235
// Unlock entire cache
236
//#define HAL_DCACHE_UNLOCK_ALL()
237
 
238
//-----------------------------------------------------------------------------
239
// Data cache line control
240
 
241
// Allocate cache lines for the given address range without reading its
242
// contents from memory.
243
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
244
 
245
// Write dirty cache lines to memory and invalidate the cache entries
246
// for the given address range.
247
#define HAL_DCACHE_FLUSH( _base_ , _size_ )     \
248
CYG_MACRO_START                                 \
249
    HAL_DCACHE_STORE( _base_ , _size_ );        \
250
    HAL_DCACHE_INVALIDATE( _base_ , _size_ );   \
251
CYG_MACRO_END
252
 
253
// Invalidate cache lines in the given range without writing to memory.
254
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )        \
255
CYG_MACRO_START                                         \
256
    cyg_uint32 _b = _base_;                             \
257
    cyg_uint32 _s = _size_;                             \
258
    while (_s > HAL_DCACHE_LINE_SIZE) {                 \
259
        asm volatile ("dci @(%0,gr0)"                   \
260
                      :                                 \
261
                      : "r"(_b)                         \
262
            );                                          \
263
        _s -= HAL_DCACHE_LINE_SIZE;                     \
264
        _b += HAL_DCACHE_LINE_SIZE;                     \
265
    }                                                   \
266
CYG_MACRO_END
267
 
268
// Write dirty cache lines to memory for the given address range.
269
#define HAL_DCACHE_STORE( _base_ , _size_ )     \
270
CYG_MACRO_START                                 \
271
    cyg_uint32 _b = _base_;                     \
272
    cyg_uint32 _s = _size_;                     \
273
    while (_s > HAL_DCACHE_LINE_SIZE) {         \
274
        asm volatile ("dcf @(%0,gr0)"           \
275
                      :                         \
276
                      : "r"(_b)                 \
277
            );                                  \
278
        _s -= HAL_DCACHE_LINE_SIZE;             \
279
        _b += HAL_DCACHE_LINE_SIZE;             \
280
    }                                           \
281
CYG_MACRO_END
282
 
283
// Preread the given range into the cache with the intention of reading
284
// from it later.
285
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
286
 
287
// Preread the given range into the cache with the intention of writing
288
// to it later.
289
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
290
 
291
// Allocate and zero the cache lines associated with the given range.
292
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
293
 
294
//-----------------------------------------------------------------------------
295
 
296
#endif // ifndef CYGONCE_HAL_CACHE_H
297
// End of hal_cache.h

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.