.TITLE EXIT AND ONEXIT .SBTTL EXIT -- EXIT TO RSX WITH STATUS .IDENT /V1.02/ .NLIST TOC,SYM .ENABL LC ; Exit with status for Whitesmith's C and Pascal. ; ; "The C Letter", V2 No 2 24-Apr-81 pp11-12 ; ; Assemble as: ; >MAC EXIT=EXIT ;+ ; exit() returns to the operating system, handing its integer argument ; to the system as the task's exit code. ; ; This occurs only after a check to see whether there are function ; calls to be executed that were set up by previous calls to onexit(). ; If there are, the function pointed to by FNP is executed. The ; return value from this function, if not null, is taken to be ; the next function to be executed before return. ; ; onexit() stores a pointer to a function that will be executed when exit() ; is called, and return the value of the previously stored function. ; ; MODIFICATIONS RECORD ; ==================== ; V1.02 1-Jul-82 CJD ; Use Syslib routine $EXST instead of EXST$/EXIT$S -- $EXST is in FCSRES. ;- .PSECT C$TEXT .GLOBL $EXST EXIT:: MOV FNP,%0 ; Get onexit function pointer 1$: CMP %0,#ONEXIT ; Default value? BEQ 2$ ; Yes, no function stored, go exit TST %0 ; 0? BEQ 2$ ; Yes, go exit again JSR PC,@%0 ; No, function to call, do so BR 1$ ; and repeat 2$: TST (SP)+ ; Purge stack MOV (SP)+,%0 ; Load exit's argument JMP $EXST ; for Syslib exit with status .SBTTL ONEXIT -- SET UP EXIT FUNCTIONS ONEXIT::MOV FNP,%0 ; Get old function pointer to return MOV 2(SP),FNP ; Put in the new first one RTS PC ; Return to caller .PSECT C$DATA .EVEN FNP: .WORD ONEXIT ; First function to call .END