1 /* Copyright (C) 1992-2015 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/>. */
19 #include "target-dcache.h"
21 #include "progspace.h"
23 /* The target dcache is kept per-address-space. This key lets us
24 associate the cache with the address space. */
26 static const struct address_space_data *target_dcache_aspace_key;
28 /* Clean up dcache, represented by ARG, which is associated with
32 target_dcache_cleanup (struct address_space *aspace, void *arg)
34 dcache_free ((DCACHE *) arg);
37 /* Target dcache is initialized or not. */
40 target_dcache_init_p (void)
43 = (DCACHE *) address_space_data (current_program_space->aspace,
44 target_dcache_aspace_key);
46 return (dcache != NULL);
49 /* Invalidate the target dcache. */
52 target_dcache_invalidate (void)
55 = (DCACHE *) address_space_data (current_program_space->aspace,
56 target_dcache_aspace_key);
59 dcache_invalidate (dcache);
62 /* Return the target dcache. Return NULL if target dcache is not
66 target_dcache_get (void)
69 = (DCACHE *) address_space_data (current_program_space->aspace,
70 target_dcache_aspace_key);
75 /* Return the target dcache. If it is not initialized yet, initialize
79 target_dcache_get_or_init (void)
82 = (DCACHE *) address_space_data (current_program_space->aspace,
83 target_dcache_aspace_key);
87 dcache = dcache_init ();
88 set_address_space_data (current_program_space->aspace,
89 target_dcache_aspace_key, dcache);
95 /* The option sets this. */
96 static int stack_cache_enabled_1 = 1;
97 /* And set_stack_cache updates this.
98 The reason for the separation is so that we don't flush the cache for
99 on->on transitions. */
100 static int stack_cache_enabled = 1;
102 /* This is called *after* the stack-cache has been set.
103 Flush the cache for off->on and on->off transitions.
104 There's no real need to flush the cache for on->off transitions,
105 except cleanliness. */
108 set_stack_cache (char *args, int from_tty, struct cmd_list_element *c)
110 if (stack_cache_enabled != stack_cache_enabled_1)
111 target_dcache_invalidate ();
113 stack_cache_enabled = stack_cache_enabled_1;
117 show_stack_cache (struct ui_file *file, int from_tty,
118 struct cmd_list_element *c, const char *value)
120 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
123 /* Return true if "stack cache" is enabled, otherwise, return false. */
126 stack_cache_enabled_p (void)
128 return stack_cache_enabled;
131 /* The option sets this. */
133 static int code_cache_enabled_1 = 1;
135 /* And set_code_cache updates this.
136 The reason for the separation is so that we don't flush the cache for
137 on->on transitions. */
138 static int code_cache_enabled = 1;
140 /* This is called *after* the code-cache has been set.
141 Flush the cache for off->on and on->off transitions.
142 There's no real need to flush the cache for on->off transitions,
143 except cleanliness. */
146 set_code_cache (char *args, int from_tty, struct cmd_list_element *c)
148 if (code_cache_enabled != code_cache_enabled_1)
149 target_dcache_invalidate ();
151 code_cache_enabled = code_cache_enabled_1;
154 /* Show option "code-cache". */
157 show_code_cache (struct ui_file *file, int from_tty,
158 struct cmd_list_element *c, const char *value)
160 fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
163 /* Return true if "code cache" is enabled, otherwise, return false. */
166 code_cache_enabled_p (void)
168 return code_cache_enabled;
171 /* -Wmissing-prototypes */
172 extern initialize_file_ftype _initialize_target_dcache;
175 _initialize_target_dcache (void)
177 add_setshow_boolean_cmd ("stack-cache", class_support,
178 &stack_cache_enabled_1, _("\
179 Set cache use for stack access."), _("\
180 Show cache use for stack access."), _("\
181 When on, use the target memory cache for all stack access, regardless of any\n\
182 configured memory regions. This improves remote performance significantly.\n\
183 By default, caching for stack access is on."),
186 &setlist, &showlist);
188 add_setshow_boolean_cmd ("code-cache", class_support,
189 &code_cache_enabled_1, _("\
190 Set cache use for code segment access."), _("\
191 Show cache use for code segment access."), _("\
192 When on, use the target memory cache for all code segment accesses,\n\
193 regardless of any configured memory regions. This improves remote\n\
194 performance significantly. By default, caching for code segment\n\
198 &setlist, &showlist);
200 target_dcache_aspace_key
201 = register_address_space_data_with_cleanup (NULL,
202 target_dcache_cleanup);