cr.c 5.0 KB

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