]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/architecture/i386/reg_help.h
xnu-344.49.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / architecture / i386 / reg_help.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
26 *
27 * File: architecture/i386/reg_help.h
28 * Author: Mike DeMoney, NeXT Computer, Inc.
29 * Modified for i386 by: Bruce Martin, NeXT Computer, Inc.
30 *
31 * This header file defines cpp macros useful for defining
32 * machine register and doing machine-level operations.
33 *
34 * HISTORY
35 * 10-Mar-92 Bruce Martin (bmartin@next.com)
36 * Adapted to i386
37 * 23-Jan-91 Mike DeMoney (mike@next.com)
38 * Created.
39 */
40
41#ifndef _ARCH_I386_REG_HELP_H_
42#define _ARCH_I386_REG_HELP_H_
43
44/* Bitfield definition aid */
45#define BITS_WIDTH(msb, lsb) ((msb)-(lsb)+1)
46#define BIT_WIDTH(pos) (1) /* mostly to record the position */
47
48/* Mask creation */
49#define MKMASK(width, offset) (((unsigned)-1)>>(32-(width))<<(offset))
50#define BITSMASK(msb, lsb) MKMASK(BITS_WIDTH(msb, lsb), lsb & 0x1f)
51#define BITMASK(pos) MKMASK(BIT_WIDTH(pos), pos & 0x1f)
52
53/* Register addresses */
54#if __ASSEMBLER__
55# define REG_ADDR(type, addr) (addr)
56#else /* __ASSEMBLER__ */
57# define REG_ADDR(type, addr) (*(volatile type *)(addr))
58#endif /* __ASSEMBLER__ */
59
60/* Cast a register to be an unsigned */
61#define CONTENTS(foo) (*(unsigned *) &(foo))
62
63/* Stack pointer must always be a multiple of 4 */
64#define STACK_INCR 4
65#define ROUND_FRAME(x) ((((unsigned)(x)) + STACK_INCR - 1) & ~(STACK_INCR-1))
66
67/* STRINGIFY -- perform all possible substitutions, then stringify */
68#define __STR(x) #x /* just a helper macro */
69#define STRINGIFY(x) __STR(x)
70
71/*
72 * REG_PAIR_DEF -- define a register pair
73 * Register pairs are appropriately aligned to allow access via
74 * ld.d and st.d.
75 *
76 * Usage:
77 * struct foo {
78 * REG_PAIR_DEF(
79 * bar_t *, barp,
80 * afu_t, afu
81 * );
82 * };
83 *
84 * Access to individual entries of the pair is via the REG_PAIR
85 * macro (below).
86 */
87#define REG_PAIR_DEF(type0, name0, type1, name1) \
88 struct { \
89 type0 name0 __attribute__(( aligned(8) )); \
90 type1 name1; \
91 } name0##_##name1
92
93/*
94 * REG_PAIR -- Macro to define names for accessing individual registers
95 * of register pairs.
96 *
97 * Usage:
98 * arg0 is first element of pair
99 * arg1 is second element of pair
100 * arg2 is desired element of pair
101 * eg:
102 * #define foo_barp REG_PAIR(barp, afu, afu)
103 */
104#define REG_PAIR(name0, name1, the_name) \
105 name0##_##name1.the_name
106
107#endif /* _ARCH_I386_REG_HELP_H_ */