1 #include <aros/kernel.h>
2 #include <proto/exec.h>
6 #include <kernel_base.h>
7 #include <kernel_cpu.h>
8 #include <kernel_debug.h>
9 #include <kernel_interrupts.h>
10 #include <kernel_memory.h>
12 /* We use own implementation of bug(), so we don't need aros/debug.h */
15 /*****************************************************************************
18 #include <proto/kernel.h>
20 AROS_LH4(void *, KrnAddExceptionHandler
,
23 AROS_LHA(uint8_t, num
, D0
),
24 AROS_LHA(exhandler_t
*, handler
, A0
),
25 AROS_LHA(void *, handlerData
, A1
),
26 AROS_LHA(void *, handlerData2
, A2
),
29 struct KernelBase
*, KernelBase
, 14, Kernel
)
32 Add a raw CPU exception handler to the chain of handlers.
35 num - CPU-specific exception number
36 handler - Pointer to a handler function
38 handlerData2 - User-defined data which is passed to the
41 Handler function uses a C calling convention and must be
44 int ExceptionHandler(void *ctx, void *handlerData, void *handlerData2)
46 handlerData and handlerData2 will be values passed to the
47 KrnAddExceptionHandler() function. ctx is a CPU context handle.
48 Consider this parameter private and reserved for now.
50 Exception handler should return nonzero value if it processes the
51 exception and wants to continue program execution. Otherwise it should
52 return zero. If all exception handlers in the chain return zero, the
53 exception will be passed on to exec.library trap handler pointed to
54 by tc_TrapCode field of task structure.
57 An opaque handle that can be used for handler removal or NULL in case
58 of failure (like unsupported exception number).
61 The specification of this function is preliminary and subject to change.
62 Consider it private for now.
69 KrnRemExceptionHandler()
73 ******************************************************************************/
77 struct IntrNode
*handle
= NULL
;
78 D(bug("[KRN] KrnAddExceptionHandler(%02x, %012p, %012p, %012p):\n", num
, handler
, handlerData
, handlerData2
));
80 if (num
< EXCEPTIONS_COUNT
)
82 /* Go to supervisor mode */
85 /* Allocate protected memory, accessible only in supervisor mode */
86 handle
= krnAllocMem(sizeof(struct IntrNode
), 0);
87 D(bug("[KRN] handle=%012p\n", handle
));
91 handle
->in_Handler
= handler
;
92 handle
->in_HandlerData
= handlerData
;
93 handle
->in_HandlerData2
= handlerData2
;
94 handle
->in_type
= it_exception
;
98 ADDHEAD(&KernelBase
->kb_Exceptions
[num
], &handle
->in_Node
);
110 /* Run exception handlers and accumulate return value */
111 int krnRunExceptionHandlers(uint8_t exception
, void *ctx
)
113 struct IntrNode
*in
, *in2
;
116 /* We can be called really early. Protect against this. */
120 ForeachNodeSafe(&KernelBase
->kb_Exceptions
[exception
], in
, in2
)
122 exhandler_t h
= in
->in_Handler
;
125 ret
|= h(ctx
, in
->in_HandlerData
, in
->in_HandlerData2
);