cache_8xx.S 9.1 KB

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