aboutsummaryrefslogtreecommitdiff
path: root/sys/nmemio/mgdptr.x
blob: 81328132dcbd51088683aa433f10b342a0a67223 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

# MGDPTR -- Given the fwa of a memory area, compute a pointer to the start
# of the data area which satisfies the desired alignment criteria.  Memory
# is allocated in units of chars, and ZLOCVA, ZMALOC, etc., return pointers
# in units of chars.

pointer procedure mgdptr (fwa, dtype, sz_align, fwa_align)

int	fwa, dtype, sz_align, fwa_align
long	bufadr
pointer	bufptr
int	modulus, loc_Mem
int	sizeof()
data	loc_Mem /NULL/

begin
	# Compute the address of the start of the user buffer area, which
	# must be aligned with fwa_align (usually Mem) for all data types.

	if (loc_Mem == NULL)
	    call zlocva (Memc, loc_Mem)
	bufadr = fwa + (5 * SZ_INT)

	modulus = mod (bufadr - fwa_align, sz_align)
	if (modulus != 0)
	    bufadr = bufadr + (sz_align - modulus)

	# Compute the buffer pointer for the desired datatype.
	bufptr = (bufadr - loc_Mem) / sizeof(dtype) + 1

	return (bufptr)
end