1 /*---------------------------------------------------------------------------*
2 Project: Dolphin OS Overview - Error handler demo
3 File: errordemo.c
4
5 Copyright 1998-2001 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: errordemo.c,v $
14 Revision 1.2 02/20/2006 04:13:11 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/13/2006 11:24:13 hiratsu
18 Initial check in.
19
20
21 3 11/28/01 13:36 Shiki
22 Minor fix.
23
24 2 8/01/01 13:04 Shiki
25 Improved the error message.
26
27 1 3/08/00 11:42p Shiki
28 Initial check-in.
29 $NoKeywords: $
30 *---------------------------------------------------------------------------*/
31
32 /*---------------------------------------------------------------------------*
33 This program shows how to set up and use the error handler
34 Does not function in emulator.
35 *---------------------------------------------------------------------------*/
36 #include <revolution.h>
37
ErrorHandler(OSError error,OSContext * context,u32 dsisr,u32 dar)38 static void ErrorHandler(OSError error,
39 OSContext* context,
40 u32 dsisr,
41 u32 dar)
42 {
43 #pragma unused (error)
44 u32 i;
45 u32* p;
46
47 OSReport("------------------------- Context 0x%08x -------------------------\n",
48 context);
49
50 for (i = 0; i < 16; i++)
51 {
52 OSReport("r%-2d = 0x%08x (%14d) r%-2d = 0x%08x (%14d)\n",
53 i, context->gpr[i], context->gpr[i],
54 i + 16, context->gpr[i + 16], context->gpr[i + 16]);
55 }
56
57 OSReport("LR = 0x%08x CR = 0x%08x\n",
58 context->lr, context->cr);
59 OSReport("SRR0 = 0x%08x SRR1 = 0x%08x\n",
60 context->srr0, context->srr1);
61 OSReport("DSISR= 0x%08x DAR = 0x%08x\n",
62 dsisr, dar);
63
64 // Dump stack crawl (at most 16 levels)
65 OSReport("\nAddress: Back Chain LR Save\n");
66 for (i = 0, p = (u32*) context->gpr[1]; // get current sp
67 p && (u32) p != 0xffffffff && i++ < 16;
68 p = (u32*) *p) // get caller sp
69 {
70 OSReport("0x%08x: 0x%08x 0x%08x\n", p, p[0], p[1]);
71 }
72
73 OSReport("\nInstruction at 0x%x (read from SRR0) attempted to access "
74 "invalid address 0x%x (read from DAR)\n",
75 context->srr0, dar);
76
77 OSHalt("Done.");
78 }
79
main(void)80 int main(void)
81 {
82 OSInit();
83 OSSetErrorHandler(OS_ERROR_DSI, (OSErrorHandler) ErrorHandler);
84
85 // Touch address zero: DSI exception will be raised.
86 *(int*) 0 = 0;
87
88 return 0;
89 }
90