v86 0.5.273 → 0.5.277
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/libv86-debug.js +4 -4
- package/build/libv86-debug.mjs +127 -127
- package/build/libv86.js +4 -4
- package/build/libv86.mjs +46 -46
- package/build/v86-debug.wasm +0 -0
- package/build/v86-fallback.wasm +0 -0
- package/build/v86.wasm +0 -0
- package/package.json +1 -1
package/build/libv86-debug.js
CHANGED
|
@@ -6139,10 +6139,10 @@ if ("undefined" !== typeof process) {
|
|
|
6139
6139
|
}, $v86$$module$src$main$$.prototype.unregister_yield = function() {
|
|
6140
6140
|
};
|
|
6141
6141
|
} else {
|
|
6142
|
-
if (
|
|
6142
|
+
if (globalThis.scheduler && "function" === typeof globalThis.scheduler.postTask && location.href.includes("use-scheduling-api")) {
|
|
6143
6143
|
$v86$$module$src$main$$.prototype.yield = function($t$jscomp$8$$, $tick$jscomp$5$$) {
|
|
6144
6144
|
$t$jscomp$8$$ = Math.max(0, $t$jscomp$8$$);
|
|
6145
|
-
|
|
6145
|
+
globalThis.scheduler.postTask(() => this.yield_callback($tick$jscomp$5$$), {delay:$t$jscomp$8$$});
|
|
6146
6146
|
}, $v86$$module$src$main$$.prototype.register_yield = function() {
|
|
6147
6147
|
}, $v86$$module$src$main$$.prototype.unregister_yield = function() {
|
|
6148
6148
|
};
|
|
@@ -6486,8 +6486,8 @@ $UART$$module$src$uart$$.prototype.data_received = function($data$jscomp$169$$)
|
|
|
6486
6486
|
this.fifo_control & 1 ? this.ThrowInterrupt(12) : this.ThrowInterrupt(4);
|
|
6487
6487
|
};
|
|
6488
6488
|
$UART$$module$src$uart$$.prototype.write_data = function($char_line$jscomp$4_out_byte$jscomp$9$$) {
|
|
6489
|
-
this.line_control & 128 ? this.baud_rate = this.baud_rate & -256 | $char_line$jscomp$4_out_byte$jscomp$9$$ : ($dbg_log$$module$src$log$$("data: " + $h$$module$src$lib$$($char_line$jscomp$4_out_byte$jscomp$9$$), 16384), this.ThrowInterrupt(2), this.bus.send("serial" + this.com + "-output-byte", $char_line$jscomp$4_out_byte$jscomp$9$$), $char_line$jscomp$4_out_byte$jscomp$9$$ = String.fromCharCode($char_line$jscomp$4_out_byte$jscomp$9$$),
|
|
6490
|
-
"\n" === $char_line$jscomp$4_out_byte$jscomp$9$$ && ($char_line$jscomp$4_out_byte$jscomp$9$$ = this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g, ""), $dbg_log$$module$src$log$$("SERIAL: " + $char_line$jscomp$4_out_byte$jscomp$9$$), this.current_line = ""));
|
|
6489
|
+
this.line_control & 128 ? this.baud_rate = this.baud_rate & -256 | $char_line$jscomp$4_out_byte$jscomp$9$$ : ($dbg_log$$module$src$log$$("data: " + $h$$module$src$lib$$($char_line$jscomp$4_out_byte$jscomp$9$$), 16384), this.ThrowInterrupt(2), this.modem_control & 16 ? this.data_received($char_line$jscomp$4_out_byte$jscomp$9$$) : this.bus.send("serial" + this.com + "-output-byte", $char_line$jscomp$4_out_byte$jscomp$9$$), $char_line$jscomp$4_out_byte$jscomp$9$$ = String.fromCharCode($char_line$jscomp$4_out_byte$jscomp$9$$),
|
|
6490
|
+
this.current_line += $char_line$jscomp$4_out_byte$jscomp$9$$, "\n" === $char_line$jscomp$4_out_byte$jscomp$9$$ && ($char_line$jscomp$4_out_byte$jscomp$9$$ = this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g, ""), $dbg_log$$module$src$log$$("SERIAL: " + $char_line$jscomp$4_out_byte$jscomp$9$$), this.current_line = ""));
|
|
6491
6491
|
};
|
|
6492
6492
|
$UART$$module$src$uart$$.prototype.set_modem_status = function($status$jscomp$10$$) {
|
|
6493
6493
|
$dbg_log$$module$src$log$$("modem status: " + $h$$module$src$lib$$($status$jscomp$10$$), 16384);
|
package/build/libv86-debug.mjs
CHANGED
|
@@ -335,8 +335,8 @@ d=0;const e={};for(let g=0;g<c.length;g++){const k=c[g];var f=void 0;if(k.includ
|
|
|
335
335
|
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[jb(a,!1,!1,!1,!1),jb(a,!0,!1,!1,!1),jb(a,!1,!0,!1,!1),jb(a,!1,
|
|
336
336
|
!1,!0,!1),jb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function xc(a){this.message=a||"File not found"}xc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=N:"undefined"!==typeof window?window.V86=N:"function"===typeof importScripts&&(self.V86=N);function H(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new P(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}H.prototype.run=
|
|
337
337
|
function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};H.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_loop();this.next_tick(a)}};H.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};H.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};H.prototype.stop=function(){this.running&&
|
|
338
|
-
(this.stopping=!0)};H.prototype.destroy=function(){this.unregister_yield()};H.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};H.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)H.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},H.prototype.register_yield=function(){},H.prototype.unregister_yield=function(){};else if(
|
|
339
|
-
"function"===typeof
|
|
338
|
+
(this.stopping=!0)};H.prototype.destroy=function(){this.unregister_yield()};H.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};H.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)H.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},H.prototype.register_yield=function(){},H.prototype.unregister_yield=function(){};else if(globalThis.scheduler&&
|
|
339
|
+
"function"===typeof globalThis.scheduler.postTask&&location.href.includes("use-scheduling-api"))H.prototype.yield=function(a,b){a=Math.max(0,a);globalThis.scheduler.postTask(()=>this.yield_callback(b),{delay:a})},H.prototype.register_yield=function(){},H.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}H.prototype.register_yield=
|
|
340
340
|
function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};H.prototype.yield=function(b,c){this.worker.postMessage({t:b,tick:c})};H.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else H.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},H.prototype.register_yield=function(){},H.prototype.unregister_yield=
|
|
341
341
|
function(){};H.prototype.save_state=function(){for(var a=[],b=gb(this.cpu,a),c=[],d=0,e=0;e<a.length;e++){var f=a[e].byteLength;c[e]={offset:d,length:f};d+=f;d=d+3&-4}b=JSON.stringify({buffer_infos:c,state:b});b=(new TextEncoder).encode(b);e=16+b.length;e=e+3&-4;var g=e+d;d=new ArrayBuffer(g);var k=new Int32Array(d,0,4);(new Uint8Array(d,16,b.length)).set(b);f=new Uint8Array(d,e);k[0]=-2039052682;k[1]=6;k[2]=g;k[3]=b.length;for(e=0;e<a.length;e++)g=a[e],l(g.constructor===Uint8Array),f.set(g,c[e].offset);
|
|
342
342
|
B("State: json size "+(b.byteLength>>10)+"k");B("State: Total buffers size "+(f.byteLength>>10)+"k");return d};H.prototype.restore_state=function(a){return ib(this.cpu,a)};if("object"===typeof performance&&performance.now)H.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");H.microtick=a.now.bind(a)}else H.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;
|
|
@@ -354,131 +354,131 @@ this.modem_status|17:this.modem_status&-18)},this);a=a.io;a.register_write(b,thi
|
|
|
354
354
|
16384);return this.lsr});a.register_write(b|5,this,function(){B("Factory test write",16384)});a.register_read(b|6,this,function(){B("read modem status: "+n(this.modem_status),16384);return this.modem_status&=240});a.register_write(b|6,this,function(d){B("write modem status: "+n(d),16384);this.set_modem_status(d)});a.register_read(b|7,this,function(){return this.scratch_register});a.register_write(b|7,this,function(d){this.scratch_register=d})}zc.prototype.get_state=function(){var a=[];a[0]=this.ints;
|
|
355
355
|
a[1]=this.baud_rate;a[2]=this.line_control;a[3]=this.lsr;a[4]=this.fifo_control;a[5]=this.ier;a[6]=this.iir;a[7]=this.modem_control;a[8]=this.modem_status;a[9]=this.scratch_register;a[10]=this.irq;return a};zc.prototype.set_state=function(a){this.ints=a[0];this.baud_rate=a[1];this.line_control=a[2];this.lsr=a[3];this.fifo_control=a[4];this.ier=a[5];this.iir=a[6];this.modem_control=a[7];this.modem_status=a[8];this.scratch_register=a[9];this.irq=a[10]};zc.prototype.CheckInterrupt=function(){this.ints&
|
|
356
356
|
4096&&this.ier&1?(this.iir=12,this.cpu.device_raise_irq(this.irq)):this.ints&16&&this.ier&1?(this.iir=4,this.cpu.device_raise_irq(this.irq)):this.ints&4&&this.ier&2?(this.iir=2,this.cpu.device_raise_irq(this.irq)):this.ints&1&&this.ier&8?(this.iir=0,this.cpu.device_raise_irq(this.irq)):(this.iir=1,this.cpu.device_lower_irq(this.irq))};zc.prototype.ThrowInterrupt=function(a){this.ints|=1<<a;this.CheckInterrupt()};zc.prototype.ClearInterrupt=function(a){this.ints&=~(1<<a);this.CheckInterrupt()};zc.prototype.data_received=
|
|
357
|
-
function(a){B("input: "+n(a),16384);this.input.push(a);this.lsr|=1;this.fifo_control&1?this.ThrowInterrupt(12):this.ThrowInterrupt(4)};zc.prototype.write_data=function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(B("data: "+n(a),16384),this.ThrowInterrupt(2),this.bus.send("serial"+this.com+"-output-byte",a),a=String.fromCharCode(a),this.current_line+=a,"\n"===a&&(a=this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g,
|
|
358
|
-
zc.prototype.set_modem_status=function(a){B("modem status: "+n(a),16384);const b=this.modem_status&15;let c=(this.modem_status^a)>>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function Ac(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);this.pci_addr32=new Int32Array(this.pci_addr.buffer);this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=
|
|
359
|
-
this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=a.io;a.io.register_write(3324,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],c)});a.io.register_write(3325,this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,
|
|
360
|
-
2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(3327,this,function(c){this.pci_write8(this.pci_addr32[0]+3|0,c)});a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});a.io.register_read_consecutive(3320,this,function(){return this.pci_status[0]},
|
|
361
|
-
function(){return this.pci_status[3]});a.io.register_write_consecutive(3320,this,function(c){this.pci_addr[0]=c&252},function(c){2===(this.pci_addr[1]&6)&&6===(c&6)?(B("CPU reboot via PCI"),a.reboot_internal()):this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,0,0,2,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
362
|
-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=new Uint8Array(this.isa_bridge_space.buffer)}
|
|
363
|
-
a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};Ac.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var f=d[4+e];if(f&1){var g=c.pci_bars[e];this.set_io_bars(g,g.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else c&&B("Warning: While restoring PCI device: Device exists in current configuration but not in snapshot ("+
|
|
364
|
-
n(b,2)+")")}this.pci_addr.set(a[256]);this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};Ac.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+n(a,4));d+=" dev="+n(c,2);d+=" addr="+n(b,2);c=this.device_spaces[a];void 0!==c?(this.pci_status32[0]
|
|
365
|
-
0,8),b>=c.byteLength&&(d+=" (undef)"),d+=" ("+this.devices[a].name+")",B(d,2048)):(this.pci_response32[0]=-1,this.pci_status32[0]=0)};Ac.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(l(!(16<=a&&44>a||48<=a&&52>a),"PCI: Expected 32-bit write, got 8-bit (addr: "+n(a)+")"),B("PCI write8 dev="+
|
|
366
|
-
a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(16<=a&&44>a?B("Warning: PCI: Expected 32-bit write, got 16-bit (addr: "+n(a)+")"):(l(!(48<=a&&52>a),"PCI: Expected 32-bit write, got 16-bit (addr: "+n(a)+")"),B("PCI writ16 dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,4),2048),d[a>>>1]=b))};Ac.prototype.pci_write32=
|
|
367
|
-
2,g=e.pci_bars[f];B("BAR"+f+" exists="+(g?"y":"n")+" changed from "+n(d[a>>2])+" to "+n(b>>>0)+" dev="+n(c>>3,2)+" ("+e.name+") ",2048);g?(l(!(g.size&g.size-1),"bar size should be power of 2"),c=a>>2,e=d[c]&1,-1===(b|3|g.size-1)?(b=~(g.size-1)|e,0===e&&(d[c]=b)):0===e&&(f=g.original_bar,(b&-16)!==(f&-16)&&B("Warning: Changing memory bar not supported, ignored",2048),d[c]=
|
|
368
|
-
e,f),d[c]=b|1)):d[a>>2]=0;B("BAR effective value: "+n(d[a>>2]>>>0),2048)}else 48===a?(B("PCI write rom address dev="+n(c>>3,2)+" ("+e.name+") value="+n(b>>>0,8),2048),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?B("PCI write dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048):(B("PCI write dev="+n(c>>3,
|
|
369
|
-
a.pci_space);l(void 0!==a.pci_bars);var b=a.pci_id;B("PCI register bdf="+n(b)+" ("+a.name+")",2048);this.devices[b]&&B("warning: overwriting device "+this.devices[b].name+" with "+a.name,2048);l(64<=a.pci_space.length);l(b<this.devices.length);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=
|
|
370
|
-
e.size+" at "+n(f),2048);e.original_bar=f;e.entries=[];if(0!==g)for(l(1===g),f&=-2,g=0;g<e.size;g++)e.entries[g]=this.io.ports[f+g]}}return c};Ac.prototype.set_io_bars=function(a,b,c){var d=a.size;B("Move io bars: from="+n(b)+" to="+n(c)+" count="+d,2048);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());var g=a.entries[f],
|
|
371
|
-
((b[15]>>8&255)-1+((a>>3)-1&255)&3)])};Ac.prototype.lower_irq=function(a){var b=this.device_spaces[a];l(b);this.cpu.device_lower_irq(this.isa_bridge_space8[96+((b[15]>>8&255)+(a>>3&255)-2&3)])};function Bc(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(B("Replace mac in eth destination field",1048576),
|
|
372
|
-
1048576),a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d)if(a=a.subarray(14),d=a[0]>>4,4!==d)B("Expected ipv4.version==4 but got: "+d,1048576);else{if(l(5===(a[0]&15),"TODO: ihl!=5"),17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];B("udp srcport="+d+" dstport="+
|
|
373
|
-
else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(B("Replace mac in dhcp.chaddr",1048576),d[28]=c[0],d[29]=c[1],d[30]=c[2],d[31]=c[3],d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const g=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===
|
|
374
|
-
6]=c[5],a[6]=a[7]=0);e+=g}}}else 2054===d&&(a=a.subarray(14),B("arp oper="+a[7]+" "+Cc(a.subarray(8,14))+" "+Cc(a.subarray(18,24)),1048576),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(B("Replace mac in arp.sha",1048576),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}
|
|
375
|
-
"0"),a[5].toString(16).padStart(2,"0")].join(":")}function Dc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=768+256*this.id;this.name="ne2k";
|
|
376
|
-
0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+
|
|
377
|
-
this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;B("Mac: "+Cc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|0,this,function(){B("Read cmd",1048576);return this.cr},function(){B("Read16 cmd",1048576);return this.cr});b.register_write(this.port|
|
|
378
|
-
f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),Bc(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),B("Command: Transfer. length="+n(f.byteLength),1048576)))});b.register_read(this.port|
|
|
379
|
-
|
|
380
|
-
31,this,function(f){this.get_page();B("Write reset: "+n(f,2),1048576)});b.register_read(this.port|1,this,function(){var f=this.get_page();if(0===f)return this.pstart;if(1===f)return B("Read pg1/01 (mac[0])",1048576),this.mac[0];if(2===f)return this.pstart;B("Read pg"+f+"/01");l(!1);return 0});b.register_write(this.port|1,this,function(f){var g=
|
|
381
|
-
n(f),1048576):(B("Write pg"+g+"/01: "+n(f),1048576),l(!1))});b.register_read(this.port|2,this,function(){var f=this.get_page();if(0===f)return this.pstop;if(1===f)return B("Read pg1/02 (mac[1])",1048576),this.mac[1];if(2===f)return this.pstop;B("Read pg"+f+"/02",1048576);l(!1);return 0});b.register_write(this.port|2,this,function(f){var g=
|
|
382
|
-
f):1===g?(B("mac[1] = "+n(f),1048576),this.mac[1]=f):(B("Write pg"+g+"/02: "+n(f),1048576),l(!1))});b.register_read(this.port|7,this,function(){var f=this.get_page();if(0===f)return B("Read isr: "+n(this.isr,2),1048576),this.isr;if(1===f)return B("Read curpg: "+n(this.curpg,2),1048576),this.curpg;l(!1);return 0});b.register_write(this.port|
|
|
383
|
-
|
|
384
|
-
f)return B("Read mar2",1048576),this.mar[2];l(!1,"TODO");return 0});b.register_write(this.port|10,this,function(f){var g=this.get_page();0===g?(B("Write remote byte count low: "+n(f,2),1048576),this.rcnt=this.rcnt&65280|f&255):B("Unimplemented: Write pg"+g+"/0a "+n(f,2),1048576)});b.register_read(this.port|11,this,function(){var f=this.get_page();if(0===
|
|
385
|
-
function(f){var g=this.get_page();0===g?(B("Write remote byte count high: "+n(f,2),1048576),this.rcnt=this.rcnt&255|f<<8&65280):B("Unimplemented: Write pg"+g+"/0b "+n(f,2),1048576)});b.register_read(this.port|8,this,function(){var f=this.get_page();if(0===f)return B("Read remote start address low",1048576),this.rsar&255;if(1===f)return B("Read mar0",1048576),
|
|
386
|
-
0===g?(B("Write remote start address low: "+n(f,2),1048576),this.rsar=this.rsar&65280|f&255):B("Unimplemented: Write pg"+g+"/08 "+n(f,2),1048576)});b.register_read(this.port|9,this,function(){var f=this.get_page();if(0===f)return B("Read remote start address high",1048576),this.rsar>>8&255;if(1===f)return B("Read mar1",1048576),this.mar[1];B("Unimplemented: Read pg"+
|
|
387
|
-
n(f,2),1048576),this.rsar=this.rsar&255|f<<8&65280):B("Unimplemented: Write pg"+g+"/09 "+n(f,2),1048576)});b.register_write(this.port|15,this,function(f){var g=this.get_page();0===g?(B("Write interrupt mask register: "+n(f,2)+" isr="+n(this.isr,2),1048576),this.imr=f,this.update_irq()):B("Unimplemented: Write pg"+g+"/0f "+n(f,2),1048576)});b.register_read(this.port|
|
|
388
|
-
1048576),this.mac[2];3===f?B("Unimplemented: Read pg3/03 (CONFIG0)",1048576):(B("Read pg"+f+"/03",1048576),l(!1));return 0});b.register_write(this.port|3,this,function(f){var g=this.get_page();0===g?(B("Write boundary: "+n(f,2),1048576),this.boundary=f):1===g?(B("mac[2] = "+n(f),1048576),this.mac[2]=f):(B("Write pg"+g+"/03: "+n(f),1048576),
|
|
389
|
-
B("Read pg"+f+"/04",1048576);l(!1);return 0});b.register_write(this.port|4,this,function(f){var g=this.get_page();0===g?(B("Write tpsr: "+n(f,2),1048576),this.tpsr=f):1===g?(B("mac[3] = "+n(f),1048576),this.mac[3]=f):(B("Write pg"+g+"/04: "+n(f),1048576),l(!1))});b.register_read(this.port|5,this,function(){var f=this.get_page();if(0===f)return B("Unimplemented: Read pg0/05 (NCR: Number of Collisions Register)",
|
|
390
|
-
1048576):(B("Read pg"+f+"/05",1048576),l(!1));return 0});b.register_write(this.port|5,this,function(f){var g=this.get_page();0===g?(B("Write tcnt low: "+n(f,2),1048576),this.tcnt=this.tcnt&-256|f):1===g?(B("mac[4] = "+n(f),1048576),this.mac[4]=f):3===g?B("Unimplemented: Write pg3/05 (CONFIG2): "+n(f),1048576):(B("Write pg"+g+"/05: "+n(f),1048576),l(!1))});b.register_read(this.port|
|
|
391
|
-
this.mac[5];3===f?B("Unimplemented: Read pg3/06 (CONFIG3)",1048576):(B("Read pg"+f+"/06",1048576),l(!1));return 0});b.register_write(this.port|6,this,function(f){var g=this.get_page();0===g?(B("Write tcnt high: "+n(f,2),1048576),this.tcnt=this.tcnt&255|f<<8):1===g?(B("mac[5] = "+n(f),1048576),this.mac[5]=f):3===g?B("Unimplemented: Write pg3/06 (CONFIG3): "+n(f),1048576):(B("Write pg"+
|
|
392
|
-
if(1===f)return B("Read mar4",1048576),this.mar[4];B("Unimplemented: Read pg"+f+"/0c",1048576);l(!1);return 0});b.register_write(this.port|12,this,function(f){var g=this.get_page();0===g?(B("RX configuration reg write: "+n(f,2),1048576),this.rxcr=f):B("Unimplemented: Write pg"+g+"/0c: "+n(f),1048576)});b.register_read(this.port|16,this,this.data_port_read8,this.data_port_read16,this.data_port_read32);
|
|
393
|
-
a.devices.pci.register_device(this)}Dc.prototype.get_state=function(){var a=[];a[0]=this.isr;a[1]=this.imr;a[2]=this.cr;a[3]=this.dcfg;a[4]=this.rcnt;a[5]=this.tcnt;a[6]=this.tpsr;a[7]=this.rsar;a[8]=this.pstart;a[9]=this.curpg;a[10]=this.boundary;a[11]=this.pstop;a[12]=this.rxcr;a[13]=this.txcr;a[14]=this.tsr;a[15]=this.mac;a[16]=this.memory;return a};Dc.prototype.set_state=function(a){this.isr=
|
|
394
|
-
a[7];this.pstart=a[8];this.curpg=a[9];this.boundary=a[10];this.pstop=a[11];this.rxcr=a[12];this.txcr=a[13];this.tsr=a[14];this.preserve_mac_from_state_image?(this.mac=a[15],this.memory=a[16]):this.mac_address_translation&&(this.mac_address_in_state=a[15],this.memory=a[16],B("Using mac address translation guest_os_mac="+Cc(this.mac_address_in_state)+" real_mac="+Cc(this.mac),1048576));this.bus.send("net"+
|
|
395
|
-
this.isr|=a;this.update_irq()};Dc.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};Dc.prototype.data_port_write=function(a){if(16>=this.rsar||16384<=this.rsar&&32768>this.rsar)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64)};Dc.prototype.data_port_write16=
|
|
396
|
-
Dc.prototype.data_port_write32=function(a){this.data_port_write(a);this.data_port_write(a>>8);this.data_port_write(a>>16);this.data_port_write(a>>24)};Dc.prototype.data_port_read=function(){let a=0;32768>this.rsar&&(a=this.memory[this.rsar]);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64);return a};Dc.prototype.data_port_read8=function(){return this.data_port_read16()&
|
|
397
|
-
1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};Dc.prototype.data_port_read32=function(){return this.data_port_read()|this.data_port_read()<<8|this.data_port_read()<<16|this.data_port_read()<<24};Dc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-end",[a.length]),this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255===a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&
|
|
398
|
-
a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),Bc(a,this.mac,this.mac_address_in_state));var b=this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),f=b+c,g=1+(c>>8),k=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;k<g&&0!==this.boundary?B("Buffer full, dropping packet pstart="+n(this.pstart)+" pstop="+n(this.pstop)+
|
|
399
|
-
" available="+n(k),1048576):(f>this.pstop<<8?(l(60<=a.length),f=(this.pstop<<8)-d,l(0<=f),this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),B("rcv cut="+n(f),1048576)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,B("rcv offset="+n(b)+" len="+
|
|
400
|
-
function(){return this.cr>>6&3};function Ec(a,b){this.bus=b;this.rows=25;this.cols=80;this.ports=4;b=[{size_supported:16,notify_offset:0},{size_supported:16,notify_offset:1},{size_supported:16,notify_offset:2},{size_supported:16,notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Fc(a,{name:"virtio-console",pci_id:96,device_id:4163,
|
|
401
|
-
1,32],on_driver_ok:()=>{}},notification:{initial_port:47360,single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},c=>{if(2!==c)l(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 2)");else for(c=this.virtio.queues[c];c.count_requests()>
|
|
402
|
-
"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 3)");else for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);e.get_next_blob(f);var g=J(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,
|
|
403
|
-
" VirtioConsole received unknown event: "+g[1]);return}}}]},isr_status:{initial_port:46848},device_specific:{initial_port:46592,struct:[{bytes:2,name:"cols",read:()=>this.cols,write:()=>{}},{bytes:2,name:"rows",read:()=>this.rows,write:()=>{}},{bytes:4,name:"max_nr_ports",read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{l(!1,"Emergency write!")}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+
|
|
404
|
-
this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&this.SendWindowSize(c,e[0],e[1])},this)}}Ec.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);I(["w","h","h",
|
|
405
|
-
d,e)};Ec.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);I(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};Ec.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Ec.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=
|
|
406
|
-
Ec.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);I(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};Ec.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Ec.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Gc(a,b){this.cpu=
|
|
407
|
-
function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=c[0];this.wheel_movement-=2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);
|
|
408
|
-
a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}Gc.prototype.reset=function(){this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=this.next_read_rate=this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=
|
|
409
|
-
100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new na(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1};Gc.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;
|
|
410
|
-
this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;a[15]=this.last_port60_byte;a[16]=this.sample_rate;a[17]=this.resolution;a[18]=this.scaling2;a[20]=this.command_register;a[21]=this.read_output_register;
|
|
411
|
-
a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};Gc.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=a[4];this.mouse_clicks=a[5];this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=
|
|
412
|
-
a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=a[18];this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;
|
|
413
|
-
this.use_mouse)};Gc.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};Gc.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(B("Mouse irq",64),this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};Gc.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux
|
|
414
|
-
this.cpu.device_raise_irq(1))};Gc.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(B("adding kbd code: "+n(a),64),this.kbd_buffer.push(a),this.raise_irq())};Gc.prototype.mouse_send_delta=function(a,b){this.have_mouse&&this.use_mouse&&(this.mouse_delta_x+=1*a,this.mouse_delta_y+=1*b,this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b))&&(this.mouse_delta_x-=a,this.mouse_delta_y-=
|
|
415
|
-
this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))};Gc.prototype.send_mouse_packet=function(a,b){var c=(0>b)<<5|(0>a)<<4|8|this.mouse_clicks;this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&15),this.wheel_movement=0):3===this.mouse_id&&
|
|
416
|
-
Gc.prototype.apply_scaling2=function(a){var b=a>>31;switch(Math.abs(a)){case 0:case 1:case 3:return a;case 2:return b;case 4:return 6*b;case 5:return 9*b;default:return a<<1}};Gc.prototype.port60_read=function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return B("Port 60 read: Empty",64),this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),this.last_port60_byte=
|
|
417
|
-
64)):(this.cpu.device_lower_irq(1),this.last_port60_byte=this.kbd_buffer.shift(),B("Port 60 read (kbd) : "+n(this.last_port60_byte),64));(this.kbd_buffer.length||this.mouse_buffer.length)&&this.raise_irq();return this.last_port60_byte};Gc.prototype.port64_read=function(){var a=16;this.next_byte_is_ready&&(a|=1);this.next_byte_is_aux&&(a|=32);B("port 64 read: "+n(a),64);return a};Gc.prototype.port60_write=function(a){B("port 60 write: "+
|
|
418
|
-
a,this.read_command_register=!1,B("Keyboard command register = "+n(this.command_register),64);else if(this.read_output_register)this.read_output_register=!1,this.mouse_buffer.clear(),this.mouse_buffer.push(a),this.mouse_irq();else if(this.next_read_sample){this.next_read_sample=!1;this.mouse_buffer.clear();this.mouse_buffer.push(250);this.sample_rate=a;switch(this.mouse_detect_state){case -1:60===a?(this.mouse_reset_workaround=!0,this.mouse_detect_state=
|
|
419
|
-
200===a?1:0);break;case 0:200===a&&(this.mouse_detect_state=1);break;case 1:this.mouse_detect_state=100===a?2:200===a?3:0;break;case 2:80===a&&(this.mouse_id=3);this.mouse_detect_state=-1;break;case 3:80===a&&(this.mouse_id=4),this.mouse_detect_state=-1}B("mouse sample rate: "+n(a)+", mouse id: "+n(this.mouse_id),64);this.sample_rate||(B("invalid sample rate, reset to 100",64),this.sample_rate=100);this.mouse_irq()}else if(this.next_read_resolution)this.next_read_resolution
|
|
420
|
-
this.mouse_buffer.push(250),3<a?(this.resolution=4,B("invalid resolution, resetting to 4",64)):(this.resolution=1<<a,B("resolution: "+this.resolution,64)),this.mouse_irq();else if(this.next_read_led)this.next_read_led=!1,this.kbd_buffer.push(250),this.kbd_irq();else if(this.next_handle_scan_code_set)this.next_handle_scan_code_set=!1,this.kbd_buffer.push(250),this.kbd_irq(),a||this.kbd_buffer.push(1);else if(this.next_read_rate)this.next_read_rate=!1,this.kbd_buffer.push(250),
|
|
421
|
-
|
|
422
|
-
this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;this.raise_irq();break;case 243:this.next_read_sample=!0;break;case 244:this.use_mouse=this.enable_mouse_stream=!0;this.bus.send("mouse-enable",!0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;case 245:this.enable_mouse_stream=!1;break;case 246:this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;
|
|
423
|
-
|
|
424
|
-
this.kbd_buffer.push(250);switch(a){case 237:this.next_read_led=!0;break;case 240:this.next_handle_scan_code_set=!0;break;case 242:this.kbd_buffer.push(171);this.kbd_buffer.push(131);break;case 243:this.next_read_rate=!0;break;case 244:B("kbd enable scanning",64);this.enable_keyboard_stream=!0;break;case 245:B("kbd disable scanning",64);this.enable_keyboard_stream=!1;break;case 246:break;case 255:this.kbd_buffer.clear();
|
|
425
|
-
default:B("Unimplemented keyboard command: "+n(a),64)}this.kbd_irq()}};Gc.prototype.port64_write=function(a){B("port 64 write: "+n(a),64);switch(a){case 32:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(this.command_register);this.kbd_irq();break;case 96:this.read_command_register=!0;break;case 209:this.read_controller_output_port=!0;break;case 211:this.read_output_register=!0;break;case 212:this.next_is_mouse_command
|
|
426
|
-
32;break;case 168:B("Enable second port",64);this.command_register&=-33;break;case 169:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 170:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(85);this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:B("Disable Keyboard",64);this.command_register|=
|
|
427
|
-
|
|
428
|
-
{ehsize:Jc},{phentsize:Jc},{phnum:Jc},{shentsize:Jc},{shnum:Jc},{shstrndx:Jc}]);console.assert(52===Lc.reduce((a,b)=>a+b.size,0));const Mc=Kc([{type:Q},{offset:Q},{vaddr:Q},{paddr:Q},{filesz:Q},{memsz:Q},{flags:Q},{align:Q}]);console.assert(32===Mc.reduce((a,b)=>a+b.size,0));const Nc=Kc([{name:Q},{type:Q},{flags:Q},{addr:Q},{offset:Q},{size:Q},{link:Q},{info:Q},{addralign:Q},{entsize:Q}]);console.assert(40===Nc.reduce((a,b)=>a+b.size,
|
|
429
|
-
console.assert(1===c.length);c=c[0];b=b[c];console.assert(0<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}function Oc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Pc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,k]=Oc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=k}return[d,e]}const Qc={[0]:0,[1]:525,
|
|
430
|
-
a.io;this.cpu=a;this.dma=a.devices.dma;this.cmd_table=this.build_cmd_lookup_table();this.sra=0;this.srb=192;this.dor=12;this.tdr=0;this.msr=128;this.dsr=0;this.cmd_phase=1;this.cmd_flags=this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=this.response_length=this.response_cursor=0;this.locked
|
|
431
|
-
96;this.eot=this.precomp_trk=0;this.drives=[new Rc("fda",d?.fda,b,4),new Rc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,this,this.read_reg_tdr);this.io.register_read(1012,this,
|
|
432
|
-
this.io.register_read(1015,this,this.read_reg_dir);this.io.register_write(1010,this,this.write_reg_dor);this.io.register_write(1011,this,this.write_reg_tdr);this.io.register_write(1012,this,this.write_reg_dsr);this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr);B("floppy controller ready",8192)}W.prototype.build_cmd_lookup_table=function(){const a=[{code:6,mask:31,argc:8,name:"READ",
|
|
433
|
-
handler:this.exec_write},{code:15,mask:255,argc:2,name:"SEEK",handler:this.exec_seek},{code:8,mask:255,argc:0,name:"SENSE INTERRUPT STATUS",handler:this.exec_sense_interrupt_status},{code:7,mask:255,argc:1,name:"RECALIBRATE",handler:this.exec_recalibrate},{code:13,mask:191,argc:5,name:"FORMAT TRACK",handler:this.exec_format_track},{code:2,mask:191,argc:8,name:"READ TRACK",handler:this.exec_unimplemented},{code:78,mask:255,argc:17,name:"RESTORE",
|
|
434
|
-
name:"SAVE",handler:this.exec_unimplemented},{code:12,mask:31,argc:8,name:"READ DELETED DATA",handler:this.exec_unimplemented},{code:17,mask:31,argc:8,name:"SCAN EQUAL",handler:this.exec_unimplemented},{code:22,mask:31,argc:8,name:"VERIFY",handler:this.exec_unimplemented},{code:25,mask:31,argc:8,name:"SCAN LOW OR EQUAL",handler:this.exec_unimplemented},{code:29,mask:31,argc:8,name:"SCAN HIGH OR EQUAL",handler:this.exec_unimplemented},{code:9,
|
|
435
|
-
{code:10,mask:191,argc:1,name:"READ ID",handler:this.exec_read_id},{code:3,mask:255,argc:2,name:"SPECIFY",handler:this.exec_specify},{code:4,mask:255,argc:1,name:"SENSE DRIVE STATUS",handler:this.exec_sense_drive_status},{code:18,mask:255,argc:1,name:"PERPENDICULAR MODE",handler:this.exec_perpendicular_mode},{code:19,mask:255,argc:3,name:"CONFIGURE",handler:this.exec_configure},{code:23,mask:255,argc:2,name:"POWERDOWN MODE",
|
|
436
|
-
{code:142,mask:255,argc:5,name:"DRIVE SPECIFICATION",handler:this.exec_unimplemented},{code:143,mask:255,argc:2,name:"RELATIVE SEEK OUT",handler:this.exec_unimplemented},{code:205,mask:255,argc:10,name:"FORMAT AND WRITE",handler:this.exec_unimplemented},{code:207,mask:255,argc:2,name:"RELATIVE SEEK IN",handler:this.exec_unimplemented},{code:20,mask:127,argc:0,name:"LOCK",handler:this.exec_lock},
|
|
437
|
-
handler:this.exec_version},{code:24,mask:255,argc:0,name:"PART ID",handler:this.exec_part_id},{code:0,mask:0,argc:0,name:"UNKNOWN COMMAND",handler:this.exec_unimplemented}],b=Array(256);for(let c=a.length-1;0<=c;c--){const d=a[c];if(255===d.mask)b[d.code]=d;else for(let e=0;256>e;e++)(e&d.mask)===d.code&&(b[e]=d)}return b};W.prototype.raise_irq=function(a){this.sra&128||(this.cpu.device_raise_irq(6),
|
|
438
|
-
function(a){this.status0=0;this.sra&128&&(this.cpu.device_lower_irq(6),this.sra&=-129,B("IRQ lowered, reason: "+a,8192))};W.prototype.set_curr_drive_no=function(a){this.curr_drive_no=a&1;return this.drives[this.curr_drive_no]};W.prototype.enter_command_phase=function(){this.cmd_phase=1;this.cmd_remaining=this.cmd_cursor=0;this.msr&=-81;this.msr|=128};W.prototype.enter_result_phase=function(a){this.cmd_phase=
|
|
439
|
-
8192);this.lower_irq("controller reset");this.sra=0;this.srb=192;this.dor=12;this.msr=128;this.curr_drive_no=0;this.status0|=192;this.response_length=this.response_cursor=0;this.drives[0].seek(0,0,1);this.drives[1].seek(0,0,1);this.enter_command_phase();this.raise_irq("controller reset");this.reset_sense_int_count=4};W.prototype.read_reg_sra=function(){B("SRA read: "+n(this.sra),
|
|
440
|
-
function(){const a=this.dor&-4|this.curr_drive_no;B("DOR read: "+n(a),8192);return a};W.prototype.read_reg_tdr=function(){B("TDR read: "+n(this.tdr),8192);return this.tdr};W.prototype.read_reg_msr=function(){B("MSR read: "+n(this.msr),8192);this.dsr&=-65;this.dor|=4;return this.msr};W.prototype.read_reg_fifo=function(){this.dsr&=-65;if(!(this.msr&128&&this.msr&64))return B("FIFO read rejected: controller not ready for reading",
|
|
441
|
-
this.cmd_phase,8192),0;if(this.response_cursor<this.response_length){const a=this.response_data[this.response_cursor++];if(this.response_cursor===this.response_length){const b="end of "+this.cmd_table[this.cmd_code].name+" response";this.msr&=-129;this.enter_command_phase();this.lower_irq(b)}return a}B("FIFO read: empty",8192);return 0};W.prototype.read_reg_dir=function(){const a=this.drives[this.curr_drive_no].media_changed?
|
|
442
|
-
this.srb&-36|(a&16?1:0)|(a&32?2:0)|(a&1?32:0);this.dor&4?a&4||B("enter RESET state",8192):a&4&&(this.reset_fdc(),this.dsr&=-65,B("exit RESET state",8192));const b=a&3;B("DOR write: "+n(a)+", motors: "+n(a>>4)+", dma: "+!!(a&8)+", reset: "+!(a&4)+", drive: "+b,8192);1<b&&B("*** WARNING: floppy drive number "+b+" not implemented!",8192);this.curr_drive_no=b&1;this.dor=a};W.prototype.write_reg_tdr=function(a){this.dor&
|
|
443
|
-
8192)};W.prototype.write_reg_dsr=function(a){this.dor&4?(B("DSR write: "+n(a),8192),a&128&&(this.dor&=-5,this.reset_fdc(),this.dor|=4),a&64&&this.reset_fdc(),this.dsr=a):B("DSR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.write_reg_fifo=function(a){this.dsr&=-65;if(this.dor&4)if(!(this.msr&128)||this.msr&64)B("FIFO write "+n(a)+" rejected: controller not ready for writing",
|
|
444
|
-
this.cmd_phase,8192);else{if(0===this.cmd_remaining){var b=this.cmd_table[a];this.cmd_code=a;this.cmd_remaining=b.argc;this.cmd_flags=this.cmd_cursor=0;(6===b.code||5===b.code)&&this.cmd_code&128&&(this.cmd_flags|=1);this.cmd_remaining&&(this.msr|=128);this.msr|=16}else this.cmd_buffer[this.cmd_cursor++]=a,this.cmd_remaining--;if(0===this.cmd_remaining){this.cmd_phase=2;a=this.cmd_table[this.cmd_code];
|
|
445
|
-
n(this.cmd_code)+": "+a.name+"("+c.join(", ")+")",8192);a.handler.call(this,b)}}else B("FIFO write "+n(a)+" rejected: floppy controller in RESET mode!",8192)};W.prototype.write_reg_ccr=function(a){this.dor&4?(B("CCR write: "+n(a),8192),this.dsr=this.dsr&-4|a&3):B("CCR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.exec_unimplemented=function(){l(!1,"Unimplemented floppy command code "+
|
|
446
|
-
W.prototype.exec_read=function(a){this.start_read_write(a,!1)};W.prototype.exec_write=function(a){this.start_read_write(a,!0)};W.prototype.exec_seek=function(a){const b=this.set_curr_drive_no(a[0]&1);a=a[1];this.enter_command_phase();b.seek(b.curr_head,a,b.curr_sect);this.status0|=32;this.raise_irq("SEEK command")};W.prototype.exec_sense_interrupt_status=function(){const a=this.drives[this.curr_drive_no];
|
|
447
|
-
this.status0&-8|this.curr_drive_no;else{B("No interrupt pending, aborting SENSE INTERRUPT command!",8192);this.response_data[0]=128;this.enter_result_phase(1);return}this.response_data[0]=b;this.response_data[1]=a.curr_track;this.enter_result_phase(2);this.lower_irq("SENSE INTERRUPT command");this.status0=192};W.prototype.exec_recalibrate=function(a){this.set_curr_drive_no(a[0]&1).seek(0,0,1);this.enter_command_phase();
|
|
448
|
-
function(a){let b=0,c=0;this.set_curr_drive_no(a[0]&1).read_only&&(b=96,c=2);this.end_read_write(b,c,0)};W.prototype.exec_read_id=function(a){const b=this.drives[this.curr_drive_no];b.curr_head=a[0]>>2&1;0!==b.max_sect&&(b.curr_sect=b.curr_sect%b.max_sect+1);this.end_read_write(0,0,0)};W.prototype.exec_specify=function(a){const b=a[1];this.step_rate_interval=a[0]>>4;this.head_load_time=b>>1;this.dor=b&1?this.dor
|
|
449
|
-
a[0];const b=this.set_curr_drive_no(a&1);b.curr_head=a>>2&1;this.response_data[0]=(b.read_only?64:0)|(0===b.curr_track?16:0)|b.curr_head<<2|this.curr_drive_no|40;this.enter_result_phase(1)};W.prototype.exec_perpendicular_mode=function(a){a=a[0];a&128&&(this.drives[this.curr_drive_no].perpendicular=a&7);this.enter_command_phase()};W.prototype.exec_configure=function(a){this.fdc_config=a[1];this.precomp_trk=
|
|
450
|
-
|
|
451
|
-
a.perpendicular<<2;this.response_data[8]=this.fdc_config;this.response_data[9]=this.precomp_trk;this.enter_result_phase(10)};W.prototype.exec_version=function(){this.response_data[0]=144;this.enter_result_phase(1)};W.prototype.exec_part_id=function(){this.response_data[0]=65;this.enter_result_phase(1)};W.prototype.start_read_write=function(a,b){const c=this.set_curr_drive_no(a[0]&1),d=a[1],e=a[2],f=a[3];
|
|
452
|
-
0,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 3:this.end_read_write(64,128,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 1:this.status0|=32}const m=128<<(7<g?7:g);g=c.chs2lba(d,e,f)*m;if(128===m)b&&128>a&&l(!1,"dtl="+a+" is less than 128, zero-padding is still unimplemented!");else if(a=this.cmd_flags&1?(2*k-f+1)*m:(k-f+
|
|
453
|
-
d;this.response_data[4]=e;this.response_data[5]=f;return}this.eot=k;B("Floppy "+this.cmd_table[this.cmd_code].name+" from: "+n(g)+", length: "+n(a)+", C/H/S: "+d+"/"+e+"/"+f+", ro: "+c.read_only+", #S: "+c.max_sect+", #H: "+c.max_head,8192);b&&c.read_only?(this.end_read_write(96,2,0),this.response_data[3]=d,this.response_data[4]=e,this.response_data[5]=f):this.dor&8?(this.msr&=-129,
|
|
454
|
-
0,0)):(this.seek_next_sect(),this.end_read_write(0,0,0))})):l(!1,this.cmd_table[this.cmd_code].name+" in PIO mode not supported!")};W.prototype.end_read_write=function(a,b,c){const d=this.drives[this.curr_drive_no];this.status0&=-8;this.status0|=this.curr_drive_no;d.curr_head&&(this.status0|=4);this.status0|=a;this.msr|=192;this.msr&=-33;this.response_data[0]=this.status0;this.response_data[1]=
|
|
455
|
-
d.curr_sect;this.response_data[6]=2;this.enter_result_phase(7);this.raise_irq(this.cmd_table[this.cmd_code].name+" command")};W.prototype.seek_next_sect=function(){const a=this.drives[this.curr_drive_no];let b=a.curr_track,c=a.curr_head,d=a.curr_sect,e=1;d>=a.max_sect||d===this.eot?(d=1,this.cmd_flags&1?0===c&&2===a.max_head?c=1:(c=0,b++,this.status0|=32,1===a.max_head&&(e=0)):(this.status0|=
|
|
456
|
-
this.srb;a[21]=this.dor;a[22]=this.tdr;a[23]=this.msr;a[24]=this.dsr;a[25]=this.cmd_phase;a[26]=this.cmd_code;a[27]=this.cmd_flags;a[28]=this.cmd_buffer;a[29]=this.cmd_cursor;a[30]=this.cmd_remaining;a[31]=this.response_data;a[32]=this.response_cursor;a[33]=this.response_length;a[34]=this.status0;a[35]=this.status1;a[36]=this.curr_drive_no;a[37]=this.reset_sense_int_count;a[38]=this.locked;a[39]=
|
|
457
|
-
a[44]=this.drives[0].get_state();a[45]=this.drives[1].get_state();return a};W.prototype.set_state=function(a){"undefined"!==typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),
|
|
458
|
-
a[36],this.reset_sense_int_count=a[37],this.locked=a[38],this.step_rate_interval=a[39],this.head_load_time=a[40],this.fdc_config=a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};const Sc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,
|
|
459
|
-
heads:2},{drive_type:4,sectors:
|
|
460
|
-
sectors:10,tracks:
|
|
461
|
-
heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Rc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=
|
|
462
|
-
|
|
463
|
-
a.byteLength+" bytes",8192),!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);B("disk inserted into "+this.name+": type: "+d.drive_type+", C/H/S: "+d.tracks+"/"+d.heads+"/"+d.sectors+", size: "+c.byteLength,8192);return!0};Rc.prototype.eject_disk=function(){this.max_sect=
|
|
464
|
-
this.buffer.buffer:null};Rc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1};Rc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,k=-1,m=-1;for(let p=0;p<Sc.length;p++){const q=Sc[p],r=q.sectors*q.tracks*q.heads*512;if(d===r)if(c||q.drive_type===b){e=p;break}else c||Qc[q.drive_type]!==Qc[b]?g=-1===g?p:g:f
|
|
465
|
-
b.set(new Uint8Array(a.buffer)),[new Ba(b.buffer),Sc[k]]):[null,null]};Rc.prototype.seek=function(a,b,c){if(b>this.max_track||0!==a&&1===this.max_head)return B("WARNING: attempt to seek to invalid track: head: "+a+", track: "+b+", sect: "+c,8192),2;if(c>this.max_sect)return B("WARNING: attempt to seek beyond last sector: "+c+" (max: "+this.max_sect+")",8192),3;let d=0;
|
|
466
|
-
(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d};Rc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=
|
|
467
|
-
a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new Ba(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Tc={[8]:"DEVICE RESET",[144]:"EXECUTE DEVICE DIAGNOSTIC",[231]:"FLUSH CACHE",[234]:"FLUSH CACHE EXT",
|
|
468
|
-
[222]:"MEDIA LOCK",[0]:"NOP",[160]:"PACKET",[200]:"READ DMA",[37]:"READ DMA EXT",[41]:"READ MULTIPLE",[196]:"READ MULTIPLE EXT",[248]:"READ NATIVE MAX ADDRESS",[39]:"READ NATIVE MAX ADDRESS EXT",[32]:"READ SECTORS",[36]:"READ SECTORS EXT",[64]:"READ VERIFY SECTORS",[245]:"SECURITY FREEZE LOCK",[239]:"SET FEATURES",[249]:"SET MAX",[198]:"SET MULTIPLE MODE",[224]:"STANDBY IMMEDIATE",
|
|
469
|
-
[16]:"<UNKNOWN 10h>",[240]:"<VENDOR-SPECIFIC F0h>"},Uc={[70]:{name:"GET CONFIGURATION",flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},
|
|
470
|
-
[81]:{name:"READ DISK INFORMATION",flags:1},[66]:{name:"READ SUBCHANNEL",flags:1},[67]:{name:"READ TOC PMA ATIP",flags:1},[82]:{name:"READ TRACK INFORMATION",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function Vc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=
|
|
471
|
-
0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,g&255|1,g>>8,0,0,1,180,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,
|
|
472
|
-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[b?{size:8}:void 0,b?{size:1}:void 0,d?{size:8}:void 0,d?{size:1}:void 0,{size:16}];a.devices.pci.register_device(this)}Object.seal(this)}Vc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Vc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);
|
|
473
|
-
d;this.control_base=e;this.irq=f;this.name="ide"+b;d=c?c[0]:void 0;c=c?c[1]:void 0;this.master=new X(this,0,d?.buffer,d?.is_cdrom);this.slave=new X(this,1,c?.buffer,c?.is_cdrom);this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)},
|
|
474
|
-
|
|
475
|
-
255});a.io.register_read(this.command_base|6,this,function(){return this.current_interface.device_reg&255});a.io.register_read(this.command_base|7,this,function(){const g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)});
|
|
476
|
-
|
|
477
|
-
5,this,function(g){this.current_interface.lba_high_reg=(this.current_interface.lba_high_reg<<8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const k=g&16;if(k&&this.current_interface===this.master||!k&&this.current_interface===this.slave)k?(B(`${this.current_interface.name}: select slave device (${this.channel_nr?"secondary":"primary"})`,32768),this.current_interface=this.slave):(B(`${this.current_interface.name}: select master device (${this.channel_nr?
|
|
478
|
-
32768),this.current_interface=this.master);this.current_interface.device_reg=g;this.current_interface.is_lba=g>>6&1;this.current_interface.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);this.cpu.device_lower_irq(this.irq)});a.io.register_read(this.control_base|0,this,this.read_status);a.io.register_write(this.control_base|0,this,this.write_control);b=46080+8*b;a.io.register_read(b|
|
|
479
|
-
void 0,this.dma_read_command);a.io.register_write(b|0,this,this.dma_write_command8,void 0,this.dma_write_command);a.io.register_read(b|2,this,this.dma_read_status);a.io.register_write(b|2,this,this.dma_write_status);a.io.register_read(b|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(b|4,this,void 0,void 0,this.dma_set_addr);Object.seal(this)}Wc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:
|
|
480
|
-
function(a){a&4&&(B(`${this.current_interface.name}: soft reset via control port (lower IRQ ${this.irq})`,32768),this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};Wc.prototype.dma_read_addr=function(){return this.prdt_addr};Wc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Wc.prototype.dma_read_status=function(){return this.dma_status};Wc.prototype.dma_write_status=function(a){this.dma_status&=~(a&
|
|
481
|
-
function(){return this.dma_read_command8()|this.dma_read_status()<<16};Wc.prototype.dma_read_command8=function(){return this.dma_command};Wc.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};Wc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();
|
|
357
|
+
function(a){B("input: "+n(a),16384);this.input.push(a);this.lsr|=1;this.fifo_control&1?this.ThrowInterrupt(12):this.ThrowInterrupt(4)};zc.prototype.write_data=function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(B("data: "+n(a),16384),this.ThrowInterrupt(2),this.modem_control&16?this.data_received(a):this.bus.send("serial"+this.com+"-output-byte",a),a=String.fromCharCode(a),this.current_line+=a,"\n"===a&&(a=this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g,
|
|
358
|
+
""),B("SERIAL: "+a),this.current_line=""))};zc.prototype.set_modem_status=function(a){B("modem status: "+n(a),16384);const b=this.modem_status&15;let c=(this.modem_status^a)>>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function Ac(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);this.pci_addr32=new Int32Array(this.pci_addr.buffer);this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=
|
|
359
|
+
new Int32Array(this.pci_response.buffer);this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=a.io;a.io.register_write(3324,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],c)});a.io.register_write(3325,this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,
|
|
360
|
+
c)});a.io.register_write(3326,this,function(c){this.pci_write8(this.pci_addr32[0]+2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(3327,this,function(c){this.pci_write8(this.pci_addr32[0]+3|0,c)});a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});a.io.register_read_consecutive(3320,this,function(){return this.pci_status[0]},
|
|
361
|
+
function(){return this.pci_status[1]},function(){return this.pci_status[2]},function(){return this.pci_status[3]});a.io.register_write_consecutive(3320,this,function(c){this.pci_addr[0]=c&252},function(c){2===(this.pci_addr[1]&6)&&6===(c&6)?(B("CPU reboot via PCI"),a.reboot_internal()):this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,0,0,2,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
362
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=new Uint8Array(this.isa_bridge_space.buffer)}
|
|
363
|
+
Ac.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};Ac.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var f=d[4+e];if(f&1){var g=c.pci_bars[e];this.set_io_bars(g,g.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else c&&B("Warning: While restoring PCI device: Device exists in current configuration but not in snapshot ("+
|
|
364
|
+
c.name+")"),d&&B("Warning: While restoring PCI device: Device doesn't exist in current configuration but does in snapshot (device "+n(b,2)+")")}this.pci_addr.set(a[256]);this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};Ac.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+n(a,4));d+=" dev="+n(c,2);d+=" addr="+n(b,2);c=this.device_spaces[a];void 0!==c?(this.pci_status32[0]=
|
|
365
|
+
-2147483648,this.pci_response32[0]=b<c.byteLength?c[b>>2]:0,d+=" "+n(this.pci_addr32[0]>>>0,8)+" -> "+n(this.pci_response32[0]>>>0,8),b>=c.byteLength&&(d+=" (undef)"),d+=" ("+this.devices[a].name+")",B(d,2048)):(this.pci_response32[0]=-1,this.pci_status32[0]=0)};Ac.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(l(!(16<=a&&44>a||48<=a&&52>a),"PCI: Expected 32-bit write, got 8-bit (addr: "+n(a)+")"),B("PCI write8 dev="+
|
|
366
|
+
n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,2),2048),d[a]=b)};Ac.prototype.pci_write16=function(a,b){l(0===(a&1));var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(16<=a&&44>a?B("Warning: PCI: Expected 32-bit write, got 16-bit (addr: "+n(a)+")"):(l(!(48<=a&&52>a),"PCI: Expected 32-bit write, got 16-bit (addr: "+n(a)+")"),B("PCI writ16 dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,4),2048),d[a>>>1]=b))};Ac.prototype.pci_write32=
|
|
367
|
+
function(a,b){l(0===(a&3));var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){var f=a-16>>2,g=e.pci_bars[f];B("BAR"+f+" exists="+(g?"y":"n")+" changed from "+n(d[a>>2])+" to "+n(b>>>0)+" dev="+n(c>>3,2)+" ("+e.name+") ",2048);g?(l(!(g.size&g.size-1),"bar size should be power of 2"),c=a>>2,e=d[c]&1,-1===(b|3|g.size-1)?(b=~(g.size-1)|e,0===e&&(d[c]=b)):0===e&&(f=g.original_bar,(b&-16)!==(f&-16)&&B("Warning: Changing memory bar not supported, ignored",2048),d[c]=
|
|
368
|
+
f),1===e&&(l(1===e),e=d[c]&65534,f=b&65534,B("io bar changed from "+n(e>>>0,8)+" to "+n(f>>>0,8)+" size="+g.size,2048),this.set_io_bars(g,e,f),d[c]=b|1)):d[a>>2]=0;B("BAR effective value: "+n(d[a>>2]>>>0),2048)}else 48===a?(B("PCI write rom address dev="+n(c>>3,2)+" ("+e.name+") value="+n(b>>>0,8),2048),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?B("PCI write dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048):(B("PCI write dev="+n(c>>3,
|
|
369
|
+
2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048),d[a>>>2]=b)};Ac.prototype.register_device=function(a){l(void 0!==a.pci_id);l(void 0!==a.pci_space);l(void 0!==a.pci_bars);var b=a.pci_id;B("PCI register bdf="+n(b)+" ("+a.name+")",2048);this.devices[b]&&B("warning: overwriting device "+this.devices[b].name+" with "+a.name,2048);l(64<=a.pci_space.length);l(b<this.devices.length);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=
|
|
370
|
+
a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],g=f&1;B("device "+a.name+" register bar of size "+e.size+" at "+n(f),2048);e.original_bar=f;e.entries=[];if(0!==g)for(l(1===g),f&=-2,g=0;g<e.size;g++)e.entries[g]=this.io.ports[f+g]}}return c};Ac.prototype.set_io_bars=function(a,b,c){var d=a.size;B("Move io bars: from="+n(b)+" to="+n(c)+" count="+d,2048);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());var g=a.entries[f],
|
|
371
|
+
k=e[c+f];l(g&&k);4096<=c+f&&(e[c+f]=g)}};Ac.prototype.raise_irq=function(a){var b=this.device_spaces[a];l(b);this.cpu.device_raise_irq(this.isa_bridge_space8[96+((b[15]>>8&255)-1+((a>>3)-1&255)&3)])};Ac.prototype.lower_irq=function(a){var b=this.device_spaces[a];l(b);this.cpu.device_lower_irq(this.isa_bridge_space8[96+((b[15]>>8&255)+(a>>3&255)-2&3)])};function Bc(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(B("Replace mac in eth destination field",1048576),
|
|
372
|
+
a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(B("Replace mac in eth source field",1048576),a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d)if(a=a.subarray(14),d=a[0]>>4,4!==d)B("Expected ipv4.version==4 but got: "+d,1048576);else{if(l(5===(a[0]&15),"TODO: ihl!=5"),17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];B("udp srcport="+d+" dstport="+
|
|
373
|
+
e+" checksum="+n(a[6]<<8|a[7],4),1048576);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)B("dhcp packet didn't match magic: "+n(e,8));else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(B("Replace mac in dhcp.chaddr",1048576),d[28]=c[0],d[29]=c[1],d[30]=c[2],d[31]=c[3],d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const g=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===
|
|
374
|
+
b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(B("Replace mac in dhcp.clientidentifier",1048576),d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+6]=c[5],a[6]=a[7]=0);e+=g}}}else 2054===d&&(a=a.subarray(14),B("arp oper="+a[7]+" "+Cc(a.subarray(8,14))+" "+Cc(a.subarray(18,24)),1048576),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(B("Replace mac in arp.sha",1048576),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}
|
|
375
|
+
function Cc(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,"0"),a[5].toString(16).padStart(2,"0")].join(":")}function Dc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=768+256*this.id;this.name="ne2k";
|
|
376
|
+
this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+
|
|
377
|
+
this.id+"-mac",Cc(this.mac));this.mar=Uint8Array.of(255,255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;B("Mac: "+Cc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|0,this,function(){B("Read cmd",1048576);return this.cr},function(){B("Read16 cmd",1048576);return this.cr});b.register_write(this.port|
|
|
378
|
+
0,this,function(f){this.cr=f;B("Write command: "+n(f,2)+" newpg="+(this.cr>>6)+" txcr="+n(this.txcr,2),1048576);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),Bc(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),B("Command: Transfer. length="+n(f.byteLength),1048576)))});b.register_read(this.port|
|
|
379
|
+
13,this,function(){var f=this.get_page();if(1===f)return B("Read mar5",1048576),this.mar[5];B("Read counter0 pg="+f,1048576);return 0});b.register_read(this.port|14,this,function(){var f=this.get_page();if(1===f)return B("Read mar6",1048576),this.mar[6];B("Read8 counter1 pg="+f,1048576);return 0},function(){B("Read16 counter1 pg="+this.get_page(),1048576);return 0});b.register_read(this.port|15,this,function(){var f=this.get_page();if(1===f)return B("Read mar7",1048576),this.mar[7];B("Read counter2 pg="+
|
|
380
|
+
f,1048576);return 0});b.register_read(this.port|31,this,function(){this.get_page();B("Read reset",1048576);this.do_interrupt(128);return 0});b.register_write(this.port|31,this,function(f){this.get_page();B("Write reset: "+n(f,2),1048576)});b.register_read(this.port|1,this,function(){var f=this.get_page();if(0===f)return this.pstart;if(1===f)return B("Read pg1/01 (mac[0])",1048576),this.mac[0];if(2===f)return this.pstart;B("Read pg"+f+"/01");l(!1);return 0});b.register_write(this.port|1,this,function(f){var g=
|
|
381
|
+
this.get_page();0===g?(B("start page: "+n(f,2),1048576),this.pstart=f):1===g?(B("mac[0] = "+n(f),1048576),this.mac[0]=f):3===g?B("Unimplemented: Write pg3/01 (9346CR): "+n(f),1048576):(B("Write pg"+g+"/01: "+n(f),1048576),l(!1))});b.register_read(this.port|2,this,function(){var f=this.get_page();if(0===f)return this.pstop;if(1===f)return B("Read pg1/02 (mac[1])",1048576),this.mac[1];if(2===f)return this.pstop;B("Read pg"+f+"/02",1048576);l(!1);return 0});b.register_write(this.port|2,this,function(f){var g=
|
|
382
|
+
this.get_page();0===g?(B("stop page: "+n(f,2),1048576),f>this.memory.length>>8&&(f=this.memory.length>>8,B("XXX: Adjusting stop page to "+n(f),1048576)),this.pstop=f):1===g?(B("mac[1] = "+n(f),1048576),this.mac[1]=f):(B("Write pg"+g+"/02: "+n(f),1048576),l(!1))});b.register_read(this.port|7,this,function(){var f=this.get_page();if(0===f)return B("Read isr: "+n(this.isr,2),1048576),this.isr;if(1===f)return B("Read curpg: "+n(this.curpg,2),1048576),this.curpg;l(!1);return 0});b.register_write(this.port|
|
|
383
|
+
7,this,function(f){var g=this.get_page();0===g?(B("Write isr: "+n(f,2),1048576),this.isr&=~f,this.update_irq()):1===g?(B("Write curpg: "+n(f,2),1048576),this.curpg=f):l(!1)});b.register_write(this.port|13,this,function(f){var g=this.get_page();0===g?(this.txcr=f,B("Write tx config: "+n(f,2),1048576)):B("Unimplemented: Write pg"+g+"/0d "+n(f,2),1048576)});b.register_write(this.port|14,this,function(f){var g=this.get_page();0===g?(B("Write data configuration: "+n(f,2),1048576),this.dcfg=f):B("Unimplemented: Write pg"+
|
|
384
|
+
g+"/0e "+n(f,2),1048576)});b.register_read(this.port|10,this,function(){var f=this.get_page();if(0===f)return B("Read pg0/0a",1048576),80;if(1===f)return B("Read mar2",1048576),this.mar[2];l(!1,"TODO");return 0});b.register_write(this.port|10,this,function(f){var g=this.get_page();0===g?(B("Write remote byte count low: "+n(f,2),1048576),this.rcnt=this.rcnt&65280|f&255):B("Unimplemented: Write pg"+g+"/0a "+n(f,2),1048576)});b.register_read(this.port|11,this,function(){var f=this.get_page();if(0===
|
|
385
|
+
f)return B("Read pg0/0b",1048576),67;if(1===f)return B("Read mar3",1048576),this.mar[3];l(!1,"TODO");return 0});b.register_write(this.port|11,this,function(f){var g=this.get_page();0===g?(B("Write remote byte count high: "+n(f,2),1048576),this.rcnt=this.rcnt&255|f<<8&65280):B("Unimplemented: Write pg"+g+"/0b "+n(f,2),1048576)});b.register_read(this.port|8,this,function(){var f=this.get_page();if(0===f)return B("Read remote start address low",1048576),this.rsar&255;if(1===f)return B("Read mar0",1048576),
|
|
386
|
+
this.mar[0];B("Unimplemented: Read pg"+f+"/08",1048576);l(!1);return 0});b.register_write(this.port|8,this,function(f){var g=this.get_page();0===g?(B("Write remote start address low: "+n(f,2),1048576),this.rsar=this.rsar&65280|f&255):B("Unimplemented: Write pg"+g+"/08 "+n(f,2),1048576)});b.register_read(this.port|9,this,function(){var f=this.get_page();if(0===f)return B("Read remote start address high",1048576),this.rsar>>8&255;if(1===f)return B("Read mar1",1048576),this.mar[1];B("Unimplemented: Read pg"+
|
|
387
|
+
f+"/09",1048576);l(!1);return 0});b.register_write(this.port|9,this,function(f){var g=this.get_page();0===g?(B("Write remote start address low: "+n(f,2),1048576),this.rsar=this.rsar&255|f<<8&65280):B("Unimplemented: Write pg"+g+"/09 "+n(f,2),1048576)});b.register_write(this.port|15,this,function(f){var g=this.get_page();0===g?(B("Write interrupt mask register: "+n(f,2)+" isr="+n(this.isr,2),1048576),this.imr=f,this.update_irq()):B("Unimplemented: Write pg"+g+"/0f "+n(f,2),1048576)});b.register_read(this.port|
|
|
388
|
+
3,this,function(){var f=this.get_page();if(0===f)return B("Read boundary: "+n(this.boundary,2),1048576),this.boundary;if(1===f)return B("Read pg1/03 (mac[2])",1048576),this.mac[2];3===f?B("Unimplemented: Read pg3/03 (CONFIG0)",1048576):(B("Read pg"+f+"/03",1048576),l(!1));return 0});b.register_write(this.port|3,this,function(f){var g=this.get_page();0===g?(B("Write boundary: "+n(f,2),1048576),this.boundary=f):1===g?(B("mac[2] = "+n(f),1048576),this.mac[2]=f):(B("Write pg"+g+"/03: "+n(f),1048576),
|
|
389
|
+
l(!1))});b.register_read(this.port|4,this,function(){var f=this.get_page();if(0===f)return this.tsr;if(1===f)return B("Read pg1/04 (mac[3])",1048576),this.mac[3];B("Read pg"+f+"/04",1048576);l(!1);return 0});b.register_write(this.port|4,this,function(f){var g=this.get_page();0===g?(B("Write tpsr: "+n(f,2),1048576),this.tpsr=f):1===g?(B("mac[3] = "+n(f),1048576),this.mac[3]=f):(B("Write pg"+g+"/04: "+n(f),1048576),l(!1))});b.register_read(this.port|5,this,function(){var f=this.get_page();if(0===f)return B("Unimplemented: Read pg0/05 (NCR: Number of Collisions Register)",
|
|
390
|
+
1048576),0;if(1===f)return B("Read pg1/05 (mac[4])",1048576),this.mac[4];3===f?B("Unimplemented: Read pg3/05 (CONFIG2)",1048576):(B("Read pg"+f+"/05",1048576),l(!1));return 0});b.register_write(this.port|5,this,function(f){var g=this.get_page();0===g?(B("Write tcnt low: "+n(f,2),1048576),this.tcnt=this.tcnt&-256|f):1===g?(B("mac[4] = "+n(f),1048576),this.mac[4]=f):3===g?B("Unimplemented: Write pg3/05 (CONFIG2): "+n(f),1048576):(B("Write pg"+g+"/05: "+n(f),1048576),l(!1))});b.register_read(this.port|
|
|
391
|
+
6,this,function(){var f=this.get_page();if(0===f)return l(!1,"TODO"),0;if(1===f)return B("Read pg1/06 (mac[5])",1048576),this.mac[5];3===f?B("Unimplemented: Read pg3/06 (CONFIG3)",1048576):(B("Read pg"+f+"/06",1048576),l(!1));return 0});b.register_write(this.port|6,this,function(f){var g=this.get_page();0===g?(B("Write tcnt high: "+n(f,2),1048576),this.tcnt=this.tcnt&255|f<<8):1===g?(B("mac[5] = "+n(f),1048576),this.mac[5]=f):3===g?B("Unimplemented: Write pg3/06 (CONFIG3): "+n(f),1048576):(B("Write pg"+
|
|
392
|
+
g+"/06: "+n(f),1048576),l(!1))});b.register_read(this.port|12,this,function(){var f=this.get_page();if(0===f)return 9;if(1===f)return B("Read mar4",1048576),this.mar[4];B("Unimplemented: Read pg"+f+"/0c",1048576);l(!1);return 0});b.register_write(this.port|12,this,function(f){var g=this.get_page();0===g?(B("RX configuration reg write: "+n(f,2),1048576),this.rxcr=f):B("Unimplemented: Write pg"+g+"/0c: "+n(f),1048576)});b.register_read(this.port|16,this,this.data_port_read8,this.data_port_read16,this.data_port_read32);
|
|
393
|
+
b.register_write(this.port|16,this,this.data_port_write16,this.data_port_write16,this.data_port_write32);a.devices.pci.register_device(this)}Dc.prototype.get_state=function(){var a=[];a[0]=this.isr;a[1]=this.imr;a[2]=this.cr;a[3]=this.dcfg;a[4]=this.rcnt;a[5]=this.tcnt;a[6]=this.tpsr;a[7]=this.rsar;a[8]=this.pstart;a[9]=this.curpg;a[10]=this.boundary;a[11]=this.pstop;a[12]=this.rxcr;a[13]=this.txcr;a[14]=this.tsr;a[15]=this.mac;a[16]=this.memory;return a};Dc.prototype.set_state=function(a){this.isr=
|
|
394
|
+
a[0];this.imr=a[1];this.cr=a[2];this.dcfg=a[3];this.rcnt=a[4];this.tcnt=a[5];this.tpsr=a[6];this.rsar=a[7];this.pstart=a[8];this.curpg=a[9];this.boundary=a[10];this.pstop=a[11];this.rxcr=a[12];this.txcr=a[13];this.tsr=a[14];this.preserve_mac_from_state_image?(this.mac=a[15],this.memory=a[16]):this.mac_address_translation&&(this.mac_address_in_state=a[15],this.memory=a[16],B("Using mac address translation guest_os_mac="+Cc(this.mac_address_in_state)+" real_mac="+Cc(this.mac),1048576));this.bus.send("net"+
|
|
395
|
+
this.id+"-mac",Cc(this.mac))};Dc.prototype.do_interrupt=function(a){B("Do interrupt "+n(a,2),1048576);this.isr|=a;this.update_irq()};Dc.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};Dc.prototype.data_port_write=function(a){if(16>=this.rsar||16384<=this.rsar&&32768>this.rsar)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64)};Dc.prototype.data_port_write16=
|
|
396
|
+
function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};Dc.prototype.data_port_write32=function(a){this.data_port_write(a);this.data_port_write(a>>8);this.data_port_write(a>>16);this.data_port_write(a>>24)};Dc.prototype.data_port_read=function(){let a=0;32768>this.rsar&&(a=this.memory[this.rsar]);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64);return a};Dc.prototype.data_port_read8=function(){return this.data_port_read16()&
|
|
397
|
+
255};Dc.prototype.data_port_read16=function(){return this.dcfg&1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};Dc.prototype.data_port_read32=function(){return this.data_port_read()|this.data_port_read()<<8|this.data_port_read()<<16|this.data_port_read()<<24};Dc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-end",[a.length]),this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255===a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&
|
|
398
|
+
1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),Bc(a,this.mac,this.mac_address_in_state));var b=this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),f=b+c,g=1+(c>>8),k=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;k<g&&0!==this.boundary?B("Buffer full, dropping packet pstart="+n(this.pstart)+" pstop="+n(this.pstop)+
|
|
399
|
+
" curpg="+n(this.curpg)+" needed="+n(g)+" boundary="+n(this.boundary)+" available="+n(k),1048576):(f>this.pstop<<8?(l(60<=a.length),f=(this.pstop<<8)-d,l(0<=f),this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),B("rcv cut="+n(f),1048576)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,B("rcv offset="+n(b)+" len="+
|
|
400
|
+
n(c)+" next="+n(e),1048576),this.do_interrupt(1))}};Dc.prototype.get_page=function(){return this.cr>>6&3};function Ec(a,b){this.bus=b;this.rows=25;this.cols=80;this.ports=4;b=[{size_supported:16,notify_offset:0},{size_supported:16,notify_offset:1},{size_supported:16,notify_offset:2},{size_supported:16,notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Fc(a,{name:"virtio-console",pci_id:96,device_id:4163,
|
|
401
|
+
subsystem_device_id:3,common:{initial_port:47104,queues:b,features:[0,1,32],on_driver_ok:()=>{}},notification:{initial_port:47360,single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},c=>{if(2!==c)l(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 2)");else for(c=this.virtio.queues[c];c.count_requests()>
|
|
402
|
+
c.size-2;)c.pop_request()},c=>{if(3!==c)l(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 3)");else for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);e.get_next_blob(f);var g=J(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,
|
|
403
|
+
e);0===f&&this.SendWindowSize(f);break;default:l(!1," VirtioConsole received unknown event: "+g[1]);return}}}]},isr_status:{initial_port:46848},device_specific:{initial_port:46592,struct:[{bytes:2,name:"cols",read:()=>this.cols,write:()=>{}},{bytes:2,name:"rows",read:()=>this.rows,write:()=>{}},{bytes:4,name:"max_nr_ports",read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{l(!1,"Emergency write!")}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+
|
|
404
|
+
c+"-input-bytes",function(e){var f=this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&this.SendWindowSize(c,e[0],e[1])},this)}}Ec.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);I(["w","h","h",
|
|
405
|
+
"h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};Ec.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);I(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};Ec.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Ec.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=
|
|
406
|
+
a[3]};Ec.prototype.reset=function(){this.virtio.reset()};Ec.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);I(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};Ec.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Ec.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Gc(a,b){this.cpu=
|
|
407
|
+
a;this.bus=b;this.reset();this.bus.register("keyboard-code",function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=c[0];this.wheel_movement-=2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);
|
|
408
|
+
a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}Gc.prototype.reset=function(){this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=this.next_read_rate=this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=
|
|
409
|
+
new na(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new na(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1};Gc.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;
|
|
410
|
+
a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;a[15]=this.last_port60_byte;a[16]=this.sample_rate;a[17]=this.resolution;a[18]=this.scaling2;a[20]=this.command_register;a[21]=this.read_output_register;
|
|
411
|
+
a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};Gc.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=a[4];this.mouse_clicks=a[5];this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=
|
|
412
|
+
a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=a[18];this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;
|
|
413
|
+
this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",this.use_mouse)};Gc.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};Gc.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(B("Mouse irq",64),this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};Gc.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=
|
|
414
|
+
!1;this.command_register&1&&(B("Keyboard irq",64),this.cpu.device_lower_irq(1),this.cpu.device_raise_irq(1))};Gc.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(B("adding kbd code: "+n(a),64),this.kbd_buffer.push(a),this.raise_irq())};Gc.prototype.mouse_send_delta=function(a,b){this.have_mouse&&this.use_mouse&&(this.mouse_delta_x+=1*a,this.mouse_delta_y+=1*b,this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b))&&(this.mouse_delta_x-=a,this.mouse_delta_y-=
|
|
415
|
+
b,this.send_mouse_packet(a,b))};Gc.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))};Gc.prototype.send_mouse_packet=function(a,b){var c=(0>b)<<5|(0>a)<<4|8|this.mouse_clicks;this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&15),this.wheel_movement=0):3===this.mouse_id&&
|
|
416
|
+
(this.mouse_buffer.push(this.wheel_movement&255),this.wheel_movement=0);this.raise_irq()};Gc.prototype.apply_scaling2=function(a){var b=a>>31;switch(Math.abs(a)){case 0:case 1:case 3:return a;case 2:return b;case 4:return 6*b;case 5:return 9*b;default:return a<<1}};Gc.prototype.port60_read=function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return B("Port 60 read: Empty",64),this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),this.last_port60_byte=
|
|
417
|
+
this.mouse_buffer.shift(),B("Port 60 read (mouse): "+n(this.last_port60_byte),64)):(this.cpu.device_lower_irq(1),this.last_port60_byte=this.kbd_buffer.shift(),B("Port 60 read (kbd) : "+n(this.last_port60_byte),64));(this.kbd_buffer.length||this.mouse_buffer.length)&&this.raise_irq();return this.last_port60_byte};Gc.prototype.port64_read=function(){var a=16;this.next_byte_is_ready&&(a|=1);this.next_byte_is_aux&&(a|=32);B("port 64 read: "+n(a),64);return a};Gc.prototype.port60_write=function(a){B("port 60 write: "+
|
|
418
|
+
n(a),64);if(this.read_command_register)this.command_register=a,this.read_command_register=!1,B("Keyboard command register = "+n(this.command_register),64);else if(this.read_output_register)this.read_output_register=!1,this.mouse_buffer.clear(),this.mouse_buffer.push(a),this.mouse_irq();else if(this.next_read_sample){this.next_read_sample=!1;this.mouse_buffer.clear();this.mouse_buffer.push(250);this.sample_rate=a;switch(this.mouse_detect_state){case -1:60===a?(this.mouse_reset_workaround=!0,this.mouse_detect_state=
|
|
419
|
+
0):(this.mouse_reset_workaround=!1,this.mouse_detect_state=200===a?1:0);break;case 0:200===a&&(this.mouse_detect_state=1);break;case 1:this.mouse_detect_state=100===a?2:200===a?3:0;break;case 2:80===a&&(this.mouse_id=3);this.mouse_detect_state=-1;break;case 3:80===a&&(this.mouse_id=4),this.mouse_detect_state=-1}B("mouse sample rate: "+n(a)+", mouse id: "+n(this.mouse_id),64);this.sample_rate||(B("invalid sample rate, reset to 100",64),this.sample_rate=100);this.mouse_irq()}else if(this.next_read_resolution)this.next_read_resolution=
|
|
420
|
+
!1,this.mouse_buffer.clear(),this.mouse_buffer.push(250),3<a?(this.resolution=4,B("invalid resolution, resetting to 4",64)):(this.resolution=1<<a,B("resolution: "+this.resolution,64)),this.mouse_irq();else if(this.next_read_led)this.next_read_led=!1,this.kbd_buffer.push(250),this.kbd_irq();else if(this.next_handle_scan_code_set)this.next_handle_scan_code_set=!1,this.kbd_buffer.push(250),this.kbd_irq(),a||this.kbd_buffer.push(1);else if(this.next_read_rate)this.next_read_rate=!1,this.kbd_buffer.push(250),
|
|
421
|
+
this.kbd_irq();else if(this.next_is_mouse_command){if(this.next_is_mouse_command=!1,B("Port 60 data register write: "+n(a),64),this.have_mouse){this.kbd_buffer.clear();this.mouse_buffer.clear();this.mouse_buffer.push(250);switch(a){case 230:B("Scaling 1:1",64);this.scaling2=!1;break;case 231:B("Scaling 2:1",64);this.scaling2=!0;break;case 232:this.next_read_resolution=!0;break;case 233:this.send_mouse_packet(0,0);break;case 235:B("unimplemented request single packet",64);this.send_mouse_packet(0,
|
|
422
|
+
0);break;case 242:B("required id: "+n(this.mouse_id),64);this.mouse_buffer.push(this.mouse_id);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;this.raise_irq();break;case 243:this.next_read_sample=!0;break;case 244:this.use_mouse=this.enable_mouse_stream=!0;this.bus.send("mouse-enable",!0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;case 245:this.enable_mouse_stream=!1;break;case 246:this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;
|
|
423
|
+
break;case 255:B("Mouse reset",64);this.mouse_buffer.push(170);this.mouse_buffer.push(0);this.use_mouse=!0;this.bus.send("mouse-enable",!0);this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;this.mouse_reset_workaround||(this.mouse_id=0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;default:B("Unimplemented mouse command: "+n(a),64)}this.mouse_irq()}}else if(this.read_controller_output_port)this.read_controller_output_port=!1,this.controller_output_port=
|
|
424
|
+
a;else{B("Port 60 data register write: "+n(a),64);this.mouse_buffer.clear();this.kbd_buffer.clear();this.kbd_buffer.push(250);switch(a){case 237:this.next_read_led=!0;break;case 240:this.next_handle_scan_code_set=!0;break;case 242:this.kbd_buffer.push(171);this.kbd_buffer.push(131);break;case 243:this.next_read_rate=!0;break;case 244:B("kbd enable scanning",64);this.enable_keyboard_stream=!0;break;case 245:B("kbd disable scanning",64);this.enable_keyboard_stream=!1;break;case 246:break;case 255:this.kbd_buffer.clear();
|
|
425
|
+
this.kbd_buffer.push(250);this.kbd_buffer.push(170);this.kbd_buffer.push(0);break;default:B("Unimplemented keyboard command: "+n(a),64)}this.kbd_irq()}};Gc.prototype.port64_write=function(a){B("port 64 write: "+n(a),64);switch(a){case 32:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(this.command_register);this.kbd_irq();break;case 96:this.read_command_register=!0;break;case 209:this.read_controller_output_port=!0;break;case 211:this.read_output_register=!0;break;case 212:this.next_is_mouse_command=
|
|
426
|
+
!0;break;case 167:B("Disable second port",64);this.command_register|=32;break;case 168:B("Enable second port",64);this.command_register&=-33;break;case 169:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 170:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(85);this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:B("Disable Keyboard",64);this.command_register|=
|
|
427
|
+
16;break;case 174:B("Enable Keyboard",64);this.command_register&=-17;break;case 254:B("CPU reboot via PS2");this.cpu.reboot_internal();break;default:B("port 64: Unimplemented command byte: "+n(a),64)}};const Hc=DataView.prototype,Ic={size:1,get:Hc.getUint8,set:Hc.setUint8},Jc={size:2,get:Hc.getUint16,set:Hc.setUint16},Q={size:4,get:Hc.getUint32,set:Hc.setUint32},Lc=Kc([{magic:Q},{class:Ic},{data:Ic},{version0:Ic},{osabi:Ic},{abiversion:Ic},{pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:Jc},
|
|
428
|
+
{machine:Jc},{version1:Q},{entry:Q},{phoff:Q},{shoff:Q},{flags:Q},{ehsize:Jc},{phentsize:Jc},{phnum:Jc},{shentsize:Jc},{shnum:Jc},{shstrndx:Jc}]);console.assert(52===Lc.reduce((a,b)=>a+b.size,0));const Mc=Kc([{type:Q},{offset:Q},{vaddr:Q},{paddr:Q},{filesz:Q},{memsz:Q},{flags:Q},{align:Q}]);console.assert(32===Mc.reduce((a,b)=>a+b.size,0));const Nc=Kc([{name:Q},{type:Q},{flags:Q},{addr:Q},{offset:Q},{size:Q},{link:Q},{info:Q},{addralign:Q},{entsize:Q}]);console.assert(40===Nc.reduce((a,b)=>a+b.size,
|
|
429
|
+
0));function Kc(a){return a.map(function(b){var c=Object.keys(b);console.assert(1===c.length);c=c[0];b=b[c];console.assert(0<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}function Oc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Pc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,k]=Oc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=k}return[d,e]}const Qc={[0]:0,[1]:525,
|
|
430
|
+
[2]:525,[3]:350,[4]:350,[5]:350};function W(a,b,c,d){this.io=a.io;this.cpu=a;this.dma=a.devices.dma;this.cmd_table=this.build_cmd_lookup_table();this.sra=0;this.srb=192;this.dor=12;this.tdr=0;this.msr=128;this.dsr=0;this.cmd_phase=1;this.cmd_flags=this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=this.response_length=this.response_cursor=0;this.locked=
|
|
431
|
+
!1;this.head_load_time=this.step_rate_interval=0;this.fdc_config=96;this.eot=this.precomp_trk=0;this.drives=[new Rc("fda",d?.fda,b,4),new Rc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,this,this.read_reg_tdr);this.io.register_read(1012,this,
|
|
432
|
+
this.read_reg_msr);this.io.register_read(1013,this,this.read_reg_fifo);this.io.register_read(1015,this,this.read_reg_dir);this.io.register_write(1010,this,this.write_reg_dor);this.io.register_write(1011,this,this.write_reg_tdr);this.io.register_write(1012,this,this.write_reg_dsr);this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr);B("floppy controller ready",8192)}W.prototype.build_cmd_lookup_table=function(){const a=[{code:6,mask:31,argc:8,name:"READ",
|
|
433
|
+
handler:this.exec_read},{code:5,mask:63,argc:8,name:"WRITE",handler:this.exec_write},{code:15,mask:255,argc:2,name:"SEEK",handler:this.exec_seek},{code:8,mask:255,argc:0,name:"SENSE INTERRUPT STATUS",handler:this.exec_sense_interrupt_status},{code:7,mask:255,argc:1,name:"RECALIBRATE",handler:this.exec_recalibrate},{code:13,mask:191,argc:5,name:"FORMAT TRACK",handler:this.exec_format_track},{code:2,mask:191,argc:8,name:"READ TRACK",handler:this.exec_unimplemented},{code:78,mask:255,argc:17,name:"RESTORE",
|
|
434
|
+
handler:this.exec_unimplemented},{code:46,mask:255,argc:0,name:"SAVE",handler:this.exec_unimplemented},{code:12,mask:31,argc:8,name:"READ DELETED DATA",handler:this.exec_unimplemented},{code:17,mask:31,argc:8,name:"SCAN EQUAL",handler:this.exec_unimplemented},{code:22,mask:31,argc:8,name:"VERIFY",handler:this.exec_unimplemented},{code:25,mask:31,argc:8,name:"SCAN LOW OR EQUAL",handler:this.exec_unimplemented},{code:29,mask:31,argc:8,name:"SCAN HIGH OR EQUAL",handler:this.exec_unimplemented},{code:9,
|
|
435
|
+
mask:63,argc:8,name:"WRITE DELETED DATA",handler:this.exec_unimplemented},{code:10,mask:191,argc:1,name:"READ ID",handler:this.exec_read_id},{code:3,mask:255,argc:2,name:"SPECIFY",handler:this.exec_specify},{code:4,mask:255,argc:1,name:"SENSE DRIVE STATUS",handler:this.exec_sense_drive_status},{code:18,mask:255,argc:1,name:"PERPENDICULAR MODE",handler:this.exec_perpendicular_mode},{code:19,mask:255,argc:3,name:"CONFIGURE",handler:this.exec_configure},{code:23,mask:255,argc:2,name:"POWERDOWN MODE",
|
|
436
|
+
handler:this.exec_unimplemented},{code:51,mask:255,argc:1,name:"OPTION",handler:this.exec_unimplemented},{code:142,mask:255,argc:5,name:"DRIVE SPECIFICATION",handler:this.exec_unimplemented},{code:143,mask:255,argc:2,name:"RELATIVE SEEK OUT",handler:this.exec_unimplemented},{code:205,mask:255,argc:10,name:"FORMAT AND WRITE",handler:this.exec_unimplemented},{code:207,mask:255,argc:2,name:"RELATIVE SEEK IN",handler:this.exec_unimplemented},{code:20,mask:127,argc:0,name:"LOCK",handler:this.exec_lock},
|
|
437
|
+
{code:14,mask:255,argc:0,name:"DUMP REGISTERS",handler:this.exec_dump_regs},{code:16,mask:255,argc:0,name:"VERSION",handler:this.exec_version},{code:24,mask:255,argc:0,name:"PART ID",handler:this.exec_part_id},{code:0,mask:0,argc:0,name:"UNKNOWN COMMAND",handler:this.exec_unimplemented}],b=Array(256);for(let c=a.length-1;0<=c;c--){const d=a[c];if(255===d.mask)b[d.code]=d;else for(let e=0;256>e;e++)(e&d.mask)===d.code&&(b[e]=d)}return b};W.prototype.raise_irq=function(a){this.sra&128||(this.cpu.device_raise_irq(6),
|
|
438
|
+
this.sra|=128,B("IRQ raised, reason: "+a,8192));this.reset_sense_int_count=0};W.prototype.lower_irq=function(a){this.status0=0;this.sra&128&&(this.cpu.device_lower_irq(6),this.sra&=-129,B("IRQ lowered, reason: "+a,8192))};W.prototype.set_curr_drive_no=function(a){this.curr_drive_no=a&1;return this.drives[this.curr_drive_no]};W.prototype.enter_command_phase=function(){this.cmd_phase=1;this.cmd_remaining=this.cmd_cursor=0;this.msr&=-81;this.msr|=128};W.prototype.enter_result_phase=function(a){this.cmd_phase=
|
|
439
|
+
3;this.response_cursor=0;this.response_length=a;this.msr|=208};W.prototype.reset_fdc=function(){B("resetting controller",8192);this.lower_irq("controller reset");this.sra=0;this.srb=192;this.dor=12;this.msr=128;this.curr_drive_no=0;this.status0|=192;this.response_length=this.response_cursor=0;this.drives[0].seek(0,0,1);this.drives[1].seek(0,0,1);this.enter_command_phase();this.raise_irq("controller reset");this.reset_sense_int_count=4};W.prototype.read_reg_sra=function(){B("SRA read: "+n(this.sra),
|
|
440
|
+
8192);return this.sra};W.prototype.read_reg_srb=function(){B("SRB read: "+n(this.srb),8192);return this.srb};W.prototype.read_reg_dor=function(){const a=this.dor&-4|this.curr_drive_no;B("DOR read: "+n(a),8192);return a};W.prototype.read_reg_tdr=function(){B("TDR read: "+n(this.tdr),8192);return this.tdr};W.prototype.read_reg_msr=function(){B("MSR read: "+n(this.msr),8192);this.dsr&=-65;this.dor|=4;return this.msr};W.prototype.read_reg_fifo=function(){this.dsr&=-65;if(!(this.msr&128&&this.msr&64))return B("FIFO read rejected: controller not ready for reading",
|
|
441
|
+
8192),0;if(3!==this.cmd_phase)return B("FIFO read rejected: floppy controller not in RESULT phase, phase: "+this.cmd_phase,8192),0;if(this.response_cursor<this.response_length){const a=this.response_data[this.response_cursor++];if(this.response_cursor===this.response_length){const b="end of "+this.cmd_table[this.cmd_code].name+" response";this.msr&=-129;this.enter_command_phase();this.lower_irq(b)}return a}B("FIFO read: empty",8192);return 0};W.prototype.read_reg_dir=function(){const a=this.drives[this.curr_drive_no].media_changed?
|
|
442
|
+
128:0;B("DIR read: "+n(a),8192);return a};W.prototype.write_reg_dor=function(a){this.srb=this.srb&-36|(a&16?1:0)|(a&32?2:0)|(a&1?32:0);this.dor&4?a&4||B("enter RESET state",8192):a&4&&(this.reset_fdc(),this.dsr&=-65,B("exit RESET state",8192));const b=a&3;B("DOR write: "+n(a)+", motors: "+n(a>>4)+", dma: "+!!(a&8)+", reset: "+!(a&4)+", drive: "+b,8192);1<b&&B("*** WARNING: floppy drive number "+b+" not implemented!",8192);this.curr_drive_no=b&1;this.dor=a};W.prototype.write_reg_tdr=function(a){this.dor&
|
|
443
|
+
4?(B("TDR write: "+n(a),8192),this.tdr=a&4):B("TDR write "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.write_reg_dsr=function(a){this.dor&4?(B("DSR write: "+n(a),8192),a&128&&(this.dor&=-5,this.reset_fdc(),this.dor|=4),a&64&&this.reset_fdc(),this.dsr=a):B("DSR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.write_reg_fifo=function(a){this.dsr&=-65;if(this.dor&4)if(!(this.msr&128)||this.msr&64)B("FIFO write "+n(a)+" rejected: controller not ready for writing",
|
|
444
|
+
8192);else if(1!==this.cmd_phase)B("FIFO write "+n(a)+" rejected: floppy controller not in COMMAND phase, phase: "+this.cmd_phase,8192);else{if(0===this.cmd_remaining){var b=this.cmd_table[a];this.cmd_code=a;this.cmd_remaining=b.argc;this.cmd_flags=this.cmd_cursor=0;(6===b.code||5===b.code)&&this.cmd_code&128&&(this.cmd_flags|=1);this.cmd_remaining&&(this.msr|=128);this.msr|=16}else this.cmd_buffer[this.cmd_cursor++]=a,this.cmd_remaining--;if(0===this.cmd_remaining){this.cmd_phase=2;a=this.cmd_table[this.cmd_code];
|
|
445
|
+
b=this.cmd_buffer.slice(0,this.cmd_cursor);const c=[];for(const d of b)c.push(n(d,2));B("FD command "+n(this.cmd_code)+": "+a.name+"("+c.join(", ")+")",8192);a.handler.call(this,b)}}else B("FIFO write "+n(a)+" rejected: floppy controller in RESET mode!",8192)};W.prototype.write_reg_ccr=function(a){this.dor&4?(B("CCR write: "+n(a),8192),this.dsr=this.dsr&-4|a&3):B("CCR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.exec_unimplemented=function(){l(!1,"Unimplemented floppy command code "+
|
|
446
|
+
n(this.cmd_code)+"!");this.status0=128;this.response_data[0]=this.status0;this.enter_result_phase(1)};W.prototype.exec_read=function(a){this.start_read_write(a,!1)};W.prototype.exec_write=function(a){this.start_read_write(a,!0)};W.prototype.exec_seek=function(a){const b=this.set_curr_drive_no(a[0]&1);a=a[1];this.enter_command_phase();b.seek(b.curr_head,a,b.curr_sect);this.status0|=32;this.raise_irq("SEEK command")};W.prototype.exec_sense_interrupt_status=function(){const a=this.drives[this.curr_drive_no];
|
|
447
|
+
let b;if(0<this.reset_sense_int_count)b=192|4-this.reset_sense_int_count--;else if(this.sra&128)b=this.status0&-8|this.curr_drive_no;else{B("No interrupt pending, aborting SENSE INTERRUPT command!",8192);this.response_data[0]=128;this.enter_result_phase(1);return}this.response_data[0]=b;this.response_data[1]=a.curr_track;this.enter_result_phase(2);this.lower_irq("SENSE INTERRUPT command");this.status0=192};W.prototype.exec_recalibrate=function(a){this.set_curr_drive_no(a[0]&1).seek(0,0,1);this.enter_command_phase();
|
|
448
|
+
this.status0|=32;this.raise_irq("RECALIBRATE command")};W.prototype.exec_format_track=function(a){let b=0,c=0;this.set_curr_drive_no(a[0]&1).read_only&&(b=96,c=2);this.end_read_write(b,c,0)};W.prototype.exec_read_id=function(a){const b=this.drives[this.curr_drive_no];b.curr_head=a[0]>>2&1;0!==b.max_sect&&(b.curr_sect=b.curr_sect%b.max_sect+1);this.end_read_write(0,0,0)};W.prototype.exec_specify=function(a){const b=a[1];this.step_rate_interval=a[0]>>4;this.head_load_time=b>>1;this.dor=b&1?this.dor&
|
|
449
|
+
-9:this.dor|8;this.enter_command_phase()};W.prototype.exec_sense_drive_status=function(a){a=a[0];const b=this.set_curr_drive_no(a&1);b.curr_head=a>>2&1;this.response_data[0]=(b.read_only?64:0)|(0===b.curr_track?16:0)|b.curr_head<<2|this.curr_drive_no|40;this.enter_result_phase(1)};W.prototype.exec_perpendicular_mode=function(a){a=a[0];a&128&&(this.drives[this.curr_drive_no].perpendicular=a&7);this.enter_command_phase()};W.prototype.exec_configure=function(a){this.fdc_config=a[1];this.precomp_trk=
|
|
450
|
+
a[2];this.enter_command_phase()};W.prototype.exec_lock=function(){this.cmd_code&128?(this.locked=!0,this.response_data[0]=16):(this.locked=!1,this.response_data[0]=0);this.enter_result_phase(1)};W.prototype.exec_dump_regs=function(){const a=this.drives[this.curr_drive_no];this.response_data[0]=this.drives[0].curr_track;this.response_data[1]=this.drives[1].curr_track;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=this.step_rate_interval;this.response_data[5]=this.head_load_time<<
|
|
451
|
+
1|(this.dor&8?1:0);this.response_data[6]=a.max_sect;this.response_data[7]=(this.locked?128:0)|a.perpendicular<<2;this.response_data[8]=this.fdc_config;this.response_data[9]=this.precomp_trk;this.enter_result_phase(10)};W.prototype.exec_version=function(){this.response_data[0]=144;this.enter_result_phase(1)};W.prototype.exec_part_id=function(){this.response_data[0]=65;this.enter_result_phase(1)};W.prototype.start_read_write=function(a,b){const c=this.set_curr_drive_no(a[0]&1),d=a[1],e=a[2],f=a[3];
|
|
452
|
+
var g=a[4];const k=a[5];a=128>a[7]?a[7]:128;switch(c.seek(e,d,f)){case 2:this.end_read_write(64,0,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 3:this.end_read_write(64,128,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 1:this.status0|=32}const m=128<<(7<g?7:g);g=c.chs2lba(d,e,f)*m;if(128===m)b&&128>a&&l(!1,"dtl="+a+" is less than 128, zero-padding is still unimplemented!");else if(a=this.cmd_flags&1?(2*k-f+1)*m:(k-f+
|
|
453
|
+
1)*m,0>=a){B("invalid data_length: "+a+" sect="+f+" eot="+k,8192);this.end_read_write(64,1,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return}this.eot=k;B("Floppy "+this.cmd_table[this.cmd_code].name+" from: "+n(g)+", length: "+n(a)+", C/H/S: "+d+"/"+e+"/"+f+", ro: "+c.read_only+", #S: "+c.max_sect+", #H: "+c.max_head,8192);b&&c.read_only?(this.end_read_write(96,2,0),this.response_data[3]=d,this.response_data[4]=e,this.response_data[5]=f):this.dor&8?(this.msr&=-129,
|
|
454
|
+
(b?this.dma.do_write:this.dma.do_read).call(this.dma,c.buffer,g,a,2,p=>{p?(B("DMA floppy error",8192),this.end_read_write(64,0,0)):(this.seek_next_sect(),this.end_read_write(0,0,0))})):l(!1,this.cmd_table[this.cmd_code].name+" in PIO mode not supported!")};W.prototype.end_read_write=function(a,b,c){const d=this.drives[this.curr_drive_no];this.status0&=-8;this.status0|=this.curr_drive_no;d.curr_head&&(this.status0|=4);this.status0|=a;this.msr|=192;this.msr&=-33;this.response_data[0]=this.status0;this.response_data[1]=
|
|
455
|
+
b;this.response_data[2]=c;this.response_data[3]=d.curr_track;this.response_data[4]=d.curr_head;this.response_data[5]=d.curr_sect;this.response_data[6]=2;this.enter_result_phase(7);this.raise_irq(this.cmd_table[this.cmd_code].name+" command")};W.prototype.seek_next_sect=function(){const a=this.drives[this.curr_drive_no];let b=a.curr_track,c=a.curr_head,d=a.curr_sect,e=1;d>=a.max_sect||d===this.eot?(d=1,this.cmd_flags&1?0===c&&2===a.max_head?c=1:(c=0,b++,this.status0|=32,1===a.max_head&&(e=0)):(this.status0|=
|
|
456
|
+
32,b++,e=0)):d++;a.seek(c,b,d);return e};W.prototype.get_state=function(){const a=[];a[19]=this.sra;a[20]=this.srb;a[21]=this.dor;a[22]=this.tdr;a[23]=this.msr;a[24]=this.dsr;a[25]=this.cmd_phase;a[26]=this.cmd_code;a[27]=this.cmd_flags;a[28]=this.cmd_buffer;a[29]=this.cmd_cursor;a[30]=this.cmd_remaining;a[31]=this.response_data;a[32]=this.response_cursor;a[33]=this.response_length;a[34]=this.status0;a[35]=this.status1;a[36]=this.curr_drive_no;a[37]=this.reset_sense_int_count;a[38]=this.locked;a[39]=
|
|
457
|
+
this.step_rate_interval;a[40]=this.head_load_time;a[41]=this.fdc_config;a[42]=this.precomp_trk;a[43]=this.eot;a[44]=this.drives[0].get_state();a[45]=this.drives[1].get_state();return a};W.prototype.set_state=function(a){"undefined"!==typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),
|
|
458
|
+
this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.status1=a[35],this.curr_drive_no=a[36],this.reset_sense_int_count=a[37],this.locked=a[38],this.step_rate_interval=a[39],this.head_load_time=a[40],this.fdc_config=a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};const Sc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,
|
|
459
|
+
sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,sectors:44,tracks:80,heads:2},{drive_type:5,sectors:48,tracks:80,heads:2},{drive_type:4,sectors:8,tracks:80,heads:2},{drive_type:4,sectors:9,tracks:80,
|
|
460
|
+
heads:2},{drive_type:4,sectors:10,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:82,heads:2},{drive_type:4,sectors:10,tracks:83,heads:2},{drive_type:4,sectors:13,tracks:80,heads:2},{drive_type:4,sectors:14,tracks:80,heads:2},{drive_type:2,sectors:15,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:82,heads:2},{drive_type:2,sectors:18,tracks:83,heads:2},{drive_type:2,sectors:20,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:80,heads:2},{drive_type:2,
|
|
461
|
+
sectors:11,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:40,heads:2},{drive_type:2,sectors:9,tracks:40,heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Rc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=
|
|
462
|
+
this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d);B("floppy drive "+this.name+" ready, drive type: "+this.drive_type,8192)}Rc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new Ba(a.buffer));const [c,d]=this.find_disk_format(a,
|
|
463
|
+
this.drive_type);if(!c)return B("WARNING: disk rejected, no suitable disk format found for image of size "+a.byteLength+" bytes",8192),!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);B("disk inserted into "+this.name+": type: "+d.drive_type+", C/H/S: "+d.tracks+"/"+d.heads+"/"+d.sectors+", size: "+c.byteLength,8192);return!0};Rc.prototype.eject_disk=function(){this.max_sect=
|
|
464
|
+
this.max_head=this.max_track=0;this.media_changed=!0;this.buffer=null};Rc.prototype.get_buffer=function(){return this.buffer?this.buffer.buffer:null};Rc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1};Rc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,k=-1,m=-1;for(let p=0;p<Sc.length;p++){const q=Sc[p],r=q.sectors*q.tracks*q.heads*512;if(d===r)if(c||q.drive_type===b){e=p;break}else c||Qc[q.drive_type]!==Qc[b]?g=-1===g?p:g:f=
|
|
465
|
+
-1===f?p:f;else d<r&&(-1===m||r<m)&&(k=p,m=r)}return-1!==e?[a,Sc[e]]:-1!==f?[a,Sc[f]]:-1!==g?[a,Sc[g]]:-1!==k?(b=new Uint8Array(m),b.set(new Uint8Array(a.buffer)),[new Ba(b.buffer),Sc[k]]):[null,null]};Rc.prototype.seek=function(a,b,c){if(b>this.max_track||0!==a&&1===this.max_head)return B("WARNING: attempt to seek to invalid track: head: "+a+", track: "+b+", sect: "+c,8192),2;if(c>this.max_sect)return B("WARNING: attempt to seek beyond last sector: "+c+" (max: "+this.max_sect+")",8192),3;let d=0;
|
|
466
|
+
const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d};Rc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=
|
|
467
|
+
this.buffer?this.buffer.get_state():null;return a};Rc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new Ba(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Tc={[8]:"DEVICE RESET",[144]:"EXECUTE DEVICE DIAGNOSTIC",[231]:"FLUSH CACHE",[234]:"FLUSH CACHE EXT",
|
|
468
|
+
[218]:"GET MEDIA STATUS",[236]:"IDENTIFY DEVICE",[161]:"IDENTIFY PACKET DEVICE",[225]:"IDLE IMMEDIATE",[145]:"INITIALIZE DEVICE PARAMETERS",[222]:"MEDIA LOCK",[0]:"NOP",[160]:"PACKET",[200]:"READ DMA",[37]:"READ DMA EXT",[41]:"READ MULTIPLE",[196]:"READ MULTIPLE EXT",[248]:"READ NATIVE MAX ADDRESS",[39]:"READ NATIVE MAX ADDRESS EXT",[32]:"READ SECTORS",[36]:"READ SECTORS EXT",[64]:"READ VERIFY SECTORS",[245]:"SECURITY FREEZE LOCK",[239]:"SET FEATURES",[249]:"SET MAX",[198]:"SET MULTIPLE MODE",[224]:"STANDBY IMMEDIATE",
|
|
469
|
+
[202]:"WRITE DMA",[53]:"WRITE DMA EXT",[57]:"WRITE MULTIPLE",[197]:"WRITE MULTIPLE EXT",[48]:"WRITE SECTORS",[52]:"WRITE SECTORS EXT",[16]:"<UNKNOWN 10h>",[240]:"<VENDOR-SPECIFIC F0h>"},Uc={[70]:{name:"GET CONFIGURATION",flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},
|
|
470
|
+
[40]:{name:"READ (10)",flags:1},[168]:{name:"READ (12)",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},[81]:{name:"READ DISK INFORMATION",flags:1},[66]:{name:"READ SUBCHANNEL",flags:1},[67]:{name:"READ TOC PMA ATIP",flags:1},[82]:{name:"READ TRACK INFORMATION",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function Vc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=
|
|
471
|
+
c&&c[1][0];if(b||d){b&&(this.primary=new Wc(this,0,c[0],496,1014,14));d&&(this.secondary=new Wc(this,1,c[1],368,886,15));c=b?this.primary.command_base:0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,g&255|1,g>>8,0,0,1,180,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,
|
|
472
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[b?{size:8}:void 0,b?{size:1}:void 0,d?{size:8}:void 0,d?{size:1}:void 0,{size:16}];a.devices.pci.register_device(this)}Object.seal(this)}Vc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Vc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);
|
|
473
|
+
this.secondary&&this.secondary.set_state(a[1])};function Wc(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=d;this.control_base=e;this.irq=f;this.name="ide"+b;d=c?c[0]:void 0;c=c?c[1]:void 0;this.master=new X(this,0,d?.buffer,d?.is_cdrom);this.slave=new X(this,1,c?.buffer,c?.is_cdrom);this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)},
|
|
474
|
+
function(){return this.current_interface.read_data(2)},function(){return this.current_interface.read_data(4)});a.io.register_read(this.command_base|1,this,function(){return this.current_interface.error_reg&255});a.io.register_read(this.command_base|2,this,function(){return this.current_interface.sector_count_reg&255});a.io.register_read(this.command_base|3,this,function(){return this.current_interface.lba_low_reg&255});a.io.register_read(this.command_base|4,this,function(){return this.current_interface.lba_mid_reg&
|
|
475
|
+
255});a.io.register_read(this.command_base|5,this,function(){return this.current_interface.lba_high_reg&255});a.io.register_read(this.command_base|6,this,function(){return this.current_interface.device_reg&255});a.io.register_read(this.command_base|7,this,function(){const g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)});
|
|
476
|
+
a.io.register_write(this.command_base|1,this,function(g){this.current_interface.features_reg=(this.current_interface.features_reg<<8|g)&65535});a.io.register_write(this.command_base|2,this,function(g){this.current_interface.sector_count_reg=(this.current_interface.sector_count_reg<<8|g)&65535});a.io.register_write(this.command_base|3,this,function(g){this.current_interface.lba_low_reg=(this.current_interface.lba_low_reg<<8|g)&65535});a.io.register_write(this.command_base|4,this,function(g){this.current_interface.lba_mid_reg=
|
|
477
|
+
(this.current_interface.lba_mid_reg<<8|g)&65535});a.io.register_write(this.command_base|5,this,function(g){this.current_interface.lba_high_reg=(this.current_interface.lba_high_reg<<8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const k=g&16;if(k&&this.current_interface===this.master||!k&&this.current_interface===this.slave)k?(B(`${this.current_interface.name}: select slave device (${this.channel_nr?"secondary":"primary"})`,32768),this.current_interface=this.slave):(B(`${this.current_interface.name}: select master device (${this.channel_nr?
|
|
478
|
+
"secondary":"primary"})`,32768),this.current_interface=this.master);this.current_interface.device_reg=g;this.current_interface.is_lba=g>>6&1;this.current_interface.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);this.cpu.device_lower_irq(this.irq)});a.io.register_read(this.control_base|0,this,this.read_status);a.io.register_write(this.control_base|0,this,this.write_control);b=46080+8*b;a.io.register_read(b|
|
|
479
|
+
0,this,this.dma_read_command8,void 0,this.dma_read_command);a.io.register_write(b|0,this,this.dma_write_command8,void 0,this.dma_write_command);a.io.register_read(b|2,this,this.dma_read_status);a.io.register_write(b|2,this,this.dma_write_status);a.io.register_read(b|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(b|4,this,void 0,void 0,this.dma_set_addr);Object.seal(this)}Wc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:
|
|
480
|
+
0};Wc.prototype.write_control=function(a){a&4&&(B(`${this.current_interface.name}: soft reset via control port (lower IRQ ${this.irq})`,32768),this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};Wc.prototype.dma_read_addr=function(){return this.prdt_addr};Wc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Wc.prototype.dma_read_status=function(){return this.dma_status};Wc.prototype.dma_write_status=function(a){this.dma_status&=~(a&
|
|
481
|
+
6)};Wc.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};Wc.prototype.dma_read_command8=function(){return this.dma_command};Wc.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};Wc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();
|
|
482
482
|
break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:B(this.current_interface.name+": spurious DMA command write, current command: "+n(this.current_interface.current_command),32768),B(this.current_interface.name+": DMA clear status bit 1h, set status bit 2h",32768),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}};Wc.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};
|
|
483
483
|
Wc.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.command_base;a[3]=this.irq;a[5]=this.control_base;a[7]=this.name;a[8]=this.device_control_reg;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};Wc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.command_base=a[2];this.irq=a[3];this.control_base=a[5];this.name=a[7];this.device_control_reg=a[8];this.prdt_addr=
|
|
484
484
|
a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]};function X(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;this.interface_nr=b;this.cpu=a.cpu;this.buffer=null;this.drive_connected=d||!!c;this.sector_size=d?2048:512;this.is_atapi=d;this.sector_count=0;this.head_count=this.is_atapi?1:0;this.device_reg=this.head=this.lba_high_reg=this.lba_mid_reg=this.features_reg=this.lba_low_reg=this.sector_count_reg=
|
package/build/libv86.js
CHANGED
|
@@ -340,9 +340,9 @@ M.prototype.get_instruction_stats=function(){var a=this.v86.cpu;var b="";var c="
|
|
|
340
340
|
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[fb(a,!1,!1,!1,!1),fb(a,!0,!1,!1,!1),fb(a,!1,!0,!1,!1),fb(a,!1,
|
|
341
341
|
!1,!0,!1),fb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function sc(a){this.message=a||"File not found"}sc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=M:"undefined"!==typeof window?window.V86=M:"function"===typeof importScripts&&(self.V86=M);function E(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new O(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}E.prototype.run=function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};E.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_loop();this.next_tick(a)}};
|
|
342
342
|
E.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};E.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};E.prototype.stop=function(){this.running&&(this.stopping=!0)};E.prototype.destroy=function(){this.unregister_yield()};E.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};E.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};
|
|
343
|
-
if("undefined"!==typeof process)E.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};else if(
|
|
344
|
-
E.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}E.prototype.register_yield=function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};E.prototype.yield=
|
|
345
|
-
c){this.worker.postMessage({t:b,tick:c})};E.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else E.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};
|
|
343
|
+
if("undefined"!==typeof process)E.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};else if(globalThis.scheduler&&"function"===typeof globalThis.scheduler.postTask&&location.href.includes("use-scheduling-api"))E.prototype.yield=function(a,b){a=Math.max(0,a);globalThis.scheduler.postTask(()=>this.yield_callback(b),{delay:a})},E.prototype.register_yield=
|
|
344
|
+
function(){},E.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}E.prototype.register_yield=function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};E.prototype.yield=
|
|
345
|
+
function(b,c){this.worker.postMessage({t:b,tick:c})};E.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else E.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};
|
|
346
346
|
E.prototype.save_state=function(){for(var a=[],b=cb(this.cpu,a),c=[],d=0,e=0;e<a.length;e++){var f=a[e].byteLength;c[e]={offset:d,length:f};d+=f;d=d+3&-4}e=JSON.stringify({buffer_infos:c,state:b});e=(new TextEncoder).encode(e);b=16+e.length;b=b+3&-4;f=b+d;d=new ArrayBuffer(f);var g=new Int32Array(d,0,4);(new Uint8Array(d,16,e.length)).set(e);b=new Uint8Array(d,b);g[0]=-2039052682;g[1]=6;g[2]=f;g[3]=e.length;for(e=0;e<a.length;e++)b.set(a[e],c[e].offset);return d};
|
|
347
347
|
E.prototype.restore_state=function(a){return eb(this.cpu,a)};if("object"===typeof performance&&performance.now)E.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");E.microtick=a.now.bind(a)}else E.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;function tc(a){this.cpu=a;var b=a.io;a.devices.pci.register_device({pci_id:56,pci_space:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0],pci_bars:[],name:"acpi"});this.timer_imprecision_offset=this.timer_last_value=0;this.status=1;this.pm1_enable=this.pm1_status=0;this.last_timer=this.get_timer(E.microtick());this.gpe=new Uint8Array(4);b.register_read(45056,this,void 0,function(){return this.pm1_status});
|
|
348
348
|
b.register_write(45056,this,void 0,function(c){z(c,4);this.pm1_status&=~c});b.register_read(45058,this,void 0,function(){return this.pm1_enable});b.register_write(45058,this,void 0,function(c){z(c);this.pm1_enable=c});b.register_read(45060,this,function(){return this.status&255},function(){return this.status});b.register_write(45060,this,void 0,function(c){z(c);this.status=c});b.register_read(45064,this,void 0,void 0,function(){return this.get_timer(E.microtick())&16777215});b.register_read(45024,
|
|
@@ -357,7 +357,7 @@ this.ier=d&15,z(d),this.CheckInterrupt())});a.register_read(b,this,function(){if
|
|
|
357
357
|
return this.modem_status&=240});a.register_write(b|6,this,function(d){z(d);this.set_modem_status(d)});a.register_read(b|7,this,function(){return this.scratch_register});a.register_write(b|7,this,function(d){this.scratch_register=d})}uc.prototype.get_state=function(){var a=[];a[0]=this.ints;a[1]=this.baud_rate;a[2]=this.line_control;a[3]=this.lsr;a[4]=this.fifo_control;a[5]=this.ier;a[6]=this.iir;a[7]=this.modem_control;a[8]=this.modem_status;a[9]=this.scratch_register;a[10]=this.irq;return a};
|
|
358
358
|
uc.prototype.set_state=function(a){this.ints=a[0];this.baud_rate=a[1];this.line_control=a[2];this.lsr=a[3];this.fifo_control=a[4];this.ier=a[5];this.iir=a[6];this.modem_control=a[7];this.modem_status=a[8];this.scratch_register=a[9];this.irq=a[10]};
|
|
359
359
|
uc.prototype.CheckInterrupt=function(){this.ints&4096&&this.ier&1?(this.iir=12,this.cpu.device_raise_irq(this.irq)):this.ints&16&&this.ier&1?(this.iir=4,this.cpu.device_raise_irq(this.irq)):this.ints&4&&this.ier&2?(this.iir=2,this.cpu.device_raise_irq(this.irq)):this.ints&1&&this.ier&8?(this.iir=0,this.cpu.device_raise_irq(this.irq)):(this.iir=1,this.cpu.device_lower_irq(this.irq))};uc.prototype.ThrowInterrupt=function(a){this.ints|=1<<a;this.CheckInterrupt()};
|
|
360
|
-
uc.prototype.ClearInterrupt=function(a){this.ints&=~(1<<a);this.CheckInterrupt()};uc.prototype.data_received=function(a){z(a);this.input.push(a);this.lsr|=1;this.fifo_control&1?this.ThrowInterrupt(12):this.ThrowInterrupt(4)};uc.prototype.write_data=function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(z(a),this.ThrowInterrupt(2),this.bus.send("serial"+this.com+"-output-byte",a))};
|
|
360
|
+
uc.prototype.ClearInterrupt=function(a){this.ints&=~(1<<a);this.CheckInterrupt()};uc.prototype.data_received=function(a){z(a);this.input.push(a);this.lsr|=1;this.fifo_control&1?this.ThrowInterrupt(12):this.ThrowInterrupt(4)};uc.prototype.write_data=function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(z(a),this.ThrowInterrupt(2),this.modem_control&16?this.data_received(a):this.bus.send("serial"+this.com+"-output-byte",a))};
|
|
361
361
|
uc.prototype.set_modem_status=function(a){z(a);const b=this.modem_status&15;let c=(this.modem_status^a)>>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function vc(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);this.pci_addr32=new Int32Array(this.pci_addr.buffer);this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=new Int32Array(this.pci_response.buffer);this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=
|
|
362
362
|
a.io;a.io.register_write(3324,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],c)});a.io.register_write(3325,this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,c)});a.io.register_write(3326,this,function(c){this.pci_write8(this.pci_addr32[0]+2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(3327,this,function(c){this.pci_write8(this.pci_addr32[0]+3|0,c)});
|
|
363
363
|
a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});a.io.register_read_consecutive(3320,this,function(){return this.pci_status[0]},function(){return this.pci_status[1]},function(){return this.pci_status[2]},function(){return this.pci_status[3]});a.io.register_write_consecutive(3320,this,function(c){this.pci_addr[0]=c&252},function(c){2===(this.pci_addr[1]&
|
package/build/libv86.mjs
CHANGED
|
@@ -302,8 +302,8 @@ d=0;const e={};for(let g=0;g<c.length;g++){const h=c[g];var f=void 0;if(h.includ
|
|
|
302
302
|
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[fb(a,!1,!1,!1,!1),fb(a,!0,!1,!1,!1),fb(a,!1,!0,!1,!1),fb(a,!1,
|
|
303
303
|
!1,!0,!1),fb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function sc(a){this.message=a||"File not found"}sc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=M:"undefined"!==typeof window?window.V86=M:"function"===typeof importScripts&&(self.V86=M);function E(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new O(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}E.prototype.run=
|
|
304
304
|
function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};E.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_loop();this.next_tick(a)}};E.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};E.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};E.prototype.stop=function(){this.running&&
|
|
305
|
-
(this.stopping=!0)};E.prototype.destroy=function(){this.unregister_yield()};E.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};E.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)E.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};else if(
|
|
306
|
-
"function"===typeof
|
|
305
|
+
(this.stopping=!0)};E.prototype.destroy=function(){this.unregister_yield()};E.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};E.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)E.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};else if(globalThis.scheduler&&
|
|
306
|
+
"function"===typeof globalThis.scheduler.postTask&&location.href.includes("use-scheduling-api"))E.prototype.yield=function(a,b){a=Math.max(0,a);globalThis.scheduler.postTask(()=>this.yield_callback(b),{delay:a})},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}E.prototype.register_yield=
|
|
307
307
|
function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};E.prototype.yield=function(b,c){this.worker.postMessage({t:b,tick:c})};E.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else E.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=
|
|
308
308
|
function(){};E.prototype.save_state=function(){for(var a=[],b=cb(this.cpu,a),c=[],d=0,e=0;e<a.length;e++){var f=a[e].byteLength;c[e]={offset:d,length:f};d+=f;d=d+3&-4}e=JSON.stringify({buffer_infos:c,state:b});e=(new TextEncoder).encode(e);b=16+e.length;b=b+3&-4;f=b+d;d=new ArrayBuffer(f);var g=new Int32Array(d,0,4);(new Uint8Array(d,16,e.length)).set(e);b=new Uint8Array(d,b);g[0]=-2039052682;g[1]=6;g[2]=f;g[3]=e.length;for(e=0;e<a.length;e++)b.set(a[e],c[e].offset);return d};E.prototype.restore_state=
|
|
309
309
|
function(a){return eb(this.cpu,a)};if("object"===typeof performance&&performance.now)E.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");E.microtick=a.now.bind(a)}else E.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;function tc(a){this.cpu=a;var b=a.io;a.devices.pci.register_device({pci_id:56,pci_space:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,0,0,
|
|
@@ -319,50 +319,50 @@ this.iir&15;z(this.iir);2===this.iir&&this.ClearInterrupt(2);this.fifo_control&1
|
|
|
319
319
|
a.register_write(b|5,this,function(){});a.register_read(b|6,this,function(){z(this.modem_status);return this.modem_status&=240});a.register_write(b|6,this,function(d){z(d);this.set_modem_status(d)});a.register_read(b|7,this,function(){return this.scratch_register});a.register_write(b|7,this,function(d){this.scratch_register=d})}uc.prototype.get_state=function(){var a=[];a[0]=this.ints;a[1]=this.baud_rate;a[2]=this.line_control;a[3]=this.lsr;a[4]=this.fifo_control;a[5]=this.ier;a[6]=this.iir;a[7]=
|
|
320
320
|
this.modem_control;a[8]=this.modem_status;a[9]=this.scratch_register;a[10]=this.irq;return a};uc.prototype.set_state=function(a){this.ints=a[0];this.baud_rate=a[1];this.line_control=a[2];this.lsr=a[3];this.fifo_control=a[4];this.ier=a[5];this.iir=a[6];this.modem_control=a[7];this.modem_status=a[8];this.scratch_register=a[9];this.irq=a[10]};uc.prototype.CheckInterrupt=function(){this.ints&4096&&this.ier&1?(this.iir=12,this.cpu.device_raise_irq(this.irq)):this.ints&16&&this.ier&1?(this.iir=4,this.cpu.device_raise_irq(this.irq)):
|
|
321
321
|
this.ints&4&&this.ier&2?(this.iir=2,this.cpu.device_raise_irq(this.irq)):this.ints&1&&this.ier&8?(this.iir=0,this.cpu.device_raise_irq(this.irq)):(this.iir=1,this.cpu.device_lower_irq(this.irq))};uc.prototype.ThrowInterrupt=function(a){this.ints|=1<<a;this.CheckInterrupt()};uc.prototype.ClearInterrupt=function(a){this.ints&=~(1<<a);this.CheckInterrupt()};uc.prototype.data_received=function(a){z(a);this.input.push(a);this.lsr|=1;this.fifo_control&1?this.ThrowInterrupt(12):this.ThrowInterrupt(4)};uc.prototype.write_data=
|
|
322
|
-
function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(z(a),this.ThrowInterrupt(2),this.bus.send("serial"+this.com+"-output-byte",a))};uc.prototype.set_modem_status=function(a){z(a);const b=this.modem_status&15;let c=(this.modem_status^a)>>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function vc(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);
|
|
323
|
-
this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=new Int32Array(this.pci_response.buffer);this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=a.io;a.io.register_write(3324,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],
|
|
324
|
-
this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,c)});a.io.register_write(3326,this,function(c){this.pci_write8(this.pci_addr32[0]+2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(3327,this,function(c){this.pci_write8(this.pci_addr32[0]+3|0,c)});a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});
|
|
325
|
-
this,function(){return this.pci_status[0]},function(){return this.pci_status[1]},function(){return this.pci_status[2]},function(){return this.pci_status[3]});a.io.register_write_consecutive(3320,this,function(c){this.pci_addr[0]=c&252},function(c){2===(this.pci_addr[1]&6)&&6===(c&6)?a.reboot_internal():this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,
|
|
326
|
-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=
|
|
327
|
-
vc.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};vc.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var f=d[4+e];if(f&1){var g=c.pci_bars[e];this.set_io_bars(g,g.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else d&&z(b,2)}this.pci_addr.set(a[256]);
|
|
328
|
-
this.pci_response.set(a[258]);this.pci_status.set(a[259])};vc.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+z(a,4));d+=" dev="+z(c,2);d+=" addr="+z(b,2);a=this.device_spaces[a];void 0!==a?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<a.byteLength?a[b>>2]:0,d+=" "+z(this.pci_addr32[0]>>>0,8)+" -> "+z(this.pci_response32[0]>>>0,8)):(this.pci_response32[0]
|
|
329
|
-
0)};vc.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer);z(a);z(c>>3,2);z(a,4);z(b,2);d[a]=b};vc.prototype.pci_write16=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer);16<=a&&44>a?z(a):(z(a),z(c>>3,2),z(a,4),z(b,4),d[a>>>1]=b)};vc.prototype.pci_write32=function(a,b){var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){e=e.pci_bars[a-16>>
|
|
330
|
-
z(c>>3,2);if(e){c=a>>2;var f=d[c]&1;-1===(b|3|e.size-1)?(b=~(e.size-1)|f,0===f&&(d[c]=b)):0===f&&(d[c]=e.original_bar);if(1===f){f=d[c]&65534;var g=b&65534;z(f>>>0,8);z(g>>>0,8);this.set_io_bars(e,f,g);d[c]=b|1}}else d[a>>2]=0;z(d[a>>2]>>>0)}else 48===a?(z(c>>3,2),z(b>>>0,8),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?(z(c>>3,2),z(a,4),z(b>>>0,8)):(z(c>>3,2),z(a,4),z(b>>>0,8),d[a>>>2]=b)};vc.prototype.register_device=function(a){var b=
|
|
331
|
-
c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],g=f&1;z(f);e.original_bar=f;e.entries=[];if(0!==g)for(f&=-2,g=0;g<e.size;g++)e.entries[g]=this.io.ports[f+g]}}return c};vc.prototype.set_io_bars=function(a,b,c){var d=a.size;z(b);z(c);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());
|
|
332
|
-
vc.prototype.raise_irq=function(a){this.cpu.device_raise_irq(this.isa_bridge_space8[96+((this.device_spaces[a][15]>>8&255)-1+((a>>3)-1&255)&3)])};vc.prototype.lower_irq=function(a){this.cpu.device_lower_irq(this.isa_bridge_space8[96+((this.device_spaces[a][15]>>8&255)+(a>>3&255)-2&3)])};function wc(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&
|
|
333
|
-
b[4]&&a[11]===b[5]&&(a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d){if(a=a.subarray(14),4===a[0]>>4&&17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];z(a[6]<<8|a[7],4);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)z(e,8);else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(d[28]=c[0],d[29]=c[1],d[30]=c[2],
|
|
334
|
-
0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const g=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+6]=c[5],a[6]=a[7]=0);e+=g}}}else 2054===d&&(a=a.subarray(14),xc(a.subarray(8,14)),xc(a.subarray(18,24)),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(a[8]=c[0],a[9]=c[1],a[10]=c[2],
|
|
335
|
-
"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,"0"),a[5].toString(16).padStart(2,"0")].join(":")}function yc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=
|
|
336
|
-
0,0,0,0,this.port&255|1,this.port>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|
|
|
337
|
-
255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;ua("Mac: "+xc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|0,this,function(){return this.cr},function(){return this.cr});b.register_write(this.port|
|
|
338
|
-
this.do_interrupt(64),f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),wc(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),z(f.byteLength)))});b.register_read(this.port|13,this,function(){return 1===this.get_page()?this.mar[5]:0});b.register_read(this.port|
|
|
339
|
-
return 0});b.register_read(this.port|15,this,function(){return 1===this.get_page()?this.mar[7]:0});b.register_read(this.port|31,this,function(){this.get_page();this.do_interrupt(128);return 0});b.register_write(this.port|31,this,function(f){this.get_page();z(f,2)});b.register_read(this.port|1,this,function(){var f=this.get_page();return 0===f?this.pstart:1===f?this.mac[0]:2===f?this.pstart:0});b.register_write(this.port|
|
|
340
|
-
this.mac[0]=f):z(f)});b.register_read(this.port|2,this,function(){var f=this.get_page();return 0===f?this.pstop:1===f?this.mac[1]:2===f?this.pstop:0});b.register_write(this.port|2,this,function(f){var g=this.get_page();0===g?(z(f,2),f>this.memory.length>>8&&(f=this.memory.length>>8,z(f)),this.pstop=f):1===g?(z(f),this.mac[1]=f):z(f)});b.register_read(this.port|7,this,function(){var f=this.get_page();return 0===f?(z(this.isr,
|
|
341
|
-
7,this,function(f){var g=this.get_page();0===g?(z(f,2),this.isr&=~f,this.update_irq()):1===g&&(z(f,2),this.curpg=f)});b.register_write(this.port|13,this,function(f){0===this.get_page()&&(this.txcr=f);z(f,2)});b.register_write(this.port|14,this,function(f){0===this.get_page()?(z(f,2),this.dcfg=f):z(f,2)});b.register_read(this.port|10,this,function(){var f=this.get_page();return 0===f?80:1===f?this.mar[2]:0});b.register_write(this.port|
|
|
342
|
-
65280|f&255):z(f,2)});b.register_read(this.port|11,this,function(){var f=this.get_page();return 0===f?67:1===f?this.mar[3]:0});b.register_write(this.port|11,this,function(f){0===this.get_page()?(z(f,2),this.rcnt=this.rcnt&255|f<<8&65280):z(f,2)});b.register_read(this.port|8,this,function(){var f=this.get_page();return 0===f?this.rsar&255:1===f?this.mar[0]:0});b.register_write(this.port|8,this,function(f){0===this.get_page()?(z(f,
|
|
343
|
-
9,this,function(){var f=this.get_page();return 0===f?this.rsar>>8&255:1===f?this.mar[1]:0});b.register_write(this.port|9,this,function(f){0===this.get_page()?(z(f,2),this.rsar=this.rsar&255|f<<8&65280):z(f,2)});b.register_write(this.port|15,this,function(f){0===this.get_page()?(z(f,2),z(this.isr,2),this.imr=f,this.update_irq()):z(f,2)});b.register_read(this.port|3,this,function(){var f=this.get_page();return 0===f?(z(this.boundary,
|
|
344
|
-
3,this,function(f){var g=this.get_page();0===g?(z(f,2),this.boundary=f):1===g?(z(f),this.mac[2]=f):z(f)});b.register_read(this.port|4,this,function(){var f=this.get_page();return 0===f?this.tsr:1===f?this.mac[3]:0});b.register_write(this.port|4,this,function(f){var g=this.get_page();0===g?(z(f,2),this.tpsr=f):1===g?(z(f),this.mac[3]=f):z(f)});b.register_read(this.port|5,this,function(){var f=this.get_page();return 0===f?0:1===f?this.mac[4]:
|
|
345
|
-
0===g?(z(f,2),this.tcnt=this.tcnt&-256|f):1===g?(z(f),this.mac[4]=f):z(f)});b.register_read(this.port|6,this,function(){var f=this.get_page();return 0===f?0:1===f?this.mac[5]:0});b.register_write(this.port|6,this,function(f){var g=this.get_page();0===g?(z(f,2),this.tcnt=this.tcnt&255|f<<8):1===g?(z(f),this.mac[5]=f):z(f)});b.register_read(this.port|12,this,function(){var f=this.get_page();return 0===f?9:1===f?this.mar[4]:0});
|
|
346
|
-
2),this.rxcr=f):z(f)});b.register_read(this.port|16,this,this.data_port_read8,this.data_port_read16,this.data_port_read32);b.register_write(this.port|16,this,this.data_port_write16,this.data_port_write16,this.data_port_write32);a.devices.pci.register_device(this)}yc.prototype.get_state=function(){var a=[];a[0]=this.isr;a[1]=this.imr;a[2]=this.cr;a[3]=this.dcfg;a[4]=this.rcnt;a[5]=this.tcnt;a[6]=this.tpsr;a[7]=this.rsar;a[8]=this.pstart;
|
|
347
|
-
a[13]=this.txcr;a[14]=this.tsr;a[15]=this.mac;a[16]=this.memory;return a};yc.prototype.set_state=function(a){this.isr=a[0];this.imr=a[1];this.cr=a[2];this.dcfg=a[3];this.rcnt=a[4];this.tcnt=a[5];this.tpsr=a[6];this.rsar=a[7];this.pstart=a[8];this.curpg=a[9];this.boundary=a[10];this.pstop=a[11];this.rxcr=a[12];this.txcr=a[13];this.tsr=a[14];this.preserve_mac_from_state_image?(this.mac=a[15],this.memory=a[16]):this.mac_address_translation&&
|
|
348
|
-
xc(this.mac));this.bus.send("net"+this.id+"-mac",xc(this.mac))};yc.prototype.do_interrupt=function(a){z(a,2);this.isr|=a;this.update_irq()};yc.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};yc.prototype.data_port_write=function(a){if(16>=this.rsar||16384<=this.rsar&&32768>this.rsar)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<
|
|
349
|
-
yc.prototype.data_port_write16=function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};yc.prototype.data_port_write32=function(a){this.data_port_write(a);this.data_port_write(a>>8);this.data_port_write(a>>16);this.data_port_write(a>>24)};yc.prototype.data_port_read=function(){let a=0;32768>this.rsar&&(a=this.memory[this.rsar]);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-
|
|
350
|
-
function(){return this.data_port_read16()&255};yc.prototype.data_port_read16=function(){return this.dcfg&1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};yc.prototype.data_port_read32=function(){return this.data_port_read()|this.data_port_read()<<8|this.data_port_read()<<16|this.data_port_read()<<24};yc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-end",[a.length]),
|
|
351
|
-
a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),wc(a,this.mac,this.mac_address_in_state));var b=this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),f=b+c,g=1+(c>>8),h=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+
|
|
352
|
-
z(this.curpg),z(g),z(this.boundary),z(h)):(f>this.pstop<<8?(f=(this.pstop<<8)-d,this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),z(f)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,z(b),z(c),z(e),this.do_interrupt(1))}};yc.prototype.get_page=
|
|
353
|
-
25;this.cols=80;this.ports=4;b=[{size_supported:16,notify_offset:0},{size_supported:16,notify_offset:1},{size_supported:16,notify_offset:2},{size_supported:16,notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Ac(a,{name:"virtio-console",pci_id:96,device_id:4163,subsystem_device_id:3,common:{initial_port:47104,queues:b,features:[0,
|
|
354
|
-
handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},c=>{if(2===c)for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3===c)for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);
|
|
355
|
-
g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,e);0===f&&this.SendWindowSize(f);break;default:return}}}]},isr_status:{initial_port:46848},device_specific:{initial_port:46592,struct:[{bytes:2,name:"cols",read:()=>this.cols,write:()=>{}},{bytes:2,name:"rows",read:()=>this.rows,write:()=>
|
|
356
|
-
write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+c+"-input-bytes",function(e){var f=this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&
|
|
357
|
-
zc.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);F(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};zc.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);F(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};zc.prototype.get_state=
|
|
358
|
-
a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};zc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};zc.prototype.reset=function(){this.virtio.reset()};zc.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);F(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};zc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};
|
|
359
|
-
function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Bc(a,b){this.cpu=a;this.bus=b;this.reset();this.bus.register("keyboard-code",function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=
|
|
360
|
-
2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}Bc.prototype.reset=function(){this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=
|
|
361
|
-
this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new ka(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new ka(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=
|
|
362
|
-
this.read_command_register=this.read_output_register=!1};Bc.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;
|
|
363
|
-
a[16]=this.sample_rate;a[17]=this.resolution;a[18]=this.scaling2;a[20]=this.command_register;a[21]=this.read_output_register;a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};Bc.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=
|
|
364
|
-
this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=a[18];this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=
|
|
365
|
-
a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",this.use_mouse)};Bc.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};Bc.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(this.cpu.device_lower_irq(12),
|
|
322
|
+
function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(z(a),this.ThrowInterrupt(2),this.modem_control&16?this.data_received(a):this.bus.send("serial"+this.com+"-output-byte",a))};uc.prototype.set_modem_status=function(a){z(a);const b=this.modem_status&15;let c=(this.modem_status^a)>>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function vc(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);
|
|
323
|
+
this.pci_addr32=new Int32Array(this.pci_addr.buffer);this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=new Int32Array(this.pci_response.buffer);this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=a.io;a.io.register_write(3324,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],
|
|
324
|
+
c)});a.io.register_write(3325,this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,c)});a.io.register_write(3326,this,function(c){this.pci_write8(this.pci_addr32[0]+2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(3327,this,function(c){this.pci_write8(this.pci_addr32[0]+3|0,c)});a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});
|
|
325
|
+
a.io.register_read_consecutive(3320,this,function(){return this.pci_status[0]},function(){return this.pci_status[1]},function(){return this.pci_status[2]},function(){return this.pci_status[3]});a.io.register_write_consecutive(3320,this,function(c){this.pci_addr[0]=c&252},function(c){2===(this.pci_addr[1]&6)&&6===(c&6)?a.reboot_internal():this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,
|
|
326
|
+
0,0,2,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=
|
|
327
|
+
new Uint8Array(this.isa_bridge_space.buffer)}vc.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};vc.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var f=d[4+e];if(f&1){var g=c.pci_bars[e];this.set_io_bars(g,g.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else d&&z(b,2)}this.pci_addr.set(a[256]);
|
|
328
|
+
this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};vc.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+z(a,4));d+=" dev="+z(c,2);d+=" addr="+z(b,2);a=this.device_spaces[a];void 0!==a?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<a.byteLength?a[b>>2]:0,d+=" "+z(this.pci_addr32[0]>>>0,8)+" -> "+z(this.pci_response32[0]>>>0,8)):(this.pci_response32[0]=
|
|
329
|
+
-1,this.pci_status32[0]=0)};vc.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer);z(a);z(c>>3,2);z(a,4);z(b,2);d[a]=b};vc.prototype.pci_write16=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer);16<=a&&44>a?z(a):(z(a),z(c>>3,2),z(a,4),z(b,4),d[a>>>1]=b)};vc.prototype.pci_write32=function(a,b){var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){e=e.pci_bars[a-16>>
|
|
330
|
+
2];z(d[a>>2]);z(b>>>0);z(c>>3,2);if(e){c=a>>2;var f=d[c]&1;-1===(b|3|e.size-1)?(b=~(e.size-1)|f,0===f&&(d[c]=b)):0===f&&(d[c]=e.original_bar);if(1===f){f=d[c]&65534;var g=b&65534;z(f>>>0,8);z(g>>>0,8);this.set_io_bars(e,f,g);d[c]=b|1}}else d[a>>2]=0;z(d[a>>2]>>>0)}else 48===a?(z(c>>3,2),z(b>>>0,8),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?(z(c>>3,2),z(a,4),z(b>>>0,8)):(z(c>>3,2),z(a,4),z(b>>>0,8),d[a>>>2]=b)};vc.prototype.register_device=function(a){var b=
|
|
331
|
+
a.pci_id;z(b);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],g=f&1;z(f);e.original_bar=f;e.entries=[];if(0!==g)for(f&=-2,g=0;g<e.size;g++)e.entries[g]=this.io.ports[f+g]}}return c};vc.prototype.set_io_bars=function(a,b,c){var d=a.size;z(b);z(c);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());
|
|
332
|
+
var g=a.entries[f];4096<=c+f&&(e[c+f]=g)}};vc.prototype.raise_irq=function(a){this.cpu.device_raise_irq(this.isa_bridge_space8[96+((this.device_spaces[a][15]>>8&255)-1+((a>>3)-1&255)&3)])};vc.prototype.lower_irq=function(a){this.cpu.device_lower_irq(this.isa_bridge_space8[96+((this.device_spaces[a][15]>>8&255)+(a>>3&255)-2&3)])};function wc(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&
|
|
333
|
+
a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d){if(a=a.subarray(14),4===a[0]>>4&&17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];z(a[6]<<8|a[7],4);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)z(e,8);else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(d[28]=c[0],d[29]=c[1],d[30]=c[2],
|
|
334
|
+
d[31]=c[3],d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const g=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+6]=c[5],a[6]=a[7]=0);e+=g}}}else 2054===d&&(a=a.subarray(14),xc(a.subarray(8,14)),xc(a.subarray(18,24)),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(a[8]=c[0],a[9]=c[1],a[10]=c[2],
|
|
335
|
+
a[11]=c[3],a[12]=c[4],a[13]=c[5]))}function xc(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,"0"),a[5].toString(16).padStart(2,"0")].join(":")}function yc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=
|
|
336
|
+
768+256*this.id;this.name="ne2k";this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|
|
|
337
|
+
0]);this.bus.send("net"+this.id+"-mac",xc(this.mac));this.mar=Uint8Array.of(255,255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;ua("Mac: "+xc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|0,this,function(){return this.cr},function(){return this.cr});b.register_write(this.port|
|
|
338
|
+
0,this,function(f){this.cr=f;z(f,2);z(this.txcr,2);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),wc(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),z(f.byteLength)))});b.register_read(this.port|13,this,function(){return 1===this.get_page()?this.mar[5]:0});b.register_read(this.port|
|
|
339
|
+
14,this,function(){return 1===this.get_page()?this.mar[6]:0},function(){this.get_page();return 0});b.register_read(this.port|15,this,function(){return 1===this.get_page()?this.mar[7]:0});b.register_read(this.port|31,this,function(){this.get_page();this.do_interrupt(128);return 0});b.register_write(this.port|31,this,function(f){this.get_page();z(f,2)});b.register_read(this.port|1,this,function(){var f=this.get_page();return 0===f?this.pstart:1===f?this.mac[0]:2===f?this.pstart:0});b.register_write(this.port|
|
|
340
|
+
1,this,function(f){var g=this.get_page();0===g?(z(f,2),this.pstart=f):1===g?(z(f),this.mac[0]=f):z(f)});b.register_read(this.port|2,this,function(){var f=this.get_page();return 0===f?this.pstop:1===f?this.mac[1]:2===f?this.pstop:0});b.register_write(this.port|2,this,function(f){var g=this.get_page();0===g?(z(f,2),f>this.memory.length>>8&&(f=this.memory.length>>8,z(f)),this.pstop=f):1===g?(z(f),this.mac[1]=f):z(f)});b.register_read(this.port|7,this,function(){var f=this.get_page();return 0===f?(z(this.isr,
|
|
341
|
+
2),this.isr):1===f?(z(this.curpg,2),this.curpg):0});b.register_write(this.port|7,this,function(f){var g=this.get_page();0===g?(z(f,2),this.isr&=~f,this.update_irq()):1===g&&(z(f,2),this.curpg=f)});b.register_write(this.port|13,this,function(f){0===this.get_page()&&(this.txcr=f);z(f,2)});b.register_write(this.port|14,this,function(f){0===this.get_page()?(z(f,2),this.dcfg=f):z(f,2)});b.register_read(this.port|10,this,function(){var f=this.get_page();return 0===f?80:1===f?this.mar[2]:0});b.register_write(this.port|
|
|
342
|
+
10,this,function(f){0===this.get_page()?(z(f,2),this.rcnt=this.rcnt&65280|f&255):z(f,2)});b.register_read(this.port|11,this,function(){var f=this.get_page();return 0===f?67:1===f?this.mar[3]:0});b.register_write(this.port|11,this,function(f){0===this.get_page()?(z(f,2),this.rcnt=this.rcnt&255|f<<8&65280):z(f,2)});b.register_read(this.port|8,this,function(){var f=this.get_page();return 0===f?this.rsar&255:1===f?this.mar[0]:0});b.register_write(this.port|8,this,function(f){0===this.get_page()?(z(f,
|
|
343
|
+
2),this.rsar=this.rsar&65280|f&255):z(f,2)});b.register_read(this.port|9,this,function(){var f=this.get_page();return 0===f?this.rsar>>8&255:1===f?this.mar[1]:0});b.register_write(this.port|9,this,function(f){0===this.get_page()?(z(f,2),this.rsar=this.rsar&255|f<<8&65280):z(f,2)});b.register_write(this.port|15,this,function(f){0===this.get_page()?(z(f,2),z(this.isr,2),this.imr=f,this.update_irq()):z(f,2)});b.register_read(this.port|3,this,function(){var f=this.get_page();return 0===f?(z(this.boundary,
|
|
344
|
+
2),this.boundary):1===f?this.mac[2]:0});b.register_write(this.port|3,this,function(f){var g=this.get_page();0===g?(z(f,2),this.boundary=f):1===g?(z(f),this.mac[2]=f):z(f)});b.register_read(this.port|4,this,function(){var f=this.get_page();return 0===f?this.tsr:1===f?this.mac[3]:0});b.register_write(this.port|4,this,function(f){var g=this.get_page();0===g?(z(f,2),this.tpsr=f):1===g?(z(f),this.mac[3]=f):z(f)});b.register_read(this.port|5,this,function(){var f=this.get_page();return 0===f?0:1===f?this.mac[4]:
|
|
345
|
+
0});b.register_write(this.port|5,this,function(f){var g=this.get_page();0===g?(z(f,2),this.tcnt=this.tcnt&-256|f):1===g?(z(f),this.mac[4]=f):z(f)});b.register_read(this.port|6,this,function(){var f=this.get_page();return 0===f?0:1===f?this.mac[5]:0});b.register_write(this.port|6,this,function(f){var g=this.get_page();0===g?(z(f,2),this.tcnt=this.tcnt&255|f<<8):1===g?(z(f),this.mac[5]=f):z(f)});b.register_read(this.port|12,this,function(){var f=this.get_page();return 0===f?9:1===f?this.mar[4]:0});
|
|
346
|
+
b.register_write(this.port|12,this,function(f){0===this.get_page()?(z(f,2),this.rxcr=f):z(f)});b.register_read(this.port|16,this,this.data_port_read8,this.data_port_read16,this.data_port_read32);b.register_write(this.port|16,this,this.data_port_write16,this.data_port_write16,this.data_port_write32);a.devices.pci.register_device(this)}yc.prototype.get_state=function(){var a=[];a[0]=this.isr;a[1]=this.imr;a[2]=this.cr;a[3]=this.dcfg;a[4]=this.rcnt;a[5]=this.tcnt;a[6]=this.tpsr;a[7]=this.rsar;a[8]=this.pstart;
|
|
347
|
+
a[9]=this.curpg;a[10]=this.boundary;a[11]=this.pstop;a[12]=this.rxcr;a[13]=this.txcr;a[14]=this.tsr;a[15]=this.mac;a[16]=this.memory;return a};yc.prototype.set_state=function(a){this.isr=a[0];this.imr=a[1];this.cr=a[2];this.dcfg=a[3];this.rcnt=a[4];this.tcnt=a[5];this.tpsr=a[6];this.rsar=a[7];this.pstart=a[8];this.curpg=a[9];this.boundary=a[10];this.pstop=a[11];this.rxcr=a[12];this.txcr=a[13];this.tsr=a[14];this.preserve_mac_from_state_image?(this.mac=a[15],this.memory=a[16]):this.mac_address_translation&&
|
|
348
|
+
(this.mac_address_in_state=a[15],this.memory=a[16],xc(this.mac_address_in_state),xc(this.mac));this.bus.send("net"+this.id+"-mac",xc(this.mac))};yc.prototype.do_interrupt=function(a){z(a,2);this.isr|=a;this.update_irq()};yc.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};yc.prototype.data_port_write=function(a){if(16>=this.rsar||16384<=this.rsar&&32768>this.rsar)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<
|
|
349
|
+
8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64)};yc.prototype.data_port_write16=function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};yc.prototype.data_port_write32=function(a){this.data_port_write(a);this.data_port_write(a>>8);this.data_port_write(a>>16);this.data_port_write(a>>24)};yc.prototype.data_port_read=function(){let a=0;32768>this.rsar&&(a=this.memory[this.rsar]);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-
|
|
350
|
+
this.pstop<<8);0===this.rcnt&&this.do_interrupt(64);return a};yc.prototype.data_port_read8=function(){return this.data_port_read16()&255};yc.prototype.data_port_read16=function(){return this.dcfg&1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};yc.prototype.data_port_read32=function(){return this.data_port_read()|this.data_port_read()<<8|this.data_port_read()<<16|this.data_port_read()<<24};yc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-end",[a.length]),
|
|
351
|
+
this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255===a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),wc(a,this.mac,this.mac_address_in_state));var b=this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),f=b+c,g=1+(c>>8),h=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+
|
|
352
|
+
this.boundary-this.pstart;h<g&&0!==this.boundary?(z(this.pstart),z(this.pstop),z(this.curpg),z(g),z(this.boundary),z(h)):(f>this.pstop<<8?(f=(this.pstop<<8)-d,this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),z(f)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,z(b),z(c),z(e),this.do_interrupt(1))}};yc.prototype.get_page=
|
|
353
|
+
function(){return this.cr>>6&3};function zc(a,b){this.bus=b;this.rows=25;this.cols=80;this.ports=4;b=[{size_supported:16,notify_offset:0},{size_supported:16,notify_offset:1},{size_supported:16,notify_offset:2},{size_supported:16,notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Ac(a,{name:"virtio-console",pci_id:96,device_id:4163,subsystem_device_id:3,common:{initial_port:47104,queues:b,features:[0,
|
|
354
|
+
1,32],on_driver_ok:()=>{}},notification:{initial_port:47360,single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},c=>{if(2===c)for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3===c)for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);
|
|
355
|
+
e.get_next_blob(f);var g=I(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,e);0===f&&this.SendWindowSize(f);break;default:return}}}]},isr_status:{initial_port:46848},device_specific:{initial_port:46592,struct:[{bytes:2,name:"cols",read:()=>this.cols,write:()=>{}},{bytes:2,name:"rows",read:()=>this.rows,write:()=>
|
|
356
|
+
{}},{bytes:4,name:"max_nr_ports",read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+c+"-input-bytes",function(e){var f=this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&
|
|
357
|
+
this.SendWindowSize(c,e[0],e[1])},this)}}zc.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);F(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};zc.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);F(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};zc.prototype.get_state=
|
|
358
|
+
function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};zc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};zc.prototype.reset=function(){this.virtio.reset()};zc.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);F(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};zc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};
|
|
359
|
+
zc.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Bc(a,b){this.cpu=a;this.bus=b;this.reset();this.bus.register("keyboard-code",function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=
|
|
360
|
+
c[0];this.wheel_movement-=2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}Bc.prototype.reset=function(){this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=
|
|
361
|
+
this.next_read_rate=this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new ka(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new ka(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=
|
|
362
|
+
0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1};Bc.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;
|
|
363
|
+
a[15]=this.last_port60_byte;a[16]=this.sample_rate;a[17]=this.resolution;a[18]=this.scaling2;a[20]=this.command_register;a[21]=this.read_output_register;a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};Bc.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=
|
|
364
|
+
a[4];this.mouse_clicks=a[5];this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=a[18];this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=
|
|
365
|
+
a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",this.use_mouse)};Bc.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};Bc.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(this.cpu.device_lower_irq(12),
|
|
366
366
|
this.cpu.device_raise_irq(12))};Bc.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=!1;this.command_register&1&&(this.cpu.device_lower_irq(1),this.cpu.device_raise_irq(1))};Bc.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(z(a),this.kbd_buffer.push(a),this.raise_irq())};Bc.prototype.mouse_send_delta=function(a,b){this.have_mouse&&this.use_mouse&&(this.mouse_delta_x+=1*a,this.mouse_delta_y+=1*b,this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|
|
|
367
367
|
0,a||b))&&(this.mouse_delta_x-=a,this.mouse_delta_y-=b,this.send_mouse_packet(a,b))};Bc.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))};Bc.prototype.send_mouse_packet=function(a,b){var c=(0>b)<<5|(0>a)<<4|8|this.mouse_clicks;this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&
|
|
368
368
|
15),this.wheel_movement=0):3===this.mouse_id&&(this.mouse_buffer.push(this.wheel_movement&255),this.wheel_movement=0);this.raise_irq()};Bc.prototype.apply_scaling2=function(a){var b=a>>31;switch(Math.abs(a)){case 0:case 1:case 3:return a;case 2:return b;case 4:return 6*b;case 5:return 9*b;default:return a<<1}};Bc.prototype.port60_read=function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),
|
package/build/v86-debug.wasm
CHANGED
|
Binary file
|
package/build/v86-fallback.wasm
CHANGED
|
Binary file
|
package/build/v86.wasm
CHANGED
|
Binary file
|