jor1k.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use strict";
  2. // jor1k compatibility
  3. var VIRTIO_MAGIC_REG = 0x0;
  4. var VIRTIO_VERSION_REG = 0x4;
  5. var VIRTIO_DEVICE_REG = 0x8;
  6. var VIRTIO_VENDOR_REG = 0xc;
  7. var VIRTIO_HOSTFEATURES_REG = 0x10;
  8. var VIRTIO_HOSTFEATURESSEL_REG = 0x14;
  9. var VIRTIO_GUESTFEATURES_REG = 0x20;
  10. var VIRTIO_GUESTFEATURESSEL_REG = 0x24;
  11. var VIRTIO_GUEST_PAGE_SIZE_REG = 0x28;
  12. var VIRTIO_QUEUESEL_REG = 0x30;
  13. var VIRTIO_QUEUENUMMAX_REG = 0x34;
  14. var VIRTIO_QUEUENUM_REG = 0x38;
  15. var VIRTIO_QUEUEALIGN_REG = 0x3C;
  16. var VIRTIO_QUEUEPFN_REG = 0x40;
  17. var VIRTIO_QUEUENOTIFY_REG = 0x50;
  18. var VIRTIO_INTERRUPTSTATUS_REG = 0x60;
  19. var VIRTIO_INTERRUPTACK_REG = 0x64;
  20. var VIRTIO_STATUS_REG = 0x70;
  21. /** @const */
  22. var VRING_DESC_F_NEXT = 1; /* This marks a buffer as continuing via the next field. */
  23. /** @const */
  24. var VRING_DESC_F_WRITE = 2; /* This marks a buffer as write-only (otherwise read-only). */
  25. /** @const */
  26. var VRING_DESC_F_INDIRECT = 4; /* This means the buffer contains a list of buffer descriptors. */
  27. function hex8(n)
  28. {
  29. return h(n);
  30. }
  31. var message = {};
  32. /** @param {...string} log */
  33. message.Debug = function(log)
  34. {
  35. dbg_log([].slice.apply(arguments).join(" "), LOG_9P);
  36. }
  37. message.Abort = function()
  38. {
  39. if(DEBUG)
  40. {
  41. throw "abort";
  42. }
  43. }
  44. // XXX: Should go through emulator interface
  45. var LoadBinaryResource;
  46. if(typeof XMLHttpRequest !== "undefined")
  47. {
  48. LoadBinaryResource = function(url, OnSuccess, OnError) {
  49. var req = new XMLHttpRequest();
  50. req.open('GET', url, true);
  51. req.responseType = "arraybuffer";
  52. req.onreadystatechange = function () {
  53. if (req.readyState != 4) {
  54. return;
  55. }
  56. if ((req.status != 200) && (req.status != 0)) {
  57. OnError("Error: Could not load file " + url);
  58. return;
  59. }
  60. var arrayBuffer = req.response;
  61. if (arrayBuffer) {
  62. OnSuccess(arrayBuffer);
  63. } else {
  64. OnError("Error: No data received from: " + url);
  65. }
  66. };
  67. /*
  68. req.onload = function(e)
  69. {
  70. var arrayBuffer = req.response;
  71. if (arrayBuffer) {
  72. OnLoadFunction(arrayBuffer);
  73. }
  74. };
  75. */
  76. req.send(null);
  77. }
  78. }
  79. else
  80. {
  81. LoadBinaryResource = function(url, OnSuccess, OnError)
  82. {
  83. //console.log(url);
  84. require("fs")["readFile"](url, function(err, data)
  85. {
  86. if(err)
  87. {
  88. OnError(err);
  89. }
  90. else
  91. {
  92. OnSuccess(new Uint8Array(data).buffer);
  93. }
  94. });
  95. }
  96. }