1 /* Copyright (C) 1992-2013 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
)
37 /* Target dcache is initialized or not. */
40 target_dcache_init_p (void)
42 DCACHE
*dcache
= address_space_data (current_program_space
->aspace
,
43 target_dcache_aspace_key
);
45 return (dcache
!= NULL
);
48 /* Invalidate the target dcache. */
51 target_dcache_invalidate (void)
53 DCACHE
*dcache
= address_space_data (current_program_space
->aspace
,
54 target_dcache_aspace_key
);
57 dcache_invalidate (dcache
);
60 /* Return the target dcache. Return NULL if target dcache is not
64 target_dcache_get (void)
66 DCACHE
*dcache
= address_space_data (current_program_space
->aspace
,
67 target_dcache_aspace_key
);
72 /* Return the target dcache. If it is not initialized yet, initialize
76 target_dcache_get_or_init (void)
78 DCACHE
*dcache
= address_space_data (current_program_space
->aspace
,
79 target_dcache_aspace_key
);
83 dcache
= dcache_init ();
84 set_address_space_data (current_program_space
->aspace
,
85 target_dcache_aspace_key
, dcache
);
91 /* The option sets this. */
92 static int stack_cache_enabled_p_1
= 1;
93 /* And set_stack_cache_enabled_p updates this.
94 The reason for the separation is so that we don't flush the cache for
95 on->on transitions. */
96 static int stack_cache_enabled_p
= 1;
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. */
104 set_stack_cache_enabled_p (char *args
, int from_tty
,
105 struct cmd_list_element
*c
)
107 if (stack_cache_enabled_p
!= stack_cache_enabled_p_1
)
108 target_dcache_invalidate ();
110 stack_cache_enabled_p
= stack_cache_enabled_p_1
;
114 show_stack_cache_enabled_p (struct ui_file
*file
, int from_tty
,
115 struct cmd_list_element
*c
, const char *value
)
117 fprintf_filtered (file
, _("Cache use for stack accesses is %s.\n"), value
);
120 /* Return true if "stack cache" is enabled, otherwise, return false. */
123 stack_cache_enabled (void)
125 return stack_cache_enabled_p
;
128 /* -Wmissing-prototypes */
129 extern initialize_file_ftype _initialize_target_dcache
;
132 _initialize_target_dcache (void)
134 add_setshow_boolean_cmd ("stack-cache", class_support
,
135 &stack_cache_enabled_p_1
, _("\
136 Set cache use for stack access."), _("\
137 Show cache use for stack access."), _("\
138 When on, use the data cache for all stack access, regardless of any\n\
139 configured memory regions. This improves remote performance significantly.\n\
140 By default, caching for stack access is on."),
141 set_stack_cache_enabled_p
,
142 show_stack_cache_enabled_p
,
143 &setlist
, &showlist
);
145 target_dcache_aspace_key
146 = register_address_space_data_with_cleanup (NULL
,
147 target_dcache_cleanup
);