serial.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!doctype html>
  2. <title>Serial example</title>
  3. <script src="../build/libv86.js"></script>
  4. <script>
  5. "use strict";
  6. window.onload = function()
  7. {
  8. var emulator = new V86({
  9. wasm_path: "../build/v86.wasm",
  10. // Uncomment to see what's going on
  11. //screen_container: document.getElementById("screen_container"),
  12. bios: {
  13. url: "../bios/seabios.bin",
  14. },
  15. vga_bios: {
  16. url: "../bios/vgabios.bin",
  17. },
  18. bzimage: {
  19. url: "../images/buildroot-bzimage68.bin",
  20. async: false,
  21. },
  22. filesystem: {},
  23. cmdline: "tsc=reliable mitigations=off random.trust_cpu=on",
  24. autostart: true,
  25. disable_keyboard: true,
  26. });
  27. // In this example we wait for output from the serial terminal, which
  28. // should be running busybox. We log in as soon as a prompt appears and then
  29. // retrieve a directory listing of the root directory
  30. var data = "";
  31. var stages = [
  32. {
  33. test: "~% ",
  34. send: "ls -1 --color=never /\n",
  35. },
  36. {
  37. test: "~% ",
  38. send: "lua -e 'print(3+4)'\n",
  39. },
  40. ];
  41. var stage = 0;
  42. emulator.add_listener("serial0-output-byte", function(byte)
  43. {
  44. var char = String.fromCharCode(byte);
  45. if(char === "\r")
  46. {
  47. return;
  48. }
  49. data += char;
  50. document.getElementById("terminal").value += char;
  51. var current = stages[stage];
  52. if(!current)
  53. {
  54. return;
  55. }
  56. if(data.endsWith(current.test))
  57. {
  58. stage++;
  59. emulator.serial0_send(current.send);
  60. var log = "Sending: " + current.send.replace(/\n/g, "\\n") + "\n";
  61. document.getElementById("log").value += log;
  62. }
  63. });
  64. };
  65. </script>
  66. <textarea readonly rows=25 cols=60 id="log">Waiting for boot ...
  67. </textarea>
  68. <textarea readonly rows=25 cols=60 id="terminal"></textarea>
  69. <div id="screen_container">
  70. <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  71. <canvas style="display: none"></canvas>
  72. </div>