gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / target-dcache.c
CommitLineData
b811d2c2 1/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
68c765e2
YQ
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"
b26dfc9a 21#include "progspace.h"
68c765e2 22
b26dfc9a
YQ
23/* The target dcache is kept per-address-space. This key lets us
24 associate the cache with the address space. */
25
35632941
TT
26static const struct address_space_key<DCACHE, dcache_deleter>
27 target_dcache_aspace_key;
68c765e2
YQ
28
29/* Target dcache is initialized or not. */
30
31int
32target_dcache_init_p (void)
33{
19ba03f4 34 DCACHE *dcache
35632941 35 = target_dcache_aspace_key.get (current_program_space->aspace);
b26dfc9a
YQ
36
37 return (dcache != NULL);
68c765e2
YQ
38}
39
40/* Invalidate the target dcache. */
41
42void
43target_dcache_invalidate (void)
44{
19ba03f4 45 DCACHE *dcache
35632941 46 = target_dcache_aspace_key.get (current_program_space->aspace);
b26dfc9a
YQ
47
48 if (dcache != NULL)
49 dcache_invalidate (dcache);
68c765e2
YQ
50}
51
52/* Return the target dcache. Return NULL if target dcache is not
53 initialized yet. */
54
55DCACHE *
56target_dcache_get (void)
57{
35632941 58 return target_dcache_aspace_key.get (current_program_space->aspace);
68c765e2
YQ
59}
60
61/* Return the target dcache. If it is not initialized yet, initialize
62 it. */
63
64DCACHE *
65target_dcache_get_or_init (void)
66{
19ba03f4 67 DCACHE *dcache
35632941 68 = target_dcache_aspace_key.get (current_program_space->aspace);
68c765e2 69
b26dfc9a 70 if (dcache == NULL)
6b1141e3
YQ
71 {
72 dcache = dcache_init ();
35632941 73 target_dcache_aspace_key.set (current_program_space->aspace, dcache);
6b1141e3 74 }
b26dfc9a
YQ
75
76 return dcache;
68c765e2
YQ
77}
78
79/* The option sets this. */
491144b5 80static bool stack_cache_enabled_1 = true;
0fb14d8f 81/* And set_stack_cache updates this.
68c765e2
YQ
82 The reason for the separation is so that we don't flush the cache for
83 on->on transitions. */
0fb14d8f 84static int stack_cache_enabled = 1;
68c765e2
YQ
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
91static void
eb4c3f4a 92set_stack_cache (const char *args, int from_tty, struct cmd_list_element *c)
68c765e2 93{
0fb14d8f 94 if (stack_cache_enabled != stack_cache_enabled_1)
68c765e2
YQ
95 target_dcache_invalidate ();
96
0fb14d8f 97 stack_cache_enabled = stack_cache_enabled_1;
68c765e2
YQ
98}
99
100static void
0fb14d8f
YQ
101show_stack_cache (struct ui_file *file, int from_tty,
102 struct cmd_list_element *c, const char *value)
68c765e2
YQ
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
109int
0fb14d8f 110stack_cache_enabled_p (void)
68c765e2 111{
0fb14d8f 112 return stack_cache_enabled;
68c765e2
YQ
113}
114
29453a14
YQ
115/* The option sets this. */
116
491144b5 117static bool code_cache_enabled_1 = true;
29453a14
YQ
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. */
122static 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
129static void
eb4c3f4a 130set_code_cache (const char *args, int from_tty, struct cmd_list_element *c)
29453a14
YQ
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
140static void
141show_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
149int
150code_cache_enabled_p (void)
151{
152 return code_cache_enabled;
153}
154
6c265988 155void _initialize_target_dcache ();
68c765e2 156void
6c265988 157_initialize_target_dcache ()
68c765e2
YQ
158{
159 add_setshow_boolean_cmd ("stack-cache", class_support,
0fb14d8f 160 &stack_cache_enabled_1, _("\
68c765e2
YQ
161Set cache use for stack access."), _("\
162Show cache use for stack access."), _("\
0fb14d8f 163When on, use the target memory cache for all stack access, regardless of any\n\
68c765e2
YQ
164configured memory regions. This improves remote performance significantly.\n\
165By default, caching for stack access is on."),
0fb14d8f
YQ
166 set_stack_cache,
167 show_stack_cache,
68c765e2 168 &setlist, &showlist);
b26dfc9a 169
29453a14
YQ
170 add_setshow_boolean_cmd ("code-cache", class_support,
171 &code_cache_enabled_1, _("\
172Set cache use for code segment access."), _("\
173Show cache use for code segment access."), _("\
174When on, use the target memory cache for all code segment accesses,\n\
175regardless of any configured memory regions. This improves remote\n\
176performance significantly. By default, caching for code segment\n\
177access is on."),
178 set_code_cache,
179 show_code_cache,
180 &setlist, &showlist);
68c765e2 181}
This page took 0.782947 seconds and 4 git commands to generate.