Google
 

Trailing-Edge - PDP-10 Archives - BB-P363B-SM_1985 - t20/nmlt20/dtet20.b36
There are no other files named dtet20.b36 in the archive.
! UPD ID= 292, SNARK:<6.1.NML>DTET20.B36.2,  15-Mar-85 13:14:15 by GLINDELL
!  Change sleep time between attempts to 'initialize protocol'
%sbttl 'TOPS-20 Specific DTE Routines'


!
! Macros
!

macro
    BOOT_ARG_BLOCK = vector [10] volatile %;	! BOOT JSYS argument block
%routine ('GET_DTE_SYSID', CD: ref CD_BLOCK) =

!++
! Function description:
!
!	This routine returns the system specific identifier
!	for the DTE described by the circuit data block.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!
! Routine value:
!
!	The system identifier for the DTE
!
!--

begin

    DECLARE_JSYS(BOOT);


    local
	BOOT_BLOCK: BOOT_ARG_BLOCK,	! BOOT JSYS argument block
        BOOT_ID : block [ch$allocation(10)];    ! To build device ID

    !
    ! Ask the system for its identifier for this DTE
    !

    $NMU$TEXT (%ref(ch$ptr(BOOT_ID,,8)), 10, 'DTE_%D',
                                             .CD[CD_DEVICE]);
    BOOT_BLOCK [$BTLID] = ch$ptr (BOOT_ID,,8);

    if not $$BOOT ($BTCLI, BOOT_BLOCK)
    then
	TASK_ERROR ('GET_DTE_SYSID called with invalid circuit id');

    .BOOT_BLOCK [$BTPRT]

end;				! of GET_DTE_SYSID
%routine ('OPEN_DTE_DEVICE', CD: ref CD_BLOCK, RSP_POINTER) =

!++
! Functional description:
!
!	This routine is called by NMU$DTE_OPEN to perform
!	system specific operations for servicing a DTE.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			System specific open succeeded
!	$false			Error opening DTE
!
!--

begin

    $true

end;				! of OPEN_DTE_DEVICE
%routine ('CLOSE_DTE_DEVICE', CD: ref CD_BLOCK) =

!++
! Functional description:
!
!	This routine is called by NMU$DTE_CLOSE to perform
!	system specific operations for releasing a DTE.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!
! Routine value:
!
!	$true			System specific release succeeded
!	$false			Error releasing DTE
!
!--

begin

    $true

end;				! of CLOSE_DTE_DEVICE
%routine ('START_PROTOCOL', CD: ref CD_BLOCK, RSP_POINTER) =

!++
! Function description:
!
!	This routine is used to initialize protocol on a
!	DTE circuit.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			Protocol successfully initialized
!	$false			Error initializing protocol
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	BOOT_BLOCK: BOOT_ARG_BLOCK,	! BOOT JSYS argument block
        COUNT;                          ! Local variable

    !
    ! Start primary protocol on the DTE
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];
    BOOT_BLOCK [$BTPRV] = $VNMCB;

    incr COUNT from 1 to 4 do
         begin

         if $$BOOT ($BTIPR, BOOT_BLOCK)
         then begin
              NMU$SCHED_PAUSE();        ! Give the others a chance to run
              return $true;             !  and return successfully
              end;
         NMU$SCHED_SLEEP(2);            ! Sleep two seconds before retrying
                                        ! (Time is chosen because DTESRV
                                        !  doorbell timeout is 1.5 seconds)

         end;

    $RESPONSE (.RSP_POINTER, NICE$_OPF, 0,
               'Could not start primary protocol on %X.  Status = %O',
               ch$ptr (CD [CD_NAME],,8),
               .BOOT_BLOCK [$BTERR]);
    return $false;

end;				! of START_PROTOCOL
%routine ('STOP_PROTOCOL', CD: ref CD_BLOCK, RSP_POINTER) =

!++
! Function description:
!
!	This routine is used to terminate protocol on a
!	DTE circuit.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			Protocol successfully terminated
!	$false			Error clearing protocol
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    !
    ! Set up argument block with DTE identifier
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];

    if not $$BOOT ($BTTPR, BOOT_BLOCK)
    then
	begin
	    $RESPONSE (.RSP_POINTER, NICE$_HWF, 0,
		       'Could not clear protocol on %X.  Status = %O',
		       ch$ptr (CD [CD_NAME],,8),
		       .BOOT_BLOCK [$BTERR]);
	    return $false;
	end;

    $true

end;				! of STOP_PROTOCOL
%routine ('DECNET_RUNNING', CD: ref CD_BLOCK, RSP_POINTER) =

!++
! Function description:
!
!	This routine is used to check if DECnet protocol is running on a
!	DTE circuit.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			DECnet protocol
!	$false			Not DECnet protocol
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    !
    ! Set up argument block with DTE identifier
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];

    if $$BOOT ($BTSTS, BOOT_BLOCK)
    then begin
         if .BOOT_BLOCK [$BTCOD] eql $VNMCB
         then return $true;
         end;
    return $false;

end;
%routine ('TRIGGER_ROM', CD: ref CD_BLOCK, RSP_POINTER) =

!++
! Function description:
!
!	This routine is called to trigger the DN20 boot-
!	strap ROM.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			Bootstrap ROM triggered successfully
!	$false			Error triggering bootstrap ROM
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    !
    ! Trigger DN20 ROM for LOAD and DUMP
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];
    BOOT_BLOCK [$BTERR] = 0;

    if not $$BOOT ($BTROM, BOOT_BLOCK)
    then
	begin
	    $RESPONSE (.RSP_POINTER, NICE$_HWF, 0,
		       'Could not trigger ROM bootstrap on %X.  Status = %O',
		       ch$ptr (CD [CD_NAME],,8),
		       .BOOT_BLOCK [$BTERR]);
	    return $false;
	end;

    NMU$SCHED_PAUSE ();

    $true

end;				! of TRIGGER_ROM
%routine ('ROM_DUMP', CD: ref CD_BLOCK, DUMP_PAGE, RSP_POINTER) =

!++
! Function description:
!
!	This routine is called to dump 2K bytes from the DN20
!	using the ROM.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.DUMP_PAGE		Page number to store dump data
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			Dump successful
!	$false			Error during ROM assisted dump
!
!--

begin

    DECLARE_JSYS (BOOT);

    literal
	MAX_ROM_DUMP_WORDS = %o'200';

    local
	COUNT,
	DUMP_COUNT,
	DUMP_POINTER,
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    !
    ! Initialize count of words dumped and dump pointer
    !

    DUMP_COUNT = 0;
    DUMP_POINTER = ch$ptr (.DUMP_PAGE^9,, 16);

    !
    ! Loop until dump page is filled with dump data
    !

    while .DUMP_COUNT lss (2 * 512)
    do
	begin

	    !
	    ! Setup argument block for next transfer of up
	    ! to MAX_ROM_DUMP_WORDS of DN20 memory.
	    !

	    COUNT = min ((2*512 - .DUMP_COUNT), MAX_ROM_DUMP_WORDS);
	    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];
	    BOOT_BLOCK [$BTERR] = 0;
	    BOOT_BLOCK [2] = 0;
	    BOOT_BLOCK [$BTFLG] = 0;
	    BOOT_BLOCK [$BTCNT] = .COUNT;
	    BOOT_BLOCK [$BTDPT] = .DUMP_POINTER;

	    !
	    ! Read dump data, assisted by primary boot ROM in DN20
	    !

	    if not $$BOOT ($BTDMP, BOOT_BLOCK)
	    then
		begin
		    $RESPONSE (.RSP_POINTER, NICE$_HWF, 0,
			       'ROM assisted dump failed on %X.  Status = %O',
			       ch$ptr (CD [CD_NAME],,8),
			       .BOOT_BLOCK [$BTERR]);
		    return $false;
		end;

	    NMU$SCHED_PAUSE ();

	    !
	    ! Update dump count and pointer
	    !

	    DUMP_COUNT = .DUMP_COUNT + .COUNT;
	    DUMP_POINTER = ch$plus (.DUMP_POINTER, .COUNT);

	end;

    $true

end;				! of ROM_DUMP
%routine ('READ_MOP_DATA', CD: ref CD_BLOCK, PTR, LEN, RSP_POINTER) =

!++
! Functional description:
!
!	This routine is used by NMU$DTE_READ to read a MOP data
!	messages from a DN20 front end.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.PTR			Pointer to message buffer
!	.LEN			Number of bytes in message buffer to write
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	Number of bytes read (-1 if error)
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    !
    ! First wait for DN20 to ring KL's doorbell
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];

    if not $$BOOT ($BTBEL, BOOT_BLOCK)
    then
	begin
	    $RESPONSE (.RSP_POINTER, NICE$_HWF, 0,
		       'DN20 on %X failed to ring KL doorbell',
		       ch$ptr (CD [CD_NAME],,8));
	    return -1;
	end;

    !
    ! Read MOP data message from DTE
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];
    BOOT_BLOCK [$BTERR] = 0;
    BOOT_BLOCK [2] = 0;
    BOOT_BLOCK [$BTFLG] = 0;
    BOOT_BLOCK [$BTCNT] = .LEN;
    BOOT_BLOCK [$BTMPT] = .PTR;

    if not $$BOOT ($BTRMP, BOOT_BLOCK)
    then
	begin
	    $RESPONSE (.RSP_POINTER, NICE$_OPF, 0,
		       'Failure reading MOP data on %X.  Status = %O',
		       ch$ptr (CD [CD_NAME],,8),
		       .BOOT_BLOCK [$BTERR]);
	    return -1;
	end;

    .BOOT_BLOCK [$BTCNT]

end;				! of READ_MOP_DATA
%routine ('WRITE_MOP_DATA', CD: ref CD_BLOCK, PTR, LEN, RSP_POINTER) =

!++
! Functional description:
!
!	This routine is used by NMU$DTE_WRITE to send MOP data
!	messages to a DN20 front end.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.PTR			Pointer to message buffer
!	.LEN			Number of bytes in message buffer to write
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			If successful
!	$false			If error
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    !
    ! Set up the BOOT JSYS argument block
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];
    BOOT_BLOCK [$BTERR] = 0;
    BOOT_BLOCK [2] = 0;
    BOOT_BLOCK [$BTFLG] = BT_BEL;
    BOOT_BLOCK [$BTCNT] = .LEN;
    BOOT_BLOCK [$BTLPT] = .PTR;

    !
    ! Send MOP message to DN20
    !

    if not $$BOOT ($BTLOD, BOOT_BLOCK)
    then
	begin
	    $RESPONSE (.RSP_POINTER, NICE$_OPF, 0,
		       'Failure sending MOP data on %X.  Status = %O',
		       ch$ptr (CD [CD_NAME],,8),
		       .BOOT_BLOCK [$BTERR]);
	    return $false;
	end;

    $true

end;				! of WRITE_MOP_DATA
%routine ('WRITE_SECONDARY_DATA', CD: ref CD_BLOCK, PTR, LEN, RSP_POINTER) =

!++
! Functional description:
!
!	This routine is used by NMU$DTE_WRITE to load the second-
!	ary bootstrap loader into a DN20 front end.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.PTR			Pointer to message buffer
!	.LEN			Number of bytes in message buffer to write
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			If successful
!	$false			If error
!
!--

begin

    DECLARE_JSYS (BOOT);

    local
	LOADER_PAGE,
	LOADER_POINTER,
        LOADER_ADDRESS,
	MOP_POINTER,
	BOOT_BLOCK: BOOT_ARG_BLOCK;	! BOOT JSYS argument block

    LOADER_PAGE = NMU$PAGE_GET () ;
    LOADER_ADDRESS = .LOADER_PAGE ^ 9;
    LOADER_POINTER = ch$ptr (.LOADER_ADDRESS,,16);
    MOP_POINTER = ch$plus (.PTR, 6);

    incr COUNT from 1 to (.LEN-8) by 2
    do
	ch$wchar_a (GETW (MOP_POINTER), LOADER_POINTER);

    !
    ! Set up the BOOT JSYS argument block
    !

    BOOT_BLOCK [$BTDTE] = .CD [CD_DTE_SYSID];
    BOOT_BLOCK [$BTERR] = 0;
    BOOT_BLOCK [$BTSEC] = .LOADER_ADDRESS;

    !
    ! Load the secondary bootstrap into the DN20
    !

    if not $$BOOT ($BTLDS, BOOT_BLOCK)
    then
	begin
	    $RESPONSE (.RSP_POINTER, NICE$_OPF, 0,
		       'Failure loading secondary boot on %X.  Status = %O',
		       ch$ptr (CD [CD_NAME],,8),
		       .BOOT_BLOCK [$BTERR]);
	    NMU$PAGE_RELEASE (.LOADER_PAGE);
	    return $false;
	end;

    NMU$PAGE_RELEASE (.LOADER_PAGE);

    NMU$SCHED_PAUSE ();

    $true

end;				! of WRITE_SECONDARY_DATA
%routine ('OWNER_IS_DECNET', CD : ref CD_BLOCK, RSP_POINTER) =

!++
! Functional description:
!
!	This routine is used by NMU$DTE_OPEN is insure that the
!	current user of a DTE is either DECNET or NML.  This is
!	to guarantee that NML doesn't interfere with ANF10 DTEs
!	or DTEs currently running diagnostics.
!
! Formal parameters:
!
!	.CD			Pointer to circuit data block
!	.RSP_POINTER		Pointer to NICE response buffer
!
! Routine value:
!
!	$true			If DTE owner is DECNET or NML
!	$false			If DTE owner isn't DECNET or NML
!
!--

begin

    $true

end;					! of OWNER_IS_DECNET