1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - demos - exceptionDisplay-3
3   File:     main.c
4 
5   Copyright 2007-2008 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   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18 
19 #define MYTRACEBUFFER_SIZE 0x1000
20 u32     myTraceBuffer[MYTRACEBUFFER_SIZE / sizeof(u32)];
21 
22 int     test1(int a);
23 int     test2(int a);
24 int     test3(int a);
25 
26 void    myExceptionCallback(u32 context, void *arg);
27 
28 //----------------------------------------------------------------
29 // test1
30 //
test1(int a)31 int test1(int a)
32 {
33     return test2(a + 1);
34 }
35 
36 //----------------------------------------------------------------
37 // test2
38 //
test2(int a)39 int test2(int a)
40 {
41     return test3(a + 2);
42 }
43 
44 //----------------------------------------------------------------
45 // test3
46 //
test3(int a)47 int test3(int a)
48 {
49     //---- force to occur exception
50     OS_Printf("now force to occur exception...\n");
51 
52     asm
53     {
54         /* *INDENT-OFF* */
55         ldr      r0, =0
56 #ifdef SDK_ARM9
57         ldr      r2, [r0,#0]
58 #else  //SDK_ARM9
59         dcd      0x06000010
60 
61 #endif //SDK_ARM9
62         /* *INDENT-ON* */
63     }
64     OS_Printf("not occurred exception.\n");
65 
66     return a + 4;
67 }
68 
69 //======================================================================
70 /*---------------------------------------------------------------------------*
71   Name:         NitroMain
72 
73   Description:  main
74 
75   Arguments:    None
76 
77   Returns:      None
78  *---------------------------------------------------------------------------*/
79 #pragma profile off
NitroMain()80 void NitroMain()
81 {
82     OS_Init();
83 
84 	OS_EnableUserExceptionHandlerOnDebugger();
85     OS_SetUserExceptionHandler(myExceptionCallback, (void *)0);
86 
87     DC_FlushAll();
88     DC_WaitWriteBufferEmpty();
89 
90 
91     //---- setup of function call trace
92     OS_InitCallTrace(myTraceBuffer, MYTRACEBUFFER_SIZE, OS_CALLTRACE_LOG /*STACK*/);
93 
94     (void)test1(0x100);
95 
96     OS_Terminate();
97 }
98 
99 /*---------------------------------------------------------------------------*
100   Name:         myExceptionCallback
101 
102   Description:  user callback for exception
103 
104   Arguments:    context :
105                 arg     :
106 
107   Returns:      None
108  *---------------------------------------------------------------------------*/
myExceptionCallback(u32 context,void * arg)109 void myExceptionCallback(u32 context, void *arg)
110 {
111 #ifdef SDK_FINALROM
112 #pragma unused( context, arg )
113 #endif
114 
115     OS_Printf("---- USER EXCEPTION CALLBACK\n");
116     OS_Printf("context=%x  arg=%x\n", context, arg);
117 
118     OS_Printf("----- CallTrace\n");
119     OS_DumpCallTrace();
120 
121     OS_Printf("---- Thread LIST\n");
122     OS_DumpThreadList();
123 }
124 
125 /*====== End of main.c ======*/
126