vm_n.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1997, 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 */
  18. #define unsigned_N XCONCAT2(unsigned_,N)
  19. #define T2H_N XCONCAT2(T2H_,N)
  20. #define H2T_N XCONCAT2(H2T_,N)
  21. #define vm_data_map_read_N XCONCAT2(vm_data_map_read_,N)
  22. #define vm_data_map_write_N XCONCAT2(vm_data_map_write_,N)
  23. INLINE_VM\
  24. (unsigned_N)
  25. vm_data_map_read_N(vm_data_map *map,
  26. unsigned_word ea,
  27. cpu *processor,
  28. unsigned_word cia)
  29. {
  30. if ((ea & (sizeof(unsigned_N)-1)) == 0) {
  31. unsigned ra = vm_real_data_addr(map, ea, 1/*is-read*/, processor, cia);
  32. unsigned_N val;
  33. if (WITH_XOR_ENDIAN)
  34. ra ^= map->translation.xor[sizeof(unsigned_N) - 1];
  35. val = XCONCAT2(core_map_read_,N)(map->read, ra, processor, cia);
  36. if (WITH_MON & MONITOR_LOAD_STORE_UNIT)
  37. mon_read(ea, ra, sizeof(unsigned_N), processor, cia);
  38. TRACE(trace_load_store, ("load cia=0x%lx ea=0x%lx N=%ld val=0x%lx\n",
  39. (long)cia, (long)ea, (long)sizeof(unsigned_N), (long)val));
  40. return val;
  41. }
  42. else {
  43. switch (CURRENT_ALIGNMENT) {
  44. case STRICT_ALIGNMENT:
  45. alignment_interrupt(processor, cia, ea);
  46. return 0;
  47. case NONSTRICT_ALIGNMENT:
  48. {
  49. unsigned_N val;
  50. if (vm_data_map_read_buffer(map, &val, ea, sizeof(unsigned_N), processor, cia)
  51. != sizeof(unsigned_N)) {
  52. cpu_error(processor, cia, "misaligned %zu byte read to 0x%lx failed",
  53. sizeof(unsigned_N), (unsigned long)ea);
  54. }
  55. val = T2H_N(val);
  56. if (WITH_MON & MONITOR_LOAD_STORE_UNIT) {
  57. /* YUCK */
  58. unsigned ra = vm_real_data_addr(map, ea, 1, processor, cia);
  59. mon_read(ea, ra, sizeof(unsigned_N), processor, cia);
  60. }
  61. TRACE(trace_load_store, ("load cia=0x%lx ea=0x%lx N=%ld data=0x%lx\n",
  62. (long)cia, (long)ea, (long)sizeof(unsigned_N), (long)val));
  63. return val;
  64. }
  65. default:
  66. error("internal error - vm_data_map_read_N - bad switch");
  67. return 0;
  68. }
  69. }
  70. }
  71. INLINE_VM\
  72. (void)
  73. vm_data_map_write_N(vm_data_map *map,
  74. unsigned_word ea,
  75. unsigned_N val,
  76. cpu *processor,
  77. unsigned_word cia)
  78. {
  79. if ((ea & (sizeof(unsigned_N)-1)) == 0) {
  80. unsigned ra = vm_real_data_addr(map, ea, 0/*is-read?*/, processor, cia);
  81. if (WITH_XOR_ENDIAN)
  82. ra ^= map->translation.xor[sizeof(unsigned_N) - 1];
  83. XCONCAT2(core_map_write_,N)(map->write, ra, val, processor, cia);
  84. if (WITH_MON & MONITOR_LOAD_STORE_UNIT)
  85. mon_write(ea, ra, sizeof(unsigned_N), processor, cia);
  86. TRACE(trace_load_store, ("store cia=0x%lx ea=0x%lx N=%ld val=0x%lx\n",
  87. (long)cia, (long)ea, (long)sizeof(unsigned_N), (long)val));
  88. }
  89. else {
  90. switch (CURRENT_ALIGNMENT) {
  91. case STRICT_ALIGNMENT:
  92. alignment_interrupt(processor, cia, ea);
  93. break;
  94. case NONSTRICT_ALIGNMENT:
  95. {
  96. unsigned_N data = H2T_N(val);
  97. if (vm_data_map_write_buffer(map, &data, ea, sizeof(unsigned_N), 0, processor, cia)
  98. != sizeof(unsigned_N)) {
  99. cpu_error(processor, cia, "misaligned %zu byte write to 0x%lx failed",
  100. sizeof(unsigned_N), (unsigned long)ea);
  101. }
  102. if (WITH_MON & MONITOR_LOAD_STORE_UNIT) {
  103. /* YUCK */
  104. unsigned ra = vm_real_data_addr(map, ea, 1, processor, cia);
  105. mon_write(ea, ra, sizeof(unsigned_N), processor, cia);
  106. }
  107. TRACE(trace_load_store, ("store cia=0x%lx ea=0x%lx N=%ld val=0x%lx\n",
  108. (long)cia, (long)ea, (long)sizeof(unsigned_N), (long)val));
  109. }
  110. break;
  111. default:
  112. error("internal error - vm_data_map_write_N - bad switch");
  113. }
  114. }
  115. }
  116. /* NOTE: see start of file for #define */
  117. #undef unsigned_N
  118. #undef T2H_N
  119. #undef H2T_N
  120. #undef vm_data_map_read_N
  121. #undef vm_data_map_write_N