interrupts.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /* frv exception and interrupt support
  2. Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. Contributed by Red Hat.
  4. This file is part of the GNU simulators.
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #define WANT_CPU frvbf
  16. #define WANT_CPU_FRVBF
  17. #include "sim-main.h"
  18. #include "bfd.h"
  19. /* FR-V Interrupt table.
  20. Describes the interrupts supported by the FR-V.
  21. This table *must* be maintained in order of interrupt priority as defined by
  22. frv_interrupt_kind. */
  23. #define DEFERRED 1
  24. #define PRECISE 1
  25. #define ITABLE_ENTRY(name, class, deferral, precision, offset) \
  26. {FRV_##name, FRV_EC_##name, class, deferral, precision, offset}
  27. struct frv_interrupt frv_interrupt_table[NUM_FRV_INTERRUPT_KINDS] =
  28. {
  29. /* External interrupts */
  30. ITABLE_ENTRY(INTERRUPT_LEVEL_1, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x21),
  31. ITABLE_ENTRY(INTERRUPT_LEVEL_2, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x22),
  32. ITABLE_ENTRY(INTERRUPT_LEVEL_3, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x23),
  33. ITABLE_ENTRY(INTERRUPT_LEVEL_4, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x24),
  34. ITABLE_ENTRY(INTERRUPT_LEVEL_5, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x25),
  35. ITABLE_ENTRY(INTERRUPT_LEVEL_6, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x26),
  36. ITABLE_ENTRY(INTERRUPT_LEVEL_7, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x27),
  37. ITABLE_ENTRY(INTERRUPT_LEVEL_8, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x28),
  38. ITABLE_ENTRY(INTERRUPT_LEVEL_9, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x29),
  39. ITABLE_ENTRY(INTERRUPT_LEVEL_10, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x2a),
  40. ITABLE_ENTRY(INTERRUPT_LEVEL_11, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x2b),
  41. ITABLE_ENTRY(INTERRUPT_LEVEL_12, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x2c),
  42. ITABLE_ENTRY(INTERRUPT_LEVEL_13, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x2d),
  43. ITABLE_ENTRY(INTERRUPT_LEVEL_14, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x2e),
  44. ITABLE_ENTRY(INTERRUPT_LEVEL_15, FRV_EXTERNAL_INTERRUPT, !DEFERRED, !PRECISE, 0x2f),
  45. /* Software interrupt */
  46. ITABLE_ENTRY(TRAP_INSTRUCTION, FRV_SOFTWARE_INTERRUPT, !DEFERRED, !PRECISE, 0x80),
  47. /* Program interrupts */
  48. ITABLE_ENTRY(COMMIT_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x19),
  49. ITABLE_ENTRY(DIVISION_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x17),
  50. ITABLE_ENTRY(DATA_STORE_ERROR, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x14),
  51. ITABLE_ENTRY(DATA_ACCESS_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x13),
  52. ITABLE_ENTRY(DATA_ACCESS_MMU_MISS, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x12),
  53. ITABLE_ENTRY(DATA_ACCESS_ERROR, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x11),
  54. ITABLE_ENTRY(MP_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x0e),
  55. ITABLE_ENTRY(FP_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x0d),
  56. ITABLE_ENTRY(MEM_ADDRESS_NOT_ALIGNED, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x10),
  57. ITABLE_ENTRY(REGISTER_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x08),
  58. ITABLE_ENTRY(MP_DISABLED, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x0b),
  59. ITABLE_ENTRY(FP_DISABLED, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x0a),
  60. ITABLE_ENTRY(PRIVILEGED_INSTRUCTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x06),
  61. ITABLE_ENTRY(ILLEGAL_INSTRUCTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x07),
  62. ITABLE_ENTRY(INSTRUCTION_ACCESS_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x03),
  63. ITABLE_ENTRY(INSTRUCTION_ACCESS_ERROR, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x02),
  64. ITABLE_ENTRY(INSTRUCTION_ACCESS_MMU_MISS, FRV_PROGRAM_INTERRUPT, !DEFERRED, PRECISE, 0x01),
  65. ITABLE_ENTRY(COMPOUND_EXCEPTION, FRV_PROGRAM_INTERRUPT, !DEFERRED, !PRECISE, 0x20),
  66. /* Break interrupt */
  67. ITABLE_ENTRY(BREAK_EXCEPTION, FRV_BREAK_INTERRUPT, !DEFERRED, !PRECISE, 0xff),
  68. /* Reset interrupt */
  69. ITABLE_ENTRY(RESET, FRV_RESET_INTERRUPT, !DEFERRED, !PRECISE, 0x00)
  70. };
  71. /* The current interrupt state. */
  72. struct frv_interrupt_state frv_interrupt_state;
  73. /* maintain the address of the start of the previous VLIW insn sequence. */
  74. IADDR previous_vliw_pc;
  75. /* Add a break interrupt to the interrupt queue. */
  76. struct frv_interrupt_queue_element *
  77. frv_queue_break_interrupt (SIM_CPU *current_cpu)
  78. {
  79. return frv_queue_interrupt (current_cpu, FRV_BREAK_EXCEPTION);
  80. }
  81. /* Add a software interrupt to the interrupt queue. */
  82. struct frv_interrupt_queue_element *
  83. frv_queue_software_interrupt (SIM_CPU *current_cpu, SI offset)
  84. {
  85. struct frv_interrupt_queue_element *new_element
  86. = frv_queue_interrupt (current_cpu, FRV_TRAP_INSTRUCTION);
  87. struct frv_interrupt *interrupt = & frv_interrupt_table[new_element->kind];
  88. interrupt->handler_offset = offset;
  89. return new_element;
  90. }
  91. /* Add a program interrupt to the interrupt queue. */
  92. struct frv_interrupt_queue_element *
  93. frv_queue_program_interrupt (
  94. SIM_CPU *current_cpu, enum frv_interrupt_kind kind
  95. )
  96. {
  97. return frv_queue_interrupt (current_cpu, kind);
  98. }
  99. /* Add an external interrupt to the interrupt queue. */
  100. struct frv_interrupt_queue_element *
  101. frv_queue_external_interrupt (
  102. SIM_CPU *current_cpu, enum frv_interrupt_kind kind
  103. )
  104. {
  105. if (! GET_H_PSR_ET ()
  106. || (kind != FRV_INTERRUPT_LEVEL_15 && kind < GET_H_PSR_PIL ()))
  107. return NULL; /* Leave it for later. */
  108. return frv_queue_interrupt (current_cpu, kind);
  109. }
  110. /* Add any interrupt to the interrupt queue. It will be added in reverse
  111. priority order. This makes it easy to find the highest priority interrupt
  112. at the end of the queue and to remove it after processing. */
  113. struct frv_interrupt_queue_element *
  114. frv_queue_interrupt (SIM_CPU *current_cpu, enum frv_interrupt_kind kind)
  115. {
  116. int i;
  117. int j;
  118. int limit = frv_interrupt_state.queue_index;
  119. struct frv_interrupt_queue_element *new_element;
  120. enum frv_interrupt_class iclass;
  121. if (limit >= FRV_INTERRUPT_QUEUE_SIZE)
  122. abort (); /* TODO: Make the queue dynamic */
  123. /* Find the right place in the queue. */
  124. for (i = 0; i < limit; ++i)
  125. {
  126. if (frv_interrupt_state.queue[i].kind >= kind)
  127. break;
  128. }
  129. /* Don't queue two external interrupts of the same priority. */
  130. iclass = frv_interrupt_table[kind].iclass;
  131. if (i < limit && iclass == FRV_EXTERNAL_INTERRUPT)
  132. {
  133. if (frv_interrupt_state.queue[i].kind == kind)
  134. return & frv_interrupt_state.queue[i];
  135. }
  136. /* Make room for the new interrupt in this spot. */
  137. for (j = limit - 1; j >= i; --j)
  138. frv_interrupt_state.queue[j + 1] = frv_interrupt_state.queue[j];
  139. /* Add the new interrupt. */
  140. frv_interrupt_state.queue_index++;
  141. new_element = & frv_interrupt_state.queue[i];
  142. new_element->kind = kind;
  143. new_element->vpc = CPU_PC_GET (current_cpu);
  144. new_element->u.data_written.length = 0;
  145. frv_set_interrupt_queue_slot (current_cpu, new_element);
  146. return new_element;
  147. }
  148. struct frv_interrupt_queue_element *
  149. frv_queue_register_exception_interrupt (SIM_CPU *current_cpu, enum frv_rec rec)
  150. {
  151. struct frv_interrupt_queue_element *new_element =
  152. frv_queue_program_interrupt (current_cpu, FRV_REGISTER_EXCEPTION);
  153. new_element->u.rec = rec;
  154. return new_element;
  155. }
  156. struct frv_interrupt_queue_element *
  157. frv_queue_mem_address_not_aligned_interrupt (SIM_CPU *current_cpu, USI addr)
  158. {
  159. struct frv_interrupt_queue_element *new_element;
  160. USI isr = GET_ISR ();
  161. /* Make sure that this exception is not masked. */
  162. if (GET_ISR_EMAM (isr))
  163. return NULL;
  164. /* Queue the interrupt. */
  165. new_element = frv_queue_program_interrupt (current_cpu,
  166. FRV_MEM_ADDRESS_NOT_ALIGNED);
  167. new_element->eaddress = addr;
  168. new_element->u.data_written = frv_interrupt_state.data_written;
  169. frv_interrupt_state.data_written.length = 0;
  170. return new_element;
  171. }
  172. struct frv_interrupt_queue_element *
  173. frv_queue_data_access_error_interrupt (SIM_CPU *current_cpu, USI addr)
  174. {
  175. struct frv_interrupt_queue_element *new_element;
  176. new_element = frv_queue_program_interrupt (current_cpu,
  177. FRV_DATA_ACCESS_ERROR);
  178. new_element->eaddress = addr;
  179. return new_element;
  180. }
  181. struct frv_interrupt_queue_element *
  182. frv_queue_data_access_exception_interrupt (SIM_CPU *current_cpu)
  183. {
  184. return frv_queue_program_interrupt (current_cpu, FRV_DATA_ACCESS_EXCEPTION);
  185. }
  186. struct frv_interrupt_queue_element *
  187. frv_queue_instruction_access_error_interrupt (SIM_CPU *current_cpu)
  188. {
  189. return frv_queue_program_interrupt (current_cpu, FRV_INSTRUCTION_ACCESS_ERROR);
  190. }
  191. struct frv_interrupt_queue_element *
  192. frv_queue_instruction_access_exception_interrupt (SIM_CPU *current_cpu)
  193. {
  194. return frv_queue_program_interrupt (current_cpu, FRV_INSTRUCTION_ACCESS_EXCEPTION);
  195. }
  196. struct frv_interrupt_queue_element *
  197. frv_queue_illegal_instruction_interrupt (
  198. SIM_CPU *current_cpu, const CGEN_INSN *insn
  199. )
  200. {
  201. SIM_DESC sd = CPU_STATE (current_cpu);
  202. switch (STATE_ARCHITECTURE (sd)->mach)
  203. {
  204. case bfd_mach_fr400:
  205. case bfd_mach_fr450:
  206. case bfd_mach_fr550:
  207. break;
  208. default:
  209. /* Some machines generate fp_exception for this case. */
  210. if (frv_is_float_insn (insn) || frv_is_media_insn (insn))
  211. {
  212. struct frv_fp_exception_info fp_info = {
  213. FSR_NO_EXCEPTION, FTT_SEQUENCE_ERROR
  214. };
  215. return frv_queue_fp_exception_interrupt (current_cpu, & fp_info);
  216. }
  217. break;
  218. }
  219. return frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  220. }
  221. struct frv_interrupt_queue_element *
  222. frv_queue_privileged_instruction_interrupt (SIM_CPU *current_cpu, const CGEN_INSN *insn)
  223. {
  224. /* The fr550 has no privileged instruction interrupt. It uses
  225. illegal_instruction. */
  226. SIM_DESC sd = CPU_STATE (current_cpu);
  227. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  228. return frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  229. return frv_queue_program_interrupt (current_cpu, FRV_PRIVILEGED_INSTRUCTION);
  230. }
  231. struct frv_interrupt_queue_element *
  232. frv_queue_float_disabled_interrupt (SIM_CPU *current_cpu)
  233. {
  234. /* The fr550 has no fp_disabled interrupt. It uses illegal_instruction. */
  235. SIM_DESC sd = CPU_STATE (current_cpu);
  236. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  237. return frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  238. return frv_queue_program_interrupt (current_cpu, FRV_FP_DISABLED);
  239. }
  240. struct frv_interrupt_queue_element *
  241. frv_queue_media_disabled_interrupt (SIM_CPU *current_cpu)
  242. {
  243. /* The fr550 has no mp_disabled interrupt. It uses illegal_instruction. */
  244. SIM_DESC sd = CPU_STATE (current_cpu);
  245. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  246. return frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  247. return frv_queue_program_interrupt (current_cpu, FRV_MP_DISABLED);
  248. }
  249. struct frv_interrupt_queue_element *
  250. frv_queue_non_implemented_instruction_interrupt (
  251. SIM_CPU *current_cpu, const CGEN_INSN *insn
  252. )
  253. {
  254. SIM_DESC sd = CPU_STATE (current_cpu);
  255. switch (STATE_ARCHITECTURE (sd)->mach)
  256. {
  257. case bfd_mach_fr400:
  258. case bfd_mach_fr450:
  259. case bfd_mach_fr550:
  260. break;
  261. default:
  262. /* Some machines generate fp_exception or mp_exception for this case. */
  263. if (frv_is_float_insn (insn))
  264. {
  265. struct frv_fp_exception_info fp_info = {
  266. FSR_NO_EXCEPTION, FTT_UNIMPLEMENTED_FPOP
  267. };
  268. return frv_queue_fp_exception_interrupt (current_cpu, & fp_info);
  269. }
  270. if (frv_is_media_insn (insn))
  271. {
  272. frv_set_mp_exception_registers (current_cpu, MTT_UNIMPLEMENTED_MPOP,
  273. 0);
  274. return NULL; /* no interrupt queued at this time. */
  275. }
  276. break;
  277. }
  278. return frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  279. }
  280. /* Queue the given fp_exception interrupt. Also update fp_info by removing
  281. masked interrupts and updating the 'slot' flield. */
  282. struct frv_interrupt_queue_element *
  283. frv_queue_fp_exception_interrupt (
  284. SIM_CPU *current_cpu, struct frv_fp_exception_info *fp_info
  285. )
  286. {
  287. SI fsr0 = GET_FSR (0);
  288. int tem = GET_FSR_TEM (fsr0);
  289. int aexc = GET_FSR_AEXC (fsr0);
  290. struct frv_interrupt_queue_element *new_element = NULL;
  291. /* Update AEXC with the interrupts that are masked. */
  292. aexc |= fp_info->fsr_mask & ~tem;
  293. SET_FSR_AEXC (fsr0, aexc);
  294. SET_FSR (0, fsr0);
  295. /* update fsr_mask with the exceptions that are enabled. */
  296. fp_info->fsr_mask &= tem;
  297. /* If there is an unmasked interrupt then queue it, unless
  298. this was a non-excepting insn, in which case simply set the NE
  299. status registers. */
  300. if (frv_interrupt_state.ne_index != NE_NOFLAG
  301. && fp_info->fsr_mask != FSR_NO_EXCEPTION)
  302. {
  303. SET_NE_FLAG (frv_interrupt_state.f_ne_flags,
  304. frv_interrupt_state.ne_index);
  305. /* TODO -- Set NESR for chips which support it. */
  306. new_element = NULL;
  307. }
  308. else if (fp_info->fsr_mask != FSR_NO_EXCEPTION
  309. || fp_info->ftt == FTT_UNIMPLEMENTED_FPOP
  310. || fp_info->ftt == FTT_SEQUENCE_ERROR
  311. || fp_info->ftt == FTT_INVALID_FR)
  312. {
  313. new_element = frv_queue_program_interrupt (current_cpu, FRV_FP_EXCEPTION);
  314. new_element->u.fp_info = *fp_info;
  315. }
  316. return new_element;
  317. }
  318. struct frv_interrupt_queue_element *
  319. frv_queue_division_exception_interrupt (SIM_CPU *current_cpu, enum frv_dtt dtt)
  320. {
  321. struct frv_interrupt_queue_element *new_element =
  322. frv_queue_program_interrupt (current_cpu, FRV_DIVISION_EXCEPTION);
  323. new_element->u.dtt = dtt;
  324. return new_element;
  325. }
  326. /* Check for interrupts caused by illegal insn access. These conditions are
  327. checked in the order specified by the fr400 and fr500 LSI specs. */
  328. void
  329. frv_detect_insn_access_interrupts (SIM_CPU *current_cpu, SCACHE *sc)
  330. {
  331. const CGEN_INSN *insn = sc->argbuf.idesc->idata;
  332. SIM_DESC sd = CPU_STATE (current_cpu);
  333. FRV_VLIW *vliw = CPU_VLIW (current_cpu);
  334. /* Check for vliw constraints. */
  335. if (vliw->constraint_violation)
  336. frv_queue_illegal_instruction_interrupt (current_cpu, insn);
  337. /* Check for non-excepting insns. */
  338. else if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_NON_EXCEPTING)
  339. && ! GET_H_PSR_NEM ())
  340. frv_queue_non_implemented_instruction_interrupt (current_cpu, insn);
  341. /* Check for conditional insns. */
  342. else if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_CONDITIONAL)
  343. && ! GET_H_PSR_CM ())
  344. frv_queue_non_implemented_instruction_interrupt (current_cpu, insn);
  345. /* Make sure floating point support is enabled. */
  346. else if (! GET_H_PSR_EF ())
  347. {
  348. /* Generate fp_disabled if it is a floating point insn or if PSR.EM is
  349. off and the insns accesses a fp register. */
  350. if (frv_is_float_insn (insn)
  351. || (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_FR_ACCESS)
  352. && ! GET_H_PSR_EM ()))
  353. frv_queue_float_disabled_interrupt (current_cpu);
  354. }
  355. /* Make sure media support is enabled. */
  356. else if (! GET_H_PSR_EM ())
  357. {
  358. /* Generate mp_disabled if it is a media insn. */
  359. if (frv_is_media_insn (insn) || CGEN_INSN_NUM (insn) == FRV_INSN_MTRAP)
  360. frv_queue_media_disabled_interrupt (current_cpu);
  361. }
  362. /* Check for privileged insns. */
  363. else if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_PRIVILEGED) &&
  364. ! GET_H_PSR_S ())
  365. frv_queue_privileged_instruction_interrupt (current_cpu, insn);
  366. #if 0 /* disable for now until we find out how FSR0.QNE gets reset. */
  367. else
  368. {
  369. /* Enter the halt state if FSR0.QNE is set and we are executing a
  370. floating point insn, a media insn or an insn which access a FR
  371. register. */
  372. SI fsr0 = GET_FSR (0);
  373. if (GET_FSR_QNE (fsr0)
  374. && (frv_is_float_insn (insn) || frv_is_media_insn (insn)
  375. || CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_FR_ACCESS)))
  376. {
  377. sim_engine_halt (sd, current_cpu, NULL, GET_H_PC (), sim_stopped,
  378. SIM_SIGINT);
  379. }
  380. }
  381. #endif
  382. }
  383. /* Record the current VLIW slot in the given interrupt queue element. */
  384. void
  385. frv_set_interrupt_queue_slot (
  386. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  387. )
  388. {
  389. FRV_VLIW *vliw = CPU_VLIW (current_cpu);
  390. int slot = vliw->next_slot - 1;
  391. item->slot = (*vliw->current_vliw)[slot];
  392. }
  393. /* Handle an individual interrupt. */
  394. static void
  395. handle_interrupt (SIM_CPU *current_cpu, IADDR pc)
  396. {
  397. struct frv_interrupt *interrupt;
  398. int writeback_done = 0;
  399. while (1)
  400. {
  401. /* Interrupts are queued in priority order with the highest priority
  402. last. */
  403. int index = frv_interrupt_state.queue_index - 1;
  404. struct frv_interrupt_queue_element *item
  405. = & frv_interrupt_state.queue[index];
  406. interrupt = & frv_interrupt_table[item->kind];
  407. switch (interrupt->iclass)
  408. {
  409. case FRV_EXTERNAL_INTERRUPT:
  410. /* Perform writeback first. This may cause a higher priority
  411. interrupt. */
  412. if (! writeback_done)
  413. {
  414. frvbf_perform_writeback (current_cpu);
  415. writeback_done = 1;
  416. continue;
  417. }
  418. frv_external_interrupt (current_cpu, item, pc);
  419. return;
  420. case FRV_SOFTWARE_INTERRUPT:
  421. frv_interrupt_state.queue_index = index;
  422. frv_software_interrupt (current_cpu, item, pc);
  423. return;
  424. case FRV_PROGRAM_INTERRUPT:
  425. /* If the program interrupt is not strict (imprecise), then perform
  426. writeback first. This may, in turn, cause a higher priority
  427. interrupt. */
  428. if (! interrupt->precise && ! writeback_done)
  429. {
  430. frv_interrupt_state.imprecise_interrupt = item;
  431. frvbf_perform_writeback (current_cpu);
  432. writeback_done = 1;
  433. continue;
  434. }
  435. frv_interrupt_state.queue_index = index;
  436. frv_program_interrupt (current_cpu, item, pc);
  437. return;
  438. case FRV_BREAK_INTERRUPT:
  439. frv_interrupt_state.queue_index = index;
  440. frv_break_interrupt (current_cpu, interrupt, pc);
  441. return;
  442. case FRV_RESET_INTERRUPT:
  443. break;
  444. default:
  445. break;
  446. }
  447. frv_interrupt_state.queue_index = index;
  448. break; /* out of loop. */
  449. }
  450. /* We should never get here. */
  451. {
  452. SIM_DESC sd = CPU_STATE (current_cpu);
  453. sim_engine_abort (sd, current_cpu, pc,
  454. "interrupt class not supported %d\n",
  455. interrupt->iclass);
  456. }
  457. }
  458. /* Check to see the if the RSTR.HR or RSTR.SR bits have been set. If so, handle
  459. the appropriate reset interrupt. */
  460. static int
  461. check_reset (SIM_CPU *current_cpu, IADDR pc)
  462. {
  463. int hsr0;
  464. int hr;
  465. int sr;
  466. SI rstr;
  467. FRV_CACHE *cache = CPU_DATA_CACHE (current_cpu);
  468. IADDR address = RSTR_ADDRESS;
  469. /* We don't want this to show up in the cache statistics, so read the
  470. cache passively. */
  471. if (! frv_cache_read_passive_SI (cache, address, & rstr))
  472. rstr = sim_core_read_unaligned_4 (current_cpu, pc, read_map, address);
  473. hr = GET_RSTR_HR (rstr);
  474. sr = GET_RSTR_SR (rstr);
  475. if (! hr && ! sr)
  476. return 0; /* no reset. */
  477. /* Reinitialize the machine state. */
  478. if (hr)
  479. frv_hardware_reset (current_cpu);
  480. else
  481. frv_software_reset (current_cpu);
  482. /* Branch to the reset address. */
  483. hsr0 = GET_HSR0 ();
  484. if (GET_HSR0_SA (hsr0))
  485. SET_H_PC (0xff000000);
  486. else
  487. SET_H_PC (0);
  488. return 1; /* reset */
  489. }
  490. /* Process any pending interrupt(s) after a group of parallel insns. */
  491. void
  492. frv_process_interrupts (SIM_CPU *current_cpu)
  493. {
  494. SI NE_flags[2];
  495. /* Need to save the pc here because writeback may change it (due to a
  496. branch). */
  497. IADDR pc = CPU_PC_GET (current_cpu);
  498. /* Check for a reset before anything else. */
  499. if (check_reset (current_cpu, pc))
  500. return;
  501. /* First queue the writes for any accumulated NE flags. */
  502. if (frv_interrupt_state.f_ne_flags[0] != 0
  503. || frv_interrupt_state.f_ne_flags[1] != 0)
  504. {
  505. GET_NE_FLAGS (NE_flags, H_SPR_FNER0);
  506. NE_flags[0] |= frv_interrupt_state.f_ne_flags[0];
  507. NE_flags[1] |= frv_interrupt_state.f_ne_flags[1];
  508. SET_NE_FLAGS (H_SPR_FNER0, NE_flags);
  509. }
  510. /* If there is no interrupt pending, then perform parallel writeback. This
  511. may cause an interrupt. */
  512. if (frv_interrupt_state.queue_index <= 0)
  513. frvbf_perform_writeback (current_cpu);
  514. /* If there is an interrupt pending, then process it. */
  515. if (frv_interrupt_state.queue_index > 0)
  516. handle_interrupt (current_cpu, pc);
  517. }
  518. /* Find the next available ESR and return its index */
  519. static int
  520. esr_for_data_access_exception (
  521. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  522. )
  523. {
  524. SIM_DESC sd = CPU_STATE (current_cpu);
  525. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  526. return 8; /* Use ESR8, EPCR8. */
  527. if (item->slot == UNIT_I0)
  528. return 8; /* Use ESR8, EPCR8, EAR8, EDR8. */
  529. return 9; /* Use ESR9, EPCR9, EAR9. */
  530. }
  531. /* Set the next available EDR register with the data which was to be stored
  532. and return the index of the register. */
  533. static int
  534. set_edr_register (
  535. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item, int edr_index
  536. )
  537. {
  538. /* EDR0, EDR4 and EDR8 are available as blocks of 4.
  539. SI data uses EDR3, EDR7 and EDR11
  540. DI data uses EDR2, EDR6 and EDR10
  541. XI data uses EDR0, EDR4 and EDR8. */
  542. int i;
  543. edr_index += 4 - item->u.data_written.length;
  544. for (i = 0; i < item->u.data_written.length; ++i)
  545. SET_EDR (edr_index + i, item->u.data_written.words[i]);
  546. return edr_index;
  547. };
  548. /* Clear ESFR0, EPCRx, ESRx, EARx and EDRx. */
  549. static void
  550. clear_exception_status_registers (SIM_CPU *current_cpu)
  551. {
  552. int i;
  553. /* It is only necessary to clear the flag bits indicating which registers
  554. are valid. */
  555. SET_ESFR (0, 0);
  556. SET_ESFR (1, 0);
  557. for (i = 0; i <= 2; ++i)
  558. {
  559. SI esr = GET_ESR (i);
  560. CLEAR_ESR_VALID (esr);
  561. SET_ESR (i, esr);
  562. }
  563. for (i = 8; i <= 15; ++i)
  564. {
  565. SI esr = GET_ESR (i);
  566. CLEAR_ESR_VALID (esr);
  567. SET_ESR (i, esr);
  568. }
  569. }
  570. /* Record state for media exception. */
  571. void
  572. frv_set_mp_exception_registers (
  573. SIM_CPU *current_cpu, enum frv_msr_mtt mtt, int sie
  574. )
  575. {
  576. /* Record the interrupt factor in MSR0. */
  577. SI msr0 = GET_MSR (0);
  578. if (GET_MSR_MTT (msr0) == MTT_NONE)
  579. SET_MSR_MTT (msr0, mtt);
  580. /* Also set the OVF bit in the appropriate MSR as well as MSR0.AOVF. */
  581. if (mtt == MTT_OVERFLOW)
  582. {
  583. FRV_VLIW *vliw = CPU_VLIW (current_cpu);
  584. int slot = vliw->next_slot - 1;
  585. SIM_DESC sd = CPU_STATE (current_cpu);
  586. /* If this insn is in the M2 slot, then set MSR1.OVF and MSR1.SIE,
  587. otherwise set MSR0.OVF and MSR0.SIE. */
  588. if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550 && (*vliw->current_vliw)[slot] == UNIT_FM1)
  589. {
  590. SI msr = GET_MSR (1);
  591. OR_MSR_SIE (msr, sie);
  592. SET_MSR_OVF (msr);
  593. SET_MSR (1, msr);
  594. }
  595. else
  596. {
  597. OR_MSR_SIE (msr0, sie);
  598. SET_MSR_OVF (msr0);
  599. }
  600. /* Generate the interrupt now if MSR0.MPEM is set on fr550 */
  601. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550 && GET_MSR_MPEM (msr0))
  602. frv_queue_program_interrupt (current_cpu, FRV_MP_EXCEPTION);
  603. else
  604. {
  605. /* Regardless of the slot, set MSR0.AOVF. */
  606. SET_MSR_AOVF (msr0);
  607. }
  608. }
  609. SET_MSR (0, msr0);
  610. }
  611. /* Determine the correct FQ register to use for the given exception.
  612. Return -1 if a register is not available. */
  613. static int
  614. fq_for_exception (
  615. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  616. )
  617. {
  618. SI fq;
  619. struct frv_fp_exception_info *fp_info = & item->u.fp_info;
  620. /* For fp_exception overflow, underflow or inexact, use FQ0 or FQ1. */
  621. if (fp_info->ftt == FTT_IEEE_754_EXCEPTION
  622. && (fp_info->fsr_mask & (FSR_OVERFLOW | FSR_UNDERFLOW | FSR_INEXACT)))
  623. {
  624. fq = GET_FQ (0);
  625. if (! GET_FQ_VALID (fq))
  626. return 0; /* FQ0 is available. */
  627. fq = GET_FQ (1);
  628. if (! GET_FQ_VALID (fq))
  629. return 1; /* FQ1 is available. */
  630. /* No FQ register is available */
  631. {
  632. SIM_DESC sd = CPU_STATE (current_cpu);
  633. IADDR pc = CPU_PC_GET (current_cpu);
  634. sim_engine_abort (sd, current_cpu, pc, "No FQ register available\n");
  635. }
  636. return -1;
  637. }
  638. /* For other exceptions, use FQ2 if the insn was in slot F0/I0 and FQ3
  639. otherwise. */
  640. if (item->slot == UNIT_FM0 || item->slot == UNIT_I0)
  641. return 2;
  642. return 3;
  643. }
  644. /* Set FSR0, FQ0-FQ9, depending on the interrupt. */
  645. static void
  646. set_fp_exception_registers (
  647. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  648. )
  649. {
  650. int fq_index;
  651. SI fq;
  652. SI insn;
  653. SI fsr0;
  654. IADDR pc;
  655. struct frv_fp_exception_info *fp_info;
  656. SIM_DESC sd = CPU_STATE (current_cpu);
  657. /* No FQ registers on fr550 */
  658. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  659. {
  660. /* Update the fsr. */
  661. fp_info = & item->u.fp_info;
  662. fsr0 = GET_FSR (0);
  663. SET_FSR_FTT (fsr0, fp_info->ftt);
  664. SET_FSR (0, fsr0);
  665. return;
  666. }
  667. /* Select an FQ and update it with the exception information. */
  668. fq_index = fq_for_exception (current_cpu, item);
  669. if (fq_index == -1)
  670. return;
  671. fp_info = & item->u.fp_info;
  672. fq = GET_FQ (fq_index);
  673. SET_FQ_MIV (fq, MIV_FLOAT);
  674. SET_FQ_SIE (fq, SIE_NIL);
  675. SET_FQ_FTT (fq, fp_info->ftt);
  676. SET_FQ_CEXC (fq, fp_info->fsr_mask);
  677. SET_FQ_VALID (fq);
  678. SET_FQ (fq_index, fq);
  679. /* Write the failing insn into FQx.OPC. */
  680. pc = item->vpc;
  681. insn = GETMEMSI (current_cpu, pc, pc);
  682. SET_FQ_OPC (fq_index, insn);
  683. /* Update the fsr. */
  684. fsr0 = GET_FSR (0);
  685. SET_FSR_QNE (fsr0); /* FQ not empty */
  686. SET_FSR_FTT (fsr0, fp_info->ftt);
  687. SET_FSR (0, fsr0);
  688. }
  689. /* Record the state of a division exception in the ISR. */
  690. static void
  691. set_isr_exception_fields (
  692. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  693. )
  694. {
  695. USI isr = GET_ISR ();
  696. int dtt = GET_ISR_DTT (isr);
  697. dtt |= item->u.dtt;
  698. SET_ISR_DTT (isr, dtt);
  699. SET_ISR (isr);
  700. }
  701. /* Set ESFR0, EPCRx, ESRx, EARx and EDRx, according to the given program
  702. interrupt. */
  703. static void
  704. set_exception_status_registers (
  705. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  706. )
  707. {
  708. struct frv_interrupt *interrupt = & frv_interrupt_table[item->kind];
  709. int slot = (item->vpc - previous_vliw_pc) / 4;
  710. int reg_index = -1;
  711. int set_ear = 0;
  712. int set_edr = 0;
  713. int set_daec = 0;
  714. int set_epcr = 0;
  715. SI esr = 0;
  716. SIM_DESC sd = CPU_STATE (current_cpu);
  717. /* If the interrupt is strict (precise) or the interrupt is on the insns
  718. in the I0 pipe, then set the 0 registers. */
  719. if (interrupt->precise)
  720. {
  721. reg_index = 0;
  722. if (interrupt->kind == FRV_REGISTER_EXCEPTION)
  723. SET_ESR_REC (esr, item->u.rec);
  724. else if (interrupt->kind == FRV_INSTRUCTION_ACCESS_EXCEPTION)
  725. SET_ESR_IAEC (esr, item->u.iaec);
  726. /* For fr550, don't set epcr for precise interrupts. */
  727. if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
  728. set_epcr = 1;
  729. }
  730. else
  731. {
  732. switch (interrupt->kind)
  733. {
  734. case FRV_DIVISION_EXCEPTION:
  735. set_isr_exception_fields (current_cpu, item);
  736. /* fall thru to set reg_index. */
  737. case FRV_COMMIT_EXCEPTION:
  738. /* For fr550, always use ESR0. */
  739. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  740. reg_index = 0;
  741. else if (item->slot == UNIT_I0)
  742. reg_index = 0;
  743. else if (item->slot == UNIT_I1)
  744. reg_index = 1;
  745. set_epcr = 1;
  746. break;
  747. case FRV_DATA_STORE_ERROR:
  748. reg_index = 14; /* Use ESR14. */
  749. break;
  750. case FRV_DATA_ACCESS_ERROR:
  751. reg_index = 15; /* Use ESR15, EPCR15. */
  752. set_ear = 1;
  753. break;
  754. case FRV_DATA_ACCESS_EXCEPTION:
  755. set_daec = 1;
  756. /* fall through */
  757. case FRV_DATA_ACCESS_MMU_MISS:
  758. case FRV_MEM_ADDRESS_NOT_ALIGNED:
  759. /* Get the appropriate ESR, EPCR, EAR and EDR.
  760. EAR will be set. EDR will not be set if this is a store insn. */
  761. set_ear = 1;
  762. /* For fr550, never use EDRx. */
  763. if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
  764. if (item->u.data_written.length != 0)
  765. set_edr = 1;
  766. reg_index = esr_for_data_access_exception (current_cpu, item);
  767. set_epcr = 1;
  768. break;
  769. case FRV_MP_EXCEPTION:
  770. /* For fr550, use EPCR2 and ESR2. */
  771. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  772. {
  773. reg_index = 2;
  774. set_epcr = 1;
  775. }
  776. break; /* MSR0-1, FQ0-9 are already set. */
  777. case FRV_FP_EXCEPTION:
  778. set_fp_exception_registers (current_cpu, item);
  779. /* For fr550, use EPCR2 and ESR2. */
  780. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr550)
  781. {
  782. reg_index = 2;
  783. set_epcr = 1;
  784. }
  785. break;
  786. default:
  787. {
  788. SIM_DESC sd = CPU_STATE (current_cpu);
  789. IADDR pc = CPU_PC_GET (current_cpu);
  790. sim_engine_abort (sd, current_cpu, pc,
  791. "invalid non-strict program interrupt kind: %d\n",
  792. interrupt->kind);
  793. break;
  794. }
  795. }
  796. } /* non-strict (imprecise) interrupt */
  797. /* Now fill in the selected exception status registers. */
  798. if (reg_index != -1)
  799. {
  800. /* Now set the exception status registers. */
  801. SET_ESFR_FLAG (reg_index);
  802. SET_ESR_EC (esr, interrupt->ec);
  803. if (set_epcr)
  804. {
  805. if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr400)
  806. SET_EPCR (reg_index, previous_vliw_pc);
  807. else
  808. SET_EPCR (reg_index, item->vpc);
  809. }
  810. if (set_ear)
  811. {
  812. SET_EAR (reg_index, item->eaddress);
  813. SET_ESR_EAV (esr);
  814. }
  815. else
  816. CLEAR_ESR_EAV (esr);
  817. if (set_edr)
  818. {
  819. int edn = set_edr_register (current_cpu, item, 0/* EDR0-3 */);
  820. SET_ESR_EDN (esr, edn);
  821. SET_ESR_EDV (esr);
  822. }
  823. else
  824. CLEAR_ESR_EDV (esr);
  825. if (set_daec)
  826. SET_ESR_DAEC (esr, item->u.daec);
  827. SET_ESR_VALID (esr);
  828. SET_ESR (reg_index, esr);
  829. }
  830. }
  831. /* Check for compound interrupts.
  832. Returns NULL if no interrupt is to be processed. */
  833. static struct frv_interrupt *
  834. check_for_compound_interrupt (
  835. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item
  836. )
  837. {
  838. struct frv_interrupt *interrupt;
  839. /* Set the exception status registers for the original interrupt. */
  840. set_exception_status_registers (current_cpu, item);
  841. interrupt = & frv_interrupt_table[item->kind];
  842. if (! interrupt->precise)
  843. {
  844. IADDR vpc = 0;
  845. int mask = 0;
  846. vpc = item->vpc;
  847. mask = (1 << item->kind);
  848. /* Look for more queued program interrupts which are non-deferred
  849. (pending inhibit), imprecise (non-strict) different than an interrupt
  850. already found and caused by a different insn. A bit mask is used
  851. to keep track of interrupts which have already been detected. */
  852. while (item != frv_interrupt_state.queue)
  853. {
  854. enum frv_interrupt_kind kind;
  855. struct frv_interrupt *next_interrupt;
  856. --item;
  857. kind = item->kind;
  858. next_interrupt = & frv_interrupt_table[kind];
  859. if (next_interrupt->iclass != FRV_PROGRAM_INTERRUPT)
  860. break; /* no program interrupts left. */
  861. if (item->vpc == vpc)
  862. continue; /* caused by the same insn. */
  863. vpc = item->vpc;
  864. if (! next_interrupt->precise && ! next_interrupt->deferred)
  865. {
  866. if (! (mask & (1 << kind)))
  867. {
  868. /* Set the exception status registers for the additional
  869. interrupt. */
  870. set_exception_status_registers (current_cpu, item);
  871. mask |= (1 << kind);
  872. interrupt = & frv_interrupt_table[FRV_COMPOUND_EXCEPTION];
  873. }
  874. }
  875. }
  876. }
  877. /* Return with either the original interrupt, a compound_exception,
  878. or no exception. */
  879. return interrupt;
  880. }
  881. /* Handle a program interrupt. */
  882. void
  883. frv_program_interrupt (
  884. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item, IADDR pc
  885. )
  886. {
  887. struct frv_interrupt *interrupt;
  888. clear_exception_status_registers (current_cpu);
  889. /* If two or more non-deferred imprecise (non-strict) interrupts occur
  890. on two or more insns, then generate a compound_exception. */
  891. interrupt = check_for_compound_interrupt (current_cpu, item);
  892. if (interrupt != NULL)
  893. {
  894. frv_program_or_software_interrupt (current_cpu, interrupt, pc);
  895. frv_clear_interrupt_classes (FRV_SOFTWARE_INTERRUPT,
  896. FRV_PROGRAM_INTERRUPT);
  897. }
  898. }
  899. /* Handle a software interrupt. */
  900. void
  901. frv_software_interrupt (
  902. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item, IADDR pc
  903. )
  904. {
  905. struct frv_interrupt *interrupt = & frv_interrupt_table[item->kind];
  906. frv_program_or_software_interrupt (current_cpu, interrupt, pc);
  907. }
  908. /* Handle a program interrupt or a software interrupt in non-operating mode. */
  909. void
  910. frv_non_operating_interrupt (
  911. SIM_CPU *current_cpu, enum frv_interrupt_kind kind, IADDR pc
  912. )
  913. {
  914. SIM_DESC sd = CPU_STATE (current_cpu);
  915. switch (kind)
  916. {
  917. case FRV_INTERRUPT_LEVEL_1:
  918. case FRV_INTERRUPT_LEVEL_2:
  919. case FRV_INTERRUPT_LEVEL_3:
  920. case FRV_INTERRUPT_LEVEL_4:
  921. case FRV_INTERRUPT_LEVEL_5:
  922. case FRV_INTERRUPT_LEVEL_6:
  923. case FRV_INTERRUPT_LEVEL_7:
  924. case FRV_INTERRUPT_LEVEL_8:
  925. case FRV_INTERRUPT_LEVEL_9:
  926. case FRV_INTERRUPT_LEVEL_10:
  927. case FRV_INTERRUPT_LEVEL_11:
  928. case FRV_INTERRUPT_LEVEL_12:
  929. case FRV_INTERRUPT_LEVEL_13:
  930. case FRV_INTERRUPT_LEVEL_14:
  931. case FRV_INTERRUPT_LEVEL_15:
  932. sim_engine_abort (sd, current_cpu, pc,
  933. "interrupt: external %d\n", kind + 1);
  934. break;
  935. case FRV_TRAP_INSTRUCTION:
  936. break; /* handle as in operating mode. */
  937. case FRV_COMMIT_EXCEPTION:
  938. sim_engine_abort (sd, current_cpu, pc,
  939. "interrupt: commit_exception\n");
  940. break;
  941. case FRV_DIVISION_EXCEPTION:
  942. sim_engine_abort (sd, current_cpu, pc,
  943. "interrupt: division_exception\n");
  944. break;
  945. case FRV_DATA_STORE_ERROR:
  946. sim_engine_abort (sd, current_cpu, pc,
  947. "interrupt: data_store_error\n");
  948. break;
  949. case FRV_DATA_ACCESS_EXCEPTION:
  950. sim_engine_abort (sd, current_cpu, pc,
  951. "interrupt: data_access_exception\n");
  952. break;
  953. case FRV_DATA_ACCESS_MMU_MISS:
  954. sim_engine_abort (sd, current_cpu, pc,
  955. "interrupt: data_access_mmu_miss\n");
  956. break;
  957. case FRV_DATA_ACCESS_ERROR:
  958. sim_engine_abort (sd, current_cpu, pc,
  959. "interrupt: data_access_error\n");
  960. break;
  961. case FRV_MP_EXCEPTION:
  962. sim_engine_abort (sd, current_cpu, pc,
  963. "interrupt: mp_exception\n");
  964. break;
  965. case FRV_FP_EXCEPTION:
  966. sim_engine_abort (sd, current_cpu, pc,
  967. "interrupt: fp_exception\n");
  968. break;
  969. case FRV_MEM_ADDRESS_NOT_ALIGNED:
  970. sim_engine_abort (sd, current_cpu, pc,
  971. "interrupt: mem_address_not_aligned\n");
  972. break;
  973. case FRV_REGISTER_EXCEPTION:
  974. sim_engine_abort (sd, current_cpu, pc,
  975. "interrupt: register_exception\n");
  976. break;
  977. case FRV_MP_DISABLED:
  978. sim_engine_abort (sd, current_cpu, pc,
  979. "interrupt: mp_disabled\n");
  980. break;
  981. case FRV_FP_DISABLED:
  982. sim_engine_abort (sd, current_cpu, pc,
  983. "interrupt: fp_disabled\n");
  984. break;
  985. case FRV_PRIVILEGED_INSTRUCTION:
  986. sim_engine_abort (sd, current_cpu, pc,
  987. "interrupt: privileged_instruction\n");
  988. break;
  989. case FRV_ILLEGAL_INSTRUCTION:
  990. sim_engine_abort (sd, current_cpu, pc,
  991. "interrupt: illegal_instruction\n");
  992. break;
  993. case FRV_INSTRUCTION_ACCESS_EXCEPTION:
  994. sim_engine_abort (sd, current_cpu, pc,
  995. "interrupt: instruction_access_exception\n");
  996. break;
  997. case FRV_INSTRUCTION_ACCESS_MMU_MISS:
  998. sim_engine_abort (sd, current_cpu, pc,
  999. "interrupt: instruction_access_mmu_miss\n");
  1000. break;
  1001. case FRV_INSTRUCTION_ACCESS_ERROR:
  1002. sim_engine_abort (sd, current_cpu, pc,
  1003. "interrupt: insn_access_error\n");
  1004. break;
  1005. case FRV_COMPOUND_EXCEPTION:
  1006. sim_engine_abort (sd, current_cpu, pc,
  1007. "interrupt: compound_exception\n");
  1008. break;
  1009. case FRV_BREAK_EXCEPTION:
  1010. sim_engine_abort (sd, current_cpu, pc,
  1011. "interrupt: break_exception\n");
  1012. break;
  1013. case FRV_RESET:
  1014. sim_engine_abort (sd, current_cpu, pc,
  1015. "interrupt: reset\n");
  1016. break;
  1017. default:
  1018. sim_engine_abort (sd, current_cpu, pc,
  1019. "unhandled interrupt kind: %d\n", kind);
  1020. break;
  1021. }
  1022. }
  1023. /* Handle a break interrupt. */
  1024. void
  1025. frv_break_interrupt (
  1026. SIM_CPU *current_cpu, struct frv_interrupt *interrupt, IADDR current_pc
  1027. )
  1028. {
  1029. IADDR new_pc;
  1030. /* BPCSR=PC
  1031. BPSR.BS=PSR.S
  1032. BPSR.BET=PSR.ET
  1033. PSR.S=1
  1034. PSR.ET=0
  1035. TBR.TT=0xff
  1036. PC=TBR
  1037. */
  1038. /* Must set PSR.S first to allow access to supervisor-only spr registers. */
  1039. SET_H_BPSR_BS (GET_H_PSR_S ());
  1040. SET_H_BPSR_BET (GET_H_PSR_ET ());
  1041. SET_H_PSR_S (1);
  1042. SET_H_PSR_ET (0);
  1043. /* Must set PSR.S first to allow access to supervisor-only spr registers. */
  1044. SET_H_SPR (H_SPR_BPCSR, current_pc);
  1045. /* Set the new PC in the TBR. */
  1046. SET_H_TBR_TT (interrupt->handler_offset);
  1047. new_pc = GET_H_SPR (H_SPR_TBR);
  1048. SET_H_PC (new_pc);
  1049. CPU_DEBUG_STATE (current_cpu) = 1;
  1050. }
  1051. /* Handle a program interrupt or a software interrupt. */
  1052. void
  1053. frv_program_or_software_interrupt (
  1054. SIM_CPU *current_cpu, struct frv_interrupt *interrupt, IADDR current_pc
  1055. )
  1056. {
  1057. USI new_pc;
  1058. int original_psr_et;
  1059. /* PCSR=PC
  1060. PSR.PS=PSR.S
  1061. PSR.ET=0
  1062. PSR.S=1
  1063. if PSR.ESR==1
  1064. SR0 through SR3=GR4 through GR7
  1065. TBR.TT=interrupt handler offset
  1066. PC=TBR
  1067. */
  1068. original_psr_et = GET_H_PSR_ET ();
  1069. SET_H_PSR_PS (GET_H_PSR_S ());
  1070. SET_H_PSR_ET (0);
  1071. SET_H_PSR_S (1);
  1072. /* Must set PSR.S first to allow access to supervisor-only spr registers. */
  1073. /* The PCSR depends on the precision of the interrupt. */
  1074. if (interrupt->precise)
  1075. SET_H_SPR (H_SPR_PCSR, previous_vliw_pc);
  1076. else
  1077. SET_H_SPR (H_SPR_PCSR, current_pc);
  1078. /* Set the new PC in the TBR. */
  1079. SET_H_TBR_TT (interrupt->handler_offset);
  1080. new_pc = GET_H_SPR (H_SPR_TBR);
  1081. SET_H_PC (new_pc);
  1082. /* If PSR.ET was not originally set, then enter the stopped state. */
  1083. if (! original_psr_et)
  1084. {
  1085. SIM_DESC sd = CPU_STATE (current_cpu);
  1086. frv_non_operating_interrupt (current_cpu, interrupt->kind, current_pc);
  1087. sim_engine_halt (sd, current_cpu, NULL, new_pc, sim_stopped, SIM_SIGINT);
  1088. }
  1089. }
  1090. /* Handle a program interrupt or a software interrupt. */
  1091. void
  1092. frv_external_interrupt (
  1093. SIM_CPU *current_cpu, struct frv_interrupt_queue_element *item, IADDR pc
  1094. )
  1095. {
  1096. USI new_pc;
  1097. struct frv_interrupt *interrupt = & frv_interrupt_table[item->kind];
  1098. /* Don't process the interrupt if PSR.ET is not set or if it is masked.
  1099. Interrupt 15 is processed even if it appears to be masked. */
  1100. if (! GET_H_PSR_ET ()
  1101. || (interrupt->kind != FRV_INTERRUPT_LEVEL_15
  1102. && interrupt->kind < GET_H_PSR_PIL ()))
  1103. return; /* Leave it for later. */
  1104. /* Remove the interrupt from the queue. */
  1105. --frv_interrupt_state.queue_index;
  1106. /* PCSR=PC
  1107. PSR.PS=PSR.S
  1108. PSR.ET=0
  1109. PSR.S=1
  1110. if PSR.ESR==1
  1111. SR0 through SR3=GR4 through GR7
  1112. TBR.TT=interrupt handler offset
  1113. PC=TBR
  1114. */
  1115. SET_H_PSR_PS (GET_H_PSR_S ());
  1116. SET_H_PSR_ET (0);
  1117. SET_H_PSR_S (1);
  1118. /* Must set PSR.S first to allow access to supervisor-only spr registers. */
  1119. SET_H_SPR (H_SPR_PCSR, GET_H_PC ());
  1120. /* Set the new PC in the TBR. */
  1121. SET_H_TBR_TT (interrupt->handler_offset);
  1122. new_pc = GET_H_SPR (H_SPR_TBR);
  1123. SET_H_PC (new_pc);
  1124. }
  1125. /* Clear interrupts which fall within the range of classes given. */
  1126. void
  1127. frv_clear_interrupt_classes (
  1128. enum frv_interrupt_class low_class, enum frv_interrupt_class high_class
  1129. )
  1130. {
  1131. int i;
  1132. int j;
  1133. int limit = frv_interrupt_state.queue_index;
  1134. /* Find the lowest priority interrupt to be removed. */
  1135. for (i = 0; i < limit; ++i)
  1136. {
  1137. enum frv_interrupt_kind kind = frv_interrupt_state.queue[i].kind;
  1138. struct frv_interrupt* interrupt = & frv_interrupt_table[kind];
  1139. if (interrupt->iclass >= low_class)
  1140. break;
  1141. }
  1142. /* Find the highest priority interrupt to be removed. */
  1143. for (j = limit - 1; j >= i; --j)
  1144. {
  1145. enum frv_interrupt_kind kind = frv_interrupt_state.queue[j].kind;
  1146. struct frv_interrupt* interrupt = & frv_interrupt_table[kind];
  1147. if (interrupt->iclass <= high_class)
  1148. break;
  1149. }
  1150. /* Shuffle the remaining high priority interrupts down into the empty space
  1151. left by the deleted interrupts. */
  1152. if (j >= i)
  1153. {
  1154. for (++j; j < limit; ++j)
  1155. frv_interrupt_state.queue[i++] = frv_interrupt_state.queue[j];
  1156. frv_interrupt_state.queue_index -= (j - i);
  1157. }
  1158. }
  1159. /* Save data written to memory into the interrupt state so that it can be
  1160. copied to the appropriate EDR register, if necessary, in the event of an
  1161. interrupt. */
  1162. void
  1163. frv_save_data_written_for_interrupts (
  1164. SIM_CPU *current_cpu, CGEN_WRITE_QUEUE_ELEMENT *item
  1165. )
  1166. {
  1167. /* Record the slot containing the insn doing the write in the
  1168. interrupt state. */
  1169. frv_interrupt_state.slot = CGEN_WRITE_QUEUE_ELEMENT_PIPE (item);
  1170. /* Now record any data written to memory in the interrupt state. */
  1171. switch (CGEN_WRITE_QUEUE_ELEMENT_KIND (item))
  1172. {
  1173. case CGEN_BI_WRITE:
  1174. case CGEN_QI_WRITE:
  1175. case CGEN_SI_WRITE:
  1176. case CGEN_SF_WRITE:
  1177. case CGEN_PC_WRITE:
  1178. case CGEN_FN_HI_WRITE:
  1179. case CGEN_FN_SI_WRITE:
  1180. case CGEN_FN_SF_WRITE:
  1181. case CGEN_FN_DI_WRITE:
  1182. case CGEN_FN_DF_WRITE:
  1183. case CGEN_FN_XI_WRITE:
  1184. case CGEN_FN_PC_WRITE:
  1185. break; /* Ignore writes to registers. */
  1186. case CGEN_MEM_QI_WRITE:
  1187. frv_interrupt_state.data_written.length = 1;
  1188. frv_interrupt_state.data_written.words[0]
  1189. = item->kinds.mem_qi_write.value;
  1190. break;
  1191. case CGEN_MEM_HI_WRITE:
  1192. frv_interrupt_state.data_written.length = 1;
  1193. frv_interrupt_state.data_written.words[0]
  1194. = item->kinds.mem_hi_write.value;
  1195. break;
  1196. case CGEN_MEM_SI_WRITE:
  1197. frv_interrupt_state.data_written.length = 1;
  1198. frv_interrupt_state.data_written.words[0]
  1199. = item->kinds.mem_si_write.value;
  1200. break;
  1201. case CGEN_MEM_DI_WRITE:
  1202. frv_interrupt_state.data_written.length = 2;
  1203. frv_interrupt_state.data_written.words[0]
  1204. = item->kinds.mem_di_write.value >> 32;
  1205. frv_interrupt_state.data_written.words[1]
  1206. = item->kinds.mem_di_write.value;
  1207. break;
  1208. case CGEN_MEM_DF_WRITE:
  1209. frv_interrupt_state.data_written.length = 2;
  1210. frv_interrupt_state.data_written.words[0]
  1211. = item->kinds.mem_df_write.value >> 32;
  1212. frv_interrupt_state.data_written.words[1]
  1213. = item->kinds.mem_df_write.value;
  1214. break;
  1215. case CGEN_MEM_XI_WRITE:
  1216. frv_interrupt_state.data_written.length = 4;
  1217. frv_interrupt_state.data_written.words[0]
  1218. = item->kinds.mem_xi_write.value[0];
  1219. frv_interrupt_state.data_written.words[1]
  1220. = item->kinds.mem_xi_write.value[1];
  1221. frv_interrupt_state.data_written.words[2]
  1222. = item->kinds.mem_xi_write.value[2];
  1223. frv_interrupt_state.data_written.words[3]
  1224. = item->kinds.mem_xi_write.value[3];
  1225. break;
  1226. case CGEN_FN_MEM_QI_WRITE:
  1227. frv_interrupt_state.data_written.length = 1;
  1228. frv_interrupt_state.data_written.words[0]
  1229. = item->kinds.fn_mem_qi_write.value;
  1230. break;
  1231. case CGEN_FN_MEM_HI_WRITE:
  1232. frv_interrupt_state.data_written.length = 1;
  1233. frv_interrupt_state.data_written.words[0]
  1234. = item->kinds.fn_mem_hi_write.value;
  1235. break;
  1236. case CGEN_FN_MEM_SI_WRITE:
  1237. frv_interrupt_state.data_written.length = 1;
  1238. frv_interrupt_state.data_written.words[0]
  1239. = item->kinds.fn_mem_si_write.value;
  1240. break;
  1241. case CGEN_FN_MEM_DI_WRITE:
  1242. frv_interrupt_state.data_written.length = 2;
  1243. frv_interrupt_state.data_written.words[0]
  1244. = item->kinds.fn_mem_di_write.value >> 32;
  1245. frv_interrupt_state.data_written.words[1]
  1246. = item->kinds.fn_mem_di_write.value;
  1247. break;
  1248. case CGEN_FN_MEM_DF_WRITE:
  1249. frv_interrupt_state.data_written.length = 2;
  1250. frv_interrupt_state.data_written.words[0]
  1251. = item->kinds.fn_mem_df_write.value >> 32;
  1252. frv_interrupt_state.data_written.words[1]
  1253. = item->kinds.fn_mem_df_write.value;
  1254. break;
  1255. case CGEN_FN_MEM_XI_WRITE:
  1256. frv_interrupt_state.data_written.length = 4;
  1257. frv_interrupt_state.data_written.words[0]
  1258. = item->kinds.fn_mem_xi_write.value[0];
  1259. frv_interrupt_state.data_written.words[1]
  1260. = item->kinds.fn_mem_xi_write.value[1];
  1261. frv_interrupt_state.data_written.words[2]
  1262. = item->kinds.fn_mem_xi_write.value[2];
  1263. frv_interrupt_state.data_written.words[3]
  1264. = item->kinds.fn_mem_xi_write.value[3];
  1265. break;
  1266. default:
  1267. {
  1268. SIM_DESC sd = CPU_STATE (current_cpu);
  1269. IADDR pc = CPU_PC_GET (current_cpu);
  1270. sim_engine_abort (sd, current_cpu, pc,
  1271. "unknown write kind during save for interrupt\n");
  1272. }
  1273. break;
  1274. }
  1275. }