DIRECTORY RefTab: FROM "LinkHash", RESInterpreter, PrincOps, PrincOpsUtils; RESIXfer: CEDAR PROGRAM IMPORTS LinkHash: RefTab, PrincOpsUtils, RI: RESInterpreter EXPORTS RESInterpreter = { OPEN PrincOps; Value: TYPE = RI.Value; DValue: TYPE = RI.DValue; Ptr1: TYPE = RI.Ptr1; Ptr2: TYPE = RI.Ptr2; LPtr1: TYPE = RI.LPtr1; LPtr2: TYPE = RI.LPtr2; Machine: TYPE = RI.Machine; Byte: TYPE = RI.Byte; Bytes: TYPE = RI.Bytes; Pair: TYPE = RI.Pair; FieldDescriptor: TYPE = PrincOps.FieldDescriptor; LCB: TYPE = RI.LCB; RestartInterpreter: PUBLIC SIGNAL [iFrame: FrameHandle] RETURNS [uFrame: FrameHandle] = CODE; FetchLink: PUBLIC PROC [m: Machine, lki: CARDINAL] RETURNS [ControlLink] = TRUSTED { codeLinks: BOOLEAN; RI.ReadAtAddress[m, LONG[m.g]]; codeLinks _ LOOPHOLE[m.g, GlobalFrameHandle].codelinks; IF codeLinks THEN { cp: LONG POINTER _ LOOPHOLE[m.cb - (lki+1)*SIZE[ControlLink]]; RETURN[LOOPHOLE[RI.Read[m, cp]]]} ELSE { cps: POINTER _ LOOPHOLE[m.g - (lki+1)*SIZE[ControlLink]]; RETURN[LOOPHOLE[RI.Read[m, LONG[cps]]]]} }; MakeProcDesc: PUBLIC PROC [m: Machine, gf: GlobalFrameHandle, entry: CARDINAL] RETURNS [ControlLink] = TRUSTED { gfi: GFTIndex; RI.ReadAtAddress[m, LONG[gf]]; gfi _ gf.gfi; RETURN [[procedure[gfi: gfi + entry / EPRange, ep: entry MOD EPRange, tag: TRUE]]]}; Xfer: PUBLIC PROC [m: Machine, dst, src: ControlLink, push: BOOL _ TRUE, free: BOOL _ FALSE] = TRUSTED { nlf: FrameHandle; nPc: CARDINAL; GF: GlobalFrameHandle; CB: FrameCodeBase; nDst: ControlLink _ dst; -- final destination GFTFrame: PROC [gfti: GFTItem] RETURNS [GlobalFrameHandle] = TRUSTED { gfti.epbias _ 0; RETURN [gfti.framePtr]}; ControlLinkType: PROC [link: ControlLink] RETURNS [ControlLinkTag] = TRUSTED { SELECT TRUE FROM link.proc => RETURN [procedure]; link.indirect => RETURN [indirect]; ENDCASE => RETURN [frame]}; CBRep: TYPE = MACHINE DEPENDENT RECORD [ lo(0:0..14): [0..77777B], out(0:15..15): BOOL, hi(1): CARDINAL]; WHILE ~nDst.proc AND nDst.indirect DO nDst _ LOOPHOLE[RI.Read[m, LOOPHOLE[LONG[nDst.link]]]]; ENDLOOP; SELECT ControlLinkType[nDst] FROM procedure => { evi: CARDINAL; ev: EntryVectorItem; gfti: GFTItem; IF ~m.interestingGfi[nDst.gfi] THEN { CallDirectly[m, nDst]; RETURN}; RI.ReadAtAddress[m, LONG[@GFT[nDst.gfi]]]; gfti _ GFT[nDst.gfi]; m.g _ LOOPHOLE[GF _ GFTFrame[gfti]]; IF GF = NIL THEN RI.UnboundProcTrap[m, dst]; RI.DoubleReadAtAddress[m, LONG[@GF.code]]; CB _ GF.code; IF LOOPHOLE[CB, CBRep].out THEN { LOOPHOLE[CB, CBRep].out _ FALSE; START LOOPHOLE[GF, PROGRAM]}; -- let the start code run in microcode m.cb _ LOOPHOLE[CB]; evi _ gfti.epbias * EPRange + nDst.ep; RI.DoubleReadAtAddress[m, @LOOPHOLE[CB, LCB].entry[evi]]; ev _ LOOPHOLE[CB, LCB].entry[evi]; nPc _ ev.initialpc * 2; IF nPc = 0 THEN RI.UnboundProcTrap[m, dst]; nlf _ RI.AllocFrame[ev.info.framesize]; RI.WriteAtAddress[m, LONG[@nlf.accesslink]]; nlf.accesslink _ GF; RI.WriteAtAddress[m, LONG[@nlf.returnlink]]; nlf.returnlink _ src; nlf.pc _ [nPc+1]; -- to make display lf get the right procedure }; frame => { IF nDst = LOOPHOLE[0] THEN RI.ControlTrap[m, src]; nlf _ LOOPHOLE[nDst]; RI.ReadAtAddress[m, LONG[@nlf.accesslink]]; m.g _ LOOPHOLE[GF _ nlf.accesslink]; RI.DoubleReadAtAddress[m, LONG[@GF.code]]; m.cb _ GF.code.longbase; RI.ReadAtAddress[m, LONG[@nlf.pc]]; nPc _ nlf.pc; IF nPc = 0 THEN RI.UnboundProcTrap[m, dst]; }; ENDCASE; IF push THEN { RI.Push[m, LOOPHOLE[dst]]; RI.Push[m, LOOPHOLE[src]]; m.sd _ m.sd - 2}; IF free THEN RI.FreeFrame[LOOPHOLE[m.l]]; m.l _ LOOPHOLE[nlf]; RI.SetPc[m, nPc]; }; LinkHashSize: CARDINAL _ 101; CallDirectly: PROC [m: Machine, proc: ControlLink] = TRUSTED { m.outCalls _ m.outCalls + 1; IF m.flushOnCall THEN RI.FlushAllCaches[m]; IF m.recordXferOut THEN { lc: LinkHash.Ref _ LOOPHOLE[m.xferData]; found: BOOLEAN; lCount: REF LONG CARDINAL; IF lc = NIL THEN { m.xferData _ lc _ LinkHash.Create[LinkHashSize]; found _ FALSE} ELSE [found, lCount] _ LinkHash.Fetch[lc, [link: proc]]; IF found THEN lCount^ _ lCount^ + 1 ELSE [] _ LinkHash.Store[lc, [link: proc], NEW [LONG CARDINAL _ 1]]; }; CallFromSimulatedStack[m, proc]; Xfer[m: m, dst: [frame[LOOPHOLE[m.l]]], src: NullLink, push: FALSE]; -- simulate return from called proc RETURN; }; CallFromSimulatedStack: PROC [m: Machine, proc: ControlLink] = TRUSTED { actualReturn: ControlLink _ PrincOpsUtils.GetReturnLink[]; LF: FrameHandle _ RI.FH[m.l]; PrincOpsUtils.SetReturnLink[[frame[LF]]]; -- to make signaller work DoDirectCall[m, proc ! UNWIND => { m.sd _ 0; -- after the unwind, stack should be empty LOOPHOLE[m.l, FrameHandle] _ SIGNAL RestartInterpreter[LOOPHOLE[actualReturn]]}]; PrincOpsUtils.SetReturnLink[actualReturn]; RETURN; }; DoDirectCall: PROC [m: Machine, proc: ControlLink] = TRUSTED { extrajunk: INT _ 0; -- to move state vector to reasonable place args, results: StateVector; args _ [ stk: NULL, instbyte: 0, stkptr: m.sd, data: lst[dest: proc, source: [frame[PrincOpsUtils.MyLocalFrame[ ]]]]]; FOR i: CARDINAL IN [0..MIN[m.sd+2, 14]) DO args.stk[i] _ m.stack[i]; ENDLOOP; TRANSFER WITH args; results _ STATE; -- could use same state vector once debugged FOR i: CARDINAL IN [0..MIN[results.stkptr+2, 14]) DO m.stack[i] _ results.stk[i]; ENDLOOP; m.sd _ results.stkptr; RETURN; }; LoadState: PUBLIC PROC [m: Machine, free: BOOL] = TRUSTED { alpha: CARDINAL _ RI.NextOpByte[m]; st: POINTER TO StateVector = LOOPHOLE[m.l + alpha]; FOR i: CARDINAL IN [0..MIN[st.stkptr+2, 14]) DO RI.ReadLocal[m, alpha+i]; m.stack[i] _ st.stk[i]; ENDLOOP; RI.ReadLocal[m, alpha+PrincOps.stackDepth]; m.sd _ st.stkptr; IF ~free THEN { RI.WriteAtAddress[m, LONG[@LOOPHOLE[m.l, FrameHandle].pc]]; LOOPHOLE[m.l, FrameHandle].pc _ [m.pc]}; RI.ReadLocal[m, alpha+PrincOps.stackDepth+1]; RI.ReadLocal[m, alpha+PrincOps.stackDepth+2]; Xfer[m: m, dst: st.dest, src: st.source, push: FALSE, free: free]}; }. RESIXfer.mesa Last Edited by: Sweet, March 5, 1985 8:52:56 am PST Types and Global Data copied pretty much from PrincOps document version3.0c don't bother to record references for Alloc since Dragon uses other scheme IF LOOPHOLE[CB, CBRep].out THEN CodeTrap[dst] ÊZ˜Jšœ ™ J™3J˜šÏk ˜ Jšœœ ˜J˜J˜ J˜J˜—šœ œœ5œ˜nJšœ ˜šœ™Jšœœ ˜Jšœœ Ïc˜Jšœœ ˜Jšœœ ˜Jšœœ ˜Jšœœ ˜J˜šœ œ˜J˜—Jšœœ ˜Jšœœ ˜Jšœœ ˜Jšœœ˜1šœœœ˜J˜—Jš œœœœœ˜]J˜—š Ïn œœœœœœ˜TJšœ œ˜Jšœœ˜Jšœ œ#˜7šœ œ˜Jš œœœ œœ˜>Jšœœœ˜!—šœ˜Jšœœœœ˜9Jšœœœ œ ˜(—J˜J˜—š Ÿ œœœ,œœœ˜pJ˜Jšœœ˜J˜ Jšœ3œœ˜T—˜J˜—šŸœœœ+œœœœœ˜hJšœ5™5J˜Jšœœ˜Jšœ˜Jšœ˜J˜-š ŸœœÐfkÏfœœ˜FJšœœ˜)—šŸœœœœ˜Nšœœ˜Jšœ œ ˜ Jšœœ ˜#Jšœœ ˜——š œœœ œœ˜(Jšœ)œ œ˜@—J˜šœ œ˜%Jš œœœ œœ˜7Jšœ˜—šœ˜!˜Jšœœ˜Jšœ˜J˜šœœ˜%J˜Jšœ˜—Jšœœœ ˜*Jšœœ ˜Jšœœœ˜$Jš œœœœœ˜,Jšœœœ˜*Jšœœ˜ šœœœ œ˜!Jšœœœ˜ Jšœœ œž&˜D—Jšœœœ˜J˜&Jšœœœœ˜9Jšœœœœ ˜"J˜Jšœ œœ˜+JšœJ™JJ˜'Jšœœ˜,Jšœœ˜Jšœœ˜,J˜Jšœž-˜?J˜—˜ Jšœœœœ˜2Jšœœ˜Jšœœ˜+Jšœœœ˜$Jšœœ ˜*Jšœœ˜Jšœ-™-Jšœœ ˜#Jšœ ˜ Jšœ œœ˜+J˜—Jšœ˜—šœœ˜Jšœ œ˜Jšœ œ˜Jšœ˜—Jšœœœ˜)Jšœœ˜Jšœ˜Jšœ˜J˜—Jšœœ˜šŸ œœ#œ˜>J˜Jšœœœ˜+šœœ˜Jšœœ ˜(Jšœœ˜Jšœœœœ˜šœœœ˜Jšœ0˜0Jšœœ˜—Jšœ4˜8Jšœœ˜#Jšœ'œœœ˜DJ˜—Jšœ ˜ Jšœœœž#˜hJšœ˜J˜J˜—šŸœœ#œ˜HJ˜:Jšœœ˜Jšœ#œž˜Cšœœ˜#Jšœ ž*˜4Jšœœœ˜Q—J˜*Jšœ˜J˜J˜—šŸ œœ#œ˜>Jšœ œž+˜?J˜šœ˜Jšœœ˜ Jšœ ˜ Jšœ˜JšœG˜G—š œœœœ˜*J˜Jšœ˜—Jšœœ˜Jšœ œž,˜=š œœœœ˜4Jšœ˜Jšœ˜—Jšœ˜Jšœ˜J˜J˜—š Ÿ œœœœœ˜;Jšœœ˜#Jšœœœœ˜3š œœœœ˜/Jšœ˜Jšœ˜Jšœ˜—Jšœ)˜+Jšœ˜šœœ˜Jšœœœ˜;Jšœ ˜(—Jšœ+˜-Jšœ+˜-Jšœ/œ˜CJ˜—J˜——…—´