prt0.as 9.0 KB

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