v86 0.5.12 → 0.5.14
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 +23 -19
- package/build/libv86-debug.mjs +125 -125
- package/build/libv86.js +16 -14
- package/build/libv86.mjs +114 -114
- package/package.json +1 -1
package/build/libv86.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
;let module = {exports:{}}; var h=h||{};h.exportSymbol=function(a,b){"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports[a]=b:"undefined"!==typeof window?window[a]=b:"function"===typeof importScripts&&(self[a]=b)};h.exportProperty=function(){};function aa(a,b){return(a||0===a?a+"":"").padEnd(b," ")}function v(a,b,c,d){return new Proxy({},{get:function(e,f){e=new a(b.buffer,c,d);const g=e[f];if("function"===typeof g)return g.bind(e);/^\d+$/.test(f);return g},set:function(e,f,g){/^\d+$/.test(f);(new a(b.buffer,
|
|
2
2
|
c,d))[f]=g;return!0}})}function A(a,b){a=(a?a.toString(16):"").toUpperCase();return"0x"+(a||0===a?a+"":"").padStart(b||1,"0")}var ba;if("undefined"!==typeof crypto&&crypto.getRandomValues){const a=new Int32Array(1);ba=function(){crypto.getRandomValues(a);return a[0]}}else if("undefined"!==typeof require){const a=require("crypto");ba=function(){return a.randomBytes(4).readInt32LE(0)}}else"undefined"!==typeof process&&import("node:crypto").then(a=>{ba=function(){return a.randomBytes(4).readInt32LE(0)}});
|
|
3
3
|
var ca;if("function"===typeof Math.clz32)ca=function(a){return 31-Math.clz32(a)};else{for(var da=new Int8Array(256),ea=0,fa=-2;256>ea;ea++)ea&ea-1||fa++,da[ea]=fa;ca=function(a){a>>>=0;var b=a>>>16;if(b){var c=b>>>8;return c?24+da[c]:16+da[b]}return(c=a>>>8)?8+da[c]:da[a]}}function ha(a){return 1>=a?1:1<<1+ca(a-1)}function ja(a){var b=new Uint8Array(a),c,d;this.length=0;this.push=function(e){this.length!==a&&this.length++;b[d]=e;d=d+1&a-1};this.shift=function(){if(this.length){var e=b[c];c=c+1&a-
|
|
4
|
-
1;this.length--;return e}return-1};this.peek=function(){return this.length?b[c]:-1};this.clear=function(){this.length=d=c=0};this.clear()}function
|
|
5
|
-
return a}};
|
|
4
|
+
1;this.length--;return e}return-1};this.peek=function(){return this.length?b[c]:-1};this.clear=function(){this.length=d=c=0};this.clear()}function ka(a){this.size=a;this.data=new Float32Array(a);this.length=this.end=this.start=0}ka.prototype.push=function(a){this.length===this.size?this.start=this.start+1&this.size-1:this.length++;this.data[this.end]=a;this.end=this.end+1&this.size-1};ka.prototype.shift=function(){if(this.length){var a=this.data[this.start];this.start=this.start+1&this.size-1;this.length--;
|
|
5
|
+
return a}};ka.prototype.shift_block=function(a){var b=new Float32Array(a);a>this.length&&(a=this.length);var c=this.start+a,d=this.data.subarray(this.start,c);b.set(d);c>=this.size&&(c-=this.size,b.set(this.data.subarray(0,c),d.length));this.start=c;this.length-=a;return b};ka.prototype.peek=function(){if(this.length)return this.data[this.start]};ka.prototype.clear=function(){this.length=this.end=this.start=0};function ma(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof ArrayBuffer&&
|
|
6
6
|
(this.view=new Uint8Array(a))}ma.prototype.set=function(a,b){const c=a>>3;a=1<<(a&7);this.view[c]=b?this.view[c]|a:this.view[c]&~a};ma.prototype.get=function(a){return this.view[a>>3]>>(a&7)&1};ma.prototype.get_buffer=function(){return this.view.buffer};var na;na="undefined"===typeof XMLHttpRequest?qa:ra;function ra(a,b,c){function d(){const l=c||0;setTimeout(()=>{na(a,b,l+1)},1E3*([1,1,2,3,5,8,13,21][l]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.as_json?"json":"arraybuffer";
|
|
7
7
|
if(b.headers)for(var f=Object.keys(b.headers),g=0;g<f.length;g++){var k=f[g];e.setRequestHeader(k,b.headers[k])}b.range&&(f=b.range.start,e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHeader("X-Accept-Encoding","identity"),e.onreadystatechange=function(){200===e.status&&(console.error("Server sent full file in response to ranged request, aborting",{filename:a}),e.abort())});e.onload=function(){if(4===e.readyState)if(200!==e.status&&206!==e.status)console.error("Loading the image "+
|
|
8
8
|
a+" failed (status %d)",e.status),500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const l=e.getResponseHeader("Content-Encoding");l&&"identity"!==l&&console.error("Server sent Content-Encoding in response to ranged request",{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)}function qa(a,b){if(b.range)import("node:fs").then(d=>d.open(a,"r",
|
|
9
9
|
(e,f)=>{if(e)throw e;e=b.range.length;var g=Buffer.allocUnsafe(e);d.read(f,g,0,e,b.range.start,k=>{if(k)throw k;b.done&&b.done(new Uint8Array(g));d.close(f,l=>{if(l)throw l;})})}));else{var c={encoding:b.as_json?"utf-8":null};import("node:fs").then(d=>d.readFile(a,c,function(e,f){e?console.log("Could not read file:",a,e):(e=f,e=b.as_json?JSON.parse(e):(new Uint8Array(e)).buffer,b.done(e))}))}}function sa(){}function ta(){}function ua(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+
|
|
10
|
-
w}function d(w){var t=256*oa,E=8*S,J=Ua?Ua.canvas:null;J&&J.width===t&&J.height===E||(J?(J.width=t,J.height=E):(J=new OffscreenCanvas(t,E),Ua=J.getContext("2d")),Ab=Ua.createImageData(t,E));const Q=Ab.data;let P=0,T;E=Bb?function(Y){T=T||Y;Q[P+3]=Y;Q[P+7]=Y;P+=8}:function(Y){T=T||Y;Q[P+3]=Y;P+=4};J=32-S;const
|
|
10
|
+
w}function d(w){var t=256*oa,E=8*S,J=Ua?Ua.canvas:null;J&&J.width===t&&J.height===E||(J?(J.width=t,J.height=E):(J=new OffscreenCanvas(t,E),Ua=J.getContext("2d")),Ab=Ua.createImageData(t,E));const Q=Ab.data;let P=0,T;E=Bb?function(Y){T=T||Y;Q[P+3]=Y;Q[P+7]=Y;P+=8}:function(Y){T=T||Y;Q[P+3]=Y;P+=4};J=32-S;const la=t*(S-1)*4;t=4*(oa-t*S);const ia=1020*oa;for(let Y=0,Ea=0;2048>Y;++Y,Ea+=J,P+=t){const Fa=Y%256;Y&&!Fa&&(P+=la);T=!1;for(let Ma=0;Ma<S;++Ma,++Ea,P+=ia){const Na=w[Ea];for(let va=128;0<va;va>>=
|
|
11
11
|
1)E(Na&va?255:0);Cb&&E(Db&&192<=Fa&&223>=Fa&&Na&1?255:0)}Vb[Y]=T?1:0}Ua.putImageData(Ab,0,0)}function e(w,t,E,J){if(t&&E){w.style.width="";w.style.height="";J&&(w.style.transform="");var Q=w.getBoundingClientRect();J?w.style.transform=(1===t?"":" scaleX("+t+")")+(1===E?"":" scaleY("+E+")"):(0===t%1&&0===E%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),
|
|
12
12
|
J=window.devicePixelRatio||1,0!==J%1&&(t/=J,E/=J));1!==t&&(w.style.width=Q.width*t+"px");1!==E&&(w.style.height=Q.height*E+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],k=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?a.scale:1,r=void 0!==a.scale?a.scale:1,z=1,y,u,H,x,I,R,pa,Ua,
|
|
13
13
|
Ab,Vb=new Int8Array(2048),S,oa,Cb,Bb,Db,Eb=0,Fb=0,nb,Wb=0,ob,Gb,pb,Hb=[],qb=Hb,rb=0,Ib=!1;this.init=function(){const w=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]),t=new Uint16Array([8962,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,402,225,237,243,250,241,209,170,186,191,8976,172,189,188,161,
|
|
14
14
|
171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var E=0,J;256>E;E++)J=126<E?t[E-127]:32>E?w[E]:E,Hb.push(String.fromCharCode(J));m.classList.add("cursor");
|
|
15
15
|
m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===u&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===u||2===u)w.src=g.toDataURL("image/png");else{const t=[9,16],E=document.createElement("canvas");E.width=x*t[0];E.height=I*t[1];const J=E.getContext("2d");J.imageSmoothingEnabled=!1;J.font=window.getComputedStyle(l).font;
|
|
16
|
-
J.textBaseline="top";for(let Q=0;Q<I;Q++)for(let P=0;P<x;P++){const T=4*(Q*x+P),
|
|
17
|
-
H[t+2]=Q;H[t+3]=P;y[w]=1};this.timer=function(){rb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ib||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<I;w++)y[w]&&(this.text_update_row(w),y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(R){var w=performance.now();if(266<w-Wb){nb=!nb;pb&&(y[n]=1);var t=4*x;for(let
|
|
18
|
-
0,ia=0;
|
|
16
|
+
J.textBaseline="top";for(let Q=0;Q<I;Q++)for(let P=0;P<x;P++){const T=4*(Q*x+P),la=H[T+0],ia=H[T+3];J.fillStyle=c(H[T+2]);J.fillRect(P*t[0],Q*t[1],t[0],t[1]);J.fillStyle=c(ia);J.fillText(qb[la],P*t[0],Q*t[1])}"none"!==m.style.display&&n<I&&p<x&&(J.fillStyle=m.style.backgroundColor,J.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=E.toDataURL("image/png")}return w};this.put_char=function(w,t,E,J,Q,P){t=4*(w*x+t);H[t+0]=E;H[t+1]=J;
|
|
17
|
+
H[t+2]=Q;H[t+3]=P;y[w]=1};this.timer=function(){rb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ib||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<I;w++)y[w]&&(this.text_update_row(w),y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(R){var w=performance.now();if(266<w-Wb){nb=!nb;pb&&(y[n]=1);var t=4*x;for(let la=
|
|
18
|
+
0,ia=0;la<I;++la)if(y[la])ia+=t;else for(var E=0;E<x;++E,ia+=4)if(H[ia+1]&1){y[la]=1;ia+=t-4*E;break}Wb=w}w=Ua.canvas;t=pa.canvas;E=4*x;const Q=x*oa,P=S;let T=0;for(let la=0,ia=0,Y=0;la<I;++la,ia+=S){if(!y[la]){Y+=E;continue}++T;pa.clearRect(0,P,Q,S);let Ea,Fa,Ma,Na;for(let va=0;va<Q;va+=oa,Y+=4){const Xb=H[Y+0];var J=H[Y+1];const Yb=H[Y+2],Zb=H[Y+3],$b=J&2?Fb:Eb;J=(!(J&1)||nb)&&Vb[($b<<8)+Xb];Ma!==Yb&&(void 0!==Ma&&(R.fillStyle=c(Ma),R.fillRect(Na,ia,va-Na,S)),Ma=Yb,Na=va);Ea!==Zb&&(void 0!==Ea&&
|
|
19
19
|
(pa.fillStyle=c(Ea),pa.fillRect(Fa,0,va-Fa,S)),Ea=Zb,Fa=va);J&&pa.drawImage(w,Xb*oa,$b*S,oa,S,va,P,oa,S)}pa.fillStyle=c(Ea);pa.fillRect(Fa,0,Q-Fa,S);pa.globalCompositeOperation="destination-in";pa.drawImage(t,0,P,Q,S,0,0,Q,S);pa.globalCompositeOperation="source-over";R.fillStyle=c(Ma);R.fillRect(Na,ia,Q-Na,S);R.drawImage(t,0,0,Q,S,0,ia,Q,S)}T&&(nb&&pb&&y[n]&&(R.fillStyle=c(H[4*(n*x+p)+3]),R.fillRect(p*oa,n*S+ob,oa,Gb-ob+1)),y.fill(0));T&&k.drawImage(R.canvas,0,0)}};this.destroy=function(){rb&&(cancelAnimationFrame(rb),
|
|
20
20
|
rb=0)};this.pause=function(){Ib=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Ib=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){u=w?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,E,J,Q,P){const T=E?16:t?9:8;if(S!==w||oa!==T||Cb!==t||Bb!==E||Db!==J||P)P=oa!==T||S!==w,S=w,oa=T,Cb=t,Bb=E,Db=J,2===u&&(d(Q),y.fill(1),P&&this.set_size_graphical_text())};
|
|
21
21
|
this.set_font_page=function(w,t){if(Eb!==w||Fb!==t)Eb=w,Fb=t,y.fill(1)};this.clear_screen=function(){k.fillStyle="#000";k.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ua){var w=oa*x,t=S*I,E=2*S;R&&R.canvas.width===w&&R.canvas.height===t&&pa.canvas.height===E||(R?(R.canvas.width=w,R.canvas.height=t,pa.canvas.width=w,pa.canvas.height=E):(R=(new OffscreenCanvas(w,t)).getContext("2d",{alpha:!1}),pa=(new OffscreenCanvas(w,E)).getContext("2d")),this.set_size_graphical(w,t,
|
|
22
22
|
w,t),y.fill(1))}};this.set_size_text=function(w,t){if(w!==x||t!==I)if(y=new Int8Array(t),H=new Int32Array(w*t*4),x=w,I=t,0===u){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(w=0;w<t;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;g.height=t;k.imageSmoothingEnabled=!1;z=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&
|
|
23
23
|
2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*z,r*z,!1)};this.set_charmap=function(w){qb=w||Hb};this.set_scale=function(w,t){q=w;r=t;e(l,q,r,!0);e(g,q*z,r*z,!1)};this.update_cursor_scanline=function(w,t,E){if(w!==ob||t!==Gb||E!==pb)0===u?E?(m.style.display="inline",m.style.height=t-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===u&&n<I&&(y[n]=1),ob=w,Gb=t,pb=E};this.update_cursor=function(w,t){if(w!==n||t!==p)w<I&&(y[w]=1),n<I&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=
|
|
24
|
-
4*w*x,E;var J=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<x;){var T=document.createElement("span");var
|
|
24
|
+
4*w*x,E;var J=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<x;){var T=document.createElement("span");var la=H[t+1]&1;var ia=H[t+2];var Y=H[t+3];la&&T.classList.add("blink");T.style.backgroundColor=c(ia);T.style.color=c(Y);for(E="";P<x&&(H[t+1]&1)===la&&H[t+2]===ia&&H[t+3]===Y;)if(E+=qb[H[t+0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=T.style.color;Q.appendChild(m);break}T.textContent=E;Q.appendChild(T)}J.parentNode.replaceChild(Q,J)};this.update_buffer=
|
|
25
25
|
function(w){for(const t of w)k.putImageData(t.image_data,t.screen_x-t.buffer_x,t.screen_y-t.buffer_y,t.buffer_x,t.buffer_y,t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<I;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){let t="";for(let E=0;E<x;E++)t+=qb[H[4*(w*x+E)]];return t};this.init()}function wa(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}wa.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};
|
|
26
26
|
wa.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};wa.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};wa.prototype.get_buffer=function(a){a(this.buffer)};wa.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};wa.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function xa(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=
|
|
27
27
|
new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=this.onload=void 0}xa.prototype.load=function(){void 0!==this.byteLength?this.onload&&this.onload(Object.create(null)):ya(this.filename,(a,b)=>{if(a)throw Error("Cannot use: "+this.filename+". "+a);this.byteLength=b;this.onload&&this.onload(Object.create(null))})};xa.prototype.get_from_cache=function(a,b){var c=b/256;a/=256;for(var d=0;d<c;d++)if(!this.block_cache.get(a+d))return;if(1===c)return this.block_cache.get(a);b=new Uint8Array(b);
|
|
@@ -63,7 +63,7 @@ b=b.read16.call(b.device,a);A(a);return b};C.prototype.port_read32=function(a){v
|
|
|
63
63
|
97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",179:"PORT_SMI_STATUS",212:"PORT_DMA2_MASK_REG",214:"PORT_DMA2_MODE_REG",218:"PORT_DMA2_MASTER_CLEAR",240:"PORT_MATH_CLEAR",368:"PORT_ATA2_CMD_BASE",496:"PORT_ATA1_CMD_BASE",632:"PORT_LPT2",744:"PORT_SERIAL4",760:"PORT_SERIAL2",884:"PORT_ATA2_CTRL_BASE",888:"PORT_LPT1",1E3:"PORT_SERIAL3",1008:"PORT_FD_BASE",
|
|
64
64
|
1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",3320:"PORT_PCI_CMD",3321:"PORT_PCI_REBOOT",3324:"PORT_PCI_DATA",1026:"PORT_BIOS_DEBUG",1296:"PORT_QEMU_CFG_CTL",1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};C.prototype.get_port_description=function(a){return Da[a]?" ("+Da[a]+")":""};var Ga={};function Ha(){this.listeners={};this.pair=void 0}Ha.prototype.register=function(a,b,
|
|
65
65
|
c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};Ha.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ha.prototype.send=function(a,b){if(this.pair&&(a=this.pair.listeners[a],void 0!==a))for(var c=0;c<a.length;c++){var d=a[c];d.fn.call(d.this_value,b)}};Ha.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};Ga.create=function(){var a=new Ha,b=new Ha;a.pair=
|
|
66
|
-
b;b.pair=a;return[a,b]};var Ia=new Uint8Array(256),Ja=[],Ka=[],La=[],Oa=new Uint8Array(256),Pa=[];function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new
|
|
66
|
+
b;b.pair=a;return[a,b]};var Ia=new Uint8Array(256),Ja=[],Ka=[],La=[],Oa=new Uint8Array(256),Pa=[];function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new ka(65536),new ka(65536)];
|
|
67
67
|
this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new wa(this.dma_buffer);
|
|
68
68
|
this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new ja(64);this.fm_current_address1=this.fm_current_address0=this.mpu_read_buffer_lastvalue=0;this.fm_waveform_select_enable=!1;this.irq=5;this.irq_triggered=new Uint8Array(16);a.io.register_read_consecutive(544,this,this.port2x0_read,this.port2x1_read,this.port2x2_read,
|
|
69
69
|
this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read);a.io.register_read_consecutive(548,this,this.port2x4_read,this.port2x5_read);a.io.register_read(550,this,this.port2x6_read);a.io.register_read(551,this,this.port2x7_read);a.io.register_read(552,this,this.port2x8_read);a.io.register_read(553,this,this.port2x9_read);a.io.register_read(554,this,this.port2xA_read);a.io.register_read(555,this,this.port2xB_read);a.io.register_read(556,this,this.port2xC_read);
|
|
@@ -182,11 +182,11 @@ c)for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{
|
|
|
182
182
|
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:()=>{}},{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(),
|
|
183
183
|
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)}}lb.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);M.Marshall(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};lb.prototype.SendName=function(a,b){const c=
|
|
184
184
|
this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);M.Marshall(["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)};lb.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};lb.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};lb.prototype.reset=function(){this.virtio.reset()};lb.prototype.SendEvent=
|
|
185
|
-
function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);M.Marshall(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};lb.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};lb.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 sb(a,b){this.cpu=a;this.bus=b;this.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
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;a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;
|
|
185
|
+
function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);M.Marshall(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};lb.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};lb.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 sb(a,b){this.cpu=a;this.bus=b;this.reset();this.bus.register("keyboard-code",function(c){this.kbd_send_code(c)},
|
|
186
|
+
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);a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);
|
|
187
|
+
a.io.register_write(100,this,this.port64_write)}sb.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=new ja(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=
|
|
188
|
+
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 ja(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};sb.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;
|
|
189
|
+
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;a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;
|
|
190
190
|
a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};sb.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=a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=a[12];this.next_read_resolution=
|
|
191
191
|
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;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",this.use_mouse)};
|
|
192
192
|
sb.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};sb.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),this.cpu.device_raise_irq(12))};sb.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))};sb.prototype.kbd_send_code=
|
|
@@ -376,107 +376,107 @@ this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.d
|
|
|
376
376
|
this.devices.uart3&&this.devices.uart3.set_state(a[81]);this.devices.virtio_console&&this.devices.virtio_console.set_state(a[82]);this.devices.virtio_net&&this.devices.virtio_net.set_state(a[83]);this.devices.virtio_balloon&&this.devices.virtio_balloon.set_state(a[84]);this.fw_value=a[62];this.devices.ioapic&&this.devices.ioapic.set_state(a[63]);this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=
|
|
377
377
|
a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];const b=new ma(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};K.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),c=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];const d=
|
|
378
378
|
a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12]};K.prototype.pack_memory=function(){var a=this.mem8.length>>12,b=[];for(var c=0;c<a;c++)this.is_memory_zeroed(c<<12,4096)||b.push(c);a=new ma(a);c=new Uint8Array(b.length<<12);for(const [d,e]of b.entries())a.set(e,1),b=e<<12,b=this.mem8.subarray(b,b+4096),c.set(b,d<<12);return{bitmap:a,packed_memory:c}};
|
|
379
|
-
K.prototype.unpack_memory=function(a,b){this.zero_memory(0,this.memory_size[0]);const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};K.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&this.devices.virtio_9p.reset();this.devices.virtio_console&&this.devices.virtio_console.reset();this.devices.virtio_net&&this.devices.virtio_net.reset();this.
|
|
380
|
-
function(){this.mem8.fill(0)};K.prototype.create_memory=function(a,b){a<b?a=b:0>(a|0)&&(a=Math.pow(2,31)-131072);a=(a-1|131071)+1|0;console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=v(Uint8Array,this.wasm_memory,b,a);this.mem32s=v(Uint32Array,this.wasm_memory,b,a>>2)};K.prototype.init=function(a,b){this.create_memory(a.memory_size||67108864,a.initrd?67108864:1048576);a.disable_jit&&
|
|
381
|
-
this.set_cpuid_level(a.cpuid_level);this.acpi_enabled[0]=+a.acpi;this.reset_cpu();var c=new C(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=Tb(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,this,function(){return 0});var d=0;c.register_read(146,this,function(){return d});c.register_write(146,this,function(e){d=e});c.register_read(1297,this,function(){return this.fw_pointer<
|
|
382
|
-
0});c.register_write(1296,this,void 0,function(e){function f(l){return new Uint8Array(Int32Array.of(l).buffer)}function g(l){return l>>8|l<<8&65280}function k(l){return l<<24|l<<8&16711680|l>>8&65280|l>>>24}sa("bios config port, index="+A(e));this.fw_pointer=0;if(0===e)this.fw_value=f(1431127377);else if(1===e)this.fw_value=f(0);else if(3===e)this.fw_value=f(this.memory_size[0]);else if(5===e)this.fw_value=f(1);else if(15===e)this.fw_value=f(1);
|
|
383
|
-
e){e=new Int32Array(4+64*this.option_roms.length);const l=new Uint8Array(e.buffer);e[0]=k(this.option_roms.length);for(let m=0;m<this.option_roms.length;m++){const {name:n,data:p}=this.option_roms[m],q=4+64*m;e[q+0>>2]=k(p.length);e[q+4>>2]=g(49152+m);for(let r=0;r<n.length;r++)l[q+8+r]=n.charCodeAt(r)}this.fw_value=l}else 32768<=e&&49152>e?this.fw_value=f(0):49152<=e&&e-49152<this.option_roms.length?this.fw_value=this.option_roms[e-49152].data:
|
|
384
|
-
f(0))});c.register_read(32,this,this.port20_read);c.register_read(33,this,this.port21_read);c.register_read(160,this,this.portA0_read);c.register_read(161,this,this.portA1_read);c.register_write(32,this,this.port20_write);c.register_write(33,this,this.port21_write);c.register_write(160,this,this.portA0_write);c.register_write(161,this,this.portA1_write);c.register_read(1232,this,this.port4D0_read);c.register_read(1233,this,this.port4D1_read);
|
|
385
|
-
this,this.port4D1_write);this.devices={};a.load_devices&&(this.devices.pci=new fb(this),this.acpi_enabled[0]&&(this.devices.ioapic=new bb(this),this.devices.apic=new ab(this),this.devices.acpi=new cb(this)),this.devices.rtc=new Lb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),this.devices.vga=new V(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new sb(this,b),this.devices.uart0=new eb(this,1016,
|
|
386
|
-
new eb(this,1E3,b)),a.uart3&&(this.devices.uart3=new eb(this,744,b)),this.devices.fdc=new O(this,a.fda,a.fdb),c=0,a.hda&&(this.devices.hda=new Mb(this,a.hda,a.hdb,!1,c++,b)),a.cdrom&&(this.devices.cdrom=new Mb(this,a.cdrom,void 0,!0,c++,b)),this.devices.pit=new db(this,b),"ne2k"===a.net_device.type?this.devices.net=new ib(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&
|
|
387
|
-
(this.devices.virtio_9p=new Ub(a.fs9p,this,b)),a.virtio_console&&(this.devices.virtio_console=new lb(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new Sb(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244))};K.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,
|
|
388
|
-
function(a,b,c){if(8192>a.byteLength){var d=new Int32Array(2048);(new Uint8Array(d.buffer)).set(new Uint8Array(a))}else d=new Int32Array(a,0,2048);for(var e=0;8192>e;e+=4){if(464367618===d[e>>2]){var f=d[e+4>>2];if(464367618+f+d[e+8>>2]|0)continue}else continue;sa("Multiboot magic found, flags: "+A(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n=
|
|
389
|
-
n);n+=q.length}if(f&2){p|=64;q=0;g.write32(31788,0);g.write32(31792,n);var r=0;var z=!1;for(let u=0;4294967296>u;u+=131072)z&&void 0!==g.memory_map_read8[u>>>17]?(g.write32(n,20),g.write32(n+4,r),g.write32(n+8,0),g.write32(n+12,u-r),g.write32(n+16,0),g.write32(n+20,1),n+=24,q+=24,z=!1):z||void 0!==g.memory_map_read8[u>>>17]||(r=u,z=!0);g.write32(31788,q)}g.write32(31744,p);q=p=0;if(f&65536){z=d[e+12>>
|
|
390
|
-
e-(z-p),0===y?void 0:y-p);g.write_blob(z,p);p=r|0;q=Math.max(y,q)}else if(1179403647===d[0]){r=new DataView(a);const [u,H]=Jb(r,xb);console.assert(52===H);console.assert(1179403647===u.magic,"Bad magic");console.assert(1===u.class,"Unimplemented: 64 bit elf");console.assert(1===u.data,"Unimplemented: big endian");console.assert(1===u.version0,"Bad version0");console.assert(2===u.type,"Unimplemented type");
|
|
391
|
-
console.assert(32===u.phentsize,"Bad program header size");console.assert(40===u.shentsize,"Bad section header size");[p]=Kb(new DataView(r.buffer,r.byteOffset+u.phoff,u.phentsize*u.phnum),yb,u.phnum);Kb(new DataView(r.buffer,r.byteOffset+u.shoff,u.shentsize*u.shnum),zb,u.shnum);r=u;z=p;p=r.entry;for(y of z)0!==y.type&&(1===y.type?y.paddr+y.memsz<g.memory_size[0]?(y.filesz&&(z=new Uint8Array(a,y.offset,y.filesz),
|
|
392
|
-
y.memsz>p&&(p=p-y.vaddr+y.paddr)):A(y.paddr):2===y.type||3===y.type||4===y.type||6===y.type||7===y.type||1685382480===y.type||1685382481===y.type||1685382482===y.type||1685382483===y.type||A(y.type))}b&&(g.write32(31764,1),g.write32(31768,n),y=q,0!==(y&4095)&&(y=(y&-4096)+4096),q=y+b.byteLength,g.write32(n,y),g.write32(n+4,q),g.write32(n+8,0),g.write32(n+12,0),g.write_blob(new Uint8Array(b),y));g.reg32[3]=31744;
|
|
393
|
-
n;n++)g.segment_is_null[n]=0,g.segment_offsets[n]=0,g.segment_limits[n]=4294967295,g.sreg[n]=45058;g.instruction_pointer[0]=g.get_seg_cs()+p|0;g.update_state_flags();g.debug.dump_state();g.debug.dump_regs();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+A(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){A(n);
|
|
394
|
-
n,this,p,p,p)}const l=new Uint8Array(512);(new Uint16Array(l.buffer))[0]=43605;l[2]=1;var k=3;l[k++]=102;l[k++]=229;l[k++]=244;let m=l[k]=0;for(let n=0;n<l.length;n++)m+=l[n];l[k]=-m;return{name:"genroms/multiboot.bin",data:l}}};K.prototype.fill_cmos=function(a,b){var c=b.boot_order||291;a.cmos_write(56,1|c>>4&240);a.cmos_write(61,c&255);a.cmos_write(21,128);a.cmos_write(22,2);c=0;1048576<=this.memory_size[0]&&
|
|
395
|
-
c>>8&255);a.cmos_write(48,c&255);a.cmos_write(49,c>>8&255);c=0;16777216<=this.memory_size[0]&&(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92,0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)};K.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=
|
|
396
|
-
786432);this.io.mmap_register(4272947200,1048576,function(e){e=e-4272947200|0;return e<d.length?d[e]:0},function(){})}this.io.mmap_register(4293918720,1048576,function(e){return this.mem8[e&1048575]}.bind(this),function(e,f){this.mem8[e&1048575]=f}.bind(this))}};K.prototype.codegen_finalize=function(a,b,c,d,e){const f=new Uint8Array(this.wasm_memory.buffer,d>>>0,e>>>0);WebAssembly.instantiate(f,
|
|
397
|
-
b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)})};K.prototype.log_uncompiled_code=function(){};K.prototype.dump_function_code=function(){};K.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};
|
|
398
|
-
function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};function mb(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=b.device_id;this.pci_space=[244,26,b.device_id&255,b.device_id>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,b.subsystem_device_id&255,b.subsystem_device_id>>
|
|
399
|
-
this.pci_bars=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature=new Uint32Array(4);this.driver_feature=new Uint32Array(4);for(var c of b.common.features)this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);b.common.features.includes(32);this.features_ok=!0;this.device_status=0;this.config_has_changed
|
|
400
|
-
this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification));c.push(this.create_isr_capability(b.isr_status));b.device_specific&&c.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(c);a.devices.pci.register_device(this);this.reset()}
|
|
401
|
-
name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=b}},{bytes:4,name:"driver_feature",
|
|
402
|
-
this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b&&this.reset();b&~this.device_status&
|
|
403
|
-
{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_select<this.queues.length?this.queues[this.queue_select]:null}},{bytes:2,name:"queue_size",read:()=>this.queue_selected?this.queue_selected.size:0,write:b=>
|
|
404
|
-
{bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&1===b&&this.queue_selected.is_configured()&&this.queue_selected.enable()}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:
|
|
405
|
-
(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_used (low dword)",
|
|
406
|
-
{bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}};mb.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0:2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+d,read:()=>65535,write:e||(()=>{})});return{type:2,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&
|
|
407
|
-
extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};mb.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};mb.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;
|
|
408
|
-
1;this.pci_bars[e.bar]={size:d};this.pci_space[c]=9;this.pci_space[c+1]=b;this.pci_space[c+2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&255;this.pci_space[c+9]=e.offset>>>8&255;this.pci_space[c+10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>24;this.pci_space[c+
|
|
409
|
-
16+f]=g;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let g=f.read;a=f.write;if(!e.use_mmio){d=function(l){return g(l&-2)>>((l&1)<<3)&255};const k=function(l){return g(l&-4)>>((l&3)<<3)&255};
|
|
410
|
-
3,this,k);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,g);this.cpu.io.register_read(c+1,this,d);this.cpu.io.register_write(c,this,void 0,a);break;case 1:this.cpu.io.register_read(c,this,g),this.cpu.io.register_write(c,this,a)}}c+=f.bytes}}this.pci_space[b]=9;this.pci_space[b+
|
|
411
|
-
|
|
412
|
-
this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};mb.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];
|
|
413
|
-
function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};mb.prototype.notify_config_changes=
|
|
414
|
-
(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};mb.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};mb.prototype.needs_reset=function(){this.device_status|=64;this.device_status&4&&this.notify_config_changes()};mb.prototype.raise_irq=function(a){A(a);this.isr_status|=a;
|
|
415
|
-
b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}W.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=this.enabled;a[3]=this.notify_offset;
|
|
416
|
-
function(a){this.size=a[0];this.size_supported=a[1];this.enabled=a[2];this.notify_offset=a[3];this.desc_addr=a[4];this.avail_addr=a[5];this.avail_last_idx=a[6];this.used_addr=a[7];this.num_staged_replies=a[8];this.mask=this.size-1;this.fix_wrapping=1!==a[9]};W.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=this.used_addr=this.avail_last_idx=
|
|
417
|
-
this.used_addr};W.prototype.enable=function(){this.is_configured();this.enabled=!0};W.prototype.set_size=function(a){this.size=a;this.mask=a-1};W.prototype.count_requests=function(){this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=(this.avail_get_idx()&~this.mask)+(this.avail_last_idx&this.mask));return this.avail_get_idx()-this.avail_last_idx&
|
|
418
|
-
a=new ac(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};W.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};W.prototype.flush_replies=function(){if(0!==this.num_staged_replies){var a=
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
2,a)};W.prototype.used_set_entry=function(a,b,c){this.cpu.write32(this.used_addr+4+8*a,b);this.cpu.write32(this.used_addr+8+8*a,c)};W.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function ac(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=
|
|
422
|
-
a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const k=a.get_descriptor(c,b);A(k.addr_high,8);A(k.addr_low,8);A(k.len,8);A(k.flags,4);A(k.next,4);if(g&&k.flags&4)c=k.addr_low,d=b=0,e=k.len/16;else{if(k.flags&2)f=!0,this.write_buffers.push(k),this.length_writable+=k.len;else{if(f)break;
|
|
423
|
-
this.read_buffers.length;){var d=this.read_buffers[this.read_buffer_idx];const e=d.addr_low+this.read_buffer_offset;d=d.len-this.read_buffer_offset;d>c?(d=c,this.read_buffer_offset+=c):(this.read_buffer_idx++,this.read_buffer_offset=0);a.set(this.cpu.read_blob(e,d),b);b+=d;c-=d}return b};ac.prototype.set_next_blob=
|
|
424
|
-
d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};function bc(){this.filedata=new Map}bc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,
|
|
425
|
-
this.storage=a;this.baseurl=b}cc.prototype.load_from_server=function(a){return new Promise(b=>{na(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};cc.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};cc.prototype.cache=
|
|
426
|
-
this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}X.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&16384)&&
|
|
427
|
-
new dc(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=a[1];this.inodedata={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};X.prototype.AddEvent=function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?
|
|
428
|
-
this.follow_fs(b).HandleEvent(b.foreign_id);b=[];for(var c=0;c<this.events.length;c++)this.events[c].id===a?this.events[c].OnEvent():b.push(this.events[c]);this.events=b};X.prototype.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";
|
|
429
|
-
this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&A(e)};X.prototype.LoadDir=function(a,
|
|
430
|
-
0===a.foreign_id};X.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);this.should_be_linked(d);e.direntries.has(c);e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(d.direntries.has(".."),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};X.prototype.unlink_from_dir=
|
|
431
|
-
e.direntries.delete(b)&&(d.nlinks--,this.IsDirectory(c)&&(d.direntries.get(".."),d.direntries.delete(".."),e.nlinks--))};X.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2):(L.Debug("Error in Filesystem: Pushed inode with name = "+
|
|
432
|
-
this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}dc.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&
|
|
433
|
-
a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};dc.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&
|
|
434
|
-
[];for(const b of a[2]){const c=new ec;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};X.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new dc(-1);this.IsDirectory(c);Object.assign(e,
|
|
435
|
-
f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [g,k]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(k)&&this.inodes[k].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};X.prototype.copy_inode=function(a,
|
|
436
|
-
1E3),b=new dc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};X.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,
|
|
437
|
-
1};X.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-
|
|
438
|
-
e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};X.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=
|
|
439
|
-
d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};X.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);
|
|
440
|
-
async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};X.prototype.OpenInode=function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return this.follow_fs(c).OpenInode(c.foreign_id,
|
|
441
|
-
async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};X.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var g=this.Unlink(c,d);if(0>g)return g}var k=
|
|
442
|
-
this.is_forwarder(g))if(this.is_forwarder(l)&&l.mount_id===g.mount_id){if(a=await this.follow_fs(l).Rename(l.foreign_id,b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e)||!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return-1;l=this.divert(a,b);const m=this.GetInode(e),n=await this.Read(l,0,m.size);this.is_forwarder(g)?(c=this.follow_fs(g),d=this.IsDirectory(l)?c.CreateDirectory(d,g.foreign_id):c.CreateFile(d,g.foreign_id),
|
|
443
|
-
d)):(this.delete_forwarder(k),this.copy_inode(m,k),this.link_under_dir(c,e,d));await this.ChangeSize(e,m.size);n&&n.length&&await this.Write(e,0,n.length,n);if(this.IsDirectory(e))for(const p of this.GetChildren(l))if(g=await this.Rename(l,p,e,p),0>g)return g;await this.DeleteData(l);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),k.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});
|
|
444
|
-
"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),e.size=b+c,f=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};X.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,
|
|
445
|
-
function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===b?-1:b};X.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};X.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=
|
|
446
|
-
this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};X.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};X.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;
|
|
447
|
-
for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};X.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):-1;if(this.is_forwarder(e))return-1;this.link_under_dir(a,b,c);return 0};X.prototype.Unlink=function(a,b){if("."===
|
|
448
|
-
e=this.inodes[a];if(this.is_forwarder(e))return this.is_forwarder(d),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};X.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};X.prototype.get_buffer=
|
|
449
|
-
this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size):null};X.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c):null};X.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};X.prototype.GetInode=
|
|
450
|
-
this.follow_fs(a).GetInode(a.foreign_id):a};X.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};X.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&a.shift();const b=
|
|
451
|
-
a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};X.prototype.GetRecursiveList=function(a,b){if(this.is_forwarder(this.inodes[a])){const c=this.follow_fs(this.inodes[a]),d=this.inodes[a].mount_id,e=b.length;c.GetRecursiveList(this.inodes[a].foreign_id,
|
|
452
|
-
d]of this.inodes[a].direntries)"."!==c&&".."!==c&&(b.push({parentid:a,name:c}),this.IsDirectory(d)&&this.GetRecursiveList(d,b))};X.prototype.RecursiveDelete=function(a){var b=[];a=this.SearchPath(a);if(-1!==a.id)for(this.GetRecursiveList(a.id,b),a=b.length-1;0<=a;a--)this.Unlink(b[a].parentid,b[a].name)};X.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&
|
|
453
|
-
this.Unlink(b.parentid,b.name)))};X.prototype.NotifyListeners=function(){};X.prototype.Check=function(){for(var a=1;a<this.inodes.length;a++)if(-1!==this.inodes[a].status){var b=this.GetInode(a);0>b.nlinks&&L.Debug("Error in filesystem: negative nlinks="+b.nlinks+" at id ="+a);if(this.IsDirectory(a)){b=this.GetInode(a);this.IsDirectory(a)&&0>this.GetParent(a)&&L.Debug("Error in filesystem: negative parent id "+
|
|
454
|
-
d);for(const e of c)32>e&&L.Debug("Error in filesystem: Unallowed char in filename")}}}};X.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);else{var c=0;for(const d of b.direntries.keys())c+=24+kb.encode(d).length;a=this.inodedata[a]=new Uint8Array(c);b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=
|
|
455
|
-
function(a,b){a=this.inodedata[a];if(b>=a.length)return a.length;let c=0;for(;;){const d=M.Unmarshall(["Q","d"],a,{offset:c})[1];if(d>b)break;c=d}return c};X.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):16384===(a.mode&61440)};X.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);
|
|
456
|
-
X.prototype.GetChildren=function(a){this.IsDirectory(a);a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).GetChildren(a.foreign_id);const b=[];for(const c of a.direntries.keys())"."!==c&&".."!==c&&b.push(c);return b};X.prototype.GetParent=function(a){this.IsDirectory(a);a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);return this.get_forwarder(a.mount_id,
|
|
457
|
-
if(a.caps)return a.caps.length;a.caps=new Uint8Array(20);a.caps[0]=0;a.caps[1]=0;a.caps[2]=0;a.caps[3]=2;a.caps[4]=255;a.caps[5]=255;a.caps[6]=255;a.caps[7]=255;a.caps[8]=255;a.caps[9]=255;a.caps[10]=255;a.caps[11]=255;a.caps[12]=63;a.caps[13]=0;a.caps[14]=0;a.caps[15]=0;a.caps[16]=63;a.caps[17]=0;a.caps[18]=0;a.caps[19]=0;return a.caps.length};function fc(a){this.fs=a;this.backtrack=new Map}fc.prototype.get_state=function(){const a=[];a[0]=
|
|
458
|
-
function(a){this.fs=a[0];this.backtrack=new Map(a[1])};X.prototype.set_forwarder=function(a,b,c){const d=this.inodes[a];this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.delete(d.foreign_id);d.status=5;d.mount_id=b;d.foreign_id=c;this.mounts[b].backtrack.set(c,a)};X.prototype.create_forwarder=function(a,b){const c=this.CreateInode(),d=this.inodes.length;this.inodes.push(c);c.fid=d;this.set_forwarder(d,a,b);return d};X.prototype.is_forwarder=
|
|
459
|
-
function(a){return 0===this.GetInode(a).fid};X.prototype.get_forwarder=function(a,b){const c=this.mounts[a].backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};X.prototype.delete_forwarder=function(a){this.is_forwarder(a);a.status=-1;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)};X.prototype.follow_fs=function(a){const b=this.mounts[a.mount_id];this.is_forwarder(a);return b.fs};X.prototype.Mount=function(a,b){a=this.SearchPath(a);
|
|
460
|
-
if(a.forward_path){var c=this.inodes[a.parentid];b=this.follow_fs(c).Mount(a.forward_path,b);return 0>b?b:this.get_forwarder(c.mount_id,b)}c=this.mounts.length;this.mounts.push(new fc(b));b=this.create_forwarder(c,0);this.link_under_dir(a.parentid,b,a.name);return b};function ec(){this.type=2;this.start=0;this.length=Infinity;this.proc_id=-1;this.client_id=""}ec.prototype.get_state=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===
|
|
461
|
-
this.client_id;return a};ec.prototype.set_state=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.proc_id=a[3];this.client_id=a[4]};ec.prototype.clone=function(){const a=new ec;a.set_state(this.get_state());return a};ec.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.client_id===a.client_id||2===this.type||2===a.type||1!==this.type&&1!==a.type||this.start+this.length<=a.start||a.start+a.length<=
|
|
462
|
-
this.proc_id&&a.client_id===this.client_id&&a.type===this.type};ec.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start};X.prototype.DescribeLock=function(a,b,c,d,e){const f=new ec;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};X.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();
|
|
463
|
-
function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c<d.locks.length;c++){a=d.locks[c];if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){a.conflicts_with(b);continue}var e=b.start+b.length;const f=b.start-a.start,g=a.start+a.length-e;if(0<f&&0<g&&a.type===b.type)return 0;
|
|
464
|
-
g)a.start=e,a.length=g;else if(0<g){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,g,a.proc_id,a.client_id))}else 0>=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=b.length,c=d.locks[e],a=!0),b.start<=d.locks[e].start);e++);a||(d.locks.splice(e,0,c),e++);for(;e<d.locks.length;e++)if(d.locks[e].is_alike(c)){d.locks[e].may_merge_after(c)&&(c.length+=
|
|
465
|
-
1));break}}return 0};X.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};X.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};const gc=["shared","exclusive","unlock"];function Ub(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=[104,111,115,116,57,112];
|
|
466
|
-
this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[];this.virtio=new mb(b,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[d=>{if(0===d){for(;this.virtqueue.has_request();)d=
|
|
467
|
-
this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,write:()=>{}}].concat(Array.from(Array(254).keys()).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:()=>{}})))}});this.virtqueue=this.virtio.queues[0]}Ub.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=
|
|
468
|
-
a[4]=this.BLOCKSIZE;a[5]=this.msize;a[6]=this.replybuffer;a[7]=this.replybuffersize;a[8]=this.fids.map(function(b){return[b.inodeid,b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a};Ub.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=a[5];this.replybuffer=a[6];this.replybuffersize=a[7];
|
|
469
|
-
uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};Ub.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};Ub.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Ub.prototype.reset=function(){this.fids=[];this.virtio.reset()};Ub.prototype.BuildReply=function(a,b,c){M.Marshall(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&L.Debug("Error in 9p: payloadsize exceeds maximum length");
|
|
470
|
-
c+7};Ub.prototype.SendError=function(a,b,c){b=M.Marshall(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};Ub.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};Ub.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=M.Unmarshall(["w","b","h"],b,c),e=d[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();
|
|
471
|
-
d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(b/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=M.Marshall("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 112:case 12:d=M.Unmarshall(["w","w"],b,c);var k=d[0];c=d[1];L.Debug("[open] fid="+k+", mode="+c);b=this.fids[k].inodeid;var l=this.fs.GetInode(b);L.Debug("file open "+this.fids[k].dbg_name);
|
|
472
|
-
c);this.fs.AddEvent(this.fids[k].inodeid,function(){L.Debug("file opened "+this.fids[k].dbg_name+" tag:"+g);var q=[];q[0]=l.qid;q[1]=this.msize-24;M.Marshall(["Q","w"],q,this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a)}.bind(this));break;case 70:d=M.Unmarshall(["w","w","s"],b,c);b=d[0];k=d[1];e=d[2];L.Debug("[link] dfid="+b+", name="+e);e=this.fs.Link(this.fids[b].inodeid,this.fids[k].inodeid,e);if(0>e){this.SendError(g,-1===e?"Operation not permitted":"Unknown error: "
|
|
473
|
-
break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=M.Unmarshall(["w","s","s","w"],b,c);k=d[0];e=d[1];b=d[2];d=d[3];L.Debug("[symlink] fid="+k+", name="+e+", symgt="+b+", gid="+d);b=this.fs.CreateSymlink(e,this.fids[k].inodeid,b);l=this.fs.GetInode(b);l.uid=this.fids[k].uid;l.gid=d;M.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 18:d=M.Unmarshall("wswwww".split(""),b,c);k=d[0];e=d[1];c=d[2];b=d[3];var m=d[4];d=d[5];
|
|
474
|
-
k+", name="+e+", major="+b+", minor="+m);b=this.fs.CreateNode(e,this.fids[k].inodeid,b,m);l=this.fs.GetInode(b);l.mode=c;l.uid=this.fids[k].uid;l.gid=d;M.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 22:d=M.Unmarshall(["w"],b,c);k=d[0];l=this.fs.GetInode(this.fids[k].inodeid);L.Debug("[readlink] fid="+k+" name="+this.fids[k].dbg_name+" target="+l.symlink);e=M.Marshall(["s"],[l.symlink],this.replybuffer,7);this.BuildReply(f,g,
|
|
475
|
-
case 72:d=M.Unmarshall(["w","s","w","w"],b,c);k=d[0];e=d[1];c=d[2];d=d[3];L.Debug("[mkdir] fid="+k+", name="+e+", mode="+c+", gid="+d);b=this.fs.CreateDirectory(e,this.fids[k].inodeid);l=this.fs.GetInode(b);l.mode=c|16384;l.uid=this.fids[k].uid;l.gid=d;M.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 14:d=M.Unmarshall(["w","s","w","w","w"],b,c);k=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[k].inodeid]);
|
|
476
|
-
k+", name="+e+", flags="+b+", mode="+c+", gid="+d);b=this.fs.CreateFile(e,this.fids[k].inodeid);this.fids[k].inodeid=b;this.fids[k].type=1;this.fids[k].dbg_name=e;l=this.fs.GetInode(b);l.uid=this.fids[k].uid;l.gid=d;l.mode=c|32768;M.Marshall(["Q","w"],[l.qid,this.msize-24],this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a);break;case 52:d=M.Unmarshall("wbwddws".split(""),b,c);k=d[0];b=d[2];e=0===d[4]?Infinity:d[4];d=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);L.Debug("[lock] fid="+
|
|
477
|
-
gc[d.type]+", start="+d.start+", length="+d.length+", proc_id="+d.proc_id);e=this.fs.Lock(this.fids[k].inodeid,d,b);M.Marshall(["b"],[e],this.replybuffer,7);this.BuildReply(f,g,1);this.SendReply(a);break;case 54:d=M.Unmarshall("wbddws".split(""),b,c);k=d[0];e=0===d[3]?Infinity:d[3];d=this.fs.DescribeLock(d[1],d[2],e,d[4],d[5]);L.Debug("[getlock] fid="+k+", type="+gc[d.type]+", start="+d.start+", length="+d.length+", proc_id="+d.proc_id);e=this.fs.GetLock(this.fids[k].inodeid,d);e||(e=
|
|
478
|
-
e=M.Marshall(["b","d","d","w","s"],[e.type,e.start,Infinity===e.length?0:e.length,e.proc_id,e.client_id],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 24:d=M.Unmarshall(["w","d"],b,c);k=d[0];l=this.fs.GetInode(this.fids[k].inodeid);L.Debug("[getattr]: fid="+k+" name="+this.fids[k].dbg_name+" request mask="+d[1]);if(!l||4===l.status){L.Debug("getattr: unlinked");this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;
|
|
479
|
-
d[4]=l.gid;d[5]=l.nlinks;d[6]=l.major<<8|l.minor;d[7]=l.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(l.size/512+1);d[10]=l.atime;d[11]=0;d[12]=l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;M.Marshall("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,g,153);this.SendReply(a);break;case 26:d=M.Unmarshall("wwwwwddddd".split(""),b,c);k=d[0];l=this.fs.GetInode(this.fids[k].inodeid);L.Debug("[setattr]: fid="+k+" request mask="+d[1]+" name="+this.fids[k].dbg_name);
|
|
379
|
+
K.prototype.unpack_memory=function(a,b){this.zero_memory(0,this.memory_size[0]);const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};K.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&this.devices.virtio_9p.reset();this.devices.virtio_console&&this.devices.virtio_console.reset();this.devices.virtio_net&&this.devices.virtio_net.reset();this.devices.ps2&&this.devices.ps2.reset();
|
|
380
|
+
this.load_bios()};K.prototype.reset_memory=function(){this.mem8.fill(0)};K.prototype.create_memory=function(a,b){a<b?a=b:0>(a|0)&&(a=Math.pow(2,31)-131072);a=(a-1|131071)+1|0;console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=v(Uint8Array,this.wasm_memory,b,a);this.mem32s=v(Uint32Array,this.wasm_memory,b,a>>2)};K.prototype.init=function(a,b){this.create_memory(a.memory_size||67108864,a.initrd?67108864:1048576);a.disable_jit&&
|
|
381
|
+
this.set_jit_config(0,1);a.cpuid_level&&this.set_cpuid_level(a.cpuid_level);this.acpi_enabled[0]=+a.acpi;this.reset_cpu();var c=new C(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=Tb(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,this,function(){return 0});var d=0;c.register_read(146,this,function(){return d});c.register_write(146,this,function(e){d=e});c.register_read(1297,this,function(){return this.fw_pointer<
|
|
382
|
+
this.fw_value.length?this.fw_value[this.fw_pointer++]:0});c.register_write(1296,this,void 0,function(e){function f(l){return new Uint8Array(Int32Array.of(l).buffer)}function g(l){return l>>8|l<<8&65280}function k(l){return l<<24|l<<8&16711680|l>>8&65280|l>>>24}sa("bios config port, index="+A(e));this.fw_pointer=0;if(0===e)this.fw_value=f(1431127377);else if(1===e)this.fw_value=f(0);else if(3===e)this.fw_value=f(this.memory_size[0]);else if(5===e)this.fw_value=f(1);else if(15===e)this.fw_value=f(1);
|
|
383
|
+
else if(13===e)this.fw_value=new Uint8Array(16);else if(25===e){e=new Int32Array(4+64*this.option_roms.length);const l=new Uint8Array(e.buffer);e[0]=k(this.option_roms.length);for(let m=0;m<this.option_roms.length;m++){const {name:n,data:p}=this.option_roms[m],q=4+64*m;e[q+0>>2]=k(p.length);e[q+4>>2]=g(49152+m);for(let r=0;r<n.length;r++)l[q+8+r]=n.charCodeAt(r)}this.fw_value=l}else 32768<=e&&49152>e?this.fw_value=f(0):49152<=e&&e-49152<this.option_roms.length?this.fw_value=this.option_roms[e-49152].data:
|
|
384
|
+
(sa("Warning: Unimplemented fw index: "+A(e)),this.fw_value=f(0))});c.register_read(32,this,this.port20_read);c.register_read(33,this,this.port21_read);c.register_read(160,this,this.portA0_read);c.register_read(161,this,this.portA1_read);c.register_write(32,this,this.port20_write);c.register_write(33,this,this.port21_write);c.register_write(160,this,this.portA0_write);c.register_write(161,this,this.portA1_write);c.register_read(1232,this,this.port4D0_read);c.register_read(1233,this,this.port4D1_read);
|
|
385
|
+
c.register_write(1232,this,this.port4D0_write);c.register_write(1233,this,this.port4D1_write);this.devices={};a.load_devices&&(this.devices.pci=new fb(this),this.acpi_enabled[0]&&(this.devices.ioapic=new bb(this),this.devices.apic=new ab(this),this.devices.acpi=new cb(this)),this.devices.rtc=new Lb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),this.devices.vga=new V(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new sb(this,b),this.devices.uart0=new eb(this,1016,
|
|
386
|
+
b),a.uart1&&(this.devices.uart1=new eb(this,760,b)),a.uart2&&(this.devices.uart2=new eb(this,1E3,b)),a.uart3&&(this.devices.uart3=new eb(this,744,b)),this.devices.fdc=new O(this,a.fda,a.fdb),c=0,a.hda&&(this.devices.hda=new Mb(this,a.hda,a.hdb,!1,c++,b)),a.cdrom&&(this.devices.cdrom=new Mb(this,a.cdrom,void 0,!0,c++,b)),this.devices.pit=new db(this,b),"ne2k"===a.net_device.type?this.devices.net=new ib(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&
|
|
387
|
+
(this.devices.virtio_net=new Nb(this,b,a.preserve_mac_from_state_image)),a.fs9p&&(this.devices.virtio_9p=new Ub(a.fs9p,this,b)),a.virtio_console&&(this.devices.virtio_console=new lb(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new Sb(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244))};K.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,
|
|
388
|
+
void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};K.prototype.load_multiboot_option_rom=function(a,b,c){if(8192>a.byteLength){var d=new Int32Array(2048);(new Uint8Array(d.buffer)).set(new Uint8Array(a))}else d=new Int32Array(a,0,2048);for(var e=0;8192>e;e+=4){if(464367618===d[e>>2]){var f=d[e+4>>2];if(464367618+f+d[e+8>>2]|0)continue}else continue;sa("Multiboot magic found, flags: "+A(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n=
|
|
389
|
+
31860,p=0;if(c){p|=4;g.write32(31760,n);c+="\x00";var q=(new TextEncoder).encode(c);g.write_blob(q,n);n+=q.length}if(f&2){p|=64;q=0;g.write32(31788,0);g.write32(31792,n);var r=0;var z=!1;for(let u=0;4294967296>u;u+=131072)z&&void 0!==g.memory_map_read8[u>>>17]?(g.write32(n,20),g.write32(n+4,r),g.write32(n+8,0),g.write32(n+12,u-r),g.write32(n+16,0),g.write32(n+20,1),n+=24,q+=24,z=!1):z||void 0!==g.memory_map_read8[u>>>17]||(r=u,z=!0);g.write32(31788,q)}g.write32(31744,p);q=p=0;if(f&65536){z=d[e+12>>
|
|
390
|
+
2];p=d[e+16>>2];var y=d[e+20>>2];q=d[e+24>>2];r=d[e+28>>2];A(z,8);A(p,8);A(y,8);A(q,8);A(r,8);z=new Uint8Array(a,e-(z-p),0===y?void 0:y-p);g.write_blob(z,p);p=r|0;q=Math.max(y,q)}else if(1179403647===d[0]){r=new DataView(a);const [u,H]=Jb(r,xb);console.assert(52===H);console.assert(1179403647===u.magic,"Bad magic");console.assert(1===u.class,"Unimplemented: 64 bit elf");console.assert(1===u.data,"Unimplemented: big endian");console.assert(1===u.version0,"Bad version0");console.assert(2===u.type,"Unimplemented type");
|
|
391
|
+
console.assert(1===u.version1,"Bad version1");console.assert(52===u.ehsize,"Bad header size");console.assert(32===u.phentsize,"Bad program header size");console.assert(40===u.shentsize,"Bad section header size");[p]=Kb(new DataView(r.buffer,r.byteOffset+u.phoff,u.phentsize*u.phnum),yb,u.phnum);Kb(new DataView(r.buffer,r.byteOffset+u.shoff,u.shentsize*u.shnum),zb,u.shnum);r=u;z=p;p=r.entry;for(y of z)0!==y.type&&(1===y.type?y.paddr+y.memsz<g.memory_size[0]?(y.filesz&&(z=new Uint8Array(a,y.offset,y.filesz),
|
|
392
|
+
g.write_blob(z,y.paddr)),q=Math.max(q,y.paddr+y.memsz),p===r.entry&&y.vaddr<=p&&y.vaddr+y.memsz>p&&(p=p-y.vaddr+y.paddr)):A(y.paddr):2===y.type||3===y.type||4===y.type||6===y.type||7===y.type||1685382480===y.type||1685382481===y.type||1685382482===y.type||1685382483===y.type||A(y.type))}b&&(g.write32(31764,1),g.write32(31768,n),y=q,0!==(y&4095)&&(y=(y&-4096)+4096),q=y+b.byteLength,g.write32(n,y),g.write32(n+4,q),g.write32(n+8,0),g.write32(n+12,0),g.write_blob(new Uint8Array(b),y));g.reg32[3]=31744;
|
|
393
|
+
g.cr[0]=1;g.protected_mode[0]=1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(n=0;6>n;n++)g.segment_is_null[n]=0,g.segment_offsets[n]=0,g.segment_limits[n]=4294967295,g.sreg[n]=45058;g.instruction_pointer[0]=g.get_seg_cs()+p|0;g.update_state_flags();g.debug.dump_state();g.debug.dump_regs();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+A(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){A(n);
|
|
394
|
+
A(q,2);q?this.device_raise_irq(n):this.device_lower_irq(n)}this.io.register_write(8192+n,this,p,p,p)}const l=new Uint8Array(512);(new Uint16Array(l.buffer))[0]=43605;l[2]=1;var k=3;l[k++]=102;l[k++]=229;l[k++]=244;let m=l[k]=0;for(let n=0;n<l.length;n++)m+=l[n];l[k]=-m;return{name:"genroms/multiboot.bin",data:l}}};K.prototype.fill_cmos=function(a,b){var c=b.boot_order||291;a.cmos_write(56,1|c>>4&240);a.cmos_write(61,c&255);a.cmos_write(21,128);a.cmos_write(22,2);c=0;1048576<=this.memory_size[0]&&
|
|
395
|
+
(c=this.memory_size[0]-1048576>>10,c=Math.min(c,65535));a.cmos_write(23,c&255);a.cmos_write(24,c>>8&255);a.cmos_write(48,c&255);a.cmos_write(49,c>>8&255);c=0;16777216<=this.memory_size[0]&&(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92,0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)};K.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=
|
|
396
|
+
new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){var d=new Uint8Array(b);this.write_blob(d,786432);this.io.mmap_register(4272947200,1048576,function(e){e=e-4272947200|0;return e<d.length?d[e]:0},function(){})}this.io.mmap_register(4293918720,1048576,function(e){return this.mem8[e&1048575]}.bind(this),function(e,f){this.mem8[e&1048575]=f}.bind(this))}};K.prototype.codegen_finalize=function(a,b,c,d,e){const f=new Uint8Array(this.wasm_memory.buffer,d>>>0,e>>>0);WebAssembly.instantiate(f,
|
|
397
|
+
{e:this.jit_imports}).then(g=>{this.wm.wasm_table.set(a+1024,g.instance.exports.f);this.codegen_finalize_finished(a,b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)})};K.prototype.log_uncompiled_code=function(){};K.prototype.dump_function_code=function(){};K.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};
|
|
398
|
+
K.prototype.device_raise_irq=function(a){this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};K.prototype.device_lower_irq=function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};function mb(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=b.device_id;this.pci_space=[244,26,b.device_id&255,b.device_id>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,b.subsystem_device_id&255,b.subsystem_device_id>>
|
|
399
|
+
8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.pci_space=this.pci_space.concat(Array(256-this.pci_space.length).fill(0));this.pci_id=b.pci_id;this.pci_bars=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature=new Uint32Array(4);this.driver_feature=new Uint32Array(4);for(var c of b.common.features)this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);b.common.features.includes(32);this.features_ok=!0;this.device_status=0;this.config_has_changed=
|
|
400
|
+
!1;this.config_generation=0;this.queues=[];for(const d of b.common.queues)this.queues.push(new W(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification));c.push(this.create_isr_capability(b.isr_status));b.device_specific&&c.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(c);a.devices.pci.register_device(this);this.reset()}
|
|
401
|
+
mb.prototype.create_common_capability=function(a){return{type:1,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=b}},{bytes:4,name:"driver_feature",
|
|
402
|
+
read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select<this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b&&this.reset();b&~this.device_status&
|
|
403
|
+
4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_select<this.queues.length?this.queues[this.queue_select]:null}},{bytes:2,name:"queue_size",read:()=>this.queue_selected?this.queue_selected.size:0,write:b=>
|
|
404
|
+
{this.queue_selected&&(b&b-1&&(b=1<<ca(b-1)+1),b>this.queue_selected.size_supported&&(b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&1===b&&this.queue_selected.is_configured()&&this.queue_selected.enable()}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:
|
|
405
|
+
0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_used (low dword)",
|
|
406
|
+
read:()=>this.queue_selected?this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}};mb.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0:2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+d,read:()=>65535,write:e||(()=>{})});return{type:2,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&
|
|
407
|
+
255,c>>24]),struct:b}};mb.prototype.create_isr_capability=function(a){return{type:3,bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};mb.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};mb.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;
|
|
408
|
+
var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;var d=e.struct.reduce((f,g)=>f+g.bytes,0);d+=e.offset;d=16>d?16:1<<ca(d-1)+1;this.pci_bars[e.bar]={size:d};this.pci_space[c]=9;this.pci_space[c+1]=b;this.pci_space[c+2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&255;this.pci_space[c+9]=e.offset>>>8&255;this.pci_space[c+10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>24;this.pci_space[c+
|
|
409
|
+
12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [f,g]of e.extra.entries())this.pci_space[c+16+f]=g;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let g=f.read;a=f.write;if(!e.use_mmio){d=function(l){return g(l&-2)>>((l&1)<<3)&255};const k=function(l){return g(l&-4)>>((l&3)<<3)&255};
|
|
410
|
+
switch(f.bytes){case 4:this.cpu.io.register_read(c,this,k,void 0,g);this.cpu.io.register_read(c+1,this,k);this.cpu.io.register_read(c+2,this,k);this.cpu.io.register_read(c+3,this,k);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,g);this.cpu.io.register_read(c+1,this,d);this.cpu.io.register_write(c,this,void 0,a);break;case 1:this.cpu.io.register_read(c,this,g),this.cpu.io.register_write(c,this,a)}}c+=f.bytes}}this.pci_space[b]=9;this.pci_space[b+
|
|
411
|
+
1]=0;this.pci_space[b+2]=20;this.pci_space[b+3]=5;this.pci_space[b+4]=0;this.pci_space[b+5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+18]=0;this.pci_space[b+19]=0};mb.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;a[1]=this.driver_feature_select;
|
|
412
|
+
a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};mb.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];
|
|
413
|
+
this.queue_select=a[9];let b=0;for(const c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null};mb.prototype.reset=function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};mb.prototype.notify_config_changes=
|
|
414
|
+
function(){this.config_has_changed=!0;this.device_status&4&&this.raise_irq(2)};mb.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};mb.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};mb.prototype.needs_reset=function(){this.device_status|=64;this.device_status&4&&this.notify_config_changes()};mb.prototype.raise_irq=function(a){A(a);this.isr_status|=a;
|
|
415
|
+
this.pci.raise_irq(this.pci_id)};mb.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_id)};function W(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}W.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=this.enabled;a[3]=this.notify_offset;
|
|
416
|
+
a[4]=this.desc_addr;a[5]=this.avail_addr;a[6]=this.avail_last_idx;a[7]=this.used_addr;a[8]=this.num_staged_replies;a[9]=1;return a};W.prototype.set_state=function(a){this.size=a[0];this.size_supported=a[1];this.enabled=a[2];this.notify_offset=a[3];this.desc_addr=a[4];this.avail_addr=a[5];this.avail_last_idx=a[6];this.used_addr=a[7];this.num_staged_replies=a[8];this.mask=this.size-1;this.fix_wrapping=1!==a[9]};W.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=this.used_addr=this.avail_last_idx=
|
|
417
|
+
this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};W.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};W.prototype.enable=function(){this.is_configured();this.enabled=!0};W.prototype.set_size=function(a){this.size=a;this.mask=a-1};W.prototype.count_requests=function(){this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=(this.avail_get_idx()&~this.mask)+(this.avail_last_idx&this.mask));return this.avail_get_idx()-this.avail_last_idx&
|
|
418
|
+
65535};W.prototype.has_request=function(){return 0!==this.count_requests()};W.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new ac(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};W.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};W.prototype.flush_replies=function(){if(0!==this.num_staged_replies){var a=
|
|
419
|
+
this.used_get_idx()+this.num_staged_replies&65535;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(29)?(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};W.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};W.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+16*b),addr_high:this.cpu.read32s(a+16*b+4),len:this.cpu.read32s(a+16*b+8),flags:this.cpu.read16(a+
|
|
420
|
+
16*b+12),next:this.cpu.read16(a+16*b+14)}};W.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};W.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};W.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};W.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};W.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};W.prototype.used_set_flags=
|
|
421
|
+
function(a){this.cpu.write16(this.used_addr,a)};W.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};W.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};W.prototype.used_set_entry=function(a,b,c){this.cpu.write32(this.used_addr+4+8*a,b);this.cpu.write32(this.used_addr+8+8*a,c)};W.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function ac(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=
|
|
422
|
+
[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const k=a.get_descriptor(c,b);A(k.addr_high,8);A(k.addr_low,8);A(k.len,8);A(k.flags,4);A(k.next,4);if(g&&k.flags&4)c=k.addr_low,d=b=0,e=k.len/16;else{if(k.flags&2)f=!0,this.write_buffers.push(k),this.length_writable+=k.len;else{if(f)break;
|
|
423
|
+
this.read_buffers.push(k);this.length_readable+=k.len}d++;if(d>e)break;if(k.flags&1)b=k.next;else break}}while(1)}ac.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c&&this.read_buffer_idx!==this.read_buffers.length;){var d=this.read_buffers[this.read_buffer_idx];const e=d.addr_low+this.read_buffer_offset;d=d.len-this.read_buffer_offset;d>c?(d=c,this.read_buffer_offset+=c):(this.read_buffer_idx++,this.read_buffer_offset=0);a.set(this.cpu.read_blob(e,d),b);b+=d;c-=d}return b};ac.prototype.set_next_blob=
|
|
424
|
+
function(a){let b=0,c=a.length;for(;c&&this.write_buffer_idx!==this.write_buffers.length;){var d=this.write_buffers[this.write_buffer_idx];const e=d.addr_low+this.write_buffer_offset;d=d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};function bc(){this.filedata=new Map}bc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,
|
|
425
|
+
b+c):null};bc.prototype.cache=async function(a,b){this.filedata.set(a,b)};bc.prototype.uncache=function(a){this.filedata.delete(a)};function cc(a,b){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}cc.prototype.load_from_server=function(a){return new Promise(b=>{na(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};cc.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};cc.prototype.cache=
|
|
426
|
+
async function(a,b){return await this.storage.cache(a,b)};cc.prototype.uncache=function(a){this.storage.uncache(a)};function X(a,b){this.inodes=[];this.events=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}X.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&16384)&&
|
|
427
|
+
a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};X.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new dc(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=a[1];this.inodedata={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};X.prototype.AddEvent=function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?
|
|
428
|
+
this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})};X.prototype.HandleEvent=function(a){var b=this.inodes[a];this.is_forwarder(b)&&this.follow_fs(b).HandleEvent(b.foreign_id);b=[];for(var c=0;c<this.events.length;c++)this.events[c].id===a?this.events[c].OnEvent():b.push(this.events[c]);this.events=b};X.prototype.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";
|
|
429
|
+
var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};X.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&A(e)};X.prototype.LoadDir=function(a,
|
|
430
|
+
b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};X.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};X.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);this.should_be_linked(d);e.direntries.has(c);e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(d.direntries.has(".."),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};X.prototype.unlink_from_dir=
|
|
431
|
+
function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);e.direntries.delete(b)&&(d.nlinks--,this.IsDirectory(c)&&(d.direntries.get(".."),d.direntries.delete(".."),e.nlinks--))};X.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2):(L.Debug("Error in Filesystem: Pushed inode with name = "+
|
|
432
|
+
c+" has no parent"),L.Abort())};function dc(a){this.direntries=new Map;this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}dc.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&
|
|
433
|
+
61440)?this.symlink:49152===(this.mode&61440)?[this.minor,this.major]:null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};dc.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&
|
|
434
|
+
61440)?this.symlink=a[1]:49152===(this.mode&61440)&&([this.minor,this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new ec;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};X.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new dc(-1);this.IsDirectory(c);Object.assign(e,
|
|
435
|
+
d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [g,k]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(k)&&this.inodes[k].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};X.prototype.copy_inode=function(a,
|
|
436
|
+
b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};X.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new dc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};X.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,
|
|
437
|
+
c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};X.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-
|
|
438
|
+
1,"newfile");return this.inodes.length-1};X.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};X.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=
|
|
439
|
+
d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};X.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);
|
|
440
|
+
b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};X.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};X.prototype.OpenInode=function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return this.follow_fs(c).OpenInode(c.foreign_id,
|
|
441
|
+
b);16384===(c.mode&61440)&&this.FillDirectory(a);return!0};X.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};X.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var g=this.Unlink(c,d);if(0>g)return g}var k=
|
|
442
|
+
this.inodes[e],l=this.inodes[a];g=this.inodes[c];if(this.is_forwarder(l)||this.is_forwarder(g))if(this.is_forwarder(l)&&l.mount_id===g.mount_id){if(a=await this.follow_fs(l).Rename(l.foreign_id,b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e)||!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return-1;l=this.divert(a,b);const m=this.GetInode(e),n=await this.Read(l,0,m.size);this.is_forwarder(g)?(c=this.follow_fs(g),d=this.IsDirectory(l)?c.CreateDirectory(d,g.foreign_id):c.CreateFile(d,g.foreign_id),
|
|
443
|
+
c=c.GetInode(d),this.copy_inode(m,c),this.set_forwarder(e,g.mount_id,d)):(this.delete_forwarder(k),this.copy_inode(m,k),this.link_under_dir(c,e,d));await this.ChangeSize(e,m.size);n&&n.length&&await this.Write(e,0,n.length,n);if(this.IsDirectory(e))for(const p of this.GetChildren(l))if(g=await this.Rename(l,p,e,p),0>g)return g;await this.DeleteData(l);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),k.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});
|
|
444
|
+
return 0};X.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),e.size=b+c,f=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};X.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,
|
|
445
|
+
await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};X.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===b?-1:b};X.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};X.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=
|
|
446
|
+
b.CountFreeInodes();return a};X.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};X.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};X.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;
|
|
447
|
+
return""};X.prototype.GetFullPath=function(a){this.IsDirectory(a);for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};X.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):-1;if(this.is_forwarder(e))return-1;this.link_under_dir(a,b,c);return 0};X.prototype.Unlink=function(a,b){if("."===
|
|
448
|
+
b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return this.is_forwarder(d),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};X.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};X.prototype.get_buffer=
|
|
449
|
+
async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size):null};X.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c):null};X.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};X.prototype.GetInode=
|
|
450
|
+
function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};X.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};X.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&a.shift();const b=
|
|
451
|
+
a.length;var c=-1,d=0;let e=null;for(var f=0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};X.prototype.GetRecursiveList=function(a,b){if(this.is_forwarder(this.inodes[a])){const c=this.follow_fs(this.inodes[a]),d=this.inodes[a].mount_id,e=b.length;c.GetRecursiveList(this.inodes[a].foreign_id,
|
|
452
|
+
b);for(a=e;a<b.length;a++)b[a].parentid=this.get_forwarder(d,b[a].parentid)}else for(const [c,d]of this.inodes[a].direntries)"."!==c&&".."!==c&&(b.push({parentid:a,name:c}),this.IsDirectory(d)&&this.GetRecursiveList(d,b))};X.prototype.RecursiveDelete=function(a){var b=[];a=this.SearchPath(a);if(-1!==a.id)for(this.GetRecursiveList(a.id,b),a=b.length-1;0<=a;a--)this.Unlink(b[a].parentid,b[a].name)};X.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&
|
|
453
|
+
61440)?this.Unlink(b.parentid,b.name):16384===(this.inodes[b.id].mode&61440)&&(this.RecursiveDelete(a),this.Unlink(b.parentid,b.name)))};X.prototype.NotifyListeners=function(){};X.prototype.Check=function(){for(var a=1;a<this.inodes.length;a++)if(-1!==this.inodes[a].status){var b=this.GetInode(a);0>b.nlinks&&L.Debug("Error in filesystem: negative nlinks="+b.nlinks+" at id ="+a);if(this.IsDirectory(a)){b=this.GetInode(a);this.IsDirectory(a)&&0>this.GetParent(a)&&L.Debug("Error in filesystem: negative parent id "+
|
|
454
|
+
a);for(const [c,d]of b.direntries){0===c.length&&L.Debug("Error in filesystem: inode with no name and id "+d);for(const e of c)32>e&&L.Debug("Error in filesystem: Unallowed char in filename")}}}};X.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);else{var c=0;for(const d of b.direntries.keys())c+=24+kb.encode(d).length;a=this.inodedata[a]=new Uint8Array(c);b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=
|
|
455
|
+
M.Marshall(["Q","d","b","s"],[b.qid,c+13+8+1+2+kb.encode(d).length,b.mode>>12,d],a,c)}};X.prototype.RoundToDirentry=function(a,b){a=this.inodedata[a];if(b>=a.length)return a.length;let c=0;for(;;){const d=M.Unmarshall(["Q","d"],a,{offset:c})[1];if(d>b)break;c=d}return c};X.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):16384===(a.mode&61440)};X.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);
|
|
456
|
+
for(const b of a.direntries.keys())if("."!==b&&".."!==b)return!1;return!0};X.prototype.GetChildren=function(a){this.IsDirectory(a);a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).GetChildren(a.foreign_id);const b=[];for(const c of a.direntries.keys())"."!==c&&".."!==c&&b.push(c);return b};X.prototype.GetParent=function(a){this.IsDirectory(a);a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);return this.get_forwarder(a.mount_id,
|
|
457
|
+
b)};X.prototype.PrepareCAPs=function(a){a=this.GetInode(a);if(a.caps)return a.caps.length;a.caps=new Uint8Array(20);a.caps[0]=0;a.caps[1]=0;a.caps[2]=0;a.caps[3]=2;a.caps[4]=255;a.caps[5]=255;a.caps[6]=255;a.caps[7]=255;a.caps[8]=255;a.caps[9]=255;a.caps[10]=255;a.caps[11]=255;a.caps[12]=63;a.caps[13]=0;a.caps[14]=0;a.caps[15]=0;a.caps[16]=63;a.caps[17]=0;a.caps[18]=0;a.caps[19]=0;return a.caps.length};function fc(a){this.fs=a;this.backtrack=new Map}fc.prototype.get_state=function(){const a=[];a[0]=
|
|
458
|
+
this.fs;a[1]=[...this.backtrack];return a};fc.prototype.set_state=function(a){this.fs=a[0];this.backtrack=new Map(a[1])};X.prototype.set_forwarder=function(a,b,c){const d=this.inodes[a];this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.delete(d.foreign_id);d.status=5;d.mount_id=b;d.foreign_id=c;this.mounts[b].backtrack.set(c,a)};X.prototype.create_forwarder=function(a,b){const c=this.CreateInode(),d=this.inodes.length;this.inodes.push(c);c.fid=d;this.set_forwarder(d,a,b);return d};X.prototype.is_forwarder=
|
|
459
|
+
function(a){return 5===a.status};X.prototype.is_a_root=function(a){return 0===this.GetInode(a).fid};X.prototype.get_forwarder=function(a,b){const c=this.mounts[a].backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};X.prototype.delete_forwarder=function(a){this.is_forwarder(a);a.status=-1;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)};X.prototype.follow_fs=function(a){const b=this.mounts[a.mount_id];this.is_forwarder(a);return b.fs};X.prototype.Mount=function(a,b){a=this.SearchPath(a);
|
|
460
|
+
if(-1===a.parentid)return-2;if(-1!==a.id)return-17;if(a.forward_path){var c=this.inodes[a.parentid];b=this.follow_fs(c).Mount(a.forward_path,b);return 0>b?b:this.get_forwarder(c.mount_id,b)}c=this.mounts.length;this.mounts.push(new fc(b));b=this.create_forwarder(c,0);this.link_under_dir(a.parentid,b,a.name);return b};function ec(){this.type=2;this.start=0;this.length=Infinity;this.proc_id=-1;this.client_id=""}ec.prototype.get_state=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===
|
|
461
|
+
this.length?0:this.length;a[3]=this.proc_id;a[4]=this.client_id;return a};ec.prototype.set_state=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.proc_id=a[3];this.client_id=a[4]};ec.prototype.clone=function(){const a=new ec;a.set_state(this.get_state());return a};ec.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.client_id===a.client_id||2===this.type||2===a.type||1!==this.type&&1!==a.type||this.start+this.length<=a.start||a.start+a.length<=
|
|
462
|
+
this.start?!1:!0};ec.prototype.is_alike=function(a){return a.proc_id===this.proc_id&&a.client_id===this.client_id&&a.type===this.type};ec.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start};X.prototype.DescribeLock=function(a,b,c,d,e){const f=new ec;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};X.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();
|
|
463
|
+
return null};X.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c<d.locks.length;c++){a=d.locks[c];if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){a.conflicts_with(b);continue}var e=b.start+b.length;const f=b.start-a.start,g=a.start+a.length-e;if(0<f&&0<g&&a.type===b.type)return 0;
|
|
464
|
+
0<f&&(a.length=f);if(0>=f&&0<g)a.start=e,a.length=g;else if(0<g){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,g,a.proc_id,a.client_id))}else 0>=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=b.length,c=d.locks[e],a=!0),b.start<=d.locks[e].start);e++);a||(d.locks.splice(e,0,c),e++);for(;e<d.locks.length;e++)if(d.locks[e].is_alike(c)){d.locks[e].may_merge_after(c)&&(c.length+=
|
|
465
|
+
d.locks[e].length,d.locks.splice(e,1));break}}return 0};X.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};X.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};const gc=["shared","exclusive","unlock"];function Ub(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=[104,111,115,116,57,112];
|
|
466
|
+
this.configspace_taglen=this.configspace_tagname.length;this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[];this.virtio=new mb(b,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[d=>{if(0===d){for(;this.virtqueue.has_request();)d=
|
|
467
|
+
this.virtqueue.pop_request(),this.ReceiveRequest(d);this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,write:()=>{}}].concat(Array.from(Array(254).keys()).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:()=>{}})))}});this.virtqueue=this.virtio.queues[0]}Ub.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=
|
|
468
|
+
this.configspace_taglen;a[2]=this.virtio;a[3]=this.VERSION;a[4]=this.BLOCKSIZE;a[5]=this.msize;a[6]=this.replybuffer;a[7]=this.replybuffersize;a[8]=this.fids.map(function(b){return[b.inodeid,b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a};Ub.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=a[5];this.replybuffer=a[6];this.replybuffersize=a[7];
|
|
469
|
+
this.fids=a[8].map(function(b){return{inodeid:b[0],type:b[1],uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};Ub.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};Ub.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Ub.prototype.reset=function(){this.fids=[];this.virtio.reset()};Ub.prototype.BuildReply=function(a,b,c){M.Marshall(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&L.Debug("Error in 9p: payloadsize exceeds maximum length");
|
|
470
|
+
this.replybuffersize=c+7};Ub.prototype.SendError=function(a,b,c){b=M.Marshall(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};Ub.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};Ub.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=M.Unmarshall(["w","b","h"],b,c),e=d[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();
|
|
471
|
+
b=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(b/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=M.Marshall("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 112:case 12:d=M.Unmarshall(["w","w"],b,c);var k=d[0];c=d[1];L.Debug("[open] fid="+k+", mode="+c);b=this.fids[k].inodeid;var l=this.fs.GetInode(b);L.Debug("file open "+this.fids[k].dbg_name);
|
|
472
|
+
e=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[k].inodeid,function(){L.Debug("file opened "+this.fids[k].dbg_name+" tag:"+g);var q=[];q[0]=l.qid;q[1]=this.msize-24;M.Marshall(["Q","w"],q,this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a)}.bind(this));break;case 70:d=M.Unmarshall(["w","w","s"],b,c);b=d[0];k=d[1];e=d[2];L.Debug("[link] dfid="+b+", name="+e);e=this.fs.Link(this.fids[b].inodeid,this.fids[k].inodeid,e);if(0>e){this.SendError(g,-1===e?"Operation not permitted":"Unknown error: "+
|
|
473
|
+
-e,-e);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=M.Unmarshall(["w","s","s","w"],b,c);k=d[0];e=d[1];b=d[2];d=d[3];L.Debug("[symlink] fid="+k+", name="+e+", symgt="+b+", gid="+d);b=this.fs.CreateSymlink(e,this.fids[k].inodeid,b);l=this.fs.GetInode(b);l.uid=this.fids[k].uid;l.gid=d;M.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 18:d=M.Unmarshall("wswwww".split(""),b,c);k=d[0];e=d[1];c=d[2];b=d[3];var m=d[4];d=d[5];
|
|
474
|
+
L.Debug("[mknod] fid="+k+", name="+e+", major="+b+", minor="+m);b=this.fs.CreateNode(e,this.fids[k].inodeid,b,m);l=this.fs.GetInode(b);l.mode=c;l.uid=this.fids[k].uid;l.gid=d;M.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 22:d=M.Unmarshall(["w"],b,c);k=d[0];l=this.fs.GetInode(this.fids[k].inodeid);L.Debug("[readlink] fid="+k+" name="+this.fids[k].dbg_name+" target="+l.symlink);e=M.Marshall(["s"],[l.symlink],this.replybuffer,7);this.BuildReply(f,g,
|
|
475
|
+
e);this.SendReply(a);break;case 72:d=M.Unmarshall(["w","s","w","w"],b,c);k=d[0];e=d[1];c=d[2];d=d[3];L.Debug("[mkdir] fid="+k+", name="+e+", mode="+c+", gid="+d);b=this.fs.CreateDirectory(e,this.fids[k].inodeid);l=this.fs.GetInode(b);l.mode=c|16384;l.uid=this.fids[k].uid;l.gid=d;M.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 14:d=M.Unmarshall(["w","s","w","w","w"],b,c);k=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[k].inodeid]);
|
|
476
|
+
L.Debug("[create] fid="+k+", name="+e+", flags="+b+", mode="+c+", gid="+d);b=this.fs.CreateFile(e,this.fids[k].inodeid);this.fids[k].inodeid=b;this.fids[k].type=1;this.fids[k].dbg_name=e;l=this.fs.GetInode(b);l.uid=this.fids[k].uid;l.gid=d;l.mode=c|32768;M.Marshall(["Q","w"],[l.qid,this.msize-24],this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a);break;case 52:d=M.Unmarshall("wbwddws".split(""),b,c);k=d[0];b=d[2];e=0===d[4]?Infinity:d[4];d=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);L.Debug("[lock] fid="+
|
|
477
|
+
k+", type="+gc[d.type]+", start="+d.start+", length="+d.length+", proc_id="+d.proc_id);e=this.fs.Lock(this.fids[k].inodeid,d,b);M.Marshall(["b"],[e],this.replybuffer,7);this.BuildReply(f,g,1);this.SendReply(a);break;case 54:d=M.Unmarshall("wbddws".split(""),b,c);k=d[0];e=0===d[3]?Infinity:d[3];d=this.fs.DescribeLock(d[1],d[2],e,d[4],d[5]);L.Debug("[getlock] fid="+k+", type="+gc[d.type]+", start="+d.start+", length="+d.length+", proc_id="+d.proc_id);e=this.fs.GetLock(this.fids[k].inodeid,d);e||(e=
|
|
478
|
+
d,e.type=2);e=M.Marshall(["b","d","d","w","s"],[e.type,e.start,Infinity===e.length?0:e.length,e.proc_id,e.client_id],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 24:d=M.Unmarshall(["w","d"],b,c);k=d[0];l=this.fs.GetInode(this.fids[k].inodeid);L.Debug("[getattr]: fid="+k+" name="+this.fids[k].dbg_name+" request mask="+d[1]);if(!l||4===l.status){L.Debug("getattr: unlinked");this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;
|
|
479
|
+
d[3]=l.uid;d[4]=l.gid;d[5]=l.nlinks;d[6]=l.major<<8|l.minor;d[7]=l.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(l.size/512+1);d[10]=l.atime;d[11]=0;d[12]=l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;M.Marshall("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,g,153);this.SendReply(a);break;case 26:d=M.Unmarshall("wwwwwddddd".split(""),b,c);k=d[0];l=this.fs.GetInode(this.fids[k].inodeid);L.Debug("[setattr]: fid="+k+" request mask="+d[1]+" name="+this.fids[k].dbg_name);
|
|
480
480
|
d[1]&1&&(l.mode=d[2]);d[1]&2&&(l.uid=d[3]);d[1]&4&&(l.gid=d[4]);d[1]&16&&(l.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(l.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(l.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(l.atime=d[6]);d[1]&256&&(l.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[k].inodeid,d[5]);this.BuildReply(f,g,0);this.SendReply(a);break;case 50:d=M.Unmarshall(["w","d"],b,c);k=d[0];this.BuildReply(f,g,0);this.SendReply(a);break;case 40:case 116:d=M.Unmarshall(["w",
|
|
481
481
|
"d","w"],b,c);k=d[0];e=d[1];m=d[2];l=this.fs.GetInode(this.fids[k].inodeid);40===f&&L.Debug("[treaddir]: fid="+k+" offset="+e+" count="+m);116===f&&L.Debug("[read]: fid="+k+" ("+this.fids[k].dbg_name+") offset="+e+" count="+m+" fidtype="+this.fids[k].type);if(!l||4===l.status){L.Debug("read/treaddir: unlinked");this.SendError(g,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[k].type)for(l.caps.length<e+m&&(m=l.caps.length-e),d=0;d<m;d++)this.replybuffer[11+d]=l.caps[e+d];else this.fs.OpenInode(this.fids[k].inodeid,
|
|
482
482
|
void 0),d=this.fids[k].inodeid,m=Math.min(m,this.replybuffer.length-11),l.size<e+m?m=l.size-e:40===f&&(m=this.fs.RoundToDirentry(d,e+m)-e),e>l.size&&(m=0),this.bus.send("9p-read-start",[this.fids[k].dbg_name]),d=await this.fs.Read(d,e,m),this.bus.send("9p-read-end",[this.fids[k].dbg_name,m]),d&&this.replybuffer.set(d,11);M.Marshall(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4+m);this.SendReply(a);break;case 118:d=M.Unmarshall(["w","d","w"],b,c);k=d[0];e=d[1];m=d[2];d=this.fids[k].dbg_name;
|