GenLisp.mesa
Copyright © 1985, 1986, 1987 by Xerox Corporation. All rights reserved.
Edward Fiala February 7, 1986 5:13:45 pm PST
Curry, September 11, 1986 11:34:35 pm PDT
Curry, September 11, 1986 2:15:07 pm PDT RETK => RET, const1 => const7, const3 => const8, LC3 => LC8
Fiala November 5, 1986 3:58:37 pm PST Fix ALS at entry to IllegalLispNum trap.
Fiala March 23, 1987 4:56:04 pm PST Eliminate Reset, Halt, and Pause stuff
to run with GenDebugger.
Fiala April 9, 1987 2:15:25 pm PST Change LC8 to LC5 for chip debugging (const8-11 don't work on chip).
Load with "quad -cx GenDebugger GenLisp". This diagnostic tests the arithmetic opcodes RLADD, RLSUB, LADD, LSUB, QLADD, and QLSUB. When correctly executed it terminates with a HALT[177777b] at PC = 4042647B on instruction 582 cycle 1112.
DIRECTORY
DragOpsCross USING [XopBase, TrapBase, TrapWidthBytes, bytesPerWord, TrapIndex, Word],
--Word, wordsPerPage, bytesPerWord, charsPerWord, bitsPerByte, bitsPerCharacter, bitsPerWord, bytesPerPage, logWordsPerPage, logBitsPerByte, logBitsPerChar, logBytesPerWord, logCharsPerWord, logBitsPerWord, logBytesPerPage, PageCount, PageNumber, maxPagesInVM, SixBitIndex, FiveBitIndex, TwoWords, FourBitIndex, Half, ThreeBitIndex, FourHalves, TwoHalves, Byte, ZerosByte, OnesByte, EightBytes, FourBytes, ByteIndex, BytesPerWord, TwoBytes, Comparison, ByteAddress, WordAddress, FieldDescriptor, RegIndex, PadByte, Lit8, Op4, Op8, JDist8, Inst, OIFormat, OQBformat, LRformat, QRformat, ShortRegQR, OBformat, LRBformat, RRformat, ODBformat, LRRBformat, RJBformat, ShortRegRJB, JBBformat, TrapWidthWords, TrapWidthBytes, XopBase, TrapBase, KernalLimit, TrapIndex, StackUnderflowTrap, IFUPageFaultTrap, ResetTrap, IFUStackOverflowTrap, EUStackOverflowTrap, RescheduleTrap, ALUCondFalse, ALUCondEZ, ALUCondLZ, ALUCondLE, ALUCondSpare, ALUCondNE, ALUCondGE, ALUCondGZ, ALUCondOver, ALUCondBC, ALUCondIL, ALUCondDO, ALUCondNotOver, ALUCondNB, ALUCondNI, ModeFault, MemAccessFault, IOAccessFault, EUPageFault, EUWriteFault, AUFault, euStack, euJunk, euToKBus, euMAR, euField, euConstant, euAux, euBogus, euLast, ifuYoungestL, ifuYoungestPC, ifuEldestL, ifuEldestPC, ifuSLimit, ifuBogus, ifuL, ifuS, ifuPC, ifuLast, EURegs, EULegalRegs, IFURegs, IFULegalRegs, StackedStatusWord, IFUStackIndex, IFUStackSize, IFUOverflow, EUStackIndex, EUStackSize, EULocalIndex, EULocals, EUAuxIndex, EUAuxRegs, EUConstIndex, EUConstants, IOLocation, ioRescheduleRequest, ioResetRequest, IOOperand, PCmdFormat, PCmdByteSelect, PCmdClass, PCmdSpace, PCmdDirection
DragOpsCrossUtils USING [IntToWord],
--InstToBytes, InstToFormat, BytePCToWordAddress, WordAddressToBytePC, IOOperandToCard, CardToIOOperand, FieldDescriptorToCard, CardToFieldDescriptor, BytesToWord, BytesToHalf, WordToBytes, HalfToBytes, HalvesToWord, WordToHalves, HighHalf, LowHalf, LeftHalf, RightHalf, SwapHalves, WordToInt, IntToWord, WordToCard, HalfToCard, ByteToCard, CardToWord, CardToHalf, CardToByte, DragAnd, DragOr, DragXor, DragNot, VanillaAdd, VanillaSub, AddDelta, HalfNot, HalfAnd, HalfOr, HalfXor, HalfShift, DoubleWordShiftLeft, SingleWordShiftLeft, SingleWordShiftRight, XopToBytePC, TrapIndexToBytePC, FieldUnit
HandCoding, --Has opcode and register defs.
HandCodingPseudos, --Label, SetLabel, GenLabel, GenLabelHere, UseLabel8A, UseLabel8B, UseLabel16, UseLabel32, LReg, PReg, SReg, AddReg, SubReg, SetRegConst, MoveReg, MoveRegI, LRegI, IndexedJump, ProcedureEntry, ProcedureExit, SetupField, ExtractField, ShiftLeft, LoadProcessorReg, StoreProcessorReg, CauseReschedule, CauseReset, GetSPLimit, SetSPLimit, GetYoungestPC, GetYoungestStatus, GetEldestPC, GetEldestStatus, SetYoungestPC, SetYoungestStatus, SetEldestPC, SetEldestStatus, Pause, Halt
HandCodingSupport; --Area, GetProc, PutProc, ProcList, NewArea, GenWithArea, Gen1WithArea, ForceOut, GetCurrentArea, LoadArea, GetOutputPC, SetOutputPC, WordAlign, ReserveData, OutputByte, OutputOneByte, OutputAlphaBeta, OutputAlphaBetaGammaDelta, OutputWord
GenLisp: CEDAR PROGRAM
IMPORTS DragOpsCrossUtils, HandCoding, HandCodingPseudos, HandCodingSupport
= BEGIN OPEN DragOpsCrossUtils, HandCoding, HandCodingPseudos, HandCodingSupport;
Word: TYPE = DragOpsCross.Word;
In this diagnostic, the auxiliary registers are called aux0, aux1, ..., aux15; the locals are called reg0, reg1, ..., reg15; and the constants are called const0, const1, ..., const15.
aux0: AuxRegSpec = [aux[0]];
aux1: AuxRegSpec = [aux[1]];
aux2: AuxRegSpec = [aux[2]];
aux3: AuxRegSpec = [aux[3]];
aux4: AuxRegSpec = [aux[4]];
aux5: AuxRegSpec = [aux[5]];
aux6: AuxRegSpec = [aux[6]];
aux14: AuxRegSpec = [aux[14]];
aux15: AuxRegSpec = [aux[15]];
const4: ConstSpec = [const[4]];
const5: ConstSpec = [const[5]];
const6: ConstSpec = [const[6]];
const7: ConstSpec = [const[7]];
const8: ConstSpec = [const[8]];
const9: ConstSpec = [const[9]];
const10: ConstSpec = [const[10]];
const11: ConstSpec = [const[11]];
LMaxNum: INT = 3777777777B;
LMinNum: INT = -4000000000B;
All: PROC = {
The Xop trap locations assigned to each opcode are at at opcode*TrapWidthBytes + xopBase*bytesPerWord = 4,000,000B + 20B * opcode, and the trap location assigned to each trap are at TrapIndex*TrapWidthBytes + TrapBase*bytesPerWord = 4,002,000B + 20B * TrapIndex. The TrapIndex definitions are in DragOpsCross.
FillXop: PROC [inst: CARDINAL, dest: Label] = {
SetOutputPC[inst * DragOpsCross.TrapWidthBytes + DragOpsCross.XopBase * DragOpsCross.bytesPerWord];
drJDB[UseLabel16[dest]];
};
FillTrap: PROC [tx: DragOpsCross.TrapIndex, dest: Label] = {
SetOutputPC[LOOPHOLE[tx, CARDINAL] * DragOpsCross.TrapWidthBytes + DragOpsCross.TrapBase * DragOpsCross.bytesPerWord];
drJDB[UseLabel16[dest]];
};
area: Area = GetCurrentArea[];
savePC: LONG CARDINAL;
IllegalLispNum: Label = GenLabel[];
LNaNUnexpected: Label = GenLabel[];
enterRLADDTest: Label = GenLabel[];
enterRLSUBTest: Label = GenLabel[];
Lisp arithmetic: The Carry is not used as an input, and is always set to 0. If either operand or the result is not in the range [LMinNum..LMaxNum], a Lisp NaN (Not a Number) trap is taken.
This procedure generates tests RLADD, QLADD, and LADD.
GenRLADD: PROC = {
RLADDTest: PROC [a, b: INT] ~ {
ax: Word ← IntToWord[a];
bx: Word ← IntToWord[b];
apb: INT ← a + b;
IF a > LMaxNum OR a < LMinNum OR b > LMaxNum OR b < LMinNum OR apb > LMaxNum OR apb < LMinNum THEN {
A Lisp NaN trap will abort the RLADD, and the trap subroutine will skip over the Pause[] below.
rlaOK: Label = GenLabel[];
rlaBad: Label = GenLabel[];
drROR[const5, const7, const7]; --Indicate NaN trap expected
drLIQB[bx]; drLIQB[ax];
drRLADD[topDst, reg1, reg0];
Pause[];
drQLADD[pushAtop, reg0];
Pause[]; Pause[];
drLADD[];
Pause[]; Pause[]; Pause[];
Verify that the registers weren't disturbed.
drLIQB[ax]; drRJEBJ[popSrc, belowSrcPop, UseLabel8B[rlaOK]]; SetLabel[rlaBad]; Pause[]; SetLabel[rlaOK];
drLIQB[bx]; drRJNEB[popSrc, belowSrcPop, UseLabel8B[rlaBad]];
}
ELSE {
No Lisp NaN trap should occur; check the result.
rlaOK: Label = GenLabel[];
rlaBad: Label = GenLabel[];
apbx: Word ← IntToWord[apb];
drROR[const5, const0, const0]; --Indicate no NaN trap expected
drLIQB[bx]; drLIQB[ax];
drQLADD[pushAtop, reg0];
drRLADD[pushDst, reg1, reg0];
drLIQB[apbx]; drRJEBJ[popSrc, belowSrc, UseLabel8B[rlaOK]];
SetLabel[rlaBad]; Pause[];
SetLabel[rlaOK];
drRJNEB[popSrc, belowSrcPop, UseLabel8B[rlaBad]];
drLADD[]; drLIQB[apbx]; drRJNEB[popSrc, belowSrcPop, UseLabel8B[rlaBad]];
Verify that Carry = 0 after a Lisp arithmetic operation.
drRUADD[pushDst, const0, const0];
drJNEBB[0, UseLabel8B[rlaBad]];
};
};
SetLabel[enterRLADDTest];
RLADDTest[ 1B, LMaxNum]; --Just barely overflows
RLADDTest[ LMaxNum, 1B];
RLADDTest[ 0B, LMinNum]; --Just barely doesn't underflow
RLADDTest[ LMinNum, 0B];
RLADDTest[ 0B, LMaxNum]; --Just barely doesn't overflow
RLADDTest[ LMaxNum, 0B];
RLADDTest[ -1B, LMinNum]; --Just barely underflows
RLADDTest[ LMinNum, -1B];
RLADDTest[0, 0];  --Other misc. test values
Set Carry = 1 to verify it has no effect and to test that Carry = 0 after a Lisp arithmetic operation.
drRUADD[const4, const7, const7];
RLADDTest[ 1252525252B, -1515151515B];
drRUADD[const4, const7, const7];
RLADDTest[-1000000000B, -1000000000B];
drRUADD[const4, const7, const7];
RLADDTest[ LMinNum, LMaxNum];
RLADDTest[ LMaxNum, LMinNum];
RLADDTest[ 777777777B, 1000000000B];
RLADDTest[ 1000000000B, 777777777B];
};
This procedure tests RLSUB, QLSUB, and LSUB.
GenRLSUB: PROC = {
RLSUBTest: PROC [a, b: INT] ~ {
ax: Word ← IntToWord[a];
bx: Word ← IntToWord[b];
amb: INT ← a - b;
IF a > LMaxNum OR a < LMinNum OR b > LMaxNum OR b < LMinNum OR amb > LMaxNum OR amb < LMinNum THEN {
A Lisp NaN trap will abort the RLADD, and the trap subroutine will skip over the Pause[] below.
rlsOK: Label = GenLabel[];
rlsBad: Label = GenLabel[];
drROR[const5, const7, const7]; --Indicate NaN trap expected
drLIQB[bx]; drLIQB[ax];
drQLSUB[pushAtop, reg0];
Pause[]; Pause[];
drRLSUB[topDst, reg1, reg0];
Pause[];
drEXDIS[]; drLIQB[bx]; --Reverse the args
drLSUB[];
Pause[]; Pause[]; Pause[];
Verify that the registers weren't disturbed.
drLIQB[bx]; drRJEBJ[popSrc, belowSrcPop, UseLabel8B[rlsOK]]; SetLabel[rlsBad]; Pause[]; SetLabel[rlsOK];
drLIQB[ax]; drRJNEB[popSrc, belowSrcPop, UseLabel8B[rlsBad]];
}
ELSE {
No Lisp NaN trap should occur; check the result.
rlsOK: Label = GenLabel[];
rlsBad: Label = GenLabel[];
ambx: Word ← IntToWord[amb];
drROR[const5, const0, const0]; --Indicate no NaN trap expected
drLIQB[bx]; drLIQB[ax];
drQLSUB[pushAtop, reg0];
drRLSUB[pushDst, reg1, reg0];
drLIQB[ambx]; drRJEBJ[popSrc, belowSrc, UseLabel8B[rlsOK]];
SetLabel[rlsBad]; Pause[];
SetLabel[rlsOK];
drRJNEB[popSrc, belowSrcPop, UseLabel8B[rlsBad]];
drEXDIS[]; drLIQB[bx]; --Reverse the args
drLSUB[];
drLIQB[ambx]; drRJNEB[popSrc, belowSrcPop, UseLabel8B[rlsBad]];
Verify that Carry = 0 after a Lisp arithmetic operation.
drRUADD[pushDst, const0, const0];
drJNEBB[0, UseLabel8B[rlsBad]];
};
};
SetLabel[enterRLSUBTest];
RLSUBTest[ 1B, -LMaxNum]; --Just barely overflows
RLSUBTest[ LMaxNum, -1B];
RLSUBTest[ -1B, -1-LMinNum]; --Just barely doesn't underflow
RLSUBTest[ LMinNum, 0B];
RLSUBTest[ 0B, -LMaxNum]; --Just barely doesn't overflow
RLSUBTest[ -LMaxNum, 0B];
RLSUBTest[ -2B, -1-LMinNum]; --Just barely underflows
RLSUBTest[ LMinNum, 1B];
RLSUBTest[0, 0];  --Other misc. test values
Set Carry = 1 to verify it has no effect and to test that Carry = 0 after a Lisp arithmetic operation.
drRUADD[const4, const7, const7];
RLSUBTest[ 1252525252B, 1515151515B];
drRUADD[const4, const7, const7];
RLSUBTest[-1000000000B, -1000000000B];
drRUADD[const4, const7, const7];
RLSUBTest[ LMinNum, -LMaxNum];
RLSUBTest[ LMaxNum, -1-LMinNum];
RLSUBTest[ 777777777B, 1000000000B];
RLSUBTest[ 1000000000B, 777777777B];
};
savePC ← GetOutputPC[area];
FillTrap[ALUCondIL, IllegalLispNum];
SetOutputPC[savePC];
Begin at PC = userBasePC = 1010000B * 4, L = 1, S = 0 as established in GenDebugger. const0 is in a ROM, so it requires no initialization; const7 is initialized to -1 here; the other constants require no initialization for this diagnostic.
drLIQB[IntToWord[-1]];
drROR[const7, topSrc, popSrc]; --Put -1 in const7.
drLIB[4];
drROR[const6, topSrc, popSrc]; --Put 4 in const6 for NaN trap
GenRLADD[];
GenRLSUB[];
Halt[177777B]; --Terminate here at the end of the program
Arrive here with the YoungestPC pointing at an opcode which experienced a Lisp NaN trap; this trap is always enabled, so no special enabling or disabling action is necessary. Unless const5 = -1 do a Pause[] (Lisp NaN not expected); otherwise, increment the PC by 4 and return.
WordAlign[area]; SetLabel[IllegalLispNum];
drALS[1]; --ALS[1 - nargs]
drLC5[];
drRJNEB[popSrc, const7, UseLabel8B[LNaNUnexpected]];
Advance the PC by 4 without smashing or using Carry (so use RVADD instead of ADDB).
GetYoungestPC[];
drRVADD[topDst, topSrc, const6];
SetYoungestPC[]; --Advance return PC by 4
drRET[377B]; --RET[nResults - 1]
SetLabel[LNaNUnexpected]; Pause[];
An enableable trap would push IFU status and exit with RET[nResults - 1].
};
END.