*---------------------------------------------------------------------*
* *
* Copyright (c) 1996, SAS Institute Inc. *
* Unpublished - All Rights Reserved *
* *
* S A S / C S A M P L E *
* *
* Name: ALOADMA *
* *
* Language: Assembler *
* *
* EntryPoint: CASM *
* *
* Entry Type: Will be based on one of the following parms being *
* passed to the asssembler via SYSPARM: *
* - NONINDEP: Standard C Linkage <---Part 1 *
* - INDEP : Standard OS Linkage <---Part 2 *
* *
* Exit Type : - Non-INDEP - return to caller *
* - INDEP - terminate the C execution framework *
* and return to the caller. *
* *
* Files Note: 'prefix' is the installation defined high level *
* qualifier for the SAS/C product. *
* *
* Function: Display the CRAB address in use at entry then *
* dynamically load a non-INDEP C function. *
* *
* ALOADMA then loops calling the dynamically loaded *
* C function for several iterations. At loop *
* completion, unload the dynamically loaded module, *
* display the CRAB address, then return to the *
* caller. *
* *
* This module has two different entry and exit paths, *
* see 'Entry Type' and 'Exit Type' above for details. *
* *
* Purpose: MVS see prefix.SAMPLE.ASM(ALOADMM) prolog *
* CMS see SAMPASM MACLIB(ALOADMM) prolog *
* *
*---------------------------------------------------------------------*
* *
* NOTE: The following Section Applies to Part # 2 ONLY! *
* *
*---------------------------------------------------------------------*
* *
* Part 2 modules: ALOADMA - An INDEP assembler program using *
* CENTRY/CEXIT which dynamically loads *
* and executes ALOADMD. *
* ALOADMD - A non-INDEP dynamically loadable *
* C function. *
* ALOADMC - A C function used by each of the above *
* modules to display the CRAB address *
* being used by that module. *
* *
* MVS - *
* Compile/Link/Go: submit jcl in prefix.SAMPLE.AUX(ALOADMJI) *
* *
* CMS - *
* Compile/Link/Go: execute CMS exec in SAMPLAUX MACLIB(ALOADMEX) *
* as: ALOADMEX *
* *
* Misc Notes: *
* - ALOADMA is not assembler dependent, use either *
* Assembler H or High Level Assembler. *
* - The OS macro ABEND is used by this sample. *
* - ALOADMA uses SYSPARM and conditional assembly to *
* provide a CENTRY/CEXIT INDEP and non-INDEP version. *
* *
* *
*---------------------------------------------------------------------*
EJECT
PRINT ON,GEN
*---------------------------------------------------------------------*
* Ensure AMODE/RMODE for ALOADMS match those of SAS/C library default.*
*---------------------------------------------------------------------*
CASM@ AMODE 31
CASM@ RMODE ANY
SPACE
CASM@ CSECT
CREGS USING
*------------------------------------------------------------------*
* The Question: Do I want an INDEP or NON-INDEP Version for *
* assembly? *
* NON-INDEP: Will be used in Part 1 of ALOADM sample. *
* INDEP : Will be used in Part 2 of ALOADM sample. *
*------------------------------------------------------------------*
AIF ('&SYSPARM' EQ 'INDEP').INDEP1
SPACE
*------------------------------------------------------------------*
* Non-INDEP requested, setup and continue. *
*------------------------------------------------------------------*
*=========> NONINDEP: Expect to be called from a C function.
*------------------------------------------------------------------*
CASM CENTRY DSA=DSALEN
AGO .NOIND1
SPACE
*------------------------------------------------------------------*
* INDEP requested, setup and continue. *
*------------------------------------------------------------------*
*=========> INDEP: Do not expect to be called from a C function.
*------------------------------------------------------------------*
.INDEP1 ANOP
CASM CENTRY DSA=DSALEN,INDEP=YES
.NOIND1 ANOP
SPACE
*------------------------------------------------------------------*
* Say Hi to the World *
*------------------------------------------------------------------*
MVC FMTPTR1,=A(FORMAT1) Copy ptr to format to parmlist
L R15,=V(PRINTF) Load the Vcon for printf ==> R15
LA R1,PARMPR1 Load the parmlist ==> R1
BALR R14,R15 Call printf()
SPACE
*------------------------------------------------------------------*
* Spacer for CRAB address display *
*------------------------------------------------------------------*
MVC FORMAT1T+10(10),=C'Entry CRAB '
MVC FMTPTR1,=A(FORMAT1T) Copy ptr to format to parmlist
L R15,=V(PRINTF) Load the Vcon for printf ==> R15
LA R1,PARMPR1 Load the parmlist ==> R1
BALR R14,R15 Display CRAB address Leader
SPACE
*------------------------------------------------------------------*
* Check the Crab *
*------------------------------------------------------------------*
L R15,=V(CRBC) Load the Vcon for crbc ==> R15
LA R1,0 Load the parmlist ==> R1
BALR R14,R15 Display CRAB address w/crbc()
SPACE
*------------------------------------------------------------------*
* Seperate assembler output from dynamically loaded output *
*------------------------------------------------------------------*
MVC FMTPTR1,=A(FORMAT5A) Copy ptr to format to parmlist
L R15,=V(PRINTF) Load the Vcon for printf ==> R15
LA R1,PARMPR1 Load the parmlist ==> R1
BALR R14,R15 Call printf()
SPACE
*------------------------------------------------------------------*
* Print out the name of the module to be loaded *
*------------------------------------------------------------------*
MVC STRING,=A(CDYNLOAD) Copy ptr to format to parmlist
MVC FMTPTR2,=A(FORMAT2) Copy ptr to module name
L R15,=V(PRINTF) Load the Vcon for printf ==> R15
LA R1,PARMPR2 Load the parmlist ==> R1
BALR R14,R15 Call printf()
SPACE
*------------------------------------------------------------------*
* Dynamicaly Load CDYNLD *
*------------------------------------------------------------------*
MVC MODNAME,CDYNLOAD Copy modulename into workarea
LA R1,MODNAME R1 = &MODNAME
ST R1,LOADMP1 Store &MODNAME in parmlist
LA R1,DSAFP R1 = &DSAFP
ST R1,LOADMP2 Store &DSAFP in parmlist
L R15,=V(LOADM) Load the Vcon for loadm ==> R15
LA R1,LOADMP1 Load the parmlist ==> R1
BALR R14,R15 Call loadm()
ICM R4,15,DSAFP R4 = _dynamn fp; ensure it is good
BNZ GOTFUNC Was it good?
ABEND 4040,DUMP NO, Issue 4040 abend!
GOTFUNC EQU *
SPACE
*------------------------------------------------------------------*
* Call the dynamically loaded CDYNLD module in a loop, the *
* CRAB displayed by this module should always be the same. *
* *
* NOTE: loadm returns a 'REMOTE FUNCTION' pointer, which points *
* to two pointers. *
* 1) Address of the function *
* 2) Pesudoregister vector (PRV) for the load module *
* containing this function *
* *
* To ensure the CRAB is pointing to the PRV for the function *
* being executed, we must switch CRABPRV to the PRV of the *
* function we are calling. We must also save the current *
* CRABPRV and restore it after the called function *
* completes. *
* *
* See the Compiler Library and User's Guide, the section *
* on 'Remote Function Pointers' for a detailed discussion *
* this subject. *
* *
*------------------------------------------------------------------*
MVC DSAPRV,CRABPRV Save the current PRV
MVC CRABPRV,4(R4) Insert new PRV Value into the CRAB
LA R3,10 X = 10; init for loop
FORLOOP DS 0H FOR I=X TO 0 {
L R15,0(,R4) R15 = Entry point
BALR R14,R15 Call _dynamn EP
MVC FMTPTR3,=A(FORMAT3) Copy format to parmlist
ST R3,COUNT Store count in parmlist
L R15,=V(PRINTF) Load the Vcon for printf==> R15
LA R1,PARMPR3 Load the parmlist ==> R1
BALR R14,R15 Call printf(), prt loop cntr
SPACE
ENDFOR DS 0H
BCT R3,FORLOOP } Bottom of for loop
SPACE
*------------------------------------------------------------------*
* Note the PRV restoration, it is now back for THIS function. *
*------------------------------------------------------------------*
MVC CRABPRV,DSAPRV Restore our PRV
SPACE
*------------------------------------------------------------------*
* Delete the dynamically loaded module from memory *
*------------------------------------------------------------------*
L R15,=V(UNLOADM) Load the Vcon for unloadm ==> R15
LA R1,DSAFP Load the parmlist ==> R1
BALR R14,R15 Call unloadm()
SPACE
*------------------------------------------------------------------*
* Seperate assembler output from dynamically loaded output *
*------------------------------------------------------------------*
MVC FMTPTR1,=A(FORMAT5B) Copy ptr to format to parmlist
L R15,=V(PRINTF) Load the Vcon for printf ==> R15
LA R1,PARMPR1 Load the parmlist ==> R1
BALR R14,R15 Display seperator line
SPACE
*------------------------------------------------------------------*
* Spacer for CRAB address display *
*------------------------------------------------------------------*
MVC FORMAT1T+10(10),=C'Exit CRAB '
MVC FMTPTR1,=A(FORMAT1T) Copy ptr to format to parmlist
L R15,=V(PRINTF) Load the Vcon for printf ==> R15
LA R1,PARMPR1 Load the parmlist ==> R1
BALR R14,R15 Display CRAB address Leader
SPACE
*------------------------------------------------------------------*
* Display exit CRAB address *
*------------------------------------------------------------------*
L R15,=V(CRBC) Load the Vcon for crbc ==> R15
LA R1,0 Load the parmlist ==> R1
BALR R14,R15 Display CRAB address w/crbc()
*------------------------------------------------------------------*
* Display exit CRAB and say ending. *
*------------------------------------------------------------------*
MVC FMTPTR4,=A(FORMAT4) Copy the format to the parmlist
L R15,=V(PRINTF) Load the Vcon for loadm ==> R15
LA R1,PARMPR4 Load the parmlist ==> R1
BALR R14,R15 Call printf(), say ending
LA R3,0 End with a zero rc
SPACE
*------------------------------------------------------------------*
* Return to caller: NON-INDEP *
*------------------------------------------------------------------*
SPACE
AIF ('&SYSPARM' EQ 'INDEP').INDEP2
SPACE
CEXIT RC=(3),DSA=DSALEN RETURN
AGO .NOIND2
SPACE
.INDEP2 ANOP
SPACE
*------------------------------------------------------------------*
* Return to caller: INDEP return, this requires that the *
* C environment be terminated prior to exit *
*------------------------------------------------------------------*
L R15,=V(L$UEXIT) Load the Vcon for L$UEXIT ==> R15
LA R1,0 Load the parmlist ==> R1
BALR R14,R15 Call L$UEXIT
CEXIT RC=(3),DSA=DSALEN,INDEP=YES
.NOIND2 ANOP
SPACE
EJECT
*------------------------------------------------------------------*
* Constatnts *
* Notes: *
* - x'15' is the newline escape character *
* - x'00' is null, string terminator *
* - Be careful moving the following constants which follow, *
* each one has null and most will have a linend. *
* *
*------------------------------------------------------------------*
LTORG
FORMAT1T DC C'CASM : ---------------->'
DC X'00' <== End
FORMAT5A DC X'15'
DC C'<--Starting: Dynamic C Function Call --->'
DC X'151500' <== End
FORMAT5B DC X'15'
DC C'<--Ending : Dynamic C Function Call --->'
DC X'151500' <== End
FORMAT1 DC C'CASM : Entry'
DC X'1500' <== End
FORMAT2 DC C'CASM : Module name = %.8s'
DC X'1500' <== End
FORMAT3 DC C'CASM : -----> Count = %d'
DC X'1500' <== End
FORMAT4 DC C'CASM : Exit'
DC X'1500' <== End
DS 0D
CDYNLOAD DS 0CL8
DC CL6'CDYNLD' LOADM Module Name
DC X'00' <== End
SPACE
*------------------------------------------------------------------*
* Working Storage *
*------------------------------------------------------------------*
SPACE
*------------------------------------------------------------------*
* DSA: Start <---------------------------------------------*
*------------------------------------------------------------------*
COPY DSA
* Variables for the dynamic load and function call *
DSAPRV DS F Workarea for current PRV
DSAFP DS A Workarea for the C function ptr
LOADMP1 DS A LOADM parm 1 (Module name)
LOADMP2 DS A LOADM parm 2 (&functionptr)
MODNAME DS CL(L'CDYNLOAD) Workarea for the module name
SPACE
*------------------------------------------------------------------*
* Note: These are parameter list that will be used in calling *
* C function printf. *
*------------------------------------------------------------------*
PARMPR1 DS 0D Address of parameter list, aligned
*
FMTPTR1 DS A Pointer to format string
*
PARMPR2 DS 0D Address of paramater list, aligned
FMTPTR2 DS A Pointer to format string
STRING DS A Pointer to data, NOTE: By Reference
*
PARMPR3 DS 0D Address of parameter list, aligned
FMTPTR3 DS A Pointer to format string
COUNT DS F Pointer to data NOTE: By Value
*
PARMPR4 DS 0D Address of parameter list, aligned
FMTPTR4 DS A Pointer to format string
*
DSALEN EQU *-DSA End of the DSA
*------------------------------------------------------------------*
* DSA: END <---------------------------------------------*
*------------------------------------------------------------------*
SPACE
COPY CRAB
SPACE
END CASM
|