2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
8 #include <aros/kernel.h>
9 #include <proto/exec.h>
13 #include <kernel_base.h>
14 #include <kernel_cpu.h>
15 #include <kernel_debug.h>
16 #include <kernel_interrupts.h>
17 #include <kernel_objects.h>
19 /* We use own implementation of bug(), so we don't need aros/debug.h */
22 /*****************************************************************************
25 #include <proto/kernel.h>
27 AROS_LH4(void *, KrnAddExceptionHandler
,
30 AROS_LHA(uint8_t, num
, D0
),
31 AROS_LHA(exhandler_t
*, handler
, A0
),
32 AROS_LHA(void *, handlerData
, A1
),
33 AROS_LHA(void *, handlerData2
, A2
),
36 struct KernelBase
*, KernelBase
, 14, Kernel
)
39 Add a raw CPU exception handler to the chain of handlers.
42 num - CPU-specific exception number
43 handler - Pointer to a handler function
45 handlerData2 - User-defined data which is passed to the
48 Handler function uses a C calling convention and must be
51 int ExceptionHandler(void *ctx, void *handlerData, void *handlerData2)
53 handlerData and handlerData2 will be values passed to the
54 KrnAddExceptionHandler() function. ctx is a CPU context handle.
55 Consider this parameter private and reserved for now.
57 Exception handler should return nonzero value if it processes the
58 exception and wants to continue program execution. Otherwise it should
59 return zero. If all exception handlers in the chain return zero, the
60 exception will be passed on to exec.library trap handler pointed to
61 by tc_TrapCode field of task structure.
64 An opaque handle that can be used for handler removal or NULL in case
65 of failure (like unsupported exception number).
68 The specification of this function is preliminary and subject to change.
69 Consider it private for now.
76 KrnRemExceptionHandler()
80 ******************************************************************************/
84 struct IntrNode
*handle
= NULL
;
85 D(bug("[KRN] KrnAddExceptionHandler(%02x, %012p, %012p, %012p):\n", num
, handler
, handlerData
, handlerData2
));
87 if (num
< EXCEPTIONS_COUNT
)
89 /* Go to supervisor mode */
92 /* Allocate protected memory, accessible only in supervisor mode */
93 handle
= krnAllocIntrNode();
94 D(bug("[KRN] handle=%012p\n", handle
));
98 handle
->in_Handler
= handler
;
99 handle
->in_HandlerData
= handlerData
;
100 handle
->in_HandlerData2
= handlerData2
;
101 handle
->in_type
= it_exception
;
105 ADDHEAD(&KernelBase
->kb_Exceptions
[num
], &handle
->in_Node
);
117 /* Run exception handlers and accumulate return value */
118 int krnRunExceptionHandlers(struct KernelBase
*KernelBase
, uint8_t exception
, void *ctx
)
120 struct IntrNode
*in
, *in2
;
123 /* We can be called really early. Protect against this. */
127 ForeachNodeSafe(&KernelBase
->kb_Exceptions
[exception
], in
, in2
)
129 exhandler_t h
= in
->in_Handler
;
132 ret
|= h(ctx
, in
->in_HandlerData
, in
->in_HandlerData2
);