cache_8xx.S 9.0 KB

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