1
0

linux-boot.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env node
  2. "use strict";
  3. const BENCH_COLLECT_STATS = +process.env.BENCH_COLLECT_STATS;
  4. const V86 = require(`../../build/${BENCH_COLLECT_STATS ? "libv86-debug" : "libv86"}.js`).V86;
  5. const print_stats = require("../../build/libv86.js").print_stats;
  6. const fs = require("fs");
  7. const path = require("path");
  8. const V86_ROOT = path.join(__dirname, "../..");
  9. const LOG_SERIAL = true;
  10. if(true)
  11. {
  12. var emulator = new V86({
  13. bios: { url: __dirname + "/../../bios/seabios.bin" },
  14. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  15. cdrom: { url: __dirname + "/../../images/linux3.iso" },
  16. autostart: true,
  17. memory_size: 32 * 1024 * 1024,
  18. disable_jit: +process.env.DISABLE_JIT,
  19. log_level: 0,
  20. });
  21. }
  22. else
  23. {
  24. var emulator = new V86({
  25. bios: { url: path.join(V86_ROOT, "/bios/seabios.bin") },
  26. vga_bios: { url: path.join(V86_ROOT, "/bios/vgabios.bin") },
  27. autostart: true,
  28. memory_size: 512 * 1024 * 1024,
  29. vga_memory_size: 8 * 1024 * 1024,
  30. network_relay_url: "<UNUSED>",
  31. bzimage_initrd_from_filesystem: true,
  32. cmdline: "rw console=ttyS0 apm=off root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose mitigations=off audit=0 tsc=reliable nowatchdog init=/usr/bin/init-openrc",
  33. filesystem: {
  34. basefs: {
  35. url: path.join(V86_ROOT, "/images/fs.json"),
  36. },
  37. baseurl: path.join(V86_ROOT, "/images/arch/"),
  38. },
  39. disable_jit: +process.env.DISABLE_JIT,
  40. log_level: 0,
  41. });
  42. }
  43. emulator.bus.register("emulator-started", function()
  44. {
  45. console.log("Booting now, please stand by");
  46. start_time = Date.now();
  47. });
  48. var serial_text = "";
  49. var start_time;
  50. emulator.add_listener("serial0-output-byte", function(byte)
  51. {
  52. var chr = String.fromCharCode(byte);
  53. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  54. {
  55. return;
  56. }
  57. if(LOG_SERIAL) process.stdout.write(chr);
  58. serial_text += chr;
  59. if(serial_text.endsWith("~% ") || serial_text.endsWith("root@localhost:~# "))
  60. {
  61. const end_time = Date.now();
  62. const elapsed = end_time - start_time;
  63. console.log("Done in %dms", elapsed);
  64. emulator.destroy();
  65. if(BENCH_COLLECT_STATS)
  66. {
  67. const cpu = emulator.v86.cpu;
  68. console.log(print_stats.stats_to_string(cpu));
  69. }
  70. }
  71. });