cgen-mem.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* Memory ops header for CGEN-based simulators.
  2. Copyright (C) 1996-2015 Free Software Foundation, Inc.
  3. Contributed by Cygnus Solutions.
  4. This file is part of the GNU 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. #ifndef CGEN_MEM_H
  16. #define CGEN_MEM_H
  17. /* TODO: This should get moved into sim-inline.h. */
  18. #ifdef MEMOPS_DEFINE_INLINE
  19. #define MEMOPS_INLINE
  20. #else
  21. #define MEMOPS_INLINE EXTERN_INLINE
  22. #endif
  23. /* Integer memory read support.
  24. There is no floating point support. In this context there are no
  25. floating point modes, only floating point operations (whose arguments
  26. and results are arrays of bits that we treat as integer modes). */
  27. #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
  28. #define DECLARE_GETMEM(mode, size) \
  29. MEMOPS_INLINE mode \
  30. XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \
  31. { \
  32. PROFILE_COUNT_READ (cpu, a, XCONCAT2 (MODE_,mode)); \
  33. /* Don't read anything into "unaligned" here. Bad name choice. */\
  34. return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, pc, read_map, a); \
  35. }
  36. #else
  37. #define DECLARE_GETMEM(mode, size) \
  38. extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR);
  39. #endif
  40. DECLARE_GETMEM (QI, 1) /* TAGS: GETMEMQI */
  41. DECLARE_GETMEM (UQI, 1) /* TAGS: GETMEMUQI */
  42. DECLARE_GETMEM (HI, 2) /* TAGS: GETMEMHI */
  43. DECLARE_GETMEM (UHI, 2) /* TAGS: GETMEMUHI */
  44. DECLARE_GETMEM (SI, 4) /* TAGS: GETMEMSI */
  45. DECLARE_GETMEM (USI, 4) /* TAGS: GETMEMUSI */
  46. DECLARE_GETMEM (DI, 8) /* TAGS: GETMEMDI */
  47. DECLARE_GETMEM (UDI, 8) /* TAGS: GETMEMUDI */
  48. #undef DECLARE_GETMEM
  49. /* Integer memory write support. */
  50. #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
  51. #define DECLARE_SETMEM(mode, size) \
  52. MEMOPS_INLINE void \
  53. XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \
  54. { \
  55. PROFILE_COUNT_WRITE (cpu, a, XCONCAT2 (MODE_,mode)); \
  56. /* Don't read anything into "unaligned" here. Bad name choice. */ \
  57. XCONCAT2 (sim_core_write_unaligned_,size) (cpu, pc, write_map, a, val); \
  58. }
  59. #else
  60. #define DECLARE_SETMEM(mode, size) \
  61. extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode);
  62. #endif
  63. DECLARE_SETMEM (QI, 1) /* TAGS: SETMEMQI */
  64. DECLARE_SETMEM (UQI, 1) /* TAGS: SETMEMUQI */
  65. DECLARE_SETMEM (HI, 2) /* TAGS: SETMEMHI */
  66. DECLARE_SETMEM (UHI, 2) /* TAGS: SETMEMUHI */
  67. DECLARE_SETMEM (SI, 4) /* TAGS: SETMEMSI */
  68. DECLARE_SETMEM (USI, 4) /* TAGS: SETMEMUSI */
  69. DECLARE_SETMEM (DI, 8) /* TAGS: SETMEMDI */
  70. DECLARE_SETMEM (UDI, 8) /* TAGS: SETMEMUDI */
  71. #undef DECLARE_SETMEM
  72. /* Instruction read support. */
  73. #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
  74. #define DECLARE_GETIMEM(mode, size) \
  75. MEMOPS_INLINE mode \
  76. XCONCAT2 (GETIMEM,mode) (SIM_CPU *cpu, IADDR a) \
  77. { \
  78. /*PROFILE_COUNT_READ (cpu, a, XCONCAT2 (MODE_,mode));*/ \
  79. /* Don't read anything into "unaligned" here. Bad name choice. */\
  80. return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, a, exec_map, a); \
  81. }
  82. #else
  83. #define DECLARE_GETIMEM(mode, size) \
  84. extern mode XCONCAT2 (GETIMEM,mode) (SIM_CPU *, ADDR);
  85. #endif
  86. DECLARE_GETIMEM (UQI, 1) /* TAGS: GETIMEMUQI */
  87. DECLARE_GETIMEM (UHI, 2) /* TAGS: GETIMEMUHI */
  88. DECLARE_GETIMEM (USI, 4) /* TAGS: GETIMEMUSI */
  89. DECLARE_GETIMEM (UDI, 8) /* TAGS: GETIMEMUDI */
  90. #undef DECLARE_GETIMEM
  91. /* Floating point support.
  92. ??? One can specify that the integer memory ops should be used instead,
  93. and treat fp values as just a series of bits. One might even bubble
  94. that notion up into the description language. However, that departs from
  95. gcc. One could cross over from gcc's notion and a "series of bits" notion
  96. between there and here, and thus still not require these routines. However,
  97. that's a complication of its own (not that having these fns isn't).
  98. But for now, we do things this way. */
  99. #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
  100. #define DECLARE_GETMEM(mode, size) \
  101. MEMOPS_INLINE mode \
  102. XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \
  103. { \
  104. PROFILE_COUNT_READ (cpu, a, XCONCAT2 (MODE_,mode)); \
  105. /* Don't read anything into "unaligned" here. Bad name choice. */\
  106. return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, pc, read_map, a); \
  107. }
  108. #else
  109. #define DECLARE_GETMEM(mode, size) \
  110. extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR);
  111. #endif
  112. DECLARE_GETMEM (SF, 4) /* TAGS: GETMEMSF */
  113. DECLARE_GETMEM (DF, 8) /* TAGS: GETMEMDF */
  114. #undef DECLARE_GETMEM
  115. #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE)
  116. #define DECLARE_SETMEM(mode, size) \
  117. MEMOPS_INLINE void \
  118. XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \
  119. { \
  120. PROFILE_COUNT_WRITE (cpu, a, XCONCAT2 (MODE_,mode)); \
  121. /* Don't read anything into "unaligned" here. Bad name choice. */ \
  122. XCONCAT2 (sim_core_write_unaligned_,size) (cpu, pc, write_map, a, val); \
  123. }
  124. #else
  125. #define DECLARE_SETMEM(mode, size) \
  126. extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode);
  127. #endif
  128. DECLARE_SETMEM (SF, 4) /* TAGS: SETMEMSF */
  129. DECLARE_SETMEM (DF, 8) /* TAGS: SETMEMDF */
  130. #undef DECLARE_SETMEM
  131. /* GETT<mode>: translate target value at P to host value.
  132. This needn't be very efficient (i.e. can call memcpy) as this is
  133. only used when interfacing with the outside world (e.g. gdb). */
  134. #if defined (MEMOPS_DEFINE_INLINE)
  135. #define DECLARE_GETT(mode, size) \
  136. mode \
  137. XCONCAT2 (GETT,mode) (unsigned char *p) \
  138. { \
  139. mode tmp; \
  140. memcpy (&tmp, p, sizeof (mode)); \
  141. return XCONCAT2 (T2H_,size) (tmp); \
  142. }
  143. #else
  144. #define DECLARE_GETT(mode, size) \
  145. extern mode XCONCAT2 (GETT,mode) (unsigned char *);
  146. #endif
  147. DECLARE_GETT (QI, 1) /* TAGS: GETTQI */
  148. DECLARE_GETT (UQI, 1) /* TAGS: GETTUQI */
  149. DECLARE_GETT (HI, 2) /* TAGS: GETTHI */
  150. DECLARE_GETT (UHI, 2) /* TAGS: GETTUHI */
  151. DECLARE_GETT (SI, 4) /* TAGS: GETTSI */
  152. DECLARE_GETT (USI, 4) /* TAGS: GETTUSI */
  153. DECLARE_GETT (DI, 8) /* TAGS: GETTDI */
  154. DECLARE_GETT (UDI, 8) /* TAGS: GETTUDI */
  155. #if 0 /* ??? defered until necessary */
  156. DECLARE_GETT (SF, 4) /* TAGS: GETTSF */
  157. DECLARE_GETT (DF, 8) /* TAGS: GETTDF */
  158. DECLARE_GETT (TF, 16) /* TAGS: GETTTF */
  159. #endif
  160. #undef DECLARE_GETT
  161. /* SETT<mode>: translate host value to target value and store at P.
  162. This needn't be very efficient (i.e. can call memcpy) as this is
  163. only used when interfacing with the outside world (e.g. gdb). */
  164. #if defined (MEMOPS_DEFINE_INLINE)
  165. #define DECLARE_SETT(mode, size) \
  166. void \
  167. XCONCAT2 (SETT,mode) (unsigned char *buf, mode val) \
  168. { \
  169. mode tmp; \
  170. tmp = XCONCAT2 (H2T_,size) (val); \
  171. memcpy (buf, &tmp, sizeof (mode)); \
  172. }
  173. #else
  174. #define DECLARE_SETT(mode, size) \
  175. extern mode XCONCAT2 (SETT,mode) (unsigned char *, mode);
  176. #endif
  177. DECLARE_SETT (QI, 1) /* TAGS: SETTQI */
  178. DECLARE_SETT (UQI, 1) /* TAGS: SETTUQI */
  179. DECLARE_SETT (HI, 2) /* TAGS: SETTHI */
  180. DECLARE_SETT (UHI, 2) /* TAGS: SETTUHI */
  181. DECLARE_SETT (SI, 4) /* TAGS: SETTSI */
  182. DECLARE_SETT (USI, 4) /* TAGS: SETTUSI */
  183. DECLARE_SETT (DI, 8) /* TAGS: SETTDI */
  184. DECLARE_SETT (UDI, 8) /* TAGS: SETTUDI */
  185. #if 0 /* ??? defered until necessary */
  186. DECLARE_SETT (SF, 4) /* TAGS: SETTSF */
  187. DECLARE_SETT (DF, 8) /* TAGS: SETTDF */
  188. DECLARE_SETT (TF, 16) /* TAGS: SETTTF */
  189. #endif
  190. #undef DECLARE_SETT
  191. #endif /* CGEN_MEM_H */