watch.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2008 David Daney
  7. */
  8. #include <linux/sched.h>
  9. #include <asm/processor.h>
  10. #include <asm/watch.h>
  11. /*
  12. * Install the watch registers for the current thread. A maximum of
  13. * four registers are installed although the machine may have more.
  14. */
  15. void mips_install_watch_registers(void)
  16. {
  17. struct mips3264_watch_reg_state *watches =
  18. &current->thread.watch.mips3264;
  19. switch (current_cpu_data.watch_reg_use_cnt) {
  20. default:
  21. BUG();
  22. case 4:
  23. write_c0_watchlo3(watches->watchlo[3]);
  24. /* Write 1 to the I, R, and W bits to clear them, and
  25. 1 to G so all ASIDs are trapped. */
  26. write_c0_watchhi3(0x40000007 | watches->watchhi[3]);
  27. case 3:
  28. write_c0_watchlo2(watches->watchlo[2]);
  29. write_c0_watchhi2(0x40000007 | watches->watchhi[2]);
  30. case 2:
  31. write_c0_watchlo1(watches->watchlo[1]);
  32. write_c0_watchhi1(0x40000007 | watches->watchhi[1]);
  33. case 1:
  34. write_c0_watchlo0(watches->watchlo[0]);
  35. write_c0_watchhi0(0x40000007 | watches->watchhi[0]);
  36. }
  37. }
  38. /*
  39. * Read back the watchhi registers so the user space debugger has
  40. * access to the I, R, and W bits. A maximum of four registers are
  41. * read although the machine may have more.
  42. */
  43. void mips_read_watch_registers(void)
  44. {
  45. struct mips3264_watch_reg_state *watches =
  46. &current->thread.watch.mips3264;
  47. switch (current_cpu_data.watch_reg_use_cnt) {
  48. default:
  49. BUG();
  50. case 4:
  51. watches->watchhi[3] = (read_c0_watchhi3() & 0x0fff);
  52. case 3:
  53. watches->watchhi[2] = (read_c0_watchhi2() & 0x0fff);
  54. case 2:
  55. watches->watchhi[1] = (read_c0_watchhi1() & 0x0fff);
  56. case 1:
  57. watches->watchhi[0] = (read_c0_watchhi0() & 0x0fff);
  58. }
  59. if (current_cpu_data.watch_reg_use_cnt == 1 &&
  60. (watches->watchhi[0] & 7) == 0) {
  61. /* Pathological case of release 1 architecture that
  62. * doesn't set the condition bits. We assume that
  63. * since we got here, the watch condition was met and
  64. * signal that the conditions requested in watchlo
  65. * were met. */
  66. watches->watchhi[0] |= (watches->watchlo[0] & 7);
  67. }
  68. }
  69. /*
  70. * Disable all watch registers. Although only four registers are
  71. * installed, all are cleared to eliminate the possibility of endless
  72. * looping in the watch handler.
  73. */
  74. void mips_clear_watch_registers(void)
  75. {
  76. switch (current_cpu_data.watch_reg_count) {
  77. default:
  78. BUG();
  79. case 8:
  80. write_c0_watchlo7(0);
  81. case 7:
  82. write_c0_watchlo6(0);
  83. case 6:
  84. write_c0_watchlo5(0);
  85. case 5:
  86. write_c0_watchlo4(0);
  87. case 4:
  88. write_c0_watchlo3(0);
  89. case 3:
  90. write_c0_watchlo2(0);
  91. case 2:
  92. write_c0_watchlo1(0);
  93. case 1:
  94. write_c0_watchlo0(0);
  95. }
  96. }
  97. void mips_probe_watch_registers(struct cpuinfo_mips *c)
  98. {
  99. unsigned int t;
  100. if ((c->options & MIPS_CPU_WATCH) == 0)
  101. return;
  102. /*
  103. * Check which of the I,R and W bits are supported, then
  104. * disable the register.
  105. */
  106. write_c0_watchlo0(7);
  107. back_to_back_c0_hazard();
  108. t = read_c0_watchlo0();
  109. write_c0_watchlo0(0);
  110. c->watch_reg_masks[0] = t & 7;
  111. /* Write the mask bits and read them back to determine which
  112. * can be used. */
  113. c->watch_reg_count = 1;
  114. c->watch_reg_use_cnt = 1;
  115. t = read_c0_watchhi0();
  116. write_c0_watchhi0(t | 0xff8);
  117. back_to_back_c0_hazard();
  118. t = read_c0_watchhi0();
  119. c->watch_reg_masks[0] |= (t & 0xff8);
  120. if ((t & 0x80000000) == 0)
  121. return;
  122. write_c0_watchlo1(7);
  123. back_to_back_c0_hazard();
  124. t = read_c0_watchlo1();
  125. write_c0_watchlo1(0);
  126. c->watch_reg_masks[1] = t & 7;
  127. c->watch_reg_count = 2;
  128. c->watch_reg_use_cnt = 2;
  129. t = read_c0_watchhi1();
  130. write_c0_watchhi1(t | 0xff8);
  131. back_to_back_c0_hazard();
  132. t = read_c0_watchhi1();
  133. c->watch_reg_masks[1] |= (t & 0xff8);
  134. if ((t & 0x80000000) == 0)
  135. return;
  136. write_c0_watchlo2(7);
  137. back_to_back_c0_hazard();
  138. t = read_c0_watchlo2();
  139. write_c0_watchlo2(0);
  140. c->watch_reg_masks[2] = t & 7;
  141. c->watch_reg_count = 3;
  142. c->watch_reg_use_cnt = 3;
  143. t = read_c0_watchhi2();
  144. write_c0_watchhi2(t | 0xff8);
  145. back_to_back_c0_hazard();
  146. t = read_c0_watchhi2();
  147. c->watch_reg_masks[2] |= (t & 0xff8);
  148. if ((t & 0x80000000) == 0)
  149. return;
  150. write_c0_watchlo3(7);
  151. back_to_back_c0_hazard();
  152. t = read_c0_watchlo3();
  153. write_c0_watchlo3(0);
  154. c->watch_reg_masks[3] = t & 7;
  155. c->watch_reg_count = 4;
  156. c->watch_reg_use_cnt = 4;
  157. t = read_c0_watchhi3();
  158. write_c0_watchhi3(t | 0xff8);
  159. back_to_back_c0_hazard();
  160. t = read_c0_watchhi3();
  161. c->watch_reg_masks[3] |= (t & 0xff8);
  162. if ((t & 0x80000000) == 0)
  163. return;
  164. /* We use at most 4, but probe and report up to 8. */
  165. c->watch_reg_count = 5;
  166. t = read_c0_watchhi4();
  167. if ((t & 0x80000000) == 0)
  168. return;
  169. c->watch_reg_count = 6;
  170. t = read_c0_watchhi5();
  171. if ((t & 0x80000000) == 0)
  172. return;
  173. c->watch_reg_count = 7;
  174. t = read_c0_watchhi6();
  175. if ((t & 0x80000000) == 0)
  176. return;
  177. c->watch_reg_count = 8;
  178. }