00001 /*BEGIN_LEGAL 00002 Intel Open Source License 00003 00004 Copyright (c) 2002-2015 Intel Corporation. All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are 00008 met: 00009 00010 Redistributions of source code must retain the above copyright notice, 00011 this list of conditions and the following disclaimer. Redistributions 00012 in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or 00014 other materials provided with the distribution. Neither the name of 00015 the Intel Corporation nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without 00017 specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 00023 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 END_LEGAL */ 00033 00034 #ifndef _XED_FLAGS_H_ 00035 # define _XED_FLAGS_H_ 00036 00037 #include "xed-types.h" 00038 #include "xed-portability.h" 00039 #include "xed-flag-enum.h" 00040 #include "xed-flag-action-enum.h" 00041 #include "xed-gen-table-defs.h" 00042 00043 00047 union xed_flag_set_s { 00048 xed_uint32_t flat; 00049 struct { 00050 xed_uint32_t cf:1; 00051 xed_uint32_t must_be_1:1; 00052 xed_uint32_t pf:1; 00053 xed_uint32_t must_be_0a:1; 00054 00055 xed_uint32_t af:1; 00056 xed_uint32_t must_be_0b:1; 00057 xed_uint32_t zf:1; 00058 xed_uint32_t sf:1; 00059 00060 xed_uint32_t tf:1; 00061 xed_uint32_t _if:1; 00062 xed_uint32_t df:1; 00063 xed_uint32_t of:1; 00064 00065 xed_uint32_t iopl:2; 00066 xed_uint32_t nt:1; 00067 xed_uint32_t must_be_0c:1; 00068 00069 xed_uint32_t rf:1; 00070 xed_uint32_t vm:1; 00071 xed_uint32_t ac:1; 00072 xed_uint32_t vif:1; 00073 00074 xed_uint32_t vip:1; 00075 xed_uint32_t id:1; 00076 xed_uint32_t must_be_0d:2; 00077 00078 xed_uint32_t must_be_0e:4; 00079 00080 // fc0,fc1,fc2,fc3 are not really part of rflags but I put them 00081 // here to save space. These bits are only used for x87 00082 // instructions. 00083 xed_uint32_t fc0:1; 00084 xed_uint32_t fc1:1; 00085 xed_uint32_t fc2:1; 00086 xed_uint32_t fc3:1; 00087 } s; 00088 00089 }; 00090 00091 typedef union xed_flag_set_s xed_flag_set_t; 00094 00095 00096 00097 XED_DLL_EXPORT int xed_flag_set_print(const xed_flag_set_t* p, char* buf, int buflen); 00101 XED_DLL_EXPORT xed_bool_t xed_flag_set_is_subset_of(const xed_flag_set_t* p, 00102 const xed_flag_set_t* other); 00104 00105 00107 00110 typedef struct xed_flag_enum_s { 00111 xed_flag_enum_t flag; 00112 // there are at most two actions per flag. The 2nd may be invalid. 00113 xed_flag_action_enum_t action; 00114 } xed_flag_action_t; 00115 00116 00117 00118 00121 00122 00123 00124 XED_DLL_EXPORT xed_flag_enum_t 00125 xed_flag_action_get_flag_name(const xed_flag_action_t* p); 00128 XED_DLL_EXPORT xed_flag_action_enum_t 00129 xed_flag_action_get_action(const xed_flag_action_t* p, unsigned int i); 00132 XED_DLL_EXPORT xed_bool_t 00133 xed_flag_action_action_invalid(const xed_flag_action_enum_t a); 00136 XED_DLL_EXPORT int xed_flag_action_print(const xed_flag_action_t* p, char* buf, int buflen); 00139 XED_DLL_EXPORT xed_bool_t 00140 xed_flag_action_read_flag(const xed_flag_action_t* p ); 00143 XED_DLL_EXPORT xed_bool_t 00144 xed_flag_action_writes_flag(const xed_flag_action_t* p); 00145 00148 XED_DLL_EXPORT xed_bool_t 00149 xed_flag_action_read_action( xed_flag_action_enum_t a); 00152 XED_DLL_EXPORT xed_bool_t 00153 xed_flag_action_write_action( xed_flag_action_enum_t a); 00155 00157 00160 typedef struct xed_simple_flag_s 00161 { 00163 xed_uint8_t nflags; 00164 00165 xed_uint8_t may_write; /* 1/0, only using one bit */ 00166 xed_uint8_t must_write; /* 1/0, only using one bit */ 00167 00169 xed_flag_set_t read; 00170 00172 xed_flag_set_t written; 00173 00175 xed_flag_set_t undefined; 00176 00177 // index in to the xed_flag_action_table. nflags limits the # of entries. 00178 xed_uint16_t fa_index; 00179 00180 } xed_simple_flag_t; 00181 00184 00185 00186 00187 XED_DLL_EXPORT unsigned int 00188 xed_simple_flag_get_nflags(const xed_simple_flag_t* p); 00189 00192 XED_DLL_EXPORT const xed_flag_set_t* 00193 xed_simple_flag_get_read_flag_set(const xed_simple_flag_t* p); 00194 00197 XED_DLL_EXPORT const xed_flag_set_t* 00198 xed_simple_flag_get_written_flag_set(const xed_simple_flag_t* p); 00199 00200 00203 XED_DLL_EXPORT const xed_flag_set_t* 00204 xed_simple_flag_get_undefined_flag_set(const xed_simple_flag_t* p); 00205 00209 XED_DLL_EXPORT xed_bool_t xed_simple_flag_get_may_write(const xed_simple_flag_t* p); 00210 00213 XED_DLL_EXPORT xed_bool_t xed_simple_flag_get_must_write(const xed_simple_flag_t* p); 00214 00217 XED_DLL_EXPORT const xed_flag_action_t* 00218 xed_simple_flag_get_flag_action(const xed_simple_flag_t* p, unsigned int i); 00219 00222 XED_DLL_EXPORT xed_bool_t 00223 xed_simple_flag_reads_flags(const xed_simple_flag_t* p); 00224 00227 XED_DLL_EXPORT xed_bool_t xed_simple_flag_writes_flags(const xed_simple_flag_t* p); 00228 00231 XED_DLL_EXPORT int xed_simple_flag_print(const xed_simple_flag_t* p, char* buf, int buflen); 00232 00235 static XED_INLINE int xed_flag_set_mask(const xed_flag_set_t* p) { 00236 return p->flat; // FIXME: could mask out the X87 flags 00237 } 00238 00240 00242 00243 00245 00246 #endif