Fix IO memory access .. SB128 driver makes noises in VMWare - CMI is untested (Curren...
[AROS.git] / rom / exec / alert.c
blobe5cd1b75eb3d92adac1d8a53ec0fb627a5217124
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Display an alert.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/alerts.h>
11 #include <exec/execbase.h>
12 #include <exec/rawfmt.h>
13 #include <proto/exec.h>
14 #include <proto/kernel.h>
15 #include <string.h>
17 #include "exec_intern.h"
18 #include "exec_util.h"
19 #include "etask.h"
21 /*****************************************************************************
23 NAME */
25 AROS_LH1(void, Alert,
27 /* SYNOPSIS */
28 AROS_LHA(ULONG, alertNum, D7),
30 /* LOCATION */
31 struct ExecBase *, SysBase, 18, Exec)
33 /* FUNCTION
34 Alerts the user of a serious system problem.
36 INPUTS
37 alertNum - This is a number which contains information about
38 the reason for the call.
40 RESULT
41 This routine may return, if the alert is not a dead-end one.
43 NOTES
44 You should not call this routine because it halts the machine,
45 displays the message and then may reboot it.
47 EXAMPLE
48 // Dead-End alert: 680x0 Access To Odd Address
49 Alert (0x80000003);
51 BUGS
53 SEE ALSO
55 INTERNALS
57 ******************************************************************************/
59 AROS_LIBFUNC_INIT
61 Exec_ExtAlert(alertNum, __builtin_return_address(0), CALLER_FRAME, AT_NONE, NULL, SysBase);
63 AROS_LIBFUNC_EXIT
66 static const ULONG contextSizes[] =
69 sizeof(struct ExceptionContext),
70 sizeof(struct MungwallContext),
73 void Exec_ExtAlert(ULONG alertNum, APTR location, APTR stack, UBYTE type, APTR data, struct ExecBase *SysBase)
75 struct Task *task = SysBase->ThisTask;
76 struct IntETask *iet = NULL;
77 int supervisor = KrnIsSuper();
79 D(bug("[exec] Alert 0x%08X, supervisor %d\n", alertNum, supervisor));
81 if (task && (task->tc_Flags & TF_ETASK) && (task->tc_State != TS_REMOVED))
83 iet = GetIntETask(task);
85 D(bug("[Alert] Task 0x%p, ETask 0x%p\n", task, iet));
87 /* Do we already have location set? */
88 if (iet->iet_AlertFlags & AF_Location)
90 /* If yes, pick it up */
91 location = iet->iet_AlertLocation;
92 stack = iet->iet_AlertStack;
94 else
96 if (supervisor && ((alertNum & ~AT_DeadEnd) == AN_StackProbe))
99 * Special case: AN_StackProbe issued by kernel's task dispatcher.
100 * Pick up data from task's context.
102 struct ExceptionContext *ctx = iet->iet_Context;
104 location = (APTR)ctx->PC;
105 stack = (APTR)ctx->FP;
106 type = AT_CPU;
107 data = ctx;
110 /* Set location */
111 iet->iet_AlertFlags |= AF_Location;
112 iet->iet_AlertLocation = location;
113 iet->iet_AlertStack = stack;
115 D(bug("[Alert] Previous frame 0x%p, caller 0x%p\n", iet->iet_AlertStack, iet->iet_AlertLocation));
118 /* If this is not a nested call, set the supplementary data if specified */
119 if (data && !(iet->iet_AlertFlags & AF_Alert))
121 D(bug("[Alert] Setting alert context, type %u, data 0x%p\n", type, data));
123 iet->iet_AlertType = type;
124 CopyMem(data, &iet->iet_AlertData, contextSizes[type]);
126 else
128 /* Either no data or already present */
129 type = iet->iet_AlertType;
130 data = &iet->iet_AlertData;
132 D(bug("[Alert] Got stored alert context, type %u, data 0x%p\n", type, data));
135 else
137 * If we have no task, or the task is being removed,
138 * we can't use the user-mode routine.
140 supervisor = TRUE;
143 * If we are running in user mode we should first try to report a problem
144 * using Intuition display.
146 if (!supervisor)
148 alertNum = Exec_UserAlert(alertNum, SysBase);
149 if (!alertNum)
152 * UserAlert() succeeded and the user decided to continue the task.
153 * Clear crash status and return happily
155 ResetETask(iet);
156 return;
160 /* Hint for SystemAlert() - if AlertType is AT_NONE, we don't have AlertData */
161 if (type == AT_NONE)
162 data = NULL;
165 * We're here if Intuition failed. Use safe (but not so
166 * system and user-friendly) way to post alerts.
168 Disable();
169 Exec_SystemAlert(alertNum, location, stack, type, data, SysBase);
170 Enable();
172 if (alertNum & AT_DeadEnd)
174 /* Um, we have to do something here in order to prevent the
175 computer from continuing... */
176 ColdReboot();
177 ShutdownA(SD_ACTION_COLDREBOOT);
181 * We succesfully displayed an alert in supervisor mode.
182 * Clear alert status by clearing respective fields in ETask.
184 if (iet)
185 ResetETask(iet);