Skip to main content

Full text of "xerox :: mesa :: 4.0 1978 :: listing :: Mesa 4 System :: Signaller.mesa Sep78"

See other formats


Signaller. mesa 



2-Sep-78 13:68:17 



Page 



-- Signaller. Mesa Edited by Sandman on May 12, 1978 3:09 PM 

DIRECTORY 

AltoDefs: FROM "altodefs" USING [BYTE], 
ControlDefs: FROM "controldef s" USING [ 

Alloc, ControlLink, Frame, FrameHandle, Free, GetReturnFrame, 

GetReturnLink, Greg, InstWord, localbase, Lreg, NullFrame, SetReturnLink, 

StateVector, WordPC], 
FrameDefs: FROM "framedefs" USING [SwapInCode] , 
ImageDefs: FROM "imagedefs" USING [PuntMesa], 
Mopcodes: FROM "mopcodes" USING [ 

zCATCH, zJ2, 2J9, zJB, zJW, zKFCB, zNOOP, zPORTI. zSLB], 
NucleusDefs: FROM "nucleusdef s" , 
SDDefs: FROM "sddefs" USING [ 

SD,NsError, sErrorList. sReturnError , sReturnErrorList , sSignal, 

sSignalList, sUncaughtSignal , sUnnamedError], 
SegmentDefs: FROM "segmentdef s" USING [Unlock], 
TrapDefs: FROM "trapdefs"; 

DEFINITIONS FROM ControlDefs; 

Signaller: PROGRAM 

IMPORTS FrameDefs, SegmentDefs 

EXPORTS FrameDefs, NucleusDefs, TrapDefs ■ 

BEGIN 

BYTE: TYPE « Al toDef s .BYTE; 

CatchPointer: TYPE = POINTER TO catch Frame; 

CatchCall: TYPE » PROCEDURE [SIGNAL] RETURNS [ActionCode]; 

CatchContinue: TYPE « PROCEDURE; 

ActionCode: TYPE - INTEGER; 
reject: ActionCode « 0; 
resume: ActionCode = 1; 
exit: ActionCode « -1; 

SendMsgSignal: PUBLIC SIGNAL RETURNS [UNSPECIFIED, UNSPECIFIED] = CODE; 

signalling: CARDINAL « 177777B; 
notSignalling: CARDINAL « 0; 

MarkSignalFrame: PROCEDURE [value: CARDINAL] - 

MACHINE CODE BEGIN Mopcodes . zSLB, 3 --OFFSET[mark]-- END; 

SignalHandler: PROCEDURE [signal: SIGNAL, message: UNSPECIFIED] « 
BEGIN 

SignalFrame: TYPE = POINTER TO FRAME[SignalHandler]; 

frame, nextFrame: FrameHandle; 
target, nextTarget: FrameHandle; 
self: FrameHandle = REGISTER[Lreg]; 
start: FrameHandle; 
catchFrame: CatchPointer; 
action: ActionCode; 
unwinding: BOOLEAN; 
catchPhrase: BOOLEAN; 
catchFSIndex: BYTE; 
catchPC. exitPC: WordPC; 
catchState: ControlDefs. StateVector; 



MarkSignal Frame[signal 1 ing] ; unwinding ♦- FALSE; 
start <- GetFrame[self . returnl ink] ; target ^ NullFrame; 
DO 

nextFrame <- start; 
UNTIL nextFrame » target DO 
frame <- nextFrame; 

IF frame. access! ink » REGISTER[Greg] AND frame. mark THEN 
BEGIN 

OPEN thisSignaller: LOOPHOLE[frame, SignalFrame]; 
IF unwinding THEN 
BEGIN 

IF signal ■ thisSignaller . signal THEN 
nextTarget ♦- IF thisSignaller .unwinding 



Signaller. mesa 2-Sep-78 13:58:17 Page 



THEN thisSignaller.nextTarget 
ELSE thisSignaller.nextFrame; 
IF thisSignaller. unwinding THEN 
BEGIN 
IF thisSignaller. frame » LOOPHOLE[frame. return! ink] THEN 

frame. returnlink ♦- [f rame[thisSignal ler.nextFrame]]; 
Con trolDefs.Free[ thisSignaller. frame]; 
END; 
nextFrame ^ GetFrame[f rame. returnl ink]; 
END 
ELSE 

nextFrame <- IF signal # thisSignaller. signal 
THEN 

IF thisSignaller. unwinding 
THEN thisSignaller.nextFrame 
ELSE GetFrame[f rame. returnl ink] 
ELSE 

IF thisSignaller. unwinding 
THEN thisSignaller.nextTarget 
ELSE thisSignaller.nextFrame; 
END 
ELSE nextFrame <- GetFrame[f rame. returnl ink]; 

IF unwinding AND nextTarget « frame THEN nextTarget <- nextFrame; 
[catchPhrase, catchFSIndex, catchPC] <- CheckCatch[f rame]; 
IF catchPhrase 
THEN 
BEGIN 

catchFrame ^ ControlDef s .Al loc[catchFSIndex]; 
catchFramet ♦- Frame[ 

accesslink: frame. accessl ink, 
pc: catchPC, 

returnlink: [f rame[self ]], 
extensions: catch[unused: , 

staticlink: f rame+localbase, messageval: message]]; 
action *- LOOPHOLE[catchFrame. CatchCall] 
[IF unwinding THEN L00PHOLE[UNWIND] ELSE signal 
I SendMsgSignal «> RESUME[message, signal]]; 
catchState ^ STATE; 
SELECT action FROM 
reject => NULL; 
resume => 
IF unwinding 

THEN ERROR ResumeError 
ELSE 
BEGIN 

catchState. dest <- ControlDef s.GetReturnLink[]; 
catchState. source «- 0; 
RETURN WITH catchState; 
END; 
exit «> 
BEGIN 

-- catchFrame is waiting to execute its exit jump 
exitPC ♦- catchFrame. pc; 
ControlDef s .Free [catch Frame]; 

target <- LOOPHOLE[catchState. stk[0]-ControlDef s .localbase]; 
nextTarget <- nextFrame; 
unwinding <- TRUE; message <- NIL; 
GO TO StartUnwind; 
END; 
ENDCASE; 
END; 
IF unwinding 
THEN 
BEGIN 

IF frame = start THEN start *- nextFrame; 
IF frame « LOOPHOLE[self. returnl ink] 

THEN self .returnl ink ♦- [f rame[nextFrame]]; 
Con trolDefs.Free[f rame]; 
END; 
REPEAT 

StartUnwind «> NULL; 
FINISHED «> EXIT 
ENDLOOP; 
REPEAT 

ucs -> NULL; 
ENDLOOP; 



Signaller. mesa 2-Sep-78 13:58:17 Page 



IF unwinding THEN target. pc ^ exitPC 
ELSE 

BEGIN 

IF SDDefs.SD[SDDefs.sUncaughtSignal] - THEN ImageDef s.PuntMesa[]; 

UncaughtSignal[message, signal, frame]; 

END; 
RETURN 
END; 

CheckCatch: PROCEDURE [frame: FrameHandle] 

RETURNS [catchPhrase: BOOLEAN, fslndex: BYTE, pc: WordPC] - 

BEGIN OPEN Mopcodes; 

iw: POINTER TO InstWord; 

parity: {even, odd}; 

Marks ignalFrame[ no tSignall ing]; 

FrameDefs . Swap I nCode[ frame. access! ink]; 

iw <- ABS[f rame.pc] + frame, accessl ink. code. codebase; 

parity <- IF frame. pc < THEN odd ELSE even; 

DO 

SELECT (IF parity«even THEN iw.evenbyte ELSE iw.oddbyte) FROM 
zCATCH «> BEGIN catchPhrase ^ parity « even; EXIT END; 
zPORTI.zNOOP -> 

IF parity=even THEN parity ^ odd 
ELSE BEGIN iw ♦■ iw + 1; parity <- even; END; 
ENDCASE => BEGIN catchPhrase ^ FALSE; EXIT END; 
ENDLOOP; 
IF catchPhrase 
THEN 

BEGIN -- [iw, parity] points at zCatch (note: parity must be even) 
pc ^ WordPC[iw - frame. accessl ink. code. codebase + 1]; 
fslndex <- iw.oddbyte; 
SELECT (iw+l).evenbyte FROM 
zJB «> 

BEGIN pc ^ [pc + 1]; GO TO evenPC END; 
IN [ZJ2..ZJ9] »> 

GO TO oddPC; 
zJW «> -- always padded 1 

BEGIN pc ^ [pc + 2]; GO TO evenPC END; 
ENDCASE; 
EXITS 

evenPC »> NULL; 
oddPC »> pc <- [-pc]; 
END; 
SegmentDefs. Unlock [frame. accessl ink. codesegment]; 
RETURN 
END; 

GetFrame: PROCEDURE [link: ControlLink] RETURNS [FrameHandle] • 
BEGIN 

-- Mar kSignalFrame[no tSignall ing]; 
DO 

WITH cl: link SELECT link. tag FROM 
frame => RETURN [cl. frame]; 
indirect => link ^ cl.linkt; 
ENDCASE => RETURN[NullFrame]; 
ENDLOOP; 
END; 



Signal: PROCEDURE [signal: SIGNAL, message: UNSPECIFIED] = SignalHandler ; 

SignalList: PROCEDURE [signal: SIGNAL, message: POINTER TO UNSPECIFIED] - 
BEGIN 

MarkSignal Frame[notSignal 1 ing]; 
SignalHandler[signal . message 1 

UNWIND «> ControlDefs.Free[message]]; 
ControlDefs. Free [mess age]; 
RETURN 
END; 

ResumeError: PUBLIC SIGNAL « CODE; 

Error: PROCEDURE [signal: SIGNAL, message: UNSPECIFIED] « 
BEGIN 
MarkSignal Fram0[no tSignall ing]; 



Signaller. mesa 2-Sep-78 13:58:17 Page 



SignalHand1er[signal , message]; 

ERROR ResumeError 

END; 

ErrorList: PROCEDURE [signal: SIGNAL, message: POINTER TO UNSPECIFIED] ■ 
BEGIN 

Marks igna1Frame[ no tSignalling]; 
SignalHancner[signa1 , message I 

UNWIND "> Contro1Defs.Free[message]]; 
Control Defs . Free [mess age]; 
ERROR ResumeError 
END; 

ReturnError: PROCEDURE [signal: SIGNAL, message: UNSPECIFIED] - 
BEGIN 

caller: FrameHandle ■ ControlDef s .GetReturnFrame[] ; 
ControlDefs.SetReturnLink[caller. return link]; 
Marks i gn al F rame[ no tSignal ling]; 
SignalHancller[signal , message I 

UNWIND «> ControlDefs.Free[caller]]; 
Con trolDefs.Free[ caller]; 
ERROR ResumeError 
END; 

ReturnErrorList: PROCEDURE [signal: SIGNAL, message: POINTER TO UNSPECIFIED] 
BEGIN 

caller: FrameHandle « ControlDef s .GetReturnFrame[]; 
ControlDef s . Se t Re turnLink[ caller .returnlink]; 
MarkSignalFrame[notSignall ing]; 
SignalHandler[signal , message I 
UNWIND =•> 

BEGIN 

ControlDef s.Free[ caller]; 

Con trolDefs.Free[mes sage]; 

END]; 
Con trolDefs.Free[ caller]; 
ControlDef s . Free [mess age]; 
ERROR ResumeError 
END; 

UnnamedError: PROCEDURE « 
BEGIN 

MarkSignalFrame[notSignalling]; 
SignalHandler[L0OPH0LE[-l], -1]; 
ERROR ResumeError 
END; 

UncaughtSignal : PROCEDURE [msg, signal: UNSPECIFIED, frame: FrameHandle] » 
MACHINE CODE BEGIN Mopcodes . zKFCB , SDDef s . sUncaughtSignal END; 

Init: PROCEDURE » 
BEGIN OPEN SDDef s; 

sd: POINTER TO ARRAY [0..0) OF UNSPECIFIED ^ SD; 
sd[sSignalList] <- SignalList; 
sd[sSignal] <- Signal; 
sd[sErrorList] *- ErrorList; 
sdfsError] <- Error; 

sd[sReturnErrorList] ^ ReturnErrorList; 
sd[sReturnError] <r ReturnError; 
sd[sUnnamedError] <- UnnamedError; 
END; 

Init[]; 

END.