Belarusian
[AROS.git] / rom / exec / alertstrings.c
blobf2bbf425dc80a2e8d661cd84747465b8239536c7
1 /*
2 * A library of alert strings and useful functions.
3 * Used by platform-specific Alert() implementations
4 */
6 #include <aros/debug.h>
7 #include <exec/alerts.h>
8 #include <exec/rawfmt.h>
9 #include <exec/tasks.h>
10 #include <proto/kernel.h>
12 #include "etask.h"
13 #include "exec_intern.h"
14 #include "exec_util.h"
16 struct Errors
18 ULONG number;
19 STRPTR string;
22 /* Get a string from an array of type Errors. */
23 static STRPTR getString(ULONG alertnum, const struct Errors *errs)
25 /* Some of alert codes have AT_DeadEnd bit set, others have it reset.
26 However in real life AT_DeadEnd bit may be set for any error, so
27 we mask it out for comparison */
28 alertnum &= ~AT_DeadEnd;
30 while((errs->number) && ((errs->number & ~AT_DeadEnd) != alertnum))
32 errs++;
34 return errs->string;
37 static const struct Errors cpustrings[] =
39 { ACPU_BusErr, "Hardware bus fault/address error" },
40 { ACPU_AddressErr, "Illegal address access (odd)" },
41 { ACPU_InstErr, "Illegal instruction" },
42 { ACPU_DivZero, "Division by zero" },
43 { ACPU_CHK, "CHK instruction error" },
44 { ACPU_TRAPV, "TRAPV instruction error" },
45 { ACPU_PrivErr, "Priviledge violation error" },
46 { ACPU_Trace, "Trace error" },
47 { ACPU_LineA, "Line 1010 (A) E mulator error" },
48 { ACPU_LineF, "Line 1111 (F) Emulator/Coprocessor error" },
49 { ACPU_Format, "Stack frame format error" },
50 { ACPU_Spurious, "Spurious interrupt error" },
51 { 0, "Unknown CPU error" }
54 static const struct Errors subsystems[] =
56 { 0x01, "exec.library " },
57 { 0x02, "graphics.library " },
58 { 0x03, "layers.library " },
59 { 0x04, "intuition.library " },
60 { 0x05, "math.library " },
61 { 0x07, "dos.library " },
62 { 0x08, "ramlib " },
63 { 0x09, "icon.library " },
64 { 0x0a, "expansion.library " },
65 { 0x0b, "diskfont.library " },
66 { 0x10, "audio.device " },
67 { 0x11, "console.device " },
68 { 0x12, "gameport.device " },
69 { 0x13, "keyboard.device " },
70 { 0x14, "trackdisk.device " },
71 { 0x15, "timer.device " },
72 { 0x20, "cia.resource " },
73 { 0x21, "disk.resource " },
74 { 0x22, "misc.resource " },
75 { 0x30, "bootstrap " },
76 { 0x31, "workbench " },
77 { 0x32, "diskcopy " },
78 { 0x33, "gadtools " },
79 { 0x34, "utility " },
81 { 0x40, "aros " },
82 { 0x41, "oop " },
83 { 0x42, "hidd " },
85 /* This takes in 0x35 as well... */
86 { 0x00, "unknown " }
89 static const struct Errors types[] =
91 { 0x01, "no memory for " },
92 { 0x02, "could not make library " },
93 { 0x03, "could not open library " },
94 { 0x04, "could not open device " },
95 { 0x05, "could not open resource " },
96 { 0x06, "IO error with " },
97 { 0x07, "no signal for/from " },
98 { 0x08, "bad parameter for/from " },
99 { 0x09, "close library error with " },
100 { 0x0a, "close device error with " },
101 { 0x0b, "process creating failure with " },
102 { 0x00, "unknown problem with "}
105 static const struct Errors execstrings[] =
107 { AN_ExcptVect, "MC68k Exception vector checksum" },
108 { AN_BaseChkSum, "ExecBase checksum" },
109 { AN_LibChkSum, "Library checksum failure" },
110 { AN_MemCorrupt, "Corrupt memory list detected" },
111 { AN_IntrMem, "No memory for interrupt servers" },
112 { AN_InitAPtr, "(obs) InitStruct of an APTR" },
113 { AN_SemCorrupt, "Semaphore in an illegal state" },
114 { AN_FreeTwice, "Memory freed twice" },
115 { AN_BogusExcpt, "Illegal mc68k exception taken" },
116 { AN_IOUsedTwice, "Attempt to reuse active IORequest" },
117 { AN_MemoryInsane, "Sanity check on memory list failed" },
118 { AN_IOAfterClose, "Attempt to use IORequest after close" },
119 { AN_StackProbe, "Stack extends out of range" },
120 { AN_BadFreeAddr, "Memory header not located" },
121 { AN_BadSemaphore, "Attempt to use the old message semaphore" },
122 { 0, "unknown exec.library error" }
125 static const struct Errors gfxstrings[] =
127 { AN_GfxNoMem, "Graphics out of memory" },
128 { AN_GfxNoMemMspc, "No memory to allocate MonitorSpec" },
129 { AN_LongFrame, "No memory for long frame" },
130 { AN_ShortFrame, "No memory for short frame" },
131 { AN_TextTmpRas, "Mo memory for TmpRas" },
132 { AN_BltBitMap, "No memory for BltBitMap" },
133 { AN_RegionMemory, "No memory for Region" },
134 { AN_MakeVPort, "No memory for MakeVPort" },
135 { AN_GfxNewError, "Error in GfxNew()" },
136 { AN_GfxFreeError, "Error in GfxFree()" },
137 { AN_GfxNoLCM, "Emergency memory not available" },
138 { AN_ObsoleteFont, "Unsupported font description used" },
139 { 0, "unknown graphics.library error" }
142 static const struct Errors unknownstrings[] =
144 { 0, "unknown error" }
147 static const struct Errors layersstrings[] =
149 { AN_LayersNoMem, "layers: no memory" },
150 { 0, "unknown layers.library error" }
153 static const struct Errors intuistrings[] =
155 { AN_GadgetType, "intuition: unknown gadget type" },
156 { AN_CreatePort, "intuition couldn't create port, no memory" },
157 { AN_ItemAlloc, "no memory for menu item" },
158 { AN_SubAlloc, "no memory for menu subitem" },
159 { AN_PlaneAlloc, "no memory for bitplane" },
160 { AN_ItemBoxTop, "top of item box < RelZero" },
161 { AN_OpenScreen, "no memory for OpenScreen()" },
162 { AN_OpenScrnRast, "no memory for OpenScreen() raster" },
163 { AN_SysScrnType, "unknown type of system screen" },
164 { AN_AddSWGadget, "add SW gadgets, no memory" },
165 { AN_OpenWindow, "no memory for OpenWindow()" },
166 { AN_BadState, "bad state return entering intuition" },
167 { AN_BadMessage, "bad message received by IDCMP" },
168 { AN_WeirdEcho, "weird echo causing incomprehension" },
169 { AN_NoConsole, "couldn't open the console.device" },
170 { AN_NoISem, "intuition skipped obtaining a semaphore" },
171 { AN_ISemOrder, "intuition got a semaphore in wrong order" },
172 { 0, "unknown intuition.library error" }
175 static const struct Errors mathstrings[] =
177 { 0, "unknown math library error" }
180 static const struct Errors dosstrings[] =
182 { AN_StartMem, "no memory at startup" },
183 { AN_EndTask, "EndTask did not end task" },
184 { AN_QPktFail, "QPkt failure" },
185 { AN_AsyncPkt, "unexpected DOS packet received" },
186 { AN_FreeVec, "freevec failed" },
187 { AN_DiskBlkSeq, "disk block sequence error" },
188 { AN_BitMap, "disk bitmap corrupt" },
189 { AN_KeyFree, "disk key already free" },
190 { AN_BadChkSum, "disk checksum bad" },
191 { AN_DiskError, "disk error" },
192 { AN_KeyRange, "disk key out of range" },
193 { AN_BadOverlay, "bad overlay" },
194 { AN_BadInitFunc, "invalid initialization packet for cli/shell" },
195 { AN_FileReclosed, "filehandle closed more than once" },
196 { 0, "unknown dos.library error" }
199 static const struct Errors ramlibstrings[] =
201 { AN_BadSegList, "bad library seglist" },
202 { 0, "unknown ramlib/lddemon error" }
205 static const struct Errors iconstrings[] =
207 { 0, "unknown icon.library error" }
210 static const struct Errors expanstrings[] =
212 { AN_BadExpansionFree, "expansion freeing region already freed"},
213 { 0, "unknown expansion.library error" }
216 static const struct Errors utilitystrings[] =
218 {0, "unknown utility.library error" }
221 static const struct Errors keymapstrings[] =
223 {0, "unknown keymap error" }
226 static const struct Errors dfontstrings[] =
228 { 0, "unknown diskfont.library error" }
231 static const struct Errors audiostrings[] =
233 { 0, "unknown audio.device error" }
236 static const struct Errors consolestrings[] =
238 { AN_NoWindow, "can't open initial console window" },
239 { 0, "unknown console.device error" }
242 static const struct Errors gameportstrings[] =
244 { 0, "unknown gameport.device error" }
247 static const struct Errors keyboardstrings[] =
249 { 0, "unknown keyboard.device error" }
252 static const struct Errors trackdiskstrings[] =
254 { AN_TDCalibSeek, "trackdisk calibrate seek error" },
255 { 0, "unknown trackdisk.device error" }
258 static const struct Errors timerstrings[] =
260 { AN_TMBadReq, "bad timer request" },
261 { AN_TMBadSupply, "bad timer powersupply frequency" },
262 { 0, "unknown timer.device error" }
265 static const struct Errors ciastrings[] =
267 { 0, "unknown cia resource error" }
270 static const struct Errors diskstrings[] =
272 { AN_DRHasDisk, "get disk unit, already has disk" },
273 { AN_DRIntNoAct,"disk interrupt, no active unit" },
274 { 0, "unknown disk.resource error" }
277 static const struct Errors miscstrings[] =
279 { 0, "unknown misc.resource error" }
282 static const struct Errors bootstrings[] =
284 { AN_BootError, "boot code returned an error" },
285 { 0, "unknown bootstrap error" }
288 static const struct Errors workbenchstrings[] =
290 { AN_NoFonts, "no fonts for workbench" },
291 { AN_WBBadStartupMsg1, "bad startup message 1 for workbench" },
292 { AN_WBBadStartupMsg2, "bad startup message 2 for workbench" },
293 { AN_WBBadIOMsg, "bad IO message for workbench" },
294 { AN_WBReLayoutToolMenu, "error with layout on tools menu" },
295 { 0, "unknown workbench error" }
298 static const struct Errors diskcopystrings[] =
300 {0, "unknown diskcopy error" }
303 static const struct Errors gadtoolsstrings[] =
305 {0, "unknown gadtools.library error" }
308 static const struct Errors arosstrings[] =
310 {0, "unknown aros.library error" }
313 static const struct Errors oopstrings[] =
315 {0, "unknown oop.library error" }
318 static const struct Errors hiddstrings[] =
320 {0, "unknown Hidd system error" }
323 static const struct Errors *const stringlist[] =
325 /* 0x00 */
326 unknownstrings,
327 execstrings,
328 gfxstrings,
329 layersstrings,
330 intuistrings,
331 mathstrings,
332 unknownstrings,
333 dosstrings,
334 ramlibstrings,
335 iconstrings,
336 expanstrings,
337 dfontstrings,
338 utilitystrings,
339 keymapstrings,
340 unknownstrings,
341 unknownstrings,
343 /* 0x10 */
344 audiostrings,
345 consolestrings,
346 gameportstrings,
347 keyboardstrings,
348 trackdiskstrings,
349 timerstrings,
350 unknownstrings,
351 unknownstrings,
352 unknownstrings,
353 unknownstrings,
354 unknownstrings,
355 unknownstrings,
356 unknownstrings,
357 unknownstrings,
358 unknownstrings,
359 unknownstrings,
361 /* 0x20 */
362 ciastrings,
363 diskstrings,
364 miscstrings,
365 unknownstrings,
366 unknownstrings,
367 unknownstrings,
368 unknownstrings,
369 unknownstrings,
370 unknownstrings,
371 unknownstrings,
372 unknownstrings,
373 unknownstrings,
374 unknownstrings,
375 unknownstrings,
376 unknownstrings,
377 unknownstrings,
379 /* 0x30 */
380 bootstrings,
381 workbenchstrings,
382 diskcopystrings,
383 gadtoolsstrings,
384 unknownstrings,
385 unknownstrings,
386 unknownstrings,
387 unknownstrings,
388 unknownstrings,
389 unknownstrings,
390 unknownstrings,
391 unknownstrings,
392 unknownstrings,
393 unknownstrings,
394 unknownstrings,
395 unknownstrings,
397 /* 0x40 */
398 arosstrings,
399 oopstrings,
400 hiddstrings
403 /* Similar to strcpy() but returns a pointer to the next byte beyond the
404 copied string. Useful for concatenation. */
405 STRPTR Alert_AddString(STRPTR dest, STRPTR src)
407 while(*src)
409 *dest++ = *src++;
411 return dest;
414 STRPTR Alert_GetTitle(ULONG alertNum)
416 if(alertNum & AG_NoMemory)
417 return "Not Enough Memory!";
418 else if(alertNum & AT_DeadEnd)
419 return "Software Failure!";
420 else
421 return "Recoverable Alert!";
424 STRPTR Alert_GetTaskName(struct Task *task)
426 STRPTR tname;
428 /* Find out the task name. The node type must be correct. */
429 if (task && ((task->tc_Node.ln_Type == NT_TASK) || (task->tc_Node.ln_Type == NT_PROCESS))
430 && (task->tc_Node.ln_Name != NULL))
431 tname = task->tc_Node.ln_Name;
432 else
433 tname = "--task not found--";
434 return tname;
437 /* Decode the alert number, and try and work out what string to get */
438 STRPTR Alert_GetString(ULONG alertnum, STRPTR buf)
440 /* Is this a CPU alert? */
441 if((alertnum & 0x7f008000) == 0)
443 /* Yes */
444 buf = Alert_AddString(buf, getString(alertnum, cpustrings));
446 /* Is this a General alert */
447 else if((alertnum & 0x8000) == 0x8000)
449 UBYTE type = (alertnum & 0x00FF0000) >> 16;
450 UWORD obj = (alertnum & 0x7fff);
451 UBYTE subsys = (alertnum & 0x7f000000) >> 24;
453 buf = Alert_AddString(buf, getString(obj, subsystems));
454 buf = Alert_AddString(buf, getString(type, types));
455 buf = Alert_AddString(buf, getString(subsys, subsystems));
457 /* This must be a specific alert */
458 else
460 UBYTE subsys = (alertnum & 0x7f000000) >> 24;
462 if(subsys < 0x80)
463 buf = Alert_AddString(buf, getString(alertnum, stringlist[subsys]));
464 else
465 buf = Alert_AddString(buf, "unknown error");
468 *buf = 0;
469 return buf;
472 static char *hdrstring = "Task : 0x%P - %s\n"
473 "Error: 0x%08lx - ";
474 static char *locstring = "PC : 0x%P\n";
475 static char *modstring = "Module %s Segment %lu %s (0x%P) Offset 0x%P\n";
476 static char *funstring = "Function %s (0x%P) Offset 0x%P\n";
478 STRPTR FormatAlert(char *buffer, ULONG alertNum, struct Task *task, struct ExecBase *SysBase)
480 char *buf;
482 buf = NewRawDoFmt(hdrstring, RAWFMTFUNC_STRING, buffer, task, Alert_GetTaskName(task), alertNum);
483 buf = Alert_GetString(alertNum, --buf);
484 *buf++ = '\n';
485 D(bug("[FormatAlert] Header:\n%s\n", buffer));
487 if (task)
489 struct IntETask *iet = GetIntETask(task);
491 if (iet->iet_AlertLocation)
493 char *modname, *segname, *symname;
494 void *segaddr, *symaddr;
495 unsigned int segnum;
497 buf = NewRawDoFmt(locstring, RAWFMTFUNC_STRING, buf, iet->iet_AlertLocation);
498 D(bug("[FormatAlert] Location string:\n%s\n", buffer));
500 #ifdef KrnDecodeLocation
501 if (KrnDecodeLocation(iet->iet_AlertLocation,
502 KDL_ModuleName , &modname, KDL_SegmentNumber, &segnum ,
503 KDL_SegmentName, &segname, KDL_SegmentStart , &segaddr,
504 KDL_SymbolName , &symname, KDL_SymbolStart , &symaddr,
505 TAG_DONE))
507 if (!segname)
508 segname = "- unknown -";
510 buf = NewRawDoFmt(modstring, RAWFMTFUNC_STRING, --buf, modname, segnum, segname, segaddr, iet->iet_AlertLocation - segaddr);
512 if (symaddr)
514 if (!symname)
515 symname = "- unknown -";
517 buf = NewRawDoFmt(funstring, RAWFMTFUNC_STRING, --buf, symname, symaddr, iet->iet_AlertLocation - symaddr);
520 #endif
521 /* After NewRawDoFmt() buf points to the character AFTER null terminator */
522 buf--;
526 *buf = 0;
527 return buf;