	.TITLE zdsetf	- Release the task waiting for log
	.IDENT	/0.AIC/
	.ENABLE	LC
;+
; ** AUTREL - This routine is a 'C' callable routine that will release
; 	      a task that is currently waiting for an local event flag
;	      In order to use this routine the caller must have been 
;	      built priviledge. It has only been tested at PR:5.
;
;		This program is system independent in that it doesnot
;	      have to be built with the system.stb. The entrypoints into
; 	      the system are resolved by calling the FDSSTB subroutine 
;	      with the name of the entry point to be found.
;
; CALL:
;		autrel( &tsknm,efn);
;
;	where
;		&tsknm	-	Is a pointer to the RAD50 representation
;				of the task name
;		
;		efn	-	Is the number of the event flag to be
;				used to release the task
;
; CALLS:
;		FDSSTB	-	Search the system stb
;
; Returns:
;		nothing in particular.
;
;-
;
; stack contents after the $SAVAL call:
;
;       +---------------------------------------+
;       |       Event flag number               | +22
;       +---------------------------------------+
;       |       Pointer to the task name        | +20
;	+---------------------------------------+
;	|       Return address 			| +16
;       +---------------------------------------+
;       |       saved r5                        | +14
;       +---------------------------------------+
;       |       saved r4                        | +12
;       +---------------------------------------+
;       |       saved r3                        | +10
;       +---------------------------------------+
;       |       saved r2                        | +06
;       +---------------------------------------+
;       |       saved r1                        | +04
;       +---------------------------------------+
;       |       saved r0                        | +02
;       +---------------------------------------+
;       |       return address for $saval       | +00
;       +---------------------------------------+
;
;
s.r0    =       0               ; Offset to r0
s.r1    =       2               ; Offset to r1
s.r2    =       4               ; Offset to r2
s.arg1  =       20              ; Offset to the first calling argument
s.arg2  =       22              ; Offset to the second calling argument.

sname:	.asciz	"$SRSTD"	; Search the System task directory
ftsk:	.asciz	"$SETF "	; Set an event flag in another task
	.even
search:	.word	0		; Address of the search routine
..free:	.word   0		; Address of the set flag routine

zdsetf::
	call	$saval		; save all of the registers just in case
	tst	..free		; Have the symbols been defined?
	bne	1$		; NE - yes they have.
	mov	#sname,-(sp)	; Find the address of $SRSTD
	call	FDSSTB		; 
	mov	r0,search	; and save it
	beq	crash		;
	mov	#ftsk,(sp)	; Find the address of $SETF
	call	FDSSTB		; 
	mov	r0,..free	; and save it.
	beq	crash		;
	tst	(sp)+		;
1$:
	mov	s.arg1(sp),r3	; Point to the task name for search call
	mov	s.arg2(sp),r1	; and fetch the event flag number
;
; We have established the environment now we will switch to the system
; state for final processing
;
	call	$swstk,100$	;; Declare a system process
	call    @search         ;; Find the TCB for this task
	bcs	90$		;; If this fails its cause he's dead.
	mov	r0,r5		;; Copy the TCB for the $setf call
	mov	r1,r0		;; and the event flag
	call	@..free		;; and now set the flag so dummy can go
90$:
	return			;; from system state
100$:				; to task state
	return			; to the caller.
crash:	iot			; failed to find STB of symbol so die.
	.end
