boot.S 12 KB

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