.TITLE ACSV$ C register save and restore with AST support .IDENT "V2.0" .ENABL LC ;+ ; ; Index C register save and restore with RSX AST's ; Index C program execution environment with RSX AST's ; ; Usage ; ; jsr r5,acsv$ ; ... ; jmp acret$ ; ; Description ; ; C program Run-time Environment with RSX AST's ; ; Each C subroutine starts with a call to CSV$ and exits by ; jumping to CRET$. Upon exit, the stack need not be equal ; to its value on entrance. This version preserves R0, so ; that AST's will work. ; ; During the execution of all C subroutines, register R5 ; points to the current "environment." Within a subroutine, ; it appears as follows: ; ; _______________ ; | | ; SP -> | 1st loc. var. | -12(R5) C$AUTO-2(R5) ; |_______________| ; | | ; | Profile ptr | -10(R5) ; |_______________| ; | | ; | Saved R2 | -6(R5) ; |_______________| ; | | ; | Saved R3 | -4(R5) ; |_______________| ; | | ; | Saved R4 | -2(R5) ; |_______________| ; | | ; R5 -> | Saved R5 | ; |_______________| ; | | ; | Return add. | +2(R5) ; |_______________| ; | | ; | First arg. | +4(R5) C$PMTR+0(R5) ; |_______________| ; | | ; | Second arg. | +6(R5) C$PMTR+2(R5) ; |_______________| ; ; Within a subroutine, Registers R0-R4 and the top of the ; stack, (sp) are available for use. Registers R0 and R1 ; are not preserved by subroutines and may be used to pass ; a return value. ; ; R5 must not be modified by a subroutine. All variable ; addressing must be done by offsets to R5. Subroutine ; arguments must be accessed by reference to C$PMTR. ; Subroutine local variables must be accessed by reference ; to C$AUTO. This permits modification of calling sequences ; without rewriting all subroutines. ; ; CSV$ refers to global symbol $$main to call the run-time startup ; program from the (RSX) library. ; ; [end] ;- ; ; Edit history ; 000001 RBD From old CSV.MAC. ; 000002 11-Mar-82 MM Added Whitesmith's entries ; V1.3 19-Oct-82 RBD Changed P-sections for new compiler. Documentation. ; V1.4 19-Jan-02 BQT Changed for I/D space and new stack layout. ; V2.0 31-Jan-02 BQT Changed since compiler now generates calls to ACSV ; when told to compile for ast. ; ; If C$PMTR/C$AUTO are undefined, just define them ; .iif ndf C$PMTR C$PMTR = 4 ;formal[n] @ c$pmtr+(r5) .iif ndf C$AUTO C$AUTO = -10 ;local[n] @ c$auto-(r5) .globl C$PMTR, C$AUTO .iif ne C$PMTR-4 .error Bad definition of C$PMTR .iif ne C$AUTO+10 .error Bad definition of C$AUTO ; ; By defining C$PMTR and C$AUTO as local symbols, the task ; builder need not do so much work .mcall astx$s .psect c$data,d,rw ASTR0:: .WORD 0 ; Preserved R0. .PSECT C$CODE,i,ro ;03 ; ; save R4-R0 and make a one-word temp slot on the stack. ; ACSV$:: MOV R0,ASTR0 ;Save R0. MOV (SP),-(SP) ;Save old R5 at correct spot. MOV R1,2(SP) ;Save R1. MOV R5,R1 ;Preserve return pointer. MOV SP,R5 ;Set frame pointer. MOV R4,-(SP) MOV R3,-(SP) MOV R2,-(SP) CLR -(SP) JSR PC,(R1) ; ; Pop stuff to return. ; ACRET$:: MOV R5,R1 MOV -(R1),R4 MOV -(R1),R3 MOV -(R1),R2 MOV R5,SP MOV (SP)+,R5 MOV (SP)+,R1 ASL R0 ADD R0,SP MOV ASTR0,R0 ASTX$S ; .END