PMM$TASKING_HELPER_PROCEDURES  ident

*copyc sya$cybil_interface_procedures
*copyc sya$constants
*copyc sya$xp_and_sf_constants
*copyc osa$basic_register_equates

         use       code
         page
.
.
.-------------------------------------------------------------------------------
.
.  PROCEDURE [XDCL] pmp$return_to_outward_call_sfsa
.      (outward_call_sfsa: ^ost$stack_frame_save_area);
.
.  PURPOSE:
.    This procedure is a helper for PMP$OUTWARD_CALL.
.    This procedure returns to a stack_frame_save_area passed to it as an argument.
.    The stack_frame_save_area must reside in a less privileged ring.  This procedure
.    POPs all stack frames in the ring in which it is called, resets its PSA to point
.    to the target stack_frame_save_area, and executes a RETURN.
.-------------------------------------------------------------------------------
.
.
         def       RETRN
RETRN    alias     PMP$RETURN_TO_OUTWARD_CALL_SFSA
RETRN    procedur
sfsa     param     val,pointer
.
         isob      x2,x0,x0,0403(16) .isolate caller ring
.
         lx        x4,a3,bs_rcpclr   .Ring crossing procedure PVA
         isob      x4,x4,x0,2453(8)  .Isolate segment and offset
         lx        x6,a3,bs_rtprc    .End of ring crossing procedure PVA
         isob      x6,x6,x0,2453(8)  .Isolate segment and offset

return_1 cpyax     x3,a_psa
         isob      x3,x3,x0,0403(16) .isolate ring in a_psa
         brrne     x2,x3,return_2    .if ring crossing
         lx        x5,a_psa,0        .previous stack frame P
         isob      x5,x5,x0,2453(8)  .Isolate segment and offset
         brxge     x5,x6,pop_it      .If not in ring crossing procedure
         brxge     x5,x4,return_3    .If in ring crossing procedure
pop_it   pop
         brreq     x0,x0,return_1
.
return_2 ploada    a_psa,sfsa        .load target sfsa pointer
         return
.
return_3 ploada    a5,sfsa           .load target sfsa pointer
         sa        a5,a_psa,26       .Change ring crossing proc to
                                     .return to target sfsa.
         return
         page
.
.
.-------------------------------------------------------------------------------
.
.  PROCEDURE [XDCL] PMP$POP_3_STACK_FRAMES
.      (pad_size: ost$segment_offset);
.
.  PURPOSE:
.    This procedure is a helper for PMP$POP_ALL_STACK_FRAMES.
.    This procedure and PMP$INTRA_RING_POPPER operate as coroutines which POP all of
.    the stack frames in the ring in which they are activated.  The intra_ring_popper
.    is partitioned into coroutines in order to minimize the amount of code written
.    in assembly language.  Each time it is called this procedure POPs three stack
.    frames -- a frame for PMP$INTRA_RING_POPPER, a frame for the previous instance of
.    PMP$POP_3_STACK_FRAMES, and the next user frame to be processed.  When the
.    POPs have been performed, DSP is reset in order to prevent unwarranted stack growth.
.-------------------------------------------------------------------------------
.
.
.
.
         use       code
         def       pop3
POP3     alias     PMP$POP_3_STACK_FRAMES
pop3     procedur
pad_size param     val,subrange,4
.
         ploadx    xf,pad_size
         pop
         pop
         la        af,a_psa,10       .save original DSP value
         pop
         addaq     af,af,8           .insure space for condition handler stack
         cpyaa     ae,af
         addax     ae,xf             .increase DSP by pad_size
         addaq     a_dsp,ae,8        .increase DSP by ap_list size
         sa        af,ae,2           .store ap_list value
         ente      x0,00120(16)
         callseg   cbp,a_bindin,ae   .call PMP$INTRA_RING_POPPER
.
.  This return instruction is needed to seperate this procedure from the next
.  procedure so as to prevent confusion when this procedure's SFSA is saved on
.  the callseg.  The SFSA must not have PMP$CALL_RING_CROSSING_PROC's PVA as P.
.
         return
         page
.
.  PMP$CALL_RING_CROSSING_PROC
.
.  This purpose of this procedure is to call PMP$RING_CROSSING_PROCEDURE
.  when the possibility for a RING ALARM exists.
.  The FREE FLAG will be set when returning across the ring boundary.
.
.  local definitions
.
.  The following constant specifies a Frame Descriptor for a stack frame save area of
.  28(16) bytes.  This is used in conjunction with the CYBIL constant
.  mmc$ring_crossing_offset defined in the deck mmt$page_map_offsets.  Any changes to
.  This area must be reflected in that deck as well as the assembly language deck
.  sym$core_trap_handler.
.
x_enviro   equ      0130(16)        .Descriptor for CALL.
x_enviro_1 equ      0140(16)        .Descriptor for CALL.
.
. Stack frame offsets
.
plist     equ      8                       .Stack - start of param list
sframe    equ      plist+128               .Stack - Area to save live registers
svarlen   equ      sframe+216              .Length of stack variable area
          page
.
.  Ring Crossing Procedure Caller
.
          use      code
          def      rcpcalr
rcpcalr   alias    PMP$CALL_RING_CROSSING_PROC
rcpcalr   bss      0
          entl     x0,r_td                 .Disable traps
          cpyxs    x0,x0
          addaq    a0,a1,svarlen           .Push stack frame
          ente     x0,41ff(16)             .Descriptor for SMULT
          smult    x0,a1,sframe            .Save A4 - AF, X1 - XF

.
. Call PMP$RING_CROSSING_PROCEDURE.
.
          ente     x0,x_enviro             .Set frame descriptor.
          callseg  bs_rcp,a3,a0            .Call the procedure.
.
          cpyaa    a0,a1                   .POP the space we PUSHed.
.
. Now call the procedure rtproc to do the actual return so that the
. proper value for TOS is preserved.
.
          ente     x0,x_enviro             .Set frame descriptor.
          callseg  bs_rtprc,a3,a0          .Callee does not return to caller.
.
. WARNING - This procedure must follow the pmp$call_ring_crossing_proc
.           in order for pmp$return_to_outward_sfsa to work.  That procedure
.           makes a test to see if the P address is in the range of rcpcalr
.           to rtproc.
.
          def      rtproc
rtproc    alias    PMP$RING_CROSSING_PROC_RETURN
          align    0,8
.
rtproc    bss      0
          addaq    a0,a1,svarlen           .Push stack frame
          la       a4,a2,18                .Get callers CSF.
          la       a2,a2,26                .Use callers PSA.  This POPs caller.
.
. The following field definition is used to support the PSFSA instruction which is
. required for CYBER-2000 but is not available in the ASSEMBLER language yet.
. When it is available, replace the VFD line with the following line:
.         psfsa                            .Purge the SFSA pushdown (CYBER-2000 only)
.
          vfd,16   0701(16)                .Purge SFSA pushdown (CYBER-2000 only)
.
.  Call pmp$enable_job_free_flag.
.
          ente     x0,x_enviro_1
          callseg  bs_free,a3,a0
          entl     x0,r_ted                .Set TRAP-ENABLE-DELAY.
          cpyxs    x0,x0
          brcr     2,5,rtproc1             .Set Free Flag.
.
rtproc1   bss      0
          cpyaa    a0,a1                   .POP the space we PUSHed.
.
          ente     x0,41ff(16)             .Descriptor for LMULT
          lmult    x0,a4,sframe            .Restore A4 - AF, X1 - XF
          return
.
          page
.
.  Binding Section
.
          use      binding
.
         ref       procname
PROCNAME alias     PMP$INTRA_RING_POPPER
cbp      address   c,procname
.
          ref      rcp
rcp       alias    PMP$RING_CROSSING_PROCEDURE
bs_rcp    address  c,rcp
.
          ref      freeflag
freeflag  alias    PMP$ENABLE_JOB_FREE_FLAG
bs_free   address  c,freeflag
.
bs_rcpclr address  c,rcpcalr
.
bs_rtprc  address  c,rtproc

          end
