;C************************************************************************
;C*
;C*  COPYRIGHT (c) 1981,1983,1984,1987,1988
;C*  Westinghouse Electric Corporation
;C*
;C*  THIS SOFTWARE IS FURNISHED WITHOUT LICENSE AND MAY BE USED AND
;C*  COPIED ONLY WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.
;C*
;C*  THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE
;C*  AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY WESTINGHOUSE.
;C*
;C*  WESTINGHOUSE ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
;C*  OF THIS SOFTWARE.
;C*
;C****************************************************************************
        .TITLE          find_uic
        .LIBRARY        /SYS$LIBRARY:LIB.MLB/
 
;++
;
; FUNCTIONAL DESCRIPTION:
;
;       Loop through all PCBs and look for another process with the
;       same UIC.  If on the same node compare PID to see if another process
;
; CALLING SEQUENCE:
;
;       answer = find_uic(UIC, PID)
;
; INPUTS:
;       4(AP) - UIC want to match
;       8(AP) - 0 if process wanting to match is on another node in cluster
;               PID if process is on same node
;
; IMPLICIT INPUTS:
;
;       SCH$GL_PCBVEC - contains address of PCB vector
;       SCH$GL_MAXPIX - maximum process index
;       SCH$GL_CURPCB - contains address of pcb of current process
;
; OUTPUTS:
;       R0 - Whether another process with the same UIC was found
;
; IMPLICIT OUTPUTS:
;       none.
;
; ROUTINE VALUE:
;
;       R0 = SS$_NORMAL -       another process found with same UIC
;          = SS$_NOMOREPROC -   no other processes found with same UIC
;          = SS$_BADPARAM -     bad UIC
;
; SIDE EFFECTS:
;
;       Some of this routine is executed at IPL SYNCH to synchronize
;       the use of the PCB Vector and the PHD for each process.
;
;       None intentional - has tendency to crash system while testing!
;--
 
        .PAGE
        .SBTTL  DECLARATIONS
        .PSECT  SCANDATA,QUAD,NOEXE
;
; System symbol definitions
;
 
        $pcbdef
        $phddef
        $ipldef
        $ssdef
 
        .PAGE
        .SBTTL  find_uic
        .PSECT  find_code,NOWRT,EXE
        .ENTRY  find_uic, ^M<>
 
;
; Check to ensure that we can write the user buffer before switch to kernel
;
        MOVL    4(AP),R2                ; UIC
        BEQL    BADARG                  ; Less than or equal 0
;
; Change mode and go get goodies
;
 
        $CMKRNL_S B^SCAN,(AP)           ; Scan all processes in kernel mode
        BRB     DONE
BADARG: MOVZWL  S^#SS$_BADPARAM,R0      ; Initial count .LE. 0
DONE:   RET
 
 
        .PAGE
        .SBTTL  SCAN
 
SCAN:
        .WORD   ^M<R2,R3,R4,R5,R6,R7,R8,R9,R10,R11> ; Register save mask
 
        MOVL    4(AP),R4                        ; UIC
        MOVL    8(AP),R5                        ; PID
        MOVL    SCH$GL_PCBVEC,R2                ; Point to top of PCB vector
        MOVL    (R2),R0                         ; Get NULL PCB address
        MOVL    PCB$L_PID(R0),R7                ; ... and its PID
        MOVL    R0,R6                           ; Remember NULL PCB address
        CLRL    R3                              ; Clear current pix
 
10$:    SETIPL  80$                             ; Synchronize use of PCB vector
        MOVL    (R2)[R3],R0                     ; Get next PCB address
        MOVL    PCB$L_PID(R0),R7                ; ... and its PID
        SETIPL  #0                              ; Back to IPL 0
        CMPL    R6,R0                           ; Is this empty (= NULL PCB)?
        BEQLU   70$
 
30$:    CMPL    R4, PCB$L_UIC(R0)               ; Check UIC
        BNEQU   70$                             ; Not the same


        CMPL    #0, R5                          ; PID supplied ?
        BEQLU   75$                             ; Found a process with the
                                                ; same UIC on another machine

        MOVL    SCH$GL_CURPCB, R8               ; Get address of current PCB
        CMPL    PCB$L_PID(R8), PCB$L_PID(R0)    ; See if found process current
                                                ; process
        BNEQU   75$                             ; Same UIC but different PID
                                                ; else found self keep looking
 
70$:    ACBL    SCH$GL_MAXPIX,#1,R3,10$         ; Loop for each proc in PCBVEC

        CLRL    R0
        MOVL    #SS$_NOMOREPROC,R0
        BRB     76$
75$:    MOVZBL  #SS$_NORMAL,R0
76$:    RET                                     ; Return to EXEC mode for exit

80$:    .LONG   IPL$_SYNCH
        ASSUME  .-10$  LE  512                  ; Make sure  < 2 pages
        .END
