2 Intel Open Source License
4 Copyright (c) 2002-2007 Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
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.
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.
32 /// @author Mark Charney <mark.charney@intel.com>
37 # define _XED_STATE_H_
38 #include <xed/xed-types.h>
39 #include <xed/xed-portability.h>
40 #include <xed/xed-address-width-enum.h> // generated
41 #include <xed/xed-machine-mode-enum.h> // generated
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 .
51 typedef struct XED_DLL_EXPORT xed_state_s {
52 /// real architected machine modes
53 xed_machine_mode_enum_t mmode;
55 /// the current default addressing width.
56 xed_address_width_enum_t addr_width;
59 xed_address_width_enum_t stack_addr_width;
62 /// @name Initialization
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.
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)
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) {
80 p->addr_width=arg_addr_width;
81 p->stack_addr_width=arg_stack_addr_width;
84 /// clear the xed_state_t
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;
94 /// @name Machine mode
96 /// return the machine mode
98 static XED_INLINE xed_machine_mode_enum_t xed_state_get_machine_mode(const xed_state_t* p) {
103 /// true iff the machine is in LONG_64 mode
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;
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);
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);
122 /// Set the machine mode
124 static XED_INLINE void xed_state_set_machine_mode( xed_state_t* p,
125 xed_machine_mode_enum_t arg_mode) {
130 /// @name Address width
132 /// Set the address width
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;
139 /// return the address width
141 static XED_INLINE xed_address_width_enum_t xed_state_get_address_width(const xed_state_t* p) {
142 return p->addr_width;
147 /// @name Stack address width
149 /// set the STACK address width
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;
157 /// Return the STACK address width
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;
165 XED_DLL_EXPORT int xed_state_print(const xed_state_t* p, char* buf, int buflen);
169 ////////////////////////////////////////////////////////////////////////////
171 //pref: "../../xed-state.c"