dscr_user_test.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * POWER Data Stream Control Register (DSCR) SPR test
  3. *
  4. * This test modifies the DSCR value through both the SPR number
  5. * based mtspr instruction and then makes sure that the same is
  6. * reflected through mfspr instruction using either of the SPR
  7. * numbers.
  8. *
  9. * When using the privilege state SPR, the instructions such as
  10. * mfspr or mtspr are priviledged and the kernel emulates them
  11. * for us. Instructions using problem state SPR can be exuecuted
  12. * directly without any emulation if the HW supports them. Else
  13. * they also get emulated by the kernel.
  14. *
  15. * Copyright 2013, Anton Blanchard, IBM Corporation.
  16. * Copyright 2015, Anshuman Khandual, IBM Corporation.
  17. *
  18. * This program is free software; you can redistribute it and/or modify it
  19. * under the terms of the GNU General Public License version 2 as published
  20. * by the Free Software Foundation.
  21. */
  22. #include "dscr.h"
  23. static int check_dscr(char *str)
  24. {
  25. unsigned long cur_dscr, cur_dscr_usr;
  26. cur_dscr = get_dscr();
  27. cur_dscr_usr = get_dscr_usr();
  28. if (cur_dscr != cur_dscr_usr) {
  29. printf("%s set, kernel get %lx != user get %lx\n",
  30. str, cur_dscr, cur_dscr_usr);
  31. return 1;
  32. }
  33. return 0;
  34. }
  35. int dscr_user(void)
  36. {
  37. int i;
  38. check_dscr("");
  39. for (i = 0; i < COUNT; i++) {
  40. set_dscr(i);
  41. if (check_dscr("kernel"))
  42. return 1;
  43. }
  44. for (i = 0; i < COUNT; i++) {
  45. set_dscr_usr(i);
  46. if (check_dscr("user"))
  47. return 1;
  48. }
  49. return 0;
  50. }
  51. int main(int argc, char *argv[])
  52. {
  53. return test_harness(dscr_user, "dscr_user_test");
  54. }