cache_8xx.S 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /*
  2. * Copyright (C) 2002 Wolfgang Denk <wd@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <config.h>
  7. #if defined(CONFIG_MPC823) || \
  8. defined(CONFIG_MPC850) || \
  9. defined(CONFIG_MPC855) || \
  10. defined(CONFIG_MPC860) || \
  11. defined(CONFIG_MPC862)
  12. #include <post.h>
  13. #include <ppc_asm.tmpl>
  14. #include <ppc_defs.h>
  15. #include <asm/cache.h>
  16. #if CONFIG_POST & CONFIG_SYS_POST_CACHE
  17. .text
  18. cache_post_dinvalidate:
  19. lis r10, IDC_INVALL@h
  20. mtspr DC_CST, r10
  21. blr
  22. cache_post_iinvalidate:
  23. lis r10, IDC_INVALL@h
  24. mtspr IC_CST, r10
  25. isync
  26. blr
  27. cache_post_ddisable:
  28. lis r10, IDC_DISABLE@h
  29. mtspr DC_CST, r10
  30. blr
  31. cache_post_dwb:
  32. lis r10, IDC_ENABLE@h
  33. mtspr DC_CST, r10
  34. lis r10, DC_CFWT@h
  35. mtspr DC_CST, r10
  36. blr
  37. cache_post_dwt:
  38. lis r10, IDC_ENABLE@h
  39. mtspr DC_CST, r10
  40. lis r10, DC_SFWT@h
  41. mtspr DC_CST, r10
  42. blr
  43. cache_post_idisable:
  44. lis r10, IDC_DISABLE@h
  45. mtspr IC_CST, r10
  46. isync
  47. blr
  48. cache_post_ienable:
  49. lis r10, IDC_ENABLE@h
  50. mtspr IC_CST, r10
  51. isync
  52. blr
  53. cache_post_iunlock:
  54. lis r10, IDC_UNALL@h
  55. mtspr IC_CST, r10
  56. isync
  57. blr
  58. cache_post_ilock:
  59. mtspr IC_ADR, r3
  60. lis r10, IDC_LDLCK@h
  61. mtspr IC_CST, r10
  62. isync
  63. blr
  64. /*
  65. * turn on the data cache
  66. * switch the data cache to write-back or write-through mode
  67. * invalidate the data cache
  68. * write the negative pattern to a cached area
  69. * read the area
  70. *
  71. * The negative pattern must be read at the last step
  72. */
  73. .global cache_post_test1
  74. cache_post_test1:
  75. mflr r0
  76. stw r0, 4(r1)
  77. stwu r3, -4(r1)
  78. stwu r4, -4(r1)
  79. bl cache_post_dwb
  80. bl cache_post_dinvalidate
  81. /* Write the negative pattern to the test area */
  82. lwz r0, 0(r1)
  83. mtctr r0
  84. li r0, 0xff
  85. lwz r3, 4(r1)
  86. subi r3, r3, 1
  87. 1:
  88. stbu r0, 1(r3)
  89. bdnz 1b
  90. /* Read the test area */
  91. lwz r0, 0(r1)
  92. mtctr r0
  93. lwz r4, 4(r1)
  94. subi r4, r4, 1
  95. li r3, 0
  96. 1:
  97. lbzu r0, 1(r4)
  98. cmpli cr0, r0, 0xff
  99. beq 2f
  100. li r3, -1
  101. b 3f
  102. 2:
  103. bdnz 1b
  104. 3:
  105. bl cache_post_ddisable
  106. bl cache_post_dinvalidate
  107. addi r1, r1, 8
  108. lwz r0, 4(r1)
  109. mtlr r0
  110. blr
  111. /*
  112. * turn on the data cache
  113. * switch the data cache to write-back or write-through mode
  114. * invalidate the data cache
  115. * write the zero pattern to a cached area
  116. * turn off the data cache
  117. * write the negative pattern to the area
  118. * turn on the data cache
  119. * read the area
  120. *
  121. * The negative pattern must be read at the last step
  122. */
  123. .global cache_post_test2
  124. cache_post_test2:
  125. mflr r0
  126. stw r0, 4(r1)
  127. stwu r3, -4(r1)
  128. stwu r4, -4(r1)
  129. bl cache_post_dwb
  130. bl cache_post_dinvalidate
  131. /* Write the zero pattern to the test area */
  132. lwz r0, 0(r1)
  133. mtctr r0
  134. li r0, 0
  135. lwz r3, 4(r1)
  136. subi r3, r3, 1
  137. 1:
  138. stbu r0, 1(r3)
  139. bdnz 1b
  140. bl cache_post_ddisable
  141. /* Write the negative pattern to the test area */
  142. lwz r0, 0(r1)
  143. mtctr r0
  144. li r0, 0xff
  145. lwz r3, 4(r1)
  146. subi r3, r3, 1
  147. 1:
  148. stbu r0, 1(r3)
  149. bdnz 1b
  150. bl cache_post_dwb
  151. /* Read the test area */
  152. lwz r0, 0(r1)
  153. mtctr r0
  154. lwz r4, 4(r1)
  155. subi r4, r4, 1
  156. li r3, 0
  157. 1:
  158. lbzu r0, 1(r4)
  159. cmpli cr0, r0, 0xff
  160. beq 2f
  161. li r3, -1
  162. b 3f
  163. 2:
  164. bdnz 1b
  165. 3:
  166. bl cache_post_ddisable
  167. bl cache_post_dinvalidate
  168. addi r1, r1, 8
  169. lwz r0, 4(r1)
  170. mtlr r0
  171. blr
  172. /*
  173. * turn on the data cache
  174. * switch the data cache to write-through mode
  175. * invalidate the data cache
  176. * write the zero pattern to a cached area
  177. * flush the data cache
  178. * write the negative pattern to the area
  179. * turn off the data cache
  180. * read the area
  181. *
  182. * The negative pattern must be read at the last step
  183. */
  184. .global cache_post_test3
  185. cache_post_test3:
  186. mflr r0
  187. stw r0, 4(r1)
  188. stwu r3, -4(r1)
  189. stwu r4, -4(r1)
  190. bl cache_post_ddisable
  191. bl cache_post_dinvalidate
  192. /* Write the zero pattern to the test area */
  193. lwz r0, 0(r1)
  194. mtctr r0
  195. li r0, 0
  196. lwz r3, 4(r1)
  197. subi r3, r3, 1
  198. 1:
  199. stbu r0, 1(r3)
  200. bdnz 1b
  201. bl cache_post_dwt
  202. bl cache_post_dinvalidate
  203. /* Write the negative pattern to the test area */
  204. lwz r0, 0(r1)
  205. mtctr r0
  206. li r0, 0xff
  207. lwz r3, 4(r1)
  208. subi r3, r3, 1
  209. 1:
  210. stbu r0, 1(r3)
  211. bdnz 1b
  212. bl cache_post_ddisable
  213. bl cache_post_dinvalidate
  214. /* Read the test area */
  215. lwz r0, 0(r1)
  216. mtctr r0
  217. lwz r4, 4(r1)
  218. subi r4, r4, 1
  219. li r3, 0
  220. 1:
  221. lbzu r0, 1(r4)
  222. cmpli cr0, r0, 0xff
  223. beq 2f
  224. li r3, -1
  225. b 3f
  226. 2:
  227. bdnz 1b
  228. 3:
  229. addi r1, r1, 8
  230. lwz r0, 4(r1)
  231. mtlr r0
  232. blr
  233. /*
  234. * turn on the data cache
  235. * switch the data cache to write-back mode
  236. * invalidate the data cache
  237. * write the negative pattern to a cached area
  238. * flush the data cache
  239. * write the zero pattern to the area
  240. * invalidate the data cache
  241. * read the area
  242. *
  243. * The negative pattern must be read at the last step
  244. */
  245. .global cache_post_test4
  246. cache_post_test4:
  247. mflr r0
  248. stw r0, 4(r1)
  249. stwu r3, -4(r1)
  250. stwu r4, -4(r1)
  251. bl cache_post_ddisable
  252. bl cache_post_dinvalidate
  253. /* Write the negative pattern to the test area */
  254. lwz r0, 0(r1)
  255. mtctr r0
  256. li r0, 0xff
  257. lwz r3, 4(r1)
  258. subi r3, r3, 1
  259. 1:
  260. stbu r0, 1(r3)
  261. bdnz 1b
  262. bl cache_post_dwb
  263. bl cache_post_dinvalidate
  264. /* Write the zero pattern to the test area */
  265. lwz r0, 0(r1)
  266. mtctr r0
  267. li r0, 0
  268. lwz r3, 4(r1)
  269. subi r3, r3, 1
  270. 1:
  271. stbu r0, 1(r3)
  272. bdnz 1b
  273. bl cache_post_ddisable
  274. bl cache_post_dinvalidate
  275. /* Read the test area */
  276. lwz r0, 0(r1)
  277. mtctr r0
  278. lwz r4, 4(r1)
  279. subi r4, r4, 1
  280. li r3, 0
  281. 1:
  282. lbzu r0, 1(r4)
  283. cmpli cr0, r0, 0xff
  284. beq 2f
  285. li r3, -1
  286. b 3f
  287. 2:
  288. bdnz 1b
  289. 3:
  290. addi r1, r1, 8
  291. lwz r0, 4(r1)
  292. mtlr r0
  293. blr
  294. cache_post_test5_1:
  295. li r3, 0
  296. cache_post_test5_2:
  297. li r3, -1
  298. /*
  299. * turn on the instruction cache
  300. * unlock the entire instruction cache
  301. * invalidate the instruction cache
  302. * lock a branch instruction in the instruction cache
  303. * replace the branch instruction with "nop"
  304. * jump to the branch instruction
  305. * check that the branch instruction was executed
  306. */
  307. .global cache_post_test5
  308. cache_post_test5:
  309. mflr r0
  310. stw r0, 4(r1)
  311. bl cache_post_ienable
  312. bl cache_post_iunlock
  313. bl cache_post_iinvalidate
  314. /* Compute r9 = cache_post_test5_reloc */
  315. bl cache_post_test5_reloc
  316. cache_post_test5_reloc:
  317. mflr r9
  318. /* Copy the test instruction to cache_post_test5_data */
  319. lis r3, (cache_post_test5_1 - cache_post_test5_reloc)@h
  320. ori r3, r3, (cache_post_test5_1 - cache_post_test5_reloc)@l
  321. add r3, r3, r9
  322. lis r4, (cache_post_test5_data - cache_post_test5_reloc)@h
  323. ori r4, r4, (cache_post_test5_data - cache_post_test5_reloc)@l
  324. add r4, r4, r9
  325. lwz r0, 0(r3)
  326. stw r0, 0(r4)
  327. bl cache_post_iinvalidate
  328. /* Lock the branch instruction */
  329. lis r3, (cache_post_test5_data - cache_post_test5_reloc)@h
  330. ori r3, r3, (cache_post_test5_data - cache_post_test5_reloc)@l
  331. add r3, r3, r9
  332. bl cache_post_ilock
  333. /* Replace the test instruction */
  334. lis r3, (cache_post_test5_2 - cache_post_test5_reloc)@h
  335. ori r3, r3, (cache_post_test5_2 - cache_post_test5_reloc)@l
  336. add r3, r3, r9
  337. lis r4, (cache_post_test5_data - cache_post_test5_reloc)@h
  338. ori r4, r4, (cache_post_test5_data - cache_post_test5_reloc)@l
  339. add r4, r4, r9
  340. lwz r0, 0(r3)
  341. stw r0, 0(r4)
  342. bl cache_post_iinvalidate
  343. /* Execute to the test instruction */
  344. cache_post_test5_data:
  345. nop
  346. bl cache_post_iunlock
  347. lwz r0, 4(r1)
  348. mtlr r0
  349. blr
  350. cache_post_test6_1:
  351. li r3, -1
  352. cache_post_test6_2:
  353. li r3, 0
  354. /*
  355. * turn on the instruction cache
  356. * unlock the entire instruction cache
  357. * invalidate the instruction cache
  358. * lock a branch instruction in the instruction cache
  359. * replace the branch instruction with "nop"
  360. * jump to the branch instruction
  361. * check that the branch instruction was executed
  362. */
  363. .global cache_post_test6
  364. cache_post_test6:
  365. mflr r0
  366. stw r0, 4(r1)
  367. bl cache_post_ienable
  368. bl cache_post_iunlock
  369. bl cache_post_iinvalidate
  370. /* Compute r9 = cache_post_test6_reloc */
  371. bl cache_post_test6_reloc
  372. cache_post_test6_reloc:
  373. mflr r9
  374. /* Copy the test instruction to cache_post_test6_data */
  375. lis r3, (cache_post_test6_1 - cache_post_test6_reloc)@h
  376. ori r3, r3, (cache_post_test6_1 - cache_post_test6_reloc)@l
  377. add r3, r3, r9
  378. lis r4, (cache_post_test6_data - cache_post_test6_reloc)@h
  379. ori r4, r4, (cache_post_test6_data - cache_post_test6_reloc)@l
  380. add r4, r4, r9
  381. lwz r0, 0(r3)
  382. stw r0, 0(r4)
  383. bl cache_post_iinvalidate
  384. /* Replace the test instruction */
  385. lis r3, (cache_post_test6_2 - cache_post_test6_reloc)@h
  386. ori r3, r3, (cache_post_test6_2 - cache_post_test6_reloc)@l
  387. add r3, r3, r9
  388. lis r4, (cache_post_test6_data - cache_post_test6_reloc)@h
  389. ori r4, r4, (cache_post_test6_data - cache_post_test6_reloc)@l
  390. add r4, r4, r9
  391. lwz r0, 0(r3)
  392. stw r0, 0(r4)
  393. bl cache_post_iinvalidate
  394. /* Execute to the test instruction */
  395. cache_post_test6_data:
  396. nop
  397. lwz r0, 4(r1)
  398. mtlr r0
  399. blr
  400. #endif /* CONFIG_MPC823 || MPC850 || MPC855 || MPC860 */
  401. #endif /* CONFIG_POST & CONFIG_SYS_POST_CACHE */