File: /usr/src/linux/include/asm-arm/arch-sa1100/bitfield.h

1     /*
2      *	FILE    	bitfield.h
3      *
4      *	Version 	1.1
5      *	Author  	Copyright (c) Marc A. Viredaz, 1998
6      *	        	DEC Western Research Laboratory, Palo Alto, CA
7      *	Date    	April 1998 (April 1997)
8      *	System  	Advanced RISC Machine (ARM)
9      *	Language	C or ARM Assembly
10      *	Purpose 	Definition of macros to operate on bit fields.
11      */
12     
13     
14     
15     #ifndef BITFIELD
16     #define BITFIELD
17     
18     #ifndef LANGUAGE
19     #define LANGUAGE	C
20     #endif /* !defined (LANGUAGE) */
21     
22     #define C       	0
23     #define Assembly	1
24     
25     #if LANGUAGE == C
26     #define UData(Data)	((unsigned int) (Data))
27     #elif LANGUAGE == Assembly
28     #define UData(Data)	(Data)
29     #endif /* LANGUAGE == C || LANGUAGE == Assembly */
30     
31     
32     /*
33      * MACRO: Fld
34      *
35      * Purpose
36      *    The macro "Fld" encodes a bit field, given its size and its shift value
37      *    with respect to bit 0.
38      *
39      * Note
40      *    A more intuitive way to encode bit fields would have been to use their
41      *    mask. However, extracting size and shift value information from a bit
42      *    field's mask is cumbersome and might break the assembler (255-character
43      *    line-size limit).
44      *
45      * Input
46      *    Size      	Size of the bit field, in number of bits.
47      *    Shft      	Shift value of the bit field with respect to bit 0.
48      *
49      * Output
50      *    Fld       	Encoded bit field.
51      */
52     
53     #define Fld(Size, Shft)	(((Size) << 16) + (Shft))
54     
55     
56     /*
57      * MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit
58      *
59      * Purpose
60      *    The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return
61      *    the size, shift value, mask, aligned mask, and first bit of a
62      *    bit field.
63      *
64      * Input
65      *    Field     	Encoded bit field (using the macro "Fld").
66      *
67      * Output
68      *    FSize     	Size of the bit field, in number of bits.
69      *    FShft     	Shift value of the bit field with respect to bit 0.
70      *    FMsk      	Mask for the bit field.
71      *    FAlnMsk   	Mask for the bit field, aligned on bit 0.
72      *    F1stBit   	First bit of the bit field.
73      */
74     
75     #define FSize(Field)	((Field) >> 16)
76     #define FShft(Field)	((Field) & 0x0000FFFF)
77     #define FMsk(Field)	(((UData (1) << FSize (Field)) - 1) << FShft (Field))
78     #define FAlnMsk(Field)	((UData (1) << FSize (Field)) - 1)
79     #define F1stBit(Field)	(UData (1) << FShft (Field))
80     
81     
82     /*
83      * MACRO: FInsrt
84      *
85      * Purpose
86      *    The macro "FInsrt" inserts a value into a bit field by shifting the
87      *    former appropriately.
88      *
89      * Input
90      *    Value     	Bit-field value.
91      *    Field     	Encoded bit field (using the macro "Fld").
92      *
93      * Output
94      *    FInsrt    	Bit-field value positioned appropriately.
95      */
96     
97     #define FInsrt(Value, Field) \
98                     	(UData (Value) << FShft (Field))
99     
100     
101     /*
102      * MACRO: FExtr
103      *
104      * Purpose
105      *    The macro "FExtr" extracts the value of a bit field by masking and
106      *    shifting it appropriately.
107      *
108      * Input
109      *    Data      	Data containing the bit-field to be extracted.
110      *    Field     	Encoded bit field (using the macro "Fld").
111      *
112      * Output
113      *    FExtr     	Bit-field value.
114      */
115     
116     #define FExtr(Data, Field) \
117                     	((UData (Data) >> FShft (Field)) & FAlnMsk (Field))
118     
119     
120     #undef C
121     #undef Assembly
122     
123     #endif /* !defined (BITFIELD) */
124