v86 0.5.194 → 0.5.199
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 +173 -31
- package/build/libv86-debug.mjs +150 -143
- package/build/libv86.js +96 -87
- package/build/libv86.mjs +148 -140
- package/package.json +1 -1
package/build/libv86-debug.mjs
CHANGED
|
@@ -10,24 +10,24 @@ c.done(new Uint8Array(f))}else d=await a.readFile(b,{encoding:c.as_json?"utf-8":
|
|
|
10
10
|
h=0;h<f.length;h++){var l=f[h];e.setRequestHeader(l,b.headers[l])}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 "+a+" failed (status %d)",e.status),
|
|
11
11
|
500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const m=e.getResponseHeader("Content-Encoding");m&&"identity"!==m&&console.error("Server sent Content-Encoding in response to ranged request",{filename:a,enc:m})}b.done&&b.done(e.response,e)}};e.onerror=function(m){console.error("Loading the image "+a+" failed",m);d()};b.progress&&(e.onprogress=function(m){b.progress(m)});e.send(null)},ua=async function(a){return new Promise((b,c)=>{sa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||
|
|
12
12
|
"";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};var va=-15786961;const B=function(){const a=aa.reduce(function(d,e){d[e[0]]=e[1];return d},{});var b="",c=0;return function(d,e){e=e||1;if(e&va){d="["+ca(a[e]||"",4)+"] "+d;if(d===b&&(c++,2048>c))return;e=new Date;e=da(e.getHours(),2)+":"+da(e.getMinutes(),2)+":"+da(e.getSeconds(),2)+"+"+da(e.getMilliseconds(),3)+" ";c&&(1===c?console.log(e+
|
|
13
|
-
b):console.log("Previous message repeated "+c+" times"),c=0);console.log(e+d);b=d}}}();function k(a,b){if(!a){debugger;console.trace();if(b)throw"Assert failed: "+b;throw"Assert failed";}}function wa(a,b){function c(y){y=y.toString(16);return"#"+"0".repeat(6-y.length)+y}function d(y){var w=256*qa,G=8*T,M=
|
|
14
|
-
U||ba;S[R+3]=ba;S[R+7]=ba;R+=8}:function(ba){U=U||ba;S[R+3]=ba;R+=4};M=32-T;const ma=w*(T-1)*4;w=4*(qa-w*T);const ja=1020*qa;for(let ba=0,ta=0;2048>ba;++ba,ta+=M,R+=w){const
|
|
13
|
+
b):console.log("Previous message repeated "+c+" times"),c=0);console.log(e+d);b=d}}}();function k(a,b){if(!a){debugger;console.trace();if(b)throw"Assert failed: "+b;throw"Assert failed";}}function wa(a,b){function c(y){y=y.toString(16);return"#"+"0".repeat(6-y.length)+y}function d(y){var w=256*qa,G=8*T,M=Xa?Xa.canvas:null;M&&M.width===w&&M.height===G||(M?(M.width=w,M.height=G):(M=new OffscreenCanvas(w,G),Xa=M.getContext("2d")),Mb=Xa.createImageData(w,G));const S=Mb.data;let R=0,U;G=Nb?function(ba){U=
|
|
14
|
+
U||ba;S[R+3]=ba;S[R+7]=ba;R+=8}:function(ba){U=U||ba;S[R+3]=ba;R+=4};M=32-T;const ma=w*(T-1)*4;w=4*(qa-w*T);const ja=1020*qa;for(let ba=0,ta=0;2048>ba;++ba,ta+=M,R+=w){const Ia=ba%256;ba&&!Ia&&(R+=ma);U=!1;for(let Oa=0;Oa<T;++Oa,++ta,R+=ja){const Pa=y[ta];for(let ya=128;0<ya;ya>>=1)G(Pa&ya?255:0);Ob&&G(Pb&&192<=Ia&&223>=Ia&&Pa&1?255:0)}gc[ba]=U?1:0}Xa.putImageData(Mb,0,0)}function e(y,w,G,M){if(w&&G){y.style.width="";y.style.height="";M&&(y.style.transform="");var S=y.getBoundingClientRect();M?y.style.transform=
|
|
15
15
|
(1===w?"":" scaleX("+w+")")+(1===G?"":" scaleY("+G+")"):(0===w%1&&0===G%1?(h.style.imageRendering="crisp-edges",h.style.imageRendering="pixelated",h.style["-ms-interpolation-mode"]="nearest-neighbor"):(h.style.imageRendering="",h.style["-ms-interpolation-mode"]=""),M=window.devicePixelRatio||1,0!==M%1&&(w/=M,G/=M));1!==w&&(y.style.width=S.width*w+"px");1!==G&&(y.style.height=S.height*G+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=
|
|
16
|
-
1;this.FLAG_FONT_PAGE_B=2;var h=f.getElementsByTagName("canvas")[0],l=h.getContext("2d",{alpha:!1}),m=f.getElementsByTagName("div")[0],p=document.createElement("div"),q,r,v=void 0!==a.scale?a.scale:1,t=void 0!==a.scale?a.scale:1,z=1,A,u,E,F,x,N,V,
|
|
16
|
+
1;this.FLAG_FONT_PAGE_B=2;var h=f.getElementsByTagName("canvas")[0],l=h.getContext("2d",{alpha:!1}),m=f.getElementsByTagName("div")[0],p=document.createElement("div"),q,r,v=void 0!==a.scale?a.scale:1,t=void 0!==a.scale?a.scale:1,z=1,A,u,E,F,x,N,V,Xa,Mb,gc=new Int8Array(2048),T,qa,Ob,Nb,Pb,Qb=0,Rb=0,vb,hc=0,wb,Sb,xb,Tb=[],lb=Tb,yb=0,Ub=!1;this.init=function(){const y=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,
|
|
17
17
|
8593,8595,8594,8592,8735,8596,9650,9660]),w=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,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,
|
|
18
|
-
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 G=0,M;256>G;G++)M=126<G?w[G-127]:32>G?y[G]:G,
|
|
19
|
-
function(){const y=new Image;if(1===u||2===u)y.src=h.toDataURL("image/png");else{const w=[9,16],G=document.createElement("canvas");G.width=F*w[0];G.height=x*w[1];const M=G.getContext("2d");M.imageSmoothingEnabled=!1;M.font=window.getComputedStyle(m).font;M.textBaseline="top";for(let S=0;S<x;S++)for(let R=0;R<F;R++){const U=4*(S*F+R),ma=E[U+0],ja=E[U+3];M.fillStyle=c(E[U+2]);M.fillRect(R*w[0],S*w[1],w[0],w[1]);M.fillStyle=c(ja);M.fillText(
|
|
20
|
-
p.style.backgroundColor,M.fillRect(r*w[0],q*w[1]+parseInt(p.style.marginTop,10),parseInt(p.style.width,10),parseInt(p.style.height,10)));y.src=G.toDataURL("image/png")}return y};this.put_char=function(y,w,G,M,S,R){k(0<=y&&y<x);k(0<=w&&w<F);k(0<=G&&256>G);w=4*(y*F+w);E[w+0]=G;E[w+1]=M;E[w+2]=S;E[w+3]=R;A[y]=1};this.timer=function(){
|
|
21
|
-
this.timer()};this.update_text=function(){for(var y=0;y<x;y++)A[y]&&(this.text_update_row(y),A[y]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(N){var y=performance.now();if(266<y-
|
|
22
|
-
continue}++U;V.clearRect(0,R,S,T);let ta,
|
|
23
|
-
0,S,T);V.globalCompositeOperation="source-over";N.fillStyle=c(
|
|
24
|
-
0===u?(m.style.display="block",h.style.display="none"):(m.style.display="none",h.style.display="block",2===u&&A&&A.fill(1))};this.set_font_bitmap=function(y,w,G,M,S,R){const U=G?16:w?9:8;if(T!==y||qa!==U||
|
|
25
|
-
function(){if(
|
|
26
|
-
w;)m.appendChild(document.createElement("div"));for(y=0;y<w;y++)this.text_update_row(y);e(m,v,t,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(y,w){h.style.display="block";h.width=y;h.height=w;l.imageSmoothingEnabled=!1;z=640>=y&&2*y<window.innerWidth*window.devicePixelRatio&&2*w<window.innerHeight*window.devicePixelRatio?2:1;e(h,v*z,t*z,!1)};this.set_charmap=function(y){
|
|
27
|
-
function(y,w,G){if(y!==
|
|
28
|
-
U.style.backgroundColor=c(ja);U.style.color=c(ba);for(G="";R<F&&(E[w+1]&1)===ma&&E[w+2]===ja&&E[w+3]===ba;){var ta=E[w+0];G+=
|
|
29
|
-
function(){for(var y=[],w=0;w<x;w++)y.push(this.get_text_row(w));return y};this.get_text_row=function(y){let w="";for(let G=0;G<F;G++)w+=
|
|
30
|
-
b.byteLength<=this.byteLength);(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};
|
|
18
|
+
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 G=0,M;256>G;G++)M=126<G?w[G-127]:32>G?y[G]:G,Tb.push(String.fromCharCode(M));p.classList.add("cursor");p.style.position="absolute";p.style.backgroundColor="#ccc";p.style.width="7px";p.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(v,t);this.timer()};this.make_screenshot=
|
|
19
|
+
function(){const y=new Image;if(1===u||2===u)y.src=h.toDataURL("image/png");else{const w=[9,16],G=document.createElement("canvas");G.width=F*w[0];G.height=x*w[1];const M=G.getContext("2d");M.imageSmoothingEnabled=!1;M.font=window.getComputedStyle(m).font;M.textBaseline="top";for(let S=0;S<x;S++)for(let R=0;R<F;R++){const U=4*(S*F+R),ma=E[U+0],ja=E[U+3];M.fillStyle=c(E[U+2]);M.fillRect(R*w[0],S*w[1],w[0],w[1]);M.fillStyle=c(ja);M.fillText(lb[ma],R*w[0],S*w[1])}"none"!==p.style.display&&q<x&&r<F&&(M.fillStyle=
|
|
20
|
+
p.style.backgroundColor,M.fillRect(r*w[0],q*w[1]+parseInt(p.style.marginTop,10),parseInt(p.style.width,10),parseInt(p.style.height,10)));y.src=G.toDataURL("image/png")}return y};this.put_char=function(y,w,G,M,S,R){k(0<=y&&y<x);k(0<=w&&w<F);k(0<=G&&256>G);w=4*(y*F+w);E[w+0]=G;E[w+1]=M;E[w+2]=S;E[w+3]=R;A[y]=1};this.timer=function(){yb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ub||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());
|
|
21
|
+
this.timer()};this.update_text=function(){for(var y=0;y<x;y++)A[y]&&(this.text_update_row(y),A[y]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(N){var y=performance.now();if(266<y-hc){vb=!vb;xb&&(A[q]=1);var w=4*F;for(let ma=0,ja=0;ma<x;++ma)if(A[ma])ja+=w;else for(var G=0;G<F;++G,ja+=4)if(E[ja+1]&1){A[ma]=1;ja+=w-4*G;break}hc=y}y=Xa.canvas;w=V.canvas;G=4*F;const S=F*qa,R=T;let U=0;for(let ma=0,ja=0,ba=0;ma<x;++ma,ja+=T){if(!A[ma]){ba+=G;
|
|
22
|
+
continue}++U;V.clearRect(0,R,S,T);let ta,Ia,Oa,Pa;for(let ya=0;ya<S;ya+=qa,ba+=4){const ic=E[ba+0];var M=E[ba+1];const jc=E[ba+2],kc=E[ba+3],lc=M&2?Rb:Qb;M=(!(M&1)||vb)&&gc[(lc<<8)+ic];Oa!==jc&&(void 0!==Oa&&(N.fillStyle=c(Oa),N.fillRect(Pa,ja,ya-Pa,T)),Oa=jc,Pa=ya);ta!==kc&&(void 0!==ta&&(V.fillStyle=c(ta),V.fillRect(Ia,0,ya-Ia,T)),ta=kc,Ia=ya);M&&V.drawImage(y,ic*qa,lc*T,qa,T,ya,R,qa,T)}V.fillStyle=c(ta);V.fillRect(Ia,0,S-Ia,T);V.globalCompositeOperation="destination-in";V.drawImage(w,0,R,S,T,0,
|
|
23
|
+
0,S,T);V.globalCompositeOperation="source-over";N.fillStyle=c(Oa);N.fillRect(Pa,ja,S-Pa,T);N.drawImage(w,0,0,S,T,0,ja,S,T)}U&&(vb&&xb&&A[q]&&(N.fillStyle=c(E[4*(q*F+r)+3]),N.fillRect(r*qa,q*T+wb,qa,Sb-wb+1)),A.fill(0));U&&l.drawImage(N.canvas,0,0)}};this.destroy=function(){yb&&(cancelAnimationFrame(yb),yb=0)};this.pause=function(){Ub=!0;p.classList.remove("blinking-cursor")};this.continue=function(){Ub=!1;p.classList.add("blinking-cursor")};this.set_mode=function(y){u=y?1:a.use_graphical_text?2:0;
|
|
24
|
+
0===u?(m.style.display="block",h.style.display="none"):(m.style.display="none",h.style.display="block",2===u&&A&&A.fill(1))};this.set_font_bitmap=function(y,w,G,M,S,R){const U=G?16:w?9:8;if(T!==y||qa!==U||Ob!==w||Nb!==G||Pb!==M||R)R=qa!==U||T!==y,T=y,qa=U,Ob=w,Nb=G,Pb=M,2===u&&(d(S),A.fill(1),R&&this.set_size_graphical_text())};this.set_font_page=function(y,w){if(Qb!==y||Rb!==w)Qb=y,Rb=w,A.fill(1)};this.clear_screen=function(){l.fillStyle="#000";l.fillRect(0,0,h.width,h.height)};this.set_size_graphical_text=
|
|
25
|
+
function(){if(Xa){var y=qa*F,w=T*x,G=2*T;N&&N.canvas.width===y&&N.canvas.height===w&&V.canvas.height===G||(N?(N.canvas.width=y,N.canvas.height=w,V.canvas.width=y,V.canvas.height=G):(N=(new OffscreenCanvas(y,w)).getContext("2d",{alpha:!1}),V=(new OffscreenCanvas(y,G)).getContext("2d")),this.set_size_graphical(y,w,y,w),A.fill(1))}};this.set_size_text=function(y,w){if(y!==F||w!==x)if(A=new Int8Array(w),E=new Int32Array(y*w*4),F=y,x=w,0===u){for(;m.childNodes.length>w;)m.removeChild(m.firstChild);for(;m.childNodes.length<
|
|
26
|
+
w;)m.appendChild(document.createElement("div"));for(y=0;y<w;y++)this.text_update_row(y);e(m,v,t,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(y,w){h.style.display="block";h.width=y;h.height=w;l.imageSmoothingEnabled=!1;z=640>=y&&2*y<window.innerWidth*window.devicePixelRatio&&2*w<window.innerHeight*window.devicePixelRatio?2:1;e(h,v*z,t*z,!1)};this.set_charmap=function(y){lb=y||Tb};this.set_scale=function(y,w){v=y;t=w;e(m,v,t,!0);e(h,v*z,t*z,!1)};this.update_cursor_scanline=
|
|
27
|
+
function(y,w,G){if(y!==wb||w!==Sb||G!==xb)0===u?G?(p.style.display="inline",p.style.height=w-y+"px",p.style.marginTop=y+"px"):p.style.display="none":2===u&&q<x&&(A[q]=1),wb=y,Sb=w,xb=G};this.update_cursor=function(y,w){if(y!==q||w!==r)y<x&&(A[y]=1),q<x&&(A[q]=1),q=y,r=w};this.text_update_row=function(y){var w=4*y*F,G;var M=m.childNodes[y];var S=document.createElement("div");for(var R=0;R<F;){var U=document.createElement("span");var ma=E[w+1]&1;var ja=E[w+2];var ba=E[w+3];ma&&U.classList.add("blink");
|
|
28
|
+
U.style.backgroundColor=c(ja);U.style.color=c(ba);for(G="";R<F&&(E[w+1]&1)===ma&&E[w+2]===ja&&E[w+3]===ba;){var ta=E[w+0];G+=lb[ta];k(lb[ta]);R++;w+=4;if(y===q)if(R===r)break;else if(R===r+1){p.style.backgroundColor=U.style.color;S.appendChild(p);break}}U.textContent=G;S.appendChild(U)}M.parentNode.replaceChild(S,M)};this.update_buffer=function(y){for(const w of y)l.putImageData(w.image_data,w.screen_x-w.buffer_x,w.screen_y-w.buffer_y,w.buffer_x,w.buffer_y,w.buffer_width,w.buffer_height)};this.get_text_screen=
|
|
29
|
+
function(){for(var y=[],w=0;w<x;w++)y.push(this.get_text_row(w));return y};this.get_text_row=function(y){let w="";for(let G=0;G<F;G++)w+=lb[E[4*(y*F+G)]];return w};this.init()}function xa(a){k(a instanceof ArrayBuffer);this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}xa.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};xa.prototype.get=function(a,b,c){k(a+b<=this.byteLength);c(new Uint8Array(this.buffer,a,b))};xa.prototype.set=function(a,b,c){k(a+
|
|
30
|
+
b.byteLength<=this.byteLength);(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};xa.prototype.get_buffer=function(a){a(this.buffer)};xa.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};xa.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function za(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=
|
|
31
31
|
this.onload=void 0}za.prototype.load=async function(){void 0===this.byteLength&&(this.byteLength=await ua(this.filename));this.onload&&this.onload(Object.create(null))};za.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);for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};za.prototype.get=function(a,b,c){k(a+b<=this.byteLength);k(0===a%256);k(0===b%256);k(b);var d=
|
|
32
32
|
this.get_from_cache(a,b);if(d)c(d);else{var e=a,f=b;this.fixed_chunk_size&&(e=a-a%this.fixed_chunk_size,f=Math.ceil((a-e+b)/this.fixed_chunk_size)*this.fixed_chunk_size);sa(this.filename,{done:function(h){h=new Uint8Array(h);this.handle_read(e,f,h);e===a&&f===b?c(h):c(h.subarray(a-e,a-e+b))}.bind(this),range:{start:e,length:f}})}};za.prototype.set=function(a,b,c){var d=b.length;k(a+b.byteLength<=this.byteLength);k(0===a%256);k(0===d%256);k(d);a/=256;d/=256;for(var e=0;e<d;e++){var f=this.block_cache.get(a+
|
|
33
33
|
e);if(void 0===f)f=b.slice(256*e,256*(e+1)),this.block_cache.set(a+e,f);else{const h=b.subarray(256*e,256*(e+1));k(f.byteLength===h.length);f.set(h)}this.block_cache_is_write.add(a+e)}c()};za.prototype.handle_read=function(a,b,c){a/=256;b/=256;for(var d=0;d<b;d++){const e=this.block_cache.get(a+d);e?c.set(e,256*d):this.cache_reads&&this.block_cache.set(a+d,c.slice(256*d,256*(d+1)))}};za.prototype.get_buffer=function(a){a()};za.prototype.get_state=function(){const a=[],b=[];for(const [c,d]of this.block_cache)k(isFinite(c)),
|
|
@@ -36,10 +36,10 @@ this.block_cache=new Map;this.block_cache_is_write=new Set;this.byteLength=b;thi
|
|
|
36
36
|
h=a-f*this.fixed_chunk_size;k(0<=h);const l=Math.ceil((h+b)/this.fixed_chunk_size),m=new Uint8Array(l*this.fixed_chunk_size);let p=0;for(let q=0;q<l;q++){var e=(f+q)*this.fixed_chunk_size;d=this.partfile_alt_format?this.basename+(f+q+"").padStart(8,"0")+this.extension:this.basename+e+"-"+(e+this.fixed_chunk_size)+this.extension;(e=this.get_from_cache(e,this.fixed_chunk_size))?(m.set(e,q*this.fixed_chunk_size),p++,p===l&&c(m.subarray(h,h+b))):sa(d,{done:async function(r){r=new Uint8Array(r);this.is_zstd&&
|
|
37
37
|
(r=await this.zstd_decompress(this.fixed_chunk_size,r),r=new Uint8Array(r));m.set(r,q*this.fixed_chunk_size);this.handle_read((f+q)*this.fixed_chunk_size,this.fixed_chunk_size|0,r);p++;p===l&&c(m.subarray(h,h+b))}.bind(this)})}}else sa(this.basename+a+"-"+(a+b)+this.extension,{done:function(f){k(f.byteLength===b);f=new Uint8Array(f);this.handle_read(a,b,f);c(f)}.bind(this)})};Aa.prototype.get_from_cache=za.prototype.get_from_cache;Aa.prototype.set=za.prototype.set;Aa.prototype.handle_read=za.prototype.handle_read;
|
|
38
38
|
Aa.prototype.get_state=za.prototype.get_state;Aa.prototype.set_state=za.prototype.set_state;function Ba(a){this.file=a;this.byteLength=a.size;1073741824<a.size&&console.warn("SyncFileBuffer: Allocating buffer of "+(a.size>>20)+" MB ...");this.buffer=new ArrayBuffer(a.size);this.onprogress=this.onload=void 0}Ba.prototype.load=function(){this.load_next(0)};Ba.prototype.load_next=function(a){var b=new FileReader;b.onload=function(d){d=new Uint8Array(d.target.result);(new Uint8Array(this.buffer,a)).set(d);
|
|
39
|
-
this.load_next(a+4194304)}.bind(this);if(this.onprogress)this.onprogress({loaded:a,total:this.byteLength,lengthComputable:!0});if(a<this.byteLength){var c=this.file.slice(a,Math.min(a+4194304,this.byteLength));b.readAsArrayBuffer(c)}else this.file=void 0,this.onload&&this.onload({buffer:this.buffer})};Ba.prototype.get=
|
|
39
|
+
this.load_next(a+4194304)}.bind(this);if(this.onprogress)this.onprogress({loaded:a,total:this.byteLength,lengthComputable:!0});if(a<this.byteLength){var c=this.file.slice(a,Math.min(a+4194304,this.byteLength));b.readAsArrayBuffer(c)}else this.file=void 0,this.onload&&this.onload({buffer:this.buffer})};Ba.prototype.get=xa.prototype.get;Ba.prototype.set=xa.prototype.set;Ba.prototype.get_buffer=xa.prototype.get_buffer;Ba.prototype.get_state=xa.prototype.get_state;Ba.prototype.set_state=xa.prototype.set_state;
|
|
40
40
|
function Ca(a){this.file=a;this.byteLength=a.size;this.block_cache=new Map;this.block_cache_is_write=new Set;this.onprogress=this.onload=void 0}Ca.prototype.load=function(){this.onload&&this.onload(Object.create(null))};Ca.prototype.get=function(a,b,c){k(0===a%256);k(0===b%256);k(b);var d=this.get_from_cache(a,b);d?c(d):(d=new FileReader,d.onload=function(e){e=new Uint8Array(e.target.result);this.handle_read(a,b,e);c(e)}.bind(this),d.readAsArrayBuffer(this.file.slice(a,a+b)))};Ca.prototype.get_from_cache=
|
|
41
41
|
za.prototype.get_from_cache;Ca.prototype.set=za.prototype.set;Ca.prototype.handle_read=za.prototype.handle_read;Ca.prototype.get_state=za.prototype.get_state;Ca.prototype.set_state=za.prototype.set_state;Ca.prototype.get_buffer=function(a){a()};Ca.prototype.get_as_file=function(a){for(var b=[],c=Array.from(this.block_cache.keys()).sort(function(l,m){return l-m}),d=0,e=0;e<c.length;e++){var f=c[e],h=this.block_cache.get(f);f*=256;k(f>=d);f!==d&&(b.push(this.file.slice(d,f)),d=f);b.push(h);d+=h.length}d!==
|
|
42
|
-
this.file.size&&b.push(this.file.slice(d));a=new File(b,a);k(a.size===this.file.size);return a};function Da(a,b){if(a.buffer instanceof ArrayBuffer)return new
|
|
42
|
+
this.file.size&&b.push(this.file.slice(d));a=new File(b,a);k(a.size===this.file.size);return a};function Da(a,b){if(a.buffer instanceof ArrayBuffer)return new xa(a.buffer);if("undefined"!==typeof File&&a.buffer instanceof File)return b=a.async,void 0===b&&(b=268435456<=a.buffer.size),b?new Ca(a.buffer):new Ba(a.buffer);if(a.url)return a.use_parts?new Aa(a.url,a.size,a.fixed_chunk_size,!1,b):new za(a.url,a.size,a.fixed_chunk_size);B("Ignored file: url="+a.url+" buffer="+a.buffer)}function C(a){this.cpu=
|
|
43
43
|
a;this.channel_page=new Uint8Array(8);this.channel_pagehi=new Uint8Array(8);this.channel_addr=new Uint16Array(8);this.channel_addr_init=new Uint16Array(8);this.channel_count=new Uint16Array(8);this.channel_count_init=new Uint16Array(8);this.channel_mask=new Uint8Array(8);this.channel_mode=new Uint8Array(8);this.unmask_listeners=[];this.lsb_msb_flipflop=0;a=a.io;a.register_write(0,this,this.port_addr_write.bind(this,0));a.register_write(2,this,this.port_addr_write.bind(this,1));a.register_write(4,
|
|
44
44
|
this,this.port_addr_write.bind(this,2));a.register_write(6,this,this.port_addr_write.bind(this,3));a.register_write(1,this,this.port_count_write.bind(this,0));a.register_write(3,this,this.port_count_write.bind(this,1));a.register_write(5,this,this.port_count_write.bind(this,2));a.register_write(7,this,this.port_count_write.bind(this,3));a.register_read(0,this,this.port_addr_read.bind(this,0));a.register_read(2,this,this.port_addr_read.bind(this,1));a.register_read(4,this,this.port_addr_read.bind(this,
|
|
45
45
|
2));a.register_read(6,this,this.port_addr_read.bind(this,3));a.register_read(1,this,this.port_count_read.bind(this,0));a.register_read(3,this,this.port_count_read.bind(this,1));a.register_read(5,this,this.port_count_read.bind(this,2));a.register_read(7,this,this.port_count_read.bind(this,3));a.register_write(192,this,this.port_addr_write.bind(this,4));a.register_write(196,this,this.port_addr_write.bind(this,5));a.register_write(200,this,this.port_addr_write.bind(this,6));a.register_write(204,this,
|
|
@@ -69,10 +69,10 @@ function(a,b){var c=this.ports[a];c.write16===this.empty_port_write&&B("write16
|
|
|
69
69
|
32);b=b.read8.call(b.device,a);k("number"===typeof b);(0>b||256<=b)&&k(!1,"8 bit port returned large value: "+n(a));return b};Ea.prototype.port_read16=function(a){var b=this.ports[a];b.read16===this.empty_port_read16&&B("read16 port #"+n(a,4)+this.get_port_description(a),32);b=b.read16.call(b.device,a);k("number"===typeof b);(0>b||65536<=b)&&k(!1,"16 bit port returned large value: "+n(a));return b};Ea.prototype.port_read32=function(a){var b=this.ports[a];b.read32===this.empty_port_read32&&B("read32 port #"+
|
|
70
70
|
n(a,4)+this.get_port_description(a),32);a=b.read32.call(b.device,a);k((a|0)===a);return a};var Fa={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",12:"PORT_DMA1_CLEAR_FF_REG",13:"PORT_DMA1_MASTER_CLEAR",32:"PORT_PIC1_CMD",33:"PORT_PIC1_DATA",64:"PORT_PIT_COUNTER0",65:"PORT_PIT_COUNTER1",66:"PORT_PIT_COUNTER2",67:"PORT_PIT_MODE",96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",
|
|
71
71
|
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",1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",
|
|
72
|
-
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"};Ea.prototype.get_port_description=function(a){return Fa[a]?" ("+Fa[a]+")":""};var Ga={};function
|
|
73
|
-
b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};
|
|
72
|
+
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"};Ea.prototype.get_port_description=function(a){return Fa[a]?" ("+Fa[a]+")":""};var Ga={};function Ha(){this.listeners={};this.pair=void 0}Ha.prototype.register=function(a,b,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,
|
|
73
|
+
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){k(1===arguments.length||2===arguments.length);setTimeout(this.send.bind(this,a,b),0)};Ga.create=function(){var a=new Ha,b=new Ha;a.pair=b;b.pair=a;return[a,b]};var Ja=new Uint8Array(256),Ka=[],La=[],Ma=[],Na=new Uint8Array(256),
|
|
74
74
|
Qa=[];function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new na(64);this.read_buffer=new na(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 oa(65536),new oa(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=
|
|
75
|
-
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
|
|
75
|
+
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 xa(this.dma_buffer);this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",
|
|
76
76
|
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 na(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,this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read);
|
|
77
77
|
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);a.io.register_read(557,this,this.port2xD_read);a.io.register_read_consecutive(558,this,this.port2xE_read,
|
|
78
78
|
this.port2xF_read);a.io.register_write_consecutive(544,this,this.port2x0_write,this.port2x1_write,this.port2x2_write,this.port2x3_write);a.io.register_write_consecutive(904,this,this.port2x0_write,this.port2x1_write);a.io.register_write_consecutive(548,this,this.port2x4_write,this.port2x5_write);a.io.register_write(550,this,this.port2x6_write);a.io.register_write(551,this,this.port2x7_write);a.io.register_write_consecutive(552,this,this.port2x8_write,this.port2x9_write);a.io.register_write(554,this,
|
|
@@ -82,7 +82,7 @@ this.dma_sample_count=0;this.dma_autoinit=!1;this.dma_buffer_uint8.fill(0);this.
|
|
|
82
82
|
this.dummy_speaker_enabled;a[8]=this.test_register;a[9]=this.dsp_highspeed;a[10]=this.dsp_stereo;a[11]=this.dsp_16bit;a[12]=this.dsp_signed;a[15]=this.dma_sample_count;a[16]=this.dma_bytes_count;a[17]=this.dma_bytes_left;a[18]=this.dma_bytes_block;a[19]=this.dma_irq;a[20]=this.dma_channel;a[21]=this.dma_channel_8bit;a[22]=this.dma_channel_16bit;a[23]=this.dma_autoinit;a[24]=this.dma_buffer_uint8;a[25]=this.dma_waiting_transfer;a[26]=this.dma_paused;a[27]=this.sampling_rate;a[28]=this.bytes_per_sample;
|
|
83
83
|
a[29]=this.e2_value;a[30]=this.e2_count;a[31]=this.asp_registers;a[33]=this.mpu_read_buffer_last_value;a[34]=this.irq;a[35]=this.irq_triggered;return a};D.prototype.set_state=function(a){this.read_buffer_lastvalue=a[2];this.command=a[3];this.command_size=a[4];this.mixer_current_address=a[5];this.mixer_registers=a[6];this.mixer_full_update();this.dummy_speaker_enabled=a[7];this.test_register=a[8];this.dsp_highspeed=a[9];this.dsp_stereo=a[10];this.dsp_16bit=a[11];this.dsp_signed=a[12];this.dma_sample_count=
|
|
84
84
|
a[15];this.dma_bytes_count=a[16];this.dma_bytes_left=a[17];this.dma_bytes_block=a[18];this.dma_irq=a[19];this.dma_channel=a[20];this.dma_channel_8bit=a[21];this.dma_channel_16bit=a[22];this.dma_autoinit=a[23];this.dma_buffer_uint8=a[24];this.dma_waiting_transfer=a[25];this.dma_paused=a[26];this.sampling_rate=a[27];this.bytes_per_sample=a[28];this.e2_value=a[29];this.e2_count=a[30];this.asp_registers=a[31];this.mpu_read_buffer_last_value=a[33];this.irq=a[34];this.irq_triggered=a[35];this.dma_buffer=
|
|
85
|
-
this.dma_buffer_uint8.buffer;this.dma_buffer_int8=new Int8Array(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
|
|
85
|
+
this.dma_buffer_uint8.buffer;this.dma_buffer_int8=new Int8Array(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 xa(this.dma_buffer);this.dma_paused?this.bus.send("dac-disable"):this.bus.send("dac-enable")};D.prototype.port2x0_read=function(){B("220 read: fm music status port (unimplemented)",8388608);return 255};D.prototype.port2x1_read=function(){B("221 read: fm music data port (write only)",8388608);
|
|
86
86
|
return 255};D.prototype.port2x2_read=function(){B("222 read: advanced fm music status port (unimplemented)",8388608);return 255};D.prototype.port2x3_read=function(){B("223 read: advanced music data port (write only)",8388608);return 255};D.prototype.port2x4_read=function(){B("224 read: mixer address port",8388608);return this.mixer_current_address};D.prototype.port2x5_read=function(){B("225 read: mixer data port",8388608);return this.mixer_read(this.mixer_current_address)};D.prototype.port2x6_read=
|
|
87
87
|
function(){B("226 read: (write only)",8388608);return 255};D.prototype.port2x7_read=function(){B("227 read: undocumented",8388608);return 255};D.prototype.port2x8_read=function(){B("228 read: fm music status port (unimplemented)",8388608);return 255};D.prototype.port2x9_read=function(){B("229 read: fm music data port (write only)",8388608);return 255};D.prototype.port2xA_read=function(){B("22A read: read data",8388608);this.read_buffer.length&&(this.read_buffer_lastvalue=this.read_buffer.shift());
|
|
88
88
|
B(" <- "+this.read_buffer_lastvalue+" "+n(this.read_buffer_lastvalue)+" '"+String.fromCharCode(this.read_buffer_lastvalue)+"'",8388608);return this.read_buffer_lastvalue};D.prototype.port2xB_read=function(){B("22B read: undocumented",8388608);return 255};D.prototype.port2xC_read=function(){B("22C read: write-buffer status",8388608);return 127};D.prototype.port2xD_read=function(){B("22D read: undocumented",8388608);return 255};D.prototype.port2xE_read=function(){B("22E read: read-buffer status / irq 8bit ack.",
|
|
@@ -102,9 +102,9 @@ H([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});H([209],0
|
|
|
102
102
|
this.read_buffer.push(this.test_register)});H([242,243],0,function(){this.raise_irq()});var Ta=new Uint8Array(256);Ta[14]=255;Ta[15]=7;Ta[55]=56;H([249],1,function(){var a=this.write_buffer.shift();B("dsp 0xf9: unknown function. input: "+a,8388608);this.read_buffer.clear();this.read_buffer.push(Ta[a])});D.prototype.mixer_read=function(a){var b=La[a];b?b=b.call(this):(b=this.mixer_registers[a],B("unhandled mixer register read. addr:"+n(a)+" data:"+n(b),8388608));return b};D.prototype.mixer_write=function(a,
|
|
103
103
|
b){var c=Ma[a];c?c.call(this,b):B("unhandled mixer register write. addr:"+n(a)+" data:"+n(b),8388608)};D.prototype.mixer_default_read=function(){B("mixer register read. addr:"+n(this.mixer_current_address),8388608);return this.mixer_registers[this.mixer_current_address]};D.prototype.mixer_default_write=function(a){B("mixer register write. addr:"+n(this.mixer_current_address)+" data:"+n(a),8388608);this.mixer_registers[this.mixer_current_address]=a};D.prototype.mixer_reset=function(){this.mixer_registers[4]=
|
|
104
104
|
204;this.mixer_registers[34]=204;this.mixer_registers[38]=204;this.mixer_registers[40]=0;this.mixer_registers[46]=0;this.mixer_registers[10]=0;this.mixer_registers[48]=192;this.mixer_registers[49]=192;this.mixer_registers[50]=192;this.mixer_registers[51]=192;this.mixer_registers[52]=192;this.mixer_registers[53]=192;this.mixer_registers[54]=0;this.mixer_registers[55]=0;this.mixer_registers[56]=0;this.mixer_registers[57]=0;this.mixer_registers[59]=0;this.mixer_registers[60]=31;this.mixer_registers[61]=
|
|
105
|
-
21;this.mixer_registers[62]=11;this.mixer_registers[63]=0;this.mixer_registers[64]=0;this.mixer_registers[65]=0;this.mixer_registers[66]=0;this.mixer_registers[67]=0;this.mixer_registers[68]=128;this.mixer_registers[69]=128;this.mixer_registers[70]=128;this.mixer_registers[71]=128;this.mixer_full_update()};D.prototype.mixer_full_update=function(){for(var a=1;a<this.mixer_registers.length;a++)
|
|
106
|
-
La[a]=b}function Va(a,b){b||(b=D.prototype.mixer_default_write);Ma[a]=b}function
|
|
107
|
-
return 0});Va(0);
|
|
105
|
+
21;this.mixer_registers[62]=11;this.mixer_registers[63]=0;this.mixer_registers[64]=0;this.mixer_registers[65]=0;this.mixer_registers[66]=0;this.mixer_registers[67]=0;this.mixer_registers[68]=128;this.mixer_registers[69]=128;this.mixer_registers[70]=128;this.mixer_registers[71]=128;this.mixer_full_update()};D.prototype.mixer_full_update=function(){for(var a=1;a<this.mixer_registers.length;a++)Na[a]||this.mixer_write(a,this.mixer_registers[a])};function Ua(a,b){b||(b=D.prototype.mixer_default_read);
|
|
106
|
+
La[a]=b}function Va(a,b){b||(b=D.prototype.mixer_default_write);Ma[a]=b}function Wa(a,b,c){Na[a]=1;La[a]=function(){return this.mixer_registers[b]&240|this.mixer_registers[c]>>>4};Ma[a]=function(d){this.mixer_registers[a]=d;var e=d<<4&240|this.mixer_registers[c]&15;this.mixer_write(b,d&240|this.mixer_registers[b]&15);this.mixer_write(c,e)}}function Ya(a,b,c){La[a]=D.prototype.mixer_default_read;Ma[a]=function(d){this.mixer_registers[a]=d;this.bus.send("mixer-volume",[b,c,(d>>>2)-62])}}Ua(0,function(){this.mixer_reset();
|
|
107
|
+
return 0});Va(0);Wa(4,50,51);Wa(34,48,49);Wa(38,52,53);Wa(40,54,55);Wa(46,56,57);Ya(48,0,0);Ya(49,0,1);Ya(50,2,0);Ya(51,2,1);Ua(59);Va(59,function(a){this.mixer_registers[59]=a;this.bus.send("mixer-volume",[1,2,6*(a>>>6)-18])});Ua(65);Va(65,function(a){this.mixer_registers[65]=a;this.bus.send("mixer-gain-left",6*(a>>>6))});Ua(66);Va(66,function(a){this.mixer_registers[66]=a;this.bus.send("mixer-gain-right",6*(a>>>6))});Ua(68);Va(68,function(a){this.mixer_registers[68]=a;a>>>=3;this.bus.send("mixer-treble-left",
|
|
108
108
|
a-(16>a?14:16))});Ua(69);Va(69,function(a){this.mixer_registers[69]=a;a>>>=3;this.bus.send("mixer-treble-right",a-(16>a?14:16))});Ua(70);Va(70,function(a){this.mixer_registers[70]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});Ua(71);Va(71,function(a){this.mixer_registers[71]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});Ua(128,function(){switch(this.irq){case 2:return 1;case 5:return 2;case 7:return 4;case 10:return 8;default:return 0}});Va(128,function(a){a&1&&(this.irq=
|
|
109
109
|
2);a&2&&(this.irq=5);a&4&&(this.irq=7);a&8&&(this.irq=10)});Ua(129,function(){var a=0;switch(this.dma_channel_8bit){case 0:a|=1;break;case 1:a|=2;break;case 3:a|=8}switch(this.dma_channel_16bit){case 5:a|=32;break;case 6:a|=64;break;case 7:a|=128}return a});Va(129,function(a){a&1&&(this.dma_channel_8bit=0);a&2&&(this.dma_channel_8bit=1);a&8&&(this.dma_channel_8bit=3);a&32&&(this.dma_channel_16bit=5);a&64&&(this.dma_channel_16bit=6);a&128&&(this.dma_channel_16bit=7)});Ua(130,function(){for(var a=32,
|
|
110
110
|
b=0;16>b;b++)a|=b*this.irq_triggered[b];return a});D.prototype.fm_default_write=function(a,b,c){B("unhandled fm register write. addr:"+b+"|"+n(c)+" data:"+n(a),8388608)};function Za(a,b){b||(b=D.prototype.fm_default_write);for(var c=0;c<a.length;c++)Qa[a[c]]=b}function $a(a,b){for(var c=[];a<=b;a++)c.push(a);return c}const ab=new Uint8Array(32);ab[0]=0;ab[1]=1;ab[2]=2;ab[3]=3;ab[4]=4;ab[5]=5;ab[8]=6;ab[9]=7;ab[10]=8;ab[11]=9;ab[12]=10;ab[13]=11;ab[16]=12;ab[17]=13;ab[18]=14;ab[19]=15;ab[20]=16;ab[21]=
|
|
@@ -141,7 +141,7 @@ this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=
|
|
|
141
141
|
8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,I.microtick());return b?a&255:a>>8};ib.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=
|
|
142
142
|
I.microtick(),B("counter"+a+" reload="+n(this.counter_reload[a])+" tick="+(this.counter_reload[a]||65536)/1193.1816666+"ms",512));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};ib.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,d=a>>6&3;a=a>>4&3;1===d&&B("Unimplemented timer1",512);3===d?B("Unimplemented read back",512):0===a?(this.counter_latch[d]=2,b=this.get_counter_value(d,I.microtick()),B("latch: "+b,512),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),B("Control: mode="+
|
|
143
143
|
b+" ctr="+d+" read_mode="+a+" bcd="+c,512),this.counter_next_low[d]=1===a?1:2===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&B("Unimplemented counter mode: "+n(b),512),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]]))};ib.prototype.dump=function(){const a=this.counter_reload[0];B("counter0 ticks every "+(a||65536)/1193.1816666+"ms (reload="+a+")")};function jb(a){if("undefined"!==typeof window)if(window.AudioContext||
|
|
144
|
-
window.webkitAudioContext){var b=window.AudioWorklet?
|
|
144
|
+
window.webkitAudioContext){var b=window.AudioWorklet?kb:mb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new nb(a,this.audio_context);this.pcspeaker=new ob(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},this);a.register("speaker-confirm-initialized",
|
|
145
145
|
function(){a.send("speaker-has-initialized")},this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}jb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();this.audio_context=null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};function nb(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}this.audio_context=b;this.sources=new Map;this.gain_right=
|
|
146
146
|
this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";this.node_treble_right.type="highshelf";this.node_treble_left.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_treble_right.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_bass_left=this.audio_context.createBiquadFilter();this.node_bass_right=
|
|
147
147
|
this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=this.audio_context.createGain();this.node_merger=this.audio_context.createChannelMerger(2);this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;
|
|
@@ -153,7 +153,7 @@ this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_r
|
|
|
153
153
|
this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}pb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;this.node_gain_left.gain.setValueAtTime(this.connected_left*this.gain_hidden*this.volume_both*this.volume_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};pb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||
|
|
154
154
|
1===a)this.connected_right=!0;this.update()};pb.prototype.disconnect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!1;if(b||1===a)this.connected_right=!1;this.update()};pb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:k(!1,"Mixer set volume - unknown channel: "+b);return}this.update()};pb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function ob(a,b,c){this.node_oscillator=
|
|
155
155
|
b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,
|
|
156
|
-
0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}ob.prototype.start=function(){this.node_oscillator.start()};function
|
|
156
|
+
0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}ob.prototype.start=function(){this.node_oscillator.start()};function kb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function h(p){if(0===p)return 1;p*=Math.PI;return Math.sin(p)/p}function l(){var p=Reflect.construct(AudioWorkletProcessor,[],l);p.kernel_size=3;p.queue_data=Array(1024);p.queue_start=0;p.queue_end=0;p.queue_length=0;p.queue_size=p.queue_data.length;p.queued_samples=
|
|
157
157
|
0;p.source_buffer_previous=m;p.source_buffer_current=m;p.source_samples_per_destination=1;p.source_block_start=0;p.source_time=0;p.source_offset=0;p.port.onmessage=q=>{switch(q.data.type){case "queue":p.queue_push(q.data.value);break;case "sampling-rate":p.source_samples_per_destination=q.data.value/sampleRate}};return p}var m=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(l.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(l,AudioWorkletProcessor);l.prototype.process=
|
|
158
158
|
l.prototype.process=function(p,q){for(p=0;p<q[0][0].length;p++){for(var r=0,v=0,t=this.source_offset+this.kernel_size,z=this.source_offset-this.kernel_size+1;z<=t;z++){var A=this.source_block_start+z;r+=this.get_sample(A,0)*this.kernel(this.source_time-z);v+=this.get_sample(A,1)*this.kernel(this.source_time-z)}if(isNaN(r)||isNaN(v))r=v=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");q[0][0][p]=r;q[0][1][p]=v;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}q=
|
|
159
159
|
this.source_offset;q+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(q);return!0};l.prototype.kernel=function(p){return h(p)*h(p/this.kernel_size)};l.prototype.get_sample=function(p,q){return 0>p?(p+=this.source_buffer_previous[0].length,this.source_buffer_previous[q][p]):this.source_buffer_current[q][p]};l.prototype.ensure_enough_data=function(p){var q=this.source_buffer_current[0].length;q-this.source_block_start<
|
|
@@ -162,7 +162,7 @@ p=Math.max(p,256);p=[new Float32Array(p),new Float32Array(p)];p[0].set(this.sour
|
|
|
162
162
|
(this.queue_data[this.queue_end]=p,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=p[0].length,this.pump())};l.prototype.queue_shift=function(){if(!this.queue_length)return m;var p=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=p[0].length;return p};l.prototype.dbg_log=function(p){this.port.postMessage({type:"debug-log",value:p})};registerProcessor("dac-processor",
|
|
163
163
|
l)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,e);b=new Blob(["var DEBUG = true;\n"+b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();this.audio_context.audioWorklet.addModule(f).then(()=>{URL.revokeObjectURL(f);this.node_processor=new AudioWorkletNode(this.audio_context,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});
|
|
164
164
|
this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=h=>{switch(h.data.type){case "pump":this.pump();break;case "debug-log":B("SpeakerWorkletDAC - Worklet: "+h.data.value)}};this.node_processor.connect(this.node_output)});this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(h){this.queue(h)},this);a.register("dac-enable",function(){this.enabled=!0},this);
|
|
165
|
-
a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(h){k(0<h,"Sampling rate should be nonzero");this.sampling_rate=h;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:h})},this);this.debugger=new qb(this.audio_context,this.node_output)}
|
|
165
|
+
a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(h){k(0<h,"Sampling rate should be nonzero");this.sampling_rate=h;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:h})},this);this.debugger=new qb(this.audio_context,this.node_output)}kb.prototype.queue=function(a){this.node_processor&&(this.debugger.push_queued_data(a),this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer]))};kb.prototype.pump=
|
|
166
166
|
function(){this.enabled&&this.bus.send("dac-request-data")};function mb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=this.node_lowpass;this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=
|
|
167
167
|
!0;this.pump()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){k(0<d,"Sampling rate should be nonzero");this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this);this.debugger=new qb(this.audio_context,this.node_output)}mb.prototype.queue=function(a){this.debugger.push_queued_data(a);var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=
|
|
168
168
|
this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),h=0,l=0;l<b;l++)for(var m=0;m<this.rate_ratio;m++,h++)e[h]=a[0][l],f[h]=a[1][l]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",
|
|
@@ -173,7 +173,7 @@ null};qb.prototype.push_queued_data=function(a){this.is_active&&(this.queued[0].
|
|
|
173
173
|
this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}rb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};rb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};rb.prototype.handle_open=
|
|
174
174
|
function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};rb.prototype.handle_error=function(){};rb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};rb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);
|
|
175
175
|
return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};rb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};rb.prototype.change_proxy=
|
|
176
|
-
function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const sb=(new Date("1970-01-01T00:00:00Z")).getTime(),tb=(new Date("1900-01-01T00:00:00Z")).getTime(),
|
|
176
|
+
function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const sb=(new Date("1970-01-01T00:00:00Z")).getTime(),tb=(new Date("1900-01-01T00:00:00Z")).getTime(),ub=sb-tb,zb=Math.pow(2,32),Ab=[118,56,54];function Bb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Cb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Db{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=
|
|
177
177
|
b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(k(0<d);d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,
|
|
178
178
|
this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Eb(){const a=new Uint8Array(1518),b=a.buffer,c=a.byteOffset;return{eth_frame:a,eth_frame_view:new DataView(b),eth_payload_view:new DataView(b,
|
|
179
179
|
c+14,1500),ipv4_payload_view:new DataView(b,c+34,1480),udp_payload_view:new DataView(b,c+42,1472),text_encoder:new TextEncoder}}function Fb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Gb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}function Hb(a,b){k(b.eth);a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Fb(0,b.eth.dest,e,a);Fb(6,b.eth.src,
|
|
@@ -186,17 +186,17 @@ b.ipv4.dest[3])+17+p,l,a));h+=p}else b.tcp&&(l=a.ipv4_payload_view,m=0,q=b.tcp,q
|
|
|
186
186
|
8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+m,l,a)),h+=m);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,h);f.setUint16(4,b.ipv4.id||0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Fb(12,b.ipv4.src,f,a);Fb(16,b.ipv4.dest,f,a);f.setUint16(10,Gb(20,0,f,a));e+=h}return d.call(c,0,e)}function Ib(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type",
|
|
187
187
|
"application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Hb(b.eth_encoder_buf,c))});return!0}function Jb(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,
|
|
188
188
|
ciaddr:0,yiaddr:Cb(b.vm_ip),siaddr:Cb(b.router_ip),giaddr:Cb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),
|
|
189
|
-
d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(Ab)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Hb(b.eth_encoder_buf,c))}function
|
|
189
|
+
d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(Ab)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Hb(b.eth_encoder_buf,c))}function Kb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),e={ethertype:d,dest:a.subarray(0,6),dest_s:Bb(a.subarray(0,6)),src:a.subarray(6,12),src_s:Bb(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,
|
|
190
190
|
a.byteLength),h=a[0]>>4&15;e=a[0]&15;var l=f.getUint8(1),m=f.getUint16(2);let p=f.getUint8(8);d=f.getUint8(9);f=f.getUint16(10);h={version:h,ihl:e,tos:l,len:m,ttl:p,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};Math.max(m,46)!==a.length&&B(`ipv4 Length mismatch: ${m} != ${a.length}`,16777216);c.ipv4=h;e=a.subarray(4*e,m);if(1===d)a=new DataView(e.buffer,e.byteOffset,e.byteLength),a={type:a.getUint8(0),code:a.getUint8(1),checksum:a.getUint16(2),data:e.subarray(4)},c.icmp=a;else if(6===
|
|
191
191
|
d)d=new DataView(e.buffer,e.byteOffset,e.byteLength),a={sport:d.getUint16(0),dport:d.getUint16(2),seq:d.getUint32(4),ackn:d.getUint32(8),doff:d.getUint8(12)>>4,winsize:d.getUint16(14),checksum:d.getUint16(16),urgent:d.getUint16(18)},d=d.getUint8(13),a.fin=!!(d&1),a.syn=!!(d&2),a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),
|
|
192
192
|
len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};if(67===a.dport||67===a.sport){e=e.subarray(8);d=new DataView(e.buffer,e.byteOffset,e.byteLength);e.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),
|
|
193
|
-
options:[]};e=e.subarray(240);for(m=0;m<e.length;++m)h=m,0!==e[m]&&(++m,l=e[m],m+=l,d.options.push(e.subarray(h,h+l+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?
|
|
193
|
+
options:[]};e=e.subarray(240);for(m=0;m<e.length;++m)h=m,0!==e[m]&&(++m,l=e[m],m+=l,d.options.push(e.subarray(h,h+l+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Lb(e.subarray(8),c):123===a.dport&&(d=e.subarray(8),d=new DataView(d.buffer,d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),
|
|
194
194
|
ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525===d?B("Unimplemented: ipv6"):B("Unknown ethertype: "+n(d),16777216);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;
|
|
195
195
|
if(c.tcp.syn&&(b.tcp_conn[a]&&B("SYN to already opened port",16777216),b.on_tcp_connection(c,a)))break a;if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{B(`I dont know about ${a}, so resetting`,16777216);a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Hb(b.eth_encoder_buf,
|
|
196
196
|
d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(m=c.dns.questions[e],m.type){case 1:d.push({name:m.name,type:m.type,class:m.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Hb(b.eth_encoder_buf,a))}else Ib(c,b);else c.dhcp?Jb(c,b):c.ntp?
|
|
197
|
-
(a=Date.now()+
|
|
197
|
+
(a=Date.now()+ub,d=a%1E3/1E3*zb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Hb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},
|
|
198
198
|
a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Hb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Hb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=Cb(c.arp.tpa)&4294967040,d=Cb(b.router_ip)&4294967040,
|
|
199
|
-
!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Hb(b.eth_encoder_buf,a))))}function
|
|
199
|
+
!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Hb(b.eth_encoder_buf,a))))}function Lb(a,b){function c(){let p=[],q;do q=d.getUint8(l),p.push((new TextDecoder).decode(a.subarray(l+1,l+1+q))),l+=q+1;while(0<q);return p}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};
|
|
200
200
|
var f=d.getUint16(4);let h=d.getUint16(6);d.getUint16(8);d.getUint16(10);let l=12;for(var m=0;m<f;m++)e.questions.push({name:c(),type:d.getInt16(l),class:d.getInt16(l+2)}),l+=4;for(f=0;f<h;f++){m={name:c(),type:d.getInt16(l),class:d.getUint16(l+2),ttl:d.getUint32(l+4)};l+=8;let p=d.getUint16(l);l+=2;m.data=a.subarray(l,l+p);l+=p;e.answers.push(m)}b.dns=e}function Vb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,h,l=0;do f=49152+(e+l)%16383,h=`${c}:${a}:${d}:${f}`;
|
|
201
201
|
while(16383>++l&&b.tcp_conn[h]);if(b.tcp_conn[h])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Wb;c.tuple=h;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;c.net=b;b.tcp_conn[h]=c;c.connect();return c}function Xb(a,b){return new Promise(c=>{let d=Vb(a,b);d.state="syn-probe";d.on("probe",c)})}function Wb(){this.state="closed";this.net=null;this.send_buffer=new Db(2048,0);this.send_chunk_buf=new Uint8Array(1460);this.delayed_send_fin=
|
|
202
202
|
this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Wb.prototype.on=function(a,b){this.events_handlers[a]=b};Wb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)};Wb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,ackn:this.ack,seq:this.seq,ack:!0};return a};Wb.prototype.packet_reply=
|
|
@@ -218,14 +218,14 @@ return}"host"===m.key.toLowerCase()?d.host=m.value:e.append(m.key,m.value)}if(!t
|
|
|
218
218
|
this.write(this.net.form_response_head(l.status,l.statusText,m));h=!0;if(l.body&&l.body.getReader){const p=l.body.getReader(),q=({value:r,done:v})=>{r&&this.write(r);if(v)this.close();else return p.read().then(q)};p.read().then(q)}else l.arrayBuffer().then(p=>{this.write(new Uint8Array(p));this.close()})}).catch(l=>{console.warn("Fetch Failed: "+f+"\n"+l);h||this.net.respond_text_and_close(this,502,"Fetch Error",`Fetch ${f} failed:\n\n${l.stack||l.message}`);this.close()})}}Yb.prototype.fetch=async function(a,
|
|
219
219
|
b){this.cors_proxy&&(a=this.cors_proxy+encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),[{status:502,statusText:"Fetch Error",headers:new Headers({"Content-Type":"text/plain"})},(new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};Yb.prototype.form_response_head=function(a,b,c){a=[`HTTP/1.1 ${a} ${b}`];for(const [d,e]of c.entries())a.push(`${d}: ${e}`);return(new TextEncoder).encode(a.join("\r\n")+
|
|
220
220
|
"\r\n\r\n")};Yb.prototype.respond_text_and_close=function(a,b,c,d){const e=new Headers({"content-type":"text/plain","content-length":d.length.toString(10),connection:"close"});a.writev([this.form_response_head(b,c,e),(new TextEncoder).encode(d)]);a.close()};Yb.prototype.parse_http_header=function(a){var b=a.match(/^([^:]*):(.*)$/);if(b)if(a=b[1],b=b[2].trim(),0===a.length)B("Header key is empty, raw header",16777216);else if(0===b.length)B("Header value is empty",16777216);else if(/^[\w-]+$/.test(a)){if(/^[\x20-\x7E]+$/.test(b))return{key:a,
|
|
221
|
-
value:b};B("Header value contains forbidden characters",16777216)}else B("Header key contains forbidden characters",16777216);else B("Unable to parse HTTP header",16777216)};Yb.prototype.send=function(a){
|
|
221
|
+
value:b};B("Header value contains forbidden characters",16777216)}else B("Header key contains forbidden characters",16777216);else B("Unable to parse HTTP header",16777216)};Yb.prototype.send=function(a){Kb(a,this)};Yb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};function $b(a,b,c){this.register_ws(a);this.last_stream=1;this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||
|
|
222
222
|
"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,10)}));this.masquerade=void 0===c.masquerade||!!c.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.eth_encoder_buf=Eb();this.bus.register("net"+
|
|
223
223
|
this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}$b.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://","ws://").replace("wisps://","wss://"));this.wispws.binaryType="arraybuffer";this.wispws.onmessage=b=>{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};$b.prototype.send_packet=
|
|
224
224
|
function(a,b,c){this.connections[c]&&(0<this.connections[c].congestion?("DATA"===b&&this.connections[c].congestion--,this.wispws.send(a)):(this.connections[c].congested=!0,this.congested_buffer.push({data:a,type:b})))};$b.prototype.process_incoming_wisp_frame=function(a){const b=new DataView(a.buffer),c=b.getUint32(1,!0);switch(a[0]){case 1:B("Server sent client-only packet CONNECT",1048576);break;case 2:if(this.connections[c])this.connections[c].data_callback(a.slice(5));else throw Error("Got a DATA packet but stream not registered. ID: "+
|
|
225
225
|
c);break;case 3:this.connections[c]&&(this.connections[c].congestion=b.getUint32(5,!0));if(this.connections[c].congested){for(const d of this.congested_buffer)this.send_packet(d.data,d.type,c);this.connections[c].congested=!1}break;case 4:this.connections[c]&&this.connections[c].close_callback(b.getUint8(5));delete this.connections[c];break;case 5:B("got a wisp V2 upgrade request, ignoring",1048576);break;default:B("Wisp server returned unknown packet: "+a[0],1048576)}};$b.prototype.send_wisp_frame=
|
|
226
226
|
function(a){let b,c;switch(a.type){case "CONNECT":const d=(new TextEncoder).encode(a.hostname);b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]={data_callback:a.data_callback,close_callback:a.close_callback,congestion:this.connections[0].congestion};break;case "DATA":b=new Uint8Array(5+a.data.length);c=new DataView(b.buffer);c.setUint8(0,2);c.setUint32(1,a.stream_id,
|
|
227
227
|
!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6);c=new DataView(b.buffer);c.setUint8(0,4);c.setUint32(1,a.stream_id,!0);c.setUint8(5,a.reason);break;default:B("Client tried to send unknown packet: "+a.type,1048576)}this.send_packet(b,a.type,a.stream_id)};$b.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};$b.prototype.on_tcp_connection=function(a,b){let c=new Wb;c.state="syn-received";c.net=this;c.tuple=
|
|
228
|
-
b;c.stream_id=this.last_stream++;this.tcp_conn[b]=c;c.on("data",d=>{0!==d.length&&this.send_wisp_frame({type:"DATA",stream_id:c.stream_id,data:d})});c.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:c.stream_id,reason:2})};c.on_shutdown=c.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:c.stream_id,hostname:a.ipv4.dest.join("."),port:a.tcp.dport,data_callback:d=>{c.write(d)},close_callback:()=>{c.close()}});c.accept(a);return!0};$b.prototype.send=function(a){
|
|
228
|
+
b;c.stream_id=this.last_stream++;this.tcp_conn[b]=c;c.on("data",d=>{0!==d.length&&this.send_wisp_frame({type:"DATA",stream_id:c.stream_id,data:d})});c.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:c.stream_id,reason:2})};c.on_shutdown=c.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:c.stream_id,hostname:a.ipv4.dest.join("."),port:a.tcp.dport,data_callback:d=>{c.write(d)},close_callback:()=>{c.close()}});c.accept(a);return!0};$b.prototype.send=function(a){Kb(a,this)};$b.prototype.receive=
|
|
229
229
|
function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};const ac="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function bc(a){function b(x){return x.shiftKey&&x.ctrlKey&&(73===x.keyCode||74===x.keyCode||75===x.keyCode)||!z.emu_enabled?!1:x.target?x.target.classList.contains("phone_keyboard")||"INPUT"!==x.target.nodeName&&"TEXTAREA"!==x.target.nodeName:!0}function c(x){!x.altKey&&q[56]&&m(56,!1);return h(x,!1)}function d(x){!x.altKey&&
|
|
230
230
|
q[56]&&m(56,!1);return h(x,!0)}function e(){for(var x=Object.keys(q),N,V=0;V<x.length;V++)N=+x[V],q[N]&&m(N,!1);q={}}function f(x){if(z.bus&&b(x))switch(x.inputType){case "insertText":for(var N=0;N<x.data.length;N++)z.simulate_char(x.data[N]);break;case "insertLineBreak":z.simulate_press(13);break;case "deleteContentBackward":z.simulate_press(8)}}function h(x,N){if(z.bus&&b(x)&&""!==x.code&&"Process"!==x.key&&"Unidentified"!==x.key&&229!==x.keyCode){x.preventDefault&&x.preventDefault();if(ac&&(r&&
|
|
231
231
|
(clearTimeout(t),x.getModifierState&&x.getModifierState("AltGraph")&&v===N&&"ControlLeft"===r.code&&"AltRight"===x.code||l(r,v),r=null),"ControlLeft"===x.code))return r=x,v=N,t=setTimeout(()=>{l(r,v);r=null},10),!1;l(x,N);return!1}}function l(x,N){a:{if(void 0!==x.code){var V=F[x.code];if(void 0!==V)break a}V=A[x.keyCode]}V?m(V,N,x.repeat):console.log("Missing char in map: keyCode="+(x.keyCode||-1).toString(16)+" code="+x.code)}function m(x,N,V){if(N)q[x]&&!V&&m(x,!1);else if(!q[x])return;(q[x]=N)||
|
|
@@ -240,12 +240,12 @@ v||r)A.bus.send("mouse-click",[!1,!1,!1]),q=v=r=!1}function f(u){if(A.bus&&c(u)&
|
|
|
240
240
|
[1*E,-(1*F)]);b&&A.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function h(u){c(u)&&m(u,!0)}function l(u){c(u)&&m(u,!1)}function m(u,E){A.bus&&(1===u.which?q=E:2===u.which?v=E:3===u.which?r=E:B("Unknown event.which: "+u.which),A.bus.send("mouse-click",[q,v,r]),u.preventDefault())}function p(u){if(c(u)){var E=u.wheelDelta||-u.detail;0>E?E=-1:0<E&&(E=1);A.bus.send("mouse-wheel",[E,0]);u.preventDefault()}}var q=!1,r=!1,v=!1,t=0,z=0,A=this;this.enabled=
|
|
241
241
|
!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=u},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=!1},this);this.bus.register("emulator-started",function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",f,!1),window.removeEventListener("mousemove",f,!1),
|
|
242
242
|
window.removeEventListener("mousedown",h,!1),window.removeEventListener("mouseup",l,!1),window.removeEventListener("wheel",p,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",e,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("mousedown",h,!1),window.addEventListener("mouseup",l,!1),window.addEventListener("wheel",p,{passive:!1}))};
|
|
243
|
-
this.init()}function
|
|
244
|
-
function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var d=[],e=0;e<c;e++)d.push(this.get_text_row(e));return d};this.get_text_row=function(d){d*=b;return String.fromCharCode.apply(String,a.subarray(d,d+b))};this.set_size_text(80,25)}function
|
|
243
|
+
this.init()}function dc(){var a,b=0,c=0;this.put_char=function(d,e,f){k(0<=d&&d<c);k(0<=e&&e<b);a[d*b+e]=f};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(d,e){if(d!==b||e!==c)a=new Uint8Array(d*e),b=d,c=e};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=
|
|
244
|
+
function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var d=[],e=0;e<c;e++)d.push(this.get_text_row(e));return d};this.get_text_row=function(d){d*=b;return String.fromCharCode.apply(String,a.subarray(d,d+b))};this.set_size_text(80,25)}function ec(a,b){function c(l){h.bus&&h.enabled&&(h.send_char(l.which),l.preventDefault())}function d(l){var m=l.which;8===m?(h.send_char(127),l.preventDefault()):9===m&&(h.send_char(9),l.preventDefault())}function e(l){if(h.enabled){for(var m=
|
|
245
245
|
l.clipboardData.getData("text/plain"),p=0;p<m.length;p++)h.send_char(m.charCodeAt(p));l.preventDefault()}}function f(l){l.target!==a&&a.blur()}var h=this;this.enabled=!0;this.bus=b;this.text="";this.text_new_line=!1;this.last_update=0;this.bus.register("serial0-output-byte",function(l){l=String.fromCharCode(l);this.show_char(l)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",
|
|
246
246
|
f,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",f,!1)};this.init();this.show_char=function(l){"\b"===l?(this.text=this.text.slice(0,-1),this.update()):"\r"!==l&&(this.text+=l,"\n"===l&&(this.text_new_line=!0),this.update())};this.update=function(){var l=Date.now(),m=l-this.last_update;16>m?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>
|
|
247
|
-
{this.update_timer=void 0;var p=Date.now();k(15<=p-this.last_update);this.last_update=p;this.render()},16-m)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=l,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(l){h.bus&&h.bus.send("serial0-input",l)}}function
|
|
248
|
-
convertEol:"true"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let f=0;f<e.length;f++)b.send("serial0-input",e.charCodeAt(f))});b.register("serial0-output-byte",function(e){c.write(Uint8Array.of(e))},this);this.destroy=function(){d.dispose();c.dispose()}}}
|
|
247
|
+
{this.update_timer=void 0;var p=Date.now();k(15<=p-this.last_update);this.last_update=p;this.render()},16-m)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=l,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(l){h.bus&&h.bus.send("serial0-input",l)}}function fc(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off",
|
|
248
|
+
convertEol:"true"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let f=0;f<e.length;f++)b.send("serial0-input",e.charCodeAt(f))});b.register("serial0-output-byte",function(e){c.write(Uint8Array.of(e))},this);this.destroy=function(){d.dispose();c.dispose()}}}fc.prototype.show=function(){this.term&&this.term.open(this.element)};function mc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;
|
|
249
249
|
this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}mc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",this.hub_to_nic_fn),this.channel.close(),
|
|
250
250
|
this.is_open=!1)};function nc(){this.filedata=new Map}nc.prototype.read=async function(a,b,c){k(a,"MemoryFileStorage read: sha256sum should be a non-empty string");return(a=this.filedata.get(a))?a.subarray(b,b+c):null};nc.prototype.cache=async function(a,b){k(a,"MemoryFileStorage cache: sha256sum should be a non-empty string");this.filedata.set(a,b)};nc.prototype.uncache=function(a){this.filedata.delete(a)};function oc(a,b){k(b,"ServerMemoryFileStorage: baseurl should not be empty");b.endsWith("/")||
|
|
251
251
|
(b+="/");this.storage=a;this.baseurl=b}oc.prototype.load_from_server=function(a){return new Promise(b=>{sa(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};oc.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)};oc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};oc.prototype.uncache=function(a){this.storage.uncache(a)};const pc=new TextDecoder,qc=new TextEncoder;
|
|
@@ -254,65 +254,65 @@ case "Q":J(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;f+=13;break;defaul
|
|
|
254
254
|
h;e.push(pc.decode(l));break;case "Q":c.offset=d;h=K(["b","w","d"],b,c);d=c.offset;e.push({type:h[0],version:h[1],path:h[2]});break;default:B("Error in Unmarshall: Unknown type="+a[f])}c.offset=d;return e}const rc=new TextEncoder;function L(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)}L.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;
|
|
255
255
|
a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&16384)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};L.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new sc(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)};L.prototype.AddEvent=
|
|
256
256
|
function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})};L.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};L.prototype.load_from_json=function(a){k(a,"Invalid fs passed to load_from_json");if(3!==
|
|
257
|
-
a.version)throw"The filesystem JSON format has changed. Please
|
|
258
|
-
|
|
259
|
-
k(this.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
(b.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
this.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.
|
|
310
|
-
b.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
b.
|
|
315
|
-
t.loadable.load()):sa(t.url,{done:function(z){t.url.endsWith(".zst")&&"initial_state"!==t.name&&(k(t.size,"A size must be provided for compressed images"),z=this.zstd_decompress(t.size,new Uint8Array(z)));c.call(this,t.name,t.as_json?z:new
|
|
257
|
+
a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};L.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],k(c.sha256sum),this.PushInode(c,
|
|
258
|
+
b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&B("Unexpected ifmt: "+n(e)+" ("+d+")",4194304)};L.prototype.LoadDir=function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};L.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};L.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];k(!this.is_forwarder(e),"Filesystem: Shouldn't link under fowarder parents");k(this.IsDirectory(a),"Filesystem: Can't link under non-directories");
|
|
259
|
+
k(this.should_be_linked(d),"Filesystem: Can't link across filesystems apart from their root");k(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks);k(!e.direntries.has(c),"Filesystem: Name '"+c+"' is already taken");e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(k(!d.direntries.has(".."),"Filesystem: Cannot link a directory twice"),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};L.prototype.unlink_from_dir=function(a,b){const c=
|
|
260
|
+
this.Search(a,b),d=this.inodes[c],e=this.inodes[a];k(!this.is_forwarder(e),"Filesystem: Can't unlink from forwarders");k(this.IsDirectory(a),"Filesystem: Can't unlink from non-directories");e.direntries.delete(b)?(d.nlinks--,this.IsDirectory(c)&&(k(d.direntries.get("..")===a,"Filesystem: Found directory with bad parent id"),d.direntries.delete(".."),e.nlinks--),k(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks)):k(!1,"Filesystem: Can't unlink non-existent file: "+b)};L.prototype.PushInode=
|
|
261
|
+
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):k(!1,"Error in Filesystem: Pushed inode with name = "+c+" has no parent")};function sc(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=
|
|
262
|
+
void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}sc.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&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]=
|
|
263
|
+
this.qid.path;a[13]=this.nlinks;return a};sc.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&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 tc;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];
|
|
264
|
+
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]};L.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new sc(-1);k(d,"Filesystem divert: name ("+b+") not found");k(this.IsDirectory(c)||1>=d.nlinks,"Filesystem: can't divert hardlinked file '"+b+"' with nlinks="+d.nlinks);Object.assign(e,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,
|
|
265
|
+
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 [h,l]of e.direntries)"."!==h&&".."!==h&&this.IsDirectory(l)&&this.inodes[l].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};L.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};L.prototype.CreateInode=function(){const a=Math.round(Date.now()/
|
|
266
|
+
1E3),b=new sc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};L.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,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-
|
|
267
|
+
1};L.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-1,"newfile");return this.inodes.length-1};L.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=
|
|
268
|
+
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};L.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=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;
|
|
269
|
+
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};L.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);b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};L.prototype.CreateBinaryFile=
|
|
270
|
+
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};L.prototype.OpenInode=function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return this.follow_fs(c).OpenInode(c.foreign_id,b);16384===(c.mode&61440)&&this.FillDirectory(a);return!0};L.prototype.CloseInode=
|
|
271
|
+
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))};L.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 h=this.Unlink(c,d);if(0>h)return h}var l=this.inodes[e],m=this.inodes[a];h=this.inodes[c];if(this.is_forwarder(m)||
|
|
272
|
+
this.is_forwarder(h))if(this.is_forwarder(m)&&m.mount_id===h.mount_id){if(a=await this.follow_fs(m).Rename(m.foreign_id,b,h.foreign_id,d),0>a)return a}else{if(this.is_a_root(e))return B("XXX: Attempted to move mountpoint ("+b+") - skipped",4194304),-1;if(!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return B("XXX: Attempted to move hardlinked file ("+b+") across filesystems - skipped",4194304),-1;m=this.divert(a,b);const p=this.GetInode(e),q=await this.Read(m,0,p.size);this.is_forwarder(h)?(c=this.follow_fs(h),
|
|
273
|
+
d=this.IsDirectory(m)?c.CreateDirectory(d,h.foreign_id):c.CreateFile(d,h.foreign_id),c=c.GetInode(d),this.copy_inode(p,c),this.set_forwarder(e,h.mount_id,d)):(this.delete_forwarder(l),this.copy_inode(p,l),this.link_under_dir(c,e,d));await this.ChangeSize(e,p.size);q&&q.length&&await this.Write(e,0,q.length,q);if(this.IsDirectory(e))for(const r of this.GetChildren(m))if(h=await this.Rename(m,r,e,r),0>h)return h;await this.DeleteData(m);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,
|
|
274
|
+
b),this.link_under_dir(c,e,d),l.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});return 0};L.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)}};L.prototype.Read=
|
|
275
|
+
async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};L.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};L.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),
|
|
276
|
+
a-=c.size;return a};L.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=b.CountFreeInodes();return a};L.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};L.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};L.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);
|
|
277
|
+
if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;k(!1,"Filesystem: Found directory inode whose parent doesn't link to it");return""};L.prototype.GetFullPath=function(a){k(this.IsDirectory(a),"Filesystem: Cannot get full path of non-directory inode");for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};L.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)&&
|
|
278
|
+
e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):(B("XXX: Attempted to hardlink a file into a child filesystem - skipped",4194304),-1);if(this.is_forwarder(e))return B("XXX: Attempted to hardlink file across filesystems - skipped",4194304),-1;this.link_under_dir(a,b,c);return 0};L.prototype.Unlink=function(a,b){if("."===b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return k(this.is_forwarder(d),"Children of forwarders should be forwarders"),
|
|
279
|
+
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};L.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])};L.prototype.get_buffer=async function(a){const b=this.inodes[a];k(b,`Filesystem get_buffer: idx ${a} does not point to an inode`);return this.inodedata[a]?
|
|
280
|
+
this.inodedata[a]:2===b.status?(k(b.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(b.sha256sum,0,b.size)):null};L.prototype.get_data=async function(a,b,c){const d=this.inodes[a];k(d,`Filesystem get_data: idx ${a} does not point to an inode`);return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?(k(d.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(d.sha256sum,b,c)):null};L.prototype.set_data=
|
|
281
|
+
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))};L.prototype.GetInode=function(a){k(!isNaN(a),"Filesystem GetInode: NaN idx");k(0<=a&&a<this.inodes.length,"Filesystem GetInode: out of range idx:"+a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};L.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=
|
|
282
|
+
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)}};L.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=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,
|
|
283
|
+
name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};L.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,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))};
|
|
284
|
+
L.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--){const c=this.Unlink(b[a].parentid,b[a].name);k(0===c,"Filesystem RecursiveDelete failed at parent="+b[a].parentid+", name='"+b[a].name+"' with error code: "+-c)}};L.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&61440)?(a=this.Unlink(b.parentid,b.name),k(0===a,"Filesystem DeleteNode failed with error code: "+
|
|
285
|
+
-a)):16384===(this.inodes[b.id].mode&61440)&&(this.RecursiveDelete(a),a=this.Unlink(b.parentid,b.name),k(0===a,"Filesystem DeleteNode failed with error code: "+-a)))};L.prototype.NotifyListeners=function(){};L.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&&B("Error in filesystem: negative nlinks="+b.nlinks+" at id ="+a,4194304);if(this.IsDirectory(a)){b=this.GetInode(a);this.IsDirectory(a)&&0>this.GetParent(a)&&B("Error in filesystem: negative parent id "+
|
|
286
|
+
a,4194304);for(const [c,d]of b.direntries){0===c.length&&B("Error in filesystem: inode with no name and id "+d,4194304);for(const e of c)32>e&&B("Error in filesystem: Unallowed char in filename",4194304)}}}};L.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+rc.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),
|
|
287
|
+
c+=J(["Q","d","b","s"],[b.qid,c+13+8+1+2+rc.encode(d).length,b.mode>>12,d],a,c)}};L.prototype.RoundToDirentry=function(a,b){const c=this.inodedata[a];k(c,`FS directory data for dirid=${a} should be generated`);k(c.length,"FS directory should have at least an entry");if(b>=c.length)return c.length;for(a=0;;){const d=K(["Q","d"],c,{offset:a})[1];if(d>b)break;a=d}return a};L.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):16384===
|
|
288
|
+
(a.mode&61440)};L.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);for(const b of a.direntries.keys())if("."!==b&&".."!==b)return!1;return!0};L.prototype.GetChildren=function(a){k(this.IsDirectory(a),"Filesystem: cannot get children of non-directory inode");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};
|
|
289
|
+
L.prototype.GetParent=function(a){k(this.IsDirectory(a),"Filesystem: cannot get parent of non-directory inode");a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);k(-1!==b,"Filesystem: should not have invalid parent ids");return this.get_forwarder(a.mount_id,b)};L.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]=
|
|
290
|
+
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 uc(a){this.fs=a;this.backtrack=new Map}uc.prototype.get_state=function(){const a=[];a[0]=this.fs;a[1]=[...this.backtrack];return a};uc.prototype.set_state=function(a){this.fs=a[0];this.backtrack=new Map(a[1])};L.prototype.set_forwarder=function(a,b,c){const d=
|
|
291
|
+
this.inodes[a];k(0===d.nlinks,"Filesystem: attempted to convert an inode into forwarder before unlinking the inode");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)};L.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};L.prototype.is_forwarder=function(a){return 5===a.status};L.prototype.is_a_root=
|
|
292
|
+
function(a){return 0===this.GetInode(a).fid};L.prototype.get_forwarder=function(a,b){var c=this.mounts[a];k(0<=b,"Filesystem get_forwarder: invalid foreign_id: "+b);k(c,"Filesystem get_forwarder: invalid mount number: "+a);c=c.backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};L.prototype.delete_forwarder=function(a){k(this.is_forwarder(a),"Filesystem delete_forwarder: expected forwarder");a.status=-1;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)};L.prototype.follow_fs=function(a){const b=
|
|
293
|
+
this.mounts[a.mount_id];k(this.is_forwarder(a),"Filesystem follow_fs: inode should be a forwarding inode");k(b,"Filesystem follow_fs: inode<id="+a.fid+"> should point to valid mounted FS");return b.fs};L.prototype.Mount=function(a,b){k(b.qidcounter===this.qidcounter,"Cannot mount filesystem whose qid numbers aren't synchronised with current filesystem.");var c=this.SearchPath(a);if(-1===c.parentid)return B("Mount failed: parent for path not found: "+a,4194304),-2;if(-1!==c.id)return B("Mount failed: file already exists at path: "+
|
|
294
|
+
a,4194304),-17;if(c.forward_path)return a=this.inodes[c.parentid],c=this.follow_fs(a).Mount(c.forward_path,b),0>c?c:this.get_forwarder(a.mount_id,c);a=this.mounts.length;this.mounts.push(new uc(b));b=this.create_forwarder(a,0);this.link_under_dir(c.parentid,b,c.name);return b};function tc(){this.type=2;this.start=0;this.length=Infinity;this.proc_id=-1;this.client_id=""}tc.prototype.get_state=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===this.length?0:this.length;a[3]=this.proc_id;
|
|
295
|
+
a[4]=this.client_id;return a};tc.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]};tc.prototype.clone=function(){const a=new tc;a.set_state(this.get_state());return a};tc.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<=this.start?!1:!0};tc.prototype.is_alike=
|
|
296
|
+
function(a){return a.proc_id===this.proc_id&&a.client_id===this.client_id&&a.type===this.type};tc.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start};L.prototype.DescribeLock=function(a,b,c,d,e){k(0===a||1===a||2===a,"Filesystem: Invalid lock type: "+a);k(0<=b,"Filesystem: Invalid negative lock starting offset: "+b);k(0<c,"Filesystem: Invalid non-positive lock length: "+c);const f=new tc;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};L.prototype.GetLock=
|
|
297
|
+
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();return null};L.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];k(0<a.length,"Filesystem: Found non-positive lock region length: "+a.length);k(0===a.type||
|
|
298
|
+
1===a.type,"Filesystem: Found invalid lock type: "+a.type);k(!d.locks[c-1]||d.locks[c-1].start<=a.start,"Filesystem: Locks should be sorted by starting offset");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){k(!a.conflicts_with(b),"Filesytem: Found conflicting lock region, despite already checked for conflicts");continue}var e=b.start+b.length;const f=b.start-a.start,h=a.start+a.length-e;if(0<f&&0<h&&a.type===b.type)return 0;
|
|
299
|
+
0<f&&(a.length=f);if(0>=f&&0<h)a.start=e,a.length=h;else if(0<h){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,h,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+=
|
|
300
|
+
d.locks[e].length,d.locks.splice(e,1));break}}return 0};L.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)};L.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)};function O(a){"number"===typeof a.log_level&&(va=a.log_level);this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=Ga.create();
|
|
301
|
+
this.bus=b[0];this.emulator_bus=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:1924});b={cpu_exception_hook:h=>this.cpu_exception_hook(h),run_hardware_timers:function(h,l){return c.run_hardware_timers(h,l)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){k(!1)},microtick:I.microtick,get_rand_int:function(){return ea()},apic_acknowledge_irq:function(){return c.devices.apic.acknowledge_irq()},stop_idling:function(){return c.stop_idling()},io_port_read8:function(h){return c.io.port_read8(h)},
|
|
302
|
+
io_port_read16:function(h){return c.io.port_read16(h)},io_port_read32:function(h){return c.io.port_read32(h)},io_port_write8:function(h,l){c.io.port_write8(h,l)},io_port_write16:function(h,l){c.io.port_write16(h,l)},io_port_write32:function(h,l){c.io.port_write32(h,l)},mmap_read8:function(h){return c.mmap_read8(h)},mmap_read16:function(h){return c.mmap_read16(h)},mmap_read32:function(h){return c.mmap_read32(h)},mmap_write8:function(h,l){c.mmap_write8(h,l)},mmap_write16:function(h,l){c.mmap_write16(h,
|
|
303
|
+
l)},mmap_write32:function(h,l){c.mmap_write32(h,l)},mmap_write64:function(h,l,m){c.mmap_write64(h,l,m)},mmap_write128:function(h,l,m,p,q){c.mmap_write128(h,l,m,p,q)},log_from_wasm:function(h,l){h=String.fromCharCode(...(new Uint8Array(d.buffer,h>>>0,l>>>0)));B(h,2)},console_log_from_wasm:function(h,l){h=String.fromCharCode(...(new Uint8Array(d.buffer,h>>>0,l>>>0)));console.error(h)},dbg_trace_from_wasm:function(){B(Error().stack,2)},codegen_finalize:(h,l,m,p,q)=>{c.codegen_finalize(h,l,m,p,q)},jit_clear_func:h=>
|
|
304
|
+
c.jit_clear_func(h),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let f=a.wasm_fn;f||(f=h=>new Promise(l=>{let m="v86-debug.wasm",p="v86-fallback.wasm";a.wasm_path?(m=a.wasm_path,p=m.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(m=__dirname+"/"+m,p=__dirname+"/"+p):(m="build/"+m,p="build/"+p);sa(m,{done:async q=>{try{const {instance:r}=await WebAssembly.instantiate(q,h);this.wasm_source=q;l(r.exports)}catch(r){sa(p,
|
|
305
|
+
{done:async v=>{const {instance:t}=await WebAssembly.instantiate(v,h);this.wasm_source=v;l(t.exports)}})}},progress:q=>{this.emulator_bus.send("download-progress",{file_index:0,file_count:1,file_name:m,lengthComputable:q.lengthComputable,total:q.total,loaded:q.loaded})}})}));f({env:b}).then(h=>{d=h.memory;h.rust_init();h=this.v86=new I(this.emulator_bus,{exports:h,wasm_table:e});c=h.cpu;this.continue_init(h,a)});this.zstd_worker=null;this.zstd_worker_request_id=0}O.prototype.continue_init=async function(a,
|
|
306
|
+
b){function c(v,t){switch(v){case "hda":e.hda=this.disk_images.hda=t;break;case "hdb":e.hdb=this.disk_images.hdb=t;break;case "cdrom":e.cdrom=this.disk_images.cdrom=t;break;case "fda":e.fda=this.disk_images.fda=t;break;case "fdb":e.fdb=this.disk_images.fdb=t;break;case "multiboot":e.multiboot=this.disk_images.multiboot=t.buffer;break;case "bzimage":e.bzimage=this.disk_images.bzimage=t.buffer;break;case "initrd":e.initrd=this.disk_images.initrd=t.buffer;break;case "bios":e.bios=t.buffer;break;case "vga_bios":e.vga_bios=
|
|
307
|
+
t.buffer;break;case "initial_state":e.initial_state=t.buffer;break;case "fs9p_json":e.fs9p_json=t;break;default:k(!1,v)}}async function d(){if(e.fs9p&&e.fs9p_json)if(e.initial_state)B("Filesystem basefs ignored: Overridden by state image");else{if(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem){const {bzimage_path:v,initrd_path:t}=this.get_bzimage_initrd_from_filesystem(e.fs9p);B("Found bzimage: "+v+" and initrd: "+t);const [z,A]=await Promise.all([e.fs9p.read_file(t),e.fs9p.read_file(v)]);
|
|
308
|
+
c.call(this,"initrd",new xa(z.buffer));c.call(this,"bzimage",new xa(A.buffer))}}else k(!b.bzimage_initrd_from_filesystem||e.initial_state,"bzimage_initrd_from_filesystem: Requires a filesystem");this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.v86.init(e);e.initial_state&&(a.restore_state(e.initial_state),e.initial_state=void 0);b.autostart&&this.v86.run();this.emulator_bus.send("emulator-loaded")}this.bus.register("emulator-stopped",function(){this.cpu_is_running=!1;
|
|
309
|
+
this.screen_adapter.pause()},this);this.bus.register("emulator-started",function(){this.cpu_is_running=!0;this.screen_adapter.continue()},this);var e={};this.disk_images={fda:void 0,fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};var f=b.boot_order?b.boot_order:b.fda?801:b.hda?786:291;e.acpi=b.acpi;e.disable_jit=b.disable_jit;e.load_devices=!0;e.memory_size=b.memory_size||67108864;e.vga_memory_size=b.vga_memory_size||8388608;e.boot_order=f;e.fastboot=b.fastboot||!1;e.fda=void 0;e.fdb=void 0;e.uart1=
|
|
310
|
+
b.uart1;e.uart2=b.uart2;e.uart3=b.uart3;e.cmdline=b.cmdline;e.preserve_mac_from_state_image=b.preserve_mac_from_state_image;e.mac_address_translation=b.mac_address_translation;e.cpuid_level=b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=b.virtio_console;e.screen_options=b.screen_options;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===f?this.network_adapter=new Yb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new mc(this.bus,b.net_device):f.startsWith("wisp://")||
|
|
311
|
+
f.startsWith("wisps://")?this.network_adapter=new $b(f,this.bus,b.net_device):this.network_adapter=new rb(f,this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new bc(this.bus));b.disable_mouse||(this.mouse_adapter=new cc(this.bus,f.container));this.screen_adapter=f.container?new wa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new dc;e.screen=this.screen_adapter;
|
|
312
|
+
e.screen_options=f;b.serial_container&&(this.serial_adapter=new ec(b.serial_container,this.bus));b.serial_container_xtermjs&&(this.serial_adapter=new fc(b.serial_container_xtermjs,this.bus));b.disable_speaker||(this.speaker_adapter=new jb(this.bus));var h=[];f=(v,t)=>{if(t)if(t.get&&t.set&&t.load)h.push({name:v,loadable:t});else{if("bios"===v||"vga_bios"===v||"initial_state"===v||"multiboot"===v||"bzimage"===v||"initrd"===v)t.async=!1;if("fda"===v||"fdb"===v)t.async=!1;t.url&&!t.async?h.push({name:v,
|
|
313
|
+
url:t.url,size:t.size}):h.push({name:v,loadable:Da(t,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");f("bios",b.bios);f("vga_bios",b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&
|
|
314
|
+
b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var l=b.filesystem.baseurl;let v=new nc;l&&(v=new oc(v,l));e.fs9p=this.fs9p=new L(v);if(f){k(l,"Filesystem: baseurl must be specified");if("object"===typeof f){var m=f.size;f=f.url}k("string"===typeof f);h.push({name:"fs9p_json",url:f,size:m,as_json:!0})}}var p=this,q=h.length,r=function(v){if(v===q)setTimeout(d.bind(this),0);else{var t=h[v];t.loadable?(t.loadable.onload=function(){c.call(this,t.name,
|
|
315
|
+
t.loadable);r(v+1)}.bind(this),t.loadable.load()):sa(t.url,{done:function(z){t.url.endsWith(".zst")&&"initial_state"!==t.name&&(k(t.size,"A size must be provided for compressed images"),z=this.zstd_decompress(t.size,new Uint8Array(z)));c.call(this,t.name,t.as_json?z:new xa(z));r(v+1)}.bind(this),progress:function(z){200===z.target.status?p.emulator_bus.send("download-progress",{file_index:v,file_count:q,file_name:t.url,lengthComputable:z.lengthComputable,total:z.total||t.size,loaded:z.loaded}):p.emulator_bus.send("download-error",
|
|
316
316
|
{file_index:v,file_count:q,file_name:t.url,request:z.target})},as_json:t.as_json})}}.bind(this);r(0)};O.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;k(!this.zstd_context);this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};O.prototype.zstd_decompress_worker=
|
|
317
317
|
async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:h,id:l}=e.data;e=d.exports;var m=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(m));var p=e.zstd_read(m,h),q=e.memory.buffer.slice(p,p+h);e.zstd_read_free(p,h);e.zstd_free_ctx(m);postMessage({result:q,id:l},[q])}else m=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int apic_acknowledge_irq stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(r=>
|
|
318
318
|
[r,()=>console.error("zstd worker unexpectedly called "+r)])),m.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),m.abort=()=>{throw Error("zstd worker aborted");},m.log_from_wasm=m.console_log_from_wasm=(r,v)=>{console.log(String.fromCharCode(...(new Uint8Array(d.exports.memory.buffer,r,v))))},m.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:m})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=
|
|
@@ -320,9 +320,9 @@ new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_sour
|
|
|
320
320
|
[]).map(e=>"/"+e);a=(a.read_dir("/boot/")||[]).map(e=>"/boot/"+e);let c,d;for(const e of[].concat(b,a)){const f=/old/i.test(e)||/fallback/i.test(e),h=/vmlinuz/i.test(e)||/bzimage/i.test(e),l=/initrd/i.test(e)||/initramfs/i.test(e);!h||d&&f||(d=e);!l||c&&f||(c=e)}c&&d||(console.log("Failed to find bzimage or initrd in filesystem. Files:"),console.log(b.join(" ")),console.log(a.join(" ")));return{initrd_path:c,bzimage_path:d}};O.prototype.run=async function(){this.v86.run()};O.prototype.stop=async function(){this.cpu_is_running&&
|
|
321
321
|
await new Promise(a=>{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.v86.stop()})};O.prototype.destroy=async function(){await this.stop();this.v86.destroy();this.keyboard_adapter&&this.keyboard_adapter.destroy();this.network_adapter&&this.network_adapter.destroy();this.mouse_adapter&&this.mouse_adapter.destroy();this.screen_adapter&&this.screen_adapter.destroy();this.serial_adapter&&this.serial_adapter.destroy();this.speaker_adapter&&this.speaker_adapter.destroy()};
|
|
322
322
|
O.prototype.restart=function(){this.v86.restart()};O.prototype.add_listener=function(a,b){this.bus.register(a,b,this)};O.prototype.remove_listener=function(a,b){this.bus.unregister(a,b)};O.prototype.restore_state=async function(a){k(1===arguments.length);this.v86.restore_state(a)};O.prototype.save_state=async function(){k(0===arguments.length);return this.v86.save_state()};O.prototype.get_instruction_counter=function(){return this.v86?this.v86.cpu.instruction_counter[0]>>>0:0};O.prototype.is_running=
|
|
323
|
-
function(){return this.cpu_is_running};O.prototype.set_fda=async function(a){const b=this.v86.cpu.devices.fdc.drives[0];if(a.url&&!a.async)await new Promise(c=>{sa(a.url,{done:d=>{b.insert_disk(new
|
|
323
|
+
function(){return this.cpu_is_running};O.prototype.set_fda=async function(a){const b=this.v86.cpu.devices.fdc.drives[0];if(a.url&&!a.async)await new Promise(c=>{sa(a.url,{done:d=>{b.insert_disk(new xa(d));c()}})});else{const c=Da(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};O.prototype.set_fdb=async function(a){const b=this.v86.cpu.devices.fdc.drives[1];if(a.url&&!a.async)await new Promise(c=>{sa(a.url,{done:d=>{b.insert_disk(new xa(d));c()}})});else{const c=
|
|
324
324
|
Da(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};O.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.drives[0].eject_disk()};O.prototype.eject_fdb=function(){this.v86.cpu.devices.fdc.drives[1].eject_disk()};O.prototype.get_disk_fda=function(){return this.v86.cpu.devices.fdc.drives[0].get_buffer()};O.prototype.get_disk_fdb=function(){return this.v86.cpu.devices.fdc.drives[1].get_buffer()};O.prototype.set_cdrom=async function(a){if(a.url&&!a.async)sa(a.url,
|
|
325
|
-
{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new
|
|
325
|
+
{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new xa(b))}});else{const b=Da(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.cdrom.set_cdrom(b)};await b.load()}};O.prototype.eject_cdrom=function(){this.v86.cpu.devices.cdrom.eject()};O.prototype.keyboard_send_scancodes=function(a){for(var b=0;b<a.length;b++)this.bus.send("keyboard-code",a[b])};O.prototype.keyboard_send_keys=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_press(a[b])};O.prototype.keyboard_send_text=
|
|
326
326
|
function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_char(a[b])};O.prototype.screen_make_screenshot=function(){return this.screen_adapter?this.screen_adapter.make_screenshot():null};O.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};O.prototype.screen_go_fullscreen=function(){if(this.screen_adapter){var a=document.getElementById("screen_container");if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||
|
|
327
327
|
a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};O.prototype.lock_mouse=async function(){const a=document.body;try{await a.requestPointerLock({unadjustedMovement:!0})}catch(b){await a.requestPointerLock()}};O.prototype.mouse_set_enabled=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};O.prototype.mouse_set_status=O.prototype.mouse_set_enabled;O.prototype.keyboard_set_enabled=
|
|
328
328
|
function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};O.prototype.keyboard_set_status=O.prototype.keyboard_set_enabled;O.prototype.serial0_send=function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",a.charCodeAt(b))};O.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};O.prototype.serial_set_modem_status=function(a,b){this.bus.send("serial"+a+"-modem-status-input",b)};O.prototype.serial_set_carrier_detect=
|
|
@@ -331,7 +331,7 @@ typeof c,"Filesystem: basefs must be a JSON object"),d.load_from_json(c));a=this
|
|
|
331
331
|
async function(a){k(1===arguments.length);var b=this.fs9p;if(b)return(b=await b.read_file(a))?b:Promise.reject(new vc)};O.prototype.automatically=function(a){const b=c=>{const d=c[0];if(d){var e=c.slice(1);d.sleep?setTimeout(()=>b(e),1E3*d.sleep):d.vga_text?this.wait_until_vga_screen_contains(d.vga_text).then(()=>b(e)):d.keyboard_send?(Array.isArray(d.keyboard_send)?this.keyboard_send_scancodes(d.keyboard_send):(k("string"===typeof d.keyboard_send),this.keyboard_send_text(d.keyboard_send)),b(e)):
|
|
332
332
|
d.call?(d.call(),b(e)):k(!1,d)}};b(a)};O.prototype.wait_until_vga_screen_contains=async function(a,b){const c=Array.isArray(a);var d=b?.timeout_msec||0;const e=new Set;b=p=>e.add(p[0]);const f=(p,q)=>q.test?q.test(p):p.startsWith(q),h=[];this.add_listener("screen-put-char",b);for(var l of this.screen_adapter.get_text_screen())if(c)h.push(l.trimRight());else if(f(l,a))return this.remove_listener("screen-put-char",b),!0;l=!1;d=d?performance.now()+d:0;a:for(;!d||performance.now()<d;){if(c){for(var m=
|
|
333
333
|
h.length;0<m&&""===h[m-1];)m--;m-=a.length;if(0<=m){let p=!0;for(let q=0;q<a.length&&p;q++)p=f(h[m+q],a[q]);if(p){l=!0;break}}}await new Promise(p=>setTimeout(p,100));for(const p of e)if(m=this.screen_adapter.get_text_row(p),c)h[p]=m.trimRight();else if(f(m,a)){l=!0;break a}e.clear()}this.remove_listener("screen-put-char",b);return l};O.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};O.prototype.write_memory=function(a,b){this.v86.cpu.write_blob(a,b)};O.prototype.set_serial_container_xtermjs=
|
|
334
|
-
function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new
|
|
334
|
+
function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new fc(a,this.bus);this.serial_adapter.show()};O.prototype.get_instruction_stats=function(){var a=this.v86.cpu;var b="";var c="COMPILE COMPILE_SKIPPED_NO_NEW_ENTRY_POINTS COMPILE_WRONG_ADDRESS_SPACE COMPILE_CUT_OFF_AT_END_OF_PAGE COMPILE_WITH_LOOP_SAFETY COMPILE_PAGE COMPILE_PAGE/COMPILE COMPILE_BASIC_BLOCK COMPILE_DUPLICATED_BASIC_BLOCK COMPILE_WASM_BLOCK COMPILE_WASM_LOOP COMPILE_DISPATCHER COMPILE_ENTRY_POINT COMPILE_WASM_TOTAL_BYTES COMPILE_WASM_TOTAL_BYTES/COMPILE_PAGE RUN_INTERPRETED RUN_INTERPRETED_NEW_PAGE RUN_INTERPRETED_PAGE_HAS_CODE RUN_INTERPRETED_PAGE_HAS_ENTRY_AFTER_PAGE_WALK RUN_INTERPRETED_NEAR_END_OF_PAGE RUN_INTERPRETED_DIFFERENT_STATE RUN_INTERPRETED_DIFFERENT_STATE_CPL3 RUN_INTERPRETED_DIFFERENT_STATE_FLAT RUN_INTERPRETED_DIFFERENT_STATE_IS32 RUN_INTERPRETED_DIFFERENT_STATE_SS32 RUN_INTERPRETED_MISSED_COMPILED_ENTRY_RUN_INTERPRETED RUN_INTERPRETED_STEPS RUN_FROM_CACHE RUN_FROM_CACHE_STEPS RUN_FROM_CACHE_STEPS/RUN_FROM_CACHE RUN_FROM_CACHE_STEPS/RUN_INTERPRETED_STEPS DIRECT_EXIT INDIRECT_JUMP INDIRECT_JUMP_NO_ENTRY NORMAL_PAGE_CHANGE NORMAL_FALLTHRU NORMAL_FALLTHRU_WITH_TARGET_BLOCK NORMAL_BRANCH NORMAL_BRANCH_WITH_TARGET_BLOCK CONDITIONAL_JUMP CONDITIONAL_JUMP_PAGE_CHANGE CONDITIONAL_JUMP_EXIT CONDITIONAL_JUMP_FALLTHRU CONDITIONAL_JUMP_FALLTHRU_WITH_TARGET_BLOCK CONDITIONAL_JUMP_BRANCH CONDITIONAL_JUMP_BRANCH_WITH_TARGET_BLOCK DISPATCHER_SMALL DISPATCHER_LARGE LOOP LOOP_SAFETY CONDITION_OPTIMISED CONDITION_UNOPTIMISED CONDITION_UNOPTIMISED_PF CONDITION_UNOPTIMISED_UNHANDLED_L CONDITION_UNOPTIMISED_UNHANDLED_LE FAILED_PAGE_CHANGE SAFE_READ_FAST SAFE_READ_SLOW_PAGE_CROSSED SAFE_READ_SLOW_NOT_VALID SAFE_READ_SLOW_NOT_USER SAFE_READ_SLOW_IN_MAPPED_RANGE SAFE_WRITE_FAST SAFE_WRITE_SLOW_PAGE_CROSSED SAFE_WRITE_SLOW_NOT_VALID SAFE_WRITE_SLOW_NOT_USER SAFE_WRITE_SLOW_IN_MAPPED_RANGE SAFE_WRITE_SLOW_READ_ONLY SAFE_WRITE_SLOW_HAS_CODE SAFE_READ_WRITE_FAST SAFE_READ_WRITE_SLOW_PAGE_CROSSED SAFE_READ_WRITE_SLOW_NOT_VALID SAFE_READ_WRITE_SLOW_NOT_USER SAFE_READ_WRITE_SLOW_IN_MAPPED_RANGE SAFE_READ_WRITE_SLOW_READ_ONLY SAFE_READ_WRITE_SLOW_HAS_CODE PAGE_FAULT TLB_MISS MAIN_LOOP MAIN_LOOP_IDLE DO_MANY_CYCLES CYCLE_INTERNAL INVALIDATE_ALL_MODULES_NO_FREE_WASM_INDICES INVALIDATE_MODULE_WRITTEN_WHILE_COMPILED INVALIDATE_MODULE_UNUSED_AFTER_OVERWRITE INVALIDATE_MODULE_DIRTY_PAGE INVALIDATE_PAGE_HAD_CODE INVALIDATE_PAGE_HAD_ENTRY_POINTS DIRTY_PAGE_DID_NOT_HAVE_CODE RUN_FROM_CACHE_EXIT_SAME_PAGE RUN_FROM_CACHE_EXIT_NEAR_END_OF_PAGE RUN_FROM_CACHE_EXIT_DIFFERENT_PAGE CLEAR_TLB FULL_CLEAR_TLB TLB_FULL TLB_GLOBAL_FULL MODRM_SIMPLE_REG MODRM_SIMPLE_REG_WITH_OFFSET MODRM_SIMPLE_CONST_OFFSET MODRM_COMPLEX SEG_OFFSET_OPTIMISED SEG_OFFSET_NOT_OPTIMISED SEG_OFFSET_NOT_OPTIMISED_ES SEG_OFFSET_NOT_OPTIMISED_FS SEG_OFFSET_NOT_OPTIMISED_GS SEG_OFFSET_NOT_OPTIMISED_NOT_FLAT".split(" "),
|
|
335
335
|
d=0;const e={};for(let h=0;h<c.length;h++){const l=c[h];var f=void 0;if(l.includes("/")){d++;const [m,p]=l.split("/");f=e[m]/e[p]}else f=e[l]=a.wm.exports.profiler_stat_get(h-d),f=1E8<=f?Math.round(f/1E6)+"m":1E5<=f?Math.round(f/1E3)+"k":f;b+=l+"="+f+"\n"}b+="\n";c=a.wm.exports.get_valid_tlb_entries_count();d=a.wm.exports.get_valid_global_tlb_entries_count();b=b+("TLB_ENTRIES="+c+" ("+d+" global, "+(c-d)+" non-global)\nWASM_TABLE_FREE=")+(a.wm.exports.jit_get_wasm_table_index_free_list_count()+"\n");
|
|
336
336
|
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[gb(a,!1,!1,!1,!1),gb(a,!0,!1,!1,!1),gb(a,!1,!0,!1,!1),gb(a,!1,
|
|
337
337
|
!1,!0,!1),gb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function wc(a){this.message=a||"File already exists"}wc.prototype=Error.prototype;function vc(a){this.message=a||"File not found"}vc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=O:"undefined"!==typeof window?window.V86=O:"function"===typeof importScripts&&(self.V86=O);function I(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new P(a,
|
|
@@ -481,12 +481,12 @@ this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.st
|
|
|
481
481
|
sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,sectors:44,tracks:80,heads:2},{drive_type:5,sectors:48,tracks:80,heads:2},{drive_type:4,sectors:8,tracks:80,heads:2},{drive_type:4,sectors:9,tracks:80,
|
|
482
482
|
heads:2},{drive_type:4,sectors:10,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:82,heads:2},{drive_type:4,sectors:10,tracks:83,heads:2},{drive_type:4,sectors:13,tracks:80,heads:2},{drive_type:4,sectors:14,tracks:80,heads:2},{drive_type:2,sectors:15,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:82,heads:2},{drive_type:2,sectors:18,tracks:83,heads:2},{drive_type:2,sectors:20,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:80,heads:2},{drive_type:2,
|
|
483
483
|
sectors:11,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:40,heads:2},{drive_type:2,sectors:9,tracks:40,heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Uc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=
|
|
484
|
-
this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d);B("floppy drive "+this.name+" ready, drive type: "+this.drive_type,8192)}Uc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new
|
|
484
|
+
this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d);B("floppy drive "+this.name+" ready, drive type: "+this.drive_type,8192)}Uc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new xa(a.buffer));const [c,d]=this.find_disk_format(a,
|
|
485
485
|
this.drive_type);if(!c)return B("WARNING: disk rejected, no suitable disk format found for image of size "+a.byteLength+" bytes",8192),!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);B("disk inserted into "+this.name+": type: "+d.drive_type+", C/H/S: "+d.tracks+"/"+d.heads+"/"+d.sectors+", size: "+c.byteLength,8192);return!0};Uc.prototype.eject_disk=function(){this.max_sect=
|
|
486
486
|
this.max_head=this.max_track=0;this.media_changed=!0;this.buffer=null};Uc.prototype.get_buffer=function(){return this.buffer?this.buffer.buffer:null};Uc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1};Uc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,h=-1,l=-1,m=-1;for(let p=0;p<Vc.length;p++){const q=Vc[p],r=q.sectors*q.tracks*q.heads*512;if(d===r)if(c||q.drive_type===b){e=p;break}else c||Tc[q.drive_type]!==Tc[b]?h=-1===h?p:h:f=
|
|
487
|
-
-1===f?p:f;else d<r&&(-1===m||r<m)&&(l=p,m=r)}return-1!==e?[a,Vc[e]]:-1!==f?[a,Vc[f]]:-1!==h?[a,Vc[h]]:-1!==l?(b=new Uint8Array(m),b.set(new Uint8Array(a.buffer)),[new
|
|
487
|
+
-1===f?p:f;else d<r&&(-1===m||r<m)&&(l=p,m=r)}return-1!==e?[a,Vc[e]]:-1!==f?[a,Vc[f]]:-1!==h?[a,Vc[h]]:-1!==l?(b=new Uint8Array(m),b.set(new Uint8Array(a.buffer)),[new xa(b.buffer),Vc[l]]):[null,null]};Uc.prototype.seek=function(a,b,c){if(b>this.max_track||0!==a&&1===this.max_head)return B("WARNING: attempt to seek to invalid track: head: "+a+", track: "+b+", sect: "+c,8192),2;if(c>this.max_sect)return B("WARNING: attempt to seek beyond last sector: "+c+" (max: "+this.max_sect+")",8192),3;let d=0;
|
|
488
488
|
const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d};Uc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=
|
|
489
|
-
this.buffer?this.buffer.get_state():null;return a};Uc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new
|
|
489
|
+
this.buffer?this.buffer.get_state():null;return a};Uc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new xa(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Wc={[8]:"DEVICE RESET",[144]:"EXECUTE DEVICE DIAGNOSTIC",[231]:"FLUSH CACHE",[234]:"FLUSH CACHE EXT",
|
|
490
490
|
[218]:"GET MEDIA STATUS",[236]:"IDENTIFY DEVICE",[161]:"IDENTIFY PACKET DEVICE",[225]:"IDLE IMMEDIATE",[145]:"INITIALIZE DEVICE PARAMETERS",[222]:"MEDIA LOCK",[0]:"NOP",[160]:"PACKET",[200]:"READ DMA",[37]:"READ DMA EXT",[41]:"READ MULTIPLE",[196]:"READ MULTIPLE EXT",[248]:"READ NATIVE MAX ADDRESS",[39]:"READ NATIVE MAX ADDRESS EXT",[32]:"READ SECTORS",[36]:"READ SECTORS EXT",[64]:"READ VERIFY SECTORS",[245]:"SECURITY FREEZE LOCK",[239]:"SET FEATURES",[249]:"SET MAX",[198]:"SET MULTIPLE MODE",[224]:"STANDBY IMMEDIATE",
|
|
491
491
|
[202]:"WRITE DMA",[53]:"WRITE DMA EXT",[57]:"WRITE MULTIPLE",[197]:"WRITE MULTIPLE EXT",[48]:"WRITE SECTORS",[52]:"WRITE SECTORS EXT",[16]:"<UNKWNON 10h>"},Xc={[70]:{name:"GET CONFIGURATION",flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},[40]:{name:"READ",flags:1},
|
|
492
492
|
[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},[81]:{name:"READ DISK INFORMATION",flags:1},[66]:{name:"READ SUBCHANNEL",flags:1},[67]:{name:"READ TOC PMA ATIP",flags:1},[82]:{name:"READ TRACK INFORMATION",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function Yc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=c&&c[1][0];if(b||d){b&&(this.primary=new Zc(this,0,c[0],496,
|
|
@@ -669,15 +669,15 @@ for(let p=0;p<this.option_roms.length;p++){const {name:q,data:r}=this.option_rom
|
|
|
669
669
|
c.register_write(233,this,function(){});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);c.register_write(1232,this,
|
|
670
670
|
this.port4D0_write);c.register_write(1233,this,this.port4D1_write);this.devices={};a.load_devices&&(this.devices.pci=new Dc(this),this.acpi_enabled[0]&&(this.devices.ioapic=new Ac(this),this.devices.apic=new zc(this),this.devices.acpi=new Bc(this)),this.devices.rtc=new hb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new C(this),this.devices.vga=new Y(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Jc(this,b),this.devices.uart0=new Cc(this,1016,b),a.uart1&&(this.devices.uart1=
|
|
671
671
|
new Cc(this,760,b)),a.uart2&&(this.devices.uart2=new Cc(this,1E3,b)),a.uart3&&(this.devices.uart3=new Cc(this,744,b)),this.devices.fdc=new W(this,a.fda,a.fdb),c=[[void 0,void 0],[void 0,void 0]],a.hda&&(c[0][0]={buffer:a.hda},c[0][1]={buffer:a.hdb}),c[1][0]={is_cdrom:!0,buffer:a.cdrom},this.devices.ide=new Yc(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,this.devices.pit=new ib(this,b),"ne2k"===a.net_device.type?this.devices.net=new Gc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):
|
|
672
|
-
"virtio"===a.net_device.type&&(this.devices.virtio_net=new $c(this,b,a.preserve_mac_from_state_image)),a.fs9p
|
|
673
|
-
(B("loaded multiboot without bios",2),this.reg32[0]=this.io.port_read32(244)));this.debug_init()};P.prototype.load_multiboot=function(a){this.bios.main&&k(!1,"load_multiboot not supported with BIOS");this.load_multiboot_option_rom(a,void 0,"")&&(B("loaded multiboot",2),this.reg32[0]=this.io.port_read32(244))};P.prototype.load_multiboot_option_rom=function(a,b,c){B("Trying multiboot from buffer of size "+
|
|
674
|
-
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){B("Multiboot checksum check failed",2);continue}}else continue;B("Multiboot magic found, flags: "+n(f>>>0,8),2);k(0===(f&-65540),"TODO");var h=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var q=31860,r=0;if(c){r|=4;h.write32(31760,
|
|
675
|
-
0);h.write32(31792,q);var t=0;let F=!1;for(let x=0;4294967296>x;x+=131072)F&&void 0!==h.memory_map_read8[x>>>17]?(h.write32(q,20),h.write32(q+4,t),h.write32(q+8,0),h.write32(q+12,x-t),h.write32(q+16,0),h.write32(q+20,1),q+=24,v+=24,F=!1):F||void 0!==h.memory_map_read8[x>>>17]||(t=x,F=!0);k(!F,"top of 4GB shouldn't have memory");h.write32(31788,v)}h.write32(31744,r);v=r=0;if(f&65536){B("Multiboot specifies its own address table",
|
|
676
|
-
r=d[e+28>>2];B("header="+n(z,8)+" load="+n(A,8)+" load_end="+n(u,8)+" bss_end="+n(E,8)+" entry="+n(r,8));k(A<=z);z=e-(z-A);0===u?v=void 0:(k(u>=A),v=u-A);z=new Uint8Array(a,z,v);h.write_blob(z,A);r|=0;v=Math.max(u,E)}else if(1179403647===d[0]){B("Multiboot image is in elf format",2);t=new DataView(a);const [F,x]=Rc(t,Oc);console.assert(52===x);for(z of Object.keys(F))B(z+": 0x"+(F[z].toString(16)>>>0));console.assert(1179403647===
|
|
677
|
-
console.assert(1===F.data,"Unimplemented: big endian");console.assert(1===F.version0,"Bad version0");console.assert(2===F.type,"Unimplemented type");console.assert(1===F.version1,"Bad version1");console.assert(52===F.ehsize,"Bad header size");console.assert(32===F.phentsize,"Bad program header size");console.assert(40===F.shentsize,"Bad section header size");[r]=Sc(new DataView(t.buffer,t.byteOffset+F.phoff,F.phentsize*F.phnum),
|
|
678
|
-
F.shnum),Qc,F.shnum);if(va){console.log("%d program headers:",r.length);for(E of r)console.log("type=%s offset=%s vaddr=%s paddr=%s filesz=%s memsz=%s flags=%s align=%s",E.type.toString(16),E.offset.toString(16),E.vaddr.toString(16),E.paddr.toString(16),E.filesz.toString(16),E.memsz.toString(16),E.flags.toString(16),E.align.toString(16));console.log("%d section headers:",z.length);for(A of z)console.log("name=%s type=%s flags=%s addr=%s offset=%s size=%s link=%s info=%s addralign=%s entsize=%s",
|
|
679
|
-
A.type.toString(16),A.flags.toString(16),A.addr.toString(16),A.offset.toString(16),A.size.toString(16),A.link.toString(16),A.info.toString(16),A.addralign.toString(16),A.entsize.toString(16))}E=F;A=r;r=E.entry;for(u of A)0!==u.type&&(1===u.type?(k(u.filesz<=u.memsz),u.paddr+u.memsz<h.memory_size[0]?(u.filesz&&(A=new Uint8Array(a,u.offset,u.filesz),h.write_blob(A,u.paddr)),v=Math.max(v,u.paddr+u.memsz),B("prg load "+u.paddr+" to "+(u.paddr+u.memsz),2),r===E.entry&&u.vaddr<=r&&u.vaddr+
|
|
680
|
-
r-u.vaddr+u.paddr)):B("Warning: Skipped loading section, paddr="+n(u.paddr)+" memsz="+u.memsz,2)):2===u.type||3===u.type||4===u.type||6===u.type||7===u.type||1685382480===u.type||1685382481===u.type||1685382482===u.type||1685382483===u.type?B("skip load type "+u.type+" "+u.paddr+" to "+(u.paddr+u.memsz),2):k(!1,"unimplemented elf section type: "+n(u.type)))}else k(!1,"Not a bootable multiboot format");b&&(h.write32(31764,1),h.write32(31768,q),u=v,0!==(u&4095)&&(u=(u&-4096)+4096),B("ramdisk address "+
|
|
672
|
+
"virtio"===a.net_device.type&&(this.devices.virtio_net=new $c(this,b,a.preserve_mac_from_state_image)),a.fs9p?this.devices.virtio_9p=new fd(a.fs9p,this,b):a.handle9p?this.devices.virtio_9p=new gd(a.handle9p,this):a.proxy9p&&(this.devices.virtio_9p=new hd(a.proxy9p,this)),a.virtio_console&&(this.devices.virtio_console=new Hc(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new dd(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(B("loading multiboot",2),a=this.load_multiboot_option_rom(a.multiboot,
|
|
673
|
+
a.initrd,a.cmdline))&&(this.bios.main?(B("adding option rom for multiboot",2),this.option_roms.push(a)):(B("loaded multiboot without bios",2),this.reg32[0]=this.io.port_read32(244)));this.debug_init()};P.prototype.load_multiboot=function(a){this.bios.main&&k(!1,"load_multiboot not supported with BIOS");this.load_multiboot_option_rom(a,void 0,"")&&(B("loaded multiboot",2),this.reg32[0]=this.io.port_read32(244))};P.prototype.load_multiboot_option_rom=function(a,b,c){B("Trying multiboot from buffer of size "+
|
|
674
|
+
a.byteLength,2);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){B("Multiboot checksum check failed",2);continue}}else continue;B("Multiboot magic found, flags: "+n(f>>>0,8),2);k(0===(f&-65540),"TODO");var h=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var q=31860,r=0;if(c){r|=4;h.write32(31760,
|
|
675
|
+
q);c+="\x00";var v=(new TextEncoder).encode(c);h.write_blob(v,q);q+=v.length}if(f&2){r|=64;v=0;h.write32(31788,0);h.write32(31792,q);var t=0;let F=!1;for(let x=0;4294967296>x;x+=131072)F&&void 0!==h.memory_map_read8[x>>>17]?(h.write32(q,20),h.write32(q+4,t),h.write32(q+8,0),h.write32(q+12,x-t),h.write32(q+16,0),h.write32(q+20,1),q+=24,v+=24,F=!1):F||void 0!==h.memory_map_read8[x>>>17]||(t=x,F=!0);k(!F,"top of 4GB shouldn't have memory");h.write32(31788,v)}h.write32(31744,r);v=r=0;if(f&65536){B("Multiboot specifies its own address table",
|
|
676
|
+
2);var z=d[e+12>>2];var A=d[e+16>>2];var u=d[e+20>>2];var E=d[e+24>>2];r=d[e+28>>2];B("header="+n(z,8)+" load="+n(A,8)+" load_end="+n(u,8)+" bss_end="+n(E,8)+" entry="+n(r,8));k(A<=z);z=e-(z-A);0===u?v=void 0:(k(u>=A),v=u-A);z=new Uint8Array(a,z,v);h.write_blob(z,A);r|=0;v=Math.max(u,E)}else if(1179403647===d[0]){B("Multiboot image is in elf format",2);t=new DataView(a);const [F,x]=Rc(t,Oc);console.assert(52===x);for(z of Object.keys(F))B(z+": 0x"+(F[z].toString(16)>>>0));console.assert(1179403647===
|
|
677
|
+
F.magic,"Bad magic");console.assert(1===F.class,"Unimplemented: 64 bit elf");console.assert(1===F.data,"Unimplemented: big endian");console.assert(1===F.version0,"Bad version0");console.assert(2===F.type,"Unimplemented type");console.assert(1===F.version1,"Bad version1");console.assert(52===F.ehsize,"Bad header size");console.assert(32===F.phentsize,"Bad program header size");console.assert(40===F.shentsize,"Bad section header size");[r]=Sc(new DataView(t.buffer,t.byteOffset+F.phoff,F.phentsize*F.phnum),
|
|
678
|
+
Pc,F.phnum);[z]=Sc(new DataView(t.buffer,t.byteOffset+F.shoff,F.shentsize*F.shnum),Qc,F.shnum);if(va){console.log("%d program headers:",r.length);for(E of r)console.log("type=%s offset=%s vaddr=%s paddr=%s filesz=%s memsz=%s flags=%s align=%s",E.type.toString(16),E.offset.toString(16),E.vaddr.toString(16),E.paddr.toString(16),E.filesz.toString(16),E.memsz.toString(16),E.flags.toString(16),E.align.toString(16));console.log("%d section headers:",z.length);for(A of z)console.log("name=%s type=%s flags=%s addr=%s offset=%s size=%s link=%s info=%s addralign=%s entsize=%s",
|
|
679
|
+
A.name.toString(16),A.type.toString(16),A.flags.toString(16),A.addr.toString(16),A.offset.toString(16),A.size.toString(16),A.link.toString(16),A.info.toString(16),A.addralign.toString(16),A.entsize.toString(16))}E=F;A=r;r=E.entry;for(u of A)0!==u.type&&(1===u.type?(k(u.filesz<=u.memsz),u.paddr+u.memsz<h.memory_size[0]?(u.filesz&&(A=new Uint8Array(a,u.offset,u.filesz),h.write_blob(A,u.paddr)),v=Math.max(v,u.paddr+u.memsz),B("prg load "+u.paddr+" to "+(u.paddr+u.memsz),2),r===E.entry&&u.vaddr<=r&&u.vaddr+
|
|
680
|
+
u.memsz>r&&(r=r-u.vaddr+u.paddr)):B("Warning: Skipped loading section, paddr="+n(u.paddr)+" memsz="+u.memsz,2)):2===u.type||3===u.type||4===u.type||6===u.type||7===u.type||1685382480===u.type||1685382481===u.type||1685382482===u.type||1685382483===u.type?B("skip load type "+u.type+" "+u.paddr+" to "+(u.paddr+u.memsz),2):k(!1,"unimplemented elf section type: "+n(u.type)))}else k(!1,"Not a bootable multiboot format");b&&(h.write32(31764,1),h.write32(31768,q),u=v,0!==(u&4095)&&(u=(u&-4096)+4096),B("ramdisk address "+
|
|
681
681
|
u),E=u+b.byteLength,h.write32(q,u),h.write32(q+4,E),h.write32(q+8,0),h.write32(q+12,0),k(E<h.memory_size[0]),h.write_blob(new Uint8Array(b),u));h.reg32[3]=31744;h.cr[0]=1;h.protected_mode[0]=1;h.flags[0]=2;h.is_32[0]=1;h.stack_size_32[0]=1;for(q=0;6>q;q++)h.segment_is_null[q]=0,h.segment_offsets[q]=0,h.segment_limits[q]=4294967295,h.sreg[q]=45058;h.instruction_pointer[0]=h.get_seg_cs()+r|0;h.update_state_flags();B("Starting multiboot kernel at:",2);h.dump_state();h.dump_regs_short();return 732803074});
|
|
682
682
|
this.io.register_write_consecutive(244,this,function(q){console.log("Test exited with code "+n(q,2));throw"HALT";},function(){},function(){},function(){});for(let q=0;15>=q;q++){function r(v){B("kvm-unit-test: Set irq "+n(q)+" to "+n(v,2));v?this.device_raise_irq(q):this.device_lower_irq(q)}this.io.register_write(8192+q,this,r,r,r)}const m=new Uint8Array(512);(new Uint16Array(m.buffer))[0]=43605;m[2]=1;var l=3;m[l++]=102;m[l++]=229;m[l++]=244;k(512>l);let p=m[l]=0;for(let q=0;q<m.length;q++)p+=m[q];
|
|
683
683
|
m[l]=-p;return{name:"genroms/multiboot.bin",data:m}}B("Multiboot header not found",2)};P.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]&&(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,
|
|
@@ -722,37 +722,44 @@ a;this.pci.raise_irq(this.pci_id)};Ic.prototype.lower_irq=function(){B("Lower ir
|
|
|
722
722
|
this.enabled;a[3]=this.notify_offset;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};Z.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]};Z.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=
|
|
723
723
|
this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};Z.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};Z.prototype.enable=function(){k(this.is_configured(),"VirtQueue must be configured before enabled");this.enabled=!0};Z.prototype.set_size=function(a){k(0===(a&a-1),"VirtQueue size must be power of 2 or zero");k(a<=this.size_supported,"VirtQueue size must be within supported size");this.size=a;this.mask=
|
|
724
724
|
a-1};Z.prototype.count_requests=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");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&65535};Z.prototype.has_request=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");return 0!==this.count_requests()};Z.prototype.pop_request=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");
|
|
725
|
-
k(this.has_request(),"VirtQueue must not pop nonexistent request");var a=this.avail_get_entry(this.avail_last_idx);B("Pop request: avail_last_idx="+this.avail_last_idx+" desc_idx="+a,2097152);a=new
|
|
725
|
+
k(this.has_request(),"VirtQueue must not pop nonexistent request");var a=this.avail_get_entry(this.avail_last_idx);B("Pop request: avail_last_idx="+this.avail_last_idx+" desc_idx="+a,2097152);a=new id(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Z.prototype.push_reply=function(a){k(this.used_addr,"VirtQueue addresses must be configured before use");k(this.num_staged_replies<this.size,"VirtQueue replies must not exceed queue size");const b=this.used_get_idx()+this.num_staged_replies&
|
|
726
726
|
this.mask;B("Push reply: used_idx="+b+" desc_idx="+a.head_idx,2097152);this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};Z.prototype.flush_replies=function(){k(this.used_addr,"VirtQueue addresses must be configured before use");if(0===this.num_staged_replies)B("flush_replies: Nothing to flush",2097152);else{B("Flushing "+this.num_staged_replies+" replies",2097152);var a=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)?
|
|
727
727
|
(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Z.prototype.notify_me_after=function(a){k(0<=a,"Must skip a non-negative number of requests");a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Z.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+16*b+12),next:this.cpu.read16(a+16*b+14)}};Z.prototype.avail_get_flags=
|
|
728
728
|
function(){return this.cpu.read16(this.avail_addr)};Z.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Z.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Z.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Z.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};Z.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};Z.prototype.used_get_idx=
|
|
729
|
-
function(){return this.cpu.read16(this.used_addr+2)};Z.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Z.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)};Z.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function
|
|
729
|
+
function(){return this.cpu.read16(this.used_addr+2)};Z.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Z.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)};Z.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function id(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=
|
|
730
730
|
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 h=this.virtio.is_feature_negotiated(28);B("<<< Descriptor chain start",2097152);do{const l=a.get_descriptor(c,b);B("descriptor: idx="+b+" addr="+n(l.addr_high,8)+":"+n(l.addr_low,8)+" len="+n(l.len,8)+" flags="+n(l.flags,4)+" next="+n(l.next,4),2097152);if(h&&l.flags&4)l.flags&1&&B("Driver bug: has set VIRTQ_DESC_F_NEXT flag in an indirect table descriptor",
|
|
731
|
-
2097152),c=l.addr_low,d=b=0,e=l.len/16,B("start indirect",2097152);else{if(l.flags&2)f=!0,this.write_buffers.push(l),this.length_writable+=l.len;else{if(f){B("Driver bug: readonly buffer after writeonly buffer within chain",2097152);break}this.read_buffers.push(l);this.length_readable+=l.len}d++;if(d>e){B("Driver bug: descriptor chain cycle detected",2097152);break}if(l.flags&1)b=l.next;else break}}while(1);B("Descriptor chain end >>>",2097152)}
|
|
732
|
-
for(;c;){if(this.read_buffer_idx===this.read_buffers.length){B("Device<"+this.virtio.name+"> Read more than device-readable buffers has",2097152);break}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};
|
|
733
|
-
this.write_buffers.length){B("Device<"+this.virtio.name+"> Write more than device-writable capacity",2097152);break}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};const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
function(){var a=[];a[0]=this.configspace_tagname;a[1]=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};fd.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);
|
|
737
|
-
a[5];this.replybuffer=a[6];this.replybuffersize=a[7];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])};fd.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};fd.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};fd.prototype.reset=function(){this.fids=[];this.virtio.reset()};fd.prototype.BuildReply=
|
|
738
|
-
[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&B("Error in 9p: payloadsize exceeds maximum length",4194304);this.replybuffersize=c+7};fd.prototype.SendError=function(a,b,c){b=J(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};fd.prototype.SendReply=function(a){k(0<=this.replybuffersize,"9P: Negative replybuffersize");a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);
|
|
739
|
-
new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=K(["w","b","h"],b,c),e=d[0],f=d[1],h=d[2];switch(f){case 8:e=this.fs.GetTotalSize();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=J("wwddddddw".split(""),d,this.replybuffer,7);
|
|
740
|
-
var l=d[0];c=d[1];B("[open] fid="+l+", mode="+c,4194304);b=this.fids[l].inodeid;var m=this.fs.GetInode(b);B("file open "+this.fids[l].dbg_name,4194304);d=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[l].inodeid,function(){B("file opened "+this.fids[l].dbg_name+" tag:"+h,4194304);var v=[];v[0]=m.qid;v[1]=this.msize-24;J(["Q","w"],v,this.replybuffer,7);this.BuildReply(f,h,17);this.SendReply(a)}.bind(this));break;
|
|
741
|
-
4194304);d=this.fs.Link(this.fids[b].inodeid,this.fids[l].inodeid,e);if(0>d){e="";-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[link]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 16:d=K(["w","s","s","w"],b,c);l=d[0];e=d[1];b=d[2];d=d[3];B("[symlink] fid="+l+", name="+e+", symgt="+b+", gid="+d,4194304);b=this.fs.CreateSymlink(e,
|
|
742
|
-
m.gid=d;J(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 18:d=K("wswwww".split(""),b,c);l=d[0];e=d[1];c=d[2];b=d[3];var p=d[4];d=d[5];B("[mknod] fid="+l+", name="+e+", major="+b+", minor="+p,4194304);b=this.fs.CreateNode(e,this.fids[l].inodeid,b,p);m=this.fs.GetInode(b);m.mode=c;m.uid=this.fids[l].uid;m.gid=d;J(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;
|
|
743
|
-
B("[readlink] fid="+l+" name="+this.fids[l].dbg_name+" target="+m.symlink,4194304);e=J(["s"],[m.symlink],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 72:d=K(["w","s","w","w"],b,c);l=d[0];e=d[1];c=d[2];d=d[3];B("[mkdir] fid="+l+", name="+e+", mode="+c+", gid="+d,4194304);b=this.fs.CreateDirectory(e,this.fids[l].inodeid);m=this.fs.GetInode(b);m.mode=c|16384;m.uid=this.fids[l].uid;m.gid=d;J(["Q"],[m.qid],
|
|
744
|
-
K(["w","s","w","w","w"],b,c);l=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[l].inodeid]);B("[create] fid="+l+", name="+e+", flags="+b+", mode="+c+", gid="+d,4194304);b=this.fs.CreateFile(e,this.fids[l].inodeid);this.fids[l].inodeid=b;this.fids[l].type=1;this.fids[l].dbg_name=e;m=this.fs.GetInode(b);m.uid=this.fids[l].uid;m.gid=d;m.mode=c|32768;J(["Q","w"],[m.qid,this.msize-24],this.replybuffer,
|
|
745
|
-
b,c);l=d[0];b=d[2];e=0===d[4]?Infinity:d[4];e=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);B("[lock] fid="+l+", type="+
|
|
746
|
-
", proc_id="+e.proc_id);d=this.fs.GetLock(this.fids[l].inodeid,e);d||(d=e,d.type=2);e=J(["b","d","d","w","s"],[d.type,d.start,Infinity===d.length?0:d.length,d.proc_id,d.client_id],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 24:d=K(["w","d"],b,c);l=d[0];m=this.fs.GetInode(this.fids[l].inodeid);B("[getattr]: fid="+l+" name="+this.fids[l].dbg_name+" request mask="+d[1],4194304);if(!m||
|
|
747
|
-
2);this.SendReply(a);break}d[0]=d[1];d[1]=m.qid;d[2]=m.mode;d[3]=m.uid;d[4]=m.gid;d[5]=m.nlinks;d[6]=m.major<<8|m.minor;d[7]=m.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(m.size/512+1);d[10]=m.atime;d[11]=0;d[12]=m.mtime;d[13]=0;d[14]=m.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;J("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,h,153);this.SendReply(a);break;case 26:d=K("wwwwwddddd".split(""),
|
|
748
|
-
d[1]+" name="+this.fids[l].dbg_name,4194304);d[1]&1&&(m.mode=d[2]);d[1]&2&&(m.uid=d[3]);d[1]&4&&(m.gid=d[4]);d[1]&16&&(m.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(m.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(m.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(m.atime=d[6]);d[1]&256&&(m.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[l].inodeid,d[5]);this.BuildReply(f,h,0);
|
|
749
|
-
break;case 40:case 116:d=K(["w","d","w"],b,c);l=d[0];e=d[1];p=d[2];m=this.fs.GetInode(this.fids[l].inodeid);40===f&&B("[treaddir]: fid="+l+" offset="+e+" count="+p,4194304);116===f&&B("[read]: fid="+l+" ("+this.fids[l].dbg_name+") offset="+e+" count="+p+" fidtype="+this.fids[l].type,4194304);if(!m||4===m.status){B("read/treaddir: unlinked",4194304);this.SendError(h,"No such file or directory",2);this.SendReply(a);
|
|
750
|
-
d]=m.caps[e+d];else this.fs.OpenInode(this.fids[l].inodeid,void 0),d=this.fids[l].inodeid,p=Math.min(p,this.replybuffer.length-11),m.size<e+p?p=m.size-e:40===f&&(p=this.fs.RoundToDirentry(d,e+p)-e),e>m.size&&(p=0),this.bus.send("9p-read-start",[this.fids[l].dbg_name]),d=await this.fs.Read(d,e,p),this.bus.send("9p-read-end",[this.fids[l].dbg_name,p]),d&&this.replybuffer.set(d,11);J(["w"],[p],this.replybuffer,
|
|
751
|
-
e=d[1];p=d[2];d=this.fids[l].dbg_name;B("[write]: fid="+l+" ("+d+") offset="+e+" count="+p+" fidtype="+this.fids[l].type,4194304);if(2===this.fids[l].type){this.SendError(h,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[l].inodeid,e,p,b.subarray(c.offset));this.bus.send("9p-write-end",[d,p]);J(["w"],[p],this.replybuffer,7);this.BuildReply(f,h,4);this.SendReply(a);break;
|
|
752
|
-
b+" newname="+d,4194304);d=await this.fs.Rename(this.fids[e].inodeid,b,this.fids[c].inodeid,d);if(0>d){e="";-2===d?e="No such file or directory":-1===d?e="Operation not permitted":-39===d?e="Directory not empty":(e="Unknown error: "+-d,k(!1,"[renameat]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 76:d=K(["w","s","w"],b,c);c=d[0];
|
|
753
|
-
e);if(-1===l){this.SendError(h,"No such file or directory",2);this.SendReply(a);break}d=this.fs.Unlink(this.fids[c].inodeid,e);if(0>d){e="";-39===d?e="Directory not empty":-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[unlink]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 100:d=K(["w","s"],
|
|
754
|
-
new Uint8Array(Math.min(16777216,2*this.msize)));e=J(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 104:d=K(["w","w","s","s","w"],b,c);l=d[0];e=d[4];B("[attach]: fid="+l+" afid="+n(d[1])+" uname="+d[2]+" aname="+d[3],4194304);this.fids[l]=this.Createfid(0,1,e,"");m=this.fs.GetInode(this.fids[l].inodeid);J(["Q"],[m.qid],this.replybuffer,
|
|
755
|
-
B("[flush] "+h,4194304);this.BuildReply(f,h,0);this.SendReply(a);break;case 110:d=K(["w","w","h"],b,c);l=d[0];p=d[1];var q=d[2];B("[walk]: fid="+d[0]+" nwfid="+d[1]+" nwname="+q,4194304);if(0===q){this.fids[p]=this.Createfid(this.fids[l].inodeid,1,this.fids[l].uid,this.fids[l].dbg_name);J(["h"],[0],this.replybuffer,7);this.BuildReply(f,h,2);this.SendReply(a);break}e=[];for(d=0;d<q;d++)e.push("s");
|
|
756
|
-
4194304);for(d=0;d<q;d++){b=this.fs.Search(b,c[d]);if(-1===b){B("Could not find: "+c[d],4194304);break}e+=J(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,e);r++;this.fids[p]=this.Createfid(b,1,this.fids[l].uid,c[d])}J(["h"],[r],this.replybuffer,7);this.BuildReply(f,h,e-7);this.SendReply(a);break;case 120:d=K(["w"],b,c);B("[clunk]: fid="+d[0],4194304);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&
|
|
757
|
-
this.BuildReply(f,h,0);this.SendReply(a);break;case 32:d=K(["w","s","d","w"],b,c);l=d[0];e=d[1];c=d[2];b=d[3];B("[txattrcreate]: fid="+l+" name="+e+" attr_size="+c+" flags="+b,4194304);this.fids[l].type=2;this.BuildReply(f,h,0);this.SendReply(a);break;case 30:d=K(["w","w","s"],b,c);l=d[0];e=d[2];B("[xattrwalk]: fid="+d[0]+" newfid="+d[1]+" name="+d[2],4194304);this.SendError(h,"Setxattr not supported",
|
|
758
|
-
|
|
731
|
+
2097152),c=l.addr_low,d=b=0,e=l.len/16,B("start indirect",2097152);else{if(l.flags&2)f=!0,this.write_buffers.push(l),this.length_writable+=l.len;else{if(f){B("Driver bug: readonly buffer after writeonly buffer within chain",2097152);break}this.read_buffers.push(l);this.length_readable+=l.len}d++;if(d>e){B("Driver bug: descriptor chain cycle detected",2097152);break}if(l.flags&1)b=l.next;else break}}while(1);B("Descriptor chain end >>>",2097152)}id.prototype.get_next_blob=function(a){let b=0,c=a.length;
|
|
732
|
+
for(;c;){if(this.read_buffer_idx===this.read_buffers.length){B("Device<"+this.virtio.name+"> Read more than device-readable buffers has",2097152);break}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};id.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c;){if(this.write_buffer_idx===
|
|
733
|
+
this.write_buffers.length){B("Device<"+this.virtio.name+"> Write more than device-writable capacity",2097152);break}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};const jd=["shared","exclusive","unlock"];function kd(a,b,c,d){const e=new Ic(a,{name:"virtio-9p",
|
|
734
|
+
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:[f=>{if(0!==f)k(!1,"Virtio9P Notified for non-existent queue: "+f+" (expected queue_id of 0)");else{for(f=e.queues[0];f.has_request();){const h=f.pop_request();d(h)}f.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",
|
|
735
|
+
read:()=>b,write:()=>{}}].concat(Array.from(Array(254).keys()).map(f=>({bytes:1,name:"mount tag name "+f,read:()=>c[f]||0,write:()=>{}})))}});return e}function fd(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=kd(b,this.configspace_taglen,this.configspace_tagname,this.ReceiveRequest.bind(this));this.virtqueue=this.virtio.queues[0];this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=
|
|
736
|
+
new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[]}fd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=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};fd.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);
|
|
737
|
+
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];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])};fd.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};fd.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};fd.prototype.reset=function(){this.fids=[];this.virtio.reset()};fd.prototype.BuildReply=
|
|
738
|
+
function(a,b,c){k(0<=c,"9P: Negative payload size");J(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&B("Error in 9p: payloadsize exceeds maximum length",4194304);this.replybuffersize=c+7};fd.prototype.SendError=function(a,b,c){b=J(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};fd.prototype.SendReply=function(a){k(0<=this.replybuffersize,"9P: Negative replybuffersize");a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);
|
|
739
|
+
this.virtqueue.flush_replies()};fd.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=K(["w","b","h"],b,c),e=d[0],f=d[1],h=d[2];switch(f){case 8:e=this.fs.GetTotalSize();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=J("wwddddddw".split(""),d,this.replybuffer,7);
|
|
740
|
+
this.BuildReply(f,h,e);this.SendReply(a);break;case 112:case 12:d=K(["w","w"],b,c);var l=d[0];c=d[1];B("[open] fid="+l+", mode="+c,4194304);b=this.fids[l].inodeid;var m=this.fs.GetInode(b);B("file open "+this.fids[l].dbg_name,4194304);d=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[l].inodeid,function(){B("file opened "+this.fids[l].dbg_name+" tag:"+h,4194304);var v=[];v[0]=m.qid;v[1]=this.msize-24;J(["Q","w"],v,this.replybuffer,7);this.BuildReply(f,h,17);this.SendReply(a)}.bind(this));break;
|
|
741
|
+
case 70:d=K(["w","w","s"],b,c);b=d[0];l=d[1];e=d[2];B("[link] dfid="+b+", name="+e,4194304);d=this.fs.Link(this.fids[b].inodeid,this.fids[l].inodeid,e);if(0>d){e="";-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[link]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 16:d=K(["w","s","s","w"],b,c);l=d[0];e=d[1];b=d[2];d=d[3];B("[symlink] fid="+l+", name="+e+", symgt="+b+", gid="+d,4194304);b=this.fs.CreateSymlink(e,
|
|
742
|
+
this.fids[l].inodeid,b);m=this.fs.GetInode(b);m.uid=this.fids[l].uid;m.gid=d;J(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 18:d=K("wswwww".split(""),b,c);l=d[0];e=d[1];c=d[2];b=d[3];var p=d[4];d=d[5];B("[mknod] fid="+l+", name="+e+", major="+b+", minor="+p,4194304);b=this.fs.CreateNode(e,this.fids[l].inodeid,b,p);m=this.fs.GetInode(b);m.mode=c;m.uid=this.fids[l].uid;m.gid=d;J(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;
|
|
743
|
+
case 22:d=K(["w"],b,c);l=d[0];m=this.fs.GetInode(this.fids[l].inodeid);B("[readlink] fid="+l+" name="+this.fids[l].dbg_name+" target="+m.symlink,4194304);e=J(["s"],[m.symlink],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 72:d=K(["w","s","w","w"],b,c);l=d[0];e=d[1];c=d[2];d=d[3];B("[mkdir] fid="+l+", name="+e+", mode="+c+", gid="+d,4194304);b=this.fs.CreateDirectory(e,this.fids[l].inodeid);m=this.fs.GetInode(b);m.mode=c|16384;m.uid=this.fids[l].uid;m.gid=d;J(["Q"],[m.qid],
|
|
744
|
+
this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 14:d=K(["w","s","w","w","w"],b,c);l=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[l].inodeid]);B("[create] fid="+l+", name="+e+", flags="+b+", mode="+c+", gid="+d,4194304);b=this.fs.CreateFile(e,this.fids[l].inodeid);this.fids[l].inodeid=b;this.fids[l].type=1;this.fids[l].dbg_name=e;m=this.fs.GetInode(b);m.uid=this.fids[l].uid;m.gid=d;m.mode=c|32768;J(["Q","w"],[m.qid,this.msize-24],this.replybuffer,
|
|
745
|
+
7);this.BuildReply(f,h,17);this.SendReply(a);break;case 52:d=K("wbwddws".split(""),b,c);l=d[0];b=d[2];e=0===d[4]?Infinity:d[4];e=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);B("[lock] fid="+l+", type="+jd[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.Lock(this.fids[l].inodeid,e,b);J(["b"],[d],this.replybuffer,7);this.BuildReply(f,h,1);this.SendReply(a);break;case 54:d=K("wbddws".split(""),b,c);l=d[0];e=0===d[3]?Infinity:d[3];e=this.fs.DescribeLock(d[1],d[2],e,d[4],
|
|
746
|
+
d[5]);B("[getlock] fid="+l+", type="+jd[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.GetLock(this.fids[l].inodeid,e);d||(d=e,d.type=2);e=J(["b","d","d","w","s"],[d.type,d.start,Infinity===d.length?0:d.length,d.proc_id,d.client_id],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 24:d=K(["w","d"],b,c);l=d[0];m=this.fs.GetInode(this.fids[l].inodeid);B("[getattr]: fid="+l+" name="+this.fids[l].dbg_name+" request mask="+d[1],4194304);if(!m||
|
|
747
|
+
4===m.status){B("getattr: unlinked",4194304);this.SendError(h,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=m.qid;d[2]=m.mode;d[3]=m.uid;d[4]=m.gid;d[5]=m.nlinks;d[6]=m.major<<8|m.minor;d[7]=m.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(m.size/512+1);d[10]=m.atime;d[11]=0;d[12]=m.mtime;d[13]=0;d[14]=m.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;J("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,h,153);this.SendReply(a);break;case 26:d=K("wwwwwddddd".split(""),
|
|
748
|
+
b,c);l=d[0];m=this.fs.GetInode(this.fids[l].inodeid);B("[setattr]: fid="+l+" request mask="+d[1]+" name="+this.fids[l].dbg_name,4194304);d[1]&1&&(m.mode=d[2]);d[1]&2&&(m.uid=d[3]);d[1]&4&&(m.gid=d[4]);d[1]&16&&(m.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(m.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(m.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(m.atime=d[6]);d[1]&256&&(m.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[l].inodeid,d[5]);this.BuildReply(f,h,0);
|
|
749
|
+
this.SendReply(a);break;case 50:d=K(["w","d"],b,c);l=d[0];this.BuildReply(f,h,0);this.SendReply(a);break;case 40:case 116:d=K(["w","d","w"],b,c);l=d[0];e=d[1];p=d[2];m=this.fs.GetInode(this.fids[l].inodeid);40===f&&B("[treaddir]: fid="+l+" offset="+e+" count="+p,4194304);116===f&&B("[read]: fid="+l+" ("+this.fids[l].dbg_name+") offset="+e+" count="+p+" fidtype="+this.fids[l].type,4194304);if(!m||4===m.status){B("read/treaddir: unlinked",4194304);this.SendError(h,"No such file or directory",2);this.SendReply(a);
|
|
750
|
+
break}if(2===this.fids[l].type)for(m.caps.length<e+p&&(p=m.caps.length-e),d=0;d<p;d++)this.replybuffer[11+d]=m.caps[e+d];else this.fs.OpenInode(this.fids[l].inodeid,void 0),d=this.fids[l].inodeid,p=Math.min(p,this.replybuffer.length-11),m.size<e+p?p=m.size-e:40===f&&(p=this.fs.RoundToDirentry(d,e+p)-e),e>m.size&&(p=0),this.bus.send("9p-read-start",[this.fids[l].dbg_name]),d=await this.fs.Read(d,e,p),this.bus.send("9p-read-end",[this.fids[l].dbg_name,p]),d&&this.replybuffer.set(d,11);J(["w"],[p],this.replybuffer,
|
|
751
|
+
7);this.BuildReply(f,h,4+p);this.SendReply(a);break;case 118:d=K(["w","d","w"],b,c);l=d[0];e=d[1];p=d[2];d=this.fids[l].dbg_name;B("[write]: fid="+l+" ("+d+") offset="+e+" count="+p+" fidtype="+this.fids[l].type,4194304);if(2===this.fids[l].type){this.SendError(h,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[l].inodeid,e,p,b.subarray(c.offset));this.bus.send("9p-write-end",[d,p]);J(["w"],[p],this.replybuffer,7);this.BuildReply(f,h,4);this.SendReply(a);break;
|
|
752
|
+
case 74:d=K(["w","s","w","s"],b,c);e=d[0];b=d[1];c=d[2];d=d[3];B("[renameat]: oldname="+b+" newname="+d,4194304);d=await this.fs.Rename(this.fids[e].inodeid,b,this.fids[c].inodeid,d);if(0>d){e="";-2===d?e="No such file or directory":-1===d?e="Operation not permitted":-39===d?e="Directory not empty":(e="Unknown error: "+-d,k(!1,"[renameat]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 76:d=K(["w","s","w"],b,c);c=d[0];
|
|
753
|
+
e=d[1];b=d[2];B("[unlink]: dirfd="+c+" name="+e+" flags="+b,4194304);l=this.fs.Search(this.fids[c].inodeid,e);if(-1===l){this.SendError(h,"No such file or directory",2);this.SendReply(a);break}d=this.fs.Unlink(this.fids[c].inodeid,e);if(0>d){e="";-39===d?e="Directory not empty":-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[unlink]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 100:d=K(["w","s"],
|
|
754
|
+
b,c);B("[version]: msize="+d[0]+" version="+d[1],4194304);this.msize!==d[0]&&(this.msize=d[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));e=J(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 104:d=K(["w","w","s","s","w"],b,c);l=d[0];e=d[4];B("[attach]: fid="+l+" afid="+n(d[1])+" uname="+d[2]+" aname="+d[3],4194304);this.fids[l]=this.Createfid(0,1,e,"");m=this.fs.GetInode(this.fids[l].inodeid);J(["Q"],[m.qid],this.replybuffer,
|
|
755
|
+
7);this.BuildReply(f,h,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=K(["h"],b,c);B("[flush] "+h,4194304);this.BuildReply(f,h,0);this.SendReply(a);break;case 110:d=K(["w","w","h"],b,c);l=d[0];p=d[1];var q=d[2];B("[walk]: fid="+d[0]+" nwfid="+d[1]+" nwname="+q,4194304);if(0===q){this.fids[p]=this.Createfid(this.fids[l].inodeid,1,this.fids[l].uid,this.fids[l].dbg_name);J(["h"],[0],this.replybuffer,7);this.BuildReply(f,h,2);this.SendReply(a);break}e=[];for(d=0;d<q;d++)e.push("s");
|
|
756
|
+
c=K(e,b,c);b=this.fids[l].inodeid;e=9;var r=0;B("walk in dir "+this.fids[l].dbg_name+" to: "+c.toString(),4194304);for(d=0;d<q;d++){b=this.fs.Search(b,c[d]);if(-1===b){B("Could not find: "+c[d],4194304);break}e+=J(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,e);r++;this.fids[p]=this.Createfid(b,1,this.fids[l].uid,c[d])}J(["h"],[r],this.replybuffer,7);this.BuildReply(f,h,e-7);this.SendReply(a);break;case 120:d=K(["w"],b,c);B("[clunk]: fid="+d[0],4194304);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&
|
|
757
|
+
(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type=-1);this.BuildReply(f,h,0);this.SendReply(a);break;case 32:d=K(["w","s","d","w"],b,c);l=d[0];e=d[1];c=d[2];b=d[3];B("[txattrcreate]: fid="+l+" name="+e+" attr_size="+c+" flags="+b,4194304);this.fids[l].type=2;this.BuildReply(f,h,0);this.SendReply(a);break;case 30:d=K(["w","w","s"],b,c);l=d[0];e=d[2];B("[xattrwalk]: fid="+d[0]+" newfid="+d[1]+" name="+d[2],4194304);this.SendError(h,"Setxattr not supported",
|
|
758
|
+
95);this.SendReply(a);break;default:B("Error in Virtio9p: Unknown id "+f+" received",4194304),k(!1)}};function gd(a,b){this.handle_fn=a;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=kd(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);var e=K(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.handle_fn(d,f=>{var h=K(["w",
|
|
759
|
+
"b","h"],f,{offset:0})[2];const l=this.tag_bufchain.get(h);l?(l.set_next_blob(f),this.virtqueue.push_reply(l),this.virtqueue.flush_replies(),this.tag_bufchain.delete(h)):console.error("No bufchain found for tag: "+h)})});this.virtqueue=this.virtio.queues[0]}gd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};gd.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];
|
|
760
|
+
this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.tag_bufchain=a[3]};gd.prototype.reset=function(){this.virtio.reset()};function hd(a,b){this.socket=void 0;this.cpu=b;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=kd(b,this.configspace_taglen,
|
|
761
|
+
this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);const e=K(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.send(d)});this.virtqueue=this.virtio.queues[0]}hd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};hd.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=
|
|
762
|
+
this.virtio.queues[0];this.tag_bufchain=a[3]};hd.prototype.reset=function(){this.virtio.reset()};hd.prototype.handle_message=function(a){a=new Uint8Array(a.data);const b=K(["w","b","h"],a,{offset:0})[2],c=this.tag_bufchain.get(b);c?(c.set_next_blob(a),this.virtqueue.push_reply(c),this.virtqueue.flush_replies(),this.tag_bufchain.delete(b)):console.error("Virtio9pProxy: No bufchain found for tag: "+b)};hd.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),
|
|
763
|
+
this.reconnect_interval))};hd.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};hd.prototype.handle_error=function(){};hd.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};hd.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=
|
|
764
|
+
Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};hd.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=
|
|
765
|
+
this.send_queue.slice(-this.send_queue_limit)),this.connect())};hd.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};export{};; export default module.exports.V86; export let {V86, CPU} = module.exports;
|