linux-boot.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. screen_dummy: true,
  40. disable_jit: +process.env.DISABLE_JIT,
  41. log_level: 0,
  42. });
  43. }
  44. emulator.bus.register("emulator-started", function()
  45. {
  46. console.error("Booting now, please stand by");
  47. start_time = Date.now();
  48. });
  49. var serial_text = "";
  50. var start_time;
  51. emulator.add_listener("serial0-output-byte", function(byte)
  52. {
  53. var chr = String.fromCharCode(byte);
  54. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  55. {
  56. return;
  57. }
  58. if(LOG_SERIAL) process.stdout.write(chr);
  59. serial_text += chr;
  60. if(serial_text.endsWith("~% ") || serial_text.endsWith("root@localhost:~# "))
  61. {
  62. const end_time = Date.now();
  63. const elapsed = end_time - start_time;
  64. console.log("Done in %dms", elapsed);
  65. emulator.stop();
  66. if(BENCH_COLLECT_STATS)
  67. {
  68. const cpu = emulator.v86.cpu;
  69. console.log(print_stats.stats_to_string(cpu));
  70. }
  71. }
  72. });