1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: os_ExceptionHandler.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: 47500 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_OS_ARM_OS_EXCEPTIONHANDLER_H_ 17 #define NN_OS_ARM_OS_EXCEPTIONHANDLER_H_ 18 19 #ifdef __cplusplus 20 21 #include <nn/types.h> 22 #include <nn/util/util_SizedEnum.h> 23 24 namespace nn { 25 namespace os { 26 namespace ARM { 27 28 /* 29 30 31 */ 32 enum ExceptionType 33 { 34 EXCEPTION_TYPE_PABT, // 35 EXCEPTION_TYPE_DABT, // 36 EXCEPTION_TYPE_UNDEF, // 37 EXCEPTION_TYPE_VFP, // 38 39 EXCEPTION_TYPE_MAX_BIT = (1u << 7) 40 }; 41 42 43 /* 44 45 46 */ 47 struct ExceptionContext 48 { 49 bit32 r[16]; // 50 bit32 cpsr; // 51 }; 52 53 54 /* 55 56 57 */ 58 struct ExceptionInfo 59 { 60 util::SizedEnum1<ExceptionType> type; // 61 NN_PADDING3; 62 bit32 fsr; // 63 bit32 far; // 64 bit32 fpexc; // 65 bit32 fpinst; // 66 bit32 fpinst2; // 67 }; 68 69 70 /* 71 72 73 */ 74 struct ExceptionBuffer 75 { 76 ExceptionInfo info; // 77 ExceptionContext context; // 78 }; 79 80 81 /* 82 83 84 85 86 87 88 89 90 91 92 93 94 95 */ 96 typedef void (*UserExceptionHandler)(ExceptionInfo* pei, ExceptionContext* pec); 97 98 99 100 /* 101 102 103 104 */ 105 ExceptionBuffer* const EXCEPTION_BUFFER_USE_HANDLER_STACK = NULL; 106 107 108 /* 109 110 111 112 */ 113 ExceptionBuffer* const EXCEPTION_BUFFER_USE_THREAD_STACK = reinterpret_cast<ExceptionBuffer*>(1); 114 115 116 /* 117 118 119 120 */ 121 const uptr HANDLER_STACK_USE_THREAD_STACK = 1; 122 123 124 125 126 127 /* 128 129 130 131 132 133 134 135 136 */ 137 void SetUserExceptionHandler( 138 UserExceptionHandler pHandler, uptr stackBottom, ExceptionBuffer* pExceptionBuffer ); 139 140 141 /* 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 */ 160 template <typename T> SetUserExceptionHandler(UserExceptionHandler pHandler,T * pStack,ExceptionBuffer * pExceptionBuffer)161 void SetUserExceptionHandler( 162 UserExceptionHandler pHandler, T* pStack, ExceptionBuffer* pExceptionBuffer) 163 { 164 SetUserExceptionHandler(pHandler, pStack->GetStackBottom(), pExceptionBuffer); 165 } 166 167 168 /* 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 */ 196 void SetUserExceptionHandlerLocal( 197 UserExceptionHandler pHandler, uptr stackBottom, ExceptionBuffer* pExceptionBuffer); 198 199 200 /* 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 */ 223 template <typename T> SetUserExceptionHandlerLocal(UserExceptionHandler pHandler,T * pStack,ExceptionBuffer * pExceptionBuffer)224 void SetUserExceptionHandlerLocal( 225 UserExceptionHandler pHandler, T* pStack, ExceptionBuffer* pExceptionBuffer) 226 { 227 SetUserExceptionHandlerLocal(pHandler, pStack->GetStackBottom(), pExceptionBuffer); 228 } 229 230 231 /* 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 */ 249 void SetUserExceptionHandler(UserExceptionHandler pHandler, uptr stackBottom); 250 251 252 /* 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 */ 271 template <typename T> SetUserExceptionHandler(UserExceptionHandler pHandler,T * pStack)272 void SetUserExceptionHandler(UserExceptionHandler pHandler, T* pStack) 273 { 274 SetUserExceptionHandler(pHandler, pStack->GetStackBottom()); 275 } 276 277 278 } // end of namespace ARM 279 } // end of namespace os 280 } // end of namespace nn 281 282 #endif // __cplusplus 283 284 #endif /* NN_OS_ARM_OS_EXCEPTIONHANDLER_H_ */ 285