Move target-dcache out of target.c
[deliverable/binutils-gdb.git] / gdb / target-dcache.c
1 /* Copyright (C) 1992-2013 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
22 /* Cache of memory operations, to speed up remote access. */
23 static DCACHE *target_dcache;
24
25 /* Target dcache is initialized or not. */
26
27 int
28 target_dcache_init_p (void)
29 {
30 return (target_dcache != NULL);
31 }
32
33 /* Invalidate the target dcache. */
34
35 void
36 target_dcache_invalidate (void)
37 {
38 if (target_dcache_init_p ())
39 dcache_invalidate (target_dcache);
40 }
41
42 /* Return the target dcache. Return NULL if target dcache is not
43 initialized yet. */
44
45 DCACHE *
46 target_dcache_get (void)
47 {
48 return target_dcache;
49 }
50
51 /* Return the target dcache. If it is not initialized yet, initialize
52 it. */
53
54 DCACHE *
55 target_dcache_get_or_init (void)
56 {
57 if (!target_dcache_init_p ())
58 target_dcache = dcache_init ();
59
60 return target_dcache;
61 }
62
63 /* The option sets this. */
64 static int stack_cache_enabled_p_1 = 1;
65 /* And set_stack_cache_enabled_p updates this.
66 The reason for the separation is so that we don't flush the cache for
67 on->on transitions. */
68 static int stack_cache_enabled_p = 1;
69
70 /* This is called *after* the stack-cache has been set.
71 Flush the cache for off->on and on->off transitions.
72 There's no real need to flush the cache for on->off transitions,
73 except cleanliness. */
74
75 static void
76 set_stack_cache_enabled_p (char *args, int from_tty,
77 struct cmd_list_element *c)
78 {
79 if (stack_cache_enabled_p != stack_cache_enabled_p_1)
80 target_dcache_invalidate ();
81
82 stack_cache_enabled_p = stack_cache_enabled_p_1;
83 }
84
85 static void
86 show_stack_cache_enabled_p (struct ui_file *file, int from_tty,
87 struct cmd_list_element *c, const char *value)
88 {
89 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
90 }
91
92 /* Return true if "stack cache" is enabled, otherwise, return false. */
93
94 int
95 stack_cache_enabled (void)
96 {
97 return stack_cache_enabled_p;
98 }
99
100 /* -Wmissing-prototypes */
101 extern initialize_file_ftype _initialize_target_dcache;
102
103 void
104 _initialize_target_dcache (void)
105 {
106 add_setshow_boolean_cmd ("stack-cache", class_support,
107 &stack_cache_enabled_p_1, _("\
108 Set cache use for stack access."), _("\
109 Show cache use for stack access."), _("\
110 When on, use the data cache for all stack access, regardless of any\n\
111 configured memory regions. This improves remote performance significantly.\n\
112 By default, caching for stack access is on."),
113 set_stack_cache_enabled_p,
114 show_stack_cache_enabled_p,
115 &setlist, &showlist);
116 }
This page took 0.163698 seconds and 4 git commands to generate.