cr.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. /*
  25. * CPU test
  26. * Condition register istructions: mtcr, mfcr, mcrxr,
  27. * crand, crandc, cror, crorc, crxor,
  28. * crnand, crnor, creqv, mcrf
  29. *
  30. * The mtcrf/mfcr instructions is tested by loading different
  31. * values into the condition register (mtcrf), moving its value
  32. * to a general-purpose register (mfcr) and comparing this value
  33. * with the expected one.
  34. * The mcrxr instruction is tested by loading a fixed value
  35. * into the XER register (mtspr), moving XER value to the
  36. * condition register (mcrxr), moving it to a general-purpose
  37. * register (mfcr) and comparing the value of this register with
  38. * the expected one.
  39. * The rest of instructions is tested by loading a fixed
  40. * value into the condition register (mtcrf), executing each
  41. * instruction several times to modify all 4-bit condition
  42. * fields, moving the value of the conditional register to a
  43. * general-purpose register (mfcr) and comparing it with the
  44. * expected one.
  45. */
  46. #include <post.h>
  47. #include "cpu_asm.h"
  48. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  49. extern void cpu_post_exec_11 (ulong *code, ulong *res, ulong op1);
  50. extern void cpu_post_exec_21x (ulong *code, ulong *op1, ulong *op2, ulong op3);
  51. static ulong cpu_post_cr_table1[] =
  52. {
  53. 0xaaaaaaaa,
  54. 0x55555555,
  55. };
  56. static unsigned int cpu_post_cr_size1 = ARRAY_SIZE(cpu_post_cr_table1);
  57. static struct cpu_post_cr_s2 {
  58. ulong xer;
  59. ulong cr;
  60. } cpu_post_cr_table2[] =
  61. {
  62. {
  63. 0xa0000000,
  64. 1
  65. },
  66. {
  67. 0x40000000,
  68. 5
  69. },
  70. };
  71. static unsigned int cpu_post_cr_size2 = ARRAY_SIZE(cpu_post_cr_table2);
  72. static struct cpu_post_cr_s3 {
  73. ulong cr;
  74. ulong cs;
  75. ulong cd;
  76. ulong res;
  77. } cpu_post_cr_table3[] =
  78. {
  79. {
  80. 0x01234567,
  81. 0,
  82. 4,
  83. 0x01230567
  84. },
  85. {
  86. 0x01234567,
  87. 7,
  88. 0,
  89. 0x71234567
  90. },
  91. };
  92. static unsigned int cpu_post_cr_size3 = ARRAY_SIZE(cpu_post_cr_table3);
  93. static struct cpu_post_cr_s4 {
  94. ulong cmd;
  95. ulong cr;
  96. ulong op1;
  97. ulong op2;
  98. ulong op3;
  99. ulong res;
  100. } cpu_post_cr_table4[] =
  101. {
  102. {
  103. OP_CRAND,
  104. 0x0000ffff,
  105. 0,
  106. 16,
  107. 0,
  108. 0x0000ffff
  109. },
  110. {
  111. OP_CRAND,
  112. 0x0000ffff,
  113. 16,
  114. 17,
  115. 0,
  116. 0x8000ffff
  117. },
  118. {
  119. OP_CRANDC,
  120. 0x0000ffff,
  121. 0,
  122. 16,
  123. 0,
  124. 0x0000ffff
  125. },
  126. {
  127. OP_CRANDC,
  128. 0x0000ffff,
  129. 16,
  130. 0,
  131. 0,
  132. 0x8000ffff
  133. },
  134. {
  135. OP_CROR,
  136. 0x0000ffff,
  137. 0,
  138. 16,
  139. 0,
  140. 0x8000ffff
  141. },
  142. {
  143. OP_CROR,
  144. 0x0000ffff,
  145. 0,
  146. 1,
  147. 0,
  148. 0x0000ffff
  149. },
  150. {
  151. OP_CRORC,
  152. 0x0000ffff,
  153. 0,
  154. 16,
  155. 0,
  156. 0x0000ffff
  157. },
  158. {
  159. OP_CRORC,
  160. 0x0000ffff,
  161. 0,
  162. 0,
  163. 0,
  164. 0x8000ffff
  165. },
  166. {
  167. OP_CRXOR,
  168. 0x0000ffff,
  169. 0,
  170. 0,
  171. 0,
  172. 0x0000ffff
  173. },
  174. {
  175. OP_CRXOR,
  176. 0x0000ffff,
  177. 0,
  178. 16,
  179. 0,
  180. 0x8000ffff
  181. },
  182. {
  183. OP_CRNAND,
  184. 0x0000ffff,
  185. 0,
  186. 16,
  187. 0,
  188. 0x8000ffff
  189. },
  190. {
  191. OP_CRNAND,
  192. 0x0000ffff,
  193. 16,
  194. 17,
  195. 0,
  196. 0x0000ffff
  197. },
  198. {
  199. OP_CRNOR,
  200. 0x0000ffff,
  201. 0,
  202. 16,
  203. 0,
  204. 0x0000ffff
  205. },
  206. {
  207. OP_CRNOR,
  208. 0x0000ffff,
  209. 0,
  210. 1,
  211. 0,
  212. 0x8000ffff
  213. },
  214. {
  215. OP_CREQV,
  216. 0x0000ffff,
  217. 0,
  218. 0,
  219. 0,
  220. 0x8000ffff
  221. },
  222. {
  223. OP_CREQV,
  224. 0x0000ffff,
  225. 0,
  226. 16,
  227. 0,
  228. 0x0000ffff
  229. },
  230. };
  231. static unsigned int cpu_post_cr_size4 = ARRAY_SIZE(cpu_post_cr_table4);
  232. int cpu_post_test_cr (void)
  233. {
  234. int ret = 0;
  235. unsigned int i;
  236. unsigned long cr_sav;
  237. int flag = disable_interrupts();
  238. asm ( "mfcr %0" : "=r" (cr_sav) : );
  239. for (i = 0; i < cpu_post_cr_size1 && ret == 0; i++)
  240. {
  241. ulong cr = cpu_post_cr_table1[i];
  242. ulong res;
  243. unsigned long code[] =
  244. {
  245. ASM_MTCR(3),
  246. ASM_MFCR(3),
  247. ASM_BLR,
  248. };
  249. cpu_post_exec_11 (code, &res, cr);
  250. ret = res == cr ? 0 : -1;
  251. if (ret != 0)
  252. {
  253. post_log ("Error at cr1 test %d !\n", i);
  254. }
  255. }
  256. for (i = 0; i < cpu_post_cr_size2 && ret == 0; i++)
  257. {
  258. struct cpu_post_cr_s2 *test = cpu_post_cr_table2 + i;
  259. ulong res;
  260. ulong xer;
  261. unsigned long code[] =
  262. {
  263. ASM_MTXER(3),
  264. ASM_MCRXR(test->cr),
  265. ASM_MFCR(3),
  266. ASM_MFXER(4),
  267. ASM_BLR,
  268. };
  269. cpu_post_exec_21x (code, &res, &xer, test->xer);
  270. ret = xer == 0 && ((res << (4 * test->cr)) & 0xe0000000) == test->xer ?
  271. 0 : -1;
  272. if (ret != 0)
  273. {
  274. post_log ("Error at cr2 test %d !\n", i);
  275. }
  276. }
  277. for (i = 0; i < cpu_post_cr_size3 && ret == 0; i++)
  278. {
  279. struct cpu_post_cr_s3 *test = cpu_post_cr_table3 + i;
  280. ulong res;
  281. unsigned long code[] =
  282. {
  283. ASM_MTCR(3),
  284. ASM_MCRF(test->cd, test->cs),
  285. ASM_MFCR(3),
  286. ASM_BLR,
  287. };
  288. cpu_post_exec_11 (code, &res, test->cr);
  289. ret = res == test->res ? 0 : -1;
  290. if (ret != 0)
  291. {
  292. post_log ("Error at cr3 test %d !\n", i);
  293. }
  294. }
  295. for (i = 0; i < cpu_post_cr_size4 && ret == 0; i++)
  296. {
  297. struct cpu_post_cr_s4 *test = cpu_post_cr_table4 + i;
  298. ulong res;
  299. unsigned long code[] =
  300. {
  301. ASM_MTCR(3),
  302. ASM_12F(test->cmd, test->op3, test->op1, test->op2),
  303. ASM_MFCR(3),
  304. ASM_BLR,
  305. };
  306. cpu_post_exec_11 (code, &res, test->cr);
  307. ret = res == test->res ? 0 : -1;
  308. if (ret != 0)
  309. {
  310. post_log ("Error at cr4 test %d !\n", i);
  311. }
  312. }
  313. asm ( "mtcr %0" : : "r" (cr_sav));
  314. if (flag)
  315. enable_interrupts();
  316. return ret;
  317. }
  318. #endif