MDDumpImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Willie-Sue, May 7, 1986 4:33:45 pm PDT
taken from mdDump.bcpl
DIRECTORY
Basics USING [BITAND, BITNOT, BITOR, BITSHIFT],
IO,
List USING [CompareProc, LORA, Sort],
Rope,
MDDefs,
MDFields,
MDGlobalVars,
MDOps,
MDUtils USING [IMPtr, PutWord, SearchSymbolTable, SearchTableProc, WriteSymbolName];
MDDumpImpl: CEDAR PROGRAM
IMPORTS
Basics, IO, List, Rope,
MDGlobalVars, MDOps, MDUtils
EXPORTS
MDOps, MDUtils
= BEGIN OPEN Basics, MDDefs, MDFields, MDGlobalVars, MDUtils;
used for dumping 1 or 2 word memories
DumpMemProc: TYPE = PROC[addr: CARDINAL]
RETURNS[num: CARDINAL, w0, w1: WORD];  -- num = 0 => not used
DumpImage: PUBLIC PROC[outFile: OutputFile] = TRUSTED {
strm: IO.STREAM = outFile.strm;
MDOps.Report[infoOnly, "Writing .MB file...\n"];
PutWord[strm, MBaddress]; PutWord[strm, IMmemx]; PutWord[strm, 0];
FOR i: CARDINAL IN [0..nInstructions) DO
imPtr: IMRecordPtr = MDUtils.IMPtr[i];
awd: WORDLOOPHOLE[imPtr.wx0.W0Addr];
dti: LONG POINTER TO Dti ← LOOPHOLE[imPtr];
w0: WORD = LOOPHOLE[dti.dti0];
w1: WORD = LOOPHOLE[dti.dti1];
w2: WORD = LOOPHOLE[dti.dti2];
IF imPtr.wx0.brkPAndIFUE = 1 THEN awd ← BITOR[awd, 140000B];
IF imPtr.wx2.emulator = 1 THEN awd ← BITOR[awd, 10000B];
PutWord[strm, MBdata]; PutWord[strm, 0];  -- block info
PutWord[strm, w0];
PutWord[strm, w1];
PutWord[strm, w2];
PutWord[strm, awd];
ENDLOOP;
strm.Flush[];
DumpXRefs[strm];  -- shouldn't have, won't do them now
DumpMem[strm, RMmemx, RMsize, DumpRM];
DumpMem[strm, IFUMmemx, IFUMsize, DumpIFUM];
DumpMem[strm, ALUFMmemx, ALUFMsize, DumpALUFM];
strm.Flush[];
};
DumpXRefs: PROC[strm: STREAM] = {
};
DumpSyms: PUBLIC PROC[outFile: OutputFile] = {
strm: STREAM ← outFile.strm;
symList: LIST OF Symbol ← NIL;
SymbolCompareProc: List.CompareProc = {
s1: Symbol = NARROW[ref1];
s2: Symbol = NARROW[ref2];
RETURN[Rope.Compare[s1.name, s2.name, FALSE]];
};
GetSyms: MDUtils.SearchTableProc = {
symList ← CONS[sym, symList];
RETURN[FALSE];
};
MDUtils.SearchSymbolTable[GetSyms];
TRUSTED
{ symList ← LOOPHOLE[List.Sort[LOOPHOLE[symList, List.LORA], SymbolCompareProc]] };
FOR sL: LIST OF Symbol ← symList, sL.rest UNTIL sL = NIL DO
sym: Symbol = sL.first;
PutWord[strm, MBsymbol];
PutWord[strm, sym.memNum];
PutWord[strm, sym.labelAddr];
WriteSymbolName[strm, sym.name];
ENDLOOP;
};
PutEndMarker: PUBLIC PROC[outFile: OutputFile] = {
PutWord[outFile.strm, MBend];
};
DumpRM: DumpMemProc = TRUSTED {
IF ~rmBits[addr] THEN RETURN[0, 0, 0];
RETURN[1, (rmArrayHead+addr)^, 0];
};
DumpIFUM: DumpMemProc = TRUSTED {
tifum: LONG POINTER TO Tifum;
imp: IFUMRecordPtr;
iAddr: CARDINAL;
IF ~ifumBits[addr] THEN RETURN[0, 0, 0];
imp ← IFUMPtr[addr];
iAddr ← imp.ifumWord0.ifad;
tifum ← LOOPHOLE[imp];
tifum.tifum0.pa ← imp.ifumWord0.pa;
IF iAddr # 7777B THEN {
ifa: WORD = MDUtils.IMPtr[iAddr].wx0.W0Addr;
nifa: WORD = BITNOT[BITSHIFT[ifa, -2]];
tifum.tifum0.notIFADr2 ← BITAND[nifa, 1777B];
};
RETURN[2, LOOPHOLE[tifum.tifum0], LOOPHOLE[tifum.tifum1] ];
};
DumpALUFM: DumpMemProc = TRUSTED {
IF ~alufmBits[addr] THEN RETURN[0, 0, 0];
RETURN[1, (alufmArrayHead+addr)^, 0]
};
DumpMem: PROC[strm: STREAM, memx, memSize: CARDINAL, proc: DumpMemProc] = {
addr: CARDINAL ← 177777B;
FOR i: CARDINAL IN [0..memSize) DO
num: CARDINAL;
w0, w1: WORD;
[num, w0, w1] ← proc[i];
IF num = 0 THEN LOOP;
IF i # addr THEN {
PutWord[strm, MBaddress];
PutWord[strm, memx];
PutWord[strm, i];
};
PutWord[strm, MBdata];
PutWord[strm, 0];
PutWord[strm, w0];
IF num = 2 THEN PutWord[strm, w1];
addr ← i + 1;
ENDLOOP;
};
IFUMPtr: PUBLIC PROC[addr: CARDINAL] RETURNS[IFUMRecordPtr] = TRUSTED
{ RETURN[LOOPHOLE[ifumArrayHead+addr*SIZE[IFUMRecord]]] };
END.