dv-bfin_wp.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* Blackfin Watchpoint (WP) model.
  2. Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. Contributed by Analog Devices, Inc.
  4. This file is part of simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /* This must come before any other includes. */
  16. #include "defs.h"
  17. #include "sim-main.h"
  18. #include "devices.h"
  19. #include "dv-bfin_wp.h"
  20. /* XXX: This is mostly a stub. */
  21. #define WPI_NUM 6 /* 6 instruction watchpoints. */
  22. #define WPD_NUM 2 /* 2 data watchpoints. */
  23. struct bfin_wp
  24. {
  25. bu32 base;
  26. /* Order after here is important -- matches hardware MMR layout. */
  27. bu32 iactl;
  28. bu32 _pad0[15];
  29. bu32 ia[WPI_NUM];
  30. bu32 _pad1[16 - WPI_NUM];
  31. bu32 iacnt[WPI_NUM];
  32. bu32 _pad2[32 - WPI_NUM];
  33. bu32 dactl;
  34. bu32 _pad3[15];
  35. bu32 da[WPD_NUM];
  36. bu32 _pad4[16 - WPD_NUM];
  37. bu32 dacnt[WPD_NUM];
  38. bu32 _pad5[32 - WPD_NUM];
  39. bu32 stat;
  40. };
  41. #define mmr_base() offsetof(struct bfin_wp, iactl)
  42. #define mmr_offset(mmr) (offsetof(struct bfin_wp, mmr) - mmr_base())
  43. #define mmr_idx(mmr) (mmr_offset (mmr) / 4)
  44. static const char * const mmr_names[] =
  45. {
  46. [mmr_idx (iactl)] = "WPIACTL",
  47. [mmr_idx (ia)] = "WPIA0", "WPIA1", "WPIA2", "WPIA3", "WPIA4", "WPIA5",
  48. [mmr_idx (iacnt)] = "WPIACNT0", "WPIACNT1", "WPIACNT2",
  49. "WPIACNT3", "WPIACNT4", "WPIACNT5",
  50. [mmr_idx (dactl)] = "WPDACTL",
  51. [mmr_idx (da)] = "WPDA0", "WPDA1", "WPDA2", "WPDA3", "WPDA4", "WPDA5",
  52. [mmr_idx (dacnt)] = "WPDACNT0", "WPDACNT1", "WPDACNT2",
  53. "WPDACNT3", "WPDACNT4", "WPDACNT5",
  54. [mmr_idx (stat)] = "WPSTAT",
  55. };
  56. #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
  57. static unsigned
  58. bfin_wp_io_write_buffer (struct hw *me, const void *source, int space,
  59. address_word addr, unsigned nr_bytes)
  60. {
  61. struct bfin_wp *wp = hw_data (me);
  62. bu32 mmr_off;
  63. bu32 value;
  64. bu32 *valuep;
  65. /* Invalid access mode is higher priority than missing register. */
  66. if (!dv_bfin_mmr_require_32 (me, addr, nr_bytes, true))
  67. return 0;
  68. value = dv_load_4 (source);
  69. mmr_off = addr - wp->base;
  70. valuep = (void *)((uintptr_t)wp + mmr_base() + mmr_off);
  71. HW_TRACE_WRITE ();
  72. switch (mmr_off)
  73. {
  74. case mmr_offset(iactl):
  75. case mmr_offset(ia[0]) ... mmr_offset(ia[WPI_NUM - 1]):
  76. case mmr_offset(iacnt[0]) ... mmr_offset(iacnt[WPI_NUM - 1]):
  77. case mmr_offset(dactl):
  78. case mmr_offset(da[0]) ... mmr_offset(da[WPD_NUM - 1]):
  79. case mmr_offset(dacnt[0]) ... mmr_offset(dacnt[WPD_NUM - 1]):
  80. *valuep = value;
  81. break;
  82. case mmr_offset(stat):
  83. /* Yes, the hardware is this dumb -- clear all bits on any write. */
  84. *valuep = 0;
  85. break;
  86. default:
  87. dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
  88. return 0;
  89. }
  90. return nr_bytes;
  91. }
  92. static unsigned
  93. bfin_wp_io_read_buffer (struct hw *me, void *dest, int space,
  94. address_word addr, unsigned nr_bytes)
  95. {
  96. struct bfin_wp *wp = hw_data (me);
  97. bu32 mmr_off;
  98. bu32 value;
  99. bu32 *valuep;
  100. /* Invalid access mode is higher priority than missing register. */
  101. if (!dv_bfin_mmr_require_32 (me, addr, nr_bytes, false))
  102. return 0;
  103. mmr_off = addr - wp->base;
  104. valuep = (void *)((uintptr_t)wp + mmr_base() + mmr_off);
  105. HW_TRACE_READ ();
  106. switch (mmr_off)
  107. {
  108. case mmr_offset(iactl):
  109. case mmr_offset(ia[0]) ... mmr_offset(ia[WPI_NUM - 1]):
  110. case mmr_offset(iacnt[0]) ... mmr_offset(iacnt[WPI_NUM - 1]):
  111. case mmr_offset(dactl):
  112. case mmr_offset(da[0]) ... mmr_offset(da[WPD_NUM - 1]):
  113. case mmr_offset(dacnt[0]) ... mmr_offset(dacnt[WPD_NUM - 1]):
  114. case mmr_offset(stat):
  115. value = *valuep;
  116. break;
  117. default:
  118. dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
  119. return 0;
  120. }
  121. dv_store_4 (dest, value);
  122. return nr_bytes;
  123. }
  124. static void
  125. attach_bfin_wp_regs (struct hw *me, struct bfin_wp *wp)
  126. {
  127. address_word attach_address;
  128. int attach_space;
  129. unsigned attach_size;
  130. reg_property_spec reg;
  131. if (hw_find_property (me, "reg") == NULL)
  132. hw_abort (me, "Missing \"reg\" property");
  133. if (!hw_find_reg_array_property (me, "reg", 0, &reg))
  134. hw_abort (me, "\"reg\" property must contain three addr/size entries");
  135. hw_unit_address_to_attach_address (hw_parent (me),
  136. &reg.address,
  137. &attach_space, &attach_address, me);
  138. hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
  139. if (attach_size != BFIN_COREMMR_WP_SIZE)
  140. hw_abort (me, "\"reg\" size must be %#x", BFIN_COREMMR_WP_SIZE);
  141. hw_attach_address (hw_parent (me),
  142. 0, attach_space, attach_address, attach_size, me);
  143. wp->base = attach_address;
  144. }
  145. static void
  146. bfin_wp_finish (struct hw *me)
  147. {
  148. struct bfin_wp *wp;
  149. wp = HW_ZALLOC (me, struct bfin_wp);
  150. set_hw_data (me, wp);
  151. set_hw_io_read_buffer (me, bfin_wp_io_read_buffer);
  152. set_hw_io_write_buffer (me, bfin_wp_io_write_buffer);
  153. attach_bfin_wp_regs (me, wp);
  154. }
  155. const struct hw_descriptor dv_bfin_wp_descriptor[] =
  156. {
  157. {"bfin_wp", bfin_wp_finish,},
  158. {NULL, NULL},
  159. };