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.mjs
CHANGED
|
@@ -7,35 +7,35 @@ pa;if("undefined"===typeof XMLHttpRequest||"undefined"!==typeof process&&process
|
|
|
7
7
|
(a=await import("node:fs/promises"));return(await a.stat(b)).size}}else na=async function(a,b,c){function d(){const l=c||0;setTimeout(()=>{na(a,b,l+1)},1E3*([1,1,2,3,5,8,13,21][l]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.as_json?"json":"arraybuffer";if(b.headers)for(var f=Object.keys(b.headers),g=0;g<f.length;g++){var h=f[g];e.setRequestHeader(h,b.headers[h])}b.range&&(f=b.range.start,e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHeader("X-Accept-Encoding",
|
|
8
8
|
"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),500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const l=e.getResponseHeader("Content-Encoding");l&&"identity"!==l&&console.error("Server sent Content-Encoding in response to ranged request",
|
|
9
9
|
{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)},pa=async function(a){return new Promise((b,c)=>{na(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(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"}})})};function qa(){}function ra(){}
|
|
10
|
-
function sa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*oa,C=8*R,J=
|
|
11
|
-
ka);S=!1;for(let
|
|
10
|
+
function sa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*oa,C=8*R,J=Ua?Ua.canvas:null;J&&J.width===t&&J.height===C||(J?(J.width=t,J.height=C):(J=new OffscreenCanvas(t,C),Ua=J.getContext("2d")),Eb=Ua.createImageData(t,C));const Q=Eb.data;let P=0,S;C=Fb?function(Z){S=S||Z;Q[P+3]=Z;Q[P+7]=Z;P+=8}:function(Z){S=S||Z;Q[P+3]=Z;P+=4};J=32-R;const ka=t*(R-1)*4;t=4*(oa-t*R);const ha=1020*oa;for(let Z=0,Fa=0;2048>Z;++Z,Fa+=J,P+=t){const Ga=Z%256;Z&&!Ga&&(P+=
|
|
11
|
+
ka);S=!1;for(let Ma=0;Ma<R;++Ma,++Fa,P+=ha){const Na=w[Fa];for(let ua=128;0<ua;ua>>=1)C(Na&ua?255:0);Gb&&C(Hb&&192<=Ga&&223>=Ga&&Na&1?255:0)}ac[Z]=S?1:0}Ua.putImageData(Eb,0,0)}function e(w,t,C,J){if(t&&C){w.style.width="";w.style.height="";J&&(w.style.transform="");var Q=w.getBoundingClientRect();J?w.style.transform=(1===t?"":" scaleX("+t+")")+(1===C?"":" scaleY("+C+")"):(0===t%1&&0===C%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):
|
|
12
12
|
(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),J=window.devicePixelRatio||1,0!==J%1&&(t/=J,C/=J));1!==t&&(w.style.width=Q.width*t+"px");1!==C&&(w.style.height=Q.height*C+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],h=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?
|
|
13
|
-
a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,y,u,H,
|
|
13
|
+
a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,y,u,H,N,v,L,T,Ua,Eb,ac=new Int8Array(2048),R,oa,Gb,Fb,Hb,Ib=0,Jb=0,pb,bc=0,qb,Kb,rb,Lb=[],sb=Lb,tb=0,Mb=!1;this.init=function(){const w=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]),t=new Uint16Array([8962,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,
|
|
14
14
|
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,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 C=0,J;256>C;C++)J=126<C?t[C-127]:32>C?w[C]:
|
|
15
|
-
C,
|
|
16
|
-
J.imageSmoothingEnabled=!1;J.font=window.getComputedStyle(l).font;J.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<
|
|
17
|
-
this.put_char=function(w,t,C,J,Q,P){t=4*(w*
|
|
18
|
-
if(266<w-
|
|
19
|
-
ha,
|
|
20
|
-
0,0)}};this.destroy=function(){
|
|
21
|
-
w,R=w,oa=S,
|
|
22
|
-
T=(new OffscreenCanvas(w,C)).getContext("2d")),this.set_size_graphical(w,t,w,t),y.fill(1))}};this.set_size_text=function(w,t){if(w!==
|
|
23
|
-
t;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_charmap=function(w){
|
|
24
|
-
t){if(w!==n||t!==p)w<v&&(y[w]=1),n<v&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*
|
|
25
|
-
break}S.textContent=C;Q.appendChild(S)}J.parentNode.replaceChild(Q,J)};this.update_buffer=function(w){for(const t of w)h.putImageData(t.image_data,t.screen_x-t.buffer_x,t.screen_y-t.buffer_y,t.buffer_x,t.buffer_y,t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<v;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){let t="";for(let C=0;C<
|
|
26
|
-
this.onload=void 0}A.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};A.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};A.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};A.prototype.get_buffer=function(a){a(this.buffer)};A.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};A.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function
|
|
27
|
-
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=this.onload=void 0}
|
|
28
|
-
for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};
|
|
29
|
-
0;e<d;e++){var f=this.block_cache.get(a+e);if(void 0===f)f=b.slice(256*e,256*(e+1)),this.block_cache.set(a+e,f);else{const g=b.subarray(256*e,256*(e+1));f.set(g)}this.block_cache_is_write.add(a+e)}c()};
|
|
30
|
-
d]of this.block_cache)isFinite(c),this.block_cache_is_write.has(c)&&b.push([c,d]);a[0]=b;return a};
|
|
15
|
+
C,Lb.push(String.fromCharCode(J));m.classList.add("cursor");m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===u&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===u||2===u)w.src=g.toDataURL("image/png");else{const t=[9,16],C=document.createElement("canvas");C.width=N*t[0];C.height=v*t[1];const J=C.getContext("2d");
|
|
16
|
+
J.imageSmoothingEnabled=!1;J.font=window.getComputedStyle(l).font;J.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<N;P++){const S=4*(Q*N+P),ka=H[S+0],ha=H[S+3];J.fillStyle=c(H[S+2]);J.fillRect(P*t[0],Q*t[1],t[0],t[1]);J.fillStyle=c(ha);J.fillText(sb[ka],P*t[0],Q*t[1])}"none"!==m.style.display&&n<v&&p<N&&(J.fillStyle=m.style.backgroundColor,J.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=C.toDataURL("image/png")}return w};
|
|
17
|
+
this.put_char=function(w,t,C,J,Q,P){t=4*(w*N+t);H[t+0]=C;H[t+1]=J;H[t+2]=Q;H[t+3]=P;y[w]=1};this.timer=function(){tb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Mb||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<v;w++)y[w]&&(this.text_update_row(w),y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();
|
|
18
|
+
if(266<w-bc){pb=!pb;rb&&(y[n]=1);var t=4*N;for(let ka=0,ha=0;ka<v;++ka)if(y[ka])ha+=t;else for(var C=0;C<N;++C,ha+=4)if(H[ha+1]&1){y[ka]=1;ha+=t-4*C;break}bc=w}w=Ua.canvas;t=T.canvas;C=4*N;const Q=N*oa,P=R;let S=0;for(let ka=0,ha=0,Z=0;ka<v;++ka,ha+=R){if(!y[ka]){Z+=C;continue}++S;T.clearRect(0,P,Q,R);let Fa,Ga,Ma,Na;for(let ua=0;ua<Q;ua+=oa,Z+=4){const cc=H[Z+0];var J=H[Z+1];const dc=H[Z+2],ec=H[Z+3],fc=J&2?Jb:Ib;J=(!(J&1)||pb)&&ac[(fc<<8)+cc];Ma!==dc&&(void 0!==Ma&&(L.fillStyle=c(Ma),L.fillRect(Na,
|
|
19
|
+
ha,ua-Na,R)),Ma=dc,Na=ua);Fa!==ec&&(void 0!==Fa&&(T.fillStyle=c(Fa),T.fillRect(Ga,0,ua-Ga,R)),Fa=ec,Ga=ua);J&&T.drawImage(w,cc*oa,fc*R,oa,R,ua,P,oa,R)}T.fillStyle=c(Fa);T.fillRect(Ga,0,Q-Ga,R);T.globalCompositeOperation="destination-in";T.drawImage(t,0,P,Q,R,0,0,Q,R);T.globalCompositeOperation="source-over";L.fillStyle=c(Ma);L.fillRect(Na,ha,Q-Na,R);L.drawImage(t,0,0,Q,R,0,ha,Q,R)}S&&(pb&&rb&&y[n]&&(L.fillStyle=c(H[4*(n*N+p)+3]),L.fillRect(p*oa,n*R+qb,oa,Kb-qb+1)),y.fill(0));S&&h.drawImage(L.canvas,
|
|
20
|
+
0,0)}};this.destroy=function(){tb&&(cancelAnimationFrame(tb),tb=0)};this.pause=function(){Mb=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Mb=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){u=w?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,C,J,Q,P){const S=C?16:t?9:8;if(R!==w||oa!==S||Gb!==t||Fb!==C||Hb!==J||P)P=oa!==S||R!==
|
|
21
|
+
w,R=w,oa=S,Gb=t,Fb=C,Hb=J,2===u&&(d(Q),y.fill(1),P&&this.set_size_graphical_text())};this.set_font_page=function(w,t){if(Ib!==w||Jb!==t)Ib=w,Jb=t,y.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ua){var w=oa*N,t=R*v,C=2*R;L&&L.canvas.width===w&&L.canvas.height===t&&T.canvas.height===C||(L?(L.canvas.width=w,L.canvas.height=t,T.canvas.width=w,T.canvas.height=C):(L=(new OffscreenCanvas(w,t)).getContext("2d",{alpha:!1}),
|
|
22
|
+
T=(new OffscreenCanvas(w,C)).getContext("2d")),this.set_size_graphical(w,t,w,t),y.fill(1))}};this.set_size_text=function(w,t){if(w!==N||t!==v)if(y=new Int8Array(t),H=new Int32Array(w*t*4),N=w,v=t,0===u){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(w=0;w<t;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;g.height=
|
|
23
|
+
t;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_charmap=function(w){sb=w||Lb};this.set_scale=function(w,t){q=w;r=t;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,t,C){if(w!==qb||t!==Kb||C!==rb)0===u?C?(m.style.display="inline",m.style.height=t-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===u&&n<v&&(y[n]=1),qb=w,Kb=t,rb=C};this.update_cursor=function(w,
|
|
24
|
+
t){if(w!==n||t!==p)w<v&&(y[w]=1),n<v&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*N,C;var J=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<N;){var S=document.createElement("span");var ka=H[t+1]&1;var ha=H[t+2];var Z=H[t+3];ka&&S.classList.add("blink");S.style.backgroundColor=c(ha);S.style.color=c(Z);for(C="";P<N&&(H[t+1]&1)===ka&&H[t+2]===ha&&H[t+3]===Z;)if(C+=sb[H[t+0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=S.style.color;Q.appendChild(m);
|
|
25
|
+
break}S.textContent=C;Q.appendChild(S)}J.parentNode.replaceChild(Q,J)};this.update_buffer=function(w){for(const t of w)h.putImageData(t.image_data,t.screen_x-t.buffer_x,t.screen_y-t.buffer_y,t.buffer_x,t.buffer_y,t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<v;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){let t="";for(let C=0;C<N;C++)t+=sb[H[4*(w*N+C)]];return t};this.init()}function A(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=
|
|
26
|
+
this.onload=void 0}A.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};A.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};A.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};A.prototype.get_buffer=function(a){a(this.buffer)};A.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};A.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function ta(a,
|
|
27
|
+
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=this.onload=void 0}ta.prototype.load=async function(){void 0===this.byteLength&&(this.byteLength=await pa(this.filename));this.onload&&this.onload(Object.create(null))};ta.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);
|
|
28
|
+
for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};ta.prototype.get=function(a,b,c){var d=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);na(this.filename,{done:function(g){g=new Uint8Array(g);this.handle_read(e,f,g);e===a&&f===b?c(g):c(g.subarray(a-e,a-e+b))}.bind(this),range:{start:e,length:f}})}};ta.prototype.set=function(a,b,c){a/=256;for(var d=b.length/256,e=
|
|
29
|
+
0;e<d;e++){var f=this.block_cache.get(a+e);if(void 0===f)f=b.slice(256*e,256*(e+1)),this.block_cache.set(a+e,f);else{const g=b.subarray(256*e,256*(e+1));f.set(g)}this.block_cache_is_write.add(a+e)}c()};ta.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)))}};ta.prototype.get_buffer=function(a){a()};ta.prototype.get_state=function(){const a=[],b=[];for(const [c,
|
|
30
|
+
d]of this.block_cache)isFinite(c),this.block_cache_is_write.has(c)&&b.push([c,d]);a[0]=b;return a};ta.prototype.set_state=function(a){a=a[0];this.block_cache.clear();this.block_cache_is_write.clear();for(const [b,c]of a)isFinite(b),this.block_cache.set(b,c),this.block_cache_is_write.add(b)};function va(a,b,c,d,e){const f=a.match(/\.[^\.]+(\.zst)?$/);this.extension=f?f[0]:"";this.basename=a.substring(0,a.length-this.extension.length);this.is_zstd=this.extension.endsWith(".zst");this.basename.endsWith("/")||
|
|
31
31
|
(this.basename+="-");this.block_cache=new Map;this.block_cache_is_write=new Set;this.byteLength=b;this.fixed_chunk_size=c;this.partfile_alt_format=!!d;this.zstd_decompress=e;this.cache_reads=!!c;this.onprogress=this.onload=void 0}va.prototype.load=function(){this.onload&&this.onload(Object.create(null))};va.prototype.get=function(a,b,c){var d=this.get_from_cache(a,b);if(d)c(d);else if(this.fixed_chunk_size){const f=Math.floor(a/this.fixed_chunk_size),g=a-f*this.fixed_chunk_size,h=Math.ceil((g+b)/
|
|
32
32
|
this.fixed_chunk_size),l=new Uint8Array(h*this.fixed_chunk_size);let m=0;for(let n=0;n<h;n++){var e=(f+n)*this.fixed_chunk_size;d=this.partfile_alt_format?this.basename+(f+n+"").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))?(l.set(e,n*this.fixed_chunk_size),m++,m===h&&c(l.subarray(g,g+b))):na(d,{done:async function(p){p=new Uint8Array(p);this.is_zstd&&(p=await this.zstd_decompress(this.fixed_chunk_size,
|
|
33
|
-
p),p=new Uint8Array(p));l.set(p,n*this.fixed_chunk_size);this.handle_read((f+n)*this.fixed_chunk_size,this.fixed_chunk_size|0,p);m++;m===h&&c(l.subarray(g,g+b))}.bind(this)})}}else na(this.basename+a+"-"+(a+b)+this.extension,{done:function(f){f=new Uint8Array(f);this.handle_read(a,b,f);c(f)}.bind(this)})};va.prototype.get_from_cache=
|
|
34
|
-
|
|
33
|
+
p),p=new Uint8Array(p));l.set(p,n*this.fixed_chunk_size);this.handle_read((f+n)*this.fixed_chunk_size,this.fixed_chunk_size|0,p);m++;m===h&&c(l.subarray(g,g+b))}.bind(this)})}}else na(this.basename+a+"-"+(a+b)+this.extension,{done:function(f){f=new Uint8Array(f);this.handle_read(a,b,f);c(f)}.bind(this)})};va.prototype.get_from_cache=ta.prototype.get_from_cache;va.prototype.set=ta.prototype.set;va.prototype.handle_read=ta.prototype.handle_read;va.prototype.get_state=ta.prototype.get_state;va.prototype.set_state=
|
|
34
|
+
ta.prototype.set_state;function wa(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}wa.prototype.load=function(){this.load_next(0)};wa.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);this.load_next(a+4194304)}.bind(this);if(this.onprogress)this.onprogress({loaded:a,
|
|
35
35
|
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})};wa.prototype.get=A.prototype.get;wa.prototype.set=A.prototype.set;wa.prototype.get_buffer=A.prototype.get_buffer;wa.prototype.get_state=A.prototype.get_state;wa.prototype.set_state=A.prototype.set_state;function xa(a){this.file=a;this.byteLength=a.size;this.block_cache=new Map;this.block_cache_is_write=
|
|
36
|
-
new Set;this.onprogress=this.onload=void 0}xa.prototype.load=function(){this.onload&&this.onload(Object.create(null))};xa.prototype.get=function(a,b,c){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)))};xa.prototype.get_from_cache=
|
|
37
|
-
|
|
38
|
-
if("undefined"!==typeof File&&a.buffer instanceof File)return b=a.async,void 0===b&&(b=268435456<=a.buffer.size),b?new xa(a.buffer):new wa(a.buffer);if(a.url)return a.use_parts?new va(a.url,a.size,a.fixed_chunk_size,!1,b):new
|
|
36
|
+
new Set;this.onprogress=this.onload=void 0}xa.prototype.load=function(){this.onload&&this.onload(Object.create(null))};xa.prototype.get=function(a,b,c){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)))};xa.prototype.get_from_cache=ta.prototype.get_from_cache;xa.prototype.set=ta.prototype.set;xa.prototype.handle_read=ta.prototype.handle_read;xa.prototype.get_state=
|
|
37
|
+
ta.prototype.get_state;xa.prototype.set_state=ta.prototype.set_state;xa.prototype.get_buffer=function(a){a()};xa.prototype.get_as_file=function(a){for(var b=[],c=Array.from(this.block_cache.keys()).sort(function(h,l){return h-l}),d=0,e=0;e<c.length;e++){var f=c[e],g=this.block_cache.get(f);f*=256;f!==d&&(b.push(this.file.slice(d,f)),d=f);b.push(g);d+=g.length}d!==this.file.size&&b.push(this.file.slice(d));return new File(b,a)};function ya(a,b){if(a.buffer instanceof ArrayBuffer)return new A(a.buffer);
|
|
38
|
+
if("undefined"!==typeof File&&a.buffer instanceof File)return b=a.async,void 0===b&&(b=268435456<=a.buffer.size),b?new xa(a.buffer):new wa(a.buffer);if(a.url)return a.use_parts?new va(a.url,a.size,a.fixed_chunk_size,!1,b):new ta(a.url,a.size,a.fixed_chunk_size)}function B(a){this.cpu=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=
|
|
39
39
|
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,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));
|
|
40
40
|
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,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,
|
|
41
41
|
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,this.port_addr_write.bind(this,7));a.register_write(194,this,this.port_count_write.bind(this,4));a.register_write(198,this,this.port_count_write.bind(this,5));a.register_write(202,this,this.port_count_write.bind(this,6));a.register_write(206,
|
|
@@ -62,7 +62,7 @@ a);(0>b||256<=b)&&z(a);return b};za.prototype.port_read16=function(a){var b=this
|
|
|
62
62
|
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",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",
|
|
63
63
|
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",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"};za.prototype.get_port_description=
|
|
64
64
|
function(a){return Aa[a]?" ("+Aa[a]+")":""};var Ba={};function Ca(){this.listeners={};this.pair=void 0}Ca.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})};Ca.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ca.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,
|
|
65
|
-
b)}};Ca.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};Ba.create=function(){var a=new Ca,b=new Ca;a.pair=b;b.pair=a;return[a,b]};var Da=new Uint8Array(256),
|
|
65
|
+
b)}};Ca.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};Ba.create=function(){var a=new Ca,b=new Ca;a.pair=b;b.pair=a;return[a,b]};var Da=new Uint8Array(256),Ea=[],Ha=[],Ia=[],Ja=new Uint8Array(256),Ka=[];function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;
|
|
66
66
|
this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new la(65536),new la(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=
|
|
67
67
|
new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new A(this.dma_buffer);this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new ja(64);this.fm_current_address1=this.fm_current_address0=this.mpu_read_buffer_lastvalue=0;this.fm_waveform_select_enable=!1;this.irq=
|
|
68
68
|
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);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,
|
|
@@ -79,19 +79,19 @@ function(){return 255};D.prototype.port2xA_read=function(){this.read_buffer.leng
|
|
|
79
79
|
!this.dsp_highspeed)<<7|127};D.prototype.port2xF_read=function(){this.lower_irq(2);return 0};D.prototype.port2x0_write=function(a){z(a);this.fm_current_address0=0};D.prototype.port2x1_write=function(a){z(a);var b=Ka[this.fm_current_address0];b||(b=this.fm_default_write);b.call(this,a,0,this.fm_current_address0)};D.prototype.port2x2_write=function(a){z(a);this.fm_current_address1=0};D.prototype.port2x3_write=function(a){z(a);var b=Ka[this.fm_current_address1];b||(b=this.fm_default_write);b.call(this,
|
|
80
80
|
a,1,this.fm_current_address1)};D.prototype.port2x4_write=function(a){z(a);this.mixer_current_address=a};D.prototype.port2x5_write=function(a){z(a);this.mixer_write(this.mixer_current_address,a)};D.prototype.port2x6_write=function(a){z(a);this.dsp_highspeed?this.dsp_highspeed=!1:a&&this.dsp_reset();this.read_buffer.clear();this.read_buffer.push(170)};D.prototype.port2x7_write=function(){};D.prototype.port2x8_write=function(){};D.prototype.port2x9_write=function(){};D.prototype.port2xA_write=function(){};
|
|
81
81
|
D.prototype.port2xB_write=function(){};D.prototype.port2xC_write=function(a){0===this.command?(z(a),this.command=a,this.write_buffer.clear(),this.command_size=Da[a]):(z(a),this.write_buffer.push(a));this.write_buffer.length>=this.command_size&&this.command_do()};D.prototype.port2xD_write=function(){};D.prototype.port2xE_write=function(){};D.prototype.port2xF_write=function(){};D.prototype.port3x0_read=function(){this.mpu_read_buffer.length&&(this.mpu_read_buffer_lastvalue=this.mpu_read_buffer.shift());
|
|
82
|
-
z(this.mpu_read_buffer_lastvalue);return this.mpu_read_buffer_lastvalue};D.prototype.port3x0_write=function(a){z(a)};D.prototype.port3x1_read=function(){return 0|128*!this.mpu_read_buffer.length};D.prototype.port3x1_write=function(a){z(a);255===a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))};D.prototype.command_do=function(){var a=
|
|
83
|
-
function(){z(this.command)};function E(a,b,c){c||(c=D.prototype.dsp_default_handler);for(var d=0;d<a.length;d++)Da[a[d]]=b,
|
|
82
|
+
z(this.mpu_read_buffer_lastvalue);return this.mpu_read_buffer_lastvalue};D.prototype.port3x0_write=function(a){z(a)};D.prototype.port3x1_read=function(){return 0|128*!this.mpu_read_buffer.length};D.prototype.port3x1_write=function(a){z(a);255===a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))};D.prototype.command_do=function(){var a=Ea[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command_size=this.command=0;this.write_buffer.clear()};D.prototype.dsp_default_handler=
|
|
83
|
+
function(){z(this.command)};function E(a,b,c){c||(c=D.prototype.dsp_default_handler);for(var d=0;d<a.length;d++)Da[a[d]]=b,Ea[a[d]]=c}function La(a){for(var b=[],c=0;16>c;c++)b.push(a+c);return b}E([14],2,function(){this.asp_registers[this.write_buffer.shift()]=this.write_buffer.shift()});E([15],1,function(){this.read_buffer.clear();this.read_buffer.push(this.asp_registers[this.write_buffer.shift()])});E([16],1,function(){var a=this.write_buffer.shift();a=Oa(a/127.5+-1,-1,1);this.dac_buffers[0].push(a);
|
|
84
84
|
this.dac_buffers[1].push(a);this.bus.send("dac-enable")});E([20,21],2,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=this.dma_autoinit=!1;this.dma_transfer_size_set();this.dma_transfer_start()});E([22],2);E([23],2);E([28],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=!1;this.dma_transfer_start()});E([31],0);E([32],0,function(){this.read_buffer.clear();
|
|
85
85
|
this.read_buffer.push(127)});E([36],2);E([44],0);E([48],0);E([49],0);E([52],0);E([53],0);E([54],0);E([55],0);E([56],0);E([64],1,function(){this.sampling_rate_change(1E6/(256-this.write_buffer.shift())/this.get_channel_count())});E([65,66],2,function(){this.sampling_rate_change(this.write_buffer.shift()<<8|this.write_buffer.shift())});E([72],2,function(){this.dma_transfer_size_set()});E([116],2);E([117],2);E([118],2);E([119],2);E([125],0);E([127],0);E([128],2);E([144],0,function(){this.dma_irq=1;this.dma_channel=
|
|
86
|
-
this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_signed=!1;this.dsp_highspeed=!0;this.dsp_16bit=!1;this.dma_transfer_start()});E([145],0);E([152],0);E([153],0);E([160],0);E([168],0);E(
|
|
87
|
-
E(
|
|
86
|
+
this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_signed=!1;this.dsp_highspeed=!0;this.dsp_16bit=!1;this.dma_transfer_start()});E([145],0);E([152],0);E([153],0);E([160],0);E([168],0);E(La(176),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=2;this.dma_channel=this.dma_channel_16bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!0;this.dma_transfer_size_set();this.dma_transfer_start()}});
|
|
87
|
+
E(La(192),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!1;this.dma_transfer_size_set();this.dma_transfer_start()}});E([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});E([209],0,function(){this.dummy_speaker_enabled=!0});E([211],0,function(){this.dummy_speaker_enabled=!1});E([212],
|
|
88
88
|
0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});E([213],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});E([214],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});E([216],0,function(){this.read_buffer.clear();this.read_buffer.push(255*this.dummy_speaker_enabled)});E([217,218],0,function(){this.dma_autoinit=!1});E([224],1,function(){this.read_buffer.clear();this.read_buffer.push(~this.write_buffer.shift())});E([225],0,function(){this.read_buffer.clear();this.read_buffer.push(4);
|
|
89
89
|
this.read_buffer.push(5)});E([226],1);E([227],0,function(){this.read_buffer.clear();for(var a=0;44>a;a++)this.read_buffer.push("COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.".charCodeAt(a));this.read_buffer.push(0)});E([228],1,function(){this.test_register=this.write_buffer.shift()});E([232],0,function(){this.read_buffer.clear();this.read_buffer.push(this.test_register)});E([242,243],0,function(){this.raise_irq()});var Pa=new Uint8Array(256);Pa[14]=255;Pa[15]=7;Pa[55]=56;E([249],1,function(){var a=
|
|
90
90
|
this.write_buffer.shift();this.read_buffer.clear();this.read_buffer.push(Pa[a])});D.prototype.mixer_read=function(a){var b=Ha[a];b?b=b.call(this):(b=this.mixer_registers[a],z(a),z(b));return b};D.prototype.mixer_write=function(a,b){var c=Ia[a];c?c.call(this,b):(z(a),z(b))};D.prototype.mixer_default_read=function(){z(this.mixer_current_address);return this.mixer_registers[this.mixer_current_address]};D.prototype.mixer_default_write=function(a){z(this.mixer_current_address);z(a);this.mixer_registers[this.mixer_current_address]=
|
|
91
91
|
a};D.prototype.mixer_reset=function(){this.mixer_registers[4]=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]=
|
|
92
92
|
0;this.mixer_registers[60]=31;this.mixer_registers[61]=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++)Ja[a]||this.mixer_write(a,this.mixer_registers[a])};
|
|
93
|
-
function Qa(a,b){b||(b=D.prototype.mixer_default_read);Ha[a]=b}function Ra(a,b){b||(b=D.prototype.mixer_default_write);Ia[a]=b}function Sa(a,b,c){Ja[a]=1;Ha[a]=function(){return this.mixer_registers[b]&240|this.mixer_registers[c]>>>4};Ia[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
|
|
94
|
-
[b,c,(d>>>2)-62])}}Qa(0,function(){this.mixer_reset();return 0});Ra(0);Sa(4,50,51);Sa(34,48,49);Sa(38,52,53);Sa(40,54,55);Sa(46,56,57);
|
|
93
|
+
function Qa(a,b){b||(b=D.prototype.mixer_default_read);Ha[a]=b}function Ra(a,b){b||(b=D.prototype.mixer_default_write);Ia[a]=b}function Sa(a,b,c){Ja[a]=1;Ha[a]=function(){return this.mixer_registers[b]&240|this.mixer_registers[c]>>>4};Ia[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 Ta(a,b,c){Ha[a]=D.prototype.mixer_default_read;Ia[a]=function(d){this.mixer_registers[a]=d;this.bus.send("mixer-volume",
|
|
94
|
+
[b,c,(d>>>2)-62])}}Qa(0,function(){this.mixer_reset();return 0});Ra(0);Sa(4,50,51);Sa(34,48,49);Sa(38,52,53);Sa(40,54,55);Sa(46,56,57);Ta(48,0,0);Ta(49,0,1);Ta(50,2,0);Ta(51,2,1);Qa(59);Ra(59,function(a){this.mixer_registers[59]=a;this.bus.send("mixer-volume",[1,2,6*(a>>>6)-18])});Qa(65);Ra(65,function(a){this.mixer_registers[65]=a;this.bus.send("mixer-gain-left",6*(a>>>6))});Qa(66);Ra(66,function(a){this.mixer_registers[66]=a;this.bus.send("mixer-gain-right",6*(a>>>6))});Qa(68);Ra(68,function(a){this.mixer_registers[68]=
|
|
95
95
|
a;a>>>=3;this.bus.send("mixer-treble-left",a-(16>a?14:16))});Qa(69);Ra(69,function(a){this.mixer_registers[69]=a;a>>>=3;this.bus.send("mixer-treble-right",a-(16>a?14:16))});Qa(70);Ra(70,function(a){this.mixer_registers[70]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});Qa(71);Ra(71,function(a){this.mixer_registers[71]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});Qa(128,function(){switch(this.irq){case 2:return 1;case 5:return 2;case 7:return 4;case 10:return 8;default:return 0}});
|
|
96
96
|
Ra(128,function(a){a&1&&(this.irq=2);a&2&&(this.irq=5);a&4&&(this.irq=7);a&8&&(this.irq=10)});Qa(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});Ra(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=
|
|
97
97
|
7)});Qa(130,function(){for(var a=32,b=0;16>b;b++)a|=b*this.irq_triggered[b];return a});D.prototype.fm_default_write=function(a,b,c){z(c);z(a)};function Va(a,b){b||(b=D.prototype.fm_default_write);for(var c=0;c<a.length;c++)Ka[a[c]]=b}function Wa(a,b){for(var c=[];a<=b;a++)c.push(a);return c}const Xa=new Uint8Array(32);Xa[0]=0;Xa[1]=1;Xa[2]=2;Xa[3]=3;Xa[4]=4;Xa[5]=5;Xa[8]=6;Xa[9]=7;Xa[10]=8;Xa[11]=9;Xa[12]=10;Xa[13]=11;Xa[16]=12;Xa[17]=13;Xa[18]=14;Xa[19]=15;Xa[20]=16;Xa[21]=17;Va([1],function(a,b){this.fm_waveform_select_enable[b]=
|
|
@@ -152,41 +152,41 @@ a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bin
|
|
|
152
152
|
void 0;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)}lb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};lb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};lb.prototype.handle_open=
|
|
153
153
|
function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};lb.prototype.handle_error=function(){};lb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};lb.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);
|
|
154
154
|
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)}}};lb.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())};lb.prototype.change_proxy=
|
|
155
|
-
function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const mb=(new Date("1970-01-01T00:00:00Z")).getTime(),nb=(new Date("1900-01-01T00:00:00Z")).getTime(),
|
|
155
|
+
function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const mb=(new Date("1970-01-01T00:00:00Z")).getTime(),nb=(new Date("1900-01-01T00:00:00Z")).getTime(),ob=mb-nb,ub=Math.pow(2,32),vb=[118,56,54];function wb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function xb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class yb{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=
|
|
156
156
|
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(;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,
|
|
157
157
|
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 zb(){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,
|
|
158
|
-
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 Ab(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Bb(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
|
|
158
|
+
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 Ab(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Bb(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 Cb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Ab(0,b.eth.dest,e,a);Ab(6,b.eth.src,e,a);
|
|
159
159
|
e.setUint16(12,b.eth.ethertype);e=14;if(b.arp){var f=a.eth_payload_view;f.setUint16(0,b.arp.htype);f.setUint16(2,b.arp.ptype);f.setUint8(4,b.arp.sha.length);f.setUint8(5,b.arp.spa.length);f.setUint16(6,b.arp.oper);Ab(8,b.arp.sha,f,a);Ab(14,b.arp.spa,f,a);Ab(18,b.arp.tha,f,a);Ab(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var g=20;if(b.icmp){var h=a.ipv4_payload_view;h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+Ab(4,b.icmp.data,h,a);h.setUint16(2,Bb(l,
|
|
160
160
|
0,h,a));g+=l}else if(b.udp){h=a.ipv4_payload_view;var m=8;if(b.dhcp){l=m;var n=a.udp_payload_view;n.setUint8(0,b.dhcp.op);n.setUint8(1,b.dhcp.htype);n.setUint8(2,b.dhcp.hlen);n.setUint8(3,b.dhcp.hops);n.setUint32(4,b.dhcp.xid);n.setUint16(8,b.dhcp.secs);n.setUint16(10,b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,b.dhcp.giaddr);Ab(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=Ab(m,p,n,
|
|
161
161
|
a);l+=m}else if(b.dns){p=m;m=a.udp_payload_view;m.setUint16(0,b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let x=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const y=a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(x+1))).written;m.setUint8(x,y);x+=1+y}m.setUint16(x,r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=
|
|
162
162
|
a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=Ab(x,n.data,m,a)}l=p+x}else b.ntp?(l=m,n=a.udp_payload_view,n.setUint8(0,b.ntp.flags),n.setUint8(1,b.ntp.stratum),n.setUint8(2,b.ntp.poll),n.setUint8(3,b.ntp.precision),n.setUint32(4,b.ntp.root_delay),n.setUint32(8,b.ntp.root_disp),n.setUint32(12,b.ntp.ref_id),n.setUint32(16,b.ntp.ref_ts_i),
|
|
163
163
|
n.setUint32(20,b.ntp.ref_ts_f),n.setUint32(24,b.ntp.ori_ts_i),n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+Ab(0,b.udp.data,a.udp_payload_view,a);m=l;h.setUint16(0,b.udp.sport);h.setUint16(2,b.udp.dport);h.setUint16(4,m);h.setUint16(6,0);h.setUint16(6,Bb(m,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|
|
|
164
164
|
b.ipv4.dest[3])+17+m,h,a));g+=m}else b.tcp&&(h=a.ipv4_payload_view,l=0,n=b.tcp,n.fin&&(l|=1),n.syn&&(l|=2),n.rst&&(l|=4),n.psh&&(l|=8),n.ack&&(l|=16),n.urg&&(l|=32),n.ece&&(l|=64),n.cwr&&(l|=128),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,80),h.setUint8(13,l),h.setUint16(14,n.winsize),h.setUint16(16,0),h.setUint16(18,n.urgent||0),l=20,b.tcp_data&&(l+=Ab(20,b.tcp_data,h,a)),h.setUint16(16,Bb(l,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<
|
|
165
|
-
8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+l,h,a)),g+=l);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,g);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);Ab(12,b.ipv4.src,f,a);Ab(16,b.ipv4.dest,f,a);f.setUint16(10,Bb(20,0,f,a));e+=g}return d.call(c,0,e)}function
|
|
166
|
-
"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(
|
|
165
|
+
8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+l,h,a)),g+=l);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,g);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);Ab(12,b.ipv4.src,f,a);Ab(16,b.ipv4.dest,f,a);f.setUint16(10,Bb(20,0,f,a));e+=g}return d.call(c,0,e)}function Db(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type",
|
|
166
|
+
"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(Cb(b.eth_encoder_buf,c))});return!0}function Nb(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,
|
|
167
167
|
ciaddr:0,yiaddr:xb(b.vm_ip),siaddr:xb(b.router_ip),giaddr:xb(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))),
|
|
168
|
-
d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(vb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(
|
|
168
|
+
d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(vb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Cb(b.eth_encoder_buf,c))}function Ob(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:wb(a.subarray(0,6)),src:a.subarray(6,12),src_s:wb(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,
|
|
169
169
|
a.byteLength),g=a[0]>>4&15;e=a[0]&15;var h=f.getUint8(1),l=f.getUint16(2);let m=f.getUint8(8);d=f.getUint8(9);f=f.getUint16(10);g={version:g,ihl:e,tos:h,len:l,ttl:m,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};c.ipv4=g;e=a.subarray(4*e,l);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===d)d=new DataView(e.buffer,e.byteOffset,e.byteLength),a={sport:d.getUint16(0),
|
|
170
170
|
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),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),
|
|
171
171
|
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),options:[]};e=e.subarray(240);for(l=0;l<e.length;++l)g=l,
|
|
172
172
|
0!==e[l]&&(++l,h=e[l],l+=h,d.options.push(e.subarray(g,g+h+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Pb(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),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),
|
|
173
173
|
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&&z(d);if(c.ipv4)if(c.tcp){if(a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`,!c.tcp.syn||!b.on_tcp_connection(c,a))if(b.tcp_conn[a])b.tcp_conn[a].process(c);
|
|
174
|
-
else{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(
|
|
175
|
-
d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(
|
|
176
|
-
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(
|
|
177
|
-
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(
|
|
178
|
-
b.receive(
|
|
174
|
+
else{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(Cb(b.eth_encoder_buf,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};
|
|
175
|
+
d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Cb(b.eth_encoder_buf,a))}else Db(c,b);else c.dhcp?Nb(c,b):c.ntp?(a=Date.now()+ob,d=a%1E3/1E3*ub,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({},
|
|
176
|
+
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(Cb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},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(Cb(b.eth_encoder_buf,a)));else c.icmp&&8===
|
|
177
|
+
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(Cb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=xb(c.arp.tpa)&4294967040,d=xb(b.router_ip)&4294967040,!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},
|
|
178
|
+
b.receive(Cb(b.eth_encoder_buf,a))))}function Pb(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),
|
|
179
179
|
type:d.getInt16(h),class:d.getUint16(h+2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}function Qb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Rb;c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=
|
|
180
180
|
b.vm_mac;c.dport=a;c.pdest=b.vm_ip;c.net=b;b.tcp_conn[g]=c;c.connect();return c}function Sb(a,b){return new Promise(c=>{let d=Qb(a,b);d.state="syn-probe";d.on("probe",c)})}function Rb(){this.state="closed";this.net=null;this.send_buffer=new yb(2048,0);this.send_chunk_buf=new Uint8Array(1460);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Rb.prototype.on=function(a,b){this.events_handlers[a]=b};Rb.prototype.emit=function(a,...b){this.events_handlers[a]&&
|
|
181
181
|
this.events_handlers[a].apply(this,b)};Rb.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};Rb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Rb.prototype.connect=
|
|
182
|
-
function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;this.state="syn-sent";let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(
|
|
183
|
-
a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0};this.state="established";this.net.receive(
|
|
184
|
-
a.tcp.ack?(this.ack=a.tcp.seq+1,this.start_seq=a.tcp.seq,this.last_received_ackn=a.tcp.ackn,a=this.ipv4_reply(),this.net.receive(
|
|
185
|
-
else if("closing"===this.state||"last-ack"===this.state){this.release();return}if(void 0===this.last_received_ackn)this.last_received_ackn=a.tcp.ackn;else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(
|
|
186
|
-
b){a=this.packet_reply(a,{rst:!0});this.net.receive(
|
|
187
|
-
a.tcp.seq?(a=this.packet_reply(a,{ack:!0}),this.net.receive(
|
|
188
|
-
!0;if("established"===this.state||"syn-received"===this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(
|
|
189
|
-
(this.state="closed",delete this.net.tcp_conn[this.tuple])};Rb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(
|
|
182
|
+
function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;this.state="syn-sent";let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Cb(this.net.eth_encoder_buf,a))};Rb.prototype.accept=function(a){this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.hsrc=this.net.router_mac;this.psrc=a.ipv4.dest;this.sport=a.tcp.dport;this.hdest=a.eth.src;this.dport=a.tcp.sport;this.pdest=a.ipv4.src;this.winsize=
|
|
183
|
+
a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0};this.state="established";this.net.receive(Cb(this.net.eth_encoder_buf,b))};Rb.prototype.process=function(a){if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Cb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===this.state)this.emit("probe",!1);else this.on_close();this.release()}else if(a.tcp.syn)"syn-sent"===this.state&&
|
|
184
|
+
a.tcp.ack?(this.ack=a.tcp.seq+1,this.start_seq=a.tcp.seq,this.last_received_ackn=a.tcp.ackn,a=this.ipv4_reply(),this.net.receive(Cb(this.net.eth_encoder_buf,a)),this.state="established",this.emit("connect")):"syn-probe"===this.state&&a.tcp.ack&&(this.emit("probe",!0),a=this.packet_reply(a,{rst:!0}),this.net.receive(Cb(this.net.eth_encoder_buf,a)),this.release());else{if(a.tcp.ack)if("syn-received"===this.state)this.state="established";else if("fin-wait-1"===this.state)a.tcp.fin||(this.state="fin-wait-2");
|
|
185
|
+
else if("closing"===this.state||"last-ack"===this.state){this.release();return}if(void 0===this.last_received_ackn)this.last_received_ackn=a.tcp.ackn;else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(Cb(this.net.eth_encoder_buf,a));return}}else if(0>
|
|
186
|
+
b){a=this.packet_reply(a,{rst:!0});this.net.receive(Cb(this.net.eth_encoder_buf,a));this.on_close();this.release();return}}a.tcp.fin?(++this.ack,b=this.packet_reply(a,{}),"established"===this.state?(b.tcp.ack=!0,this.state="close-wait",this.on_shutdown()):"fin-wait-1"===this.state?(a.tcp.ack?this.release():this.state="closing",b.tcp.ack=!0):"fin-wait-2"===this.state?(this.release(),b.tcp.ack=!0):(this.release(),this.on_close(),b.tcp.rst=!0),this.net.receive(Cb(this.net.eth_encoder_buf,b))):this.ack!==
|
|
187
|
+
a.tcp.seq?(a=this.packet_reply(a,{ack:!0}),this.net.receive(Cb(this.net.eth_encoder_buf,a))):a.tcp.ack&&0<a.tcp_data.length&&(this.ack+=a.tcp_data.length,b=this.ipv4_reply(),this.net.receive(Cb(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Rb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Rb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Rb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=
|
|
188
|
+
!0;if("established"===this.state||"syn-received"===this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Cb(this.net.eth_encoder_buf,a)))}this.pump()};Rb.prototype.on_shutdown=function(){this.emit("shutdown")};Rb.prototype.on_close=function(){this.emit("close")};Rb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&
|
|
189
|
+
(this.state="closed",delete this.net.tcp_conn[this.tuple])};Rb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(Cb(this.net.eth_encoder_buf,c));this.pending=!0}};function Tb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||
|
|
190
190
|
"192.168.86.1").split(".").map(function(c){return parseInt(c,10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";this.doh_server=b.doh_server;this.tcp_conn={};this.eth_encoder_buf=zb();this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=new Uint8Array(c.split(":").map(function(d){return parseInt(d,
|
|
191
191
|
16)}))},this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this)}Tb.prototype.destroy=function(){};Tb.prototype.on_tcp_connection=function(a,b){if(80===a.tcp.dport){let c=new Rb;c.state="syn-received";c.net=this;c.on("data",Ub);c.tuple=b;c.accept(a);this.tcp_conn[b]=c;return!0}return!1};Tb.prototype.connect=function(a){return Qb(a,this)};Tb.prototype.tcp_probe=function(a){return Sb(a,this)};async function Ub(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&
|
|
192
192
|
-1!==this.read.indexOf("\r\n\r\n")){a=this.read.indexOf("\r\n\r\n");var b=this.read.substring(0,a).split(/\r\n/);a=this.read.substring(a+4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let h=1;h<b.length;++h){const l=this.net.parse_http_header(b[h]);if(!l){console.warn('The request contains an invalid header: "%s"',
|
|
@@ -204,20 +204,20 @@ c.setUint8(0,2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE"
|
|
|
204
204
|
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};Vb.prototype.send=function(a){Ob(a,this)};Vb.prototype.receive=function(a){this.bus.send("net"+
|
|
205
205
|
this.id+"-receive",new Uint8Array(a))};const Wb="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function Xb(a){function b(v){return v.shiftKey&&v.ctrlKey&&(73===v.keyCode||74===v.keyCode||75===v.keyCode)||!x.emu_enabled?!1:v.target?v.target.classList.contains("phone_keyboard")||"INPUT"!==v.target.nodeName&&"TEXTAREA"!==v.target.nodeName:!0}function c(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!1)}function d(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!0)}
|
|
206
206
|
function e(){for(var v=Object.keys(n),L,T=0;T<v.length;T++)L=+v[T],n[L]&&l(L,!1);n={}}function f(v){if(x.bus&&b(v))switch(v.inputType){case "insertText":for(var L=0;L<v.data.length;L++)x.simulate_char(v.data[L]);break;case "insertLineBreak":x.simulate_press(13);break;case "deleteContentBackward":x.simulate_press(8)}}function g(v,L){if(x.bus&&b(v)&&""!==v.code&&"Process"!==v.key&&"Unidentified"!==v.key&&229!==v.keyCode){v.preventDefault&&v.preventDefault();if(Wb&&(p&&(clearTimeout(r),v.getModifierState&&
|
|
207
|
-
v.getModifierState("AltGraph")&&q===L&&"ControlLeft"===p.code&&"AltRight"===v.code||h(p,q),p=null),"ControlLeft"===v.code))return p=v,q=L,r=setTimeout(()=>{h(p,q);p=null},10),!1;h(v,L);return!1}}function h(v,L){a:{if(void 0!==v.code){var T=
|
|
207
|
+
v.getModifierState("AltGraph")&&q===L&&"ControlLeft"===p.code&&"AltRight"===v.code||h(p,q),p=null),"ControlLeft"===v.code))return p=v,q=L,r=setTimeout(()=>{h(p,q);p=null},10),!1;h(v,L);return!1}}function h(v,L){a:{if(void 0!==v.code){var T=N[v.code];if(void 0!==T)break a}T=y[v.keyCode]}T?l(T,L,v.repeat):console.log("Missing char in map: keyCode="+(v.keyCode||-1).toString(16)+" code="+v.code)}function l(v,L,T){if(L)n[v]&&!T&&l(v,!1);else if(!n[v])return;(n[v]=L)||(v|=128);255<v?(m(v>>8),m(v&255)):
|
|
208
208
|
m(v)}function m(v){x.bus.send("keyboard-code",v)}var n={},p=null,q=!1,r=0,x=this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
209
209
|
0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),u={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,
|
|
210
|
-
114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},H={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var
|
|
210
|
+
114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},H={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var N={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,
|
|
211
211
|
Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,
|
|
212
212
|
ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==
|
|
213
213
|
typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1),window.removeEventListener("input",f,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1),window.addEventListener("input",f,!1))};this.init();this.simulate_press=function(v){v={keyCode:v};g(v,!0);g(v,!1)};this.simulate_char=function(v){var L=
|
|
214
|
-
v.charCodeAt(0);L in u?this.simulate_press(u[L]):L in H?(m(42),this.simulate_press(H[L]),m(170)):console.log("ascii -> keyCode not found: ",L,v)}}function
|
|
215
|
-
[!1,!1,!1]),n=q=p=!1}function f(u){if(y.bus&&c(u)&&y.is_running){var H=0,
|
|
214
|
+
v.charCodeAt(0);L in u?this.simulate_press(u[L]):L in H?(m(42),this.simulate_press(H[L]),m(170)):console.log("ascii -> keyCode not found: ",L,v)}}function Yb(a,b){function c(u){if(!y.enabled||!y.emu_enabled)return!1;var H=b||document.body,N;if(!(N=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===H){N=!0;break a}u=u.parentNode}N=!1}return N}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,x=u.clientY)}function e(){if(n||q||p)y.bus.send("mouse-click",
|
|
215
|
+
[!1,!1,!1]),n=q=p=!1}function f(u){if(y.bus&&c(u)&&y.is_running){var H=0,N=0,v=u.changedTouches;v?v.length&&(v=v[v.length-1],H=v.clientX-r,N=v.clientY-x,r=v.clientX,x=v.clientY,u.preventDefault()):"number"===typeof u.movementX?(H=u.movementX,N=u.movementY):"number"===typeof u.webkitMovementX?(H=u.webkitMovementX,N=u.webkitMovementY):"number"===typeof u.mozMovementX?(H=u.mozMovementX,N=u.mozMovementY):(H=u.clientX-r,N=u.clientY-x,r=u.clientX,x=u.clientY);y.bus.send("mouse-delta",[1*H,-(1*N)]);b&&y.bus.send("mouse-absolute",
|
|
216
216
|
[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(u){c(u)&&l(u,!0)}function h(u){c(u)&&l(u,!1)}function l(u,H){y.bus&&(1===u.which?n=H:2===u.which?q=H:3===u.which&&(p=H),y.bus.send("mouse-click",[n,q,p]),u.preventDefault())}function m(u){if(c(u)){var H=u.wheelDelta||-u.detail;0>H?H=-1:0<H&&(H=1);y.bus.send("mouse-wheel",[H,0]);u.preventDefault()}}var n=!1,p=!1,q=!1,r=0,x=0,y=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=
|
|
217
217
|
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),window.removeEventListener("mousedown",g,!1),window.removeEventListener("mouseup",h,!1),window.removeEventListener("wheel",
|
|
218
|
-
m,{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",g,!1),window.addEventListener("mouseup",h,!1),window.addEventListener("wheel",m,{passive:!1}))};this.init()}function
|
|
218
|
+
m,{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",g,!1),window.addEventListener("mouseup",h,!1),window.addEventListener("wheel",m,{passive:!1}))};this.init()}function Zb(){var a,b=0,c=0;this.put_char=function(d,e,f){a[d*b+e]=f};this.destroy=function(){};this.pause=
|
|
219
219
|
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=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};
|
|
220
|
-
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
|
|
220
|
+
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 $b(a,b){function c(h){g.bus&&g.enabled&&(g.send_char(h.which),h.preventDefault())}function d(h){var l=h.which;8===l?(g.send_char(127),h.preventDefault()):9===l&&(g.send_char(9),h.preventDefault())}function e(h){if(g.enabled){for(var l=h.clipboardData.getData("text/plain"),m=0;m<l.length;m++)g.send_char(l.charCodeAt(m));h.preventDefault()}}function f(h){h.target!==a&&a.blur()}
|
|
221
221
|
var g=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(h){h=String.fromCharCode(h);this.show_char(h)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",f,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",
|
|
222
222
|
d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",f,!1)};this.init();this.show_char=function(h){"\b"===h?(this.text=this.text.slice(0,-1),this.update()):"\r"!==h&&(this.text+=h,"\n"===h&&(this.text_new_line=!0),this.update())};this.update=function(){var h=Date.now(),l=h-this.last_update;16>l?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-l)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),
|
|
223
223
|
this.update_timer=void 0),this.last_update=h,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(h){g.bus&&g.bus.send("serial0-input",h)}}function gc(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off",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",
|
|
@@ -228,7 +228,7 @@ b)};jc.prototype.uncache=function(a){this.storage.uncache(a)};const kc=new TextD
|
|
|
228
228
|
lc.encode(e);f+=e.byteLength;l+=e.byteLength;c.set(e,d);d+=e.byteLength;c[h+0]=l&255;c[h+1]=l>>8&255;break;case "Q":G(["b","w","d"],[e.type,e.version,e.path],c,d),d+=13,f+=13}return f}function I(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>0;e.push(g);break;case "d":g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>0;d+=4;e.push(g);break;case "h":g=b[d++];e.push(g+(b[d++]<<8));break;case "b":e.push(b[d++]);break;
|
|
229
229
|
case "s":g=b[d++];g+=b[d++]<<8;var h=b.slice(d,d+g);d+=g;e.push(kc.decode(h));break;case "Q":c.offset=d,g=I(["b","w","d"],b,c),d=c.offset,e.push({type:g[0],version:g[1],path:g[2]})}c.offset=d;return e}const mc=new TextEncoder;function K(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)}K.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;
|
|
230
230
|
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)};K.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new nc(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)};K.prototype.AddEvent=
|
|
231
|
-
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})};K.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};K.prototype.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please
|
|
231
|
+
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})};K.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};K.prototype.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";
|
|
232
232
|
var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};K.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&z(e)};K.prototype.LoadDir=function(a,
|
|
233
233
|
b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};K.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};K.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);this.should_be_linked(d);e.direntries.has(c);e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(d.direntries.has(".."),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};K.prototype.unlink_from_dir=
|
|
234
234
|
function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);e.direntries.delete(b)&&(d.nlinks--,this.IsDirectory(c)&&(d.direntries.get(".."),d.direntries.delete(".."),e.nlinks--))};K.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length&&(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2)};function nc(a){this.direntries=new Map;
|
|
@@ -265,41 +265,42 @@ a.proc_id&&this.client_id===a.client_id||2===this.type||2===a.type||1!==this.typ
|
|
|
265
265
|
K.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();return null};K.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c<d.locks.length;c++){a=d.locks[c];if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;
|
|
266
266
|
if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){a.conflicts_with(b);continue}var e=b.start+b.length;const f=b.start-a.start,g=a.start+a.length-e;if(0<f&&0<g&&a.type===b.type)return 0;0<f&&(a.length=f);if(0>=f&&0<g)a.start=e,a.length=g;else if(0<g){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,g,a.proc_id,a.client_id))}else 0>=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=
|
|
267
267
|
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+=d.locks[e].length,d.locks.splice(e,1));break}}return 0};K.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)};K.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=
|
|
268
|
-
this.GetInode(a.id);return this.Read(a.id,0,b.size)};function
|
|
268
|
+
this.GetInode(a.id);return this.Read(a.id,0,b.size)};function M(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=Ba.create();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:g=>this.cpu_exception_hook(g),run_hardware_timers:function(g,h){return c.run_hardware_timers(g,h)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){},microtick:F.microtick,get_rand_int:function(){return ba()},
|
|
269
269
|
apic_acknowledge_irq:function(){return c.devices.apic.acknowledge_irq()},stop_idling:function(){return c.stop_idling()},io_port_read8:function(g){return c.io.port_read8(g)},io_port_read16:function(g){return c.io.port_read16(g)},io_port_read32:function(g){return c.io.port_read32(g)},io_port_write8:function(g,h){c.io.port_write8(g,h)},io_port_write16:function(g,h){c.io.port_write16(g,h)},io_port_write32:function(g,h){c.io.port_write32(g,h)},mmap_read8:function(g){return c.mmap_read8(g)},mmap_read16:function(g){return c.mmap_read16(g)},
|
|
270
270
|
mmap_read32:function(g){return c.mmap_read32(g)},mmap_write8:function(g,h){c.mmap_write8(g,h)},mmap_write16:function(g,h){c.mmap_write16(g,h)},mmap_write32:function(g,h){c.mmap_write32(g,h)},mmap_write64:function(g,h,l){c.mmap_write64(g,h,l)},mmap_write128:function(g,h,l,m,n){c.mmap_write128(g,h,l,m,n)},log_from_wasm:function(g,h){String.fromCharCode(...(new Uint8Array(d.buffer,g>>>0,h>>>0)))},console_log_from_wasm:function(g,h){g=String.fromCharCode(...(new Uint8Array(d.buffer,g>>>0,h>>>0)));console.error(g)},
|
|
271
271
|
dbg_trace_from_wasm:function(){},codegen_finalize:(g,h,l,m,n)=>{c.codegen_finalize(g,h,l,m,n)},jit_clear_func:g=>c.jit_clear_func(g),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let f=a.wasm_fn;f||(f=g=>new Promise(h=>{let l="v86.wasm",m="v86-fallback.wasm";a.wasm_path?(l=a.wasm_path,m=l.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(l=__dirname+"/"+l,m=__dirname+"/"+m):(l="build/"+l,m="build/"+m);na(l,{done:async n=>
|
|
272
272
|
{try{const {instance:p}=await WebAssembly.instantiate(n,g);this.wasm_source=n;h(p.exports)}catch(p){na(m,{done:async q=>{const {instance:r}=await WebAssembly.instantiate(q,g);this.wasm_source=q;h(r.exports)}})}},progress:n=>{this.emulator_bus.send("download-progress",{file_index:0,file_count:1,file_name:l,lengthComputable:n.lengthComputable,total:n.total,loaded:n.loaded})}})}));f({env:b}).then(g=>{d=g.memory;g.rust_init();g=this.v86=new F(this.emulator_bus,{exports:g,wasm_table:e});c=g.cpu;this.continue_init(g,
|
|
273
|
-
a)});this.zstd_worker=null;this.zstd_worker_request_id=0}
|
|
273
|
+
a)});this.zstd_worker=null;this.zstd_worker_request_id=0}M.prototype.continue_init=async function(a,b){function c(q,r){switch(q){case "hda":e.hda=this.disk_images.hda=r;break;case "hdb":e.hdb=this.disk_images.hdb=r;break;case "cdrom":e.cdrom=this.disk_images.cdrom=r;break;case "fda":e.fda=this.disk_images.fda=r;break;case "fdb":e.fdb=this.disk_images.fdb=r;break;case "multiboot":e.multiboot=this.disk_images.multiboot=r.buffer;break;case "bzimage":e.bzimage=this.disk_images.bzimage=r.buffer;break;
|
|
274
274
|
case "initrd":e.initrd=this.disk_images.initrd=r.buffer;break;case "bios":e.bios=r.buffer;break;case "vga_bios":e.vga_bios=r.buffer;break;case "initial_state":e.initial_state=r.buffer;break;case "fs9p_json":e.fs9p_json=r}}async function d(){if(e.fs9p&&e.fs9p_json&&!e.initial_state&&(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem)){const {bzimage_path:q,initrd_path:r}=this.get_bzimage_initrd_from_filesystem(e.fs9p),[x,y]=await Promise.all([e.fs9p.read_file(r),e.fs9p.read_file(q)]);
|
|
275
275
|
c.call(this,"initrd",new A(x.buffer));c.call(this,"bzimage",new A(y.buffer))}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;this.screen_adapter.pause()},this);this.bus.register("emulator-started",function(){this.cpu_is_running=!0;this.screen_adapter.continue()},
|
|
276
276
|
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=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=
|
|
277
277
|
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 Tb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new hc(this.bus,b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Vb(f,this.bus,b.net_device):this.network_adapter=new lb(f,this.bus);e.net_device=
|
|
278
|
-
b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new Xb(this.bus));b.disable_mouse||(this.mouse_adapter=new
|
|
278
|
+
b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new Xb(this.bus));b.disable_mouse||(this.mouse_adapter=new Yb(this.bus,f.container));this.screen_adapter=f.container?new sa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new Zb;e.screen=this.screen_adapter;e.screen_options=f;b.serial_container&&(this.serial_adapter=new $b(b.serial_container,this.bus));b.serial_container_xtermjs&&
|
|
279
279
|
(this.serial_adapter=new gc(b.serial_container_xtermjs,this.bus));b.disable_speaker||(this.speaker_adapter=new fb(this.bus));var g=[];f=(q,r)=>{if(r)if(r.get&&r.set&&r.load)g.push({name:q,loadable:r});else{if("bios"===q||"vga_bios"===q||"initial_state"===q||"multiboot"===q||"bzimage"===q||"initrd"===q)r.async=!1;if("fda"===q||"fdb"===q)r.async=!1;r.url&&!r.async?g.push({name:q,url:r.url,size:r.size}):g.push({name:q,loadable:ya(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");
|
|
280
|
-
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){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new ic;h&&(q=new jc(q,h));e.fs9p=this.fs9p=new K(q);
|
|
281
|
-
0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):na(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===
|
|
282
|
-
loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};
|
|
283
|
-
null;return d};
|
|
280
|
+
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&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new ic;h&&(q=new jc(q,h));e.fs9p=this.fs9p=new K(q);
|
|
281
|
+
if(f){if("object"===typeof f){var l=f.size;f=f.url}g.push({name:"fs9p_json",url:f,size:l,as_json:!0})}}var m=this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):na(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===
|
|
282
|
+
x.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};M.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;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));
|
|
283
|
+
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};M.prototype.zstd_decompress_worker=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:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=
|
|
284
|
+
e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,id:h},[n])}else l=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(p=>
|
|
284
285
|
[p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),l.abort=()=>{throw Error("zstd worker aborted");},l.log_from_wasm=l.console_log_from_wasm=(p,q)=>{console.log(String.fromCharCode(...(new Uint8Array(d.exports.memory.buffer,p,q))))},l.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:l})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=
|
|
285
|
-
new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,[this.wasm_source])}return new Promise(c=>{const d=this.zstd_worker_request_id++,e=async f=>{f.data.id===d&&(this.zstd_worker.removeEventListener("message",e),c(f.data.result))};this.zstd_worker.addEventListener("message",e);this.zstd_worker.postMessage({src:b,decompressed_size:a,id:d},[b.buffer])})};
|
|
286
|
-
[]).map(e=>"/boot/"+e);let c,d;for(const e of[].concat(b,a)){const f=/old/i.test(e)||/fallback/i.test(e),g=/vmlinuz/i.test(e)||/bzimage/i.test(e),h=/initrd/i.test(e)||/initramfs/i.test(e);!g||d&&f||(d=e);!h||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}};
|
|
287
|
-
{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.v86.stop()})};
|
|
288
|
-
|
|
289
|
-
async function(a){const b=this.v86.cpu.devices.fdc.drives[0];if(a.url&&!a.async)await new Promise(c=>{na(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=ya(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};
|
|
290
|
-
()=>{b.insert_disk(c)};await c.load()}};
|
|
291
|
-
else{const b=ya(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.cdrom.set_cdrom(b)};await b.load()}};
|
|
292
|
-
|
|
293
|
-
a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};
|
|
294
|
-
|
|
295
|
-
function(a,b){this.bus.send("serial"+a+"-ring-indicator-input",b)};
|
|
296
|
-
-a);};
|
|
297
|
-
b(e)):d.keyboard_send?(Array.isArray(d.keyboard_send)?this.keyboard_send_scancodes(d.keyboard_send):this.keyboard_send_text(d.keyboard_send),b(e)):d.call&&(d.call(),b(e))}};b(a)};
|
|
298
|
-
a))return this.remove_listener("screen-put-char",b),!0;h=!1;d=d?performance.now()+d:0;a:for(;!d||performance.now()<d;){if(c){for(var l=g.length;0<l&&""===g[l-1];)l--;l-=a.length;if(0<=l){let m=!0;for(let n=0;n<a.length&&m;n++)m=f(g[l+n],a[n]);if(m){h=!0;break}}}await new Promise(m=>setTimeout(m,100));for(const m of e)if(l=this.screen_adapter.get_text_row(m),c)g[m]=l.trimRight();else if(f(l,a)){h=!0;break a}e.clear()}this.remove_listener("screen-put-char",b);return h};
|
|
299
|
-
b){return this.v86.cpu.read_blob(a,b)};
|
|
286
|
+
new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,[this.wasm_source])}return new Promise(c=>{const d=this.zstd_worker_request_id++,e=async f=>{f.data.id===d&&(this.zstd_worker.removeEventListener("message",e),c(f.data.result))};this.zstd_worker.addEventListener("message",e);this.zstd_worker.postMessage({src:b,decompressed_size:a,id:d},[b.buffer])})};M.prototype.get_bzimage_initrd_from_filesystem=function(a){const b=(a.read_dir("/")||[]).map(e=>"/"+e);a=(a.read_dir("/boot/")||
|
|
287
|
+
[]).map(e=>"/boot/"+e);let c,d;for(const e of[].concat(b,a)){const f=/old/i.test(e)||/fallback/i.test(e),g=/vmlinuz/i.test(e)||/bzimage/i.test(e),h=/initrd/i.test(e)||/initramfs/i.test(e);!g||d&&f||(d=e);!h||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}};M.prototype.run=async function(){this.v86.run()};M.prototype.stop=async function(){this.cpu_is_running&&await new Promise(a=>
|
|
288
|
+
{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.v86.stop()})};M.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()};
|
|
289
|
+
M.prototype.restart=function(){this.v86.restart()};M.prototype.add_listener=function(a,b){this.bus.register(a,b,this)};M.prototype.remove_listener=function(a,b){this.bus.unregister(a,b)};M.prototype.restore_state=async function(a){this.v86.restore_state(a)};M.prototype.save_state=async function(){return this.v86.save_state()};M.prototype.get_instruction_counter=function(){return this.v86?this.v86.cpu.instruction_counter[0]>>>0:0};M.prototype.is_running=function(){return this.cpu_is_running};M.prototype.set_fda=
|
|
290
|
+
async function(a){const b=this.v86.cpu.devices.fdc.drives[0];if(a.url&&!a.async)await new Promise(c=>{na(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=ya(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};M.prototype.set_fdb=async function(a){const b=this.v86.cpu.devices.fdc.drives[1];if(a.url&&!a.async)await new Promise(c=>{na(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=ya(a,this.zstd_decompress_worker.bind(this));c.onload=
|
|
291
|
+
()=>{b.insert_disk(c)};await c.load()}};M.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.drives[0].eject_disk()};M.prototype.eject_fdb=function(){this.v86.cpu.devices.fdc.drives[1].eject_disk()};M.prototype.get_disk_fda=function(){return this.v86.cpu.devices.fdc.drives[0].get_buffer()};M.prototype.get_disk_fdb=function(){return this.v86.cpu.devices.fdc.drives[1].get_buffer()};M.prototype.set_cdrom=async function(a){if(a.url&&!a.async)na(a.url,{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new A(b))}});
|
|
292
|
+
else{const b=ya(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.cdrom.set_cdrom(b)};await b.load()}};M.prototype.eject_cdrom=function(){this.v86.cpu.devices.cdrom.eject()};M.prototype.keyboard_send_scancodes=function(a){for(var b=0;b<a.length;b++)this.bus.send("keyboard-code",a[b])};M.prototype.keyboard_send_keys=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_press(a[b])};M.prototype.keyboard_send_text=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_char(a[b])};
|
|
293
|
+
M.prototype.screen_make_screenshot=function(){return this.screen_adapter?this.screen_adapter.make_screenshot():null};M.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};M.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||a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&
|
|
294
|
+
a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};M.prototype.lock_mouse=async function(){const a=document.body;try{await a.requestPointerLock({unadjustedMovement:!0})}catch(b){await a.requestPointerLock()}};M.prototype.mouse_set_enabled=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};M.prototype.mouse_set_status=M.prototype.mouse_set_enabled;M.prototype.keyboard_set_enabled=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};M.prototype.keyboard_set_status=
|
|
295
|
+
M.prototype.keyboard_set_enabled;M.prototype.serial0_send=function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",a.charCodeAt(b))};M.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};M.prototype.serial_set_modem_status=function(a,b){this.bus.send("serial"+a+"-modem-status-input",b)};M.prototype.serial_set_carrier_detect=function(a,b){this.bus.send("serial"+a+"-carrier-detect-input",b)};M.prototype.serial_set_ring_indicator=
|
|
296
|
+
function(a,b){this.bus.send("serial"+a+"-ring-indicator-input",b)};M.prototype.serial_set_data_set_ready=function(a,b){this.bus.send("serial"+a+"-data-set-ready-input",b)};M.prototype.serial_set_clear_to_send=function(a,b){this.bus.send("serial"+a+"-clear-to-send-input",b)};M.prototype.mount_fs=async function(a,b,c){var d=new ic;b&&(d=new jc(d,b));d=new K(d,this.fs9p.qidcounter);b&&d.load_from_json(c);a=this.fs9p.Mount(a,d);if(-2===a)throw new qc;if(-17===a)throw new rc;if(0>a)throw Error("Failed to mount. Error number: "+
|
|
297
|
+
-a);};M.prototype.create_file=async function(a,b){var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];a=c.SearchPath(a).parentid;if(""!==d&&-1!==a)await c.CreateBinaryFile(d,a,b);else return Promise.reject(new qc)}};M.prototype.read_file=async function(a){var b=this.fs9p;if(b)return(a=await b.read_file(a))?a:Promise.reject(new qc)};M.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(()=>
|
|
298
|
+
b(e)):d.keyboard_send?(Array.isArray(d.keyboard_send)?this.keyboard_send_scancodes(d.keyboard_send):this.keyboard_send_text(d.keyboard_send),b(e)):d.call&&(d.call(),b(e))}};b(a)};M.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=m=>e.add(m[0]);const f=(m,n)=>n.test?n.test(m):m.startsWith(n),g=[];this.add_listener("screen-put-char",b);for(var h of this.screen_adapter.get_text_screen())if(c)g.push(h.trimRight());else if(f(h,
|
|
299
|
+
a))return this.remove_listener("screen-put-char",b),!0;h=!1;d=d?performance.now()+d:0;a:for(;!d||performance.now()<d;){if(c){for(var l=g.length;0<l&&""===g[l-1];)l--;l-=a.length;if(0<=l){let m=!0;for(let n=0;n<a.length&&m;n++)m=f(g[l+n],a[n]);if(m){h=!0;break}}}await new Promise(m=>setTimeout(m,100));for(const m of e)if(l=this.screen_adapter.get_text_row(m),c)g[m]=l.trimRight();else if(f(l,a)){h=!0;break a}e.clear()}this.remove_listener("screen-put-char",b);return h};M.prototype.read_memory=function(a,
|
|
300
|
+
b){return this.v86.cpu.read_blob(a,b)};M.prototype.write_memory=function(a,b){this.v86.cpu.write_blob(a,b)};M.prototype.set_serial_container_xtermjs=function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new gc(a,this.bus);this.serial_adapter.show()};M.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(" "),
|
|
300
301
|
d=0;const e={};for(let g=0;g<c.length;g++){const h=c[g];var f=void 0;if(h.includes("/")){d++;const [l,m]=h.split("/");f=e[l]/e[m]}else f=e[h]=a.wm.exports.profiler_stat_get(g-d),f=1E8<=f?Math.round(f/1E6)+"m":1E5<=f?Math.round(f/1E3)+"k":f;b+=h+"="+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");
|
|
301
302
|
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[cb(a,!1,!1,!1,!1),cb(a,!0,!1,!1,!1),cb(a,!1,!0,!1,!1),cb(a,!1,
|
|
302
|
-
!1,!0,!1),cb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function rc(a){this.message=a||"File already exists"}rc.prototype=Error.prototype;function qc(a){this.message=a||"File not found"}qc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=
|
|
303
|
+
!1,!0,!1),cb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function rc(a){this.message=a||"File already exists"}rc.prototype=Error.prototype;function qc(a){this.message=a||"File not found"}qc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=M:"undefined"!==typeof window?window.V86=M:"function"===typeof importScripts&&(self.V86=M);function F(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new O(a,
|
|
303
304
|
b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}F.prototype.run=function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};F.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_loop();this.next_tick(a)}};F.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};F.prototype.yield_callback=
|
|
304
305
|
function(a){a===this.tick_counter&&this.do_tick()};F.prototype.stop=function(){this.running&&(this.stopping=!0)};F.prototype.destroy=function(){this.unregister_yield()};F.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};F.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)F.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},F.prototype.register_yield=
|
|
305
306
|
function(){},F.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}F.prototype.register_yield=function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};F.prototype.yield=
|
|
@@ -556,7 +557,7 @@ c=>{var d=this.virtio.queues[c];if(d.has_request()){d=d.pop_request();const e=ne
|
|
|
556
557
|
this.free_cb(this.zeroed),1<this.fp_cmd&&(this.fp_cmd=1),this.virtio.notify_config_changes())}if(0<f.length_writable)for(new Uint8Array(0),e=0;e<f.write_buffers.length;++e){let g=f.write_buffers[e];this.zeroed+=g.len;this.virtio.cpu.zero_memory(g.addr_low,g.len)}this.virtio.queues[c].push_reply(f)}this.virtio.queues[c].flush_replies()}]},isr_status:{initial_port:55040},device_specific:{initial_port:54784,struct:[{bytes:4,name:"num_pages",read:()=>this.num_pages,write:()=>{}},{bytes:4,name:"actual",
|
|
557
558
|
read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}Wc.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};Wc.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};Wc.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};Wc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};
|
|
558
559
|
Wc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};Wc.prototype.GetStats=function(a){this.stats_cb=a;for(a=this.virtio.queues[2];a.has_request();){const b=a.pop_request();this.virtio.queues[2].push_reply(b)}this.virtio.queues[2].flush_replies()};Wc.prototype.Reset=function(){};function Xc(a,b,c,d){var e=new Uint8Array(b);const f=new Uint16Array(b);var g=new Uint32Array(b),h=e[497]||4,l=f[255];if(43605!==l)z(l);else if(l=f[257]|f[258]<<16,1400005704!==
|
|
559
|
-
l)z(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],x=518<=l?g[142]:255,y=g[146],u=g[147],H=g[150],
|
|
560
|
+
l)z(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],x=518<=l?g[142]:255,y=g[146],u=g[147],H=g[150],N=g[151],v=g[152];z(l);z(m);z(n);z(g[133]);z(p);z(q);z(r);z(x);z(y);z(u);z(N);z(H);z(v);e[528]=255;e[529]=m&-97|128;f[274]=56832;f[253]=65535;z(56832);d+="\x00";z(581632);g[138]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);h=512*(h+1);z(h);d=new Uint8Array(b,0,h);b=new Uint8Array(b,h);e=h=0;c&&(h=67108864,e=c.byteLength,a.set(new Uint8Array(c),h));g[134]=h;g[135]=e;a.set(d,
|
|
560
561
|
524288);a.set(b,1048576);a=new Uint8Array(512);(new Uint16Array(a.buffer))[0]=43605;a[2]=1;c=3;a[c++]=250;a[c++]=184;a[c++]=32768;a[c++]=128;a[c++]=142;a[c++]=192;a[c++]=142;a[c++]=216;a[c++]=142;a[c++]=224;a[c++]=142;a[c++]=232;a[c++]=142;a[c++]=208;a[c++]=188;a[c++]=57344;a[c++]=224;a[c++]=234;a[c++]=0;a[c++]=0;a[c++]=32800;a[c++]=128;g=a[c]=0;for(b=0;b<a.length;b++)g+=a[b];a[c]=-g;return{name:"genroms/kernel.bin",data:a}}}function O(a,b,c){this.stop_idling=c;this.wm=b;this.wasm_patch();this.create_jit_imports();
|
|
561
562
|
this.wasm_memory=b=this.wm.exports.memory;this.memory_size=k(Uint32Array,b,812,1);this.mem8=new Uint8Array(0);this.mem32s=new Int32Array(this.mem8.buffer);this.segment_is_null=k(Uint8Array,b,724,8);this.segment_offsets=k(Int32Array,b,736,8);this.segment_limits=k(Uint32Array,b,768,8);this.segment_access_bytes=k(Uint8Array,b,512,8);this.protected_mode=k(Int32Array,b,800,1);this.idtr_size=k(Int32Array,b,564,1);this.idtr_offset=k(Int32Array,b,568,1);this.gdtr_size=k(Int32Array,b,572,1);this.gdtr_offset=
|
|
562
563
|
k(Int32Array,b,576,1);this.tss_size_32=k(Int32Array,b,1128,1);this.page_fault=k(Uint32Array,b,540,8);this.cr=k(Int32Array,b,580,8);this.cpl=k(Uint8Array,b,612,1);this.is_32=k(Int32Array,b,804,1);this.stack_size_32=k(Int32Array,b,808,1);this.in_hlt=k(Uint8Array,b,616,1);this.last_virt_eip=k(Int32Array,b,620,1);this.eip_phys=k(Int32Array,b,624,1);this.sysenter_cs=k(Int32Array,b,636,1);this.sysenter_esp=k(Int32Array,b,640,1);this.sysenter_eip=k(Int32Array,b,644,1);this.prefixes=k(Int32Array,b,648,1);
|
|
@@ -591,63 +592,70 @@ if(0===e)this.fw_value=f(1431127377);else if(1===e)this.fw_value=f(0);else if(3=
|
|
|
591
592
|
for(let r=0;r<n.length;r++)l[q+8+r]=n.charCodeAt(r)}this.fw_value=l}else 32768<=e&&49152>e?this.fw_value=f(0):49152<=e&&e-49152<this.option_roms.length?this.fw_value=this.option_roms[e-49152].data:(qa("Warning: Unimplemented fw index: "+z(e)),this.fw_value=f(0))});c.register_read(32,this,this.port20_read);c.register_read(33,this,this.port21_read);c.register_read(160,this,this.portA0_read);c.register_read(161,this,this.portA1_read);c.register_write(32,this,this.port20_write);c.register_write(33,this,
|
|
592
593
|
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,this.port4D0_write);c.register_write(1233,this,this.port4D1_write);this.devices={};a.load_devices&&(this.devices.pci=new wc(this),this.acpi_enabled[0]&&(this.devices.ioapic=new tc(this),this.devices.apic=new sc(this),this.devices.acpi=new uc(this)),this.devices.rtc=new db(this),
|
|
593
594
|
this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),this.devices.vga=new X(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Cc(this,b),this.devices.uart0=new vc(this,1016,b),a.uart1&&(this.devices.uart1=new vc(this,760,b)),a.uart2&&(this.devices.uart2=new vc(this,1E3,b)),a.uart3&&(this.devices.uart3=new vc(this,744,b)),this.devices.fdc=new V(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,
|
|
594
|
-
buffer:a.cdrom},this.devices.ide=new Qc(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,this.devices.pit=new eb(this,b),"ne2k"===a.net_device.type?this.devices.net=new zc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new Sc(this,b,a.preserve_mac_from_state_image)),a.fs9p
|
|
595
|
-
new Wc(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244));this.debug_init()};O.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};O.prototype.load_multiboot_option_rom=
|
|
596
|
-
new Int32Array(a,0,2048);for(var e=0;8192>e;e+=4){if(464367618===d[e>>2]){var f=d[e+4>>2];if(464367618+f+d[e+8>>2]|0)continue}else continue;qa("Multiboot magic found, flags: "+z(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n=31860,p=0;if(c){p|=4;g.write32(31760,n);c+="\x00";var q=(new TextEncoder).encode(c);g.write_blob(q,
|
|
597
|
-
u;u+=131072)x&&void 0!==g.memory_map_read8[u>>>17]?(g.write32(n,20),g.write32(n+4,r),g.write32(n+8,0),g.write32(n+12,u-r),g.write32(n+16,0),g.write32(n+20,1),n+=24,q+=24,x=!1):x||void 0!==g.memory_map_read8[u>>>17]||(r=u,x=!0);g.write32(31788,q)}g.write32(31744,p);q=p=0;if(f&65536){x=d[e+12>>2];p=d[e+16>>2];var y=d[e+20>>2];q=d[e+24>>2];r=d[e+28>>2];z(x,8);z(p,8);z(y,8);z(q,8);z(r,8);x=new Uint8Array(a,
|
|
598
|
-
new DataView(a);const [u,H]=Kc(r,Hc);console.assert(52===H);console.assert(1179403647===u.magic,"Bad magic");console.assert(1===u.class,"Unimplemented: 64 bit elf");console.assert(1===u.data,"Unimplemented: big endian");console.assert(1===u.version0,"Bad version0");console.assert(2===u.type,"Unimplemented type");console.assert(1===u.version1,"Bad version1");console.assert(52===u.ehsize,"Bad header size");
|
|
599
|
-
[p]=Lc(new DataView(r.buffer,r.byteOffset+u.phoff,u.phentsize*u.phnum),Ic,u.phnum);Lc(new DataView(r.buffer,r.byteOffset+u.shoff,u.shentsize*u.shnum),Jc,u.shnum);r=u;x=p;p=r.entry;for(y of x)0!==y.type&&(1===y.type?y.paddr+y.memsz<g.memory_size[0]?(y.filesz&&(x=new Uint8Array(a,y.offset,y.filesz),g.write_blob(x,y.paddr)),q=Math.max(q,y.paddr+y.memsz),p===r.entry&&y.vaddr<=p&&y.vaddr+
|
|
600
|
-
y.type||1685382481===y.type||1685382482===y.type||1685382483===y.type||z(y.type))}b&&(g.write32(31764,1),g.write32(31768,n),y=q,0!==(y&4095)&&(y=(y&-4096)+4096),q=y+b.byteLength,g.write32(n,y),g.write32(n+4,q),g.write32(n+8,0),g.write32(n+12,0),g.write_blob(new Uint8Array(b),y));g.reg32[3]=31744;g.cr[0]=1;g.protected_mode[0]=1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(n=0;6>
|
|
601
|
-
g.get_seg_cs()+p|0;g.update_state_flags();g.dump_state();g.dump_regs_short();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+z(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){z(n);z(q,2);q?this.device_raise_irq(n):this.device_lower_irq(n)}this.io.register_write(8192+
|
|
602
|
-
244;let m=l[h]=0;for(let n=0;n<l.length;n++)m+=l[n];l[h]=-m;return{name:"genroms/multiboot.bin",data:l}}};O.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,
|
|
603
|
-
16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92,0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)};O.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){var d=new Uint8Array(b);this.write_blob(d,
|
|
604
|
-
function(){})}this.io.mmap_register(4293918720,1048576,function(e){return this.mem8[e&1048575]}.bind(this),function(e,f){this.mem8[e&1048575]=f}.bind(this))}};O.prototype.codegen_finalize=function(a,b,c,d,e){const f=new Uint8Array(this.wasm_memory.buffer,d>>>0,e>>>0);WebAssembly.instantiate(f,{e:this.jit_imports}).then(g=>{this.wm.wasm_table.set(a+1024,g.instance.exports.f);this.codegen_finalize_finished(a,
|
|
605
|
-
function(){};O.prototype.dump_function_code=function(){};O.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};O.prototype.device_raise_irq=function(a){this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};O.prototype.device_lower_irq=
|
|
606
|
-
O.prototype.debug_init=function(){};O.prototype.dump_stack=function(){};O.prototype.debug_get_state=function(){};O.prototype.dump_state=function(){};O.prototype.get_regs_short=function(){};O.prototype.dump_regs_short=function(){};O.prototype.dump_gdt_ldt=function(){};O.prototype.dump_idt=function(){};O.prototype.dump_page_structures=function(){if(this.cr[4]&32)for(var a=0;4>a;a++){var b=this.read32s(this.cr[3]+
|
|
607
|
-
|
|
608
|
-
0,0,0,0,0,0,244,26,b.subsystem_device_id&255,b.subsystem_device_id>>8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.pci_space=this.pci_space.concat(Array(256-this.pci_space.length).fill(0));this.pci_id=b.pci_id;this.pci_bars=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature=new Uint32Array(4);this.driver_feature=new Uint32Array(4);for(var c of b.common.features)this.device_feature[c>>>
|
|
609
|
-
this.features_ok=!0;this.device_status=0;this.config_has_changed=!1;this.config_generation=0;this.queues=[];for(const d of b.common.queues)this.queues.push(new Y(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification));c.push(this.create_isr_capability(b.isr_status));b.device_specific&&
|
|
610
|
-
a.devices.pci.register_device(this);this.reset()}Bc.prototype.create_common_capability=function(a){return{type:1,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},
|
|
611
|
-
b}},{bytes:4,name:"driver_feature",read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select<this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",
|
|
612
|
-
{0===b&&this.reset();b&~this.device_status&4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_select<
|
|
613
|
-
this.queue_selected.size:0,write:b=>{this.queue_selected&&(b&b-1&&(b=1<<ca(b-1)+1),b>this.queue_selected.size_supported&&(b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&1===b&&this.queue_selected.is_configured()&&
|
|
614
|
-
this.queue_selected.notify_offset:0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&
|
|
615
|
-
0,write:()=>{}},{bytes:4,name:"queue_used (low dword)",read:()=>this.queue_selected?this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}};Bc.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0:2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+
|
|
616
|
-
offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),struct:b}};Bc.prototype.create_isr_capability=function(a){return{type:3,bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};Bc.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,
|
|
617
|
-
function(a){let b=this.pci_space[52]=64;var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;var d=e.struct.reduce((f,g)=>f+g.bytes,0);d+=e.offset;d=16>d?16:1<<ca(d-1)+1;this.pci_bars[e.bar]={size:d};this.pci_space[c]=9;this.pci_space[c+1]=b;this.pci_space[c+2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&
|
|
618
|
-
11]=e.offset>>>24;this.pci_space[c+12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [f,g]of e.extra.entries())this.pci_space[c+16+f]=g;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let g=
|
|
619
|
-
|
|
620
|
-
9;this.pci_space[b+1]=0;this.pci_space[b+2]=20;this.pci_space[b+3]=5;this.pci_space[b+4]=0;this.pci_space[b+5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+
|
|
621
|
-
a[1]=this.driver_feature_select;a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};Bc.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=
|
|
622
|
-
a[7];this.isr_status=a[8];this.queue_select=a[9];let b=0;for(const c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null};Bc.prototype.reset=function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];
|
|
623
|
-
Bc.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4&&this.raise_irq(2)};Bc.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};Bc.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};Bc.prototype.needs_reset=function(){this.device_status|=
|
|
624
|
-
function(a){z(a);this.isr_status|=a;this.pci.raise_irq(this.pci_id)};Bc.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_id)};function Y(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}Y.prototype.get_state=
|
|
625
|
-
a[2]=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};Y.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=
|
|
626
|
-
this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};Y.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};Y.prototype.enable=function(){this.is_configured();this.enabled=!0};Y.prototype.set_size=function(a){this.size=a;this.mask=a-1};Y.prototype.count_requests=function(){this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=
|
|
627
|
-
this.avail_last_idx&65535};Y.prototype.has_request=function(){return 0!==this.count_requests()};Y.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new
|
|
628
|
-
this.used_get_idx()+this.num_staged_replies&65535;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(29)?(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Y.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Y.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+
|
|
629
|
-
16*b+12),next:this.cpu.read16(a+16*b+14)}};Y.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};Y.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Y.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Y.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Y.prototype.used_get_flags=
|
|
630
|
-
function(a){this.cpu.write16(this.used_addr,a)};Y.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};Y.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Y.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)};Y.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function
|
|
631
|
-
[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);z(h.addr_high,8);z(h.addr_low,8);z(h.len,8);z(h.flags,4);z(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags&
|
|
632
|
-
this.read_buffers.push(h);this.length_readable+=h.len}d++;if(d>e)break;if(h.flags&1)b=h.next;else break}}while(1)}
|
|
633
|
-
function(a){let b=0,c=a.length;for(;c&&this.write_buffer_idx!==this.write_buffers.length;){var d=this.write_buffers[this.write_buffer_idx];const e=d.addr_low+this.write_buffer_offset;d=d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};function
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
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};Yc.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=
|
|
637
|
-
type:b[1],uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};Yc.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};Yc.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Yc.prototype.reset=function(){this.fids=[];this.virtio.reset()};Yc.prototype.BuildReply=function(a,b,c){G(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=
|
|
638
|
-
a,b)};Yc.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};Yc.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=I(["w","b","h"],b,c),e=d[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();var h=this.fs.GetSpace();d=[16914839];
|
|
639
|
-
d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=G("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 112:case 12:d=I(["w","w"],b,c);e=d[0];c=d[1];b=this.fids[e].inodeid;var l=this.fs.GetInode(b);h=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[e].inodeid,function(){var q=[];q[0]=l.qid;q[1]=this.msize-24;G(["Q","w"],q,
|
|
640
|
-
"w","s"],b,c);b=d[0];e=d[1];h=d[2];h=this.fs.Link(this.fids[b].inodeid,this.fids[e].inodeid,h);if(0>h){this.SendError(g,-1===h?"Operation not permitted":"Unknown error: "+-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=I(["w","s","s","w"],b,c);e=d[0];h=d[1];var m=d[3];b=this.fs.CreateSymlink(h,this.fids[e].inodeid,d[2]);l=this.fs.GetInode(b);l.uid=this.fids[e].uid;
|
|
641
|
-
I("wswwww".split(""),b,c);e=d[0];h=d[1];c=d[2];b=d[3];var n=d[4];m=d[5];b=this.fs.CreateNode(h,this.fids[e].inodeid,b,n);l=this.fs.GetInode(b);l.mode=c;l.uid=this.fids[e].uid;l.gid=m;G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 22:d=I(["w"],b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);e=G(["s"],[l.symlink],this.replybuffer,7);this.BuildReply(f,g,
|
|
642
|
-
this.fids[e].inodeid);l=this.fs.GetInode(b);l.mode=c|16384;l.uid=this.fids[e].uid;l.gid=m;G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 14:d=I(["w","s","w","w","w"],b,c);e=d[0];h=d[1];b=d[2];c=d[3];m=d[4];this.bus.send("9p-create",[h,this.fids[e].inodeid]);b=this.fs.CreateFile(h,this.fids[e].inodeid);this.fids[e].inodeid=b;this.fids[e].type=
|
|
643
|
-
24],this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a);break;case 52:d=I("wbwddws".split(""),b,c);e=d[0];b=d[2];h=0===d[4]?Infinity:d[4];d=this.fs.DescribeLock(d[1],d[3],h,d[5],d[6]);h=this.fs.Lock(this.fids[e].inodeid,d,b);G(["b"],[h],this.replybuffer,7);this.BuildReply(f,g,1);this.SendReply(a);break;case 54:d=I("wbddws".split(""),b,c);e=d[0];h=0===d[3]?Infinity:
|
|
644
|
-
"d","w","s"],[h.type,h.start,Infinity===h.length?0:h.length,h.proc_id,h.client_id],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 24:d=I(["w","d"],b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;d[3]=l.uid;d[4]=l.gid;d[5]=
|
|
645
|
-
l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;G("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,g,153);this.SendReply(a);break;case 26:d=I("wwwwwddddd".split(""),b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);d[1]&1&&(l.mode=d[2]);d[1]&2&&(l.uid=d[3]);d[1]&4&&(l.gid=d[4]);d[1]&16&&(l.atime=Math.floor((new Date).getTime()/
|
|
646
|
-
128&&(l.atime=d[6]);d[1]&256&&(l.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[e].inodeid,d[5]);this.BuildReply(f,g,0);this.SendReply(a);break;case 50:d=I(["w","d"],b,c);e=d[0];this.BuildReply(f,g,0);this.SendReply(a);break;case 40:case 116:d=I(["w","d","w"],b,c);e=d[0];h=d[1];m=d[2];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",
|
|
647
|
-
m;d++)this.replybuffer[11+d]=l.caps[h+d];else this.fs.OpenInode(this.fids[e].inodeid,void 0),d=this.fids[e].inodeid,m=Math.min(m,this.replybuffer.length-11),l.size<h+m?m=l.size-h:40===f&&(m=this.fs.RoundToDirentry(d,h+m)-h),h>l.size&&(m=0),this.bus.send("9p-read-start",[this.fids[e].dbg_name]),d=await this.fs.Read(d,h,m),this.bus.send("9p-read-end",[this.fids[e].dbg_name,m]),d&&this.replybuffer.set(d,
|
|
648
|
-
"d","w"],b,c);e=d[0];h=d[1];m=d[2];d=this.fids[e].dbg_name;if(2===this.fids[e].type){this.SendError(g,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[e].inodeid,h,m,b.subarray(c.offset));this.bus.send("9p-write-end",[d,m]);G(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4);this.SendReply(a);break;case 74:d=I(["w","s","w","s"],b,c);h=await this.fs.Rename(this.fids[d[0]].inodeid,
|
|
649
|
-
|
|
650
|
-
break}this.BuildReply(f,g,0);this.SendReply(a);break;case 100:e=I(["w","s"],b,c);this.msize!==e[0]&&(this.msize=e[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));e=G(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 104:d=I(["w","w","s","s","w"],b,c);e=d[0];h=d[4];qa("[attach]: fid="+e+" afid="+z(d[1])+" uname="+d[2]+" aname="+
|
|
651
|
-
G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=I(["h"],b,c);this.BuildReply(f,g,0);this.SendReply(a);break;case 110:d=I(["w","w","h"],b,c);e=d[0];m=d[1];n=d[2];if(0===n){this.fids[m]=this.Createfid(this.fids[e].inodeid,1,this.fids[e].uid,this.fids[e].dbg_name);G(["h"],[0],this.replybuffer,7);this.BuildReply(f,g,2);this.SendReply(a);
|
|
652
|
-
n;d++){b=this.fs.Search(b,c[d]);if(-1===b)break;h+=G(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,h);p++;this.fids[m]=this.Createfid(b,1,this.fids[e].uid,c[d])}G(["h"],[p],this.replybuffer,7);this.BuildReply(f,g,h-7);this.SendReply(a);break;case 120:d=I(["w"],b,c);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type
|
|
653
|
-
d[0];h=d[1];b=d[3];this.fids[e].type=2;this.BuildReply(f,g,0);this.SendReply(a);break;case 30:d=I(["w","w","s"],b,c),e=d[0],h=d[2],this.SendError(g,"Setxattr not supported",95),this.SendReply(a)}};
|
|
595
|
+
buffer:a.cdrom},this.devices.ide=new Qc(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,this.devices.pit=new eb(this,b),"ne2k"===a.net_device.type?this.devices.net=new zc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new Sc(this,b,a.preserve_mac_from_state_image)),a.fs9p?this.devices.virtio_9p=new Yc(a.fs9p,this,b):a.handle9p?this.devices.virtio_9p=new Zc(a.handle9p,this):a.proxy9p&&(this.devices.virtio_9p=new $c(a.proxy9p,
|
|
596
|
+
this)),a.virtio_console&&(this.devices.virtio_console=new Ac(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new Wc(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244));this.debug_init()};O.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};O.prototype.load_multiboot_option_rom=
|
|
597
|
+
function(a,b,c){if(8192>a.byteLength){var d=new Int32Array(2048);(new Uint8Array(d.buffer)).set(new Uint8Array(a))}else d=new Int32Array(a,0,2048);for(var e=0;8192>e;e+=4){if(464367618===d[e>>2]){var f=d[e+4>>2];if(464367618+f+d[e+8>>2]|0)continue}else continue;qa("Multiboot magic found, flags: "+z(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n=31860,p=0;if(c){p|=4;g.write32(31760,n);c+="\x00";var q=(new TextEncoder).encode(c);g.write_blob(q,
|
|
598
|
+
n);n+=q.length}if(f&2){p|=64;q=0;g.write32(31788,0);g.write32(31792,n);var r=0;var x=!1;for(let u=0;4294967296>u;u+=131072)x&&void 0!==g.memory_map_read8[u>>>17]?(g.write32(n,20),g.write32(n+4,r),g.write32(n+8,0),g.write32(n+12,u-r),g.write32(n+16,0),g.write32(n+20,1),n+=24,q+=24,x=!1):x||void 0!==g.memory_map_read8[u>>>17]||(r=u,x=!0);g.write32(31788,q)}g.write32(31744,p);q=p=0;if(f&65536){x=d[e+12>>2];p=d[e+16>>2];var y=d[e+20>>2];q=d[e+24>>2];r=d[e+28>>2];z(x,8);z(p,8);z(y,8);z(q,8);z(r,8);x=new Uint8Array(a,
|
|
599
|
+
e-(x-p),0===y?void 0:y-p);g.write_blob(x,p);p=r|0;q=Math.max(y,q)}else if(1179403647===d[0]){r=new DataView(a);const [u,H]=Kc(r,Hc);console.assert(52===H);console.assert(1179403647===u.magic,"Bad magic");console.assert(1===u.class,"Unimplemented: 64 bit elf");console.assert(1===u.data,"Unimplemented: big endian");console.assert(1===u.version0,"Bad version0");console.assert(2===u.type,"Unimplemented type");console.assert(1===u.version1,"Bad version1");console.assert(52===u.ehsize,"Bad header size");
|
|
600
|
+
console.assert(32===u.phentsize,"Bad program header size");console.assert(40===u.shentsize,"Bad section header size");[p]=Lc(new DataView(r.buffer,r.byteOffset+u.phoff,u.phentsize*u.phnum),Ic,u.phnum);Lc(new DataView(r.buffer,r.byteOffset+u.shoff,u.shentsize*u.shnum),Jc,u.shnum);r=u;x=p;p=r.entry;for(y of x)0!==y.type&&(1===y.type?y.paddr+y.memsz<g.memory_size[0]?(y.filesz&&(x=new Uint8Array(a,y.offset,y.filesz),g.write_blob(x,y.paddr)),q=Math.max(q,y.paddr+y.memsz),p===r.entry&&y.vaddr<=p&&y.vaddr+
|
|
601
|
+
y.memsz>p&&(p=p-y.vaddr+y.paddr)):z(y.paddr):2===y.type||3===y.type||4===y.type||6===y.type||7===y.type||1685382480===y.type||1685382481===y.type||1685382482===y.type||1685382483===y.type||z(y.type))}b&&(g.write32(31764,1),g.write32(31768,n),y=q,0!==(y&4095)&&(y=(y&-4096)+4096),q=y+b.byteLength,g.write32(n,y),g.write32(n+4,q),g.write32(n+8,0),g.write32(n+12,0),g.write_blob(new Uint8Array(b),y));g.reg32[3]=31744;g.cr[0]=1;g.protected_mode[0]=1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(n=0;6>
|
|
602
|
+
n;n++)g.segment_is_null[n]=0,g.segment_offsets[n]=0,g.segment_limits[n]=4294967295,g.sreg[n]=45058;g.instruction_pointer[0]=g.get_seg_cs()+p|0;g.update_state_flags();g.dump_state();g.dump_regs_short();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+z(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){z(n);z(q,2);q?this.device_raise_irq(n):this.device_lower_irq(n)}this.io.register_write(8192+
|
|
603
|
+
n,this,p,p,p)}const l=new Uint8Array(512);(new Uint16Array(l.buffer))[0]=43605;l[2]=1;var h=3;l[h++]=102;l[h++]=229;l[h++]=244;let m=l[h]=0;for(let n=0;n<l.length;n++)m+=l[n];l[h]=-m;return{name:"genroms/multiboot.bin",data:l}}};O.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,
|
|
604
|
+
c>>8&255);a.cmos_write(48,c&255);a.cmos_write(49,c>>8&255);c=0;16777216<=this.memory_size[0]&&(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92,0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)};O.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){var d=new Uint8Array(b);this.write_blob(d,
|
|
605
|
+
786432);this.io.mmap_register(4272947200,1048576,function(e){e=e-4272947200|0;return e<d.length?d[e]:0},function(){})}this.io.mmap_register(4293918720,1048576,function(e){return this.mem8[e&1048575]}.bind(this),function(e,f){this.mem8[e&1048575]=f}.bind(this))}};O.prototype.codegen_finalize=function(a,b,c,d,e){const f=new Uint8Array(this.wasm_memory.buffer,d>>>0,e>>>0);WebAssembly.instantiate(f,{e:this.jit_imports}).then(g=>{this.wm.wasm_table.set(a+1024,g.instance.exports.f);this.codegen_finalize_finished(a,
|
|
606
|
+
b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)})};O.prototype.log_uncompiled_code=function(){};O.prototype.dump_function_code=function(){};O.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};O.prototype.device_raise_irq=function(a){this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};O.prototype.device_lower_irq=
|
|
607
|
+
function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};O.prototype.debug_init=function(){};O.prototype.dump_stack=function(){};O.prototype.debug_get_state=function(){};O.prototype.dump_state=function(){};O.prototype.get_regs_short=function(){};O.prototype.dump_regs_short=function(){};O.prototype.dump_gdt_ldt=function(){};O.prototype.dump_idt=function(){};O.prototype.dump_page_structures=function(){if(this.cr[4]&32)for(var a=0;4>a;a++){var b=this.read32s(this.cr[3]+
|
|
608
|
+
8*a);b&1&&this.dump_page_directory(b&4294963200,!0,a<<30)}else this.dump_page_directory(this.cr[3],!1,0)};O.prototype.dump_page_directory=function(){};O.prototype.get_memory_dump=function(){};O.prototype.memory_hex_dump=function(){};O.prototype.used_memory_dump=function(){};O.prototype.debug_interrupt=function(){};O.prototype.debug_dump_code=function(){};O.prototype.dump_wasm=function(){};function Bc(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=b.device_id;this.pci_space=[244,26,b.device_id&
|
|
609
|
+
255,b.device_id>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,b.subsystem_device_id&255,b.subsystem_device_id>>8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.pci_space=this.pci_space.concat(Array(256-this.pci_space.length).fill(0));this.pci_id=b.pci_id;this.pci_bars=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature=new Uint32Array(4);this.driver_feature=new Uint32Array(4);for(var c of b.common.features)this.device_feature[c>>>
|
|
610
|
+
5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);b.common.features.includes(32);this.features_ok=!0;this.device_status=0;this.config_has_changed=!1;this.config_generation=0;this.queues=[];for(const d of b.common.queues)this.queues.push(new Y(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification));c.push(this.create_isr_capability(b.isr_status));b.device_specific&&
|
|
611
|
+
c.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(c);a.devices.pci.register_device(this);this.reset()}Bc.prototype.create_common_capability=function(a){return{type:1,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},
|
|
612
|
+
{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=b}},{bytes:4,name:"driver_feature",read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select<this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",
|
|
613
|
+
read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b&&this.reset();b&~this.device_status&4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_select<
|
|
614
|
+
this.queues.length?this.queues[this.queue_select]:null}},{bytes:2,name:"queue_size",read:()=>this.queue_selected?this.queue_selected.size:0,write:b=>{this.queue_selected&&(b&b-1&&(b=1<<ca(b-1)+1),b>this.queue_selected.size_supported&&(b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&1===b&&this.queue_selected.is_configured()&&
|
|
615
|
+
this.queue_selected.enable()}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&
|
|
616
|
+
(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_used (low dword)",read:()=>this.queue_selected?this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}};Bc.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0:2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+
|
|
617
|
+
d,read:()=>65535,write:e||(()=>{})});return{type:2,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),struct:b}};Bc.prototype.create_isr_capability=function(a){return{type:3,bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};Bc.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,
|
|
618
|
+
use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};Bc.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;var d=e.struct.reduce((f,g)=>f+g.bytes,0);d+=e.offset;d=16>d?16:1<<ca(d-1)+1;this.pci_bars[e.bar]={size:d};this.pci_space[c]=9;this.pci_space[c+1]=b;this.pci_space[c+2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&
|
|
619
|
+
255;this.pci_space[c+9]=e.offset>>>8&255;this.pci_space[c+10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>24;this.pci_space[c+12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [f,g]of e.extra.entries())this.pci_space[c+16+f]=g;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let g=
|
|
620
|
+
f.read;a=f.write;if(!e.use_mmio){d=function(l){return g(l&-2)>>((l&1)<<3)&255};const h=function(l){return g(l&-4)>>((l&3)<<3)&255};switch(f.bytes){case 4:this.cpu.io.register_read(c,this,h,void 0,g);this.cpu.io.register_read(c+1,this,h);this.cpu.io.register_read(c+2,this,h);this.cpu.io.register_read(c+3,this,h);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,g);this.cpu.io.register_read(c+1,this,d);this.cpu.io.register_write(c,this,void 0,a);break;
|
|
621
|
+
case 1:this.cpu.io.register_read(c,this,g),this.cpu.io.register_write(c,this,a)}}c+=f.bytes}}this.pci_space[b]=9;this.pci_space[b+1]=0;this.pci_space[b+2]=20;this.pci_space[b+3]=5;this.pci_space[b+4]=0;this.pci_space[b+5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+
|
|
622
|
+
18]=0;this.pci_space[b+19]=0};Bc.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;a[1]=this.driver_feature_select;a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};Bc.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=
|
|
623
|
+
a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];this.queue_select=a[9];let b=0;for(const c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null};Bc.prototype.reset=function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];
|
|
624
|
+
for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};Bc.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4&&this.raise_irq(2)};Bc.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};Bc.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};Bc.prototype.needs_reset=function(){this.device_status|=
|
|
625
|
+
64;this.device_status&4&&this.notify_config_changes()};Bc.prototype.raise_irq=function(a){z(a);this.isr_status|=a;this.pci.raise_irq(this.pci_id)};Bc.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_id)};function Y(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}Y.prototype.get_state=
|
|
626
|
+
function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=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};Y.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=
|
|
627
|
+
1!==a[9]};Y.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};Y.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};Y.prototype.enable=function(){this.is_configured();this.enabled=!0};Y.prototype.set_size=function(a){this.size=a;this.mask=a-1};Y.prototype.count_requests=function(){this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=
|
|
628
|
+
(this.avail_get_idx()&~this.mask)+(this.avail_last_idx&this.mask));return this.avail_get_idx()-this.avail_last_idx&65535};Y.prototype.has_request=function(){return 0!==this.count_requests()};Y.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new ad(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Y.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);
|
|
629
|
+
this.num_staged_replies++};Y.prototype.flush_replies=function(){if(0!==this.num_staged_replies){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)?(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Y.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Y.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+
|
|
630
|
+
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)}};Y.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};Y.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Y.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Y.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Y.prototype.used_get_flags=
|
|
631
|
+
function(){return this.cpu.read16(this.used_addr)};Y.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};Y.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};Y.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Y.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)};Y.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function ad(a,
|
|
632
|
+
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=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);z(h.addr_high,8);z(h.addr_low,8);z(h.len,8);z(h.flags,4);z(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags&
|
|
633
|
+
2)f=!0,this.write_buffers.push(h),this.length_writable+=h.len;else{if(f)break;this.read_buffers.push(h);this.length_readable+=h.len}d++;if(d>e)break;if(h.flags&1)b=h.next;else break}}while(1)}ad.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c&&this.read_buffer_idx!==this.read_buffers.length;){var d=this.read_buffers[this.read_buffer_idx];const e=d.addr_low+this.read_buffer_offset;d=d.len-this.read_buffer_offset;d>c?(d=c,this.read_buffer_offset+=c):(this.read_buffer_idx++,this.read_buffer_offset=
|
|
634
|
+
0);a.set(this.cpu.read_blob(e,d),b);b+=d;c-=d}return b};ad.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c&&this.write_buffer_idx!==this.write_buffers.length;){var d=this.write_buffers[this.write_buffer_idx];const e=d.addr_low+this.write_buffer_offset;d=d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};function bd(a,b,c,d){const e=
|
|
635
|
+
new Bc(a,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[f=>{if(0===f){for(f=e.queues[0];f.has_request();){const g=f.pop_request();d(g)}f.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>b,write:()=>{}}].concat(Array.from(Array(254).keys()).map(f=>
|
|
636
|
+
({bytes:1,name:"mount tag name "+f,read:()=>c[f]||0,write:()=>{}})))}});return e}function Yc(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=bd(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=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[]}Yc.prototype.get_state=
|
|
637
|
+
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};Yc.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=
|
|
638
|
+
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])};Yc.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};Yc.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Yc.prototype.reset=function(){this.fids=[];this.virtio.reset()};Yc.prototype.BuildReply=function(a,b,c){G(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=
|
|
639
|
+
c+7};Yc.prototype.SendError=function(a,b,c){b=G(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};Yc.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};Yc.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=I(["w","b","h"],b,c),e=d[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();var h=this.fs.GetSpace();d=[16914839];
|
|
640
|
+
d[1]=this.BLOCKSIZE;d[2]=Math.floor(h/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=G("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 112:case 12:d=I(["w","w"],b,c);e=d[0];c=d[1];b=this.fids[e].inodeid;var l=this.fs.GetInode(b);h=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[e].inodeid,function(){var q=[];q[0]=l.qid;q[1]=this.msize-24;G(["Q","w"],q,
|
|
641
|
+
this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a)}.bind(this));break;case 70:d=I(["w","w","s"],b,c);b=d[0];e=d[1];h=d[2];h=this.fs.Link(this.fids[b].inodeid,this.fids[e].inodeid,h);if(0>h){this.SendError(g,-1===h?"Operation not permitted":"Unknown error: "+-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=I(["w","s","s","w"],b,c);e=d[0];h=d[1];var m=d[3];b=this.fs.CreateSymlink(h,this.fids[e].inodeid,d[2]);l=this.fs.GetInode(b);l.uid=this.fids[e].uid;
|
|
642
|
+
l.gid=m;G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 18:d=I("wswwww".split(""),b,c);e=d[0];h=d[1];c=d[2];b=d[3];var n=d[4];m=d[5];b=this.fs.CreateNode(h,this.fids[e].inodeid,b,n);l=this.fs.GetInode(b);l.mode=c;l.uid=this.fids[e].uid;l.gid=m;G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 22:d=I(["w"],b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);e=G(["s"],[l.symlink],this.replybuffer,7);this.BuildReply(f,g,
|
|
643
|
+
e);this.SendReply(a);break;case 72:d=I(["w","s","w","w"],b,c);e=d[0];h=d[1];c=d[2];m=d[3];b=this.fs.CreateDirectory(h,this.fids[e].inodeid);l=this.fs.GetInode(b);l.mode=c|16384;l.uid=this.fids[e].uid;l.gid=m;G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 14:d=I(["w","s","w","w","w"],b,c);e=d[0];h=d[1];b=d[2];c=d[3];m=d[4];this.bus.send("9p-create",[h,this.fids[e].inodeid]);b=this.fs.CreateFile(h,this.fids[e].inodeid);this.fids[e].inodeid=b;this.fids[e].type=
|
|
644
|
+
1;this.fids[e].dbg_name=h;l=this.fs.GetInode(b);l.uid=this.fids[e].uid;l.gid=m;l.mode=c|32768;G(["Q","w"],[l.qid,this.msize-24],this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a);break;case 52:d=I("wbwddws".split(""),b,c);e=d[0];b=d[2];h=0===d[4]?Infinity:d[4];d=this.fs.DescribeLock(d[1],d[3],h,d[5],d[6]);h=this.fs.Lock(this.fids[e].inodeid,d,b);G(["b"],[h],this.replybuffer,7);this.BuildReply(f,g,1);this.SendReply(a);break;case 54:d=I("wbddws".split(""),b,c);e=d[0];h=0===d[3]?Infinity:
|
|
645
|
+
d[3];d=this.fs.DescribeLock(d[1],d[2],h,d[4],d[5]);h=this.fs.GetLock(this.fids[e].inodeid,d);h||(h=d,h.type=2);e=G(["b","d","d","w","s"],[h.type,h.start,Infinity===h.length?0:h.length,h.proc_id,h.client_id],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 24:d=I(["w","d"],b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;d[3]=l.uid;d[4]=l.gid;d[5]=
|
|
646
|
+
l.nlinks;d[6]=l.major<<8|l.minor;d[7]=l.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(l.size/512+1);d[10]=l.atime;d[11]=0;d[12]=l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;G("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,g,153);this.SendReply(a);break;case 26:d=I("wwwwwddddd".split(""),b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);d[1]&1&&(l.mode=d[2]);d[1]&2&&(l.uid=d[3]);d[1]&4&&(l.gid=d[4]);d[1]&16&&(l.atime=Math.floor((new Date).getTime()/
|
|
647
|
+
1E3));d[1]&32&&(l.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(l.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(l.atime=d[6]);d[1]&256&&(l.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[e].inodeid,d[5]);this.BuildReply(f,g,0);this.SendReply(a);break;case 50:d=I(["w","d"],b,c);e=d[0];this.BuildReply(f,g,0);this.SendReply(a);break;case 40:case 116:d=I(["w","d","w"],b,c);e=d[0];h=d[1];m=d[2];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",
|
|
648
|
+
2);this.SendReply(a);break}if(2===this.fids[e].type)for(l.caps.length<h+m&&(m=l.caps.length-h),d=0;d<m;d++)this.replybuffer[11+d]=l.caps[h+d];else this.fs.OpenInode(this.fids[e].inodeid,void 0),d=this.fids[e].inodeid,m=Math.min(m,this.replybuffer.length-11),l.size<h+m?m=l.size-h:40===f&&(m=this.fs.RoundToDirentry(d,h+m)-h),h>l.size&&(m=0),this.bus.send("9p-read-start",[this.fids[e].dbg_name]),d=await this.fs.Read(d,h,m),this.bus.send("9p-read-end",[this.fids[e].dbg_name,m]),d&&this.replybuffer.set(d,
|
|
649
|
+
11);G(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4+m);this.SendReply(a);break;case 118:d=I(["w","d","w"],b,c);e=d[0];h=d[1];m=d[2];d=this.fids[e].dbg_name;if(2===this.fids[e].type){this.SendError(g,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[e].inodeid,h,m,b.subarray(c.offset));this.bus.send("9p-write-end",[d,m]);G(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4);this.SendReply(a);break;case 74:d=I(["w","s","w","s"],b,c);h=await this.fs.Rename(this.fids[d[0]].inodeid,
|
|
650
|
+
d[1],this.fids[d[2]].inodeid,d[3]);if(0>h){this.SendError(g,-2===h?"No such file or directory":-1===h?"Operation not permitted":-39===h?"Directory not empty":"Unknown error: "+-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 76:d=I(["w","s","w"],b,c);c=d[0];h=d[1];b=d[2];e=this.fs.Search(this.fids[c].inodeid,h);if(-1===e){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}h=this.fs.Unlink(this.fids[c].inodeid,h);if(0>h){this.SendError(g,-39===
|
|
651
|
+
h?"Directory not empty":-1===h?"Operation not permitted":"Unknown error: "+-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 100:e=I(["w","s"],b,c);this.msize!==e[0]&&(this.msize=e[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));e=G(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 104:d=I(["w","w","s","s","w"],b,c);e=d[0];h=d[4];qa("[attach]: fid="+e+" afid="+z(d[1])+" uname="+d[2]+" aname="+
|
|
652
|
+
d[3],4194304);this.fids[e]=this.Createfid(0,1,h,"");l=this.fs.GetInode(this.fids[e].inodeid);G(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=I(["h"],b,c);this.BuildReply(f,g,0);this.SendReply(a);break;case 110:d=I(["w","w","h"],b,c);e=d[0];m=d[1];n=d[2];if(0===n){this.fids[m]=this.Createfid(this.fids[e].inodeid,1,this.fids[e].uid,this.fids[e].dbg_name);G(["h"],[0],this.replybuffer,7);this.BuildReply(f,g,2);this.SendReply(a);
|
|
653
|
+
break}h=[];for(d=0;d<n;d++)h.push("s");c=I(h,b,c);b=this.fids[e].inodeid;h=9;var p=0;for(d=0;d<n;d++){b=this.fs.Search(b,c[d]);if(-1===b)break;h+=G(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,h);p++;this.fids[m]=this.Createfid(b,1,this.fids[e].uid,c[d])}G(["h"],[p],this.replybuffer,7);this.BuildReply(f,g,h-7);this.SendReply(a);break;case 120:d=I(["w"],b,c);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type=
|
|
654
|
+
-1);this.BuildReply(f,g,0);this.SendReply(a);break;case 32:d=I(["w","s","d","w"],b,c);e=d[0];h=d[1];b=d[3];this.fids[e].type=2;this.BuildReply(f,g,0);this.SendReply(a);break;case 30:d=I(["w","w","s"],b,c),e=d[0],h=d[2],this.SendError(g,"Setxattr not supported",95),this.SendReply(a)}};function Zc(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=bd(b,this.configspace_taglen,this.configspace_tagname,
|
|
655
|
+
async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);var e=I(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.handle_fn(d,f=>{var g=I(["w","b","h"],f,{offset:0})[2];const h=this.tag_bufchain.get(g);h?(h.set_next_blob(f),this.virtqueue.push_reply(h),this.virtqueue.flush_replies(),this.tag_bufchain.delete(g)):console.error("No bufchain found for tag: "+g)})});this.virtqueue=this.virtio.queues[0]}Zc.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;
|
|
656
|
+
a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};Zc.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.tag_bufchain=a[3]};Zc.prototype.reset=function(){this.virtio.reset()};function $c(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=
|
|
657
|
+
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=bd(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);const e=I(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.send(d)});this.virtqueue=this.virtio.queues[0]}$c.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;
|
|
658
|
+
a[2]=this.virtio;a[3]=this.tag_bufchain;return a};$c.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.tag_bufchain=a[3]};$c.prototype.reset=function(){this.virtio.reset()};$c.prototype.handle_message=function(a){a=new Uint8Array(a.data);const b=I(["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)):
|
|
659
|
+
console.error("Virtio9pProxy: No bufchain found for tag: "+b)};$c.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};$c.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};$c.prototype.handle_error=function(){};$c.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};$c.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=
|
|
660
|
+
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);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)}}};$c.prototype.send=function(a){this.socket&&
|
|
661
|
+
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())};$c.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;
|