gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / target-dcache.c
1 /* Copyright (C) 1992-2020 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
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.
9
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.
14
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/>. */
17
18 #include "defs.h"
19 #include "target-dcache.h"
20 #include "gdbcmd.h"
21 #include "progspace.h"
22
23 /* The target dcache is kept per-address-space. This key lets us
24 associate the cache with the address space. */
25
26 static const struct address_space_key<DCACHE, dcache_deleter>
27 target_dcache_aspace_key;
28
29 /* Target dcache is initialized or not. */
30
31 int
32 target_dcache_init_p (void)
33 {
34 DCACHE *dcache
35 = target_dcache_aspace_key.get (current_program_space->aspace);
36
37 return (dcache != NULL);
38 }
39
40 /* Invalidate the target dcache. */
41
42 void
43 target_dcache_invalidate (void)
44 {
45 DCACHE *dcache
46 = target_dcache_aspace_key.get (current_program_space->aspace);
47
48 if (dcache != NULL)
49 dcache_invalidate (dcache);
50 }
51
52 /* Return the target dcache. Return NULL if target dcache is not
53 initialized yet. */
54
55 DCACHE *
56 target_dcache_get (void)
57 {
58 return target_dcache_aspace_key.get (current_program_space->aspace);
59 }
60
61 /* Return the target dcache. If it is not initialized yet, initialize
62 it. */
63
64 DCACHE *
65 target_dcache_get_or_init (void)
66 {
67 DCACHE *dcache
68 = target_dcache_aspace_key.get (current_program_space->aspace);
69
70 if (dcache == NULL)
71 {
72 dcache = dcache_init ();
73 target_dcache_aspace_key.set (current_program_space->aspace, dcache);
74 }
75
76 return dcache;
77 }
78
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;
85
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. */
90
91 static void
92 set_stack_cache (const char *args, int from_tty, struct cmd_list_element *c)
93 {
94 if (stack_cache_enabled != stack_cache_enabled_1)
95 target_dcache_invalidate ();
96
97 stack_cache_enabled = stack_cache_enabled_1;
98 }
99
100 static void
101 show_stack_cache (struct ui_file *file, int from_tty,
102 struct cmd_list_element *c, const char *value)
103 {
104 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
105 }
106
107 /* Return true if "stack cache" is enabled, otherwise, return false. */
108
109 int
110 stack_cache_enabled_p (void)
111 {
112 return stack_cache_enabled;
113 }
114
115 /* The option sets this. */
116
117 static bool code_cache_enabled_1 = true;
118
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;
123
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. */
128
129 static void
130 set_code_cache (const char *args, int from_tty, struct cmd_list_element *c)
131 {
132 if (code_cache_enabled != code_cache_enabled_1)
133 target_dcache_invalidate ();
134
135 code_cache_enabled = code_cache_enabled_1;
136 }
137
138 /* Show option "code-cache". */
139
140 static void
141 show_code_cache (struct ui_file *file, int from_tty,
142 struct cmd_list_element *c, const char *value)
143 {
144 fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
145 }
146
147 /* Return true if "code cache" is enabled, otherwise, return false. */
148
149 int
150 code_cache_enabled_p (void)
151 {
152 return code_cache_enabled;
153 }
154
155 void _initialize_target_dcache ();
156 void
157 _initialize_target_dcache ()
158 {
159 add_setshow_boolean_cmd ("stack-cache", class_support,
160 &stack_cache_enabled_1, _("\
161 Set cache use for stack access."), _("\
162 Show cache use for stack access."), _("\
163 When on, use the target memory cache for all stack access, regardless of any\n\
164 configured memory regions. This improves remote performance significantly.\n\
165 By default, caching for stack access is on."),
166 set_stack_cache,
167 show_stack_cache,
168 &setlist, &showlist);
169
170 add_setshow_boolean_cmd ("code-cache", class_support,
171 &code_cache_enabled_1, _("\
172 Set cache use for code segment access."), _("\
173 Show cache use for code segment access."), _("\
174 When on, use the target memory cache for all code segment accesses,\n\
175 regardless of any configured memory regions. This improves remote\n\
176 performance significantly. By default, caching for code segment\n\
177 access is on."),
178 set_code_cache,
179 show_code_cache,
180 &setlist, &showlist);
181 }
This page took 0.032492 seconds and 4 git commands to generate.