memory.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. CPU.prototype.mmap_read8 = function(addr)
  3. {
  4. return this.memory_map_read8[addr >>> MMAP_BLOCK_BITS](addr);
  5. };
  6. CPU.prototype.mmap_write8 = function(addr, value)
  7. {
  8. this.memory_map_write8[addr >>> MMAP_BLOCK_BITS](addr, value);
  9. };
  10. CPU.prototype.mmap_read16 = function(addr)
  11. {
  12. var fn = this.memory_map_read8[addr >>> MMAP_BLOCK_BITS];
  13. return fn(addr) | fn(addr + 1 | 0) << 8;
  14. };
  15. CPU.prototype.mmap_write16 = function(addr, value)
  16. {
  17. var fn = this.memory_map_write8[addr >>> MMAP_BLOCK_BITS];
  18. fn(addr, value & 0xFF);
  19. fn(addr + 1 | 0, value >> 8 & 0xFF);
  20. };
  21. CPU.prototype.mmap_read32 = function(addr)
  22. {
  23. var aligned_addr = addr >>> MMAP_BLOCK_BITS;
  24. return this.memory_map_read32[aligned_addr](addr);
  25. };
  26. CPU.prototype.mmap_write32 = function(addr, value)
  27. {
  28. var aligned_addr = addr >>> MMAP_BLOCK_BITS;
  29. this.memory_map_write32[aligned_addr](addr, value);
  30. };
  31. CPU.prototype.mmap_write128 = function(addr, value0, value1, value2, value3)
  32. {
  33. var aligned_addr = addr >>> MMAP_BLOCK_BITS;
  34. // This should hold since writes across pages are split up
  35. dbg_assert(aligned_addr === (addr + 12) >>> MMAP_BLOCK_BITS);
  36. var write_func32 = this.memory_map_write32[aligned_addr];
  37. write_func32(addr, value0);
  38. write_func32(addr + 4, value1);
  39. write_func32(addr + 8, value2);
  40. write_func32(addr + 12, value3);
  41. };
  42. /**
  43. * @param {Array.<number>|Uint8Array} blob
  44. * @param {number} offset
  45. */
  46. CPU.prototype.write_blob = function(blob, offset)
  47. {
  48. dbg_assert(blob && blob.length >= 0);
  49. dbg_assert(!this.in_mapped_range(offset));
  50. dbg_assert(!this.in_mapped_range(offset + blob.length));
  51. this.jit_dirty_cache(offset, offset + blob.length);
  52. this.mem8.set(blob, offset);
  53. };
  54. CPU.prototype.read_blob = function(offset, length)
  55. {
  56. dbg_assert(!this.in_mapped_range(offset));
  57. dbg_assert(!this.in_mapped_range(offset + length));
  58. return this.mem8.subarray(offset, offset + length);
  59. };