boot_cw.s 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 SPC56ECxx/boot.s
  15. * @brief SPC56ECxx boot-related code.
  16. *
  17. * @addtogroup PPC_BOOT
  18. * @{
  19. */
  20. #include "boot.h"
  21. #if !defined(__DOXYGEN__)
  22. .extern _boot_address
  23. .extern __ram_start__
  24. .extern __ram_end__
  25. .extern __ivpr_base__
  26. .extern _unhandled_exception
  27. /* BAM record.*/
  28. .section .boot, 16
  29. #if BOOT_USE_VLE
  30. .long 0x015A0000
  31. #else
  32. .long 0x005A0000
  33. #endif
  34. .long _reset_address
  35. .align 4
  36. .globl _reset_address
  37. .type _reset_address, @function
  38. _reset_address:
  39. #if BOOT_PERFORM_CORE_INIT
  40. e_bl _coreinit
  41. #endif
  42. e_bl _ivinit
  43. #if BOOT_RELOCATE_IN_RAM
  44. /*
  45. * Image relocation in RAM.
  46. */
  47. e_lis r4, __ram_reloc_start__@h
  48. e_or2i r4, r4, __ram_reloc_start__@l
  49. e_lis r5, __ram_reloc_dest__@h
  50. e_or2i r5, r5, __ram_reloc_dest__@l
  51. e_lis r6, __ram_reloc_end__@h
  52. e_or2i r6, r6, __ram_reloc_end__@l
  53. .relloop:
  54. se_cmpl r4, r6
  55. se_bge .relend
  56. se_lwz r7, 0(r4)
  57. se_addi r4, 4
  58. se_stw r7, 0(r5)
  59. se_addi r5, 4
  60. se_b .relloop
  61. .relend:
  62. e_lis r3, _boot_address@h
  63. e_or2i r3, _boot_address@l
  64. mtctr r3
  65. se_bctrl
  66. #else
  67. e_b _boot_address
  68. #endif
  69. #if BOOT_PERFORM_CORE_INIT
  70. .align 4
  71. _ramcode:
  72. tlbwe
  73. se_isync
  74. se_blr
  75. .align 2
  76. _coreinit:
  77. /*
  78. * Invalidating all TLBs except TLB0.
  79. */
  80. e_lis r3, 0
  81. mtspr 625, r3 /* MAS1 */
  82. mtspr 626, r3 /* MAS2 */
  83. mtspr 627, r3 /* MAS3 */
  84. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(1))@h
  85. mtspr 624, r3 /* MAS0 */
  86. tlbwe
  87. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(2))@h
  88. mtspr 624, r3 /* MAS0 */
  89. tlbwe
  90. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(3))@h
  91. mtspr 624, r3 /* MAS0 */
  92. tlbwe
  93. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(4))@h
  94. mtspr 624, r3 /* MAS0 */
  95. tlbwe
  96. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(5))@h
  97. mtspr 624, r3 /* MAS0 */
  98. tlbwe
  99. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(6))@h
  100. mtspr 624, r3 /* MAS0 */
  101. tlbwe
  102. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(7))@h
  103. mtspr 624, r3 /* MAS0 */
  104. tlbwe
  105. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(8))@h
  106. mtspr 624, r3 /* MAS0 */
  107. tlbwe
  108. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(9))@h
  109. mtspr 624, r3 /* MAS0 */
  110. tlbwe
  111. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(10))@h
  112. mtspr 624, r3 /* MAS0 */
  113. tlbwe
  114. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(11))@h
  115. mtspr 624, r3 /* MAS0 */
  116. tlbwe
  117. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(12))@h
  118. mtspr 624, r3 /* MAS0 */
  119. tlbwe
  120. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(13))@h
  121. mtspr 624, r3 /* MAS0 */
  122. tlbwe
  123. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(14))@h
  124. mtspr 624, r3 /* MAS0 */
  125. tlbwe
  126. e_lis r3, (MAS0_TBLMAS_TBL | MAS0_ESEL(15))@h
  127. mtspr 624, r3 /* MAS0 */
  128. tlbwe
  129. /*
  130. * TLB1 allocated to internal RAM.
  131. */
  132. e_lis r3, TLB1_MAS0@h
  133. mtspr 624, r3 /* MAS0 */
  134. e_lis r3, TLB1_MAS1@h
  135. e_or2i r3, TLB1_MAS1@l
  136. mtspr 625, r3 /* MAS1 */
  137. e_lis r3, TLB1_MAS2@h
  138. e_or2i r3, TLB1_MAS2@l
  139. mtspr 626, r3 /* MAS2 */
  140. e_lis r3, TLB1_MAS3@h
  141. e_or2i r3, TLB1_MAS3@l
  142. mtspr 627, r3 /* MAS3 */
  143. tlbwe
  144. /*
  145. * TLB2 allocated to internal Peripherals Bridge A.
  146. */
  147. e_lis r3, TLB2_MAS0@h
  148. mtspr 624, r3 /* MAS0 */
  149. e_lis r3, TLB2_MAS1@h
  150. e_or2i r3, TLB2_MAS1@l
  151. mtspr 625, r3 /* MAS1 */
  152. e_lis r3, TLB2_MAS2@h
  153. e_or2i r3, TLB2_MAS2@l
  154. mtspr 626, r3 /* MAS2 */
  155. e_lis r3, TLB2_MAS3@h
  156. e_or2i r3, TLB2_MAS3@l
  157. mtspr 627, r3 /* MAS3 */
  158. tlbwe
  159. /*
  160. * TLB3 allocated to internal Peripherals Bridge B.
  161. */
  162. e_lis r3, TLB3_MAS0@h
  163. mtspr 624, r3 /* MAS0 */
  164. e_lis r3, TLB3_MAS1@h
  165. e_or2i r3, TLB3_MAS1@l
  166. mtspr 625, r3 /* MAS1 */
  167. e_lis r3, TLB3_MAS2@h
  168. e_or2i r3, TLB3_MAS2@l
  169. mtspr 626, r3 /* MAS2 */
  170. e_lis r3, TLB3_MAS3@h
  171. e_or2i r3, TLB3_MAS3@l
  172. mtspr 627, r3 /* MAS3 */
  173. tlbwe
  174. /*
  175. * TLB4 allocated to on-platform peripherals.
  176. */
  177. e_lis r3, TLB4_MAS0@h
  178. mtspr 624, r3 /* MAS0 */
  179. e_lis r3, TLB4_MAS1@h
  180. e_or2i r3, TLB4_MAS1@l
  181. mtspr 625, r3 /* MAS1 */
  182. e_lis r3, TLB4_MAS2@h
  183. e_or2i r3, TLB4_MAS2@l
  184. mtspr 626, r3 /* MAS2 */
  185. e_lis r3, TLB4_MAS3@h
  186. e_or2i r3, TLB4_MAS3@l
  187. mtspr 627, r3 /* MAS3 */
  188. tlbwe
  189. /*
  190. * TLB5 allocated to on-platform peripherals.
  191. */
  192. e_lis r3, TLB5_MAS0@h
  193. mtspr 624, r3 /* MAS0 */
  194. e_lis r3, TLB5_MAS1@h
  195. e_or2i r3, TLB5_MAS1@l
  196. mtspr 625, r3 /* MAS1 */
  197. e_lis r3, TLB5_MAS2@h
  198. e_or2i r3, TLB5_MAS2@l
  199. mtspr 626, r3 /* MAS2 */
  200. e_lis r3, TLB5_MAS3@h
  201. e_or2i r3, TLB5_MAS3@l
  202. mtspr 627, r3 /* MAS3 */
  203. tlbwe
  204. /*
  205. * RAM clearing, this device requires a write to all RAM location in
  206. * order to initialize the ECC detection hardware, this is going to
  207. * slow down the startup but there is no way around.
  208. */
  209. xor r0, r0, r0
  210. xor r1, r1, r1
  211. xor r2, r2, r2
  212. xor r3, r3, r3
  213. xor r4, r4, r4
  214. xor r5, r5, r5
  215. xor r6, r6, r6
  216. xor r7, r7, r7
  217. xor r8, r8, r8
  218. xor r9, r9, r9
  219. xor r10, r10, r10
  220. xor r11, r11, r11
  221. xor r12, r12, r12
  222. xor r13, r13, r13
  223. xor r14, r14, r14
  224. xor r15, r15, r15
  225. xor r16, r16, r16
  226. xor r17, r17, r17
  227. xor r18, r18, r18
  228. xor r19, r19, r19
  229. xor r20, r20, r20
  230. xor r21, r21, r21
  231. xor r22, r22, r22
  232. xor r23, r23, r23
  233. xor r24, r24, r24
  234. xor r25, r25, r25
  235. xor r26, r26, r26
  236. xor r27, r27, r27
  237. xor r28, r28, r28
  238. xor r29, r29, r29
  239. xor r30, r30, r30
  240. xor r31, r31, r31
  241. e_lis r4, __ram_start__@h
  242. e_or2i r4, __ram_start__@l
  243. e_lis r5, __ram_end__@h
  244. e_or2i r5, __ram_end__@l
  245. .cleareccloop:
  246. se_cmpl r4, r5
  247. se_bge .cleareccend
  248. e_stmw r16, 0(r4)
  249. e_addi r4, r4, 64
  250. se_b .cleareccloop
  251. .cleareccend:
  252. /*
  253. * Special function registers clearing, required in order to avoid
  254. * possible problems with lockstep mode.
  255. */
  256. mtcrf 0xFF, r31
  257. mtspr 9, r31 /* CTR */
  258. mtspr 22, r31 /* DEC */
  259. mtspr 26, r31 /* SRR0-1 */
  260. mtspr 27, r31
  261. mtspr 54, r31 /* DECAR */
  262. mtspr 58, r31 /* CSRR0-1 */
  263. mtspr 59, r31
  264. mtspr 61, r31 /* DEAR */
  265. mtspr 256, r31 /* USPRG0 */
  266. mtspr 272, r31 /* SPRG1-7 */
  267. mtspr 273, r31
  268. mtspr 274, r31
  269. mtspr 275, r31
  270. mtspr 276, r31
  271. mtspr 277, r31
  272. mtspr 278, r31
  273. mtspr 279, r31
  274. mtspr 285, r31 /* TBU */
  275. mtspr 284, r31 /* TBL */
  276. #if 0
  277. mtspr 318, r31 /* DVC1-2 */
  278. mtspr 319, r31
  279. #endif
  280. mtspr 562, r31 /* DBCNT */
  281. mtspr 570, r31 /* MCSRR0 */
  282. mtspr 571, r31 /* MCSRR1 */
  283. mtspr 604, r31 /* SPRG8-9 */
  284. mtspr 605, r31
  285. /*
  286. * *Finally* the TLB0 is re-allocated to flash, note, the final phase
  287. * is executed from RAM.
  288. */
  289. e_lis r3, TLB0_MAS0@h
  290. mtspr 624, r3 /* MAS0 */
  291. e_lis r3, TLB0_MAS1@h
  292. e_or2i r3, TLB0_MAS1@l
  293. mtspr 625, r3 /* MAS1 */
  294. e_lis r3, TLB0_MAS2@h
  295. e_or2i r3, TLB0_MAS2@l
  296. mtspr 626, r3 /* MAS2 */
  297. e_lis r3, TLB0_MAS3@h
  298. e_or2i r3, TLB0_MAS3@l
  299. mtspr 627, r3 /* MAS3 */
  300. se_mflr r4
  301. e_lis r6, _ramcode@h
  302. e_or2i r6, _ramcode@l
  303. e_lis r7, 0x40010000@h
  304. mtctr r7
  305. se_lwz r3, 0(r6)
  306. se_stw r3, 0(r7)
  307. se_lwz r3, 4(r6)
  308. se_stw r3, 4(r7)
  309. se_lwz r3, 8(r6)
  310. se_stw r3, 8(r7)
  311. se_bctrl
  312. mtlr r4
  313. /*
  314. * Branch prediction enabled.
  315. */
  316. e_li r3, BOOT_BUCSR_DEFAULT
  317. mtspr 1013, r3 /* BUCSR */
  318. /*
  319. * Cache invalidated and then enabled.
  320. */
  321. se_li r3, LICSR1_ICINV
  322. mtspr 1011, r3 /* LICSR1 */
  323. .inv: mfspr r3, 1011 /* LICSR1 */
  324. e_andi. r3, r3, LICSR1_ICINV
  325. se_bne .inv
  326. e_lis r3, BOOT_LICSR1_DEFAULT@h
  327. e_or2i r3, BOOT_LICSR1_DEFAULT@l
  328. mtspr 1011, r3 /* LICSR1 */
  329. se_blr
  330. #endif /* BOOT_PERFORM_CORE_INIT */
  331. /*
  332. * Exception vectors initialization.
  333. */
  334. .align 4
  335. _ivinit:
  336. /* MSR initialization.*/
  337. e_lis r3, BOOT_MSR_DEFAULT@h
  338. e_ori r3, r3, BOOT_MSR_DEFAULT@l
  339. mtMSR r3
  340. /* IVPR initialization.*/
  341. e_lis r3, __ivpr_base__@h
  342. e_or2i r3, __ivpr_base__@l
  343. mtIVPR r3
  344. /* IVORs initialization.*/
  345. e_lis r3, _unhandled_exception@h
  346. e_or2i r3, _unhandled_exception@l
  347. mtspr 400, r3 /* IVOR0-15 */
  348. mtspr 401, r3
  349. mtspr 402, r3
  350. mtspr 403, r3
  351. mtspr 404, r3
  352. mtspr 405, r3
  353. mtspr 406, r3
  354. mtspr 407, r3
  355. mtspr 408, r3
  356. mtspr 409, r3
  357. mtspr 410, r3
  358. mtspr 411, r3
  359. mtspr 412, r3
  360. mtspr 413, r3
  361. mtspr 414, r3
  362. mtspr 415, r3
  363. mtspr 528, r3 /* IVOR32-34 */
  364. mtspr 529, r3
  365. mtspr 530, r3
  366. se_blr
  367. #endif /* !defined(__DOXYGEN__) */
  368. /** @} */