Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / target-dcache.c
blob2a29685e608fd8eda18d585d19efa3cc623be4b1
1 /* Copyright (C) 1992-2021 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 "defs.h"
19 #include "target-dcache.h"
20 #include "gdbcmd.h"
21 #include "progspace.h"
22 #include "cli/cli-cmds.h"
24 /* The target dcache is kept per-address-space. This key lets us
25 associate the cache with the address space. */
27 static const struct address_space_key<DCACHE, dcache_deleter>
28 target_dcache_aspace_key;
30 /* Target dcache is initialized or not. */
32 int
33 target_dcache_init_p (void)
35 DCACHE *dcache
36 = target_dcache_aspace_key.get (current_program_space->aspace);
38 return (dcache != NULL);
41 /* Invalidate the target dcache. */
43 void
44 target_dcache_invalidate (void)
46 DCACHE *dcache
47 = target_dcache_aspace_key.get (current_program_space->aspace);
49 if (dcache != NULL)
50 dcache_invalidate (dcache);
53 /* Return the target dcache. Return NULL if target dcache is not
54 initialized yet. */
56 DCACHE *
57 target_dcache_get (void)
59 return target_dcache_aspace_key.get (current_program_space->aspace);
62 /* Return the target dcache. If it is not initialized yet, initialize
63 it. */
65 DCACHE *
66 target_dcache_get_or_init (void)
68 DCACHE *dcache
69 = target_dcache_aspace_key.get (current_program_space->aspace);
71 if (dcache == NULL)
73 dcache = dcache_init ();
74 target_dcache_aspace_key.set (current_program_space->aspace, dcache);
77 return dcache;
80 /* The option sets this. */
81 static bool stack_cache_enabled_1 = true;
82 /* And set_stack_cache updates this.
83 The reason for the separation is so that we don't flush the cache for
84 on->on transitions. */
85 static int stack_cache_enabled = 1;
87 /* This is called *after* the stack-cache has been set.
88 Flush the cache for off->on and on->off transitions.
89 There's no real need to flush the cache for on->off transitions,
90 except cleanliness. */
92 static void
93 set_stack_cache (const char *args, int from_tty, struct cmd_list_element *c)
95 if (stack_cache_enabled != stack_cache_enabled_1)
96 target_dcache_invalidate ();
98 stack_cache_enabled = stack_cache_enabled_1;
101 static void
102 show_stack_cache (struct ui_file *file, int from_tty,
103 struct cmd_list_element *c, const char *value)
105 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
108 /* Return true if "stack cache" is enabled, otherwise, return false. */
111 stack_cache_enabled_p (void)
113 return stack_cache_enabled;
116 /* The option sets this. */
118 static bool code_cache_enabled_1 = true;
120 /* And set_code_cache updates this.
121 The reason for the separation is so that we don't flush the cache for
122 on->on transitions. */
123 static int code_cache_enabled = 1;
125 /* This is called *after* the code-cache has been set.
126 Flush the cache for off->on and on->off transitions.
127 There's no real need to flush the cache for on->off transitions,
128 except cleanliness. */
130 static void
131 set_code_cache (const char *args, int from_tty, struct cmd_list_element *c)
133 if (code_cache_enabled != code_cache_enabled_1)
134 target_dcache_invalidate ();
136 code_cache_enabled = code_cache_enabled_1;
139 /* Show option "code-cache". */
141 static void
142 show_code_cache (struct ui_file *file, int from_tty,
143 struct cmd_list_element *c, const char *value)
145 fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
148 /* Return true if "code cache" is enabled, otherwise, return false. */
151 code_cache_enabled_p (void)
153 return code_cache_enabled;
156 /* Implement the 'maint flush dcache' command. */
158 static void
159 maint_flush_dcache_command (const char *command, int from_tty)
161 target_dcache_invalidate ();
162 if (from_tty)
163 printf_filtered (_("The dcache was flushed.\n"));
166 void _initialize_target_dcache ();
167 void
168 _initialize_target_dcache ()
170 add_setshow_boolean_cmd ("stack-cache", class_support,
171 &stack_cache_enabled_1, _("\
172 Set cache use for stack access."), _("\
173 Show cache use for stack access."), _("\
174 When on, use the target memory cache for all stack access, regardless of any\n\
175 configured memory regions. This improves remote performance significantly.\n\
176 By default, caching for stack access is on."),
177 set_stack_cache,
178 show_stack_cache,
179 &setlist, &showlist);
181 add_setshow_boolean_cmd ("code-cache", class_support,
182 &code_cache_enabled_1, _("\
183 Set cache use for code segment access."), _("\
184 Show cache use for code segment access."), _("\
185 When on, use the target memory cache for all code segment accesses,\n\
186 regardless of any configured memory regions. This improves remote\n\
187 performance significantly. By default, caching for code segment\n\
188 access is on."),
189 set_code_cache,
190 show_code_cache,
191 &setlist, &showlist);
193 add_cmd ("dcache", class_maintenance, maint_flush_dcache_command,
194 _("\
195 Force gdb to flush its target memory data cache.\n\
197 The dcache caches all target memory accesses where possible, this\n\
198 includes the stack-cache and the code-cache."),
199 &maintenanceflushlist);