// One synthetic image state used by all four subproofs, never guest evidence. import {fill} from './native_worker_fixture.mjs'; import {fixture as irqFixture,bindings} from './native_irq_transition_fixture.mjs'; import {pages,words} from './native_fixture.mjs'; import {dmaPacket} from '../../scripts/os-acceptance/dma-network.mjs'; const W=b=>Array.from({length:b.length/8},(_,i)=>b.readBigUInt64LE(i*8)); const packet=(id,q)=>dmaPacket((BigInt('0x'+id)^0x4b32313535444d41n).toString(16).padStart(16,'0'),q); function desc(b,at,address,length,flags,next){b.writeBigUInt64LE(address,at);b.writeUInt32LE(length,at+8);b.writeUInt16LE(flags,at+12);b.writeUInt16LE(next,at+14);} export function nativeFixture(first=100,tco=0n){ const input=fill(first),irq=irqFixture(first,tco),sector=Buffer.alloc(512,0x55),baseline={sent:1,received:2},fresh=new Set([1,2,300,301,302,10,20,30,40,50,230,60]); const exchange={afterCapturedStage:30,tx:packet(input.bootId,1).toString('hex'),rx:packet(input.bootId,0).toString('hex'),sentCount:2,receivedCount:3}; let lastRows,resetRows;const epoch=BigInt('0x'+input.bootId),deadline=2880000015n; for(const[index,s]of input.snapshots.entries()){ const stage=Number(s.OS_K2155_EVIDENCE.readBigUInt64LE(8)); for(const[k,b]of Object.entries(irq.snapshots[index]))if(k.startsWith('OS_K2155_IRQ_')||k.startsWith('irq-')||k.startsWith('gic-'))s[k]=Buffer.from(b); if(index>=4&&index<8)s.OS_K2155_CPU_STATE.writeBigUInt64LE(irq.snapshots[index].OS_K2155_CPU_STATE.readBigUInt64LE(24),24); if(stage===0){s.OS_K2155_DMA_DEVICES=Buffer.alloc(1024);s.OS_K2155_NATIVE_STATE=Buffer.alloc(256);continue;} const reset=index>=21,released=index>=23,closed=index>=15,drained=index>=20,phase=index<8?0:index<15?1:index===15?2:index<=18?3:index===19?4:index===20?5:index<=22?6:7; const state=[0x4b323135354e4154n,phase,phase<2?0:phase*10+index,0xa003e00,epoch,1,0x21550001,22,phase>=2?1:0,phase>=3?1:0,0,phase>=4?0:2,phase===0||phase>=5?0:1,phase>=6?0:15,phase>=6?0:3,phase>=7?0:22,phase>=7?52:30,30,phase>=7?1:0,phase>=7?1:0,index>=15?deadline:0]; while(state.length<32)state.push(0);s.OS_K2155_NATIVE_STATE=words(state); const rows=Array(128).fill(0n); for(let d=0;d<2;d++){ const row=Array(64).fill(0n),count=d===0?1:2,base=d===0?0xa003e00:0xa003c00,id=d===0?2:1; let interrupt=reset?0:index===1?0:index===2?d===0?1:0:index===3?1:index>=8&&index<=19?0:index===20?d===0?0:1:irq.snapshots[index]['mmio-'+d+'-interrupt'].readUInt32LE(0); row.splice(0,12,...[base,epoch,id,0x554d4551,reset?0:15,reset?0:1,reset||d===0?0:1,interrupt,closed?1:0,drained?1:0,released?1:0,d===0||stage===230?0:1].map(BigInt)); for(const[name,value]of [['magic',0x74726976],['version',2],['device',id],['vendor',0x554d4551],['status',reset?0:15],['ready',reset?0:1],['interrupt',interrupt]]){const b=Buffer.alloc(4);b.writeUInt32LE(value);s['mmio-'+d+'-'+name]=b;} for(let q=0;q=2:index>=3,pending=d===1&&q===0&&!drained,raw=Array.from({length:4},()=>Buffer.alloc(4096)); row.splice(12+q*20,4,...frames); if(submitted){const length=pending?0:d===0?513:q===0?72:0;row.splice(16+q*20,6,...[1,1,pending?0:1,0,length,0].map(BigInt));} if(submitted&&!released){ const[de,av,us,bu]=raw;av.writeUInt16LE(1,2);us.writeUInt16LE(pending?0:1,2);us.writeUInt32LE(pending?0:d===0?513:q===0?72:0,8); if(d===0){desc(de,0,frames[3],16,1,1);desc(de,16,frames[3]+512n,512,3,2);desc(de,32,frames[3]+16n,1,2,0);bu.writeBigUInt64LE(111n,8);sector.copy(bu,512);} else{desc(de,0,frames[3],q===0?2048:72,q===0?2:0,0);if(!pending)packet(input.bootId,q).copy(bu,12);bu[2048]=0xa5;} } if(released)row.splice(12+q*20,20,...resetRows.slice(d*64+12+q*20,d*64+32+q*20)); for(let p=0;p<4;p++)s[`dma-${d}-${q}-${p}`]=raw[p]; } rows.splice(d*64,64,...row); } if(fresh.has(stage))lastRows=words(rows);s.OS_K2155_DMA_DEVICES=Buffer.from(lastRows);if(stage===50)resetRows=rows; } return {...input,compiled:{...input.compiled,...irq.compiled},symbols:{...input.symbols,...irq.symbols},bindings,sector,baseline,exchange}; }