cr.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 =
  57. sizeof (cpu_post_cr_table1) / sizeof (ulong);
  58. static struct cpu_post_cr_s2 {
  59. ulong xer;
  60. ulong cr;
  61. } cpu_post_cr_table2[] =
  62. {
  63. {
  64. 0xa0000000,
  65. 1
  66. },
  67. {
  68. 0x40000000,
  69. 5
  70. },
  71. };
  72. static unsigned int cpu_post_cr_size2 =
  73. sizeof (cpu_post_cr_table2) / sizeof (struct cpu_post_cr_s2);
  74. static struct cpu_post_cr_s3 {
  75. ulong cr;
  76. ulong cs;
  77. ulong cd;
  78. ulong res;
  79. } cpu_post_cr_table3[] =
  80. {
  81. {
  82. 0x01234567,
  83. 0,
  84. 4,
  85. 0x01230567
  86. },
  87. {
  88. 0x01234567,
  89. 7,
  90. 0,
  91. 0x71234567
  92. },
  93. };
  94. static unsigned int cpu_post_cr_size3 =
  95. sizeof (cpu_post_cr_table3) / sizeof (struct cpu_post_cr_s3);
  96. static struct cpu_post_cr_s4 {
  97. ulong cmd;
  98. ulong cr;
  99. ulong op1;
  100. ulong op2;
  101. ulong op3;
  102. ulong res;
  103. } cpu_post_cr_table4[] =
  104. {
  105. {
  106. OP_CRAND,
  107. 0x0000ffff,
  108. 0,
  109. 16,
  110. 0,
  111. 0x0000ffff
  112. },
  113. {
  114. OP_CRAND,
  115. 0x0000ffff,
  116. 16,
  117. 17,
  118. 0,
  119. 0x8000ffff
  120. },
  121. {
  122. OP_CRANDC,
  123. 0x0000ffff,
  124. 0,
  125. 16,
  126. 0,
  127. 0x0000ffff
  128. },
  129. {
  130. OP_CRANDC,
  131. 0x0000ffff,
  132. 16,
  133. 0,
  134. 0,
  135. 0x8000ffff
  136. },
  137. {
  138. OP_CROR,
  139. 0x0000ffff,
  140. 0,
  141. 16,
  142. 0,
  143. 0x8000ffff
  144. },
  145. {
  146. OP_CROR,
  147. 0x0000ffff,
  148. 0,
  149. 1,
  150. 0,
  151. 0x0000ffff
  152. },
  153. {
  154. OP_CRORC,
  155. 0x0000ffff,
  156. 0,
  157. 16,
  158. 0,
  159. 0x0000ffff
  160. },
  161. {
  162. OP_CRORC,
  163. 0x0000ffff,
  164. 0,
  165. 0,
  166. 0,
  167. 0x8000ffff
  168. },
  169. {
  170. OP_CRXOR,
  171. 0x0000ffff,
  172. 0,
  173. 0,
  174. 0,
  175. 0x0000ffff
  176. },
  177. {
  178. OP_CRXOR,
  179. 0x0000ffff,
  180. 0,
  181. 16,
  182. 0,
  183. 0x8000ffff
  184. },
  185. {
  186. OP_CRNAND,
  187. 0x0000ffff,
  188. 0,
  189. 16,
  190. 0,
  191. 0x8000ffff
  192. },
  193. {
  194. OP_CRNAND,
  195. 0x0000ffff,
  196. 16,
  197. 17,
  198. 0,
  199. 0x0000ffff
  200. },
  201. {
  202. OP_CRNOR,
  203. 0x0000ffff,
  204. 0,
  205. 16,
  206. 0,
  207. 0x0000ffff
  208. },
  209. {
  210. OP_CRNOR,
  211. 0x0000ffff,
  212. 0,
  213. 1,
  214. 0,
  215. 0x8000ffff
  216. },
  217. {
  218. OP_CREQV,
  219. 0x0000ffff,
  220. 0,
  221. 0,
  222. 0,
  223. 0x8000ffff
  224. },
  225. {
  226. OP_CREQV,
  227. 0x0000ffff,
  228. 0,
  229. 16,
  230. 0,
  231. 0x0000ffff
  232. },
  233. };
  234. static unsigned int cpu_post_cr_size4 =
  235. sizeof (cpu_post_cr_table4) / sizeof (struct cpu_post_cr_s4);
  236. int cpu_post_test_cr (void)
  237. {
  238. int ret = 0;
  239. unsigned int i;
  240. unsigned long cr_sav;
  241. int flag = disable_interrupts();
  242. asm ( "mfcr %0" : "=r" (cr_sav) : );
  243. for (i = 0; i < cpu_post_cr_size1 && ret == 0; i++)
  244. {
  245. ulong cr = cpu_post_cr_table1[i];
  246. ulong res;
  247. unsigned long code[] =
  248. {
  249. ASM_MTCR(3),
  250. ASM_MFCR(3),
  251. ASM_BLR,
  252. };
  253. cpu_post_exec_11 (code, &res, cr);
  254. ret = res == cr ? 0 : -1;
  255. if (ret != 0)
  256. {
  257. post_log ("Error at cr1 test %d !\n", i);
  258. }
  259. }
  260. for (i = 0; i < cpu_post_cr_size2 && ret == 0; i++)
  261. {
  262. struct cpu_post_cr_s2 *test = cpu_post_cr_table2 + i;
  263. ulong res;
  264. ulong xer;
  265. unsigned long code[] =
  266. {
  267. ASM_MTXER(3),
  268. ASM_MCRXR(test->cr),
  269. ASM_MFCR(3),
  270. ASM_MFXER(4),
  271. ASM_BLR,
  272. };
  273. cpu_post_exec_21x (code, &res, &xer, test->xer);
  274. ret = xer == 0 && ((res << (4 * test->cr)) & 0xe0000000) == test->xer ?
  275. 0 : -1;
  276. if (ret != 0)
  277. {
  278. post_log ("Error at cr2 test %d !\n", i);
  279. }
  280. }
  281. for (i = 0; i < cpu_post_cr_size3 && ret == 0; i++)
  282. {
  283. struct cpu_post_cr_s3 *test = cpu_post_cr_table3 + i;
  284. ulong res;
  285. unsigned long code[] =
  286. {
  287. ASM_MTCR(3),
  288. ASM_MCRF(test->cd, test->cs),
  289. ASM_MFCR(3),
  290. ASM_BLR,
  291. };
  292. cpu_post_exec_11 (code, &res, test->cr);
  293. ret = res == test->res ? 0 : -1;
  294. if (ret != 0)
  295. {
  296. post_log ("Error at cr3 test %d !\n", i);
  297. }
  298. }
  299. for (i = 0; i < cpu_post_cr_size4 && ret == 0; i++)
  300. {
  301. struct cpu_post_cr_s4 *test = cpu_post_cr_table4 + i;
  302. ulong res;
  303. unsigned long code[] =
  304. {
  305. ASM_MTCR(3),
  306. ASM_12F(test->cmd, test->op3, test->op1, test->op2),
  307. ASM_MFCR(3),
  308. ASM_BLR,
  309. };
  310. cpu_post_exec_11 (code, &res, test->cr);
  311. ret = res == test->res ? 0 : -1;
  312. if (ret != 0)
  313. {
  314. post_log ("Error at cr4 test %d !\n", i);
  315. }
  316. }
  317. asm ( "mtcr %0" : : "r" (cr_sav));
  318. if (flag)
  319. enable_interrupts();
  320. return ret;
  321. }
  322. #endif