
	.TITLE	MISC "Random but useful routines"
	.IDENT /v1.0/
;+
; Facility:
;	MISC.MAR - Miscellaneous routines that need to be written in MACRO
;
; Abstract:
;
; Author:
;	Bruce R. Miller, MILLER@TGV.COM
;	TGV, Inc.
;	603 Mission St.
;	Santa Cruz, CA 95060
;	(408) 427-4366
;
; Date:
;	20-MAY-1991
;
; Functional Description:
;
; Copyright (c) 1991 Bruce R. Miller
; All rights reserved.
;
;	Redistribution and use in source and binary forms are permitted
;	provided that the above copyright notice and this paragraph are
;	duplicated in all such forms and that any documentation,
;	advertising materials, and other materials related to such
;	distribution and use acknowledge that the software was developed
;	by Bruce R. Miller.
;	THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR
;	IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
;	WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
;
;Modifications:
;
;-

	.link		"sys$system:sys.stb"/SELECTIVE_SEARCH
	.library	"sys$Library:lib.mlb"

	$IODEF
	$PSLDEF
	$SSDEF
	$CCBDEF
	$DDBDEF
	$DDTDEF
	$IPLDEF
	$PRDEF
	$PSLDEF
	$UCBDEF

;
; Find_Template_UCB does just that.  Given a channel number, which it
; assumes is valid, it find the CCB, finds the UCB, finds the DDB, then
; it uses the first UCB, which it assumes to be the 


.entry Find_DDB,^M<R2,R3,R4>
	; Now we want to lock down the I/O database before proceeding
;	MOVL    G^CTL$GL_PCB,R4			; get my PCB address
;	JSB	G^SCH$IOLOCKW			; lock & return

	MOVL	4(AP),R0
	MNEGL	R0,R1				; get negative offset
	MOVL	G^CTL$GL_CCBBASE,R2		; get CCB vector high address
	MOVAB	(R2)[R1],R0			; get Channel Control Block
	MOVL	CCB$L_UCB(R0),R0		; get Unit Control Block
	BEQL	100$				; fail if non-existant
	MOVL	UCB$L_DDB(R0),R0		; Get Device Data Block

;	BEQL	100$				; fail if non-existant
;	MOVL	DDB$L_UCB(R0),R0		; Get first UCB
;	BEQL	100$				; fail if non-existant
;	MOVZWL	UCB$W_UNIT(R0),R1		; get unit number
;	BNEQ	100$				; fail if not unit zero

100$:	; Unlock the I/O database and return
;	PUSHL	R0
;	MOVL	G^CTL$GL_PCB,R4			; get PCB
;	JSB	G^SCH$IOUNLOCK			; unlock I/O database
;	ENBINT	SRC=#0				; Set IPL to 0
;	POPL	R0
	RET					; return

.entry	Find_DDT,^m<R2,R7>
	PUSHL	4(AP)				; push channel number
	CALLS	#1,Find_DDB			; Get DDB
	BEQL	100$				; If failed exit error

	MOVL	DDB$L_DDT(R0),R1		; Get Driver Dispatch Table
	MOVL	#SS$_NORMAL,R0			; success

100$:	RET



.entry	Crash_VMS,^m<>
	JMP	@#^xFFFFFFFF			; that'll do it

.entry	Halt_VAX,^m<>
	HALT					; Yes, it's that simple

.end
