]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/dcache.c
1 /* Caching code. Typically used by remote back ends for
4 Copyright 1992, 1993 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 int remote_dcache
= 0;
28 /* The data cache records all the data read from the remote machine
29 since the last time it stopped.
31 Each cache block holds LINE_SIZE bytes of data
32 starting at a multiple-of-LINE_SIZE address. */
34 #define LINE_SIZE_MASK ((LINE_SIZE - 1)) /* eg 7*2+1= 111*/
35 #define XFORM(x) (((x) & LINE_SIZE_MASK) >> 2)
37 /* Free all the data cache blocks, thus discarding all cached data. */
42 register struct dcache_block
*db
;
44 if (remote_dcache
> 0)
45 while ((db
= dcache
->dcache_valid
.next
) != &dcache
->dcache_valid
)
48 insque (db
, &dcache
->dcache_free
);
55 * If addr is present in the dcache, return the address of the block
60 dcache_hit (dcache
, addr
)
64 register struct dcache_block
*db
;
67 || remote_dcache
== 0)
70 /* Search all cache blocks for one that is at this address. */
71 db
= dcache
->dcache_valid
.next
;
72 while (db
!= &dcache
->dcache_valid
)
74 if ((addr
& ~LINE_SIZE_MASK
) == db
->addr
)
82 /* Return the int data at address ADDR in dcache block DC. */
85 dcache_value (db
, addr
)
86 struct dcache_block
*db
;
90 || remote_dcache
== 0)
92 return (db
->data
[XFORM (addr
)]);
95 /* Get a free cache block, put or keep it on the valid list,
96 and return its address. The caller should store into the block
97 the address and data that it describes, then remque it from the
98 free list and insert it into the valid list. This procedure
99 prevents errors from creeping in if a memory retrieval is
100 interrupted (which used to put garbage blocks in the valid
103 struct dcache_block
*
104 dcache_alloc (dcache
)
107 register struct dcache_block
*db
;
109 if (remote_dcache
== 0)
112 if ((db
= dcache
->dcache_free
.next
) == &dcache
->dcache_free
)
114 /* If we can't get one from the free list, take last valid and put
115 it on the free list. */
116 db
= dcache
->dcache_valid
.last
;
118 insque (db
, &dcache
->dcache_free
);
122 insque (db
, &dcache
->dcache_valid
);
126 /* Using the data cache DCACHE return the contents of the word at
127 address ADDR in the remote machine. */
129 dcache_fetch (dcache
, addr
)
133 register struct dcache_block
*db
;
135 if (remote_dcache
== 0)
139 (*dcache
->read_memory
) (addr
, (unsigned char *) &i
, 4);
143 db
= dcache_hit (dcache
, addr
);
146 db
= dcache_alloc (dcache
);
148 (*dcache
->read_memory
) (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
150 db
->addr
= addr
& ~LINE_SIZE_MASK
;
151 remque (db
); /* Off the free list */
152 insque (db
, &dcache
->dcache_valid
); /* On the valid list */
154 return (dcache_value (db
, addr
));
157 /* Write the word at ADDR both in the data cache and in the remote machine. */
159 dcache_poke (dcache
, addr
, data
)
164 register struct dcache_block
*db
;
166 if (remote_dcache
== 0)
168 (*dcache
->write_memory
) (addr
, (unsigned char *) &data
, 4);
172 /* First make sure the word is IN the cache. DB is its cache block. */
173 db
= dcache_hit (dcache
, addr
);
176 db
= dcache_alloc (dcache
);
178 (*dcache
->write_memory
) (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
180 db
->addr
= addr
& ~LINE_SIZE_MASK
;
181 remque (db
); /* Off the free list */
182 insque (db
, &dcache
->dcache_valid
); /* On the valid list */
185 /* Modify the word in the cache. */
186 db
->data
[XFORM (addr
)] = data
;
188 /* Send the changed word. */
190 (*dcache
->write_memory
) (addr
, (unsigned char *) &data
, 4);
194 /* Initialize the data cache. */
196 dcache_init (reading
, writing
)
201 register struct dcache_block
*db
;
204 dcache
= (DCACHE
*) xmalloc (sizeof (*dcache
));
205 dcache
->read_memory
= reading
;
206 dcache
->write_memory
= writing
;
207 dcache
->the_cache
= (struct dcache_block
*)
208 xmalloc (sizeof (*dcache
->the_cache
) * DCACHE_SIZE
);
210 dcache
->dcache_free
.next
= dcache
->dcache_free
.last
= &dcache
->dcache_free
;
211 dcache
->dcache_valid
.next
= dcache
->dcache_valid
.last
= &dcache
->dcache_valid
;
212 for (db
= dcache
->the_cache
, i
= 0; i
< DCACHE_SIZE
; i
++, db
++)
213 insque (db
, &dcache
->dcache_free
);
219 _initialitize_dcache ()
222 (add_set_cmd ("remotecache", class_support
, var_boolean
,
223 (char *) &remote_dcache
,
225 Set cache use for remote targets.\n\
226 When on, use data caching for remote targets. For many remote targets\n\
227 this option can offer better throughput for reading target memory.\n\
228 Unfortunately, gdb does not currently know anything about volatile\n\
229 registers and thus data caching will produce incorrect results with\n\
230 volatile registers are in use. By default, this option is off.",