anchor.diff:        endrule
         rule waiting if (reqState == Waiting);
   	 let done <- writeEngine.writeServers[0].response.get();
  -	 //$display("done waiting for write");
  +	 $display("done waiting for write");
   	 reqState <= Idle;
         endrule
   
  
positive.code:       Reg#(Bit#(32)) reqHeadReg <- mkReg(0);
        Reg#(Bit#(32)) reqTailReg <- mkReg(0);
        Reg#(Bit#(16)) wordCountReg <- mkReg(0);
        Reg#(Bit#(16)) demuxCountReg <- mkReg(0);
        Reg#(Bit#(16)) messageWordsReg <- mkReg(0);
        Reg#(Bit#(16)) methodIdReg <- mkReg(0);
        Reg#(SharedMemoryPortalState) reqState <- mkReg(Idle);
  
        rule updateReqHeadTail if (reqState == Idle && readyReg);
  	 //$display("updateReqHeadTail");
  	 readEngine.readServers[0].request.put(MemengineCmd { sglId: sglIdReg,
  							     base: 0,
  							     burstLen: 16,
  
negative.code: 	    wordCount = reqLimitReg - reqTailReg;
  	    tail = 4;
  	 end
  	 if (verbose) $display("requestMessage id=%d tail=%h head=%h wordCount=%d", sglIdReg, reqTailReg, reqHeadReg, wordCount);
  
  	 reqTailReg <= tail;
  	 wordCountReg <= truncate(wordCount);
  	 readEngine.readServers[0].request.put(MemengineCmd {sglId: sglIdReg,
  							     base: extend(reqTailReg << 2),
  							     burstLen: 16,
  							     len: wordCount << 2
  							     });
  	 reqState <= MessageHeaderRequested;
        endrule
  
        MIFO#(4,1,4,Bit#(32)) readMifo <- mkMIFO();
        rule demuxwords if (readMifo.enqReady());
  	 let data <- toGet(readEngine.dataPipes[0]).get();
  	 Vector#(2,Bit#(32)) dvec = unpack(data);
  	 let enqCount = 2;
  	 Vector#(4,Bit#(32)) dvec4;
  	 dvec4[0] = dvec[0];
  	 dvec4[1] = dvec[1];
  	 dvec4[2] = 0;
  	 dvec4[3] = 0;
  	 readMifo.enq(enqCount, dvec4);
        endrule
  
        rule receiveMessageHeader if (reqState == MessageHeaderRequested);
  	 let vec <- toGet(readMifo).get();
  	 let hdr = vec[0];
  	 let methodId = hdr[31:16];
  	 let messageWords = hdr[15:0];
  	 methodIdReg <= methodId;
  	 if (verbose)
  	    $display("receiveMessageHeader hdr=%x methodId=%x messageWords=%d wordCount=%d", hdr, methodId, messageWords, wordCountReg);
  	 wordCountReg <= wordCountReg - 1;
  	 messageWordsReg <= messageWords - 1;
  	 if (wordCountReg <= messageWords)
  	    reqState <= UpdateTail;
  	 else if (messageWords == 1)
  	    reqState <= MessageHeaderRequested;
  	 else
  	    reqState <= MessageRequested;
        endrule
  
        //GearBox(Bit#(64),Bit#(32)) gb <- mkNto1Gearbox(defaultClock,defaultReset,defaultClock,defaultReset);
        rule receiveMessage if (reqState == MessageRequested);
  	 let vec <- toGet(readMifo).get();
  	 let data = vec[0];
  	 $display("receiveMessage data=%x messageWords=%d wordCount=%d", data, messageWordsReg, wordCountReg);
  	 if (methodIdReg != 16'hFFFF)
  	    portal.requests[methodIdReg].enq(data);
  
  	 messageWordsReg <= messageWordsReg - 1;
  	 wordCountReg <= wordCountReg - 1;
  	 if (messageWordsReg == 1)
  	    reqState <= MessageHeaderRequested;
  	 else if (wordCountReg <= 1)
  	    reqState <= UpdateTail;
        endrule
  
        rule updateTail if (reqState == UpdateTail);
  	 $display("updateTail: tail=%d", reqTailReg);
  	 // update the tail pointer
  	 writeEngine.writeServers[0].request.put(MemengineCmd {sglId: sglIdReg,
  							       base: 8,
  