1 /* Blackfin Core Event Controller (CEC) model.
3 Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
6 This file is part of 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/>. */
21 /* This must come before any other includes. */
27 #include "sim-signal.h"
29 #include "dv-bfin_cec.h"
30 #include "dv-bfin_evt.h"
31 #include "dv-bfin_mmu.h"
38 struct hw_event
*pending
;
40 /* Order after here is important -- matches hardware MMR layout. */
41 bu32 evt_override
, imask
, ipend
, ilat
, iprio
;
43 #define mmr_base() offsetof(struct bfin_cec, evt_override)
44 #define mmr_offset(mmr) (offsetof(struct bfin_cec, mmr) - mmr_base())
46 static const char * const mmr_names
[] =
48 "EVT_OVERRIDE", "IMASK", "IPEND", "ILAT", "IPRIO",
50 #define mmr_name(off) mmr_names[(off) / 4]
52 static void _cec_raise (SIM_CPU
*, struct bfin_cec
*, int);
55 bfin_cec_hw_event_callback (struct hw
*me
, void *data
)
57 struct bfin_cec
*cec
= data
;
58 hw_event_queue_deschedule (me
, cec
->pending
);
59 _cec_raise (cec
->cpu
, cec
, -1);
63 bfin_cec_check_pending (struct hw
*me
, struct bfin_cec
*cec
)
67 cec
->pending
= hw_event_queue_schedule (me
, 0, bfin_cec_hw_event_callback
, cec
);
70 _cec_check_pending (SIM_CPU
*cpu
, struct bfin_cec
*cec
)
72 bfin_cec_check_pending (cec
->me
, cec
);
76 _cec_imask_write (struct bfin_cec
*cec
, bu32 value
)
78 cec
->imask
= (value
& IVG_MASKABLE_B
) | (cec
->imask
& IVG_UNMASKABLE_B
);
82 bfin_cec_io_write_buffer (struct hw
*me
, const void *source
,
83 int space
, address_word addr
, unsigned nr_bytes
)
85 struct bfin_cec
*cec
= hw_data (me
);
89 /* Invalid access mode is higher priority than missing register. */
90 if (!dv_bfin_mmr_require_32 (me
, addr
, nr_bytes
, true))
93 value
= dv_load_4 (source
);
94 mmr_off
= addr
- cec
->base
;
100 case mmr_offset(evt_override
):
101 cec
->evt_override
= value
;
103 case mmr_offset(imask
):
104 _cec_imask_write (cec
, value
);
105 bfin_cec_check_pending (me
, cec
);
107 case mmr_offset(ipend
):
108 /* Read-only register. */
110 case mmr_offset(ilat
):
111 dv_w1c_4 (&cec
->ilat
, value
, 0xffee);
113 case mmr_offset(iprio
):
114 cec
->iprio
= (value
& IVG_UNMASKABLE_B
);
122 bfin_cec_io_read_buffer (struct hw
*me
, void *dest
,
123 int space
, address_word addr
, unsigned nr_bytes
)
125 struct bfin_cec
*cec
= hw_data (me
);
129 /* Invalid access mode is higher priority than missing register. */
130 if (!dv_bfin_mmr_require_32 (me
, addr
, nr_bytes
, false))
133 mmr_off
= addr
- cec
->base
;
134 valuep
= (void *)((uintptr_t)cec
+ mmr_base() + mmr_off
);
138 dv_store_4 (dest
, *valuep
);
143 static const struct hw_port_descriptor bfin_cec_ports
[] =
145 { "emu", IVG_EMU
, 0, input_port
, },
146 { "rst", IVG_RST
, 0, input_port
, },
147 { "nmi", IVG_NMI
, 0, input_port
, },
148 { "evx", IVG_EVX
, 0, input_port
, },
149 { "ivhw", IVG_IVHW
, 0, input_port
, },
150 { "ivtmr", IVG_IVTMR
, 0, input_port
, },
151 { "ivg7", IVG7
, 0, input_port
, },
152 { "ivg8", IVG8
, 0, input_port
, },
153 { "ivg9", IVG9
, 0, input_port
, },
154 { "ivg10", IVG10
, 0, input_port
, },
155 { "ivg11", IVG11
, 0, input_port
, },
156 { "ivg12", IVG12
, 0, input_port
, },
157 { "ivg13", IVG13
, 0, input_port
, },
158 { "ivg14", IVG14
, 0, input_port
, },
159 { "ivg15", IVG15
, 0, input_port
, },
164 bfin_cec_port_event (struct hw
*me
, int my_port
, struct hw
*source
,
165 int source_port
, int level
)
167 struct bfin_cec
*cec
= hw_data (me
);
168 _cec_raise (cec
->cpu
, cec
, my_port
);
172 attach_bfin_cec_regs (struct hw
*me
, struct bfin_cec
*cec
)
174 address_word attach_address
;
176 unsigned attach_size
;
177 reg_property_spec reg
;
179 if (hw_find_property (me
, "reg") == NULL
)
180 hw_abort (me
, "Missing \"reg\" property");
182 if (!hw_find_reg_array_property (me
, "reg", 0, ®
))
183 hw_abort (me
, "\"reg\" property must contain three addr/size entries");
185 hw_unit_address_to_attach_address (hw_parent (me
),
187 &attach_space
, &attach_address
, me
);
188 hw_unit_size_to_attach_size (hw_parent (me
), ®
.size
, &attach_size
, me
);
190 if (attach_size
!= BFIN_COREMMR_CEC_SIZE
)
191 hw_abort (me
, "\"reg\" size must be %#x", BFIN_COREMMR_CEC_SIZE
);
193 hw_attach_address (hw_parent (me
),
194 0, attach_space
, attach_address
, attach_size
, me
);
196 cec
->base
= attach_address
;
197 /* XXX: should take from the device tree. */
198 cec
->cpu
= STATE_CPU (hw_system (me
), 0);
203 bfin_cec_finish (struct hw
*me
)
205 struct bfin_cec
*cec
;
207 cec
= HW_ZALLOC (me
, struct bfin_cec
);
209 set_hw_data (me
, cec
);
210 set_hw_io_read_buffer (me
, bfin_cec_io_read_buffer
);
211 set_hw_io_write_buffer (me
, bfin_cec_io_write_buffer
);
212 set_hw_ports (me
, bfin_cec_ports
);
213 set_hw_port_event (me
, bfin_cec_port_event
);
215 attach_bfin_cec_regs (me
, cec
);
217 /* Initialize the CEC. */
218 cec
->imask
= IVG_UNMASKABLE_B
;
219 cec
->ipend
= IVG_RST_B
| IVG_IRPTEN_B
;
222 const struct hw_descriptor dv_bfin_cec_descriptor
[] =
224 {"bfin_cec", bfin_cec_finish
,},
228 static const char * const excp_decoded
[] =
230 [VEC_SYS
] = "Custom exception 0 (system call)",
231 [VEC_EXCPT01
] = "Custom exception 1 (software breakpoint)",
232 [VEC_EXCPT02
] = "Custom exception 2 (KGDB hook)",
233 [VEC_EXCPT03
] = "Custom exception 3 (userspace stack overflow)",
234 [VEC_EXCPT04
] = "Custom exception 4 (dump trace buffer)",
235 [VEC_EXCPT05
] = "Custom exception 5",
236 [VEC_EXCPT06
] = "Custom exception 6",
237 [VEC_EXCPT07
] = "Custom exception 7",
238 [VEC_EXCPT08
] = "Custom exception 8",
239 [VEC_EXCPT09
] = "Custom exception 9",
240 [VEC_EXCPT10
] = "Custom exception 10",
241 [VEC_EXCPT11
] = "Custom exception 11",
242 [VEC_EXCPT12
] = "Custom exception 12",
243 [VEC_EXCPT13
] = "Custom exception 13",
244 [VEC_EXCPT14
] = "Custom exception 14",
245 [VEC_EXCPT15
] = "Custom exception 15",
246 [VEC_STEP
] = "Hardware single step",
247 [VEC_OVFLOW
] = "Trace buffer overflow",
248 [VEC_UNDEF_I
] = "Undefined instruction",
249 [VEC_ILGAL_I
] = "Illegal instruction combo (multi-issue)",
250 [VEC_CPLB_VL
] = "DCPLB protection violation",
251 [VEC_MISALI_D
] = "Unaligned data access",
252 [VEC_UNCOV
] = "Unrecoverable event (double fault)",
253 [VEC_CPLB_M
] = "DCPLB miss",
254 [VEC_CPLB_MHIT
] = "Multiple DCPLB hit",
255 [VEC_WATCH
] = "Watchpoint match",
256 [VEC_ISTRU_VL
] = "ADSP-BF535 only",
257 [VEC_MISALI_I
] = "Unaligned instruction access",
258 [VEC_CPLB_I_VL
] = "ICPLB protection violation",
259 [VEC_CPLB_I_M
] = "ICPLB miss",
260 [VEC_CPLB_I_MHIT
] = "Multiple ICPLB hit",
261 [VEC_ILL_RES
] = "Illegal supervisor resource",
264 #define CEC_STATE(cpu) DV_STATE_CACHED (cpu, cec)
266 #define __cec_get_ivg(val) (ffs ((val) & ~IVG_IRPTEN_B) - 1)
267 #define _cec_get_ivg(cec) __cec_get_ivg ((cec)->ipend & ~IVG_EMU_B)
270 cec_get_ivg (SIM_CPU
*cpu
)
272 switch (STATE_ENVIRONMENT (CPU_STATE (cpu
)))
274 case OPERATING_ENVIRONMENT
:
275 return _cec_get_ivg (CEC_STATE (cpu
));
282 _cec_is_supervisor_mode (struct bfin_cec
*cec
)
284 return (cec
->ipend
& ~(IVG_EMU_B
| IVG_IRPTEN_B
));
287 cec_is_supervisor_mode (SIM_CPU
*cpu
)
289 switch (STATE_ENVIRONMENT (CPU_STATE (cpu
)))
291 case OPERATING_ENVIRONMENT
:
292 return _cec_is_supervisor_mode (CEC_STATE (cpu
));
293 case USER_ENVIRONMENT
:
300 _cec_is_user_mode (struct bfin_cec
*cec
)
302 return !_cec_is_supervisor_mode (cec
);
305 cec_is_user_mode (SIM_CPU
*cpu
)
307 return !cec_is_supervisor_mode (cpu
);
310 _cec_require_supervisor (SIM_CPU
*cpu
, struct bfin_cec
*cec
)
312 if (_cec_is_user_mode (cec
))
313 cec_exception (cpu
, VEC_ILL_RES
);
316 cec_require_supervisor (SIM_CPU
*cpu
)
318 /* Do not call _cec_require_supervisor() to avoid CEC_STATE()
319 as that macro requires OS operating mode. */
320 if (cec_is_user_mode (cpu
))
321 cec_exception (cpu
, VEC_ILL_RES
);
324 #define excp_to_sim_halt(reason, sigrc) \
325 sim_engine_halt (CPU_STATE (cpu), cpu, NULL, PCREG, reason, sigrc)
327 cec_exception (SIM_CPU
*cpu
, int excp
)
329 SIM_DESC sd
= CPU_STATE (cpu
);
332 TRACE_EVENTS (cpu
, "processing exception %#x in EVT%i", excp
,
335 /* Ideally what would happen here for real hardware exceptions (not
336 fake sim ones) is that:
337 - For service exceptions (excp <= 0x11):
338 RETX is the _next_ PC which can be tricky with jumps/hardware loops/...
339 - For error exceptions (excp > 0x11):
340 RETX is the _current_ PC (i.e. the one causing the exception)
341 - PC is loaded with EVT3 MMR
342 - ILAT/IPEND in CEC is updated depending on current IVG level
343 - the fault address MMRs get updated with data/instruction info
344 - Execution continues on in the EVT3 handler */
346 /* Handle simulator exceptions first. */
350 excp_to_sim_halt (sim_exited
, 0);
353 excp_to_sim_halt (sim_exited
, 1);
356 /* GDB expects us to step over EMUEXCPT. */
357 /* XXX: What about hwloops and EMUEXCPT at the end?
358 Pretty sure gdb doesn't handle this already... */
359 SET_PCREG (PCREG
+ 2);
360 /* Only trap when we are running in gdb. */
361 if (STATE_OPEN_KIND (sd
) == SIM_OPEN_DEBUG
)
362 excp_to_sim_halt (sim_stopped
, SIM_SIGTRAP
);
365 /* If running in gdb, simply trap. */
366 if (STATE_OPEN_KIND (sd
) == SIM_OPEN_DEBUG
)
367 excp_to_sim_halt (sim_stopped
, SIM_SIGTRAP
);
369 excp_to_sim_halt (sim_exited
, 2);
375 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
377 /* ICPLB regs always get updated. */
378 /* XXX: Should optimize this call path ... */
379 if (excp
!= VEC_MISALI_I
&& excp
!= VEC_MISALI_D
380 && excp
!= VEC_CPLB_I_M
&& excp
!= VEC_CPLB_M
381 && excp
!= VEC_CPLB_I_VL
&& excp
!= VEC_CPLB_VL
382 && excp
!= VEC_CPLB_I_MHIT
&& excp
!= VEC_CPLB_MHIT
)
383 mmu_log_ifault (cpu
);
384 _cec_raise (cpu
, CEC_STATE (cpu
), IVG_EVX
);
385 /* We need to restart the engine so that we don't return
386 and continue processing this bad insn. */
388 sim_engine_restart (sd
, cpu
, NULL
, PCREG
);
393 TRACE_EVENTS (cpu
, "running virtual exception handler");
401 case VEC_EXCPT01
: /* Userspace gdb breakpoint. */
405 case VEC_UNDEF_I
: /* Undefined instruction. */
409 case VEC_ILL_RES
: /* Illegal supervisor resource. */
410 case VEC_MISALI_I
: /* Misaligned instruction. */
420 sim_io_eprintf (sd
, "Unhandled exception %#x at 0x%08x (%s)\n",
421 excp
, PCREG
, excp_decoded
[excp
]);
427 excp_to_sim_halt (sim_stopped
, sigrc
);
430 bu32
cec_cli (SIM_CPU
*cpu
)
432 struct bfin_cec
*cec
;
435 if (STATE_ENVIRONMENT (CPU_STATE (cpu
)) != OPERATING_ENVIRONMENT
)
438 cec
= CEC_STATE (cpu
);
439 _cec_require_supervisor (cpu
, cec
);
441 /* XXX: what about IPEND[4] ? */
442 old_mask
= cec
->imask
;
443 _cec_imask_write (cec
, 0);
445 TRACE_EVENTS (cpu
, "CLI changed IMASK from %#x to %#x", old_mask
, cec
->imask
);
450 void cec_sti (SIM_CPU
*cpu
, bu32 ints
)
452 struct bfin_cec
*cec
;
455 if (STATE_ENVIRONMENT (CPU_STATE (cpu
)) != OPERATING_ENVIRONMENT
)
458 cec
= CEC_STATE (cpu
);
459 _cec_require_supervisor (cpu
, cec
);
461 /* XXX: what about IPEND[4] ? */
462 old_mask
= cec
->imask
;
463 _cec_imask_write (cec
, ints
);
465 TRACE_EVENTS (cpu
, "STI changed IMASK from %#x to %#x", old_mask
, cec
->imask
);
467 /* Check for pending interrupts that are now enabled. */
468 _cec_check_pending (cpu
, cec
);
472 cec_irpten_enable (SIM_CPU
*cpu
, struct bfin_cec
*cec
)
474 /* Globally mask interrupts. */
475 TRACE_EVENTS (cpu
, "setting IPEND[4] to globally mask interrupts");
476 cec
->ipend
|= IVG_IRPTEN_B
;
480 cec_irpten_disable (SIM_CPU
*cpu
, struct bfin_cec
*cec
)
482 /* Clear global interrupt mask. */
483 TRACE_EVENTS (cpu
, "clearing IPEND[4] to not globally mask interrupts");
484 cec
->ipend
&= ~IVG_IRPTEN_B
;
488 _cec_raise (SIM_CPU
*cpu
, struct bfin_cec
*cec
, int ivg
)
490 SIM_DESC sd
= CPU_STATE (cpu
);
491 int curr_ivg
= _cec_get_ivg (cec
);
495 TRACE_EVENTS (cpu
, "processing request for EVT%i while at EVT%i",
498 irpten
= (cec
->ipend
& IVG_IRPTEN_B
);
499 snen
= (SYSCFGREG
& SYSCFG_SNEN
);
504 /* Just check for higher latched interrupts. */
508 goto done
; /* All interrupts are masked anyways. */
510 ivg
= __cec_get_ivg (cec
->ilat
& cec
->imask
);
512 goto done
; /* Nothing latched. */
515 goto done
; /* Nothing higher latched. */
517 if (!snen
&& ivg
== curr_ivg
)
518 goto done
; /* Self nesting disabled. */
520 /* Still here, so fall through to raise to higher pending. */
523 cec
->ilat
|= (1 << ivg
);
527 /* These two are always processed. */
528 if (ivg
== IVG_EMU
|| ivg
== IVG_RST
)
531 /* Anything lower might trigger a double fault. */
534 /* Double fault ! :( */
535 SET_EXCAUSE (VEC_UNCOV
);
536 /* XXX: SET_RETXREG (...); */
537 sim_io_error (sd
, "%s: double fault at 0x%08x ! :(", __func__
, PCREG
);
538 excp_to_sim_halt (sim_stopped
, SIM_SIGABRT
);
541 /* No double fault -> always process. */
544 else if (irpten
&& curr_ivg
!= IVG_USER
)
546 /* Interrupts are globally masked. */
548 else if (!(cec
->imask
& (1 << ivg
)))
550 /* This interrupt is masked. */
552 else if (ivg
< curr_ivg
|| (snen
&& ivg
== curr_ivg
))
558 cec
->ipend
|= (1 << ivg
);
559 cec
->ilat
&= ~(1 << ivg
);
561 /* Interrupts are processed in between insns which means the return
562 point is the insn-to-be-executed (which is the current PC). But
563 exceptions are handled while executing an insn, so we may have to
564 advance the PC ourselves when setting RETX.
565 XXX: Advancing the PC should only be for "service" exceptions, and
566 handling them after executing the insn should be OK, which
567 means we might be able to use the event interface for it. */
573 /* Signal the JTAG ICE. */
574 /* XXX: what happens with 'raise 0' ? */
576 excp_to_sim_halt (sim_stopped
, SIM_SIGTRAP
);
577 /* XXX: Need an easy way for gdb to signal it isnt here. */
578 cec
->ipend
&= ~IVG_EMU_B
;
581 /* Have the core reset simply exit (i.e. "shutdown"). */
582 excp_to_sim_halt (sim_exited
, 0);
585 /* XXX: Should check this. */
589 /* Non-service exceptions point to the excepting instruction. */
594 bu32 nextpc
= hwloop_get_next_pc (cpu
, oldpc
, INSN_LEN
);
595 SET_RETXREG (nextpc
);
600 /* XXX: what happens with 'raise 4' ? */
601 sim_io_error (sd
, "%s: what to do with 'raise 4' ?", __func__
);
604 SET_RETIREG (oldpc
| (ivg
== curr_ivg
? 1 : 0));
608 /* If EVT_OVERRIDE is in effect (IVG7+), use the reset address. */
609 if ((cec
->evt_override
& 0xff80) & (1 << ivg
))
610 SET_PCREG (cec_get_reset_evt (cpu
));
612 SET_PCREG (cec_get_evt (cpu
, ivg
));
614 BFIN_TRACE_BRANCH (cpu
, oldpc
, PCREG
, -1, "CEC changed PC (to EVT%i):", ivg
);
615 BFIN_CPU_STATE
.did_jump
= true;
617 /* Enable the global interrupt mask upon interrupt entry. */
619 cec_irpten_enable (cpu
, cec
);
622 /* When moving between states, don't let internal states bleed through. */
625 /* When going from user to super, we set LSB in LB regs to avoid
626 misbehavior and/or malicious code.
627 Also need to load SP alias with KSP. */
628 if (curr_ivg
== IVG_USER
)
631 for (i
= 0; i
< 2; ++i
)
632 if (!(LBREG (i
) & 1))
633 SET_LBREG (i
, LBREG (i
) | 1);
639 TRACE_EVENTS (cpu
, "now at EVT%i", _cec_get_ivg (cec
));
643 cec_read_ret_reg (SIM_CPU
*cpu
, int ivg
)
647 case IVG_EMU
: return RETEREG
;
648 case IVG_NMI
: return RETNREG
;
649 case IVG_EVX
: return RETXREG
;
650 default: return RETIREG
;
655 cec_latch (SIM_CPU
*cpu
, int ivg
)
657 struct bfin_cec
*cec
;
659 if (STATE_ENVIRONMENT (CPU_STATE (cpu
)) != OPERATING_ENVIRONMENT
)
662 SET_PCREG (cec_read_ret_reg (cpu
, ivg
));
663 BFIN_TRACE_BRANCH (cpu
, oldpc
, PCREG
, -1, "CEC changed PC");
667 cec
= CEC_STATE (cpu
);
668 cec
->ilat
|= (1 << ivg
);
669 _cec_check_pending (cpu
, cec
);
673 cec_hwerr (SIM_CPU
*cpu
, int hwerr
)
675 SET_HWERRCAUSE (hwerr
);
676 cec_latch (cpu
, IVG_IVHW
);
680 cec_return (SIM_CPU
*cpu
, int ivg
)
682 SIM_DESC sd
= CPU_STATE (cpu
);
683 struct bfin_cec
*cec
;
690 BFIN_CPU_STATE
.did_jump
= true;
691 if (STATE_ENVIRONMENT (sd
) != OPERATING_ENVIRONMENT
)
693 SET_PCREG (cec_read_ret_reg (cpu
, ivg
));
694 BFIN_TRACE_BRANCH (cpu
, oldpc
, PCREG
, -1, "CEC changed PC");
698 cec
= CEC_STATE (cpu
);
700 /* XXX: This isn't entirely correct ... */
701 cec
->ipend
&= ~IVG_EMU_B
;
703 curr_ivg
= _cec_get_ivg (cec
);
709 TRACE_EVENTS (cpu
, "returning from EVT%i (should be EVT%i)", curr_ivg
, ivg
);
711 /* Not allowed to return from usermode. */
712 if (curr_ivg
== IVG_USER
)
713 cec_exception (cpu
, VEC_ILL_RES
);
715 if (ivg
> IVG15
|| ivg
< 0)
716 sim_io_error (sd
, "%s: ivg %i out of range !", __func__
, ivg
);
718 _cec_require_supervisor (cpu
, cec
);
723 /* RTE -- only valid in emulation mode. */
724 /* XXX: What does the hardware do ? */
725 if (curr_ivg
!= IVG_EMU
)
726 cec_exception (cpu
, VEC_ILL_RES
);
729 /* RTN -- only valid in NMI. */
730 /* XXX: What does the hardware do ? */
731 if (curr_ivg
!= IVG_NMI
)
732 cec_exception (cpu
, VEC_ILL_RES
);
735 /* RTX -- only valid in exception. */
736 /* XXX: What does the hardware do ? */
737 if (curr_ivg
!= IVG_EVX
)
738 cec_exception (cpu
, VEC_ILL_RES
);
741 /* RTI -- not valid in emulation, nmi, exception, or user. */
742 /* XXX: What does the hardware do ? */
743 if (curr_ivg
== IVG_EMU
|| curr_ivg
== IVG_NMI
744 || curr_ivg
== IVG_EVX
|| curr_ivg
== IVG_USER
)
745 cec_exception (cpu
, VEC_ILL_RES
);
748 /* XXX: Is this even possible ? */
749 excp_to_sim_halt (sim_stopped
, SIM_SIGABRT
);
752 newpc
= cec_read_ret_reg (cpu
, ivg
);
754 /* XXX: Does this nested trick work on EMU/NMI/EVX ? */
756 /* XXX: Delayed clear shows bad PCREG register trace above ? */
757 SET_PCREG (newpc
& ~1);
759 BFIN_TRACE_BRANCH (cpu
, oldpc
, PCREG
, -1, "CEC changed PC (from EVT%i)", ivg
);
761 /* Update ipend after the BFIN_TRACE_BRANCH so dv-bfin_trace
762 knows current CEC state wrt overflow. */
764 cec
->ipend
&= ~(1 << ivg
);
766 /* Disable global interrupt mask to let any interrupt take over, but
767 only when we were already in a RTI level. Only way we could have
768 raised at that point is if it was cleared in the first place. */
769 if (ivg
>= IVG_IVHW
|| ivg
== IVG_RST
)
770 cec_irpten_disable (cpu
, cec
);
772 /* When going from super to user, we clear LSB in LB regs in case
773 it was set on the transition up.
774 Also need to load SP alias with USP. */
775 if (_cec_get_ivg (cec
) == -1)
778 for (i
= 0; i
< 2; ++i
)
780 SET_LBREG (i
, LBREG (i
) & ~1);
785 /* Check for pending interrupts before we return to usermode. */
786 _cec_check_pending (cpu
, cec
);
790 cec_push_reti (SIM_CPU
*cpu
)
792 /* XXX: Need to check hardware with popped RETI value
793 and bit 1 is set (when handling nested interrupts).
794 Also need to check behavior wrt SNEN in SYSCFG. */
795 struct bfin_cec
*cec
;
797 if (STATE_ENVIRONMENT (CPU_STATE (cpu
)) != OPERATING_ENVIRONMENT
)
800 TRACE_EVENTS (cpu
, "pushing RETI");
802 cec
= CEC_STATE (cpu
);
803 cec_irpten_disable (cpu
, cec
);
804 /* Check for pending interrupts. */
805 _cec_check_pending (cpu
, cec
);
809 cec_pop_reti (SIM_CPU
*cpu
)
811 /* XXX: Need to check hardware with popped RETI value
812 and bit 1 is set (when handling nested interrupts).
813 Also need to check behavior wrt SNEN in SYSCFG. */
814 struct bfin_cec
*cec
;
816 if (STATE_ENVIRONMENT (CPU_STATE (cpu
)) != OPERATING_ENVIRONMENT
)
819 TRACE_EVENTS (cpu
, "popping RETI");
821 cec
= CEC_STATE (cpu
);
822 cec_irpten_enable (cpu
, cec
);