mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
Switch include style
This commit is contained in:
parent
858f24537f
commit
25570458b5
4 changed files with 100 additions and 23 deletions
97
nodejs-loader.mjs
Normal file
97
nodejs-loader.mjs
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
import vm from "node:vm";
|
||||||
|
import url from "node:url";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import crypto from "node:crypto";
|
||||||
|
import perf_hooks from "node:perf_hooks";
|
||||||
|
|
||||||
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
|
let files = [
|
||||||
|
"src/const.js",
|
||||||
|
"src/config.js",
|
||||||
|
"src/log.js",
|
||||||
|
"src/cpu.js",
|
||||||
|
"src/debug.js",
|
||||||
|
"src/io.js",
|
||||||
|
"src/main.js",
|
||||||
|
"src/lib.js",
|
||||||
|
"src/buffer.js",
|
||||||
|
"src/ide.js",
|
||||||
|
"src/pci.js",
|
||||||
|
"src/floppy.js",
|
||||||
|
"src/memory.js",
|
||||||
|
"src/dma.js",
|
||||||
|
"src/pit.js",
|
||||||
|
"src/vga.js",
|
||||||
|
"src/ps2.js",
|
||||||
|
|
||||||
|
"src/rtc.js",
|
||||||
|
"src/uart.js",
|
||||||
|
|
||||||
|
"src/acpi.js",
|
||||||
|
"src/apic.js",
|
||||||
|
"src/ioapic.js",
|
||||||
|
|
||||||
|
"src/state.js",
|
||||||
|
"src/ne2k.js",
|
||||||
|
"src/sb16.js",
|
||||||
|
"src/virtio.js",
|
||||||
|
"src/virtio_console.js",
|
||||||
|
//"src/virtio_net.js",
|
||||||
|
//"src/virtio_balloon.js",
|
||||||
|
"src/bus.js",
|
||||||
|
|
||||||
|
"src/debug.js",
|
||||||
|
"src/elf.js",
|
||||||
|
"src/kernel.js",
|
||||||
|
|
||||||
|
"lib/9p.js",
|
||||||
|
"lib/filesystem.js",
|
||||||
|
"lib/jor1k.js",
|
||||||
|
"lib/marshall.js",
|
||||||
|
"lib/utf8.js",
|
||||||
|
|
||||||
|
"src/browser/screen.js",
|
||||||
|
"src/browser/keyboard.js",
|
||||||
|
"src/browser/mouse.js",
|
||||||
|
"src/browser/speaker.js",
|
||||||
|
"src/browser/serial.js",
|
||||||
|
"src/browser/network.js",
|
||||||
|
"src/browser/fake_network.js",
|
||||||
|
"src/browser/fetch_network.js",
|
||||||
|
"src/browser/starter.js",
|
||||||
|
"src/browser/worker_bus.js",
|
||||||
|
"src/browser/dummy_screen.js",
|
||||||
|
"src/browser/print_stats.js",
|
||||||
|
"src/browser/filestorage.js"
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
let globals = Object.create(globalThis);
|
||||||
|
let v86 = {};
|
||||||
|
|
||||||
|
let ctx = vm.createContext(globals);
|
||||||
|
globals.DEBUG = false;
|
||||||
|
globals.module = {exports:v86};
|
||||||
|
Object.defineProperty(globals, "crypto", {value: crypto});
|
||||||
|
globals.require = (what) => {
|
||||||
|
return ({
|
||||||
|
perf_hooks,
|
||||||
|
fs
|
||||||
|
})[what];
|
||||||
|
};
|
||||||
|
|
||||||
|
for( let f of files ) {
|
||||||
|
vm.runInContext(fs.readFileSync(path.join(__dirname, f), "utf8"), ctx, {
|
||||||
|
filename: f
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export let {
|
||||||
|
V86,
|
||||||
|
CPU,
|
||||||
|
FetchNetworkAdapter,
|
||||||
|
MemoryFileStorage,
|
||||||
|
ServerFileStorageWrapper,
|
||||||
|
} = globals;
|
||||||
|
|
@ -1133,10 +1133,3 @@ TCPConnection.prototype.pump = function() {
|
||||||
this.net.receive(make_packet(reply));
|
this.net.receive(make_packet(reply));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(typeof module !== "undefined" && typeof module.exports !== "undefined")
|
|
||||||
{
|
|
||||||
module.exports["fake_tcp_connect"] = fake_tcp_connect;
|
|
||||||
module.exports["handle_fake_networking"] = handle_fake_networking;
|
|
||||||
module.exports["TCPConnection"] = TCPConnection;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,6 @@ FetchNetworkAdapter.prototype.receive = function(data)
|
||||||
this.bus.send("net" + this.id + "-receive", new Uint8Array(data));
|
this.bus.send("net" + this.id + "-receive", new Uint8Array(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if(typeof module !== "undefined" && typeof module.exports !== "undefined")
|
if(typeof module !== "undefined" && typeof module.exports !== "undefined")
|
||||||
{
|
{
|
||||||
module.exports["FetchNetworkAdapter"] = FetchNetworkAdapter;
|
module.exports["FetchNetworkAdapter"] = FetchNetworkAdapter;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,9 @@
|
||||||
const dgram = require("node:dgram");
|
import dgram from "node:dgram";
|
||||||
const server = dgram.createSocket("udp4");
|
import { V86, FetchNetworkAdapter } from "../nodejs-loader.mjs";
|
||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
|
|
||||||
// qemu-system-i386 -m 2G -nographic -hda ~/disk.qcow2 -netdev dgram,id=net0,remote.type=inet,remote.host=127.0.0.1,remote.port=6677,local.host=127.0.0.1,local.port=7744,local.type=inet -device e1000,netdev=net0
|
// qemu-system-i386 -m 2G -nographic -hda ~/disk.qcow2 -netdev dgram,id=net0,remote.type=inet,remote.host=127.0.0.1,remote.port=6677,local.host=127.0.0.1,local.port=7744,local.type=inet -device e1000,netdev=net0
|
||||||
|
|
||||||
globalThis.dbg_assert = require("node:assert");
|
const server = dgram.createSocket("udp4");
|
||||||
globalThis.dbg_log = (what, level) => console.log(what);
|
|
||||||
globalThis.LOG_NET = 0;
|
|
||||||
globalThis.LOG_FETCH = 1;
|
|
||||||
|
|
||||||
const { fake_tcp_connect, handle_fake_networking } = require(path.join(__dirname, "..", "src", "browser", "fake_network.js"));
|
|
||||||
globalThis.fake_tcp_connect = fake_tcp_connect;
|
|
||||||
globalThis.handle_fake_networking = handle_fake_networking;
|
|
||||||
|
|
||||||
const { FetchNetworkAdapter } = require(path.join(__dirname, "..", "src", "browser", "fetch_network.js"));
|
|
||||||
|
|
||||||
const events = {};
|
const events = {};
|
||||||
|
|
||||||
const bus = {
|
const bus = {
|
||||||
Loading…
Add table
Add a link
Reference in a new issue