1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - demos - exceptionDisplay-1
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 void    myExceptionCallback(u32 context, void *arg);
20 
21 /*---------------------------------------------------------------------------*
22   Name:         NitroMain
23 
24   Description:  Main.
25 
26   Arguments:    None.
27 
28   Returns:      None.
29  *---------------------------------------------------------------------------*/
30 #include <nitro/code32.h>
NitroMain(void)31 void NitroMain(void)
32 {
33     OS_Init();
34 
35 	OS_EnableUserExceptionHandlerOnDebugger();
36     OS_SetUserExceptionHandler(myExceptionCallback, (void *)0);
37 
38     //---- The reason we're flushing the cache here is because the protection unit changes when an exception is generated. We want to reliably write addresses, etc. related to the exception.
39     //
40     //
41     DC_FlushAll();
42     DC_WaitWriteBufferEmpty();
43 
44 
45     //---- div0 exception has not occurred
46     OS_Printf("now calculate to divide by 0.\n");
47     {
48         int     a = 1;
49         int     b = 0;
50         volatile int c = a / b;
51     }
52     OS_Printf("not occurred exception.\n");
53 
54     //---- Force exception to occur
55     OS_Printf("now force to occur exception...\n");
56     asm
57     {
58         /* *INDENT-OFF* */
59         ldr      r0, =123
60         ldr      r1, =0
61         ldr      r2, =256
62         ldr      r3, =1000
63         ldr      r4, =2000
64         ldr      r5, =3000
65         ldr      r6, =4000
66         ldr      r7, =5000
67         mov      r8, pc
68         ldr      r9, =0xff
69         ldr      r10, =0xee
70         ldr      r12, =0x123
71 
72 #ifdef SDK_ARM9
73         ldr      r11, [r1,#0]
74 #else  //SDK_ARM9
75         dcd      0x06000010
76 
77 #endif //SDK_ARM9
78 
79         /* *INDENT-ON* */
80     }
81     OS_Printf("not occurred exception.\n");
82 
83     OS_Terminate();
84 }
85 
86 /*---------------------------------------------------------------------------*
87   Name:         myExceptionCallback
88 
89   Description:  user callback for exception
90 
91   Arguments:    context:
92                 arg:
93 
94   Returns:      None.
95  *---------------------------------------------------------------------------*/
myExceptionCallback(u32 context,void * arg)96 void myExceptionCallback(u32 context, void *arg)
97 {
98 #ifdef SDK_FINALROM
99 #pragma unused( context, arg )
100 #endif
101 
102     OS_Printf("---- USER EXCEPTION CALLBACK\n");
103     OS_Printf("context=%x  arg=%x\n", context, arg);
104 
105     OS_Printf("---- Thread LIST\n");
106     OS_DumpThreadList();
107 }
108 
109 #include <nitro/codereset.h>
110 
111 /*====== End of main.c ======*/
112