1/* 2 * Copyright (c) 2004, Apple Computer, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 13 * its contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved. 29 * 30 * File: architecture/nrw/reg_help.h 31 * Author: Mike DeMoney, NeXT Computer, Inc. 32 * 33 * This header file defines cpp macros useful for defining 34 * machine register and doing machine-level operations. 35 * 36 * HISTORY 37 * 23-Jan-91 Mike DeMoney (mike@next.com) 38 * Created. 39 */ 40 41#ifndef _NRW_REG_HELP_H_ 42#define _NRW_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/* STRINGIFY -- perform all possible substitutions, then stringify */ 64#define __STR(x) #x /* just a helper macro */ 65#define STRINGIFY(x) __STR(x) 66 67 68#endif /* _NRW_REG_HELP_H_ */ 69