1 /* Copyright (C) 1992-2024 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include "target-dcache.h"
19 #include "progspace.h"
20 #include "cli/cli-cmds.h"
22 /* The target dcache is kept per-address-space. This key lets us
23 associate the cache with the address space. */
25 static const registry
<address_space
>::key
<DCACHE
, dcache_deleter
>
26 target_dcache_aspace_key
;
28 /* Target dcache is initialized or not. */
31 target_dcache_init_p (address_space_ref_ptr aspace
)
34 = target_dcache_aspace_key
.get (aspace
.get ());
36 return (dcache
!= NULL
);
39 /* Invalidate the target dcache. */
42 target_dcache_invalidate (address_space_ref_ptr aspace
)
45 = target_dcache_aspace_key
.get (aspace
.get ());
48 dcache_invalidate (dcache
);
51 /* Return the target dcache. Return NULL if target dcache is not
55 target_dcache_get (address_space_ref_ptr aspace
)
57 return target_dcache_aspace_key
.get (aspace
.get ());
60 /* Return the target dcache. If it is not initialized yet, initialize
64 target_dcache_get_or_init (address_space_ref_ptr aspace
)
67 = target_dcache_aspace_key
.get (aspace
.get ());
71 dcache
= dcache_init ();
72 target_dcache_aspace_key
.set (aspace
.get (), dcache
);
78 /* The option sets this. */
79 static bool stack_cache_enabled_1
= true;
80 /* And set_stack_cache updates this.
81 The reason for the separation is so that we don't flush the cache for
82 on->on transitions. */
83 static int stack_cache_enabled
= 1;
85 /* This is called *after* the stack-cache has been set.
86 Flush the cache for off->on and on->off transitions.
87 There's no real need to flush the cache for on->off transitions,
88 except cleanliness. */
91 set_stack_cache (const char *args
, int from_tty
, struct cmd_list_element
*c
)
93 if (stack_cache_enabled
!= stack_cache_enabled_1
)
94 target_dcache_invalidate (current_program_space
->aspace
);
96 stack_cache_enabled
= stack_cache_enabled_1
;
100 show_stack_cache (struct ui_file
*file
, int from_tty
,
101 struct cmd_list_element
*c
, const char *value
)
103 gdb_printf (file
, _("Cache use for stack accesses is %s.\n"), value
);
106 /* Return true if "stack cache" is enabled, otherwise, return false. */
109 stack_cache_enabled_p (void)
111 return stack_cache_enabled
;
114 /* The option sets this. */
116 static bool code_cache_enabled_1
= true;
118 /* And set_code_cache updates this.
119 The reason for the separation is so that we don't flush the cache for
120 on->on transitions. */
121 static int code_cache_enabled
= 1;
123 /* This is called *after* the code-cache has been set.
124 Flush the cache for off->on and on->off transitions.
125 There's no real need to flush the cache for on->off transitions,
126 except cleanliness. */
129 set_code_cache (const char *args
, int from_tty
, struct cmd_list_element
*c
)
131 if (code_cache_enabled
!= code_cache_enabled_1
)
132 target_dcache_invalidate (current_program_space
->aspace
);
134 code_cache_enabled
= code_cache_enabled_1
;
137 /* Show option "code-cache". */
140 show_code_cache (struct ui_file
*file
, int from_tty
,
141 struct cmd_list_element
*c
, const char *value
)
143 gdb_printf (file
, _("Cache use for code accesses is %s.\n"), value
);
146 /* Return true if "code cache" is enabled, otherwise, return false. */
149 code_cache_enabled_p (void)
151 return code_cache_enabled
;
154 /* Implement the 'maint flush dcache' command. */
157 maint_flush_dcache_command (const char *command
, int from_tty
)
159 target_dcache_invalidate (current_program_space
->aspace
);
161 gdb_printf (_("The dcache was flushed.\n"));
164 void _initialize_target_dcache ();
166 _initialize_target_dcache ()
168 add_setshow_boolean_cmd ("stack-cache", class_support
,
169 &stack_cache_enabled_1
, _("\
170 Set cache use for stack access."), _("\
171 Show cache use for stack access."), _("\
172 When on, use the target memory cache for all stack access, regardless of any\n\
173 configured memory regions. This improves remote performance significantly.\n\
174 By default, caching for stack access is on."),
177 &setlist
, &showlist
);
179 add_setshow_boolean_cmd ("code-cache", class_support
,
180 &code_cache_enabled_1
, _("\
181 Set cache use for code segment access."), _("\
182 Show cache use for code segment access."), _("\
183 When on, use the target memory cache for all code segment accesses,\n\
184 regardless of any configured memory regions. This improves remote\n\
185 performance significantly. By default, caching for code segment\n\
189 &setlist
, &showlist
);
191 add_cmd ("dcache", class_maintenance
, maint_flush_dcache_command
,
193 Force gdb to flush its target memory data cache.\n\
195 The dcache caches all target memory accesses where possible, this\n\
196 includes the stack-cache and the code-cache."),
197 &maintenanceflushlist
);