gint/src/core/exch.s
Lephe 5630814897
core: allow custom panics and exception catching
This change introduces two new mechanismes for executing user code when
an exception occurs.

* This first is the custom panic message, which usually displays "System
  ERROR". The function that performs this task can now be user-defined.
  It is also run in user mode because the exception handler rte's into
  it, allowing it to execute any kind of interrupt-inducing task. The
  behavior is undefined if this function raises an exception.

* The second is an exception-catching function, which (when set) is
  called every time an exception occurs, and is granted the chance of
  handling the exception to continue execution normally. It can be used
  in various ways, the most primitive of which is recording the
  exception and going back. It runs in interrupt mode and must not raise
  any kind of exception.
2019-09-13 08:10:30 +02:00

54 lines
740 B
ArmAsm

.global _gint_exch_tlbh
.section .gint.exch_tlbh
.align 4
_gint_exch_tlbh:
sts.l pr, @-r15
mov.l r8, @-r15
mov.l .expevt, r8
/* Panic if the catcher is NULL */
mov.l .catcher, r0
mov.l @r0, r0
tst r0, r0
bt panic
/* Leave if the catcher returns zero */
jsr @r0
mov.l @r8, r4
tst r0, r0
bt end
panic:
/* RTE to the panic function, but manually, so that SPC is preserved */
mov.l @r8, r4
ldc r4, r4_bank
mov.l @r15+, r8
lds.l @r15+, pr
/* Here we switch banks so r0..r7 change meaning! */
stc ssr, r0
ldc r0, sr
mov.l .panic, r0
mov.l @r0, r0
jmp @r0
nop
end:
mov.l @r15+, r8
lds.l @r15+, pr
rte
nop
.align 4
.expevt:
.long 0xff000024
.catcher:
.long _gint_exc_catcher
.panic:
.long _gint_exc_panic