cache_8xx.S 9.1 KB

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