use the locations specified in the bcm2708_boot header
[AROS.git] / rom / kernel / addexceptionhandler.c
blobb24b36606c1f13717ba653d6db4e35fe29d6ef44
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 */
8 #include <aros/kernel.h>
9 #include <proto/exec.h>
11 #include <inttypes.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 */
20 #define D(x)
22 /*****************************************************************************
24 NAME */
25 #include <proto/kernel.h>
27 AROS_LH4(void *, KrnAddExceptionHandler,
29 /* SYNOPSIS */
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),
35 /* LOCATION */
36 struct KernelBase *, KernelBase, 14, Kernel)
38 /* FUNCTION
39 Add a raw CPU exception handler to the chain of handlers.
41 INPUTS
42 num - CPU-specific exception number
43 handler - Pointer to a handler function
44 handlerData,
45 handlerData2 - User-defined data which is passed to the
46 handler.
48 Handler function uses a C calling convention and must be
49 declared as follows:
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.
63 RESULT
64 An opaque handle that can be used for handler removal or NULL in case
65 of failure (like unsupported exception number).
67 NOTES
68 The specification of this function is preliminary and subject to change.
69 Consider it private for now.
71 EXAMPLE
73 BUGS
75 SEE ALSO
76 KrnRemExceptionHandler()
78 INTERNALS
80 ******************************************************************************/
82 AROS_LIBFUNC_INIT
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 */
90 (void)goSuper();
92 /* Allocate protected memory, accessible only in supervisor mode */
93 handle = krnAllocIntrNode();
94 D(bug("[KRN] handle=%012p\n", handle));
96 if (handle)
98 handle->in_Handler = handler;
99 handle->in_HandlerData = handlerData;
100 handle->in_HandlerData2 = handlerData2;
101 handle->in_type = it_exception;
102 handle->in_nr = num;
104 Disable();
105 ADDHEAD(&KernelBase->kb_Exceptions[num], &handle->in_Node);
106 Enable();
109 goUser();
112 return handle;
114 AROS_LIBFUNC_EXIT
117 /* Run exception handlers and accumulate return value */
118 int krnRunExceptionHandlers(struct KernelBase *KernelBase, uint8_t exception, void *ctx)
120 struct IntrNode *in, *in2;
121 int ret = 0;
123 /* We can be called really early. Protect against this. */
124 if (!KernelBase)
125 return 0;
127 ForeachNodeSafe(&KernelBase->kb_Exceptions[exception], in, in2)
129 exhandler_t h = in->in_Handler;
131 if (h)
132 ret |= h(ctx, in->in_HandlerData, in->in_HandlerData2);
135 return ret;