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