<> <> <> <> DIRECTORY EtherTesterOps, NewEthernetFace USING [controlBlockSize], VM USING [AddressForPageNumber, Interval, lowCore, PagesForWords, SimpleAllocate, SwapIn]; EtherTesterStorageImpl: PROGRAM IMPORTS NewEthernetFace, VM EXPORTS EtherTesterOps = BEGIN <> <<>> BufferObj: TYPE = REF BufferType; BufferType: TYPE = RECORD[ next: BufferObj _ NIL, size: CARDINAL, available: BOOL _ FALSE, buffer: LONG POINTER ]; bufferChain: BufferObj; AllocateOneBuffer: PUBLIC PROC[size: CARDINAL] RETURNS [b: LONG POINTER] = { this: BufferObj _ NIL; interval: VM.Interval; Clear: PROC = { p: LONG POINTER _ this.buffer; THROUGH [0..size) DO p^ _ 0; p _ p + 1; ENDLOOP; this.available _ FALSE; }; FOR this _ bufferChain, this.next UNTIL this = NIL DO IF this.size >= size AND this.available THEN { Clear[]; RETURN[this.buffer] }; ENDLOOP; <<>> <> this _ NEW[BufferType _ [size: size, buffer: NIL] ]; interval _ VM.SimpleAllocate[VM.PagesForWords[size]]; VM.SwapIn[interval: interval, kill: TRUE, pin: TRUE]; this.buffer _ VM.AddressForPageNumber[interval.page]; Clear[]; IF bufferChain = NIL THEN bufferChain _ this ELSE { prev: BufferObj _ NIL; FOR now: BufferObj _ bufferChain, now.next UNTIL now = NIL DO IF now.size >= size THEN { -- insert this before now IF prev = NIL THEN bufferChain _ this ELSE prev.next _ this; this.next _ now; RETURN[this.buffer]; }; prev _ now; ENDLOOP; prev.next _ this; -- largest so far }; RETURN[this.buffer]; }; FreeOneBuffer: PUBLIC PROC[b: LONG POINTER] = { FOR this: BufferObj _ bufferChain, this.next UNTIL this = NIL DO IF this.buffer = b THEN { this.available _ TRUE; RETURN }; ENDLOOP; }; <> IocbType: TYPE = RECORD[ next: LONG POINTER TO IocbType, rest: SEQUENCE COMPUTED CARDINAL OF WORD ]; iocbChain: LONG POINTER TO IocbType _ NIL; AllocateOneIOCB: PUBLIC PROC RETURNS [iocb: LONG POINTER] = { IF iocbChain # NIL THEN { iocb _ iocbChain; iocbChain _ iocbChain.next} ELSE iocb _ VM.lowCore.NEW[IocbType[NewEthernetFace.controlBlockSize]]; }; FreeOneIOCB: PUBLIC PROC[iocbPtr: LONG POINTER] = { i: LONG POINTER TO IocbType = LOOPHOLE[iocbPtr]; i.next_ iocbChain; iocbChain_ i; }; END.