; ACCESS_PROT.MAR

;*****************************************************************************
; 
; AEON Systems, Inc.
; 8401 Washington PL NE
; Albuquerque, NM 87113
; (505) 828-9120
; 
; $Source: /afs/slac/g/lcls/cvs/epics/extensions/src/edm/util/misc/eln/access_prot.mar,v $
; 
; $Revision: 1.3 $			$Date: 2011/08/08 18:57:21 $
; 
; $Author: jrock $			$Locker:  $
; 
; FACILITY:	Machine Check Handler
; 
; ABSTRACT:	This module attempts to access a given memory location.
;		In the event a machine check occurs, execution continues
;		and a non-normal status is returned to the caller. It is
;		designed to be used to ensure that device adaptor memory
;		actually exists.
; 
; ENVIRONMENT:	VAXELN, Kernel mode, non-reentrant
; 
;*****************************************************************************

.ident "$Revision: 1.3 $"

.title access_protected_routine
.global access_protected

;*****************************************************************************
;
; FUNCTIONAL DESCRIPTION:
; 
; 	access_protected accesses a range of memory locations and traps
;	machine check errors. It is used to probe the existance of I/O
;	memory.
;
;
;	usage
;
;	  int access_protected ( char size_code, char access_mode,
;	   int num_words_to_check, void *address, int value );
;
; FORMAL ARGUMENTS:
;
;	size_code is one of 'L', 'W' or 'B' corresponding to a target
;	type of longword, word or byte
;
;	access_mode is either 'R' for read or 'W' for write
;
;	num_items_to_check gives the number of items for which access is
;	attempted
; 
;	address is the starting address location
;
;	value is the value to be written when access mode is 'W'
;
; COMPLETION CODES:
; 
;	KER$_NORMAL:	Successful routine completion
;
;	Other VAXELN status codes if not successful
; 
;*****************************************************************************

$mchkdef

.entry access_protected ^m<r2,r3,r4>

;	mchkprtct_init w^done,-
;			#<MCHK$M_NEXM!MCHK$M_MCHK!MCHK$M_LOG>
	pushal w^done
	pushl #<MCHK$M_NEXM!MCHK$M_MCHK!MCHK$M_LOG>
	jsb g^ker$machinechk_protect

	movl 20(ap), r1
	movl 16(ap), r2
	movl 12(ap), r3
	decl r3

	cmpb #^A/W/, 8(ap)
	beql write
	cmpb #^A/w/, 8(ap)
	bneq read

write:
	cmpb #^A/L/, 4(ap)
	beql long_write
	cmpb #^A/l/, 4(ap)
	beql long_write

	cmpb #^A/W/, 4(ap)
	beql word_write
	cmpb #^A/w/, 4(ap)
	beql word_write

	brw byte_write

read:
	cmpb #^A/L/, 4(ap)
	beql long_read
	cmpb #^A/l/, 4(ap)
	beql long_read

	cmpb #^A/W/, 4(ap)
	beql word_read
	cmpb #^A/w/, 4(ap)
	beql word_read

	brw byte_read

;;;;
; longword read
;
long_read:
	movl (r2)+, (r1)
	sobgeq r3, long_read
	rsb

;;;
; word read
;
word_read:
	movw (r2)+, (r1)
	sobgeq r3, word_read
	rsb

;;;
; byte read
;
byte_read:
	movb (r2)+, (r1)
	sobgeq r3, byte_read
	rsb

;;;;
; longword write
;
long_write:
	movl (r1), (r2)+
	sobgeq r3, long_write
	rsb

;;;
; word write
;
word_write:
	movw (r1), (r2)+
	sobgeq r3, word_write
	rsb

;;;
; byte write
;
byte_write:
	movb (r1), (r2)+
	sobgeq r3, byte_write
	rsb

;	MCHPRTCT_END done
done:
	ret

.end
