options.c revision 1.1 1 1.1 christos /* FRV simulator memory option handling.
2 1.1 christos Copyright (C) 1999-2014 Free Software Foundation, Inc.
3 1.1 christos Contributed by Red Hat.
4 1.1 christos
5 1.1 christos This file is part of GDB, the GNU debugger.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #define WANT_CPU frvbf
21 1.1 christos #define WANT_CPU_FRVBF
22 1.1 christos
23 1.1 christos #include "sim-main.h"
24 1.1 christos #include "sim-assert.h"
25 1.1 christos #include "sim-options.h"
26 1.1 christos
27 1.1 christos #ifdef HAVE_STRING_H
28 1.1 christos #include <string.h>
29 1.1 christos #else
30 1.1 christos #ifdef HAVE_STRINGS_H
31 1.1 christos #include <strings.h>
32 1.1 christos #endif
33 1.1 christos #endif
34 1.1 christos #ifdef HAVE_STDLIB_H
35 1.1 christos #include <stdlib.h>
36 1.1 christos #endif
37 1.1 christos
38 1.1 christos /* FRV specific command line options. */
39 1.1 christos
40 1.1 christos enum {
41 1.1 christos OPTION_FRV_DATA_CACHE = OPTION_START,
42 1.1 christos OPTION_FRV_INSN_CACHE,
43 1.1 christos OPTION_FRV_PROFILE_CACHE,
44 1.1 christos OPTION_FRV_PROFILE_PARALLEL,
45 1.1 christos OPTION_FRV_TIMER,
46 1.1 christos OPTION_FRV_MEMORY_LATENCY
47 1.1 christos };
48 1.1 christos
49 1.1 christos static DECLARE_OPTION_HANDLER (frv_option_handler);
50 1.1 christos
51 1.1 christos const OPTION frv_options[] =
52 1.1 christos {
53 1.1 christos { {"profile", optional_argument, NULL, 'p'},
54 1.1 christos 'p', "on|off", "Perform profiling",
55 1.1 christos frv_option_handler },
56 1.1 christos { {"data-cache", optional_argument, NULL, OPTION_FRV_DATA_CACHE },
57 1.1 christos '\0', "WAYS[,SETS[,LINESIZE]]", "Enable data cache",
58 1.1 christos frv_option_handler },
59 1.1 christos { {"insn-cache", optional_argument, NULL, OPTION_FRV_INSN_CACHE },
60 1.1 christos '\0', "WAYS[,SETS[,LINESIZE]]", "Enable instruction cache",
61 1.1 christos frv_option_handler },
62 1.1 christos { {"profile-cache", optional_argument, NULL, OPTION_FRV_PROFILE_CACHE },
63 1.1 christos '\0', "on|off", "Profile caches",
64 1.1 christos frv_option_handler },
65 1.1 christos { {"profile-parallel", optional_argument, NULL, OPTION_FRV_PROFILE_PARALLEL },
66 1.1 christos '\0', "on|off", "Profile parallelism",
67 1.1 christos frv_option_handler },
68 1.1 christos { {"timer", required_argument, NULL, OPTION_FRV_TIMER },
69 1.1 christos '\0', "CYCLES,INTERRUPT", "Set Interrupt Timer",
70 1.1 christos frv_option_handler },
71 1.1 christos { {"memory-latency", required_argument, NULL, OPTION_FRV_MEMORY_LATENCY },
72 1.1 christos '\0', "CYCLES", "Set Latency of memory",
73 1.1 christos frv_option_handler },
74 1.1 christos { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
75 1.1 christos };
76 1.1 christos
77 1.1 christos static char *
78 1.1 christos parse_size (char *chp, address_word *nr_bytes)
79 1.1 christos {
80 1.1 christos /* <nr_bytes> */
81 1.1 christos *nr_bytes = strtoul (chp, &chp, 0);
82 1.1 christos return chp;
83 1.1 christos }
84 1.1 christos
85 1.1 christos static address_word
86 1.1 christos check_pow2 (address_word value, char *argname, char *optname, SIM_DESC sd)
87 1.1 christos {
88 1.1 christos if ((value & (value - 1)) != 0)
89 1.1 christos {
90 1.1 christos sim_io_eprintf (sd, "%s argument to %s must be a power of 2\n",
91 1.1 christos argname, optname);
92 1.1 christos return 0; /* will enable default value. */
93 1.1 christos }
94 1.1 christos
95 1.1 christos return value;
96 1.1 christos }
97 1.1 christos
98 1.1 christos static void
99 1.1 christos parse_cache_option (SIM_DESC sd, char *arg, char *cache_name, int is_data_cache)
100 1.1 christos {
101 1.1 christos int i;
102 1.1 christos address_word ways = 0, sets = 0, linesize = 0;
103 1.1 christos if (arg != NULL)
104 1.1 christos {
105 1.1 christos char *chp = arg;
106 1.1 christos /* parse the arguments */
107 1.1 christos chp = parse_size (chp, &ways);
108 1.1 christos ways = check_pow2 (ways, "WAYS", cache_name, sd);
109 1.1 christos if (*chp == ',')
110 1.1 christos {
111 1.1 christos chp = parse_size (chp + 1, &sets);
112 1.1 christos sets = check_pow2 (sets, "SETS", cache_name, sd);
113 1.1 christos if (*chp == ',')
114 1.1 christos {
115 1.1 christos chp = parse_size (chp + 1, &linesize);
116 1.1 christos linesize = check_pow2 (linesize, "LINESIZE", cache_name, sd);
117 1.1 christos }
118 1.1 christos }
119 1.1 christos }
120 1.1 christos for (i = 0; i < MAX_NR_PROCESSORS; ++i)
121 1.1 christos {
122 1.1 christos SIM_CPU *current_cpu = STATE_CPU (sd, i);
123 1.1 christos FRV_CACHE *cache = is_data_cache ? CPU_DATA_CACHE (current_cpu)
124 1.1 christos : CPU_INSN_CACHE (current_cpu);
125 1.1 christos cache->ways = ways;
126 1.1 christos cache->sets = sets;
127 1.1 christos cache->line_size = linesize;
128 1.1 christos frv_cache_init (current_cpu, cache);
129 1.1 christos }
130 1.1 christos }
131 1.1 christos
132 1.1 christos static SIM_RC
133 1.1 christos frv_option_handler (SIM_DESC sd, sim_cpu *current_cpu, int opt,
134 1.1 christos char *arg, int is_command)
135 1.1 christos {
136 1.1 christos switch (opt)
137 1.1 christos {
138 1.1 christos case 'p' :
139 1.1 christos if (! WITH_PROFILE)
140 1.1 christos sim_io_eprintf (sd, "Profiling not compiled in, `-p' ignored\n");
141 1.1 christos else
142 1.1 christos {
143 1.1 christos unsigned mask = PROFILE_USEFUL_MASK;
144 1.1 christos if (WITH_PROFILE_CACHE_P)
145 1.1 christos mask |= (1 << PROFILE_CACHE_IDX);
146 1.1 christos if (WITH_PROFILE_PARALLEL_P)
147 1.1 christos mask |= (1 << PROFILE_PARALLEL_IDX);
148 1.1 christos return set_profile_option_mask (sd, "profile", mask, arg);
149 1.1 christos }
150 1.1 christos break;
151 1.1 christos
152 1.1 christos case OPTION_FRV_DATA_CACHE:
153 1.1 christos parse_cache_option (sd, arg, "data_cache", 1/*is_data_cache*/);
154 1.1 christos return SIM_RC_OK;
155 1.1 christos
156 1.1 christos case OPTION_FRV_INSN_CACHE:
157 1.1 christos parse_cache_option (sd, arg, "insn_cache", 0/*is_data_cache*/);
158 1.1 christos return SIM_RC_OK;
159 1.1 christos
160 1.1 christos case OPTION_FRV_PROFILE_CACHE:
161 1.1 christos if (WITH_PROFILE_CACHE_P)
162 1.1 christos return sim_profile_set_option (sd, "-cache", PROFILE_CACHE_IDX, arg);
163 1.1 christos else
164 1.1 christos sim_io_eprintf (sd, "Cache profiling not compiled in, `--profile-cache' ignored\n");
165 1.1 christos break;
166 1.1 christos
167 1.1 christos case OPTION_FRV_PROFILE_PARALLEL:
168 1.1 christos if (WITH_PROFILE_PARALLEL_P)
169 1.1 christos {
170 1.1 christos unsigned mask
171 1.1 christos = (1 << PROFILE_MODEL_IDX) | (1 << PROFILE_PARALLEL_IDX);
172 1.1 christos return set_profile_option_mask (sd, "-parallel", mask, arg);
173 1.1 christos }
174 1.1 christos else
175 1.1 christos sim_io_eprintf (sd, "Parallel profiling not compiled in, `--profile-parallel' ignored\n");
176 1.1 christos break;
177 1.1 christos
178 1.1 christos case OPTION_FRV_TIMER:
179 1.1 christos {
180 1.1 christos char *chp = arg;
181 1.1 christos address_word cycles, interrupt;
182 1.1 christos chp = parse_size (chp, &cycles);
183 1.1 christos if (chp == arg)
184 1.1 christos {
185 1.1 christos sim_io_eprintf (sd, "Cycle count required for --timer\n");
186 1.1 christos return SIM_RC_FAIL;
187 1.1 christos }
188 1.1 christos if (*chp != ',')
189 1.1 christos {
190 1.1 christos sim_io_eprintf (sd, "Interrupt number required for --timer\n");
191 1.1 christos return SIM_RC_FAIL;
192 1.1 christos }
193 1.1 christos chp = parse_size (chp + 1, &interrupt);
194 1.1 christos if (interrupt < 1 || interrupt > 15)
195 1.1 christos {
196 1.1 christos sim_io_eprintf (sd, "Interrupt number for --timer must be greater than 0 and less that 16\n");
197 1.1 christos return SIM_RC_FAIL;
198 1.1 christos }
199 1.1 christos frv_interrupt_state.timer.enabled = 1;
200 1.1 christos frv_interrupt_state.timer.value = cycles;
201 1.1 christos frv_interrupt_state.timer.current = 0;
202 1.1 christos frv_interrupt_state.timer.interrupt =
203 1.1 christos FRV_INTERRUPT_LEVEL_1 + interrupt - 1;
204 1.1 christos }
205 1.1 christos return SIM_RC_OK;
206 1.1 christos
207 1.1 christos case OPTION_FRV_MEMORY_LATENCY:
208 1.1 christos {
209 1.1 christos int i;
210 1.1 christos char *chp = arg;
211 1.1 christos address_word cycles;
212 1.1 christos chp = parse_size (chp, &cycles);
213 1.1 christos if (chp == arg)
214 1.1 christos {
215 1.1 christos sim_io_eprintf (sd, "Cycle count required for --memory-latency\n");
216 1.1 christos return SIM_RC_FAIL;
217 1.1 christos }
218 1.1 christos for (i = 0; i < MAX_NR_PROCESSORS; ++i)
219 1.1 christos {
220 1.1 christos SIM_CPU *current_cpu = STATE_CPU (sd, i);
221 1.1 christos FRV_CACHE *insn_cache = CPU_INSN_CACHE (current_cpu);
222 1.1 christos FRV_CACHE *data_cache = CPU_DATA_CACHE (current_cpu);
223 1.1 christos insn_cache->memory_latency = cycles;
224 1.1 christos data_cache->memory_latency = cycles;
225 1.1 christos }
226 1.1 christos }
227 1.1 christos return SIM_RC_OK;
228 1.1 christos
229 1.1 christos default:
230 1.1 christos sim_io_eprintf (sd, "Unknown FRV option %d\n", opt);
231 1.1 christos return SIM_RC_FAIL;
232 1.1 christos
233 1.1 christos }
234 1.1 christos
235 1.1 christos return SIM_RC_FAIL;
236 1.1 christos }
237