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