Belarusian
[AROS.git] / rom / exec / traphandler.c
blob05faf6ba2abfafc1f85967a30a65dfd038cf7d17
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Default trap handler
6 Lang: english
7 */
9 #include <exec/alerts.h>
10 #include <exec/tasks.h>
11 #include <proto/exec.h>
13 #include "kernel_cpu.h"
15 #include "etask.h"
16 #include "exec_intern.h"
17 #include "exec_util.h"
19 /* In original AmigaOS the trap handler is entered in supervisor mode with the
20 * following on the supervisor stack:
21 * 0(sp).l = trap#
22 * 4(sp) Processor dependent exception frame
23 * In our current implementation we use two pointers on stack. Context structure is
24 * currently private because it differs even on the same CPU, however i beleive it
25 * should be changed to some generalized form in order to allow applications (debuggers)
26 * to use it.
29 void Exec_TrapHandler(ULONG trapNum, struct AROSCPUContext *ctx)
31 struct Task *task = SysBase->ThisTask;
32 struct IntETask *iet;
34 /* Our situation is deadend */
35 trapNum |= AT_DeadEnd;
37 if (task)
39 /* Get internal task structure */
40 iet = GetIntETask(task);
41 /* Protection against double-crash. If the alert code is already specified, we have
42 a second crash during processing the first one. Then we just pick up initial alert code
43 and just call Alert(). */
44 if (iet->iet_AlertCode)
45 trapNum = iet->iet_AlertCode;
46 else
48 /* Otherwise we can try to send the crash to user level. Set alert information for the task */
49 #ifdef GET_PC
50 iet->iet_AlertLocation = GET_PC(ctx);
51 #endif
53 #ifdef SET_PC
54 iet->iet_AlertCode = trapNum;
55 /* Make the task to jump to crash handler. We don't care about return address etc because
56 the alert is deadend anyway. */
57 SET_PC(ctx, Exec_CrashHandler);
58 /* Let the task go */
59 return;
60 #endif
64 Alert(trapNum);
65 } /* TrapHandler */