All:
PROC = {
--area: Area = GetCurrentArea[];
These labels are for trap procedures.
IFUStackOverflow: Label = GenLabel[];
IFUStkOvfBad: Label = GenLabel[];
EUStackOverflow: Label = GenLabel[];
EUStkOvfBad: Label = GenLabel[];
Reschedule: Label = GenLabel[];
RescheduleBad: Label = GenLabel[];
ErrorXop1Trap: Label = GenLabel[];
AlreadyInKernel: Label = GenLabel[];
TurnOnTraps: Label = GenLabel[];
TurnOffTraps: Label = GenLabel[];
TurnOnUserMode: Label = GenLabel[];
enterIFUStackOverflowTest: Label = GenLabel[];
enterSLimitTest: Label = GenLabel[];
enterRescheduleTest: Label = GenLabel[];
Must be first instruction on a page that is otherwise unused.
IFUPageFaultAddress: LONG CARDINAL = 27000000000B;
All traps enter kernel mode and disable traps. Disabling affects only Reschedule, EU stack overflow, and IFU stack overflow.
When traps are enabled, the IFU stack allows 11 normal calls but converts the 12th call into an IFU stack overflow trap; when traps are disabled, all 15 levels of the IFU stack are usable. Note, however, that when a trap or KFC is the 12th call, it will complete and disable traps without causing an IFU stack overflow trap. There is no IFU stack underflow trap; the first location in the IFU stack must be made to contain a return link to an appropriate trap procedure (or use the trick of causing a page fault).
When traps are enabled, any opcode causing S to wind up in the range [SLimit..SLimit+16) causes an EU stack overflow trap; this detects both underflows and overflows, though underflow can only happen due to a programming error.
Xops and KFC trap at opcode*TrapWidthBytes + xopBase*bytesPerWord = 4,000,000B + 20B * opcode.
FillXop:
PROC [inst:
CARDINAL, dest: Label] = {
SetOutputPC[inst * DragOpsCross.TrapWidthBytes + DragOpsCross.XopBase * DragOpsCross.bytesPerWord];
drJDB[UseLabel16[dest]];
};
A trap's location is TrapIndex*TrapWidthBytes + TrapBase*bytesPerWord =
4,002,000B + 20B * TrapIndex. TrapIndex definitions are in DragOpsCross.
FillTrap:
PROC [tx: DragOpsCross.TrapIndex, dest: Label] = {
SetOutputPC[LOOPHOLE[tx, CARDINAL] * DragOpsCross.TrapWidthBytes + DragOpsCross.TrapBase * DragOpsCross.bytesPerWord];
drJDB[UseLabel16[dest]];
};
16 bytes between consecutive trap instructions is insufficient for StandardTrap, so the trap instruction must be filled separately with FillTrap[TrapName, dest]. aux8 has previously been loaded with a code for the trap presently expected (or 0 if none), and an opcode which is supposed to trap is followed by enough XPause[] opcodes to fill out 6 bytes (i.e., enough for a 5-byte trapping opcode and a 1-byte XPause[] after it); then if no trap occurs, the first XPause[] after the opcode will stop simulation; or if the wrong trap occurs, the mismatch on aux8 will cause XPause[] to occur. Otherwise, the trap procedure will return to the 6th byte after the location that trapped.
StandardTrap:
PROC [dest: Label, code:
CARDINAL] = {
TrapUnexpected: Label = GenLabel[];
SetLabel[dest];
drALS[1]; --ALS[1 - nargs]
drLIB[code];
drRJNEB[popSrc, aux8, UseLabel8B[TrapUnexpected]];
Advance return PC by 6
GetYoungestPC[]; drRVADD[topDst, const4, topSrc]; SetYoungestPC[];
drRET[377B]; --RET[nResults - 1]
SetLabel[TrapUnexpected]; Pause[];
};
Procedures to enable and disable traps in the caller's context; must be in Kernel mode.
EnableTraps: PROC [] = { drDFC[UseLabel32[TurnOnTraps]]; };
DisableTraps: PROC [] = { drDFC[UseLabel32[TurnOffTraps]]; };
EnterUser: PROC [] = { drDFC[UseLabel32[TurnOnUserMode]]; };
Indicate KFC trap expected by loading 12 into aux8
EnterKernel: PROC [] = { drLIB[12]; drROR[aux8, popSrc, topSrc]; drKFC[]; drROR[aux8, const0, const0]; };
XPause[] = Pause[] but uses opcode 2 instead of 0.
XPause:
PROC = {
HandCodingSupport.OutputByte[HandCodingSupport.GetCurrentArea[], LOOPHOLE[2]];
};
Test conditions which should and should not cause IFU stack overflow trap. Begin here in Kernel mode with traps disabled, and 0 IFU call stack entries.
GenIFUStackOverflow:
PROC [] ~ {
exitIFUStkOvfTest: Label = GenLabel[];
SetLabel[enterIFUStackOverflowTest];
drASL[377B]; --0 locals, 0 pushes on the EU stack, 0 calls on the IFU stack
drLIB[40B + 4B + 2B];
drSIP[ifuStatus]; --UserModeKeep + TrapsEnabled + RescheduleKeep
Now in Kernel mode with traps enabled.
drLFC[3]; --1 calls
drLFC[3]; --2 calls
drLFC[3]; --3 calls
drLFC[3]; --4 calls
drLFC[3]; --5 calls
drLFC[3]; --6 calls
drLFC[3]; --7 calls
drLFC[3]; --8 calls
drLFC[3]; --9 calls
drLFC[3]; --10 calls
drLIQB[UseLabel32[exitIFUStkOvfTest]]; --Return PC for stack overflow trap
drLIB[1]; drROR[aux8, popSrc, topSrc]; --Indicate IFU stack overflow expected
drDFC[CardToWord[IFUPageFaultAddress]]; --11 calls
The DFC completes, but the following instruction is on a non-existent page and gets an IFU page fault which does a 12th call and gets converted into an IFU stack overflow trap. The IFU stack overflow trap handler will return here, if this happened correctly.
SetLabel[exitIFUStkOvfTest];
drROR[aux8, const0, const0]; --Indicate no traps expected
Remove the 11 calls from the stack and cleanup
FOR I: CARDINAL IN [0..10] DO GetEldestPC[]; ENDLOOP;
drASL[17B]; --L = 1, S = 20B, traps enabled, Kernel mode, 0 calls on the stack
};
GenSLimit:
PROC [] ~ {
SetLabel[enterSLimitTest];
Verify that EU stack overflow prevails over Reschedule when it is true at the time traps are enabled and Reschedule turned on by a SIP.
drASL[377B]; --S = 0, L = 1
drLIB[1]; drSIP[ifuStatus]; --Turn off trap enable, turn on Reschedule
drLC0[];
drLIB[1]; drSIP[ifuSLimit];
Indicate EU stack overflow expected.
drLIB[2]; drROR[aux8, topSrc, popSrc]; --S = SLimit = 1 now
drLIB[4B + 1B]; drSIP[ifuStatus]; --Trap enable + Reschedule
XPause[]; XPause[]; XPause[]; XPause[]; XPause[]; XPause[];
EU stack overflow should prevail over Reschedule here because it is true at the onset of the trap; trap returns here with reschedule-waiting turned off and traps disabled.
drROR[aux8, const0, const0]; --No trap expected
drLIB[160B]; drSIP[ifuSLimit];
drASL[377B]; --L = 1, S = 0, traps disabled, Kernel mode, 0 calls on the stack
};
Verify the occurrence of Reschedule trap when Reschedule is requested by this processor.
GenReschedule:
PROC [] ~ {
RescheduleOK: Label = GenLabel[];
SetLabel[enterRescheduleTest];
drASL[17B]; --L = 1, S = 20B, 0 calls on the stack
drLIQB[UseLabel32[RescheduleOK]]; --Reschedule trap will send control here
drLIB[11]; drROR[aux8, popSrc, topSrc]; --Reschedule trap expected
When the condition (TrapsEnabled & Reschedule) = TRUE as a result of SIP or RET, Reschedule should take immediately.
drLIB[40B + 4B + 1B]; --User mode keep + TrapEnable + Reschedule
drSIP[ifuYoungestL]; --**was ifuStatus
XPause[];
Return here after Reschedule has occurred.
SetLabel[RescheduleOK];
drROR[aux8, const0, const0]; --No traps expected
drLIB[40B + 1B]; --User mode keep + Reschedule (= traps disabled)
drSIP[ifuYoungestL]; --Shouldn't trap; **was ifuStatus
User mode keep + Traps enabled (shouldn't trap); turns off Reschedule.
drLIB[40B + 4B]; drSIP[ifuYoungestL]; --**was ifuStatus
CauseReschedule issues the IO command which sends Reschedule to all processors, but this action isn't simulated by Lizard.
--CauseReschedule[];
No-ops while waiting for Reschedule
--drJ1[]; drJ1[]; drJ1[]; drJ1[]; drJ1[];
--XPause[];
};
spLimit is set with room for 17 overflow words (just in case).
drLIB[128-16-1];
SetSPLimit[];
drROR[aux8, const0, const0]; --Initialize aux8 to 0, meaning no traps expected.
drLIB[6];
drROR[const4, popSrc, topSrc]; --Initialize const4 to 6 for the trap routines.
GenIFUStackOverflow[];
GenSLimit[];
GenReschedule[];
Halt[177777B]; --Terminate here at the end of the program
IFU stack overflow trap has code 1
EU stack overflow has code 2
EU write protect fault trap has code 3
Arrive here when an IFU page fault has given rise to an IFU stack overflow trap; the youngest PC should point at the instruction which page faulted.
SetLabel[IFUStackOverflow];
drLIB[1]; drRJNEB[popSrc, aux8, UseLabel8B[IFUStkOvfBad]];
GetYoungestPC[];
drLIQB[CardToWord[IFUPageFaultAddress]];
drRJNEB[popSrc, belowSrcPop, UseLabel8B[IFUStkOvfBad]];
SetYoungestPC[]; --Change return address
drRETN[];
SetLabel[IFUStkOvfBad]; Pause[];
Arrive here when an EU stack overflow trap has occurred with reschedule-waiting also true. Trap must turn off the reschedule-waiting and pop the stack twice to eliminate the EU stack overflow condition.
SetLabel[EUStackOverflow];
drLIB[2]; drRJNEB[popSrc, aux8, UseLabel8B[EUStkOvfBad]];
GetYoungestPC[]; drRVADD[topDst, topSrc, const4]; SetYoungestPC[];
--****Turn off reschedule-waiting and disable traps
drRETN[];
SetLabel[EUStkOvfBad]; Pause[];
****Does Reschedule-waiting have to be cleared here?
SetLabel[Reschedule]; --Arg is the return PC
drLIB[11]; drRJNEB[popSrc, aux8, UseLabel8B[RescheduleBad]];
SetYoungestPC[];
drRETN[];
SetLabel[RescheduleBad]; Pause[];
XPause[] (opcode 2) is used instead of Pause[] (opcode 0) to enter the debugger from user mode. This is done by first executing KFC to enter monitor mode and then doing Pause[].
SetLabel[ErrorXop1Trap];
drLIQB[CardToWord[600000B]]; GetYoungestStatus[]; drAND[];
drJEBB[0, UseLabel8B[AlreadyInKernel]];
EnterKernel[];
SetLabel[AlreadyInKernel];
Pause[];
SetLabel[TurnOnTraps]; --Call here with EnableTraps[]
drLIB[377B]; GetYoungestStatus[]; drAND[]; --Preserve L
drLIQB[CardToWord[200000B]]; drOR[]; SetYoungestStatus[]; --Set trapsEnabled
drRETN[];
SetLabel[TurnOffTraps]; --Call here with DisableTraps[]
drLIB[377B]; GetYoungestStatus[]; drAND[]; --Preserve L, clear trapsEnabled and User
SetYoungestStatus[]; --Set trapsEnabled
drRETN[];
SetLabel[TurnOnUserMode]; --Call here with EnterUser[]
drLIB[377B]; GetYoungestStatus[]; drAND[]; --Preserve L
Set trapsEnabled and user mode
drLIQB[CardToWord[600000B]]; drOR[]; SetYoungestStatus[];
drRETN[];
These calls to FillXop and FillTrap initialize the trap locations with JDB[trap procedure].
FillXop[2B, ErrorXop1Trap];
FillTrap[IFUStackOverflowTrap, IFUStackOverflow];
FillTrap[EUStackOverflowTrap, EUStackOverflow];
FillTrap[EUPageFault, EUPageFlt];
FillTrap[IFUPageFaultTrap, IFUPageFault];
FillTrap[RescheduleTrap, Reschedule];