boot_ghs.s 12 KB

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