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 V86Starter({
  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-bzimage.bin",
  20. size: 5166352,
  21. async: false,
  22. },
  23. filesystem: {},
  24. cmdline: "tsc=reliable mitigations=off random.trust_cpu=on",
  25. autostart: true,
  26. disable_keyboard: true,
  27. });
  28. // In this example we wait for output from the serial terminal, which
  29. // should be running busybox. We log in as soon as a prompt appears and then
  30. // retrieve a directory listing of the root directory
  31. var data = "";
  32. var stages = [
  33. {
  34. test: "~% ",
  35. send: "ls -1 --color=never /\n",
  36. },
  37. {
  38. test: "~% ",
  39. send: "lua -e 'print(3+4)'\n",
  40. },
  41. ];
  42. var stage = 0;
  43. emulator.add_listener("serial0-output-char", function(char)
  44. {
  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>