]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/target-dcache.c
Revise signal mapping function in GDB interface for RX sim.
[thirdparty/binutils-gdb.git] / gdb / target-dcache.c
CommitLineData
ecd75fc8 1/* Copyright (C) 1992-2014 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
26static const struct address_space_data *target_dcache_aspace_key;
27
28/* Clean up dcache, represented by ARG, which is associated with
29 ASPACE. */
30
31static void
32target_dcache_cleanup (struct address_space *aspace, void *arg)
33{
34 dcache_free (arg);
35}
68c765e2
YQ
36
37/* Target dcache is initialized or not. */
38
39int
40target_dcache_init_p (void)
41{
b26dfc9a
YQ
42 DCACHE *dcache = address_space_data (current_program_space->aspace,
43 target_dcache_aspace_key);
44
45 return (dcache != NULL);
68c765e2
YQ
46}
47
48/* Invalidate the target dcache. */
49
50void
51target_dcache_invalidate (void)
52{
b26dfc9a
YQ
53 DCACHE *dcache = address_space_data (current_program_space->aspace,
54 target_dcache_aspace_key);
55
56 if (dcache != NULL)
57 dcache_invalidate (dcache);
68c765e2
YQ
58}
59
60/* Return the target dcache. Return NULL if target dcache is not
61 initialized yet. */
62
63DCACHE *
64target_dcache_get (void)
65{
b26dfc9a
YQ
66 DCACHE *dcache = address_space_data (current_program_space->aspace,
67 target_dcache_aspace_key);
68
69 return dcache;
68c765e2
YQ
70}
71
72/* Return the target dcache. If it is not initialized yet, initialize
73 it. */
74
75DCACHE *
76target_dcache_get_or_init (void)
77{
b26dfc9a
YQ
78 DCACHE *dcache = address_space_data (current_program_space->aspace,
79 target_dcache_aspace_key);
68c765e2 80
b26dfc9a 81 if (dcache == NULL)
6b1141e3
YQ
82 {
83 dcache = dcache_init ();
84 set_address_space_data (current_program_space->aspace,
85 target_dcache_aspace_key, dcache);
86 }
b26dfc9a
YQ
87
88 return dcache;
68c765e2
YQ
89}
90
91/* The option sets this. */
0fb14d8f
YQ
92static int stack_cache_enabled_1 = 1;
93/* And set_stack_cache updates this.
68c765e2
YQ
94 The reason for the separation is so that we don't flush the cache for
95 on->on transitions. */
0fb14d8f 96static int stack_cache_enabled = 1;
68c765e2
YQ
97
98/* This is called *after* the stack-cache has been set.
99 Flush the cache for off->on and on->off transitions.
100 There's no real need to flush the cache for on->off transitions,
101 except cleanliness. */
102
103static void
0fb14d8f 104set_stack_cache (char *args, int from_tty, struct cmd_list_element *c)
68c765e2 105{
0fb14d8f 106 if (stack_cache_enabled != stack_cache_enabled_1)
68c765e2
YQ
107 target_dcache_invalidate ();
108
0fb14d8f 109 stack_cache_enabled = stack_cache_enabled_1;
68c765e2
YQ
110}
111
112static void
0fb14d8f
YQ
113show_stack_cache (struct ui_file *file, int from_tty,
114 struct cmd_list_element *c, const char *value)
68c765e2
YQ
115{
116 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
117}
118
119/* Return true if "stack cache" is enabled, otherwise, return false. */
120
121int
0fb14d8f 122stack_cache_enabled_p (void)
68c765e2 123{
0fb14d8f 124 return stack_cache_enabled;
68c765e2
YQ
125}
126
29453a14
YQ
127/* The option sets this. */
128
129static int code_cache_enabled_1 = 1;
130
131/* And set_code_cache updates this.
132 The reason for the separation is so that we don't flush the cache for
133 on->on transitions. */
134static int code_cache_enabled = 1;
135
136/* This is called *after* the code-cache has been set.
137 Flush the cache for off->on and on->off transitions.
138 There's no real need to flush the cache for on->off transitions,
139 except cleanliness. */
140
141static void
142set_code_cache (char *args, int from_tty, struct cmd_list_element *c)
143{
144 if (code_cache_enabled != code_cache_enabled_1)
145 target_dcache_invalidate ();
146
147 code_cache_enabled = code_cache_enabled_1;
148}
149
150/* Show option "code-cache". */
151
152static void
153show_code_cache (struct ui_file *file, int from_tty,
154 struct cmd_list_element *c, const char *value)
155{
156 fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
157}
158
159/* Return true if "code cache" is enabled, otherwise, return false. */
160
161int
162code_cache_enabled_p (void)
163{
164 return code_cache_enabled;
165}
166
68c765e2
YQ
167/* -Wmissing-prototypes */
168extern initialize_file_ftype _initialize_target_dcache;
169
170void
171_initialize_target_dcache (void)
172{
173 add_setshow_boolean_cmd ("stack-cache", class_support,
0fb14d8f 174 &stack_cache_enabled_1, _("\
68c765e2
YQ
175Set cache use for stack access."), _("\
176Show cache use for stack access."), _("\
0fb14d8f 177When on, use the target memory cache for all stack access, regardless of any\n\
68c765e2
YQ
178configured memory regions. This improves remote performance significantly.\n\
179By default, caching for stack access is on."),
0fb14d8f
YQ
180 set_stack_cache,
181 show_stack_cache,
68c765e2 182 &setlist, &showlist);
b26dfc9a 183
29453a14
YQ
184 add_setshow_boolean_cmd ("code-cache", class_support,
185 &code_cache_enabled_1, _("\
186Set cache use for code segment access."), _("\
187Show cache use for code segment access."), _("\
188When on, use the target memory cache for all code segment accesses,\n\
189regardless of any configured memory regions. This improves remote\n\
190performance significantly. By default, caching for code segment\n\
191access is on."),
192 set_code_cache,
193 show_code_cache,
194 &setlist, &showlist);
195
b26dfc9a
YQ
196 target_dcache_aspace_key
197 = register_address_space_data_with_cleanup (NULL,
198 target_dcache_cleanup);
68c765e2 199}