MANION@xrt.upenn.EDU (Frank Manion) (07/13/87)
Tim Lee writes: > PROBLEM: I HAVE A FORTRAN PROGRAM WHICH NEEDS TO HANDLE AN AST. > I WOULD LIKE TO LOCK IN MEMORY THE PAGES OF EITHER THE WHOLE PROGRAM OR > MINIMALLY THOSE PARTS REQUIRED TO HANDLE THE AST (COMMON BLOCKS AND THE > AST ROUTINE ITSELF) SO THAT THE RESPONSE TIME WILL BE QUICK. TO USE THE > SYSTEM SERVICES LOCK PAGES IN MEMORY ROUTINE SYS$LCKPAG OR SYS$LKWSET > I NEED TO KNOW THE ADDRESSES OF THE PAGES TO BE LOCKED. I DO NOT KNOW HOW > TO USE SYSTEM ROUTINES (SYS$GETJPI??) TO FIND THESE ADDRESSES. Jerry Leichter gives the proper response for storage elements (ie. variables). > The %LOC function allows you to obtain the address of a storage > element, such as a variable in a common block. What you'd probably do > is apply %LOC to a pair of variables, one at the beginning of the common > block, one at the end. There is a simple, straight forward approach to getting both the starting and ending address of a Fortran routine: use the ENTRY statement to insert a name at the very end of the routine in question, then use the %loc builtin function to get the addresses in question. The following (tested) code demonstrates this. The code also demonstrates what happens if you try to fetch the address of a routine from inside a itself (see below). external ast,ast_end integer*4 ast type *,'in main, routine address = ',%loc(ast),' end = ',%loc(ast_end) c insert calls to sys$lkwset here. c actual last address in AST is %loc(ast_end)-1 call ast c etc... end integer*4 function ast i = %loc(ast) ! see below type *,'routine thinks it''s address = ',i return entry ast_end return end Note that you must get the addresses from a routine external to the target routine. If you try to get the address of a function from within the function, Fortran will return the address of the "psudo-variable" (in psect $local) which is used for storing the function value prior to stuffing it in r0. If you try to get the address of a subroutine from within the subroutine, the compiler will generate a fatal error. As stated previously by Jerry, while this solution currently works, there would seem to be little guarantee that a future Fortran compiler would work the same. As Jerry points out, this is the result of trying to force a lower level construct onto a high level language. Use any of the suggested hacks with caution. -------------------------------------------------------------------- Reply to: MANION%XRT@CIS.UPENN.EDU Frank J. Manion Phone: (215) 728-3660 The Fox Chase Cancer Center 7701 Burholme Avenue Philadelphia, PA 19111 --------------------------------------------------------------------