cprt0.as 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. @ (c) 2006 by devkitPro (http://www.devkitpro.org)
  2. .section ".crt0","ax"
  3. .global _start
  4. .align
  5. .arm
  6. .cpu arm7tdmi
  7. @---------------------------------------------------------------------------------
  8. _start:
  9. @---------------------------------------------------------------------------------
  10. b rom_header_end
  11. .fill 156,1,0 @ Nintendo Logo Character Data (8000004h)
  12. .fill 16,1,0 @ Game Title
  13. .byte 0x30,0x31 @ Maker Code (80000B0h)
  14. .byte 0x96 @ Fixed Value (80000B2h)
  15. .byte 0x00 @ Main Unit Code (80000B3h)
  16. .byte 0x00 @ Device Type (80000B4h)
  17. .fill 7,1,0 @ unused
  18. .byte 0x00 @ Software Version No (80000BCh)
  19. .byte 0xf0 @ Complement Check (80000BDh)
  20. .byte 0x00,0x00 @ Checksum (80000BEh)
  21. @---------------------------------------------------------------------------------
  22. rom_header_end:
  23. @---------------------------------------------------------------------------------
  24. b start_vector @ This branch must be here for proper
  25. @ positioning of the following header.
  26. .GLOBAL __boot_method, __slave_number
  27. @---------------------------------------------------------------------------------
  28. __boot_method:
  29. @---------------------------------------------------------------------------------
  30. .byte 0 @ boot method (0=ROM boot, 3=Multiplay boot)
  31. @---------------------------------------------------------------------------------
  32. __slave_number:
  33. @---------------------------------------------------------------------------------
  34. .byte 0 @ slave # (1=slave#1, 2=slave#2, 3=slave#3)
  35. .byte 0 @ reserved
  36. .byte 0 @ reserved
  37. .word 0 @ reserved
  38. .word 0 @ reserved
  39. .word 0 @ reserved
  40. .word 0 @ reserved
  41. .word 0 @ reserved
  42. .word 0 @ reserved
  43. .global start_vector
  44. .align
  45. @---------------------------------------------------------------------------------
  46. start_vector:
  47. @---------------------------------------------------------------------------------
  48. mov r0, #0x4000000 @ REG_BASE
  49. str r0, [r0, #0x208]
  50. mov r0, #0x12 @ Switch to IRQ Mode
  51. msr cpsr, r0
  52. ldr sp, =__sp_irq @ Set IRQ stack
  53. mov r0, #0x1f @ Switch to System Mode
  54. msr cpsr, r0
  55. ldr sp, =__sp_usr @ Set user stack
  56. @---------------------------------------------------------------------------------
  57. @ Enter Thumb mode
  58. @---------------------------------------------------------------------------------
  59. add r0, pc, #1
  60. bx r0
  61. .thumb
  62. ldr r0, =__text_start
  63. lsl r0, #5 @ Was code compiled at 0x08000000 or higher?
  64. bcs DoEWRAMClear @ yes, you can not run it in external WRAM
  65. mov r0, pc
  66. lsl r0, #5 @ Are we running from ROM (0x8000000 or higher) ?
  67. bcc SkipEWRAMClear @ No, so no need to do a copy.
  68. @---------------------------------------------------------------------------------
  69. @ We were started in ROM, silly emulators. :P
  70. @ So we need to copy to ExWRAM.
  71. @---------------------------------------------------------------------------------
  72. mov r2, #2
  73. lsl r2, r2, #24 @ r2= 0x02000000
  74. ldr r3, =__end__ @ last ewram address
  75. sub r3, r2 @ r3= actual binary size
  76. mov r6, r2 @ r6= 0x02000000
  77. lsl r1, r2, #2 @ r1= 0x08000000
  78. bl CopyMem
  79. bx r6 @ Jump to the code to execute
  80. @---------------------------------------------------------------------------------
  81. DoEWRAMClear: @ Clear External WRAM to 0x00
  82. @---------------------------------------------------------------------------------
  83. mov r1, #0x40
  84. lsl r1, #12 @ r1 = 0x40000
  85. lsl r0, r1, #7 @ r0 = 0x2000000
  86. bl ClearMem
  87. @---------------------------------------------------------------------------------
  88. SkipEWRAMClear: @ Clear Internal WRAM to 0x00
  89. @---------------------------------------------------------------------------------
  90. @---------------------------------------------------------------------------------
  91. @ Clear BSS section to 0x00
  92. @---------------------------------------------------------------------------------
  93. ldr r0, =__bss_start__
  94. ldr r1, =__bss_end__
  95. sub r1, r0
  96. bl ClearMem
  97. @---------------------------------------------------------------------------------
  98. @ Clear SBSS section to 0x00
  99. @---------------------------------------------------------------------------------
  100. ldr r0, =__sbss_start__
  101. ldr r1, =__sbss_end__
  102. sub r1, r0
  103. bl ClearMem
  104. @---------------------------------------------------------------------------------
  105. @ Copy initialized data (data section) from LMA to VMA (ROM to RAM)
  106. @---------------------------------------------------------------------------------
  107. ldr r1, =__data_lma
  108. ldr r2, =__data_start__
  109. ldr r4, =__data_end__
  110. bl CopyMemChk
  111. @---------------------------------------------------------------------------------
  112. @ Copy internal work ram (iwram section) from LMA to VMA (ROM to RAM)
  113. @---------------------------------------------------------------------------------
  114. ldr r1,= __iwram_lma
  115. ldr r2,= __iwram_start__
  116. ldr r4,= __iwram_end__
  117. bl CopyMemChk
  118. @---------------------------------------------------------------------------------
  119. @ Copy internal work ram overlay 0 (iwram0 section) from LMA to VMA (ROM to RAM)
  120. @---------------------------------------------------------------------------------
  121. ldr r2,= __load_stop_iwram0
  122. ldr r1,= __load_start_iwram0
  123. sub r3, r2, r1 @ Is there any data to copy?
  124. beq CIW0Skip @ no
  125. ldr r2,= __iwram_overlay_start
  126. bl CopyMem
  127. @---------------------------------------------------------------------------------
  128. CIW0Skip:
  129. @---------------------------------------------------------------------------------
  130. @ Copy external work ram (ewram section) from LMA to VMA (ROM to RAM)
  131. @---------------------------------------------------------------------------------
  132. ldr r1, =__ewram_lma
  133. ldr r2, =__ewram_start
  134. ldr r4, =__ewram_end
  135. bl CopyMemChk
  136. @---------------------------------------------------------------------------------
  137. CEW0Skip:
  138. @---------------------------------------------------------------------------------
  139. @ set heap end
  140. @---------------------------------------------------------------------------------
  141. ldr r1, =fake_heap_end
  142. ldr r0, =__eheap_end
  143. str r0, [r1]
  144. @---------------------------------------------------------------------------------
  145. @ global constructors
  146. @---------------------------------------------------------------------------------
  147. ldr r3, =__libc_init_array
  148. bl _blx_r3_stub
  149. @---------------------------------------------------------------------------------
  150. @ Jump to user code
  151. @---------------------------------------------------------------------------------
  152. mov r0, #0 @ int argc
  153. mov r1, #0 @ char *argv[]
  154. ldr r3, =main
  155. bl _blx_r3_stub
  156. @---------------------------------------------------------------------------------
  157. @ Clear memory to 0x00 if length != 0
  158. @---------------------------------------------------------------------------------
  159. @ r0 = Start Address
  160. @ r1 = Length
  161. @---------------------------------------------------------------------------------
  162. ClearMem:
  163. @---------------------------------------------------------------------------------
  164. mov r2,#3 @ These commands are used in cases where
  165. add r1,r2 @ the length is not a multiple of 4,
  166. bic r1,r2 @ even though it should be.
  167. beq ClearMX @ Length is zero so exit
  168. mov r2,#0
  169. @---------------------------------------------------------------------------------
  170. ClrLoop:
  171. @---------------------------------------------------------------------------------
  172. stmia r0!, {r2}
  173. sub r1,#4
  174. bne ClrLoop
  175. @---------------------------------------------------------------------------------
  176. ClearMX:
  177. @---------------------------------------------------------------------------------
  178. bx lr
  179. @---------------------------------------------------------------------------------
  180. _blx_r3_stub:
  181. @---------------------------------------------------------------------------------
  182. bx r3
  183. @---------------------------------------------------------------------------------
  184. @ Copy memory if length != 0
  185. @---------------------------------------------------------------------------------
  186. @ r1 = Source Address
  187. @ r2 = Dest Address
  188. @ r4 = Dest Address + Length
  189. @---------------------------------------------------------------------------------
  190. CopyMemChk:
  191. @---------------------------------------------------------------------------------
  192. sub r3, r4, r2 @ Is there any data to copy?
  193. @---------------------------------------------------------------------------------
  194. @ Copy memory
  195. @---------------------------------------------------------------------------------
  196. @ r1 = Source Address
  197. @ r2 = Dest Address
  198. @ r3 = Length
  199. @---------------------------------------------------------------------------------
  200. CopyMem:
  201. @---------------------------------------------------------------------------------
  202. mov r0, #3 @ These commands are used in cases where
  203. add r3, r0 @ the length is not a multiple of 4,
  204. bic r3, r0 @ even though it should be.
  205. beq CIDExit @ Length is zero so exit
  206. @---------------------------------------------------------------------------------
  207. CIDLoop:
  208. @---------------------------------------------------------------------------------
  209. ldmia r1!, {r0}
  210. stmia r2!, {r0}
  211. sub r3, #4
  212. bne CIDLoop
  213. @---------------------------------------------------------------------------------
  214. CIDExit:
  215. @---------------------------------------------------------------------------------
  216. bx lr
  217. .align
  218. .pool
  219. .end