1 /* FRV simulator memory option handling.
2 Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 Contributed by Red Hat.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #define WANT_CPU frvbf
21 #define WANT_CPU_FRVBF
24 #include "sim-assert.h"
25 #include "sim-options.h"
30 /* FRV specific command line options. */
33 OPTION_FRV_DATA_CACHE
= OPTION_START
,
34 OPTION_FRV_INSN_CACHE
,
35 OPTION_FRV_PROFILE_CACHE
,
36 OPTION_FRV_PROFILE_PARALLEL
,
38 OPTION_FRV_MEMORY_LATENCY
41 static DECLARE_OPTION_HANDLER (frv_option_handler
);
43 const OPTION frv_options
[] =
45 { {"profile", optional_argument
, NULL
, 'p'},
46 'p', "on|off", "Perform profiling",
48 { {"data-cache", optional_argument
, NULL
, OPTION_FRV_DATA_CACHE
},
49 '\0', "WAYS[,SETS[,LINESIZE]]", "Enable data cache",
51 { {"insn-cache", optional_argument
, NULL
, OPTION_FRV_INSN_CACHE
},
52 '\0', "WAYS[,SETS[,LINESIZE]]", "Enable instruction cache",
54 { {"profile-cache", optional_argument
, NULL
, OPTION_FRV_PROFILE_CACHE
},
55 '\0', "on|off", "Profile caches",
57 { {"profile-parallel", optional_argument
, NULL
, OPTION_FRV_PROFILE_PARALLEL
},
58 '\0', "on|off", "Profile parallelism",
60 { {"timer", required_argument
, NULL
, OPTION_FRV_TIMER
},
61 '\0', "CYCLES,INTERRUPT", "Set Interrupt Timer",
63 { {"memory-latency", required_argument
, NULL
, OPTION_FRV_MEMORY_LATENCY
},
64 '\0', "CYCLES", "Set Latency of memory",
66 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
70 parse_size (char *chp
, address_word
*nr_bytes
)
73 *nr_bytes
= strtoul (chp
, &chp
, 0);
78 check_pow2 (address_word value
, char *argname
, char *optname
, SIM_DESC sd
)
80 if ((value
& (value
- 1)) != 0)
82 sim_io_eprintf (sd
, "%s argument to %s must be a power of 2\n",
84 return 0; /* will enable default value. */
91 parse_cache_option (SIM_DESC sd
, char *arg
, char *cache_name
, int is_data_cache
)
94 address_word ways
= 0, sets
= 0, linesize
= 0;
98 /* parse the arguments */
99 chp
= parse_size (chp
, &ways
);
100 ways
= check_pow2 (ways
, "WAYS", cache_name
, sd
);
103 chp
= parse_size (chp
+ 1, &sets
);
104 sets
= check_pow2 (sets
, "SETS", cache_name
, sd
);
107 chp
= parse_size (chp
+ 1, &linesize
);
108 linesize
= check_pow2 (linesize
, "LINESIZE", cache_name
, sd
);
112 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
114 SIM_CPU
*current_cpu
= STATE_CPU (sd
, i
);
115 FRV_CACHE
*cache
= is_data_cache
? CPU_DATA_CACHE (current_cpu
)
116 : CPU_INSN_CACHE (current_cpu
);
119 cache
->line_size
= linesize
;
120 frv_cache_init (current_cpu
, cache
);
125 frv_option_handler (SIM_DESC sd
, sim_cpu
*current_cpu
, int opt
,
126 char *arg
, int is_command
)
132 sim_io_eprintf (sd
, "Profiling not compiled in, `-p' ignored\n");
135 unsigned mask
= PROFILE_USEFUL_MASK
;
136 if (WITH_PROFILE_CACHE_P
)
137 mask
|= (1 << PROFILE_CACHE_IDX
);
138 if (WITH_PROFILE_PARALLEL_P
)
139 mask
|= (1 << PROFILE_PARALLEL_IDX
);
140 return set_profile_option_mask (sd
, "profile", mask
, arg
);
144 case OPTION_FRV_DATA_CACHE
:
145 parse_cache_option (sd
, arg
, "data_cache", 1/*is_data_cache*/);
148 case OPTION_FRV_INSN_CACHE
:
149 parse_cache_option (sd
, arg
, "insn_cache", 0/*is_data_cache*/);
152 case OPTION_FRV_PROFILE_CACHE
:
153 if (WITH_PROFILE_CACHE_P
)
154 return sim_profile_set_option (sd
, "-cache", PROFILE_CACHE_IDX
, arg
);
156 sim_io_eprintf (sd
, "Cache profiling not compiled in, `--profile-cache' ignored\n");
159 case OPTION_FRV_PROFILE_PARALLEL
:
160 if (WITH_PROFILE_PARALLEL_P
)
163 = (1 << PROFILE_MODEL_IDX
) | (1 << PROFILE_PARALLEL_IDX
);
164 return set_profile_option_mask (sd
, "-parallel", mask
, arg
);
167 sim_io_eprintf (sd
, "Parallel profiling not compiled in, `--profile-parallel' ignored\n");
170 case OPTION_FRV_TIMER
:
173 address_word cycles
, interrupt
;
174 chp
= parse_size (chp
, &cycles
);
177 sim_io_eprintf (sd
, "Cycle count required for --timer\n");
182 sim_io_eprintf (sd
, "Interrupt number required for --timer\n");
185 chp
= parse_size (chp
+ 1, &interrupt
);
186 if (interrupt
< 1 || interrupt
> 15)
188 sim_io_eprintf (sd
, "Interrupt number for --timer must be greater than 0 and less that 16\n");
191 frv_interrupt_state
.timer
.enabled
= 1;
192 frv_interrupt_state
.timer
.value
= cycles
;
193 frv_interrupt_state
.timer
.current
= 0;
194 frv_interrupt_state
.timer
.interrupt
=
195 FRV_INTERRUPT_LEVEL_1
+ interrupt
- 1;
199 case OPTION_FRV_MEMORY_LATENCY
:
204 chp
= parse_size (chp
, &cycles
);
207 sim_io_eprintf (sd
, "Cycle count required for --memory-latency\n");
210 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
212 SIM_CPU
*current_cpu
= STATE_CPU (sd
, i
);
213 FRV_CACHE
*insn_cache
= CPU_INSN_CACHE (current_cpu
);
214 FRV_CACHE
*data_cache
= CPU_DATA_CACHE (current_cpu
);
215 insn_cache
->memory_latency
= cycles
;
216 data_cache
->memory_latency
= cycles
;
222 sim_io_eprintf (sd
, "Unknown FRV option %d\n", opt
);