Advertisement
Guest User

Custom Exception Handler

a guest
Jan 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Custom Exception Handler
  2.  
  3. This code will display exception information on the television screen when an exception occurs. After the console is finished scrolling, you will be returned to the Wii System Menu.
  4.  
  5. (NTSC-U)
  6. C20235F4 00000011
  7. 9421FF80 BC410008
  8. 48000055 2A2A2A2A
  9. 2A2A2043 7573746F
  10. 6D204578 63657074
  11. 696F6E20 48616E64
  12. 6C657220 2A2A2A2A
  13. 2A0A2A2A 2A2A2A2A
  14. 2A2A2A20 62792053
  15. 74617220 26205269
  16. 69646566 69202A2A
  17. 2A2A2A2A 2A2A2A0A
  18. 00000000 7C6802A6
  19. 4CC63182 3D808002
  20. 618C3500 7D8803A6
  21. 4E800021 B8410008
  22. 38210080 28030011
  23. 60000000 00000000
  24. 040238A8 281E0005
  25. C20238BC 0000000D
  26. 9421FF80 BC410008
  27. 48000039 596F7520
  28. 77696C6C 206E6F77
  29. 20626520 72657475
  30. 726E6564 20746F20
  31. 74686520 57696920
  32. 53797374 656D204D
  33. 656E752E 00000000
  34. 7C6802A6 4CC63182
  35. 3D808002 618C3500
  36. 7D8803A6 4E800021
  37. B8410008 38210080
  38. 39610020 00000000
  39. 04226160 48000090
  40. C2226260 00000003
  41. 3D808000 618CB0E8
  42. 7D8803A6 4E800020
  43. 60000000 00000000
  44. 022A3090 00000023
  45.  
  46. (PAL)
  47. C2023694 00000011
  48. 9421FF80 BC410008
  49. 48000055 2A2A2A2A
  50. 2A2A2043 7573746F
  51. 6D204578 63657074
  52. 696F6E20 48616E64
  53. 6C657220 2A2A2A2A
  54. 2A0A2A2A 2A2A2A2A
  55. 2A2A2A20 62792053
  56. 74617220 26205269
  57. 69646566 69202A2A
  58. 2A2A2A2A 2A2A2A0A
  59. 00000000 7C6802A6
  60. 4CC63182 3D808002
  61. 618C35A0 7D8803A6
  62. 4E800021 B8410008
  63. 38210080 28030011
  64. 60000000 00000000
  65. 04023948 281E0005
  66. C202395C 0000000D
  67. 9421FF80 BC410008
  68. 48000039 596F7520
  69. 77696C6C 206E6F77
  70. 20626520 72657475
  71. 726E6564 20746F20
  72. 74686520 57696920
  73. 53797374 656D204D
  74. 656E752E 00000000
  75. 7C6802A6 4CC63182
  76. 3D808002 618C35A0
  77. 7D8803A6 4E800021
  78. B8410008 38210080
  79. 39610020 00000000
  80. 042264E4 48000090
  81. C22265E4 00000003
  82. 3D808000 618CB188
  83. 7D8803A6 4E800020
  84. 60000000 00000000
  85. 022A7410 00000023
  86.  
  87. (NTSC-J)
  88. C20235B4 00000011
  89. 9421FF80 BC410008
  90. 48000055 2A2A2A2A
  91. 2A2A2043 7573746F
  92. 6D204578 63657074
  93. 696F6E20 48616E64
  94. 6C657220 2A2A2A2A
  95. 2A0A2A2A 2A2A2A2A
  96. 2A2A2A20 62792053
  97. 74617220 26205269
  98. 69646566 69202A2A
  99. 2A2A2A2A 2A2A2A0A
  100. 00000000 7C6802A6
  101. 4CC63182 3D808002
  102. 618C34C0 7D8803A6
  103. 4E800021 B8410008
  104. 38210080 28030011
  105. 60000000 00000000
  106. 04023868 281E0005
  107. C202387C 0000000D
  108. 9421FF80 BC410008
  109. 48000039 596F7520
  110. 77696C6C 206E6F77
  111. 20626520 72657475
  112. 726E6564 20746F20
  113. 74686520 57696920
  114. 53797374 656D204D
  115. 656E752E 00000000
  116. 7C6802A6 4CC63182
  117. 3D808002 618C34C0
  118. 7D8803A6 4E800021
  119. B8410008 38210080
  120. 39610020 00000000
  121. 04226404 48000090
  122. C2226504 00000003
  123. 3D808000 618CB0AC
  124. 7D8803A6 4E800020
  125. 60000000 00000000
  126. 022A6D90 00000023
  127.  
  128. (NTSC-K)
  129. C20236F4 00000011
  130. 9421FF80 BC410008
  131. 48000055 2A2A2A2A
  132. 2A2A2043 7573746F
  133. 6D204578 63657074
  134. 696F6E20 48616E64
  135. 6C657220 2A2A2A2A
  136. 2A0A2A2A 2A2A2A2A
  137. 2A2A2A20 62792053
  138. 74617220 26205269
  139. 69646566 69202A2A
  140. 2A2A2A2A 2A2A2A0A
  141. 00000000 7C6802A6
  142. 4CC63182 3D808002
  143. 618C3600 7D8803A6
  144. 4E800021 B8410008
  145. 38210080 28030011
  146. 60000000 00000000
  147. 040239A8 281E0005
  148. C20239BC 0000000D
  149. 9421FF80 BC410008
  150. 48000039 596F7520
  151. 77696C6C 206E6F77
  152. 20626520 72657475
  153. 726E6564 20746F20
  154. 74686520 57696920
  155. 53797374 656D204D
  156. 656E752E 00000000
  157. 7C6802A6 4CC63182
  158. 3D808002 618C3600
  159. 7D8803A6 4E800021
  160. B8410008 38210080
  161. 39610020 00000000
  162. 04226858 48000090
  163. C2226958 00000003
  164. 3D808000 618CB234
  165. 7D8803A6 4E800020
  166. 60000000 00000000
  167. 02295410 00000023
  168.  
  169.  
  170.  
  171. #============================================================#
  172. #                           Source                           #
  173. #------------------------------------------------------------#
  174. # PrintContext_ Exception Type Address Ports:                #
  175. # RMCE - 0x800235F4                                          #
  176. # RMCP - 0x80023694                                          #
  177. # RMCJ - 0x800235B4                                          #
  178. # RMCK - 0x800236F4                                          #
  179. #============================================================#
  180.  
  181. .macro push_stack size, registers
  182.        stwu r1, \size(r1) # Make space for 30 registers
  183.        stmw r2, 8(r1) # Push r2-r31 onto the stack
  184. .endm
  185.  
  186. .macro absolute_bl register, address
  187.        lis \register, \address@h
  188.        ori \register, \register, \address@l
  189.        mtlr \register
  190.        blrl
  191. .endm
  192.  
  193. .macro pop_stack registers, size
  194.        lmw \registers, 8(r1) # Pop r2-r31 off the stack
  195.        addi r1, r1, \size # Release the space
  196. .endm
  197.  
  198. .set region, ''
  199.  
  200. .if     (region == 'E' || region == 'e') # RMCE
  201.         .set nw4r_db_Exception_Printf_, 0x80023500
  202. .elseif (region == 'P' || region == 'p') # RMCP
  203.         .set nw4r_db_Exception_Printf_, 0x800235A0
  204. .elseif (region == 'J' || region == 'j') # RMCJ
  205.         .set nw4r_db_Exception_Printf_, 0x800234C0
  206. .elseif (region == 'K' || region == 'k') # RMCK
  207.         .set nw4r_db_Exception_Printf_, 0x80023600
  208. .else # Invalid Region
  209.         .abort
  210. .endif
  211.  
  212. # Function Prologue...
  213. push_stack -128, r2
  214.  
  215. bl branch_link_write_exception_printf_statement
  216.  
  217. .string "****** Custom Exception Handler *****\n********* by Star & Riidefi *********\n\0\0\0"
  218.  
  219. branch_link_write_exception_printf_statement:
  220. mflr r3 # Store the pointer to the String into r3
  221.  
  222. # Call nw4r_db_Exception_Printf_
  223. crclr 4*cr1+eq # Zero out Condition Register 1, indicating the Floating-Point Registers do not need to be preserved
  224. absolute_bl r12, nw4r_db_Exception_Printf_
  225.  
  226. # Function Epilogue...
  227. pop_stack r2, 128
  228.  
  229. # Original Instruction
  230. cmplwi r3, 0x11 # if ( error < OS_ERROR_MAX )
  231.  
  232. #============================================================#
  233. #                       ShowStackTrace_                      #
  234. #============================================================#
  235. # Display a back trace of up to 5 levels of the stack.       #
  236. #============================================================#
  237.  
  238. (NTSC-U)
  239. 040238A8 281E0005
  240.  
  241. (PAL)
  242. 04023948 281E0005
  243.  
  244. (NTSC-J)
  245. 04023868 281E0005
  246.  
  247. (NTSC-K)
  248. 040239A8 281E0005
  249.  
  250. #============================================================#
  251. #                           Source                           #
  252. #------------------------------------------------------------#
  253. # PrintContext_ Function Return Address Ports:               #
  254. # RMCE - 0x800238BC                                          #
  255. # RMCP - 0x8002395C                                          #
  256. # RMCJ - 0x8002387C                                          #
  257. # RMCK - 0x800239BC                                          #
  258. #============================================================#
  259.  
  260. .macro push_stack size, registers
  261.        stwu r1, \size(r1) # Make space for 30 registers
  262.        stmw r2, 8(r1) # Push r2-r31 onto the stack
  263. .endm
  264.  
  265. .macro absolute_bl register, address
  266.        lis \register, \address@h
  267.        ori \register, \register, \address@l
  268.        mtlr \register
  269.        blrl
  270. .endm
  271.  
  272. .macro pop_stack registers, size
  273.        lmw \registers, 8(r1) # Pop r2-r31 off the stack
  274.        addi r1, r1, \size # Release the space
  275. .endm
  276.  
  277. .set region, ''
  278.  
  279. .if     (region == 'E' || region == 'e') # RMCE
  280.         .set nw4r_db_Exception_Printf_, 0x80023500
  281. .elseif (region == 'P' || region == 'p') # RMCP
  282.         .set nw4r_db_Exception_Printf_, 0x800235A0
  283. .elseif (region == 'J' || region == 'j') # RMCJ
  284.         .set nw4r_db_Exception_Printf_, 0x800234C0
  285. .elseif (region == 'K' || region == 'k') # RMCK
  286.         .set nw4r_db_Exception_Printf_, 0x80023600
  287. .else # Invalid Region
  288.         .abort
  289. .endif
  290.  
  291. # Function Prologue...
  292. push_stack -128, r2
  293.  
  294. bl branch_link_write_exception_printf_statement
  295.  
  296. .string "You will now be returned to the Wii System Menu.\0\0\0"
  297.  
  298. branch_link_write_exception_printf_statement:
  299. mflr r3 # Store the pointer to the String into r3
  300.  
  301. # Call nw4r_db_Exception_Printf_
  302. crclr 4*cr1+eq # Zero out Condition Register 1, indicating the Floating-Point Registers do not need to be preserved
  303. absolute_bl r12, nw4r_db_Exception_Printf_
  304.  
  305. # Function Epilogue...
  306. pop_stack r2, 128
  307.  
  308. # Original Instruction
  309. addi r11, r1, 32
  310.  
  311. #============================================================#
  312. #                   EGG::ExceptionCallBack                   #
  313. #============================================================#
  314. # Automatically display the console and it's contents.       #
  315. #============================================================#
  316.  
  317. (NTSC-U)
  318. 04226160 48000090
  319.  
  320. (PAL)
  321. 042264E4 48000090
  322.  
  323. (NTSC-J)
  324. 04226404 48000090
  325.  
  326. (NTSC-K)
  327. 04226858 48000090
  328.  
  329. #============================================================#
  330. #                           Source                           #
  331. #------------------------------------------------------------#
  332. # offset = Console_GetBufferHeadLine(console) Address Ports: #
  333. # RMCE - 0x80226260                                          #
  334. # RMCP - 0x802265E4                                          #
  335. # RMCJ - 0x80226504                                          #
  336. # RMCK - 0x80226958                                          #
  337. #============================================================#
  338.  
  339. .macro absolute_b register, address
  340.       lis \register, \address@h
  341.       ori \register, \register, \address@l
  342.       mtlr \register
  343.       blr
  344. .endm
  345.  
  346. .set region, ''
  347.  
  348. .if     (region == 'E' || region == 'e') # RMCE
  349.        .set System_SystemManager_returnToMenu, 0x8000B0E8
  350. .elseif (region == 'P' || region == 'p') # RMCP
  351.        .set System_SystemManager_returnToMenu, 0x8000B188
  352. .elseif (region == 'J' || region == 'j') # RMCJ
  353.        .set System_SystemManager_returnToMenu, 0x8000B0AC
  354. .elseif (region == 'K' || region == 'k') # RMCK
  355.        .set System_SystemManager_returnToMenu, 0x8000B234
  356. .else # Invalid Region
  357.        .abort
  358. .endif
  359.  
  360. # Call System::SystemManager::returnToMenu()
  361. absolute_b r12, System_SystemManager_returnToMenu
  362.  
  363. #============================================================#
  364. #                            Note                            #
  365. #------------------------------------------------------------#
  366. # Since we never return from the function call, we do not    #
  367. # need to preserve any registers.                            #
  368. #============================================================#
  369.  
  370. #============================================================#
  371. #                  nw4r::db::exception .bss                  #
  372. #============================================================#
  373. # enum                                                       #
  374. # {                                                          #
  375. #     EXCEPTION_INFO_MAIN     = 0x1,                         #
  376. #     EXCEPTION_INFO_GPR      = 0x2,                         #
  377. #     EXCEPTION_INFO_GPRMAP   = 0x4,                         #
  378. #     EXCEPTION_INFO_SRR0MAP  = 0x8,                         #
  379. #     EXCEPTION_INFO_FPR      = 0x10,                        #
  380. #     EXCEPTION_INFO_TRACE    = 0x20,                        #
  381. #                                                            #
  382. #     EXCEPTION_INFO_ALL      = 0x3F,                        #
  383. # };                                                         #
  384. #                                                            #
  385. # Set the information flag to display the Main Information,  #
  386. # General Purpose Registers, and a Stack Trace.              #
  387. #============================================================#
  388.  
  389. (NTSC-U)
  390. 022A3090 00000023
  391.  
  392. (PAL)
  393. 022A7410 00000023
  394.  
  395. (NTSC-J)
  396. 022A6D90 00000023
  397.  
  398. (NTSC-K)
  399. 02295410 00000023
  400.  
  401.  
  402.  
  403. Code Creators: Star, Riidefi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement