// Synthetic host bytes only. These must never be recorded as guest execution. const set=(b,i,n)=>b.writeBigUInt64LE(BigInt(n),i*8); const pattern=lba=>({112:0xd1,113:0xa2,120:0xb3})[lba]; export function nativeHostFixture(caseId){ const frames=[0x41000000,0x41001000,0x41002000,0x41003000],words=Buffer.alloc(2048); const pages=frames.map(address=>({address,bytes:Buffer.alloc(4096)})),stages=[]; const count=caseId===0?9:caseId===1?3:6,ops=[[1,112],[4,0],[1,113],[4,0],[1,120],[4,0],[0,112],[0,113],[0,120]]; for(const [i,value] of [[0,0x4b32313530494f32n],[2,caseId],[3,1000],[4,996],[15,2048],[16,0xa003e00],[22,1000],[27,1]])set(words,i,value); frames.forEach((f,i)=>set(words,17+i,f)); const capture=stage=>{set(words,1,stage);stages.push({stage,bytes:Buffer.from(words),dmaPages:stage===3?[]:pages.map(p=>({...p,bytes:Buffer.from(p.bytes)}))});}; const progress=()=>[caseId===1?1:3,caseId===0?3:caseId===1?1:2,caseId===0?1:0,caseId===0?0:caseId===1?5:110,caseId===1?2:3,caseId===0?3:caseId===1?1:2].forEach((v,i)=>set(words,6+i,v)); capture(1); for(let seq=1;seq<=count;seq++){ const [op,lba]=ops[seq-1],timeout=caseId===2&&seq===6,eio=caseId===1&&seq===3; const usedIndex=timeout?seq-1:seq,len=timeout?0:op===0?513:1,status=timeout?255:eio?1:0; if(seq>=7){progress();set(words,13,seq-7);} set(words,12,seq); [seq,op,lba,usedIndex,0,len,status,op,lba,seq*100,seq*100+2000,seq*100+(timeout?2001:1),timeout?110:eio?5:0,op===4?2:3,0,2048].forEach((v,i)=>set(words,32+(seq-1)*16+i,v)); const entries=op===4?[[frames[3],16,1,1],[frames[3]+16,1,2,0]]:[[frames[3],16,1,1],[frames[3]+512,512,op===0?3:1,2],[frames[3]+16,1,2,0]]; const [desc,avail,used,request]=pages.map(p=>p.bytes); entries.forEach(([address,size,flags,next],i)=>{desc.writeBigUInt64LE(BigInt(address),i*16);desc.writeUInt32LE(size,i*16+8);desc.writeUInt16LE(flags,i*16+12);desc.writeUInt16LE(next,i*16+14);}); avail.writeUInt16LE(seq,2);used.writeUInt16LE(usedIndex,2);used.writeUInt32LE(len,8+(seq-1)%8*8); request.writeUInt32LE(op,0);request.writeBigUInt64LE(BigInt(lba),8);request[16]=status; request.fill(pattern(op===4?ops[seq-2][1]:lba),512,1024);capture(100+seq); } progress();set(words,13,caseId===0?3:0);capture(2); for(const [i,n] of [[5,1000],[14,1],[23,caseId!==0?1:0],[24,1]])set(words,i,n);capture(3); const before=Buffer.alloc(1024*1024,0x5a),after=Buffer.from(before); for(const lba of caseId===1?[112]:[112,113,120])after.fill(pattern(lba),lba*512,(lba+1)*512); const serial=stages.map(s=>'TURKOS/OS/K2150: CAPTURE STAGE=0x'+s.stage.toString(16).padStart(16,'0')).join('\n')+ '\nTURKOS/OS/K2150-NATIVE-FLUSH:\nTURKOS/OS/K2150: PASS\nTURKOS/OS/K640: PASS\n'; return {caseId,stages,final:Buffer.from(words),serial,before,after}; }