1 /* collection of junk waiting time to sort out
2 Copyright (C) 1998, 1999, 2000, 2001, 2003, 2007
3 Free Software Foundation, Inc.
6 This file is part of the GNU Simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "sim-options.h"
26 /* True if SPR is the number of accumulator or accumulator guard register. */
27 #define SPR_IS_ACC(SPR) ((SPR) >= 1408 && (SPR) <= 1535)
29 /* Initialization of the frv cpu. */
30 void frv_initialize (SIM_CPU *, SIM_DESC);
31 void frv_term (SIM_DESC);
32 void frv_power_on_reset (SIM_CPU *);
33 void frv_hardware_reset (SIM_CPU *);
34 void frv_software_reset (SIM_CPU *);
36 /* The reset register. See FRV LSI section 10.3.1 */
37 #define RSTR_ADDRESS 0xfeff0500
38 #define RSTR_INITIAL_VALUE 0x00000400
39 #define RSTR_HARDWARE_RESET 0x00000200
40 #define RSTR_SOFTWARE_RESET 0x00000100
42 #define GET_RSTR_HR(rstr) (((rstr) >> 1) & 1)
43 #define GET_RSTR_SR(rstr) (((rstr) ) & 1)
45 #define SET_RSTR_H(rstr) ((rstr) |= (1 << 9))
46 #define SET_RSTR_S(rstr) ((rstr) |= (1 << 8))
48 #define CLEAR_RSTR_P(rstr) ((rstr) &= ~(1 << 10))
49 #define CLEAR_RSTR_H(rstr) ((rstr) &= ~(1 << 9))
50 #define CLEAR_RSTR_S(rstr) ((rstr) &= ~(1 << 8))
51 #define CLEAR_RSTR_HR(rstr) ((rstr) &= ~(1 << 1))
52 #define CLEAR_RSTR_SR(rstr) ((rstr) &= ~1)
54 /* Cutomized hardware get/set functions. */
55 extern USI frvbf_h_spr_get_handler (SIM_CPU *, UINT);
56 extern void frvbf_h_spr_set_handler (SIM_CPU *, UINT, USI);
57 extern USI frvbf_h_gr_get_handler (SIM_CPU *, UINT);
58 extern void frvbf_h_gr_set_handler (SIM_CPU *, UINT, USI);
59 extern UHI frvbf_h_gr_hi_get_handler (SIM_CPU *, UINT);
60 extern void frvbf_h_gr_hi_set_handler (SIM_CPU *, UINT, UHI);
61 extern UHI frvbf_h_gr_lo_get_handler (SIM_CPU *, UINT);
62 extern void frvbf_h_gr_lo_set_handler (SIM_CPU *, UINT, UHI);
63 extern DI frvbf_h_gr_double_get_handler (SIM_CPU *, UINT);
64 extern void frvbf_h_gr_double_set_handler (SIM_CPU *, UINT, DI);
65 extern SF frvbf_h_fr_get_handler (SIM_CPU *, UINT);
66 extern void frvbf_h_fr_set_handler (SIM_CPU *, UINT, SF);
67 extern DF frvbf_h_fr_double_get_handler (SIM_CPU *, UINT);
68 extern void frvbf_h_fr_double_set_handler (SIM_CPU *, UINT, DF);
69 extern USI frvbf_h_fr_int_get_handler (SIM_CPU *, UINT);
70 extern void frvbf_h_fr_int_set_handler (SIM_CPU *, UINT, USI);
71 extern DI frvbf_h_cpr_double_get_handler (SIM_CPU *, UINT);
72 extern void frvbf_h_cpr_double_set_handler (SIM_CPU *, UINT, DI);
73 extern void frvbf_h_gr_quad_set_handler (SIM_CPU *, UINT, SI *);
74 extern void frvbf_h_fr_quad_set_handler (SIM_CPU *, UINT, SI *);
75 extern void frvbf_h_cpr_quad_set_handler (SIM_CPU *, UINT, SI *);
76 extern void frvbf_h_psr_s_set_handler (SIM_CPU *, BI);
78 extern USI spr_psr_get_handler (SIM_CPU *);
79 extern void spr_psr_set_handler (SIM_CPU *, USI);
80 extern USI spr_tbr_get_handler (SIM_CPU *);
81 extern void spr_tbr_set_handler (SIM_CPU *, USI);
82 extern USI spr_bpsr_get_handler (SIM_CPU *);
83 extern void spr_bpsr_set_handler (SIM_CPU *, USI);
84 extern USI spr_ccr_get_handler (SIM_CPU *);
85 extern void spr_ccr_set_handler (SIM_CPU *, USI);
86 extern void spr_cccr_set_handler (SIM_CPU *, USI);
87 extern USI spr_cccr_get_handler (SIM_CPU *);
88 extern USI spr_isr_get_handler (SIM_CPU *);
89 extern void spr_isr_set_handler (SIM_CPU *, USI);
90 extern USI spr_sr_get_handler (SIM_CPU *, UINT);
91 extern void spr_sr_set_handler (SIM_CPU *, UINT, USI);
93 extern void frvbf_switch_supervisor_user_context (SIM_CPU *);
95 extern QI frvbf_set_icc_for_shift_left (SIM_CPU *, SI, SI, QI);
96 extern QI frvbf_set_icc_for_shift_right (SIM_CPU *, SI, SI, QI);
99 extern void frvbf_signed_integer_divide (SIM_CPU *, SI, SI, int, int);
100 extern void frvbf_unsigned_integer_divide (SIM_CPU *, USI, USI, int, int);
101 extern SI frvbf_shift_left_arith_saturate (SIM_CPU *, SI, SI);
102 extern SI frvbf_iacc_cut (SIM_CPU *, DI, SI);
104 extern void frvbf_clear_accumulators (SIM_CPU *, SI, int);
106 extern SI frvbf_scan_result (SIM_CPU *, SI);
107 extern SI frvbf_cut (SIM_CPU *, SI, SI, SI);
108 extern SI frvbf_media_cut (SIM_CPU *, DI, SI);
109 extern SI frvbf_media_cut_ss (SIM_CPU *, DI, SI);
110 extern void frvbf_media_cop (SIM_CPU *, int);
111 extern UQI frvbf_cr_logic (SIM_CPU *, SI, UQI, UQI);
113 extern void frvbf_set_write_next_vliw_addr_to_LR (SIM_CPU *, int);
114 extern int frvbf_write_next_vliw_addr_to_LR;
116 extern void frvbf_set_ne_index (SIM_CPU *, int);
117 extern void frvbf_force_update (SIM_CPU *);
119 #define GETTWI GETTSI
120 #define SETTWI SETTSI
123 /* Hardware/device support.
124 ??? Will eventually want to move device stuff to config files. */
126 /* Support for the MCCR register (Cache Control Register) is needed in order
127 for overlays to work correctly with the scache: cached instructions need
128 to be flushed when the instruction space is changed at runtime. */
130 /* These were just copied from another port and are necessary to build, but
131 but don't appear to be used. */
132 #define MCCR_ADDR 0xffffffff
138 /* sim_core_attach device argument. */
139 extern device frv_devices;
141 /* FIXME: Temporary, until device support ready. */
142 struct _device { int foo; };
144 /* maintain the address of the start of the previous VLIW insn sequence. */
145 extern IADDR previous_vliw_pc;
146 extern CGEN_ATTR_VALUE_ENUM_TYPE frv_current_fm_slot;
148 /* Hardware status. */
149 #define GET_HSR0() GET_H_SPR (H_SPR_HSR0)
150 #define SET_HSR0(hsr0) SET_H_SPR (H_SPR_HSR0, (hsr0))
152 #define GET_HSR0_ICE(hsr0) (((hsr0) >> 31) & 1)
153 #define SET_HSR0_ICE(hsr0) ((hsr0) |= (1 << 31))
154 #define CLEAR_HSR0_ICE(hsr0) ((hsr0) &= ~(1 << 31))
156 #define GET_HSR0_DCE(hsr0) (((hsr0) >> 30) & 1)
157 #define SET_HSR0_DCE(hsr0) ((hsr0) |= (1 << 30))
158 #define CLEAR_HSR0_DCE(hsr0) ((hsr0) &= ~(1 << 30))
160 #define GET_HSR0_CBM(hsr0) (((hsr0) >> 27) & 1)
161 #define GET_HSR0_RME(hsr0) (((hsr0) >> 22) & 1)
162 #define GET_HSR0_SA(hsr0) (((hsr0) >> 12) & 1)
163 #define GET_HSR0_FRN(hsr0) (((hsr0) >> 11) & 1)
164 #define GET_HSR0_GRN(hsr0) (((hsr0) >> 10) & 1)
165 #define GET_HSR0_FRHE(hsr0) (((hsr0) >> 9) & 1)
166 #define GET_HSR0_FRLE(hsr0) (((hsr0) >> 8) & 1)
167 #define GET_HSR0_GRHE(hsr0) (((hsr0) >> 7) & 1)
168 #define GET_HSR0_GRLE(hsr0) (((hsr0) >> 6) & 1)
170 #define GET_IHSR8() GET_H_SPR (H_SPR_IHSR8)
171 #define GET_IHSR8_NBC(ihsr8) ((ihsr8) & 1)
172 #define GET_IHSR8_ICDM(ihsr8) (((ihsr8) >> 1) & 1)
173 #define GET_IHSR8_ICWE(ihsr8) (((ihsr8) >> 8) & 7)
174 #define GET_IHSR8_DCWE(ihsr8) (((ihsr8) >> 12) & 7)
176 void frvbf_insn_cache_preload (SIM_CPU *, SI, USI, int);
177 void frvbf_data_cache_preload (SIM_CPU *, SI, USI, int);
178 void frvbf_insn_cache_unlock (SIM_CPU *, SI);
179 void frvbf_data_cache_unlock (SIM_CPU *, SI);
180 void frvbf_insn_cache_invalidate (SIM_CPU *, SI, int);
181 void frvbf_data_cache_invalidate (SIM_CPU *, SI, int);
182 void frvbf_data_cache_flush (SIM_CPU *, SI, int);
184 /* FR-V Interrupt classes.
185 These are declared in order of increasing priority. */
186 enum frv_interrupt_class
188 FRV_EXTERNAL_INTERRUPT,
189 FRV_SOFTWARE_INTERRUPT,
190 FRV_PROGRAM_INTERRUPT,
193 NUM_FRV_INTERRUPT_CLASSES
196 /* FR-V Interrupt kinds.
197 These are declared in order of increasing priority. */
198 enum frv_interrupt_kind
200 /* External interrupts */
201 FRV_INTERRUPT_LEVEL_1,
202 FRV_INTERRUPT_LEVEL_2,
203 FRV_INTERRUPT_LEVEL_3,
204 FRV_INTERRUPT_LEVEL_4,
205 FRV_INTERRUPT_LEVEL_5,
206 FRV_INTERRUPT_LEVEL_6,
207 FRV_INTERRUPT_LEVEL_7,
208 FRV_INTERRUPT_LEVEL_8,
209 FRV_INTERRUPT_LEVEL_9,
210 FRV_INTERRUPT_LEVEL_10,
211 FRV_INTERRUPT_LEVEL_11,
212 FRV_INTERRUPT_LEVEL_12,
213 FRV_INTERRUPT_LEVEL_13,
214 FRV_INTERRUPT_LEVEL_14,
215 FRV_INTERRUPT_LEVEL_15,
216 /* Software interrupt */
217 FRV_TRAP_INSTRUCTION,
218 /* Program interrupts */
219 FRV_COMMIT_EXCEPTION,
220 FRV_DIVISION_EXCEPTION,
221 FRV_DATA_STORE_ERROR,
222 FRV_DATA_ACCESS_EXCEPTION,
223 FRV_DATA_ACCESS_MMU_MISS,
224 FRV_DATA_ACCESS_ERROR,
227 FRV_MEM_ADDRESS_NOT_ALIGNED,
228 FRV_REGISTER_EXCEPTION,
231 FRV_PRIVILEGED_INSTRUCTION,
232 FRV_ILLEGAL_INSTRUCTION,
233 FRV_INSTRUCTION_ACCESS_EXCEPTION,
234 FRV_INSTRUCTION_ACCESS_ERROR,
235 FRV_INSTRUCTION_ACCESS_MMU_MISS,
236 FRV_COMPOUND_EXCEPTION,
237 /* Break interrupt */
239 /* Reset interrupt */
241 NUM_FRV_INTERRUPT_KINDS
244 /* FRV interrupt exception codes */
247 FRV_EC_DATA_STORE_ERROR = 0x00,
248 FRV_EC_INSTRUCTION_ACCESS_MMU_MISS = 0x01,
249 FRV_EC_INSTRUCTION_ACCESS_ERROR = 0x02,
250 FRV_EC_INSTRUCTION_ACCESS_EXCEPTION = 0x03,
251 FRV_EC_PRIVILEGED_INSTRUCTION = 0x04,
252 FRV_EC_ILLEGAL_INSTRUCTION = 0x05,
253 FRV_EC_FP_DISABLED = 0x06,
254 FRV_EC_MP_DISABLED = 0x07,
255 FRV_EC_MEM_ADDRESS_NOT_ALIGNED = 0x0b,
256 FRV_EC_REGISTER_EXCEPTION = 0x0c,
257 FRV_EC_FP_EXCEPTION = 0x0d,
258 FRV_EC_MP_EXCEPTION = 0x0e,
259 FRV_EC_DATA_ACCESS_ERROR = 0x10,
260 FRV_EC_DATA_ACCESS_MMU_MISS = 0x11,
261 FRV_EC_DATA_ACCESS_EXCEPTION = 0x12,
262 FRV_EC_DIVISION_EXCEPTION = 0x13,
263 FRV_EC_COMMIT_EXCEPTION = 0x14,
264 FRV_EC_NOT_EXECUTED = 0x1f,
265 FRV_EC_INTERRUPT_LEVEL_1 = FRV_EC_NOT_EXECUTED,
266 FRV_EC_INTERRUPT_LEVEL_2 = FRV_EC_NOT_EXECUTED,
267 FRV_EC_INTERRUPT_LEVEL_3 = FRV_EC_NOT_EXECUTED,
268 FRV_EC_INTERRUPT_LEVEL_4 = FRV_EC_NOT_EXECUTED,
269 FRV_EC_INTERRUPT_LEVEL_5 = FRV_EC_NOT_EXECUTED,
270 FRV_EC_INTERRUPT_LEVEL_6 = FRV_EC_NOT_EXECUTED,
271 FRV_EC_INTERRUPT_LEVEL_7 = FRV_EC_NOT_EXECUTED,
272 FRV_EC_INTERRUPT_LEVEL_8 = FRV_EC_NOT_EXECUTED,
273 FRV_EC_INTERRUPT_LEVEL_9 = FRV_EC_NOT_EXECUTED,
274 FRV_EC_INTERRUPT_LEVEL_10 = FRV_EC_NOT_EXECUTED,
275 FRV_EC_INTERRUPT_LEVEL_11 = FRV_EC_NOT_EXECUTED,
276 FRV_EC_INTERRUPT_LEVEL_12 = FRV_EC_NOT_EXECUTED,
277 FRV_EC_INTERRUPT_LEVEL_13 = FRV_EC_NOT_EXECUTED,
278 FRV_EC_INTERRUPT_LEVEL_14 = FRV_EC_NOT_EXECUTED,
279 FRV_EC_INTERRUPT_LEVEL_15 = FRV_EC_NOT_EXECUTED,
280 FRV_EC_TRAP_INSTRUCTION = FRV_EC_NOT_EXECUTED,
281 FRV_EC_COMPOUND_EXCEPTION = FRV_EC_NOT_EXECUTED,
282 FRV_EC_BREAK_EXCEPTION = FRV_EC_NOT_EXECUTED,
283 FRV_EC_RESET = FRV_EC_NOT_EXECUTED
287 This struct contains enough information to describe a particular interrupt
291 enum frv_interrupt_kind kind;
293 enum frv_interrupt_class iclass;
294 unsigned char deferred;
295 unsigned char precise;
296 unsigned char handler_offset;
299 /* FR-V Interrupt table.
300 Describes the interrupts supported by the FR-V. */
301 extern struct frv_interrupt frv_interrupt_table[];
303 /* FR-V Interrupt State.
304 Interrupts are queued during execution of parallel insns and the interupt(s)
305 to be handled determined by analysing the queue after each VLIW insn. */
306 #define FRV_INTERRUPT_QUEUE_SIZE (4 * 4) /* 4 interrupts x 4 insns for now. */
308 /* register_exception codes */
311 FRV_REC_UNIMPLEMENTED = 0,
312 FRV_REC_UNALIGNED = 1
315 /* instruction_access_exception codes */
318 FRV_IAEC_PROTECT_VIOLATION = 1
321 /* data_access_exception codes */
324 FRV_DAEC_PROTECT_VIOLATION = 1
327 /* division_exception ISR codes */
330 FRV_DTT_NO_EXCEPTION = 0,
331 FRV_DTT_DIVISION_BY_ZERO = 1,
332 FRV_DTT_OVERFLOW = 2,
336 /* data written during an insn causing an interrupt */
337 struct frv_data_written
339 USI words[4]; /* Actual data in words */
340 int length; /* length of data written */
343 /* fp_exception info */
344 /* Trap codes for FSR0 and FQ registers. */
347 FSR_INVALID_OPERATION = 0x20,
349 FSR_UNDERFLOW = 0x08,
350 FSR_DIVISION_BY_ZERO = 0x04,
352 FSR_DENORMAL_INPUT = 0x01,
356 /* Floating point trap types for FSR. */
360 FTT_IEEE_754_EXCEPTION = 1,
361 FTT_UNIMPLEMENTED_FPOP = 3,
362 FTT_SEQUENCE_ERROR = 4,
364 FTT_DENORMAL_INPUT = 7
367 struct frv_fp_exception_info
369 enum frv_fsr_traps fsr_mask; /* interrupt code for FSR */
370 enum frv_fsr_ftt ftt; /* floating point trap type */
373 struct frv_interrupt_queue_element
375 enum frv_interrupt_kind kind; /* kind of interrupt */
376 IADDR vpc; /* address of insn causing interrupt */
377 int slot; /* VLIW slot containing the insn. */
378 USI eaddress; /* address of data access */
380 enum frv_rec rec; /* register exception code */
381 enum frv_iaec iaec; /* insn access exception code */
382 enum frv_daec daec; /* data access exception code */
383 enum frv_dtt dtt; /* division exception code */
384 struct frv_fp_exception_info fp_info;
385 struct frv_data_written data_written;
389 struct frv_interrupt_timer
394 enum frv_interrupt_kind interrupt;
397 struct frv_interrupt_state
399 /* The interrupt queue */
400 struct frv_interrupt_queue_element queue[FRV_INTERRUPT_QUEUE_SIZE];
403 /* interrupt queue element causing imprecise interrupt. */
404 struct frv_interrupt_queue_element *imprecise_interrupt;
406 /* interrupt timer. */
407 struct frv_interrupt_timer timer;
409 /* The last data written stored as an array of words. */
410 struct frv_data_written data_written;
412 /* The vliw slot of the insn causing the interrupt. */
415 /* target register index for non excepting insns. */
416 #define NE_NOFLAG (-1)
419 /* Accumulated NE flags for non excepting floating point insns. */
423 extern struct frv_interrupt_state frv_interrupt_state;
425 /* Macros to manipulate the PSR. */
426 #define GET_PSR() GET_H_SPR (H_SPR_PSR)
428 #define SET_PSR_ET(psr, et) ( \
429 (psr) = ((psr) & ~0x1) | ((et) & 0x1) \
432 #define GET_PSR_PS(psr) (((psr) >> 1) & 1)
434 #define SET_PSR_S(psr, s) ( \
435 (psr) = ((psr) & ~(0x1 << 2)) | (((s) & 0x1) << 2) \
438 /* Macros to handle the ISR register. */
439 #define GET_ISR() GET_H_SPR (H_SPR_ISR)
440 #define SET_ISR(isr) SET_H_SPR (H_SPR_ISR, (isr))
442 #define GET_ISR_EDE(isr) (((isr) >> 5) & 1)
444 #define GET_ISR_DTT(isr) (((isr) >> 3) & 3)
445 #define SET_ISR_DTT(isr, dtt) ( \
446 (isr) = ((isr) & ~(0x3 << 3)) | (((dtt) & 0x3) << 3) \
449 #define SET_ISR_AEXC(isr) ((isr) |= (1 << 2))
451 #define GET_ISR_EMAM(isr) ((isr) & 1)
453 /* Macros to handle exception status registers.
454 Get and set the hardware directly, since we may be getting/setting fields
455 which are not accessible to the user. */
456 #define GET_ESR(index) \
457 (CPU (h_spr[H_SPR_ESR0 + (index)]))
458 #define SET_ESR(index, esr) \
459 (CPU (h_spr[H_SPR_ESR0 + (index)]) = (esr))
461 #define SET_ESR_VALID(esr) ((esr) |= 1)
462 #define CLEAR_ESR_VALID(esr) ((esr) &= ~1)
464 #define SET_ESR_EC(esr, ec) ( \
465 (esr) = ((esr) & ~(0x1f << 1)) | (((ec) & 0x1f) << 1) \
468 #define SET_ESR_REC(esr, rec) ( \
469 (esr) = ((esr) & ~(0x3 << 6)) | (((rec) & 0x3) << 6) \
472 #define SET_ESR_IAEC(esr, iaec) ( \
473 (esr) = ((esr) & ~(0x1 << 8)) | (((iaec) & 0x1) << 8) \
476 #define SET_ESR_DAEC(esr, daec) ( \
477 (esr) = ((esr) & ~(0x1 << 9)) | (((daec) & 0x1) << 9) \
480 #define SET_ESR_EAV(esr) ((esr) |= (1 << 11))
481 #define CLEAR_ESR_EAV(esr) ((esr) &= ~(1 << 11))
483 #define GET_ESR_EDV(esr) (((esr) >> 12) & 1)
484 #define SET_ESR_EDV(esr) ((esr) |= (1 << 12))
485 #define CLEAR_ESR_EDV(esr) ((esr) &= ~(1 << 12))
487 #define GET_ESR_EDN(esr) ( \
488 ((esr) >> 13) & 0xf \
490 #define SET_ESR_EDN(esr, edn) ( \
491 (esr) = ((esr) & ~(0xf << 13)) | (((edn) & 0xf) << 13) \
494 #define SET_EPCR(index, address) \
495 (CPU (h_spr[H_SPR_EPCR0 + (index)]) = (address))
497 #define SET_EAR(index, address) \
498 (CPU (h_spr[H_SPR_EAR0 + (index)]) = (address))
500 #define SET_EDR(index, edr) \
501 (CPU (h_spr[H_SPR_EDR0 + (index)]) = (edr))
503 #define GET_ESFR(index) \
504 (CPU (h_spr[H_SPR_ESFR0 + (index)]))
505 #define SET_ESFR(index, esfr) \
506 (CPU (h_spr[H_SPR_ESFR0 + (index)]) = (esfr))
508 #define GET_ESFR_FLAG(findex) ( \
510 ((CPU (h_spr[H_SPR_ESFR0]) >> ((findex)-32)) & 1) \
512 ((CPU (h_spr[H_SPR_ESFR1]) >> (findex)) & 1) \
514 #define SET_ESFR_FLAG(findex) ( \
516 (CPU (h_spr[H_SPR_ESFR0]) = \
517 (CPU (h_spr[H_SPR_ESFR0]) | (1 << ((findex)-32))) \
519 (CPU (h_spr[H_SPR_ESFR1]) = \
520 (CPU (h_spr[H_SPR_ESFR1]) | (1 << (findex))) \
524 /* The FSR registers.
525 Get and set the hardware directly, since we may be getting/setting fields
526 which are not accessible to the user. */
527 #define GET_FSR(index) \
528 (CPU (h_spr[H_SPR_FSR0 + (index)]))
529 #define SET_FSR(index, fsr) \
530 (CPU (h_spr[H_SPR_FSR0 + (index)]) = (fsr))
532 #define GET_FSR_TEM(fsr) ( \
533 ((fsr) >> 24) & 0x3f \
536 #define SET_FSR_QNE(fsr) ((fsr) |= (1 << 20))
537 #define GET_FSR_QNE(fsr) (((fsr) >> 20) & 1)
539 #define SET_FSR_FTT(fsr, ftt) ( \
540 (fsr) = ((fsr) & ~(0x7 << 17)) | (((ftt) & 0x7) << 17) \
543 #define GET_FSR_AEXC(fsr) ( \
544 ((fsr) >> 10) & 0x3f \
546 #define SET_FSR_AEXC(fsr, aexc) ( \
547 (fsr) = ((fsr) & ~(0x3f << 10)) | (((aexc) & 0x3f) << 10) \
550 /* SIMD instruction exception codes for FQ. */
558 /* MIV field of FQ. */
565 /* The FQ registers are 64 bits wide and are implemented as 32 bit pairs. The
566 index here refers to the low order 32 bit element.
567 Get and set the hardware directly, since we may be getting/setting fields
568 which are not accessible to the user. */
569 #define GET_FQ(index) \
570 (CPU (h_spr[H_SPR_FQST0 + 2 * (index)]))
571 #define SET_FQ(index, fq) \
572 (CPU (h_spr[H_SPR_FQST0 + 2 * (index)]) = (fq))
574 #define SET_FQ_MIV(fq, miv) ( \
575 (fq) = ((fq) & ~(0x1 << 31)) | (((miv) & 0x1) << 31) \
578 #define SET_FQ_SIE(fq, sie) ( \
579 (fq) = ((fq) & ~(0x3 << 15)) | (((sie) & 0x3) << 15) \
582 #define SET_FQ_FTT(fq, ftt) ( \
583 (fq) = ((fq) & ~(0x7 << 7)) | (((ftt) & 0x7) << 7) \
586 #define SET_FQ_CEXC(fq, cexc) ( \
587 (fq) = ((fq) & ~(0x3f << 1)) | (((cexc) & 0x3f) << 1) \
590 #define GET_FQ_VALID(fq) ((fq) & 1)
591 #define SET_FQ_VALID(fq) ((fq) |= 1)
593 #define SET_FQ_OPC(index, insn) \
594 (CPU (h_spr[H_SPR_FQOP0 + 2 * (index)]) = (insn))
596 /* mp_exception support. */
597 /* Media trap types for MSR. */
602 MTT_ACC_NOT_ALIGNED = 2,
603 MTT_ACC_NOT_IMPLEMENTED = 2, /* Yes -- same value as MTT_ACC_NOT_ALIGNED. */
604 MTT_CR_NOT_ALIGNED = 3,
605 MTT_UNIMPLEMENTED_MPOP = 5,
609 /* Media status registers.
610 Get and set the hardware directly, since we may be getting/setting fields
611 which are not accessible to the user. */
612 #define GET_MSR(index) \
613 (CPU (h_spr[H_SPR_MSR0 + (index)]))
614 #define SET_MSR(index, msr) \
615 (CPU (h_spr[H_SPR_MSR0 + (index)]) = (msr))
617 #define GET_MSR_AOVF(msr) ((msr) & 1)
618 #define SET_MSR_AOVF(msr) ((msr) |= 1)
620 #define GET_MSR_OVF(msr) ( \
623 #define SET_MSR_OVF(msr) ( \
626 #define CLEAR_MSR_OVF(msr) ( \
630 #define OR_MSR_SIE(msr, sie) ( \
631 (msr) |= (((sie) & 0xf) << 2) \
633 #define CLEAR_MSR_SIE(msr) ( \
634 (msr) &= ~(0xf << 2) \
637 #define GET_MSR_MTT(msr) ( \
638 ((msr) >> 12) & 0x7 \
640 #define SET_MSR_MTT(msr, mtt) ( \
641 (msr) = ((msr) & ~(0x7 << 12)) | (((mtt) & 0x7) << 12) \
643 #define GET_MSR_EMCI(msr) ( \
644 ((msr) >> 24) & 0x1 \
646 #define GET_MSR_MPEM(msr) ( \
647 ((msr) >> 27) & 0x1 \
649 #define GET_MSR_SRDAV(msr) ( \
650 ((msr) >> 28) & 0x1 \
652 #define GET_MSR_RDAV(msr) ( \
653 ((msr) >> 29) & 0x1 \
655 #define GET_MSR_RD(msr) ( \
656 ((msr) >> 30) & 0x3 \
659 void frvbf_media_register_not_aligned (SIM_CPU *);
660 void frvbf_media_acc_not_aligned (SIM_CPU *);
661 void frvbf_media_cr_not_aligned (SIM_CPU *);
662 void frvbf_media_overflow (SIM_CPU *, int);
664 /* Functions for queuing and processing interrupts. */
665 struct frv_interrupt_queue_element *
666 frv_queue_break_interrupt (SIM_CPU *);
668 struct frv_interrupt_queue_element *
669 frv_queue_software_interrupt (SIM_CPU *, SI);
671 struct frv_interrupt_queue_element *
672 frv_queue_program_interrupt (SIM_CPU *, enum frv_interrupt_kind);
674 struct frv_interrupt_queue_element *
675 frv_queue_external_interrupt (SIM_CPU *, enum frv_interrupt_kind);
677 struct frv_interrupt_queue_element *
678 frv_queue_illegal_instruction_interrupt (SIM_CPU *, const CGEN_INSN *);
680 struct frv_interrupt_queue_element *
681 frv_queue_privileged_instruction_interrupt (SIM_CPU *, const CGEN_INSN *);
683 struct frv_interrupt_queue_element *
684 frv_queue_float_disabled_interrupt (SIM_CPU *);
686 struct frv_interrupt_queue_element *
687 frv_queue_media_disabled_interrupt (SIM_CPU *);
689 struct frv_interrupt_queue_element *
690 frv_queue_non_implemented_instruction_interrupt (SIM_CPU *, const CGEN_INSN *);
692 struct frv_interrupt_queue_element *
693 frv_queue_register_exception_interrupt (SIM_CPU *, enum frv_rec);
695 struct frv_interrupt_queue_element *
696 frv_queue_mem_address_not_aligned_interrupt (SIM_CPU *, USI);
698 struct frv_interrupt_queue_element *
699 frv_queue_data_access_error_interrupt (SIM_CPU *, USI);
701 struct frv_interrupt_queue_element *
702 frv_queue_instruction_access_error_interrupt (SIM_CPU *);
704 struct frv_interrupt_queue_element *
705 frv_queue_instruction_access_exception_interrupt (SIM_CPU *);
707 struct frv_interrupt_queue_element *
708 frv_queue_fp_exception_interrupt (SIM_CPU *, struct frv_fp_exception_info *);
710 enum frv_dtt frvbf_division_exception (SIM_CPU *, enum frv_dtt, int, int);
712 struct frv_interrupt_queue_element *
713 frv_queue_interrupt (SIM_CPU *, enum frv_interrupt_kind);
716 frv_set_interrupt_queue_slot (SIM_CPU *, struct frv_interrupt_queue_element *);
718 void frv_set_mp_exception_registers (SIM_CPU *, enum frv_msr_mtt, int);
719 void frv_detect_insn_access_interrupts (SIM_CPU *, SCACHE *);
721 void frv_process_interrupts (SIM_CPU *);
723 void frv_break_interrupt (SIM_CPU *, struct frv_interrupt *, IADDR);
724 void frv_non_operating_interrupt (SIM_CPU *, enum frv_interrupt_kind, IADDR);
725 void frv_program_interrupt (
726 SIM_CPU *, struct frv_interrupt_queue_element *, IADDR
728 void frv_software_interrupt (
729 SIM_CPU *, struct frv_interrupt_queue_element *, IADDR
731 void frv_external_interrupt (
732 SIM_CPU *, struct frv_interrupt_queue_element *, IADDR
734 void frv_program_or_software_interrupt (
735 SIM_CPU *, struct frv_interrupt *, IADDR
737 void frv_clear_interrupt_classes (
738 enum frv_interrupt_class, enum frv_interrupt_class
742 frv_save_data_written_for_interrupts (SIM_CPU *, CGEN_WRITE_QUEUE_ELEMENT *);
744 /* Special purpose traps. */
745 #define TRAP_SYSCALL 0x80
746 #define TRAP_BREAKPOINT 0x81
747 #define TRAP_REGDUMP1 0x82
748 #define TRAP_REGDUMP2 0x83
750 /* Handle the trap insns */
751 void frv_itrap (SIM_CPU *, PCADDR, USI, int);
752 void frv_mtrap (SIM_CPU *);
753 /* Handle the break insn. */
754 void frv_break (SIM_CPU *);
755 /* Handle the rett insn. */
756 USI frv_rett (SIM_CPU *current_cpu, PCADDR pc, BI debug_field);
758 /* Parallel write queue flags. */
759 #define FRV_WRITE_QUEUE_FORCE_WRITE 1
761 #define CGEN_WRITE_QUEUE_ELEMENT_PIPE(element) CGEN_WRITE_QUEUE_ELEMENT_WORD1 (element)
763 /* Functions and macros for handling non-excepting instruction side effects.
764 Get and set the hardware directly, since we may be getting/setting fields
765 which are not accessible to the user. */
766 #define GET_NECR() (GET_H_SPR (H_SPR_NECR))
767 #define GET_NECR_ELOS(necr) (((necr) >> 6) & 1)
768 #define GET_NECR_NEN(necr) (((necr) >> 1) & 0x1f)
769 #define GET_NECR_VALID(necr) (((necr) ) & 1)
772 /* NESR field values. See Tables 30-33 in section 4.4.2.1 of the FRV
773 Architecture volume 1. */
774 #define NESR_MEM_ADDRESS_NOT_ALIGNED 0x0b
775 #define NESR_REGISTER_NOT_ALIGNED 0x1
776 #define NESR_UQI_SIZE 0
777 #define NESR_QI_SIZE 1
778 #define NESR_UHI_SIZE 2
779 #define NESR_HI_SIZE 3
780 #define NESR_SI_SIZE 4
781 #define NESR_DI_SIZE 5
782 #define NESR_XI_SIZE 6
784 #define GET_NESR(index) GET_H_SPR (H_SPR_NESR0 + (index))
785 #define SET_NESR(index, value) ( \
786 sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, \
787 H_SPR_NESR0 + (index), (value)), \
788 frvbf_force_update (current_cpu) \
790 #define GET_NESR_VALID(nesr) ((nesr) & 1)
791 #define SET_NESR_VALID(nesr) ((nesr) |= 1)
793 #define SET_NESR_EAV(nesr) ((nesr) |= (1 << 31))
795 #define GET_NESR_FR(nesr) (((nesr) >> 30) & 1)
796 #define SET_NESR_FR(nesr) ((nesr) |= (1 << 30))
797 #define CLEAR_NESR_FR(nesr) ((nesr) &= ~(1 << 30))
799 #define GET_NESR_DRN(nesr) (((nesr) >> 24) & 0x3f)
800 #define SET_NESR_DRN(nesr, drn) ( \
801 (nesr) = ((nesr) & ~(0x3f << 24)) | (((drn) & 0x3f) << 24) \
804 #define SET_NESR_SIZE(nesr, data_size) ( \
805 (nesr) = ((nesr) & ~(0x7 << 21)) | (((data_size) & 0x7) << 21) \
808 #define SET_NESR_NEAN(nesr, index) ( \
809 (nesr) = ((nesr) & ~(0x1f << 10)) | (((index) & 0x1f) << 10) \
812 #define GET_NESR_DAEC(nesr) (((nesr) >> 9) & 1)
813 #define SET_NESR_DAEC(nesr, daec) ( \
814 (nesr) = ((nesr) & ~(1 << 9)) | (((daec) & 1) << 9) \
817 #define GET_NESR_REC(nesr) (((nesr) >> 6) & 3)
818 #define SET_NESR_REC(nesr, rec) ( \
819 (nesr) = ((nesr) & ~(3 << 6)) | (((rec) & 3) << 6) \
822 #define GET_NESR_EC(nesr) (((nesr) >> 1) & 0x1f)
823 #define SET_NESR_EC(nesr, ec) ( \
824 (nesr) = ((nesr) & ~(0x1f << 1)) | (((ec) & 0x1f) << 1) \
827 #define SET_NEEAR(index, address) ( \
828 sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, \
829 H_SPR_NEEAR0 + (index), (address)), \
830 frvbf_force_update (current_cpu) \
833 #define GET_NE_FLAGS(flags, NE_base) ( \
834 (flags)[0] = GET_H_SPR ((NE_base)), \
835 (flags)[1] = GET_H_SPR ((NE_base) + 1) \
837 #define SET_NE_FLAGS(NE_base, flags) ( \
838 sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, (NE_base), \
840 frvbf_force_update (current_cpu), \
841 sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, (NE_base) + 1, \
843 frvbf_force_update (current_cpu) \
846 #define GET_NE_FLAG(flags, index) ( \
848 ((flags[0] >> ((index) - 32)) & 1) \
850 ((flags[1] >> (index)) & 1) \
852 #define SET_NE_FLAG(flags, index) ( \
854 ((flags)[0] |= (1 << ((index) - 32))) \
856 ((flags)[1] |= (1 << (index))) \
858 #define CLEAR_NE_FLAG(flags, index) ( \
860 ((flags)[0] &= ~(1 << ((index) - 32))) \
862 ((flags)[1] &= ~(1 << (index))) \
865 BI frvbf_check_non_excepting_load (SIM_CPU *, SI, SI, SI, SI, QI, BI);
866 void frvbf_check_recovering_store (SIM_CPU *, PCADDR, SI, int, int);
868 void frvbf_clear_ne_flags (SIM_CPU *, SI, BI);
869 void frvbf_commit (SIM_CPU *, SI, BI);
871 void frvbf_fpu_error (CGEN_FPU *, int);
873 void frv_vliw_setup_insn (SIM_CPU *, const CGEN_INSN *);
875 extern int insns_in_slot[];
877 #define COUNT_INSNS_IN_SLOT(slot) \
879 if (WITH_PROFILE_MODEL_P) \
880 ++insns_in_slot[slot]; \
883 #define INSNS_IN_SLOT(slot) (insns_in_slot[slot])
885 /* Multiple loads and stores. */
886 void frvbf_load_multiple_GR (SIM_CPU *, PCADDR, SI, SI, int);
887 void frvbf_load_multiple_FRint (SIM_CPU *, PCADDR, SI, SI, int);
888 void frvbf_load_multiple_CPR (SIM_CPU *, PCADDR, SI, SI, int);
889 void frvbf_store_multiple_GR (SIM_CPU *, PCADDR, SI, SI, int);
890 void frvbf_store_multiple_FRint (SIM_CPU *, PCADDR, SI, SI, int);
891 void frvbf_store_multiple_CPR (SIM_CPU *, PCADDR, SI, SI, int);
893 /* Memory and cache support. */
894 QI frvbf_read_mem_QI (SIM_CPU *, IADDR, SI);
895 UQI frvbf_read_mem_UQI (SIM_CPU *, IADDR, SI);
896 HI frvbf_read_mem_HI (SIM_CPU *, IADDR, SI);
897 UHI frvbf_read_mem_UHI (SIM_CPU *, IADDR, SI);
898 SI frvbf_read_mem_SI (SIM_CPU *, IADDR, SI);
899 SI frvbf_read_mem_WI (SIM_CPU *, IADDR, SI);
900 DI frvbf_read_mem_DI (SIM_CPU *, IADDR, SI);
901 DF frvbf_read_mem_DF (SIM_CPU *, IADDR, SI);
903 USI frvbf_read_imem_USI (SIM_CPU *, PCADDR);
905 void frvbf_write_mem_QI (SIM_CPU *, IADDR, SI, QI);
906 void frvbf_write_mem_UQI (SIM_CPU *, IADDR, SI, UQI);
907 void frvbf_write_mem_HI (SIM_CPU *, IADDR, SI, HI);
908 void frvbf_write_mem_UHI (SIM_CPU *, IADDR, SI, UHI);
909 void frvbf_write_mem_SI (SIM_CPU *, IADDR, SI, SI);
910 void frvbf_write_mem_WI (SIM_CPU *, IADDR, SI, SI);
911 void frvbf_write_mem_DI (SIM_CPU *, IADDR, SI, DI);
912 void frvbf_write_mem_DF (SIM_CPU *, IADDR, SI, DF);
914 void frvbf_mem_set_QI (SIM_CPU *, IADDR, SI, QI);
915 void frvbf_mem_set_HI (SIM_CPU *, IADDR, SI, HI);
916 void frvbf_mem_set_SI (SIM_CPU *, IADDR, SI, SI);
917 void frvbf_mem_set_DI (SIM_CPU *, IADDR, SI, DI);
918 void frvbf_mem_set_DF (SIM_CPU *, IADDR, SI, DF);
919 void frvbf_mem_set_XI (SIM_CPU *, IADDR, SI, SI *);
921 void frv_set_write_queue_slot (SIM_CPU *current_cpu);
923 /* FRV specific options. */
924 extern const OPTION frv_options[];
926 #endif /* FRV_SIM_H */