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] / misc / decoder_test / XED2 / include / xed / xed-state.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-state.h
32 /// @author  Mark Charney   <mark.charney@intel.com> 
33
34
35
36 #ifndef _XED_STATE_H_
37 # define _XED_STATE_H_
38 #include "xed-types.h"
39 #include "xed-portability.h"
40 #include "xed-address-width-enum.h" // generated
41 #include "xed-machine-mode-enum.h" // generated
42
43
44 /// Encapsulates machine modes for decoder/encoder requests.
45 /// It specifies the machine operating mode as a 
46 /// #xed_machine_mode_enum_t 
47 /// for decoding and encoding. For all modes other than the 64b long mode
48 /// (XED_MACHINE_MODE_LONG_64), a default addressing width, and a stack
49 /// addressing width must be supplied of type #xed_address_width_enum_t .
50 /// @ingroup INIT
51 typedef struct XED_DLL_EXPORT xed_state_s {
52   /// real architected machine modes
53   xed_machine_mode_enum_t mmode; 
54   
55   /// the current default addressing width.
56   xed_address_width_enum_t addr_width;
57   
58   /// for 16b/32b modes
59   xed_address_width_enum_t stack_addr_width; 
60 } xed_state_t;
61
62 /// @name Initialization
63 //@{
64 /// Constructor.
65 /// The mode, and addresses widths are enumerations that specify the number
66 /// of bits.  In 64b mode (#XED_MACHINE_MODE_LONG_64) the address width and
67 /// stack address widths are 64b (#XED_ADDRESS_WIDTH_64b). In other machine
68 /// modes, you must specify valid addressing widths.
69 ///
70 /// @param p the pointer to the #xed_state_t type
71 /// @param arg_mmode the machine mode of type #xed_machine_mode_enum_t
72 /// @param arg_addr_width the address width of type #xed_address_width_enum_t (only required if not the mode is not #XED_MACHINE_MODE_LONG_64)
73 /// @param arg_stack_addr_width the stack address width of type #xed_address_width_enum_t (only required if not the mode is not #XED_MACHINE_MODE_LONG_64)
74 /// @ingroup INIT
75 static XED_INLINE void xed_state_init(xed_state_t* p,
76                                       xed_machine_mode_enum_t arg_mmode,
77                                       xed_address_width_enum_t arg_addr_width,
78                                       xed_address_width_enum_t arg_stack_addr_width) {
79     p->mmode=arg_mmode;
80     p->addr_width=arg_addr_width;
81     p->stack_addr_width=arg_stack_addr_width;
82 }
83
84 /// clear the xed_state_t
85 /// @ingroup INIT
86 static XED_INLINE void xed_state_zero(xed_state_t* p) {
87     p->mmode= XED_MACHINE_MODE_INVALID;
88     p->addr_width=XED_ADDRESS_WIDTH_INVALID;
89     p->stack_addr_width=XED_ADDRESS_WIDTH_INVALID;
90 }
91
92 //@}
93
94 /// @name Machine mode
95 //@{
96 /// return the machine mode
97 /// @ingroup INIT
98 static XED_INLINE xed_machine_mode_enum_t   xed_state_get_machine_mode(const xed_state_t* p) {
99     return p->mmode; 
100 }
101
102
103 /// true iff the machine is in LONG_64 mode
104 /// @ingroup INIT
105 static XED_INLINE xed_bool_t xed_state_long64_mode(const xed_state_t* p) { 
106     return xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_64;
107 }
108
109 /// @ingroup INIT
110 static XED_INLINE xed_bool_t xed_state_mode_width_16(const xed_state_t* p) {
111     return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LEGACY_16) ||
112         (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_COMPAT_16);
113 }
114
115 /// @ingroup INIT
116 static XED_INLINE xed_bool_t xed_state_mode_width_32(const xed_state_t* p) {
117     return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LEGACY_32) ||
118         (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_COMPAT_32);
119 }
120   
121
122 /// Set the machine mode  
123 /// @ingroup INIT
124 static XED_INLINE void  xed_state_set_machine_mode( xed_state_t* p,
125                         xed_machine_mode_enum_t arg_mode)  {
126     p->mmode = arg_mode;
127 }
128 //@}
129
130 /// @name Address width
131 //@{
132 /// Set the address width
133 /// @ingroup INIT
134 static XED_INLINE void xed_state_set_address_width(xed_state_t* p,
135                                                    xed_address_width_enum_t arg_addr_width) {
136     p->addr_width = arg_addr_width;
137 }
138
139 /// return the address width
140 /// @ingroup INIT
141 static XED_INLINE xed_address_width_enum_t  xed_state_get_address_width(const xed_state_t* p) {
142     return p->addr_width;
143 }
144
145 //@}
146
147 /// @name Stack address width
148 //@{
149 /// set the STACK address width
150 /// @ingroup INIT
151 static XED_INLINE void  xed_state_set_stack_address_width(xed_state_t* p,
152                               xed_address_width_enum_t arg_addr_width) {
153     p->stack_addr_width = arg_addr_width;
154 }
155
156
157 /// Return the STACK address width
158 /// @ingroup INIT
159 static XED_INLINE xed_address_width_enum_t  xed_state_get_stack_address_width(const xed_state_t* p) {
160     return p->stack_addr_width;
161 }
162 //@}
163
164 /// @ingroup INIT
165 XED_DLL_EXPORT int xed_state_print(const xed_state_t* p, char* buf, int buflen);
166
167 #endif
168
169 ////////////////////////////////////////////////////////////////////////////
170 //Local Variables:
171 //pref: "../../xed-state.c"
172 //End: