// Explicit synthetic host fixture, never physical guest evidence. import {nativeHostFixture} from './k2150-storage-host-fixture.mjs'; import {expectedCalls} from './k2150-el0-storage-check.mjs'; const set=(b,i,v)=>b.writeBigUInt64LE(BigInt(v),i*8); export function shutdownHostFixture(caseId){ const input=nativeHostFixture(caseId),flushCount=caseId===1?3:6; const copy=s=>({...s,bytes:Buffer.from(s.bytes),dmaPages:s.dmaPages.map(p=>({...p,bytes:Buffer.from(p.bytes)}))}); const worker=copy(input.stages[0]);worker.stage=200;set(worker.bytes,1,200); const complete=copy(input.stages.find(s=>s.stage===2));complete.stage=201;set(complete.bytes,1,201);set(complete.bytes,12,flushCount);set(complete.bytes,13,0); for(let i=32+flushCount*16;i<256;i++)set(complete.bytes,i,0); complete.dmaPages=copy(input.stages.find(s=>s.stage===100+flushCount)).dmaPages; input.stages.splice(1,0,worker); input.stages.splice(input.stages.findIndex(s=>s.stage===100+flushCount)+1,0,complete); for(const s of input.stages){ const initial=s.stage===1,worker=s.stage===200,pending=s.stage>=101&&s.stage<=100+flushCount; const total=initial?0:worker?5:pending?7:13,b=Buffer.alloc(2048);s.el0=b; for(const [i,value] of [[0,0x4b32313530454c30n],[1,s.stage],[2,caseId],[3,996],[4,initial?0:996],[5,total===13?996:0], [6,initial?0:0x2159],[7,initial?0:5],[9,total===13?0x2150:0],[10,total===13?8:0],[12,total===13?1:0], [13,total===13&&caseId===0?1:0],[14,total===13?(caseId===0?0:caseId===1?5:110):0],[15,total===13?flushCount:0], [16,total],[17,total>=5?0x42000000:0],[18,total>=7?0x42010000:0],[19,total>=5?0x42001000:0],[20,total>=7?0x42011000:0], [22,initial?0:2],[23,total===13?2:0],[24,initial?0:2],[25,total>=7?1:0],[26,total===13?1:0],[27,total===13?1:0], [28,total===13&&caseId!==0?1:0],[29,total===13&&caseId===0?1:0],[31,total===13?flushCount:0]])set(b,i,value); expectedCalls(caseId).slice(0,total).forEach(([pid,number,arg0,result],n)=>{ [pid,0x21500000+pid,number,arg0,0,0,pending&&n===6?0:result,number===1?1:0, 0x80000004,0x80003ff0,0x3c0,0x56000000,8,n+1,0,0].forEach((v,i)=>set(b,32+n*16+i,v)); }); } input.el0Final=Buffer.from(input.stages.at(-1).el0); const program=Buffer.alloc(4);program.writeUInt32LE(0xd4000001); input.programs={1:Buffer.from(program),9:Buffer.from(program)}; input.serial=input.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-EL0-STORAGE: WORKER_EXIT=0x0000000000002159 PID1_EXIT=0x0000000000002150 CALLS=0x000000000000000d CLEAN=0x'+(caseId===0?'0000000000000001':'0000000000000000')+'\nTURKOS/OS/K2150: PASS\nTURKOS/OS/K640: PASS\n'; return input; }