1
0

serial.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-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-byte", function(byte)
  44. {
  45. var char = String.fromCharCode(byte);
  46. if(char === "\r")
  47. {
  48. return;
  49. }
  50. data += char;
  51. document.getElementById("terminal").value += char;
  52. var current = stages[stage];
  53. if(!current)
  54. {
  55. return;
  56. }
  57. if(data.endsWith(current.test))
  58. {
  59. stage++;
  60. emulator.serial0_send(current.send);
  61. var log = "Sending: " + current.send.replace(/\n/g, "\\n") + "\n";
  62. document.getElementById("log").value += log;
  63. }
  64. });
  65. };
  66. </script>
  67. <textarea readonly rows=25 cols=60 id="log">Waiting for boot ...
  68. </textarea>
  69. <textarea readonly rows=25 cols=60 id="terminal"></textarea>
  70. <div id="screen_container">
  71. <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  72. <canvas style="display: none"></canvas>
  73. </div>