boot.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SPC564Axx/boot.s
  15. * @brief SPC564Axx boot-related code.
  16. *
  17. * @addtogroup PPC_BOOT
  18. * @{
  19. */
  20. #include "boot.h"
  21. #if defined(__HIGHTEC__)
  22. #define se_bge bge
  23. #endif
  24. #if !defined(__DOXYGEN__)
  25. /* BAM record.*/
  26. .section .boot, "ax"
  27. #if BOOT_USE_VLE
  28. .long 0x015A0000
  29. #else
  30. .long 0x005A0000
  31. #endif
  32. .long _reset_address
  33. .align 2
  34. .globl _reset_address
  35. .type _reset_address, @function
  36. _reset_address:
  37. #if BOOT_PERFORM_CORE_INIT
  38. e_bl _coreinit
  39. #endif
  40. e_bl _ivinit
  41. #if BOOT_RELOCATE_IN_RAM
  42. /*
  43. * Image relocation in RAM.
  44. */
  45. e_lis r4, __ram_reloc_start__@h
  46. e_or2i r4, __ram_reloc_start__@l
  47. e_lis r5, __ram_reloc_dest__@h
  48. e_or2i r5, __ram_reloc_dest__@l
  49. e_lis r6, __ram_reloc_end__@h
  50. e_or2i r6, r6, __ram_reloc_end__@l
  51. .relloop:
  52. se_cmpl r4, r6
  53. se_bge .relend
  54. se_lwz r7, 0(r4)
  55. se_addi r4, 4
  56. se_stw r7, 0(r5)
  57. se_addi r5, 4
  58. se_b .relloop
  59. .relend:
  60. e_lis r3, _boot_address@h
  61. e_or2i r3, _boot_address@l
  62. mtctr r3
  63. se_bctrl
  64. #else
  65. e_b _boot_address
  66. #endif
  67. #if BOOT_PERFORM_CORE_INIT
  68. .align 2
  69. _ramcode:
  70. tlbwe
  71. se_isync
  72. se_blr
  73. .align 2
  74. _coreinit:
  75. /*
  76. * Invalidating all TLBs except TLB1.
  77. */
  78. e_lis r3, 0
  79. mtspr 625, r3 /* MAS1 */
  80. mtspr 626, r3 /* MAS2 */
  81. mtspr 627, r3 /* MAS3 */
  82. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(0))@h
  83. mtspr 624, r3 /* MAS0 */
  84. tlbwe
  85. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(2))@h
  86. mtspr 624, r3 /* MAS0 */
  87. tlbwe
  88. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(3))@h
  89. mtspr 624, r3 /* MAS0 */
  90. tlbwe
  91. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(4))@h
  92. mtspr 624, r3 /* MAS0 */
  93. tlbwe
  94. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(5))@h
  95. mtspr 624, r3 /* MAS0 */
  96. tlbwe
  97. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(6))@h
  98. mtspr 624, r3 /* MAS0 */
  99. tlbwe
  100. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(7))@h
  101. mtspr 624, r3 /* MAS0 */
  102. tlbwe
  103. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(8))@h
  104. mtspr 624, r3 /* MAS0 */
  105. tlbwe
  106. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(9))@h
  107. mtspr 624, r3 /* MAS0 */
  108. tlbwe
  109. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(10))@h
  110. mtspr 624, r3 /* MAS0 */
  111. tlbwe
  112. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(11))@h
  113. mtspr 624, r3 /* MAS0 */
  114. tlbwe
  115. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(12))@h
  116. mtspr 624, r3 /* MAS0 */
  117. tlbwe
  118. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(13))@h
  119. mtspr 624, r3 /* MAS0 */
  120. tlbwe
  121. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(14))@h
  122. mtspr 624, r3 /* MAS0 */
  123. tlbwe
  124. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(15))@h
  125. mtspr 624, r3 /* MAS0 */
  126. tlbwe
  127. /*
  128. * TLB0 allocated to internal RAM.
  129. */
  130. e_lis r3, TLB0_MAS0@h
  131. mtspr 624, r3 /* MAS0 */
  132. e_lis r3, TLB0_MAS1@h
  133. e_or2i r3, TLB0_MAS1@l
  134. mtspr 625, r3 /* MAS1 */
  135. e_lis r3, TLB0_MAS2@h
  136. e_or2i r3, TLB0_MAS2@l
  137. mtspr 626, r3 /* MAS2 */
  138. e_lis r3, TLB0_MAS3@h
  139. e_or2i r3, TLB0_MAS3@l
  140. mtspr 627, r3 /* MAS3 */
  141. tlbwe
  142. /*
  143. * TLB2 allocated to internal Peripherals Bridge A.
  144. */
  145. e_lis r3, TLB2_MAS0@h
  146. mtspr 624, r3 /* MAS0 */
  147. e_lis r3, TLB2_MAS1@h
  148. e_or2i r3, TLB2_MAS1@l
  149. mtspr 625, r3 /* MAS1 */
  150. e_lis r3, TLB2_MAS2@h
  151. e_or2i r3, TLB2_MAS2@l
  152. mtspr 626, r3 /* MAS2 */
  153. e_lis r3, TLB2_MAS3@h
  154. e_or2i r3, TLB2_MAS3@l
  155. mtspr 627, r3 /* MAS3 */
  156. tlbwe
  157. /*
  158. * TLB3 allocated to internal Peripherals Bridge B.
  159. */
  160. e_lis r3, TLB3_MAS0@h
  161. mtspr 624, r3 /* MAS0 */
  162. e_lis r3, TLB3_MAS1@h
  163. e_or2i r3, TLB3_MAS1@l
  164. mtspr 625, r3 /* MAS1 */
  165. e_lis r3, TLB3_MAS2@h
  166. e_or2i r3, TLB3_MAS2@l
  167. mtspr 626, r3 /* MAS2 */
  168. e_lis r3, TLB3_MAS3@h
  169. e_or2i r3, TLB3_MAS3@l
  170. mtspr 627, r3 /* MAS3 */
  171. tlbwe
  172. /*
  173. * TLB4 allocated to on-platform peripherals.
  174. */
  175. e_lis r3, TLB4_MAS0@h
  176. mtspr 624, r3 /* MAS0 */
  177. e_lis r3, TLB4_MAS1@h
  178. e_or2i r3, TLB4_MAS1@l
  179. mtspr 625, r3 /* MAS1 */
  180. e_lis r3, TLB4_MAS2@h
  181. e_or2i r3, TLB4_MAS2@l
  182. mtspr 626, r3 /* MAS2 */
  183. e_lis r3, TLB4_MAS3@h
  184. e_or2i r3, TLB4_MAS3@l
  185. mtspr 627, r3 /* MAS3 */
  186. tlbwe
  187. /*
  188. * RAM clearing, this device requires a write to all RAM location in
  189. * order to initialize the ECC detection hardware, this is going to
  190. * slow down the startup but there is no way around.
  191. */
  192. xor r0, r0, r0
  193. xor r1, r1, r1
  194. xor r2, r2, r2
  195. xor r3, r3, r3
  196. xor r4, r4, r4
  197. xor r5, r5, r5
  198. xor r6, r6, r6
  199. xor r7, r7, r7
  200. xor r8, r8, r8
  201. xor r9, r9, r9
  202. xor r10, r10, r10
  203. xor r11, r11, r11
  204. xor r12, r12, r12
  205. xor r13, r13, r13
  206. xor r14, r14, r14
  207. xor r15, r15, r15
  208. xor r16, r16, r16
  209. xor r17, r17, r17
  210. xor r18, r18, r18
  211. xor r19, r19, r19
  212. xor r20, r20, r20
  213. xor r21, r21, r21
  214. xor r22, r22, r22
  215. xor r23, r23, r23
  216. xor r24, r24, r24
  217. xor r25, r25, r25
  218. xor r26, r26, r26
  219. xor r27, r27, r27
  220. xor r28, r28, r28
  221. xor r29, r29, r29
  222. xor r30, r30, r30
  223. xor r31, r31, r31
  224. e_lis r4, __ram_start__@h
  225. e_or2i r4, __ram_start__@l
  226. e_lis r5, __ram_end__@h
  227. e_or2i r5, __ram_end__@l
  228. .cleareccloop:
  229. se_cmpl r4, r5
  230. se_bge .cleareccend
  231. e_stmw r16, 0(r4)
  232. e_addi r4, r4, 64
  233. se_b .cleareccloop
  234. .cleareccend:
  235. /*
  236. * *Finally* the TLB1 is re-allocated to flash, note, the final phase
  237. * is executed from RAM.
  238. */
  239. e_lis r3, TLB1_MAS0@h
  240. mtspr 624, r3 /* MAS0 */
  241. e_lis r3, TLB1_MAS1@h
  242. e_or2i r3, TLB1_MAS1@l
  243. mtspr 625, r3 /* MAS1 */
  244. e_lis r3, TLB1_MAS2@h
  245. e_or2i r3, TLB1_MAS2@l
  246. mtspr 626, r3 /* MAS2 */
  247. e_lis r3, TLB1_MAS3@h
  248. e_or2i r3, TLB1_MAS3@l
  249. mtspr 627, r3 /* MAS3 */
  250. mflr r4
  251. e_lis r6, _ramcode@h
  252. e_or2i r6, _ramcode@l
  253. e_lis r7, 0x40010000@h
  254. mtctr r7
  255. se_lwz r3, 0(r6)
  256. se_stw r3, 0(r7)
  257. se_lwz r3, 4(r6)
  258. se_stw r3, 4(r7)
  259. se_lwz r3, 8(r6)
  260. se_stw r3, 8(r7)
  261. se_bctrl
  262. mtlr r4
  263. /*
  264. * Branch prediction enabled.
  265. */
  266. e_li r3, BOOT_BUCSR_DEFAULT
  267. mtspr 1013, r3 /* BUCSR */
  268. /*
  269. * Cache invalidated and then enabled.
  270. */
  271. e_li r3, LICSR1_ICINV
  272. mtspr 1011, r3 /* LICSR1 */
  273. .inv: mfspr r3, 1011 /* LICSR1 */
  274. e_and2i. r3, LICSR1_ICINV
  275. se_bne .inv
  276. e_lis r3, BOOT_LICSR1_DEFAULT@h
  277. e_or2i r3, BOOT_LICSR1_DEFAULT@l
  278. mtspr 1011, r3 /* LICSR1 */
  279. se_blr
  280. #endif /* BOOT_PERFORM_CORE_INIT */
  281. /*
  282. * Exception vectors initialization.
  283. */
  284. .align 2
  285. _ivinit:
  286. /* MSR initialization.*/
  287. e_lis r3, BOOT_MSR_DEFAULT@h
  288. e_or2i r3, BOOT_MSR_DEFAULT@l
  289. mtMSR r3
  290. /* IVPR initialization.*/
  291. e_lis r3, __ivpr_base__@h
  292. e_or2i r3, __ivpr_base__@l
  293. mtIVPR r3
  294. /* IVORs initialization.*/
  295. e_lis r3, _unhandled_exception@h
  296. e_or2i r3, _unhandled_exception@l
  297. mtspr 400, r3 /* IVOR0-15 */
  298. mtspr 401, r3
  299. mtspr 402, r3
  300. mtspr 403, r3
  301. mtspr 404, r3
  302. mtspr 405, r3
  303. mtspr 406, r3
  304. mtspr 407, r3
  305. mtspr 408, r3
  306. mtspr 409, r3
  307. mtspr 410, r3
  308. mtspr 411, r3
  309. mtspr 412, r3
  310. mtspr 413, r3
  311. mtspr 414, r3
  312. mtspr 415, r3
  313. mtspr 528, r3 /* IVOR32-34 */
  314. mtspr 529, r3
  315. mtspr 530, r3
  316. se_blr
  317. .section .handlers, "ax"
  318. /*
  319. * Unhandled exceptions handler.
  320. */
  321. .weak _unhandled_exception
  322. .type _unhandled_exception, @function
  323. _unhandled_exception:
  324. se_b _unhandled_exception
  325. #endif /* !defined(__DOXYGEN__) */
  326. /** @} */