     ! Modified     25/February/90   12:00                              FAUXST5


    !--------------------------------------------------------------------!
    !                                                                    !
    !   Run Time Support for the AUXILARY STACK (for Fortran or Imp)     !
    !                                                                    !
    !                                                                    !
    !--------------------------------------------------------------------!



!---History:
    !
    !
    !FAUXST5   added procedure INITAUX which may be called before the
          !    auxilary stack has been created to define the size of
          !    the auxilary stack
    !FAUXST4   on some hosts (UNICORN) malloc may not return a double
          !    word aligned area - explicitly align the area returned
          !    by malloc
    !FAUXST3   re-select a positive going Auxilary Stack.
    !FAUXST2   re-implemented for a negative going Auxilary Stack.
    !FAUXST1   first version, for Fortran or Imp. Later versions should be
          !    extended for C and other languages, and should update the
          !    mechanism by which any failures are reported.




!---Global Data:
    !
   %recordformat form of auxstack info (                                     %c
                                                                             %c
                %integer size,         {size of Auxstack        }
                %integer base,         {base address of Auxstack}
                %integer cur ,         {current top of Auxstack }
                %integer max )         {top address of Auxstack }

   %externalrecord (form of auxstack info) auxstdata %alias "s_auxstdata"


!---Constants:
    !
   %constinteger default auxstack size= x'40000'



%externalintegerfn auxst %alias "s#auxst" (%integer ep)
    !
   %externalintegerfnspec malloc (%integer bytes)
   %integer base,size,adj

%if ep= 0 %thenstart
    !
    !   Initialise the Auxilary Stack
    !
        size = auxstdata_size
    %if size<= 0 %then size= default auxstack size
        base = malloc (size)
    %if base = 0 %thenstart
                  newline
                  print string ("No Space for Auxilary Stack
");              %monitor
                 %stop
                 %finish
         adj = base & 7
     %if adj # 0 %thenstart
                  adj = 8 - adj
                  base= base + adj
                  size= size - adj
                 %finish
         auxstdata_base= base
         auxstdata_size= size
         auxstdata_max = base + size
         auxstdata_cur = base
%result= auxstdata_cur
%finishelsestart

    !
    !   Report an Auxilary Stack Adjustment Failure
    !
        newline
        print string ("Invalid Operation on Auxilary Stack
");     newline
       %monitor
       %stop
    %finish
%end; !of auxst


%externalroutine initaux (%integer Kbytes)
    !
    !A Procedure to Initialise the Size of the Auxilary stack. It must
    !  be called before the Auxilary Stack is created. If the Auxilary
    !  stack already exists then this procedure has no effect.

%if Kbytes> 0 %and (auxstdata_size<= 0  %orc
                    auxstdata_base = 0) %then auxstdata_size= Kbytes<< 10

%end; !of initaux

%endoffile
