1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     dbg_ExceptionScreen.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  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   $Rev: 49370 $
14  *---------------------------------------------------------------------------*/
15 
16 /* Please see man pages for details
17 
18 
19 
20 */
21 
22 #ifndef NN_DBG_CTR_DBG_EXCEPTIONSCREEN_H_
23 #define NN_DBG_CTR_DBG_EXCEPTIONSCREEN_H_
24 
25 #ifdef  __cplusplus
26 
27 #include <nn/dbg/CTR/dbg_DirectPrint.h>
28 #include <nn/os/os_ExceptionHandlerSelect.h>
29 #include <nn/os.h>
30 #include <nn/math.h>
31 #include <nn/util/util_FlagsEnum.h>
32 #include <gles2/gl2.h>
33 
34 namespace nn { namespace fnd {
35     class IAllocator;
36 }}
37 
38 namespace nn { namespace dbg { namespace CTR {
39 
40 //----------------------------------------------------------------------
41 //
42 //
43 //
44 //
45 //
46 //
47 //
48 //
49 //
50 //
51 //
52 //
53 //
54 //
55 //----------------------------------------------------------------------
56 class ExceptionScreen
57 {
58 private:
59     static const size_t EXCEPTION_STACK_SIZE = 0xa00;   //
60 
61 public:
62     static const int MAX_BUILD_INFO_CHARS = 32;
63 
64     //----------------------------------------------------------------------
65     //
66     //
67     //----------------------------------------------------------------------
68     enum Option
69     {
70         //----------------------------------------------------------------------
71         //
72         //----------------------------------------------------------------------
73         OPTION_WRITE_TO_SD,
74 
75         //----------------------------------------------------------------------
76         //
77         //----------------------------------------------------------------------
78         OPTION_DIRECT_PRINT,
79 
80         //----------------------------------------------------------------------
81         //
82         //
83         //----------------------------------------------------------------------
84         OPTION_WAIT_KEY,
85 
86         NUM_OF_OPTION,
87 
88         //----------------------------------------------------------------------
89         //
90         //
91         //
92         //----------------------------------------------------------------------
93         OPTION_DEFAULT = (OPTION_WRITE_TO_SD|OPTION_DIRECT_PRINT)
94     };
95 
96 public:
97     ~ExceptionScreen();
98 
99 public:
100     //----------------------------------------------------------------------
101     //
102     //
103     //
104     //
105     //
106     //
107     //
108     //
109     //
110     //
111     //
112     //
113     //----------------------------------------------------------------------
114     static void Create( nn::fnd::IAllocator* allocator, bit32 option = OPTION_DEFAULT );
115 
116     //----------------------------------------------------------------------
117     //
118     //
119     //
120     //
121     //
122     //
123     //
124     //
125     //
126     //
127     //
128     //----------------------------------------------------------------------
GetDirectPrint()129     static DirectPrint* GetDirectPrint() { return &(s_ExceptionScreen->m_DirectPrint); };
130 
131     //----------------------------------------------------------------------
132     //
133     //
134     //
135     //
136     //
137     //
138     //
139     //----------------------------------------------------------------------
SetBuildInfo(const wchar_t * pBuildInfo)140     static void SetBuildInfo( const wchar_t* pBuildInfo ) { s_ExceptionScreen->SetBuildInfoImpl( pBuildInfo ); }
141 
142     //----------------------------------------------------------------------
143     //
144     //
145     //
146     //
147     //
148     //
149     //
150     //----------------------------------------------------------------------
SetSuffix(const wchar_t * pSuffix)151     static void SetSuffix( const wchar_t* pSuffix ) { s_ExceptionScreen->SetSuffixImpl( pSuffix ); }
152 
153     //----------------------------------------------------------------------
154     //
155     //
156     //
157     //
158     //
159     //
160     //
161     //
162     //
163     //
164     //
165     //
166     //
167     //
168     //
169     //----------------------------------------------------------------------
170     static void HandleException(nn::os::ExceptionInfo* pei, nn::os::ExceptionContext* pec);
171 
172     //----------------------------------------------------------------------
173     //
174     //
175     //
176     //
177     //
178     //
179     //
180     //
181     //
182     //
183     //
184     //
185     //
186     //
187     //
188     //
189     //
190     //
191     //----------------------------------------------------------------------
192     static s32 PutBackTraceString(char* pOut, size_t size, uptr stackPtr, bit32 lr);
193 
PrepareDisplaybuffer()194     static void PrepareDisplaybuffer() { s_ExceptionScreen->PrepareDisplaybufferImpl(); }
195 
196 private:
197     DirectPrint                 m_DirectPrint;
198     GLuint                      m_Display[ 1 ];
199     wchar_t                     m_BuildInfo[ MAX_BUILD_INFO_CHARS ];
200     wchar_t                     m_Suffix[ 16 ];
201     util::FlagsEnum4<Option>    m_Option;
202     NN_PADDING4;
203     os::StackBuffer<EXCEPTION_STACK_SIZE>   m_Stack;
204 
205     static ExceptionScreen* s_ExceptionScreen;
206 
207 private:
208     ExceptionScreen(bit32 option);
209     void OnHalt( const char* msg );
210     void RegisterHandler();
211     void ExceptionHandlerBody(nn::os::ExceptionInfo* pei, nn::os::ExceptionContext* pec);
212     void SetBuildInfoImpl( const wchar_t* pBuildInfo );
213     void SetSuffixImpl( const wchar_t* pSuffix );
214     void PrepareDisplaybufferImpl();
215 
216     void AssignNewDisplaybuffer();
217 
218     static void ExceptionHandler(nn::os::ExceptionInfo* pei, nn::os::ExceptionContext* pec);
219 };
220 
221 
222 
223 }}}
224 #endif
225 
226 #endif  // NN_DBG_CTR_DBG_EXCEPTIONSCREEN_H_
227