corefile-n.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef N
  15. #error "N must be #defined"
  16. #endif
  17. /* NOTE: see end of file for #undef of these macros */
  18. #define unsigned_N XCONCAT2(unsigned_,N)
  19. #define T2H_N XCONCAT2(T2H_,N)
  20. #define H2T_N XCONCAT2(H2T_,N)
  21. #define core_map_read_N XCONCAT2(core_map_read_,N)
  22. #define core_map_write_N XCONCAT2(core_map_write_,N)
  23. INLINE_CORE(unsigned_N)
  24. core_map_read_N(core_map *map,
  25. unsigned_word addr,
  26. cpu *processor,
  27. unsigned_word cia)
  28. {
  29. core_mapping *mapping = core_map_find_mapping(map,
  30. addr,
  31. sizeof(unsigned_N),
  32. processor,
  33. cia,
  34. 1); /*abort*/
  35. if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
  36. unsigned_N data;
  37. if (device_io_read_buffer(mapping->device,
  38. &data,
  39. mapping->space,
  40. addr,
  41. sizeof(unsigned_N), /* nr_bytes */
  42. processor,
  43. cia) != sizeof(unsigned_N))
  44. device_error(mapping->device, "internal error - core_read_N() - io_read_buffer should not fail");
  45. return T2H_N(data);
  46. }
  47. else
  48. return T2H_N(*(unsigned_N*)core_translate(mapping, addr));
  49. }
  50. INLINE_CORE(void)
  51. core_map_write_N(core_map *map,
  52. unsigned_word addr,
  53. unsigned_N val,
  54. cpu *processor,
  55. unsigned_word cia)
  56. {
  57. core_mapping *mapping = core_map_find_mapping(map,
  58. addr,
  59. sizeof(unsigned_N),
  60. processor,
  61. cia,
  62. 1); /*abort*/
  63. if (WITH_CALLBACK_MEMORY && mapping->device != NULL) {
  64. unsigned_N data = H2T_N(val);
  65. if (device_io_write_buffer(mapping->device,
  66. &data,
  67. mapping->space,
  68. addr,
  69. sizeof(unsigned_N), /* nr_bytes */
  70. processor,
  71. cia) != sizeof(unsigned_N))
  72. device_error(mapping->device, "internal error - core_write_N() - io_write_buffer should not fail");
  73. }
  74. else
  75. *(unsigned_N*)core_translate(mapping, addr) = H2T_N(val);
  76. }
  77. /* NOTE: see start of file for #define of these macros */
  78. #undef unsigned_N
  79. #undef T2H_N
  80. #undef H2T_N
  81. #undef core_map_read_N
  82. #undef core_map_write_N