boot.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 SPC56ELxx/boot.s
  15. * @brief SPC56ELxx 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. e_bl _coreinit
  38. e_bl _ivinit
  39. #if BOOT_RELOCATE_IN_RAM
  40. /*
  41. * Image relocation in RAM.
  42. */
  43. e_lis r4, __ram_reloc_start__@h
  44. e_or2i r4, __ram_reloc_start__@l
  45. e_lis r5, __ram_reloc_dest__@h
  46. e_or2i r5, __ram_reloc_dest__@l
  47. e_lis r6, __ram_reloc_end__@h
  48. e_or2i r6, r6, __ram_reloc_end__@l
  49. .relloop:
  50. se_cmpl r4, r6
  51. se_bge .relend
  52. se_lwz r7, 0(r4)
  53. se_addi r4, 4
  54. se_stw r7, 0(r5)
  55. se_addi r5, 4
  56. se_b .relloop
  57. .relend:
  58. e_lis r3, _boot_address@h
  59. e_or2i r3, _boot_address@l
  60. mtctr r3
  61. se_bctrl
  62. #else
  63. e_b _boot_address
  64. #endif
  65. #if BOOT_PERFORM_CORE_INIT
  66. .align 2
  67. _ramcode:
  68. tlbwe
  69. se_isync
  70. se_blr
  71. #endif /* BOOT_PERFORM_CORE_INIT */
  72. .align 2
  73. _coreinit:
  74. #if BOOT_PERFORM_CORE_INIT
  75. /*
  76. * Invalidating all TLBs except TLB0.
  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(1))@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. * TLB1 allocated to internal RAM.
  129. */
  130. e_lis r3, TLB1_MAS0@h
  131. mtspr 624, r3 /* MAS0 */
  132. e_lis r3, TLB1_MAS1@h
  133. e_or2i r3, TLB1_MAS1@l
  134. mtspr 625, r3 /* MAS1 */
  135. e_lis r3, TLB1_MAS2@h
  136. e_or2i r3, TLB1_MAS2@l
  137. mtspr 626, r3 /* MAS2 */
  138. e_lis r3, TLB1_MAS3@h
  139. e_or2i r3, TLB1_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. * TLB5 allocated to on-platform peripherals.
  189. */
  190. e_lis r3, TLB5_MAS0@h
  191. mtspr 624, r3 /* MAS0 */
  192. e_lis r3, TLB5_MAS1@h
  193. e_or2i r3, TLB5_MAS1@l
  194. mtspr 625, r3 /* MAS1 */
  195. e_lis r3, TLB5_MAS2@h
  196. e_or2i r3, TLB5_MAS2@l
  197. mtspr 626, r3 /* MAS2 */
  198. e_lis r3, TLB5_MAS3@h
  199. e_or2i r3, TLB5_MAS3@l
  200. mtspr 627, r3 /* MAS3 */
  201. tlbwe
  202. /*
  203. * RAM clearing, this device requires a write to all RAM location in
  204. * order to initialize the ECC detection hardware, this is going to
  205. * slow down the startup but there is no way around.
  206. */
  207. xor r0, r0, r0
  208. xor r1, r1, r1
  209. xor r2, r2, r2
  210. xor r3, r3, r3
  211. xor r4, r4, r4
  212. xor r5, r5, r5
  213. xor r6, r6, r6
  214. xor r7, r7, r7
  215. xor r8, r8, r8
  216. xor r9, r9, r9
  217. xor r10, r10, r10
  218. xor r11, r11, r11
  219. xor r12, r12, r12
  220. xor r13, r13, r13
  221. xor r14, r14, r14
  222. xor r15, r15, r15
  223. xor r16, r16, r16
  224. xor r17, r17, r17
  225. xor r18, r18, r18
  226. xor r19, r19, r19
  227. xor r20, r20, r20
  228. xor r21, r21, r21
  229. xor r22, r22, r22
  230. xor r23, r23, r23
  231. xor r24, r24, r24
  232. xor r25, r25, r25
  233. xor r26, r26, r26
  234. xor r27, r27, r27
  235. xor r28, r28, r28
  236. xor r29, r29, r29
  237. xor r30, r30, r30
  238. xor r31, r31, r31
  239. e_lis r4, __ram_start__@h
  240. e_or2i r4, __ram_start__@l
  241. e_lis r5, __ram_end__@h
  242. e_or2i r5, __ram_end__@l
  243. .cleareccloop:
  244. se_cmpl r4, r5
  245. se_bge .cleareccend
  246. e_stmw r16, 0(r4)
  247. e_addi r4, r4, 64
  248. se_b .cleareccloop
  249. .cleareccend:
  250. #endif /* BOOT_PERFORM_CORE_INIT */
  251. /*
  252. * Special function registers clearing, required in order to avoid
  253. * possible problems with lockstep mode.
  254. */
  255. mtcrf 0xFF, r31
  256. mtspr 9, r31 /* CTR */
  257. mtspr 22, r31 /* DEC */
  258. mtspr 26, r31 /* SRR0-1 */
  259. mtspr 27, r31
  260. mtspr 54, r31 /* DECAR */
  261. mtspr 58, r31 /* CSRR0-1 */
  262. mtspr 59, r31
  263. mtspr 61, r31 /* DEAR */
  264. mtspr 256, r31 /* USPRG0 */
  265. mtspr 272, r31 /* SPRG1-7 */
  266. mtspr 273, r31
  267. mtspr 274, r31
  268. mtspr 275, r31
  269. mtspr 276, r31
  270. mtspr 277, r31
  271. mtspr 278, r31
  272. mtspr 279, r31
  273. mtspr 285, r31 /* TBU */
  274. mtspr 284, r31 /* TBL */
  275. #if 0
  276. mtspr 318, r31 /* DVC1-2 */
  277. mtspr 319, r31
  278. #endif
  279. mtspr 562, r31 /* DBCNT */
  280. mtspr 570, r31 /* MCSRR0 */
  281. mtspr 571, r31 /* MCSRR1 */
  282. mtspr 604, r31 /* SPRG8-9 */
  283. mtspr 605, r31
  284. #if BOOT_PERFORM_CORE_INIT
  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. 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. #endif /* BOOT_PERFORM_CORE_INIT */
  314. /*
  315. * Branch prediction enabled.
  316. */
  317. e_li r3, BOOT_BUCSR_DEFAULT
  318. mtspr 1013, r3 /* BUCSR */
  319. /*
  320. * Cache invalidated and then enabled.
  321. */
  322. e_li r3, LICSR1_ICINV
  323. mtspr 1011, r3 /* LICSR1 */
  324. .inv: mfspr r3, 1011 /* LICSR1 */
  325. e_and2i. r3, LICSR1_ICINV
  326. se_bne .inv
  327. e_lis r3, BOOT_LICSR1_DEFAULT@h
  328. e_or2i r3, BOOT_LICSR1_DEFAULT@l
  329. mtspr 1011, r3 /* LICSR1 */
  330. se_blr
  331. /*
  332. * Exception vectors initialization.
  333. */
  334. .align 2
  335. _ivinit:
  336. /* MSR initialization.*/
  337. e_lis r3, BOOT_MSR_DEFAULT@h
  338. e_or2i 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. .section .handlers, "ax"
  368. /*
  369. * Unhandled exceptions handler.
  370. */
  371. .weak _unhandled_exception
  372. .type _unhandled_exception, @function
  373. _unhandled_exception:
  374. se_b _unhandled_exception
  375. #endif /* !defined(__DOXYGEN__) */
  376. /** @} */