1 /* Copyright (C) 1992-2020 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_key
<DCACHE
, dcache_deleter
>
27 target_dcache_aspace_key
;
29 /* Target dcache is initialized or not. */
32 target_dcache_init_p (void)
35 = target_dcache_aspace_key
.get (current_program_space
->aspace
);
37 return (dcache
!= NULL
);
40 /* Invalidate the target dcache. */
43 target_dcache_invalidate (void)
46 = target_dcache_aspace_key
.get (current_program_space
->aspace
);
49 dcache_invalidate (dcache
);
52 /* Return the target dcache. Return NULL if target dcache is not
56 target_dcache_get (void)
58 return target_dcache_aspace_key
.get (current_program_space
->aspace
);
61 /* Return the target dcache. If it is not initialized yet, initialize
65 target_dcache_get_or_init (void)
68 = target_dcache_aspace_key
.get (current_program_space
->aspace
);
72 dcache
= dcache_init ();
73 target_dcache_aspace_key
.set (current_program_space
->aspace
, dcache
);
79 /* The option sets this. */
80 static bool stack_cache_enabled_1
= true;
81 /* And set_stack_cache updates this.
82 The reason for the separation is so that we don't flush the cache for
83 on->on transitions. */
84 static int stack_cache_enabled
= 1;
86 /* This is called *after* the stack-cache has been set.
87 Flush the cache for off->on and on->off transitions.
88 There's no real need to flush the cache for on->off transitions,
89 except cleanliness. */
92 set_stack_cache (const char *args
, int from_tty
, struct cmd_list_element
*c
)
94 if (stack_cache_enabled
!= stack_cache_enabled_1
)
95 target_dcache_invalidate ();
97 stack_cache_enabled
= stack_cache_enabled_1
;
101 show_stack_cache (struct ui_file
*file
, int from_tty
,
102 struct cmd_list_element
*c
, const char *value
)
104 fprintf_filtered (file
, _("Cache use for stack accesses is %s.\n"), value
);
107 /* Return true if "stack cache" is enabled, otherwise, return false. */
110 stack_cache_enabled_p (void)
112 return stack_cache_enabled
;
115 /* The option sets this. */
117 static bool code_cache_enabled_1
= true;
119 /* And set_code_cache updates this.
120 The reason for the separation is so that we don't flush the cache for
121 on->on transitions. */
122 static int code_cache_enabled
= 1;
124 /* This is called *after* the code-cache has been set.
125 Flush the cache for off->on and on->off transitions.
126 There's no real need to flush the cache for on->off transitions,
127 except cleanliness. */
130 set_code_cache (const char *args
, int from_tty
, struct cmd_list_element
*c
)
132 if (code_cache_enabled
!= code_cache_enabled_1
)
133 target_dcache_invalidate ();
135 code_cache_enabled
= code_cache_enabled_1
;
138 /* Show option "code-cache". */
141 show_code_cache (struct ui_file
*file
, int from_tty
,
142 struct cmd_list_element
*c
, const char *value
)
144 fprintf_filtered (file
, _("Cache use for code accesses is %s.\n"), value
);
147 /* Return true if "code cache" is enabled, otherwise, return false. */
150 code_cache_enabled_p (void)
152 return code_cache_enabled
;
156 _initialize_target_dcache (void)
158 add_setshow_boolean_cmd ("stack-cache", class_support
,
159 &stack_cache_enabled_1
, _("\
160 Set cache use for stack access."), _("\
161 Show cache use for stack access."), _("\
162 When on, use the target memory cache for all stack access, regardless of any\n\
163 configured memory regions. This improves remote performance significantly.\n\
164 By default, caching for stack access is on."),
167 &setlist
, &showlist
);
169 add_setshow_boolean_cmd ("code-cache", class_support
,
170 &code_cache_enabled_1
, _("\
171 Set cache use for code segment access."), _("\
172 Show cache use for code segment access."), _("\
173 When on, use the target memory cache for all code segment accesses,\n\
174 regardless of any configured memory regions. This improves remote\n\
175 performance significantly. By default, caching for code segment\n\
179 &setlist
, &showlist
);