1/*
2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef	_ARCH_ARM_REG_HELP_H_
25#define	_ARCH_ARM_REG_HELP_H_
26
27/* Bitfield definition aid */
28#define	BITS_WIDTH(msb, lsb)	((msb)-(lsb)+1)
29#define	BIT_WIDTH(pos)		(1)	/* mostly to record the position */
30
31/* Mask creation */
32#define	MKMASK(width, offset)	(((unsigned)-1)>>(32-(width))<<(offset))
33#define	BITSMASK(msb, lsb)	MKMASK(BITS_WIDTH(msb, lsb), lsb & 0x1f)
34#define	BITMASK(pos)		MKMASK(BIT_WIDTH(pos), pos & 0x1f)
35
36/* Register addresses */
37#if	__ASSEMBLER__
38# define	REG_ADDR(type, addr)	(addr)
39#else	/* __ASSEMBLER__ */
40# define	REG_ADDR(type, addr)	(*(volatile type *)(addr))
41#endif	/* __ASSEMBLER__ */
42
43/* Cast a register to be an unsigned */
44#if defined(__arm__)
45#define	CONTENTS(foo)	(*(unsigned*) &(foo))
46/* Stack pointer must always be a multiple of 4 */
47#define	STACK_INCR	4
48#else
49#error Unknown architecture.
50#endif
51
52#define	ROUND_FRAME(x)	((((unsigned)(x)) + STACK_INCR - 1) & ~(STACK_INCR-1))
53
54/* STRINGIFY -- perform all possible substitutions, then stringify */
55#define	__STR(x)	#x		/* just a helper macro */
56#define	STRINGIFY(x)	__STR(x)
57
58#endif	/* _ARCH_ARM_REG_HELP_H_ */
59