summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/m68k/shared/cache/cache.c
blob: ce98f006c69d1ef5a9c5f23e397b3697cd0f0f52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 *  Cache Management Support Routines for the MC68040
 *
 *  $Id$
 */

#include <rtems.h>
#include "cache_.h"

/*  
 *  Since the cacr is common to all mc680x0, provide macros
 *  for masking values in that register.
 */

/* 
 *  Used to clear bits in the cacr.
 */
#define _CPU_CACR_AND(mask)                                        \
  {                                                                \
  register unsigned long _value = mask;                            \
  register unsigned long _ctl = 0;                                 \
  asm volatile ( "movec %%cacr, %0;           /* read the cacr */  \
                  andl %2, %0;                /* and with _val */  \
                  movec %1, %%cacr"           /* write the cacr */ \
   : "=d" (_ctl) : "0" (_ctl), "d" (_value) : "%%cc" );            \
  }


/*  
 *  Used to set bits in the cacr.
 */
#define _CPU_CACR_OR(mask)                                         \
	{                                                                \
  register unsigned long _value = mask;                            \
  register unsigned long _ctl = 0;                                 \
  asm volatile ( "movec %%cacr, %0;           /* read the cacr */  \
                  orl %2, %0;                 /* or with _val */   \
                  movec %1, %%cacr"           /* write the cacr */ \
   : "=d" (_ctl) : "0" (_ctl), "d" (_value) : "%%cc" );            \
  }

   
/*
 * CACHE MANAGER: The following functions are CPU-specific.
 * They provide the basic implementation for the rtems_* cache
 * management routines. If a given function has no meaning for the CPU,
 * it does nothing by default.
 */
#if ( defined(__mc68020__) || defined(__mc68030__) )

#if defined(__mc68030__)

/* Only the mc68030 has a data cache; it is writethrough only. */

void _CPU_flush_1_data_cache_line ( const void * d_addr ) {}
void _CPU_flush_entire_data_cache ( const void * d_addr ) {}

void _CPU_invalidate_1_data_cache_line (
  const void * d_addr )
{
  void * p_address = (void *) _CPU_virtual_to_physical( d_addr );
  asm volatile ( "movec %0, %%caar" :: "a" (p_address) );      /* write caar */
  _CPU_CACR_OR(0x00000400);
}

void _CPU_invalidate_entire_data_cache ( void )
{
  _CPU_CACR_OR( 0x00000800 );
}

void _CPU_freeze_data_cache ( void )
{
  _CPU_CACR_OR( 0x00000200 );
}

void _CPU_unfreeze_data_cache ( void )
{
  _CPU_CACR_AND( 0xFFFFFDFF );
}

void _CPU_enable_data_cache ( void )
{
  _CPU_CACR_OR( 0x00000100 );
}
void _CPU_disable_data_cache (	void )
{
  _CPU_CACR_AND( 0xFFFFFEFF );
}
#endif


/* Both the 68020 and 68030 have instruction caches */

void _CPU_invalidate_1_inst_cache_line (
  const void * d_addr )
{
  void * p_address = (void *) _CPU_virtual_to_physical( d_addr );
  asm volatile ( "movec %0, %%caar" :: "a" (p_address) );      /* write caar */
  _CPU_CACR_OR( 0x00000004 );
}

void _CPU_invalidate_entire_inst_cache ( void )
{
  _CPU_CACR_OR( 0x00000008 );
}

void _CPU_freeze_inst_cache ( void )
{
  _CPU_CACR_OR( 0x00000002);
}

void _CPU_unfreeze_inst_cache ( void )
{
  _CPU_CACR_AND( 0xFFFFFFFD );
}

void _CPU_enable_inst_cache ( void )
{
  _CPU_CACR_OR( 0x00000001 );
}

void _CPU_disable_inst_cache (	void )
{
  _CPU_CACR_AND( 0xFFFFFFFE );
}


#elif ( defined(__mc68040__) || defined (__mc68060__) )

/* Cannot be frozen */
void _CPU_freeze_data_cache ( void ) {}
void _CPU_unfreeze_data_cache ( void ) {}
void _CPU_freeze_inst_cache ( void ) {}
void _CPU_unfreeze_inst_cache ( void ) {}

void _CPU_flush_1_data_cache_line (
  const void * d_addr )
{
  void * p_address = (void *) _CPU_virtual_to_physical( d_addr );
  asm volatile ( "cpushl %%dc,(%0)" :: "a" (p_address) );
}

void _CPU_invalidate_1_data_cache_line (
  const void * d_addr )
{
  void * p_address = (void *) _CPU_virtual_to_physical( d_addr );
  asm volatile ( "cinvl %%dc,(%0)" :: "a" (p_address) );
}

void _CPU_flush_entire_data_cache ( void )
{
	asm volatile ( "cpusha %%dc" :: );
}

void _CPU_invalidate_entire_data_cache ( void )
{
	asm volatile ( "cinva %%dc" :: );
}

void _CPU_enable_data_cache ( void )
{
  _CPU_CACR_OR( 0x80000000 );
}

void _CPU_disable_data_cache ( void )
{
  _CPU_CACR_AND( 0x7FFFFFFF );
}

void _CPU_invalidate_1_inst_cache_line (
  const void * i_addr )
{
  void * p_address = (void *)  _CPU_virtual_to_physical( i_addr );
  asm volatile ( "cinvl %%ic,(%0)" :: "a" (p_address) );
}

void _CPU_invalidate_entire_inst_cache ( void )
{
		asm volatile ( "cinva %%ic" :: );
}

void _CPU_enable_inst_cache ( void )
{
  _CPU_CACR_OR( 0x00008000 );
}

void _CPU_disable_inst_cache ( void )
{
	_CPU_CACR_AND( 0xFFFF7FFF );
}
#endif
/* end of file */