Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / palacios / include / xed / xed-immdis.h
1 /*BEGIN_LEGAL 
2 Intel Open Source License 
3
4 Copyright (c) 2002-2007 Intel Corporation 
5 All rights reserved. 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.  Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution.  Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
18  
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 END_LEGAL */
31 /// @file xed-immdis.h
32 /// @author  Mark Charney   <mark.charney@intel.com> 
33
34
35
36 #ifndef _XED_IMMDIS_H_
37 # define _XED_IMMDIS_H_
38
39 #include <xed/xed-types.h>
40 #include <xed/xed-common-defs.h>
41 #include <xed/xed-util.h>
42
43
44 ////////////////////////////////////////////////////////////////////////////
45 // DEFINES
46 ////////////////////////////////////////////////////////////////////////////
47
48 ////////////////////////////////////////////////////////////////////////////
49 // TYPES
50 ////////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////////
52 // PROTOTYPES
53 ////////////////////////////////////////////////////////////////////////////
54
55 ////////////////////////////////////////////////////////////////////////////
56 // GLOBALS
57 ////////////////////////////////////////////////////////////////////////////
58
59 #define XED_MAX_IMMDIS_BYTES 8
60
61 // A union for speed of zeroing
62 union xed_immdis_values_t
63 {
64     xed_uint8_t x[XED_MAX_IMMDIS_BYTES];// STORED LITTLE ENDIAN. BYTE 0 is LSB
65     xed_uint64_t q;
66 };
67
68 /// Stores immediates and displacements for the encoder & decoder.
69 typedef struct XED_DLL_EXPORT xed_immdis_s {
70     union xed_immdis_values_t value;
71     unsigned int currently_used_space :4; // current number of assigned bytes
72     unsigned int max_allocated_space :4; // max allocation, 4 or 8
73     xed_bool_t present : 1;
74     xed_bool_t immediate_is_unsigned : 1;
75 } xed_immdis_t;
76
77 XED_DLL_EXPORT void xed_immdis__check(xed_immdis_t* q, int p) ;
78
79
80 XED_DLL_EXPORT void xed_immdis_init(xed_immdis_t* p, int max_bytes);
81
82 /// @name Sizes and lengths
83 //@{
84 /// return the number of bytes added
85 XED_DLL_EXPORT unsigned int xed_immdis_get_bytes(const xed_immdis_t* p) ;
86
87 //@}
88
89 /// @name Accessors for the value of the immediate or displacement
90 //@{
91 XED_DLL_EXPORT xed_int64_t 
92 xed_immdis_get_signed64(const xed_immdis_t* p);
93
94 XED_DLL_EXPORT xed_uint64_t 
95 xed_immdis_get_unsigned64(const xed_immdis_t* p);
96
97 XED_DLL_EXPORT xed_bool_t
98 xed_immdis_is_zero(const xed_immdis_t* p) ;
99
100 XED_DLL_EXPORT xed_bool_t
101 xed_immdis_is_one(const xed_immdis_t* p) ;
102
103 /// Access the i'th byte of the immediate
104 XED_DLL_EXPORT xed_uint8_t   xed_immdis_get_byte(const xed_immdis_t* p, unsigned int i) ;
105 //@}
106
107 /// @name Presence / absence of an immediate or displacement
108 //@{
109 XED_DLL_EXPORT void    xed_immdis_set_present(xed_immdis_t* p) ;
110
111 /// True if the object has had a value or individual bytes added to it.
112 XED_DLL_EXPORT xed_bool_t    xed_immdis_is_present(const xed_immdis_t* p) ;
113 //@}
114
115
116 /// @name Initialization and setup
117 //@{
118 XED_DLL_EXPORT void     xed_immdis_set_max_len(xed_immdis_t* p, unsigned int mx) ;
119 XED_DLL_EXPORT void
120 xed_immdis_zero(xed_immdis_t* p);
121
122 XED_DLL_EXPORT unsigned int    xed_immdis_get_max_length(const xed_immdis_t* p) ;
123
124 //@}
125
126 /// @name Signed vs Unsigned
127 //@{ 
128 /// Return true if  signed.
129 XED_DLL_EXPORT xed_bool_t
130 xed_immdis_is_unsigned(const xed_immdis_t* p) ;
131 /// Return true if signed.
132 XED_DLL_EXPORT xed_bool_t
133 xed_immdis_is_signed(const xed_immdis_t* p) ;
134     
135 /// Set the immediate to be signed; For decoder use only.
136 XED_DLL_EXPORT void 
137 xed_immdis_set_signed(xed_immdis_t* p) ;
138 /// Set the immediate to be unsigned; For decoder use only.
139 XED_DLL_EXPORT void 
140 xed_immdis_set_unsigned( xed_immdis_t* p) ;
141 //@}
142
143
144 /// @name Adding / setting values
145 //@{
146 XED_DLL_EXPORT void
147 xed_immdis_add_byte(xed_immdis_t* p, xed_uint8_t b);
148
149
150 XED_DLL_EXPORT void
151 xed_immdis_add_byte_array(xed_immdis_t* p, int nb, xed_uint8_t* ba);
152
153 /// Add 1, 2, 4 or 8 bytes depending on the value x and the mask of
154 /// legal_widths. The default value of legal_widths = 0x5 only stops
155 /// adding bytes only on 1 or 4 byte quantities - depending on which
156 /// bytes of x are zero -- as is used for most memory addressing.  You
157 /// can set legal_widths to 0x7 for branches (1, 2 or 4 byte branch
158 /// displacements). Or if you have an 8B displacement, you can set
159 /// legal_widths to 0x8. NOTE: add_shortest_width will add up to
160 /// XED_MAX_IMMDIS_BYTES if the x value requires it. NOTE: 16b memory
161 /// addressing can have 16b immediates.
162 XED_DLL_EXPORT void
163 xed_immdis_add_shortest_width_signed(xed_immdis_t* p, xed_int64_t x, xed_uint8_t legal_widths);
164
165 /// See add_shortest_width_signed()
166 XED_DLL_EXPORT void
167 xed_immdis_add_shortest_width_unsigned(xed_immdis_t* p, xed_uint64_t x, xed_uint8_t legal_widths );
168
169
170 /// add an 8 bit value to the byte array
171 XED_DLL_EXPORT void
172 xed_immdis_add8(xed_immdis_t* p, xed_int8_t d);
173
174 /// add a 16 bit value to the byte array
175 XED_DLL_EXPORT void
176 xed_immdis_add16(xed_immdis_t* p, xed_int16_t d);
177
178 /// add a 32 bit value to the byte array
179 XED_DLL_EXPORT void
180 xed_immdis_add32(xed_immdis_t* p, xed_int32_t d);
181
182 /// add a 64 bit value to the byte array.
183 XED_DLL_EXPORT void
184 xed_immdis_add64(xed_immdis_t* p, xed_int64_t d);
185
186 //@}
187
188
189 /// @name printing / debugging
190 //@{
191
192 /// just print the raw bytes in hex with a leading 0x
193 XED_DLL_EXPORT int xed_immdis_print(const xed_immdis_t* p, char* buf, int buflen);
194
195 /// Print the value as a signed or unsigned number depending on the
196 /// value of the immediate_is_unsigned variable.
197 XED_DLL_EXPORT int
198 xed_immdis_print_signed_or_unsigned(const xed_immdis_t* p, char* buf, int buflen);
199
200 /// print the signed value, appropriate width, with a leading 0x
201 XED_DLL_EXPORT int
202 xed_immdis_print_value_signed(const xed_immdis_t* p, char* buf, int buflen);
203
204 /// print the unsigned value, appropriate width, with a leading 0x
205 XED_DLL_EXPORT int
206 xed_immdis_print_value_unsigned(const xed_immdis_t* p, char* buf, int buflen);
207
208 int xed_immdis__print_ptr(const xed_immdis_t* p, char* buf, int buflen);
209 #endif
210
211 //@}
212
213
214 ////////////////////////////////////////////////////////////////////////////
215 //Local Variables:
216 //pref: "../../xed-immdis.c"
217 //End: