1 /* FRV simulator memory option handling.
2 Copyright (C) 1999, 2000 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 2, or (at your option)
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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #define WANT_CPU frvbf
22 #define WANT_CPU_FRVBF
25 #include "sim-assert.h"
26 #include "sim-options.h"
39 /* FRV specific command line options. */
42 OPTION_FRV_DATA_CACHE
= OPTION_START
,
43 OPTION_FRV_INSN_CACHE
,
44 OPTION_FRV_PROFILE_CACHE
,
45 OPTION_FRV_PROFILE_PARALLEL
,
47 OPTION_FRV_MEMORY_LATENCY
50 static DECLARE_OPTION_HANDLER (frv_option_handler
);
52 const OPTION frv_options
[] =
54 { {"profile", optional_argument
, NULL
, 'p'},
55 'p', "on|off", "Perform profiling",
57 { {"data-cache", optional_argument
, NULL
, OPTION_FRV_DATA_CACHE
},
58 '\0', "WAYS[,SETS[,LINESIZE]]", "Enable data cache",
60 { {"insn-cache", optional_argument
, NULL
, OPTION_FRV_INSN_CACHE
},
61 '\0', "WAYS[,SETS[,LINESIZE]]", "Enable instruction cache",
63 { {"profile-cache", optional_argument
, NULL
, OPTION_FRV_PROFILE_CACHE
},
64 '\0', "on|off", "Profile caches",
66 { {"profile-parallel", optional_argument
, NULL
, OPTION_FRV_PROFILE_PARALLEL
},
67 '\0', "on|off", "Profile parallelism",
69 { {"timer", required_argument
, NULL
, OPTION_FRV_TIMER
},
70 '\0', "CYCLES,INTERRUPT", "Set Interrupt Timer",
72 { {"memory-latency", required_argument
, NULL
, OPTION_FRV_MEMORY_LATENCY
},
73 '\0', "CYCLES", "Set Latency of memory",
75 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
79 parse_size (char *chp
, address_word
*nr_bytes
)
82 *nr_bytes
= strtoul (chp
, &chp
, 0);
87 check_pow2 (address_word value
, char *argname
, char *optname
, SIM_DESC sd
)
89 if ((value
& (value
- 1)) != 0)
91 sim_io_eprintf (sd
, "%s argument to %s must be a power of 2\n",
93 return 0; /* will enable default value. */
100 parse_cache_option (SIM_DESC sd
, char *arg
, char *cache_name
, int is_data_cache
)
103 address_word ways
= 0, sets
= 0, linesize
= 0;
107 /* parse the arguments */
108 chp
= parse_size (chp
, &ways
);
109 ways
= check_pow2 (ways
, "WAYS", cache_name
, sd
);
112 chp
= parse_size (chp
+ 1, &sets
);
113 sets
= check_pow2 (sets
, "SETS", cache_name
, sd
);
116 chp
= parse_size (chp
+ 1, &linesize
);
117 linesize
= check_pow2 (linesize
, "LINESIZE", cache_name
, sd
);
121 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
123 SIM_CPU
*current_cpu
= STATE_CPU (sd
, i
);
124 FRV_CACHE
*cache
= is_data_cache
? CPU_DATA_CACHE (current_cpu
)
125 : CPU_INSN_CACHE (current_cpu
);
128 cache
->line_size
= linesize
;
129 frv_cache_init (current_cpu
, cache
);
134 frv_option_handler (SIM_DESC sd
, sim_cpu
*current_cpu
, int opt
,
135 char *arg
, int is_command
)
141 sim_io_eprintf (sd
, "Profiling not compiled in, `-p' ignored\n");
144 unsigned mask
= PROFILE_USEFUL_MASK
;
145 if (WITH_PROFILE_CACHE_P
)
146 mask
|= (1 << PROFILE_CACHE_IDX
);
147 if (WITH_PROFILE_PARALLEL_P
)
148 mask
|= (1 << PROFILE_PARALLEL_IDX
);
149 return set_profile_option_mask (sd
, "profile", mask
, arg
);
153 case OPTION_FRV_DATA_CACHE
:
154 parse_cache_option (sd
, arg
, "data_cache", 1/*is_data_cache*/);
157 case OPTION_FRV_INSN_CACHE
:
158 parse_cache_option (sd
, arg
, "insn_cache", 0/*is_data_cache*/);
161 case OPTION_FRV_PROFILE_CACHE
:
162 if (WITH_PROFILE_CACHE_P
)
163 return sim_profile_set_option (sd
, "-cache", PROFILE_CACHE_IDX
, arg
);
165 sim_io_eprintf (sd
, "Cache profiling not compiled in, `--profile-cache' ignored\n");
168 case OPTION_FRV_PROFILE_PARALLEL
:
169 if (WITH_PROFILE_PARALLEL_P
)
172 = (1 << PROFILE_MODEL_IDX
) | (1 << PROFILE_PARALLEL_IDX
);
173 return set_profile_option_mask (sd
, "-parallel", mask
, arg
);
176 sim_io_eprintf (sd
, "Parallel profiling not compiled in, `--profile-parallel' ignored\n");
179 case OPTION_FRV_TIMER
:
182 address_word cycles
, interrupt
;
183 chp
= parse_size (chp
, &cycles
);
186 sim_io_eprintf (sd
, "Cycle count required for --timer\n");
191 sim_io_eprintf (sd
, "Interrupt number required for --timer\n");
194 chp
= parse_size (chp
+ 1, &interrupt
);
195 if (interrupt
< 1 || interrupt
> 15)
197 sim_io_eprintf (sd
, "Interrupt number for --timer must be greater than 0 and less that 16\n");
200 frv_interrupt_state
.timer
.enabled
= 1;
201 frv_interrupt_state
.timer
.value
= cycles
;
202 frv_interrupt_state
.timer
.current
= 0;
203 frv_interrupt_state
.timer
.interrupt
=
204 FRV_INTERRUPT_LEVEL_1
+ interrupt
- 1;
208 case OPTION_FRV_MEMORY_LATENCY
:
213 chp
= parse_size (chp
, &cycles
);
216 sim_io_eprintf (sd
, "Cycle count required for --memory-latency\n");
219 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
221 SIM_CPU
*current_cpu
= STATE_CPU (sd
, i
);
222 FRV_CACHE
*insn_cache
= CPU_INSN_CACHE (current_cpu
);
223 FRV_CACHE
*data_cache
= CPU_DATA_CACHE (current_cpu
);
224 insn_cache
->memory_latency
= cycles
;
225 data_cache
->memory_latency
= cycles
;
231 sim_io_eprintf (sd
, "Unknown FRV option %d\n", opt
);