00001 /*BEGIN_LEGAL 00002 Copyright (c) 2004-2008, Intel Corp. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above 00013 copyright notice, this list of conditions and the following 00014 disclaimer in the documentation and/or other materials provided 00015 with the distribution. 00016 00017 * Neither the name of Intel Corporation nor the names of its 00018 contributors may be used to endorse or promote products derived 00019 from this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00025 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00029 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 END_LEGAL */ 00035 00036 00037 00038 #ifndef _XED_STATE_H_ 00039 # define _XED_STATE_H_ 00040 #include "xed-types.h" 00041 #include "xed-portability.h" 00042 #include "xed-address-width-enum.h" // generated 00043 #include "xed-machine-mode-enum.h" // generated 00044 00045 00054 typedef struct XED_DLL_EXPORT xed_state_s { 00056 xed_machine_mode_enum_t mmode; 00057 00059 xed_address_width_enum_t addr_width; 00060 00062 xed_address_width_enum_t stack_addr_width; 00063 } xed_state_t; 00064 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 static XED_INLINE void xed_state_init(xed_state_t* p, 00079 xed_machine_mode_enum_t arg_mmode, 00080 xed_address_width_enum_t arg_addr_width, 00081 xed_address_width_enum_t arg_stack_addr_width) { 00082 p->mmode=arg_mmode; 00083 (void)arg_addr_width; // NOT USED 00084 p->stack_addr_width=arg_stack_addr_width; 00085 } 00086 00089 static XED_INLINE void xed_state_zero(xed_state_t* p) { 00090 p->mmode= XED_MACHINE_MODE_INVALID; 00091 p->stack_addr_width=XED_ADDRESS_WIDTH_INVALID; 00092 } 00093 00095 00097 00098 00099 00100 static XED_INLINE xed_machine_mode_enum_t xed_state_get_machine_mode(const xed_state_t* p) { 00101 return p->mmode; 00102 } 00103 00104 00107 static XED_INLINE xed_bool_t xed_state_long64_mode(const xed_state_t* p) { 00108 return xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_64; 00109 } 00110 00112 static XED_INLINE xed_bool_t xed_state_real_mode(const xed_state_t* p) { 00113 return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_REAL_16); 00114 } 00115 00117 static XED_INLINE xed_bool_t xed_state_mode_width_16(const xed_state_t* p) { 00118 return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LEGACY_16) || 00119 (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_COMPAT_16); 00120 } 00121 00123 static XED_INLINE xed_bool_t xed_state_mode_width_32(const xed_state_t* p) { 00124 return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LEGACY_32) || 00125 (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_COMPAT_32); 00126 } 00127 00128 00131 static XED_INLINE void xed_state_set_machine_mode( xed_state_t* p, 00132 xed_machine_mode_enum_t arg_mode) { 00133 p->mmode = arg_mode; 00134 } 00136 00138 00139 00140 00141 static XED_INLINE void xed_state_set_address_width(xed_state_t* p, 00142 xed_address_width_enum_t arg_addr_width) { 00143 (void)p; 00144 (void)arg_addr_width; 00145 } 00146 00149 static XED_INLINE xed_address_width_enum_t xed_state_get_address_width(const xed_state_t* p) { 00150 switch(xed_state_get_machine_mode(p)) { 00151 case XED_MACHINE_MODE_LONG_64: 00152 return XED_ADDRESS_WIDTH_64b; 00153 00154 case XED_MACHINE_MODE_REAL_16: 00155 /* should be 20b... but if you are working w/real mode then you're 00156 going to have to deal with somehow. Could easily make this be 00157 20b if anyone cares. */ 00158 return XED_ADDRESS_WIDTH_32b; 00159 00160 case XED_MACHINE_MODE_LEGACY_32: 00161 case XED_MACHINE_MODE_LONG_COMPAT_32: 00162 return XED_ADDRESS_WIDTH_32b; 00163 case XED_MACHINE_MODE_LEGACY_16: 00164 case XED_MACHINE_MODE_LONG_COMPAT_16: 00165 return XED_ADDRESS_WIDTH_16b; 00166 default: 00167 return XED_ADDRESS_WIDTH_INVALID; 00168 } 00169 } 00170 00172 00174 00175 00176 00177 static XED_INLINE void xed_state_set_stack_address_width(xed_state_t* p, 00178 xed_address_width_enum_t arg_addr_width) { 00179 p->stack_addr_width = arg_addr_width; 00180 } 00181 00182 00185 static XED_INLINE xed_address_width_enum_t xed_state_get_stack_address_width(const xed_state_t* p) { 00186 return p->stack_addr_width; 00187 } 00189 00191 XED_DLL_EXPORT int xed_state_print(const xed_state_t* p, char* buf, int buflen); 00192 00193 #endif 00194 00196 //Local Variables: 00197 //pref: "../../xed-state.c" 00198 //End: