├── input_data └── drmemtrace.ls.1139582.4300.dir │ ├── raw │ ├── funclist.log │ ├── encodings.bin │ ├── modules.log │ └── drmemtrace.ls.1139582.8571.raw │ └── trace │ ├── serial_schedule.bin │ └── drmemtrace.ls.1139582.8571.trace ├── src ├── xed │ ├── lib │ │ ├── libxed.a │ │ └── libxed-ild.a │ └── include │ │ ├── xed-attributes.h │ │ ├── xed-init-pointer-names.h │ │ ├── xed-encode-check.h │ │ ├── xed-version.h │ │ ├── xed-operand-ctype-map.h │ │ ├── xed-init.h │ │ ├── xed-convert-table-init.h │ │ ├── xed-encoder-gen-defs.h │ │ ├── xed-isa-set.h │ │ ├── xed-common-defs.h │ │ ├── xed-gen-table-defs.h │ │ ├── xed-chip-features.h │ │ ├── xed-operand-action.h │ │ ├── xed-immed.h │ │ ├── xed-build-defines.h │ │ ├── xed-cpuid-rec.h │ │ ├── xed-common-hdrs.h │ │ ├── xed-syntax-enum.h │ │ ├── xed-address-width-enum.h │ │ ├── xed-operand-convert-enum.h │ │ ├── xed-operand-visibility-enum.h │ │ ├── xed-format-options.h │ │ ├── xed-reg-class.h │ │ ├── xed-ild.h │ │ ├── xed-disas.h │ │ ├── xed-operand-type-enum.h │ │ ├── xed-patch.h │ │ ├── xed-reg-role-enum.h │ │ ├── xed-flag-action-enum.h │ │ ├── xed-machine-mode-enum.h │ │ ├── xed-operand-action-enum.h │ │ ├── xed-operand-ctype-enum.h │ │ ├── xed-interface.h │ │ ├── xed-rep-prefix.h │ │ ├── xed-get-time.h │ │ ├── xed-encoder-iforms.h │ │ ├── xed-mapu-enum.h │ │ ├── xed-ild-enum.h │ │ ├── xed-agen.h │ │ ├── xed-decode.h │ │ ├── xed-flag-enum.h │ │ ├── xed-operand-element-type-enum.h │ │ ├── xed-decoded-inst.h │ │ ├── xed-print-info.h │ │ ├── xed-reg-class-enum.h │ │ ├── xed-types.h │ │ ├── xed-operand-element-xtype-enum.h │ │ ├── xed-encode-direct.h │ │ ├── xed-error-enum.h │ │ ├── xed-iform-map.h │ │ ├── xed-operand-storage.h │ │ ├── xed-portability.h │ │ ├── xed-exception-enum.h │ │ ├── xed-chip-enum.h │ │ ├── xed-immdis.h │ │ ├── xed-state.h │ │ └── xed-flags.h └── trace │ ├── headers │ ├── analyzer_runner.h │ ├── dead_code_analysis.h │ ├── record_file_reader.cpp │ ├── directory_iterator.h │ ├── utils.h │ ├── memtrace_stream.h │ └── memref.h │ └── cpps │ ├── main.cpp │ ├── analyzer_runner.cpp │ ├── trace_entry.cpp │ ├── directory_iterator.cpp │ └── file_reader.cpp ├── poster-Feijiang Han.png ├── DynamoRIO-tutorial-feb2017.pdf ├── cpp.hint ├── .clang-format ├── CMakeLists.txt ├── .vscode └── settings.json └── README.md /input_data/drmemtrace.ls.1139582.4300.dir/raw/funclist.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /input_data/drmemtrace.ls.1139582.4300.dir/raw/encodings.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /input_data/drmemtrace.ls.1139582.4300.dir/trace/serial_schedule.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/xed/lib/libxed.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/src/xed/lib/libxed.a -------------------------------------------------------------------------------- /poster-Feijiang Han.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/poster-Feijiang Han.png -------------------------------------------------------------------------------- /src/xed/lib/libxed-ild.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/src/xed/lib/libxed-ild.a -------------------------------------------------------------------------------- /DynamoRIO-tutorial-feb2017.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/DynamoRIO-tutorial-feb2017.pdf -------------------------------------------------------------------------------- /cpp.hint: -------------------------------------------------------------------------------- 1 | // 提示文件帮助 Visual Studio IDE 解释 Visual C++ 标识符, 2 | // 如函数和宏的名称。 3 | // 有关详细信息,请参见 https://go.microsoft.com/fwlink/?linkid=865984 4 | #define START_PACKED_STRUCTURE 5 | -------------------------------------------------------------------------------- /input_data/drmemtrace.ls.1139582.4300.dir/raw/modules.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/input_data/drmemtrace.ls.1139582.4300.dir/raw/modules.log -------------------------------------------------------------------------------- /input_data/drmemtrace.ls.1139582.4300.dir/raw/drmemtrace.ls.1139582.8571.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/input_data/drmemtrace.ls.1139582.4300.dir/raw/drmemtrace.ls.1139582.8571.raw -------------------------------------------------------------------------------- /input_data/drmemtrace.ls.1139582.4300.dir/trace/drmemtrace.ls.1139582.8571.trace: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeijiangHan/dead_code_analyzer/HEAD/input_data/drmemtrace.ls.1139582.4300.dir/trace/drmemtrace.ls.1139582.8571.trace -------------------------------------------------------------------------------- /src/trace/headers/analyzer_runner.h: -------------------------------------------------------------------------------- 1 | /* analyzer_runner: represent a memory trace analysis tool that can process 2 | * a trace from multiple inputs: a file, from a raw file, or over a pipe online. 3 | */ 4 | 5 | #ifndef _ANALYZER_RUNNER_H_ 6 | #define _ANALYZER_RUNNER_H_ 1 7 | 8 | #include "analyzer.h" 9 | 10 | class analyzer_runner_t : public analyzer_t { 11 | public: 12 | analyzer_runner_t(std::string tracedir, bool verbose); 13 | virtual ~analyzer_runner_t(); 14 | 15 | protected: 16 | bool 17 | create_analysis_tool(); 18 | bool 19 | init_analysis_tool(); 20 | void 21 | destroy_analysis_tool(); 22 | }; 23 | 24 | #endif /* _ANALYZER_RUNNER_H_ */ 25 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | AlignTrailingComments: true 4 | AllowShortBlocksOnASingleLine: false 5 | AllowShortCaseLabelsOnASingleLine: true 6 | AllowShortFunctionsOnASingleLine: false 7 | AllowShortIfStatementsOnASingleLine: false 8 | AlwaysBreakAfterDefinitionReturnType: All 9 | AlwaysBreakAfterReturnType: All 10 | AlignAfterOpenBracket: Align 11 | AlignEscapedNewlines: Left 12 | BinPackArguments: true 13 | BinPackParameters: true 14 | BreakBeforeBinaryOperators: None 15 | ColumnLimit: 90 16 | FixNamespaceComments: true 17 | NamespaceIndentation: None 18 | IndentWidth: 4 19 | IndentPPDirectives: AfterHash 20 | PointerAlignment: Right 21 | CommentPragmas: '^ clang-format: ' 22 | SortIncludes: false 23 | MaxEmptyLinesToKeep: 1 24 | --- 25 | -------------------------------------------------------------------------------- /src/xed/include/xed-attributes.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | #if !defined(XED_ATTRIBUTES_H) 20 | # define XED_ATTRIBUTES_H 21 | #include "xed-types.h" 22 | 23 | typedef struct { 24 | xed_uint64_t a1; 25 | xed_uint64_t a2; 26 | } xed_attributes_t; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/xed/include/xed-init-pointer-names.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-init-pointer-names.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_INIT_POINTER_NAMES_H) 24 | # define XED_INIT_POINTER_NAMES_H 25 | #include "xed-internal-header.h" 26 | #define XED_MAX_POINTER_NAMES 65 27 | #endif 28 | -------------------------------------------------------------------------------- /src/xed/include/xed-encode-check.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | 20 | #ifndef XED_ENCODE_CHECK_H 21 | # define XED_ENCODE_CHECK_H 22 | #include "xed-common-hdrs.h" 23 | #include "xed-types.h" 24 | 25 | 26 | /// turn off (or on) argument checking if using the checked encoder interface. 27 | /// values 1, 0 28 | /// @ingroup ENC2 29 | XED_DLL_EXPORT void xed_enc2_set_check_args(xed_bool_t on); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/xed/include/xed-version.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | #if !defined(XED_VERSION_H) 20 | # define XED_VERSION_H 21 | #include "xed-common-hdrs.h" 22 | 23 | ///@ingroup INIT 24 | /// Returns a string representing XED svn commit revision and time stamp. 25 | XED_DLL_EXPORT char const* xed_get_version(void); 26 | ///@ingroup INIT 27 | /// Returns a copyright string. 28 | XED_DLL_EXPORT char const* xed_get_copyright(void); 29 | #endif 30 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-ctype-map.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-ctype-map.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_CTYPE_MAP_H) 24 | # define XED_OPERAND_CTYPE_MAP_H 25 | #include "xed-internal-header.h" 26 | xed_operand_ctype_enum_t xed_operand_get_ctype(xed_operand_enum_t opname); 27 | unsigned int xed_operand_decider_get_width(xed_operand_enum_t opname); 28 | #endif 29 | -------------------------------------------------------------------------------- /src/xed/include/xed-init.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-init.h 19 | /// 20 | 21 | 22 | 23 | 24 | #if !defined(XED_INIT_H) 25 | # define XED_INIT_H 26 | 27 | 28 | /// @ingroup INIT 29 | /// This is the call to initialize the XED encode and decode tables. It 30 | /// must be called once before using XED. 31 | void XED_DLL_EXPORT xed_tables_init(void); 32 | 33 | //////////////////////////////////////////////////////////////////////////// 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/xed/include/xed-convert-table-init.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-convert-table-init.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_CONVERT_TABLE_INIT_H) 24 | # define XED_CONVERT_TABLE_INIT_H 25 | #include "xed-internal-header.h" 26 | typedef struct { 27 | 28 | const char** table_name; 29 | 30 | xed_operand_enum_t opnd; 31 | 32 | unsigned int limit; 33 | 34 | } xed_convert_table_t; 35 | extern xed_convert_table_t xed_convert_table[XED_OPERAND_CONVERT_LAST]; 36 | #endif 37 | -------------------------------------------------------------------------------- /src/xed/include/xed-encoder-gen-defs.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-encoder-gen-defs.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_ENCODER_GEN_DEFS_H) 24 | # define XED_ENCODER_GEN_DEFS_H 25 | #define XED_ENCODE_ORDER_MAX_ENTRIES 32 26 | #define XED_ENCODE_ORDER_MAX_OPERANDS 5 27 | #define XED_ENCODE_MAX_FB_PATTERNS 126 28 | #define XED_ENCODE_MAX_EMIT_PATTERNS 200 29 | #define XED_ENCODE_FB_VALUES_TABLE_SIZE 4285 30 | #define XED_ENCODE_MAX_IFORMS 7733 31 | #define XED_ENC_GROUPS 537 32 | #endif 33 | -------------------------------------------------------------------------------- /src/xed/include/xed-isa-set.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-isa-set.h 19 | 20 | 21 | #if !defined(XED_ISA_SET_H) 22 | # define XED_ISA_SET_H 23 | 24 | #include "xed-common-hdrs.h" 25 | #include "xed-types.h" 26 | #include "xed-isa-set-enum.h" /* generated */ 27 | #include "xed-chip-enum.h" /* generated */ 28 | 29 | /// @ingroup ISASET 30 | /// return 1 if the isa_set is part included in the specified chip, 0 31 | /// otherwise. 32 | XED_DLL_EXPORT xed_bool_t 33 | xed_isa_set_is_valid_for_chip(xed_isa_set_enum_t isa_set, 34 | xed_chip_enum_t chip); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/xed/include/xed-common-defs.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-common-defs.h 19 | /// @brief some pervasive defines 20 | 21 | 22 | 23 | #ifndef XED_COMMON_DEFS_H 24 | # define XED_COMMON_DEFS_H 25 | 26 | // for most things it is 4, but one 64b mov allows 8 27 | #define XED_MAX_DISPLACEMENT_BYTES 8 28 | 29 | // for most things it is max 4, but one 64b mov allows 8. 30 | #define XED_MAX_IMMEDIATE_BYTES 8 31 | 32 | #define XED_MAX_INSTRUCTION_BYTES 15 33 | 34 | 35 | #define XED_BYTE_MASK(x) ((x) & 0xFF) 36 | #define XED_BYTE_CAST(x) (XED_STATIC_CAST(xed_uint8_t,x)) 37 | 38 | #endif 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.7) 2 | # Project name 3 | project(deadcode) 4 | # Set compilation version 5 | set (CMAKE_CXX_STANDARD 14) 6 | # 1. Header files and cpp files of the project itself 7 | set(SOURCE_FILES 8 | src/trace/cpps/main.cpp 9 | src/trace/headers/directory_iterator.h src/trace/cpps/directory_iterator.cpp 10 | src/trace/headers/file_reader.h src/trace/cpps/file_reader.cpp 11 | src/trace/headers/reader.h src/trace/cpps/reader.cpp 12 | src/trace/headers/record_file_reader.h src/trace/headers/record_file_reader.cpp 13 | src/trace/headers/memref.h src/trace/headers/memtrace_stream.h src/trace/headers/utils.h 14 | src/trace/headers/trace_entry.h src/trace/cpps/trace_entry.cpp 15 | src/trace/headers/analyzer.h src/trace/cpps/analyzer.cpp 16 | src/trace/headers/analyzer_runner.h src/trace/cpps/analyzer_runner.cpp 17 | src/trace/headers/analysis_tool.h 18 | src/trace/headers/dead_code_analysis.h src/trace/cpps/dead_code_analysis.cpp) 19 | 20 | # Set external library links 21 | set(ZLIB_INCLUDE src/xed/include) 22 | set(ZLIB_LIBRARIES src/xed/lib) 23 | 24 | # Link external libraries 25 | include_directories(${ZLIB_INCLUDE}) 26 | link_directories(${ZLIB_LIBRARIES}) 27 | find_package (Threads) 28 | # Set compilation files 29 | add_executable(deadcode ${SOURCE_FILES}) 30 | 31 | # Link third-party libraries together 32 | target_link_libraries (deadcode libxed.a Threads::Threads) -------------------------------------------------------------------------------- /src/xed/include/xed-gen-table-defs.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-gen-table-defs.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_GEN_TABLE_DEFS_H) 24 | # define XED_GEN_TABLE_DEFS_H 25 | #define XED_ICLASS_NAME_STR_MAX 142 26 | #define XED_MAX_ATTRIBUTE_COUNT 99 27 | #define XED_MAX_INST_TABLE_NODES 7706 28 | #define XED_MAX_OPERAND_TABLE_NODES 1538 29 | #define XED_MAX_OPERAND_SEQUENCES 9059 30 | #define XED_MAX_REQUIRED_SIMPLE_FLAGS_ENTRIES 99 31 | #define XED_MAX_REQUIRED_COMPLEX_FLAGS_ENTRIES 37 32 | #define XED_MAX_GLOBAL_FLAG_ACTIONS 472 33 | #define XED_MAX_IFORMS_PER_ICLASS 26 34 | #define XED_MAX_REQUIRED_ATTRIBUTES 211 35 | #define XED_MAX_CONVERT_PATTERNS 5 36 | #define XED_MAX_DECORATIONS_PER_OPERAND 3 37 | #define XED_MAX_MAP_VEX 3 38 | #define XED_MAX_MAP_EVEX 6 39 | #endif 40 | -------------------------------------------------------------------------------- /src/xed/include/xed-chip-features.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | #if !defined(XED_CHIP_FEATURES_H) 20 | # define XED_CHIP_FEATURES_H 21 | 22 | #include "xed-common-hdrs.h" 23 | #include "xed-types.h" 24 | #include "xed-isa-set-enum.h" /* generated */ 25 | #include "xed-chip-enum.h" /* generated */ 26 | 27 | #define XED_FEATURE_VECTOR_MAX 6 28 | /// @ingroup ISASET 29 | typedef struct 30 | { 31 | xed_uint64_t f[XED_FEATURE_VECTOR_MAX]; 32 | } xed_chip_features_t; 33 | 34 | 35 | /// fill in the contents of p with the vector of chip features. 36 | XED_DLL_EXPORT void 37 | xed_get_chip_features(xed_chip_features_t* p, xed_chip_enum_t chip); 38 | 39 | /// present = 1 to turn the feature on. present=0 to remove the feature. 40 | XED_DLL_EXPORT void 41 | xed_modify_chip_features(xed_chip_features_t* p, 42 | xed_isa_set_enum_t isa_set, 43 | xed_bool_t present); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-action.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-action.h 19 | /// 20 | 21 | #if !defined(XED_OPERAND_ACTION_H) 22 | # define XED_OPERAND_ACTION_H 23 | 24 | #include "xed-types.h" 25 | #include "xed-operand-action-enum.h" 26 | 27 | XED_DLL_EXPORT xed_uint_t xed_operand_action_read(const xed_operand_action_enum_t rw); 28 | XED_DLL_EXPORT xed_uint_t xed_operand_action_read_only(const xed_operand_action_enum_t rw); 29 | XED_DLL_EXPORT xed_uint_t xed_operand_action_written(const xed_operand_action_enum_t rw); 30 | XED_DLL_EXPORT xed_uint_t xed_operand_action_written_only(const xed_operand_action_enum_t rw); 31 | XED_DLL_EXPORT xed_uint_t xed_operand_action_read_and_written(const xed_operand_action_enum_t rw); 32 | XED_DLL_EXPORT xed_uint_t xed_operand_action_conditional_read(const xed_operand_action_enum_t rw); 33 | XED_DLL_EXPORT xed_uint_t xed_operand_action_conditional_write(const xed_operand_action_enum_t rw); 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/xed/include/xed-immed.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-immed.h 19 | /// 20 | 21 | #ifndef XED_IMMED_H 22 | # define XED_IMMED_H 23 | 24 | #include "xed-types.h" 25 | #include "xed-common-defs.h" 26 | #include "xed-util.h" 27 | 28 | XED_DLL_EXPORT xed_int64_t xed_immed_from_bytes(xed_int8_t* bytes, xed_uint_t n); 29 | /* 30 | Convert an array of bytes representing a Little Endian byte ordering 31 | of a number (11 22 33 44 55.. 88), in to a a 64b SIGNED number. That gets 32 | stored in memory in little endian format of course. 33 | 34 | Input 11 22 33 44 55 66 77 88, 8 35 | Output 0x8877665544332211 (stored in memory as (lsb) 11 22 33 44 55 66 77 88 (msb)) 36 | 37 | Input f0, 1 38 | Output 0xffff_ffff_ffff_fff0 (stored in memory as f0 ff ff ff ff ff ff ff) 39 | 40 | Input f0 00, 2 41 | Output 0x0000_0000_0000_00F0 (stored in memory a f0 00 00 00 00 00 00 00) 42 | 43 | Input 03, 1 44 | Output 0x0000_0000_0000_0030 (stored in memory a 30 00 00 00 00 00 00 00) 45 | */ 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/xed/include/xed-build-defines.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | #if !defined(XED_BUILD_DEFINES_H) 19 | # define XED_BUILD_DEFINES_H 20 | 21 | # if !defined(XED_AMD_ENABLED) 22 | # define XED_AMD_ENABLED 23 | # endif 24 | # if !defined(XED_AVX) 25 | # define XED_AVX 26 | # endif 27 | # if !defined(XED_CET) 28 | # define XED_CET 29 | # endif 30 | # if !defined(XED_DECODER) 31 | # define XED_DECODER 32 | # endif 33 | # if !defined(XED_ENCODER) 34 | # define XED_ENCODER 35 | # endif 36 | # if !defined(XED_MPX) 37 | # define XED_MPX 38 | # endif 39 | # if !defined(XED_SUPPORTS_AVX512) 40 | # define XED_SUPPORTS_AVX512 41 | # endif 42 | # if !defined(XED_SUPPORTS_LZCNT_TZCNT) 43 | # define XED_SUPPORTS_LZCNT_TZCNT 44 | # endif 45 | # if !defined(XED_SUPPORTS_SHA) 46 | # define XED_SUPPORTS_SHA 47 | # endif 48 | # if !defined(XED_SUPPORTS_WBNOINVD) 49 | # define XED_SUPPORTS_WBNOINVD 50 | # endif 51 | # if !defined(XED_VERSION) 52 | # define XED_VERSION "v2022.10.11" 53 | # endif 54 | # if !defined(XED_VIA_ENABLED) 55 | # define XED_VIA_ENABLED 56 | # endif 57 | #endif 58 | -------------------------------------------------------------------------------- /src/trace/cpps/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../headers/analyzer_runner.h" 4 | 5 | /* 6 | * 检查命令行参数是否正确,如果不正确则输出使用说明并退出程序 7 | 创建一个analyzer_runner_t类型的对象,用来运行分析器 8 | 调用analyzer_runner_t的run()方法运行分析器,如果返回值为false则表示运行失败,输出错误信息并退出程序 9 | 调用analyzer_runner_t的print_stats()方法输出分析结果,如果返回值为false则表示输出结果失败,输出错误信息并退出程序。 10 | 释放analyzer_runner_t对象所占用的空间并结束程序. 11 | 这段代码还包含了一些宏定义,如FATAL_ERROR,用于在程序发生错误时输出错误信息并终止程序。 12 | * */ 13 | 14 | #define FATAL_ERROR(msg, ...) \ 15 | do { \ 16 | fprintf(stderr, "ERROR: " msg "\n", ##__VA_ARGS__); \ 17 | fflush(stderr); \ 18 | exit(1); \ 19 | } while (0) 20 | 21 | #define VERBOSE 0 22 | static analyzer_t *analyzer; 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | if (argc != 2) { 27 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 28 | return 1; 29 | } 30 | 31 | analyzer = new analyzer_runner_t(argv[1], VERBOSE); 32 | if (!*analyzer) { 33 | std::string error_string_ = analyzer->get_error_string(); 34 | FATAL_ERROR("failed to initialize analyzer%s%s", 35 | error_string_.empty() ? "" : ": ", error_string_.c_str()); 36 | } 37 | 38 | if (!analyzer->run()) { 39 | std::string error_string_ = analyzer->get_error_string(); 40 | FATAL_ERROR("failed to run analyzer%s%s", error_string_.empty() ? "" : ": ", 41 | error_string_.c_str()); 42 | } 43 | 44 | if (!analyzer->print_stats()) { 45 | std::string error_string_ = analyzer->get_error_string(); 46 | FATAL_ERROR("failed to print results%s%s", error_string_.empty() ? "" : ": ", 47 | error_string_.c_str()); 48 | } 49 | // release analyzer's space 50 | delete analyzer; 51 | 52 | return 0; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.h": "cpp", 4 | "algorithm": "cpp", 5 | "atomic": "cpp", 6 | "bit": "cpp", 7 | "bitset": "cpp", 8 | "cctype": "cpp", 9 | "clocale": "cpp", 10 | "cmath": "cpp", 11 | "compare": "cpp", 12 | "concepts": "cpp", 13 | "cstddef": "cpp", 14 | "cstdint": "cpp", 15 | "cstdio": "cpp", 16 | "cstdlib": "cpp", 17 | "cstring": "cpp", 18 | "ctime": "cpp", 19 | "cwchar": "cpp", 20 | "deque": "cpp", 21 | "exception": "cpp", 22 | "list": "cpp", 23 | "map": "cpp", 24 | "string": "cpp", 25 | "unordered_map": "cpp", 26 | "vector": "cpp", 27 | "fstream": "cpp", 28 | "initializer_list": "cpp", 29 | "iomanip": "cpp", 30 | "ios": "cpp", 31 | "iosfwd": "cpp", 32 | "iostream": "cpp", 33 | "istream": "cpp", 34 | "iterator": "cpp", 35 | "limits": "cpp", 36 | "memory": "cpp", 37 | "new": "cpp", 38 | "ostream": "cpp", 39 | "queue": "cpp", 40 | "ranges": "cpp", 41 | "ratio": "cpp", 42 | "span": "cpp", 43 | "sstream": "cpp", 44 | "stdexcept": "cpp", 45 | "stop_token": "cpp", 46 | "streambuf": "cpp", 47 | "system_error": "cpp", 48 | "thread": "cpp", 49 | "tuple": "cpp", 50 | "type_traits": "cpp", 51 | "typeinfo": "cpp", 52 | "utility": "cpp", 53 | "xfacet": "cpp", 54 | "xhash": "cpp", 55 | "xiosbase": "cpp", 56 | "xlocale": "cpp", 57 | "xlocinfo": "cpp", 58 | "xlocmon": "cpp", 59 | "xlocnum": "cpp", 60 | "xloctime": "cpp", 61 | "xmemory": "cpp", 62 | "xstddef": "cpp", 63 | "xstring": "cpp", 64 | "xtr1common": "cpp", 65 | "xtree": "cpp", 66 | "xutility": "cpp" 67 | } 68 | } -------------------------------------------------------------------------------- /src/xed/include/xed-cpuid-rec.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | #ifndef XED_CPUID_REC_H 20 | # define XED_CPUID_REC_H 21 | #include "xed-types.h" 22 | #include "xed-portability.h" 23 | #include "xed-cpuid-bit-enum.h" 24 | #include "xed-isa-set-enum.h" 25 | 26 | 27 | typedef struct { 28 | xed_uint32_t leaf; // cpuid leaf 29 | xed_uint32_t subleaf; // cpuid subleaf 30 | xed_uint32_t bit; // the bit number for the feature 31 | xed_reg_enum_t reg; // the register containing the bit (EAX,EBX,ECX,EDX) 32 | } xed_cpuid_rec_t; 33 | 34 | #define XED_MAX_CPUID_BITS_PER_ISA_SET (4) 35 | 36 | /// Returns the name of the i'th cpuid bit associated with this isa-set. 37 | /// Call this repeatedly, with 0 <= i < 38 | /// XED_MAX_CPUID_BITS_PER_ISA_SET. Give up when i == 39 | /// XED_MAX_CPUID_BITS_PER_ISA_SET or the return value is 40 | /// XED_CPUID_BIT_INVALID. 41 | XED_DLL_EXPORT 42 | xed_cpuid_bit_enum_t 43 | xed_get_cpuid_bit_for_isa_set(xed_isa_set_enum_t isaset, 44 | xed_uint_t i); 45 | 46 | /// This provides the details of the CPUID bit specification, if the 47 | /// enumeration value is not sufficient. Returns 1 on success and fills in 48 | /// the structure pointed to by p. Returns 0 on failure. 49 | XED_DLL_EXPORT 50 | xed_int_t 51 | xed_get_cpuid_rec(xed_cpuid_bit_enum_t cpuid_bit, 52 | xed_cpuid_rec_t* p); 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /src/xed/include/xed-common-hdrs.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-common-hdrs.h 19 | /// 20 | 21 | 22 | 23 | #ifndef XED_COMMON_HDRS_H 24 | # define XED_COMMON_HDRS_H 25 | 26 | 27 | 28 | #if defined(__FreeBSD__) || defined(__NetBSD__) 29 | # define XED_BSD 30 | #endif 31 | #if defined(__linux__) 32 | # define XED_LINUX 33 | #endif 34 | #if defined(_MSC_VER) 35 | # define XED_WINDOWS 36 | #endif 37 | #if defined(__APPLE__) 38 | # define XED_MAC 39 | #endif 40 | 41 | 42 | #if defined(XED_DLL) 43 | // __declspec(dllexport) works with GNU GCC or MS compilers, but not ICC 44 | // on linux 45 | 46 | # if defined(XED_WINDOWS) 47 | # define XED_DLL_EXPORT __declspec(dllexport) 48 | # define XED_DLL_IMPORT __declspec(dllimport) 49 | # elif defined(XED_LINUX) || defined(XED_BSD) || defined(XED_MAC) 50 | # define XED_DLL_EXPORT __attribute__((visibility("default"))) 51 | # define XED_DLL_IMPORT 52 | # else 53 | # define XED_DLL_EXPORT 54 | # define XED_DLL_IMPORT 55 | # endif 56 | 57 | # if defined(XED_BUILD) 58 | /* when building XED, we export symbols */ 59 | # define XED_DLL_GLOBAL XED_DLL_EXPORT 60 | # else 61 | /* when building XED clients, we import symbols */ 62 | # define XED_DLL_GLOBAL XED_DLL_IMPORT 63 | # endif 64 | #else 65 | # define XED_DLL_EXPORT 66 | # define XED_DLL_IMPORT 67 | # define XED_DLL_GLOBAL 68 | #endif 69 | 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /src/xed/include/xed-syntax-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-syntax-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_SYNTAX_ENUM_H) 24 | # define XED_SYNTAX_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_SYNTAX_INVALID_DEFINED 1 27 | #define XED_SYNTAX_XED_DEFINED 1 28 | #define XED_SYNTAX_ATT_DEFINED 1 29 | #define XED_SYNTAX_INTEL_DEFINED 1 30 | #define XED_SYNTAX_LAST_DEFINED 1 31 | typedef enum { 32 | XED_SYNTAX_INVALID, 33 | XED_SYNTAX_XED, ///< XED disassembly syntax 34 | XED_SYNTAX_ATT, ///< ATT SYSV disassembly syntax 35 | XED_SYNTAX_INTEL, ///< Intel disassembly syntax 36 | XED_SYNTAX_LAST 37 | } xed_syntax_enum_t; 38 | 39 | /// This converts strings to #xed_syntax_enum_t types. 40 | /// @param s A C-string. 41 | /// @return #xed_syntax_enum_t 42 | /// @ingroup ENUM 43 | XED_DLL_EXPORT xed_syntax_enum_t str2xed_syntax_enum_t(const char* s); 44 | /// This converts strings to #xed_syntax_enum_t types. 45 | /// @param p An enumeration element of type xed_syntax_enum_t. 46 | /// @return string 47 | /// @ingroup ENUM 48 | XED_DLL_EXPORT const char* xed_syntax_enum_t2str(const xed_syntax_enum_t p); 49 | 50 | /// Returns the last element of the enumeration 51 | /// @return xed_syntax_enum_t The last element of the enumeration. 52 | /// @ingroup ENUM 53 | XED_DLL_EXPORT xed_syntax_enum_t xed_syntax_enum_t_last(void); 54 | #endif 55 | -------------------------------------------------------------------------------- /src/xed/include/xed-address-width-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-address-width-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_ADDRESS_WIDTH_ENUM_H) 24 | # define XED_ADDRESS_WIDTH_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_ADDRESS_WIDTH_INVALID_DEFINED 1 27 | #define XED_ADDRESS_WIDTH_16b_DEFINED 1 28 | #define XED_ADDRESS_WIDTH_32b_DEFINED 1 29 | #define XED_ADDRESS_WIDTH_64b_DEFINED 1 30 | #define XED_ADDRESS_WIDTH_LAST_DEFINED 1 31 | typedef enum { 32 | XED_ADDRESS_WIDTH_INVALID=0, 33 | XED_ADDRESS_WIDTH_16b=2, ///< 16b addressing 34 | XED_ADDRESS_WIDTH_32b=4, ///< 32b addressing 35 | XED_ADDRESS_WIDTH_64b=8, ///< 64b addressing 36 | XED_ADDRESS_WIDTH_LAST 37 | } xed_address_width_enum_t; 38 | 39 | /// This converts strings to #xed_address_width_enum_t types. 40 | /// @param s A C-string. 41 | /// @return #xed_address_width_enum_t 42 | /// @ingroup ENUM 43 | XED_DLL_EXPORT xed_address_width_enum_t str2xed_address_width_enum_t(const char* s); 44 | /// This converts strings to #xed_address_width_enum_t types. 45 | /// @param p An enumeration element of type xed_address_width_enum_t. 46 | /// @return string 47 | /// @ingroup ENUM 48 | XED_DLL_EXPORT const char* xed_address_width_enum_t2str(const xed_address_width_enum_t p); 49 | 50 | /// Returns the last element of the enumeration 51 | /// @return xed_address_width_enum_t The last element of the enumeration. 52 | /// @ingroup ENUM 53 | XED_DLL_EXPORT xed_address_width_enum_t xed_address_width_enum_t_last(void); 54 | #endif 55 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-convert-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-convert-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_CONVERT_ENUM_H) 24 | # define XED_OPERAND_CONVERT_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPERAND_CONVERT_INVALID_DEFINED 1 27 | #define XED_OPERAND_CONVERT_ZEROSTR_DEFINED 1 28 | #define XED_OPERAND_CONVERT_SAESTR_DEFINED 1 29 | #define XED_OPERAND_CONVERT_ROUNDC_DEFINED 1 30 | #define XED_OPERAND_CONVERT_BCASTSTR_DEFINED 1 31 | #define XED_OPERAND_CONVERT_LAST_DEFINED 1 32 | typedef enum { 33 | XED_OPERAND_CONVERT_INVALID, 34 | XED_OPERAND_CONVERT_ZEROSTR, 35 | XED_OPERAND_CONVERT_SAESTR, 36 | XED_OPERAND_CONVERT_ROUNDC, 37 | XED_OPERAND_CONVERT_BCASTSTR, 38 | XED_OPERAND_CONVERT_LAST 39 | } xed_operand_convert_enum_t; 40 | 41 | /// This converts strings to #xed_operand_convert_enum_t types. 42 | /// @param s A C-string. 43 | /// @return #xed_operand_convert_enum_t 44 | /// @ingroup ENUM 45 | XED_DLL_EXPORT xed_operand_convert_enum_t str2xed_operand_convert_enum_t(const char* s); 46 | /// This converts strings to #xed_operand_convert_enum_t types. 47 | /// @param p An enumeration element of type xed_operand_convert_enum_t. 48 | /// @return string 49 | /// @ingroup ENUM 50 | XED_DLL_EXPORT const char* xed_operand_convert_enum_t2str(const xed_operand_convert_enum_t p); 51 | 52 | /// Returns the last element of the enumeration 53 | /// @return xed_operand_convert_enum_t The last element of the enumeration. 54 | /// @ingroup ENUM 55 | XED_DLL_EXPORT xed_operand_convert_enum_t xed_operand_convert_enum_t_last(void); 56 | #endif 57 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-visibility-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-visibility-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_VISIBILITY_ENUM_H) 24 | # define XED_OPERAND_VISIBILITY_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPVIS_INVALID_DEFINED 1 27 | #define XED_OPVIS_EXPLICIT_DEFINED 1 28 | #define XED_OPVIS_IMPLICIT_DEFINED 1 29 | #define XED_OPVIS_SUPPRESSED_DEFINED 1 30 | #define XED_OPVIS_LAST_DEFINED 1 31 | typedef enum { 32 | XED_OPVIS_INVALID, 33 | XED_OPVIS_EXPLICIT, ///< Shows up in operand encoding 34 | XED_OPVIS_IMPLICIT, ///< Part of the opcode, but listed as an operand 35 | XED_OPVIS_SUPPRESSED, ///< Part of the opcode, but not typically listed as an operand 36 | XED_OPVIS_LAST 37 | } xed_operand_visibility_enum_t; 38 | 39 | /// This converts strings to #xed_operand_visibility_enum_t types. 40 | /// @param s A C-string. 41 | /// @return #xed_operand_visibility_enum_t 42 | /// @ingroup ENUM 43 | XED_DLL_EXPORT xed_operand_visibility_enum_t str2xed_operand_visibility_enum_t(const char* s); 44 | /// This converts strings to #xed_operand_visibility_enum_t types. 45 | /// @param p An enumeration element of type xed_operand_visibility_enum_t. 46 | /// @return string 47 | /// @ingroup ENUM 48 | XED_DLL_EXPORT const char* xed_operand_visibility_enum_t2str(const xed_operand_visibility_enum_t p); 49 | 50 | /// Returns the last element of the enumeration 51 | /// @return xed_operand_visibility_enum_t The last element of the enumeration. 52 | /// @ingroup ENUM 53 | XED_DLL_EXPORT xed_operand_visibility_enum_t xed_operand_visibility_enum_t_last(void); 54 | #endif 55 | -------------------------------------------------------------------------------- /src/xed/include/xed-format-options.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-format-options.h 19 | 20 | 21 | #ifndef XED_FORMAT_OPTIONS_H 22 | # define XED_FORMAT_OPTIONS_H 23 | #include "xed-types.h" 24 | 25 | 26 | /// @name Formatting options 27 | //@{ 28 | 29 | /// Options for the disasembly formatting functions. Set once during 30 | /// initialization by a calling #xed_format_set_options 31 | /// @ingroup PRINT 32 | typedef struct { 33 | /// by default, XED prints the hex address before any symbolic name for 34 | /// branch targets. If set to zero, then XED will not print the hex 35 | /// address before a valid symbolic name. 36 | unsigned int hex_address_before_symbolic_name; 37 | 38 | /// Simple XML output format for the Intel syntax disassembly. 39 | unsigned int xml_a; 40 | /// Include flags in the XML formatting (must also supply xml_a) 41 | unsigned int xml_f; 42 | 43 | /// omit unit scale "*1" 44 | unsigned int omit_unit_scale; 45 | 46 | /// do not sign extend signed immediates 47 | unsigned int no_sign_extend_signed_immediates; 48 | 49 | /// write-mask-with-curly-brackets, omit k0 50 | unsigned int write_mask_curly_k0; 51 | 52 | /// lowercase hexadecimal 53 | xed_bool_t lowercase_hex; 54 | 55 | /// Show negative memory displacements as 56 | /// positive numbers. 57 | xed_bool_t positive_memory_displacements; 58 | 59 | } xed_format_options_t; 60 | 61 | /// Optionally, customize the disassembly formatting options by passing 62 | /// in a #xed_format_options_t structure. 63 | /// @ingroup PRINT 64 | XED_DLL_EXPORT void 65 | xed_format_set_options(xed_format_options_t format_options); 66 | //@} 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/xed/include/xed-reg-class.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-reg-class.h 19 | /// 20 | 21 | #ifndef XED_REG_CLASS_H 22 | # define XED_REG_CLASS_H 23 | 24 | #include "xed-types.h" 25 | #include "xed-reg-enum.h" // a generated file 26 | #include "xed-reg-class-enum.h" // a generated file 27 | 28 | /// Returns the register class of the given input register. 29 | ///@ingroup REGINTFC 30 | XED_DLL_EXPORT xed_reg_class_enum_t xed_reg_class(xed_reg_enum_t r); 31 | 32 | /// Returns the specific width GPR reg class (like XED_REG_CLASS_GPR32 or 33 | /// XED_REG_CLASS_GPR64) 34 | /// for a given GPR register. Or XED_REG_INVALID if not a GPR. 35 | ///@ingroup REGINTFC 36 | XED_DLL_EXPORT xed_reg_class_enum_t xed_gpr_reg_class(xed_reg_enum_t r); 37 | 38 | /// Returns the largest enclosing register for any kind of register; This 39 | /// is mostly useful for GPRs. (64b mode assumed) 40 | ///@ingroup REGINTFC 41 | XED_DLL_EXPORT xed_reg_enum_t 42 | xed_get_largest_enclosing_register(xed_reg_enum_t r); 43 | 44 | /// Returns the largest enclosing register for any kind of register; This 45 | /// is mostly useful for GPRs in 32b mode. 46 | ///@ingroup REGINTFC 47 | XED_DLL_EXPORT xed_reg_enum_t 48 | xed_get_largest_enclosing_register32(xed_reg_enum_t r); 49 | 50 | /// Returns the width, in bits, of the named register. 32b mode 51 | ///@ingroup REGINTFC 52 | XED_DLL_EXPORT xed_uint32_t 53 | xed_get_register_width_bits(xed_reg_enum_t r); 54 | 55 | /// Returns the width, in bits, of the named register. 64b mode. 56 | ///@ingroup REGINTFC 57 | XED_DLL_EXPORT xed_uint32_t 58 | xed_get_register_width_bits64(xed_reg_enum_t r); 59 | 60 | //////////////////////////////////////////////////////////////////////////// 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/xed/include/xed-ild.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | /// @file xed-ild.h 20 | /// instruction length decoder 21 | 22 | #if !defined(XED_ILD_H) 23 | # define XED_ILD_H 24 | #include "xed-common-hdrs.h" 25 | #include "xed-common-defs.h" 26 | #include "xed-portability.h" 27 | #include "xed-types.h" 28 | #include "xed-decoded-inst.h" 29 | 30 | #include "xed-operand-accessors.h" 31 | 32 | 33 | /// This function just does instruction length decoding. 34 | /// It does not return a fully decoded instruction. 35 | /// @param xedd the decoded instruction of type #xed_decoded_inst_t . 36 | /// Mode/state sent in via xedd; See the #xed_state_t . 37 | /// @param itext the pointer to the array of instruction text bytes 38 | /// @param bytes the length of the itext input array. 39 | /// 1 to 15 bytes, anything more is ignored. 40 | /// @return #xed_error_enum_t indicating success (#XED_ERROR_NONE) or 41 | /// failure. 42 | /// Only two failure codes are valid for this function: 43 | /// #XED_ERROR_BUFFER_TOO_SHORT and #XED_ERROR_GENERAL_ERROR. 44 | /// In general this function cannot tell if the instruction is valid or 45 | /// not. For valid instructions, XED can figure out if enough bytes were 46 | /// provided to decode the instruction. If not enough were provided, 47 | /// XED returns #XED_ERROR_BUFFER_TOO_SHORT. 48 | /// From this function, the #XED_ERROR_GENERAL_ERROR is an indication 49 | /// that XED could not decode the instruction's length because the 50 | /// instruction was so invalid that even its length 51 | /// may across implmentations. 52 | /// 53 | /// @ingroup DEC 54 | XED_DLL_EXPORT xed_error_enum_t 55 | xed_ild_decode(xed_decoded_inst_t* xedd, 56 | const xed_uint8_t* itext, 57 | const unsigned int bytes); 58 | 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /src/xed/include/xed-disas.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-disas.h 19 | /// 20 | 21 | #if !defined(XED_DISAS_H) 22 | # define XED_DISAS_H 23 | 24 | #include "xed-types.h" 25 | 26 | /// @ingroup PRINT 27 | /// A #xed_disassembly_callback_fn_t takes an address, a pointer to a 28 | /// symbol buffer of buffer_length bytes, and a pointer to an offset. The 29 | /// function fills in the symbol_buffer and sets the offset to the desired 30 | /// offset for that symbol. If the function succeeds, it returns 1. 31 | // The call back should return 0 if the buffer is not long enough to 32 | // include the null termination.If no symbolic information is 33 | // located, the function returns zero. 34 | /// @param address The input address for which we want symbolic name and offset 35 | /// @param symbol_buffer A buffer to hold the symbol name. The callback function should fill this in and terminate 36 | /// with a null byte. 37 | /// @param buffer_length The maximum length of the symbol_buffer including then null 38 | /// @param offset A pointer to a xed_uint64_t to hold the offset from the provided symbol. 39 | /// @param context This void* pointer passed to the disassembler's new interface so that the caller can identify 40 | /// the proper context against which to resolve the symbols. 41 | /// The disassembler passes this value to 42 | /// the callback. The legacy formatters 43 | /// that do not have context will pass zero for this parameter. 44 | /// @return 0 on failure, 1 on success. 45 | typedef int (*xed_disassembly_callback_fn_t)( 46 | xed_uint64_t address, 47 | char* symbol_buffer, 48 | xed_uint32_t buffer_length, 49 | xed_uint64_t* offset, 50 | void* context); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-type-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-type-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_TYPE_ENUM_H) 24 | # define XED_OPERAND_TYPE_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPERAND_TYPE_INVALID_DEFINED 1 27 | #define XED_OPERAND_TYPE_ERROR_DEFINED 1 28 | #define XED_OPERAND_TYPE_IMM_DEFINED 1 29 | #define XED_OPERAND_TYPE_IMM_CONST_DEFINED 1 30 | #define XED_OPERAND_TYPE_NT_LOOKUP_FN_DEFINED 1 31 | #define XED_OPERAND_TYPE_NT_LOOKUP_FN2_DEFINED 1 32 | #define XED_OPERAND_TYPE_NT_LOOKUP_FN4_DEFINED 1 33 | #define XED_OPERAND_TYPE_REG_DEFINED 1 34 | #define XED_OPERAND_TYPE_LAST_DEFINED 1 35 | typedef enum { 36 | XED_OPERAND_TYPE_INVALID, 37 | XED_OPERAND_TYPE_ERROR, 38 | XED_OPERAND_TYPE_IMM, 39 | XED_OPERAND_TYPE_IMM_CONST, 40 | XED_OPERAND_TYPE_NT_LOOKUP_FN, 41 | XED_OPERAND_TYPE_NT_LOOKUP_FN2, 42 | XED_OPERAND_TYPE_NT_LOOKUP_FN4, 43 | XED_OPERAND_TYPE_REG, 44 | XED_OPERAND_TYPE_LAST 45 | } xed_operand_type_enum_t; 46 | 47 | /// This converts strings to #xed_operand_type_enum_t types. 48 | /// @param s A C-string. 49 | /// @return #xed_operand_type_enum_t 50 | /// @ingroup ENUM 51 | XED_DLL_EXPORT xed_operand_type_enum_t str2xed_operand_type_enum_t(const char* s); 52 | /// This converts strings to #xed_operand_type_enum_t types. 53 | /// @param p An enumeration element of type xed_operand_type_enum_t. 54 | /// @return string 55 | /// @ingroup ENUM 56 | XED_DLL_EXPORT const char* xed_operand_type_enum_t2str(const xed_operand_type_enum_t p); 57 | 58 | /// Returns the last element of the enumeration 59 | /// @return xed_operand_type_enum_t The last element of the enumeration. 60 | /// @ingroup ENUM 61 | XED_DLL_EXPORT xed_operand_type_enum_t xed_operand_type_enum_t_last(void); 62 | #endif 63 | -------------------------------------------------------------------------------- /src/trace/cpps/analyzer_runner.cpp: -------------------------------------------------------------------------------- 1 | #include "../headers/analyzer.h" 2 | #include "../headers/analyzer_runner.h" 3 | #include "../headers/utils.h" 4 | #include "../headers/directory_iterator.h" 5 | #include "../headers/file_reader.h" 6 | #include "../headers/dead_code_analysis.h" 7 | 8 | analyzer_runner_t::analyzer_runner_t(std::string tracedir, bool verbose) 9 | { 10 | worker_count_ = 0; 11 | skip_instrs_ = false; 12 | parallel_ = false; 13 | 14 | if (!directory_iterator_t::is_directory(tracedir)) { 15 | success_ = false; 16 | error_string_ = "Directory does not exist: " + tracedir; 17 | return; 18 | } 19 | 20 | if (!create_analysis_tool()) { 21 | success_ = false; 22 | error_string_ = "Failed to create analysis tool"; 23 | return; 24 | } 25 | 26 | if (!init_file_reader(tracedir, verbose)) { 27 | success_ = false; 28 | error_string_ = "Failed to initialize file reader"; 29 | return; 30 | } 31 | 32 | if (!init_analysis_tool()) { 33 | success_ = false; 34 | error_string_ = "Failed to initialize analysis tool"; 35 | return; 36 | } 37 | } 38 | 39 | analyzer_runner_t::~analyzer_runner_t() 40 | { 41 | destroy_analysis_tool(); 42 | } 43 | 44 | bool 45 | analyzer_runner_t::create_analysis_tool() 46 | { 47 | tools_ = new analysis_tool_t *[1]; 48 | tools_[0] = dead_code_analysis_create(); 49 | if (tools_[0] == NULL) 50 | return false; 51 | if (!*tools_[0]) { 52 | std::string tool_error = tools_[0]->get_error_string(); 53 | if (tool_error.empty()) 54 | tool_error = "no error message provided."; 55 | error_string_ = "Tool failed to initialize: " + tool_error; 56 | delete tools_[0]; 57 | tools_[0] = NULL; 58 | return false; 59 | } 60 | num_tools_ = 1; 61 | return true; 62 | } 63 | 64 | bool 65 | analyzer_runner_t::init_analysis_tool() 66 | { 67 | std::string tool_error = tools_[0]->initialize_stream(serial_trace_iter_.get()); 68 | if (!tool_error.empty()) { 69 | error_string_ = "Tool failed to initialize: " + tool_error; 70 | delete tools_[0]; 71 | tools_[0] = NULL; 72 | return false; 73 | } 74 | return true; 75 | } 76 | 77 | void 78 | analyzer_runner_t::destroy_analysis_tool() 79 | { 80 | if (!success_) 81 | return; 82 | for (int i = 0; i < num_tools_; i++) 83 | delete tools_[i]; 84 | delete[] tools_; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/xed/include/xed-patch.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | #ifndef XED_PATCH_H 19 | # define XED_PATCH_H 20 | #include "xed-encoder-hl.h" 21 | 22 | /// @name Patching decoded instructions 23 | //@{ 24 | 25 | 26 | /// Replace a memory displacement. 27 | /// The widths of original displacement and replacement must match. 28 | /// @param xedd A decoded instruction. 29 | /// @param itext The corresponding encoder output, byte array. 30 | /// @param disp A xed_enc_displacement_t object describing the new displacement. 31 | /// @returns xed_bool_t 1=success, 0=failure 32 | /// @ingroup ENCHLPATCH 33 | XED_DLL_EXPORT xed_bool_t 34 | xed_patch_disp(xed_decoded_inst_t* xedd, 35 | xed_uint8_t* itext, 36 | xed_enc_displacement_t disp); 37 | 38 | /// Replace a branch displacement. 39 | /// The widths of original displacement and replacement must match. 40 | /// @param xedd A decoded instruction. 41 | /// @param itext The corresponding encoder output, byte array. 42 | /// @param disp A xed_encoder_operand_t object describing the new displacement. 43 | /// @returns xed_bool_t 1=success, 0=failure 44 | /// @ingroup ENCHLPATCH 45 | XED_DLL_EXPORT xed_bool_t 46 | xed_patch_relbr(xed_decoded_inst_t* xedd, 47 | xed_uint8_t* itext, 48 | xed_encoder_operand_t disp); 49 | 50 | /// Replace an imm0 immediate value. 51 | /// The widths of original immediate and replacement must match. 52 | /// @param xedd A decoded instruction. 53 | /// @param itext The corresponding encoder output, byte array. 54 | /// @param imm0 A xed_encoder_operand_t object describing the new immediate. 55 | /// @returns xed_bool_t 1=success, 0=failure 56 | /// @ingroup ENCHLPATCH 57 | XED_DLL_EXPORT xed_bool_t 58 | xed_patch_imm0(xed_decoded_inst_t* xedd, 59 | xed_uint8_t* itext, 60 | xed_encoder_operand_t imm0); 61 | 62 | //@} 63 | #endif 64 | -------------------------------------------------------------------------------- /src/xed/include/xed-reg-role-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-reg-role-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_REG_ROLE_ENUM_H) 24 | # define XED_REG_ROLE_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_REG_ROLE_INVALID_DEFINED 1 27 | #define XED_REG_ROLE_NORMAL_DEFINED 1 28 | #define XED_REG_ROLE_SEGREG0_DEFINED 1 29 | #define XED_REG_ROLE_SEGREG1_DEFINED 1 30 | #define XED_REG_ROLE_BASE0_DEFINED 1 31 | #define XED_REG_ROLE_BASE1_DEFINED 1 32 | #define XED_REG_ROLE_INDEX_DEFINED 1 33 | #define XED_REG_ROLE_LAST_DEFINED 1 34 | typedef enum { 35 | XED_REG_ROLE_INVALID, 36 | XED_REG_ROLE_NORMAL, ///< Register is a normal register 37 | XED_REG_ROLE_SEGREG0, ///< The segment register associated with the first memop 38 | XED_REG_ROLE_SEGREG1, ///< The segment register associated with the second memop 39 | XED_REG_ROLE_BASE0, ///< The base register associated with the first memop 40 | XED_REG_ROLE_BASE1, ///< The base register associated with the second memop 41 | XED_REG_ROLE_INDEX, ///< The index register associated with the first memop 42 | XED_REG_ROLE_LAST 43 | } xed_reg_role_enum_t; 44 | 45 | /// This converts strings to #xed_reg_role_enum_t types. 46 | /// @param s A C-string. 47 | /// @return #xed_reg_role_enum_t 48 | /// @ingroup ENUM 49 | XED_DLL_EXPORT xed_reg_role_enum_t str2xed_reg_role_enum_t(const char* s); 50 | /// This converts strings to #xed_reg_role_enum_t types. 51 | /// @param p An enumeration element of type xed_reg_role_enum_t. 52 | /// @return string 53 | /// @ingroup ENUM 54 | XED_DLL_EXPORT const char* xed_reg_role_enum_t2str(const xed_reg_role_enum_t p); 55 | 56 | /// Returns the last element of the enumeration 57 | /// @return xed_reg_role_enum_t The last element of the enumeration. 58 | /// @ingroup ENUM 59 | XED_DLL_EXPORT xed_reg_role_enum_t xed_reg_role_enum_t_last(void); 60 | #endif 61 | -------------------------------------------------------------------------------- /src/xed/include/xed-flag-action-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-flag-action-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_FLAG_ACTION_ENUM_H) 24 | # define XED_FLAG_ACTION_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_FLAG_ACTION_INVALID_DEFINED 1 27 | #define XED_FLAG_ACTION_u_DEFINED 1 28 | #define XED_FLAG_ACTION_tst_DEFINED 1 29 | #define XED_FLAG_ACTION_mod_DEFINED 1 30 | #define XED_FLAG_ACTION_0_DEFINED 1 31 | #define XED_FLAG_ACTION_pop_DEFINED 1 32 | #define XED_FLAG_ACTION_ah_DEFINED 1 33 | #define XED_FLAG_ACTION_1_DEFINED 1 34 | #define XED_FLAG_ACTION_LAST_DEFINED 1 35 | typedef enum { 36 | XED_FLAG_ACTION_INVALID, 37 | XED_FLAG_ACTION_u, ///< undefined (treated as a write) 38 | XED_FLAG_ACTION_tst, ///< test (read) 39 | XED_FLAG_ACTION_mod, ///< modification (write) 40 | XED_FLAG_ACTION_0, ///< value will be zero (write) 41 | XED_FLAG_ACTION_pop, ///< value comes from the stack (write) 42 | XED_FLAG_ACTION_ah, ///< value comes from AH (write) 43 | XED_FLAG_ACTION_1, ///< value will be 1 (write) 44 | XED_FLAG_ACTION_LAST 45 | } xed_flag_action_enum_t; 46 | 47 | /// This converts strings to #xed_flag_action_enum_t types. 48 | /// @param s A C-string. 49 | /// @return #xed_flag_action_enum_t 50 | /// @ingroup ENUM 51 | XED_DLL_EXPORT xed_flag_action_enum_t str2xed_flag_action_enum_t(const char* s); 52 | /// This converts strings to #xed_flag_action_enum_t types. 53 | /// @param p An enumeration element of type xed_flag_action_enum_t. 54 | /// @return string 55 | /// @ingroup ENUM 56 | XED_DLL_EXPORT const char* xed_flag_action_enum_t2str(const xed_flag_action_enum_t p); 57 | 58 | /// Returns the last element of the enumeration 59 | /// @return xed_flag_action_enum_t The last element of the enumeration. 60 | /// @ingroup ENUM 61 | XED_DLL_EXPORT xed_flag_action_enum_t xed_flag_action_enum_t_last(void); 62 | #endif 63 | -------------------------------------------------------------------------------- /src/trace/headers/dead_code_analysis.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEAD_CODE_ANALYSIS_H_ 2 | #define _DEAD_CODE_ANALYSIS_H_ 1 3 | 4 | #include "analysis_tool.h" 5 | #include "memref.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class read_write { 14 | public: 15 | bool read; 16 | bool write; 17 | // the previous instruction 18 | memref_t obj; 19 | 20 | int index_write; 21 | read_write() { 22 | read = false; 23 | write = false; 24 | index_write = 0; 25 | } 26 | }; 27 | 28 | class deadCode { 29 | public: 30 | memref_t obj; // key 31 | int index = -1; // index 32 | deadCode(){} 33 | deadCode(memref_t obj, int index){ 34 | obj = obj; 35 | index = index; 36 | } 37 | bool operator < (deadCode & dc) { 38 | return this->index < dc.index; 39 | } 40 | }; 41 | 42 | struct CodeNumber { 43 | int allCodeNumber = -1; 44 | int deadCodeNumber_read = 0; 45 | int deadCodeNumber_write = 0; 46 | }; 47 | 48 | 49 | // Hash function for pair objects 50 | struct pair_hash { 51 | template 52 | std::size_t operator()(const std::pair& p) const { 53 | return std::hash()(p.first) ^ std::hash()(p.second); 54 | } 55 | }; 56 | 57 | class dead_code_analysis_t : public analysis_tool_t { 58 | public: 59 | // Constructor 60 | dead_code_analysis_t(); 61 | // Destructor 62 | virtual ~dead_code_analysis_t(); 63 | // Processes a memory reference 64 | bool process_memref(const memref_t& memref) override; 65 | // Prints analysis results 66 | bool print_results() override; 67 | protected: 68 | // Number of read references 69 | uint64_t num_read_refs_; 70 | // Number of write references 71 | uint64_t num_write_refs_; 72 | private: 73 | // Counts for analysis stats 74 | CodeNumber number; 75 | // Map of address reads/writes per thread 76 | std::unordered_map, read_write*, pair_hash> addr_read_write; 77 | // Sorted dead code instructions 78 | std::vector sorted_deadCode; 79 | // Instruction corresponding to a memref 80 | memref_t ins_memref; 81 | // Adds dead code 82 | void addDeadCode(int index, const memref_t obj); 83 | // Initializes address mapping for thread 84 | void initAddrReadWrite_thread(memref_t memref); 85 | // Detects dead code 86 | void detectDeadCode_thread(memref_t memref); 87 | }; 88 | 89 | /** Creates an instance of a TLB simulator. */ 90 | analysis_tool_t * 91 | dead_code_analysis_create(void); 92 | 93 | #endif -------------------------------------------------------------------------------- /src/xed/include/xed-machine-mode-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-machine-mode-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_MACHINE_MODE_ENUM_H) 24 | # define XED_MACHINE_MODE_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_MACHINE_MODE_INVALID_DEFINED 1 27 | #define XED_MACHINE_MODE_LONG_64_DEFINED 1 28 | #define XED_MACHINE_MODE_LONG_COMPAT_32_DEFINED 1 29 | #define XED_MACHINE_MODE_LONG_COMPAT_16_DEFINED 1 30 | #define XED_MACHINE_MODE_LEGACY_32_DEFINED 1 31 | #define XED_MACHINE_MODE_LEGACY_16_DEFINED 1 32 | #define XED_MACHINE_MODE_REAL_16_DEFINED 1 33 | #define XED_MACHINE_MODE_REAL_32_DEFINED 1 34 | #define XED_MACHINE_MODE_LAST_DEFINED 1 35 | typedef enum { 36 | XED_MACHINE_MODE_INVALID, 37 | XED_MACHINE_MODE_LONG_64, ///< 64b operating mode 38 | XED_MACHINE_MODE_LONG_COMPAT_32, ///< 32b protected mode 39 | XED_MACHINE_MODE_LONG_COMPAT_16, ///< 16b protected mode 40 | XED_MACHINE_MODE_LEGACY_32, ///< 32b protected mode 41 | XED_MACHINE_MODE_LEGACY_16, ///< 16b protected mode 42 | XED_MACHINE_MODE_REAL_16, ///< 16b real mode 43 | XED_MACHINE_MODE_REAL_32, ///< 32b real mode (CS.D bit = 1) 44 | XED_MACHINE_MODE_LAST 45 | } xed_machine_mode_enum_t; 46 | 47 | /// This converts strings to #xed_machine_mode_enum_t types. 48 | /// @param s A C-string. 49 | /// @return #xed_machine_mode_enum_t 50 | /// @ingroup ENUM 51 | XED_DLL_EXPORT xed_machine_mode_enum_t str2xed_machine_mode_enum_t(const char* s); 52 | /// This converts strings to #xed_machine_mode_enum_t types. 53 | /// @param p An enumeration element of type xed_machine_mode_enum_t. 54 | /// @return string 55 | /// @ingroup ENUM 56 | XED_DLL_EXPORT const char* xed_machine_mode_enum_t2str(const xed_machine_mode_enum_t p); 57 | 58 | /// Returns the last element of the enumeration 59 | /// @return xed_machine_mode_enum_t The last element of the enumeration. 60 | /// @ingroup ENUM 61 | XED_DLL_EXPORT xed_machine_mode_enum_t xed_machine_mode_enum_t_last(void); 62 | #endif 63 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-action-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-action-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_ACTION_ENUM_H) 24 | # define XED_OPERAND_ACTION_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPERAND_ACTION_INVALID_DEFINED 1 27 | #define XED_OPERAND_ACTION_RW_DEFINED 1 28 | #define XED_OPERAND_ACTION_R_DEFINED 1 29 | #define XED_OPERAND_ACTION_W_DEFINED 1 30 | #define XED_OPERAND_ACTION_RCW_DEFINED 1 31 | #define XED_OPERAND_ACTION_CW_DEFINED 1 32 | #define XED_OPERAND_ACTION_CRW_DEFINED 1 33 | #define XED_OPERAND_ACTION_CR_DEFINED 1 34 | #define XED_OPERAND_ACTION_LAST_DEFINED 1 35 | typedef enum { 36 | XED_OPERAND_ACTION_INVALID, 37 | XED_OPERAND_ACTION_RW, ///< Read and written (must write) 38 | XED_OPERAND_ACTION_R, ///< Read-only 39 | XED_OPERAND_ACTION_W, ///< Write-only (must write) 40 | XED_OPERAND_ACTION_RCW, ///< Read and conditionlly written (may write) 41 | XED_OPERAND_ACTION_CW, ///< Conditionlly written (may write) 42 | XED_OPERAND_ACTION_CRW, ///< Conditionlly read, always written (must write) 43 | XED_OPERAND_ACTION_CR, ///< Conditional read 44 | XED_OPERAND_ACTION_LAST 45 | } xed_operand_action_enum_t; 46 | 47 | /// This converts strings to #xed_operand_action_enum_t types. 48 | /// @param s A C-string. 49 | /// @return #xed_operand_action_enum_t 50 | /// @ingroup ENUM 51 | XED_DLL_EXPORT xed_operand_action_enum_t str2xed_operand_action_enum_t(const char* s); 52 | /// This converts strings to #xed_operand_action_enum_t types. 53 | /// @param p An enumeration element of type xed_operand_action_enum_t. 54 | /// @return string 55 | /// @ingroup ENUM 56 | XED_DLL_EXPORT const char* xed_operand_action_enum_t2str(const xed_operand_action_enum_t p); 57 | 58 | /// Returns the last element of the enumeration 59 | /// @return xed_operand_action_enum_t The last element of the enumeration. 60 | /// @ingroup ENUM 61 | XED_DLL_EXPORT xed_operand_action_enum_t xed_operand_action_enum_t_last(void); 62 | #endif 63 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-ctype-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-ctype-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_CTYPE_ENUM_H) 24 | # define XED_OPERAND_CTYPE_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPERAND_CTYPE_INVALID_DEFINED 1 27 | #define XED_OPERAND_CTYPE_XED_BITS_T_DEFINED 1 28 | #define XED_OPERAND_CTYPE_XED_CHIP_ENUM_T_DEFINED 1 29 | #define XED_OPERAND_CTYPE_XED_ERROR_ENUM_T_DEFINED 1 30 | #define XED_OPERAND_CTYPE_XED_ICLASS_ENUM_T_DEFINED 1 31 | #define XED_OPERAND_CTYPE_XED_INT64_T_DEFINED 1 32 | #define XED_OPERAND_CTYPE_XED_REG_ENUM_T_DEFINED 1 33 | #define XED_OPERAND_CTYPE_XED_UINT16_T_DEFINED 1 34 | #define XED_OPERAND_CTYPE_XED_UINT64_T_DEFINED 1 35 | #define XED_OPERAND_CTYPE_XED_UINT8_T_DEFINED 1 36 | #define XED_OPERAND_CTYPE_LAST_DEFINED 1 37 | typedef enum { 38 | XED_OPERAND_CTYPE_INVALID, 39 | XED_OPERAND_CTYPE_XED_BITS_T, 40 | XED_OPERAND_CTYPE_XED_CHIP_ENUM_T, 41 | XED_OPERAND_CTYPE_XED_ERROR_ENUM_T, 42 | XED_OPERAND_CTYPE_XED_ICLASS_ENUM_T, 43 | XED_OPERAND_CTYPE_XED_INT64_T, 44 | XED_OPERAND_CTYPE_XED_REG_ENUM_T, 45 | XED_OPERAND_CTYPE_XED_UINT16_T, 46 | XED_OPERAND_CTYPE_XED_UINT64_T, 47 | XED_OPERAND_CTYPE_XED_UINT8_T, 48 | XED_OPERAND_CTYPE_LAST 49 | } xed_operand_ctype_enum_t; 50 | 51 | /// This converts strings to #xed_operand_ctype_enum_t types. 52 | /// @param s A C-string. 53 | /// @return #xed_operand_ctype_enum_t 54 | /// @ingroup ENUM 55 | XED_DLL_EXPORT xed_operand_ctype_enum_t str2xed_operand_ctype_enum_t(const char* s); 56 | /// This converts strings to #xed_operand_ctype_enum_t types. 57 | /// @param p An enumeration element of type xed_operand_ctype_enum_t. 58 | /// @return string 59 | /// @ingroup ENUM 60 | XED_DLL_EXPORT const char* xed_operand_ctype_enum_t2str(const xed_operand_ctype_enum_t p); 61 | 62 | /// Returns the last element of the enumeration 63 | /// @return xed_operand_ctype_enum_t The last element of the enumeration. 64 | /// @ingroup ENUM 65 | XED_DLL_EXPORT xed_operand_ctype_enum_t xed_operand_ctype_enum_t_last(void); 66 | #endif 67 | -------------------------------------------------------------------------------- /src/xed/include/xed-interface.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /* 19 | /// @file xed-interface.h 20 | /// 21 | */ 22 | 23 | 24 | 25 | #if !defined(XED_INTERFACE_H) 26 | # define XED_INTERFACE_H 27 | 28 | #if defined(_WIN32) && defined(_MANAGED) 29 | #pragma unmanaged 30 | #endif 31 | 32 | #include "xed-build-defines.h" /* generated */ 33 | #include "xed-portability.h" 34 | 35 | #include "xed-common-hdrs.h" 36 | #include "xed-types.h" 37 | #include "xed-operand-enum.h" 38 | 39 | #include "xed-init.h" 40 | #include "xed-decode.h" 41 | #include "xed-ild.h" 42 | 43 | #include "xed-state.h" /* dstate, legacy */ 44 | #include "xed-syntax-enum.h" 45 | #include "xed-reg-class-enum.h" /* generated */ 46 | #include "xed-reg-class.h" 47 | 48 | #if defined(XED_ENCODER) 49 | # include "xed-encode.h" 50 | # include "xed-encoder-hl.h" 51 | # include "xed-patch.h" 52 | #endif 53 | #if defined(XED_ENC2_ENCODER) 54 | # include "xed-encode-direct.h" 55 | # include "xed-encode-check.h" 56 | #endif 57 | 58 | #include "xed-util.h" 59 | #include "xed-operand-action.h" 60 | 61 | #include "xed-version.h" 62 | #include "xed-decoded-inst.h" 63 | #include "xed-decoded-inst-api.h" 64 | #include "xed-inst.h" 65 | #include "xed-iclass-enum.h" /* generated */ 66 | #include "xed-category-enum.h" /* generated */ 67 | #include "xed-extension-enum.h" /* generated */ 68 | #include "xed-attribute-enum.h" /* generated */ 69 | #include "xed-exception-enum.h" /* generated */ 70 | #include "xed-operand-element-type-enum.h" /* generated */ 71 | #include "xed-operand-element-xtype-enum.h" /* generated */ 72 | 73 | #include "xed-disas.h" // callbacks for disassembly 74 | #include "xed-format-options.h" /* options for disassembly */ 75 | 76 | #include "xed-iform-enum.h" /* generated */ 77 | /* indicates the first and last index of each iform, for building tables */ 78 | #include "xed-iformfl-enum.h" /* generated */ 79 | /* mapping iforms to iclass/category/extension */ 80 | #include "xed-iform-map.h" 81 | #include "xed-rep-prefix.h" 82 | 83 | 84 | #include "xed-agen.h" 85 | #include "xed-cpuid-rec.h" 86 | #include "xed-isa-set.h" 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/xed/include/xed-rep-prefix.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-immed.h 19 | /// 20 | 21 | #ifndef XED_REP_PREFIX_H 22 | # define XED_REP_PREFIX_H 23 | 24 | #include "xed-types.h" 25 | #include "xed-common-defs.h" 26 | #include "xed-iclass-enum.h" 27 | /// @name REP-like prefix removal and addition 28 | //@{ 29 | 30 | /// @ingroup DEC Take an instruction with a REP/REPE/REPNE prefix and 31 | /// return the corresponding xed_iclass_enum_t without that prefix. The 32 | /// return value differs from the other functions in this group: If the 33 | /// input iclass does not have REP/REPNE/REPE prefix, the function returns 34 | /// the original instruction. 35 | XED_DLL_EXPORT xed_iclass_enum_t xed_rep_remove(xed_iclass_enum_t x); 36 | 37 | /// @ingroup DEC Take an #xed_iclass_enum_t value without a REPE prefix and 38 | /// return the corresponding #xed_iclass_enum_t with a REPE prefix. If the 39 | /// input instruction cannot have have a REPE prefix, this function returns 40 | /// XED_ICLASS_INVALID. 41 | XED_DLL_EXPORT xed_iclass_enum_t xed_repe_map(xed_iclass_enum_t iclass); 42 | 43 | /// @ingroup DEC Take an #xed_iclass_enum_t value without a REPNE prefix 44 | /// and return the corresponding #xed_iclass_enum_t with a REPNE prefix. If 45 | /// the input instruction cannot have a REPNE prefix, this function returns 46 | /// XED_ICLASS_INVALID. 47 | XED_DLL_EXPORT xed_iclass_enum_t xed_repne_map(xed_iclass_enum_t iclass); 48 | 49 | /// @ingroup DEC Take an #xed_iclass_enum_t value without a REP prefix and 50 | /// return the corresponding #xed_iclass_enum_t with a REP prefix. If the 51 | /// input instruction cannot have a REP prefix, this function returns 52 | /// XED_ICLASS_INVALID. 53 | XED_DLL_EXPORT xed_iclass_enum_t xed_rep_map(xed_iclass_enum_t iclass); 54 | 55 | /// @ingroup DEC Take an #xed_iclass_enum_t value for an instruction with a 56 | /// REP/REPNE/REPE prefix and return the corresponding #xed_iclass_enum_t 57 | /// without that prefix. If the input instruction does not have a 58 | /// REP/REPNE/REPE prefix, this function returns XED_ICLASS_INVALID. 59 | XED_DLL_EXPORT xed_iclass_enum_t xed_norep_map(xed_iclass_enum_t iclass); 60 | //@} 61 | #endif 62 | -------------------------------------------------------------------------------- /src/xed/include/xed-get-time.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | #if !defined(XED_GET_TIME_H) 20 | # define XED_GET_TIME_H 21 | 22 | # include "xed-portability.h" 23 | # include "xed-types.h" 24 | # if defined(__INTEL_COMPILER) && __INTEL_COMPILER > 810 && !defined(_M_IA64) 25 | # include 26 | # endif 27 | # if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 810 && !defined(_M_IA64) 28 | # if __INTEL_COMPILER < 1000 29 | # pragma intrinsic(__rdtsc) 30 | # endif 31 | # endif 32 | # if !defined(__INTEL_COMPILER) 33 | /* MSVS8 and later */ 34 | # if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(_M_IA64) 35 | # include 36 | # pragma intrinsic(__rdtsc) 37 | # endif 38 | # if defined(__GNUC__) 39 | # if defined(__i386__) || defined(i386) || defined(i686) || defined(__x86_64__) 40 | # include 41 | # endif 42 | # endif 43 | # endif 44 | 45 | 46 | static XED_INLINE xed_uint64_t xed_get_time(void) { 47 | xed_union64_t ticks; 48 | # if defined(__GNUC__) 49 | # if defined(__i386__) || defined(i386) || defined(i686) || defined(__x86_64__) 50 | # if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9 && __GNUC_PATCHLEVEL__ >= 3) 51 | ticks.u64 = __rdtsc(); 52 | # else 53 | __asm__ volatile ("rdtsc":"=a" (ticks.s.lo32), "=d"(ticks.s.hi32)); 54 | # endif 55 | # define XED_FOUND_RDTSC 56 | # endif 57 | # endif 58 | # if defined(__INTEL_COMPILER) && __INTEL_COMPILER>=810 && !defined(_M_IA64) 59 | ticks.u64 = __rdtsc(); 60 | # define XED_FOUND_RDTSC 61 | # endif 62 | # if !defined(__INTEL_COMPILER) 63 | # if !defined(XED_FOUND_RDTSC) && defined(_MSC_VER) && _MSC_VER >= 1400 && \ 64 | !defined(_M_IA64) && !defined(_MANAGED) /* MSVS7, 8 */ 65 | ticks.u64 = __rdtsc(); 66 | # define XED_FOUND_RDTSC 67 | # endif 68 | # endif 69 | # if !defined(XED_FOUND_RDTSC) 70 | ticks.u64 = 0; 71 | # endif 72 | return ticks.u64; 73 | } 74 | #undef XED_FOUND_RDTSC 75 | #endif 76 | -------------------------------------------------------------------------------- /src/xed/include/xed-encoder-iforms.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-encoder-iforms.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_ENCODER_IFORMS_H) 24 | # define XED_ENCODER_IFORMS_H 25 | #include "xed-types.h" 26 | typedef struct xed_encoder_iforms_s { 27 | xed_uint32_t x_SIBBASE_ENCODE; 28 | xed_uint32_t x_SIBBASE_ENCODE_SIB1; 29 | xed_uint32_t x_SIBINDEX_ENCODE; 30 | xed_uint32_t x_MODRM_MOD_ENCODE; 31 | xed_uint32_t x_MODRM_RM_ENCODE; 32 | xed_uint32_t x_MODRM_RM_ENCODE_EA16_SIB0; 33 | xed_uint32_t x_MODRM_RM_ENCODE_EA64_SIB0; 34 | xed_uint32_t x_MODRM_RM_ENCODE_EA32_SIB0; 35 | xed_uint32_t x_SIB_NT; 36 | xed_uint32_t x_DISP_NT; 37 | xed_uint32_t x_REMOVE_SEGMENT; 38 | xed_uint32_t x_REX_PREFIX_ENC; 39 | xed_uint32_t x_PREFIX_ENC; 40 | xed_uint32_t x_VEXED_REX; 41 | xed_uint32_t x_XOP_TYPE_ENC; 42 | xed_uint32_t x_XOP_MAP_ENC; 43 | xed_uint32_t x_XOP_REXXB_ENC; 44 | xed_uint32_t x_VEX_TYPE_ENC; 45 | xed_uint32_t x_VEX_REXR_ENC; 46 | xed_uint32_t x_VEX_REXXB_ENC; 47 | xed_uint32_t x_VEX_MAP_ENC; 48 | xed_uint32_t x_VEX_REG_ENC; 49 | xed_uint32_t x_VEX_ESCVL_ENC; 50 | xed_uint32_t x_SE_IMM8; 51 | xed_uint32_t x_VSIB_ENC_BASE; 52 | xed_uint32_t x_VSIB_ENC; 53 | xed_uint32_t x_EVEX_62_REXR_ENC; 54 | xed_uint32_t x_EVEX_REXX_ENC; 55 | xed_uint32_t x_EVEX_REXB_ENC; 56 | xed_uint32_t x_EVEX_REXRR_ENC; 57 | xed_uint32_t x_EVEX_MAP_ENC; 58 | xed_uint32_t x_EVEX_REXW_VVVV_ENC; 59 | xed_uint32_t x_EVEX_U_ENC; 60 | xed_uint32_t x_EVEX_PP_ENC; 61 | xed_uint32_t x_AVX512_EVEX_BYTE3_ENC; 62 | xed_uint32_t x_UIMMv; 63 | xed_uint32_t x_SIMMz; 64 | xed_uint32_t x_SIMM8; 65 | xed_uint32_t x_UIMM8; 66 | xed_uint32_t x_UIMM8_1; 67 | xed_uint32_t x_UIMM16; 68 | xed_uint32_t x_UIMM32; 69 | xed_uint32_t x_BRDISP8; 70 | xed_uint32_t x_BRDISP32; 71 | xed_uint32_t x_BRDISPz; 72 | xed_uint32_t x_MEMDISPv; 73 | xed_uint32_t x_MEMDISP32; 74 | xed_uint32_t x_MEMDISP16; 75 | xed_uint32_t x_MEMDISP8; 76 | xed_uint32_t x_MEMDISP; 77 | } xed_encoder_iforms_t; 78 | #endif 79 | -------------------------------------------------------------------------------- /src/xed/include/xed-mapu-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-mapu-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_MAPU_ENUM_H) 24 | # define XED_MAPU_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_MAPU_INVALID_DEFINED 1 27 | #define XED_MAPU_AMD_3DNOW_DEFINED 1 28 | #define XED_MAPU_AMD_XOP8_DEFINED 1 29 | #define XED_MAPU_AMD_XOP9_DEFINED 1 30 | #define XED_MAPU_AMD_XOPA_DEFINED 1 31 | #define XED_MAPU_EVEX_MAP1_DEFINED 1 32 | #define XED_MAPU_EVEX_MAP2_DEFINED 1 33 | #define XED_MAPU_EVEX_MAP3_DEFINED 1 34 | #define XED_MAPU_EVEX_MAP5_DEFINED 1 35 | #define XED_MAPU_EVEX_MAP6_DEFINED 1 36 | #define XED_MAPU_LEGACY_MAP0_DEFINED 1 37 | #define XED_MAPU_LEGACY_MAP1_DEFINED 1 38 | #define XED_MAPU_LEGACY_MAP2_DEFINED 1 39 | #define XED_MAPU_LEGACY_MAP3_DEFINED 1 40 | #define XED_MAPU_VEX_MAP1_DEFINED 1 41 | #define XED_MAPU_VEX_MAP2_DEFINED 1 42 | #define XED_MAPU_VEX_MAP3_DEFINED 1 43 | #define XED_MAPU_LAST_DEFINED 1 44 | typedef enum { 45 | XED_MAPU_INVALID, 46 | XED_MAPU_AMD_3DNOW, 47 | XED_MAPU_AMD_XOP8, 48 | XED_MAPU_AMD_XOP9, 49 | XED_MAPU_AMD_XOPA, 50 | XED_MAPU_EVEX_MAP1, 51 | XED_MAPU_EVEX_MAP2, 52 | XED_MAPU_EVEX_MAP3, 53 | XED_MAPU_EVEX_MAP5, 54 | XED_MAPU_EVEX_MAP6, 55 | XED_MAPU_LEGACY_MAP0, 56 | XED_MAPU_LEGACY_MAP1, 57 | XED_MAPU_LEGACY_MAP2, 58 | XED_MAPU_LEGACY_MAP3, 59 | XED_MAPU_VEX_MAP1, 60 | XED_MAPU_VEX_MAP2, 61 | XED_MAPU_VEX_MAP3, 62 | XED_MAPU_LAST 63 | } xed_mapu_enum_t; 64 | 65 | /// This converts strings to #xed_mapu_enum_t types. 66 | /// @param s A C-string. 67 | /// @return #xed_mapu_enum_t 68 | /// @ingroup ENUM 69 | XED_DLL_EXPORT xed_mapu_enum_t str2xed_mapu_enum_t(const char* s); 70 | /// This converts strings to #xed_mapu_enum_t types. 71 | /// @param p An enumeration element of type xed_mapu_enum_t. 72 | /// @return string 73 | /// @ingroup ENUM 74 | XED_DLL_EXPORT const char* xed_mapu_enum_t2str(const xed_mapu_enum_t p); 75 | 76 | /// Returns the last element of the enumeration 77 | /// @return xed_mapu_enum_t The last element of the enumeration. 78 | /// @ingroup ENUM 79 | XED_DLL_EXPORT xed_mapu_enum_t xed_mapu_enum_t_last(void); 80 | #endif 81 | -------------------------------------------------------------------------------- /src/xed/include/xed-ild-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-ild-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_ILD_ENUM_H) 24 | # define XED_ILD_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_ILD_AMD_3DNOW_DEFINED 1 27 | #define XED_ILD_AMD_XOP8_DEFINED 1 28 | #define XED_ILD_AMD_XOP9_DEFINED 1 29 | #define XED_ILD_AMD_XOPA_DEFINED 1 30 | #define XED_ILD_EVEX_MAP1_DEFINED 1 31 | #define XED_ILD_EVEX_MAP2_DEFINED 1 32 | #define XED_ILD_EVEX_MAP3_DEFINED 1 33 | #define XED_ILD_EVEX_MAP5_DEFINED 1 34 | #define XED_ILD_EVEX_MAP6_DEFINED 1 35 | #define XED_ILD_LEGACY_MAP0_DEFINED 1 36 | #define XED_ILD_LEGACY_MAP1_DEFINED 1 37 | #define XED_ILD_LEGACY_MAP2_DEFINED 1 38 | #define XED_ILD_LEGACY_MAP3_DEFINED 1 39 | #define XED_ILD_VEX_MAP1_DEFINED 1 40 | #define XED_ILD_VEX_MAP2_DEFINED 1 41 | #define XED_ILD_VEX_MAP3_DEFINED 1 42 | #define XED_ILD_MAP_INVALID_DEFINED 1 43 | #define XED_ILD_LAST_DEFINED 1 44 | typedef enum { 45 | XED_ILD_AMD_3DNOW=4, 46 | XED_ILD_AMD_XOP8=8, 47 | XED_ILD_AMD_XOP9=9, 48 | XED_ILD_AMD_XOPA=10, 49 | XED_ILD_EVEX_MAP1=1, 50 | XED_ILD_EVEX_MAP2=2, 51 | XED_ILD_EVEX_MAP3=3, 52 | XED_ILD_EVEX_MAP5=5, 53 | XED_ILD_EVEX_MAP6=6, 54 | XED_ILD_LEGACY_MAP0=0, 55 | XED_ILD_LEGACY_MAP1=1, 56 | XED_ILD_LEGACY_MAP2=2, 57 | XED_ILD_LEGACY_MAP3=3, 58 | XED_ILD_VEX_MAP1=1, 59 | XED_ILD_VEX_MAP2=2, 60 | XED_ILD_VEX_MAP3=3, 61 | XED_ILD_MAP_INVALID, 62 | XED_ILD_LAST 63 | } xed_ild_map_enum_t; 64 | 65 | /// This converts strings to #xed_ild_map_enum_t types. 66 | /// @param s A C-string. 67 | /// @return #xed_ild_map_enum_t 68 | /// @ingroup ENUM 69 | XED_DLL_EXPORT xed_ild_map_enum_t str2xed_ild_map_enum_t(const char* s); 70 | /// This converts strings to #xed_ild_map_enum_t types. 71 | /// @param p An enumeration element of type xed_ild_map_enum_t. 72 | /// @return string 73 | /// @ingroup ENUM 74 | XED_DLL_EXPORT const char* xed_ild_map_enum_t2str(const xed_ild_map_enum_t p); 75 | 76 | /// Returns the last element of the enumeration 77 | /// @return xed_ild_map_enum_t The last element of the enumeration. 78 | /// @ingroup ENUM 79 | XED_DLL_EXPORT xed_ild_map_enum_t xed_ild_map_enum_t_last(void); 80 | #endif 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 |

4 | 5 | license 6 | 7 | language 8 | 9 | linux 10 | release 11 | 12 |
If you are interested in This project, please kindly give Me a triple `Star`, `Fork` and `Watch`, Thanks!
13 |
14 | 15 | # DeadCode Detection Framework 16 | 17 | **Using DynamoRIO and XED to find redundant executions (Dead code)** 18 | * **This project can be used as a framework for dead code analysis.** 19 | * **This project can also be seen as introductory training to help students or beginners explore some instruction-level programming work** 20 | 21 | > [!IMPORTANT] 22 | > 1. This tool aims to detect and analyze dead code (redundant executions) in binary files using DynamoRIO and XED. 23 | > 2. Here, I only implement a basic logic to detect dead writes and reads 24 | > 3. You have the freedom to modify the detection logic in [dead_code_analysis.cpp](https://github.com/FeijiangHan/DeadCodeDetection/blob/main/src/trace/cpps/dead_code_analysis.cpp) to achieve better dead code detection than what is currently implemented. 25 | > 4. You can also modify the code output logic to use CSV or any other file you want 26 | > 5. This project does not read files using C++, so you need to configure the compiler to specify the binary path in order to get the binary into the program. I feel that Clion is more convenient, VScode is slightly more complicated 27 | 28 | 29 | **Here is a poster of me showcasing my work during NCSU GEARE training:** 30 | ![poster-Feijiang Han](https://github.com/FeijiangHan/dead_code_analyzer/blob/main/poster-Feijiang%20Han.png) 31 | 32 | 33 | **The process can be summarized as follows:** 34 | 35 | 1. Obtain the binary file (trace) that needs to be parsed. 36 | 2. Extract the necessary code from DynamoRIO for parsing the target binary. This step gathers detailed information about instructions, such as read/write operations and parameter details. 37 | 3. Utilize [Intel XED](https://intelxed.github.io/) to decode register details and analyze fine-grained parameters. 38 | 4. Modify the dead code detection logic in [dead_code_analysis.cpp](https://github.com/FeijiangHan/DeadCodeDetection/blob/main/src/trace/cpps/dead_code_analysis.cpp). The implementation includes detecting redundant reads and redundant writes. 39 | 5. The analysis results will be output to the 'out' file, which can be further analyzed. 40 | 41 | 42 | **TODO:** 43 | 44 | - Optimize the output format for better readability. 45 | - Implement more sophisticated dead code detection logic. 46 | 47 | Please refer to the project repository for more information and access to the source code. 48 | -------------------------------------------------------------------------------- /src/xed/include/xed-agen.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-agen.h 19 | /// 20 | 21 | 22 | #ifndef XED_AGEN_H 23 | # define XED_AGEN_H 24 | #include "xed-decoded-inst.h" 25 | #include "xed-error-enum.h" 26 | 27 | 28 | /// A function for obtaining register values. 32b return values should be 29 | /// zero extended to 64b. The error value is set to nonzero if the callback 30 | /// experiences some sort of problem. @ingroup AGEN 31 | typedef xed_uint64_t (*xed_register_callback_fn_t)(xed_reg_enum_t reg, 32 | void* context, 33 | xed_bool_t* error); 34 | 35 | /// A function for obtaining the segment base values. 32b return values 36 | /// should be zero extended zero extended to 64b. The error value is set to 37 | /// nonzero if the callback experiences some sort of problem. 38 | /// @ingroup AGEN 39 | typedef xed_uint64_t (*xed_segment_base_callback_fn_t)(xed_reg_enum_t reg, 40 | void* context, 41 | xed_bool_t* error); 42 | 43 | 44 | /// Initialize the callback functions. Tell XED what to call when using 45 | /// #xed_agen. 46 | /// @ingroup AGEN 47 | XED_DLL_EXPORT void xed_agen_register_callback(xed_register_callback_fn_t register_fn, 48 | xed_segment_base_callback_fn_t segment_fn); 49 | 50 | /// Using the registered callbacks, compute the memory address for a 51 | /// specified memop in a decoded instruction. memop_index can have the 52 | /// value 0 for XED_OPERAND_MEM0, XED_OPERAND_AGEN, or 1 for 53 | /// XED_OPERAND_MEM1. Any other value results in an error being 54 | /// returned. The context parameter which is passed to the registered 55 | /// callbacks can be used to identify which thread's state is being 56 | /// referenced. The context parameter can also be used to specify which 57 | /// element of a vector register should be returned for gather an scatter 58 | /// operations. 59 | /// @ingroup AGEN 60 | XED_DLL_EXPORT xed_error_enum_t xed_agen(xed_decoded_inst_t* xedd, 61 | unsigned int memop_index, 62 | void* context, 63 | xed_uint64_t* out_address); 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/trace/headers/record_file_reader.cpp: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include "record_file_reader.h" 36 | 37 | namespace dynamorio { 38 | namespace drmemtrace { 39 | 40 | /* clang-format off */ /* (make vera++ newline-after-type check happy) */ 41 | template <> 42 | /* clang-format on */ 43 | record_file_reader_t::~record_file_reader_t() 44 | { 45 | } 46 | 47 | template <> 48 | bool 49 | record_file_reader_t::open_single_file(const std::string &path) 50 | { 51 | auto fstream = 52 | std::unique_ptr(new std::ifstream(path, std::ifstream::binary)); 53 | if (!*fstream) 54 | return false; 55 | VPRINT(this, 1, "Opened input file %s\n", path.c_str()); 56 | input_file_ = std::move(fstream); 57 | return true; 58 | } 59 | 60 | template <> 61 | bool 62 | record_file_reader_t::read_next_entry() 63 | { 64 | if (!input_file_->read((char *)&cur_entry_, sizeof(cur_entry_))) 65 | return false; 66 | VPRINT(this, 4, "Read from file: type=%s (%d), size=%d, addr=%zu\n", 67 | trace_type_names[cur_entry_.type], cur_entry_.type, cur_entry_.size, 68 | cur_entry_.addr); 69 | return true; 70 | } 71 | 72 | } // namespace drmemtrace 73 | } // namespace dynamorio 74 | -------------------------------------------------------------------------------- /src/trace/cpps/trace_entry.cpp: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2015-2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | #include "../headers/trace_entry.h" 34 | 35 | const char *const trace_type_names[] = { 36 | "read", 37 | "write", 38 | "prefetch", 39 | "prefetch_read_l1", 40 | "prefetch_read_l2", 41 | "prefetch_read_l3", 42 | "prefetchnta", 43 | "prefetch_read", 44 | "prefetch_write", 45 | "prefetch_instr", 46 | "instr", 47 | "direct_jump", 48 | "indirect_jump", 49 | "conditional_jump", 50 | "direct_call", 51 | "indirect_call", 52 | "return", 53 | "instr_bundle", 54 | "instr_flush", 55 | "instr_flush_end", 56 | "data_flush", 57 | "data_flush_end", 58 | "thread", 59 | "thread_exit", 60 | "pid", 61 | "header", 62 | "footer", 63 | "hw prefetch", 64 | "marker", 65 | "non-fetched instr", 66 | "maybe-fetched instr", 67 | "sysenter", 68 | "prefetch_read_l1_nt", 69 | "prefetch_read_l2_nt", 70 | "prefetch_read_l3_nt", 71 | "prefetch_instr_l1", 72 | "prefetch_instr_l1_nt", 73 | "prefetch_instr_l2", 74 | "prefetch_instr_l2_nt", 75 | "prefetch_instr_l3", 76 | "prefetch_instr_l3_nt", 77 | "prefetch_write_l1", 78 | "prefetch_write_l1_nt", 79 | "prefetch_write_l2", 80 | "prefetch_write_l2_nt", 81 | "prefetch_write_l3", 82 | "prefetch_write_l3_nt", 83 | "encoding", 84 | }; 85 | -------------------------------------------------------------------------------- /src/xed/include/xed-decode.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-decode.h 19 | 20 | 21 | #ifndef XED_DECODE_H 22 | # define XED_DECODE_H 23 | 24 | #include "xed-decoded-inst.h" 25 | #include "xed-error-enum.h" 26 | #include "xed-chip-features.h" 27 | 28 | /// This is the main interface to the decoder. 29 | /// @param xedd the decoded instruction of type #xed_decoded_inst_t . Mode/state sent in via xedd; See the #xed_state_t 30 | /// @param itext the pointer to the array of instruction text bytes 31 | /// @param bytes the length of the itext input array. 1 to 15 bytes, anything more is ignored. 32 | /// @return #xed_error_enum_t indicating success (#XED_ERROR_NONE) or failure. Note failure can be due to not 33 | /// enough bytes in the input array. 34 | /// 35 | /// The maximum instruction is 15B and XED will tell you how long the 36 | /// actual instruction is via an API function call 37 | /// xed_decoded_inst_get_length(). However, it is not always safe or 38 | /// advisable for XED to read 15 bytes if the decode location is at the 39 | /// boundary of some sort of protection limit. For example, if one is 40 | /// decoding near the end of a page and the XED user does not want to cause 41 | /// extra page faults, one might send in the number of bytes that would 42 | /// stop at the page boundary. In this case, XED might not be able to 43 | /// decode the instruction and would return an error. The XED user would 44 | /// then have to decide if it was safe to touch the next page and try again 45 | /// to decode with more bytes. Also sometimes the user process does not 46 | /// have read access to the next page and this allows the user to prevent 47 | /// XED from causing process termination by limiting the memory range that 48 | /// XED will access. 49 | /// 50 | /// @ingroup DEC 51 | XED_DLL_EXPORT xed_error_enum_t 52 | xed_decode(xed_decoded_inst_t* xedd, 53 | const xed_uint8_t* itext, 54 | const unsigned int bytes); 55 | 56 | /// @ingroup DEC 57 | /// See #xed_decode(). This version of the decode API adds a CPUID feature 58 | /// vector to support restricting decode based on both a specified chip via 59 | /// #xed_decoded_inst_set_input_chip() and a modify-able cpuid feature 60 | /// vector obtained from #xed_get_chip_features(). 61 | XED_DLL_EXPORT xed_error_enum_t 62 | xed_decode_with_features(xed_decoded_inst_t* xedd, 63 | const xed_uint8_t* itext, 64 | const unsigned int bytes, 65 | xed_chip_features_t* features); 66 | 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /src/trace/cpps/directory_iterator.cpp: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2017-2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | #include 34 | #include "../headers/directory_iterator.h" 35 | #include "../headers/utils.h" 36 | 37 | // Following typical stream iterator convention, the default constructor 38 | // produces an EOF object. 39 | directory_iterator_t::directory_iterator_t(const std::string &directory) 40 | { 41 | dir_ = opendir(directory.c_str()); 42 | if (dir_ == nullptr) { 43 | error_descr_ = "Failed to access directory."; 44 | return; 45 | } 46 | ++*this; 47 | at_eof_ = false; 48 | } 49 | 50 | directory_iterator_t::~directory_iterator_t() 51 | { 52 | if (dir_ != nullptr) 53 | closedir(dir_); 54 | } 55 | 56 | // Work around clang-format bug: no newline after return type for single-char operator. 57 | // clang-format off 58 | const std::string & 59 | directory_iterator_t::operator*() 60 | // clang-format on 61 | { 62 | return cur_file_; 63 | } 64 | 65 | directory_iterator_t & 66 | directory_iterator_t::operator++() 67 | { 68 | ent_ = readdir(dir_); 69 | if (ent_ == nullptr) 70 | at_eof_ = true; 71 | else 72 | cur_file_ = ent_->d_name; 73 | return *this; 74 | } 75 | 76 | bool 77 | directory_iterator_t::is_directory(const std::string &path) 78 | { 79 | DIR *pdir; 80 | bool is_dir = false; 81 | 82 | pdir = opendir(path.c_str()); 83 | if (pdir != nullptr) { 84 | is_dir = true; 85 | (void)closedir(pdir); 86 | } 87 | return is_dir; 88 | } 89 | -------------------------------------------------------------------------------- /src/xed/include/xed-flag-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-flag-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_FLAG_ENUM_H) 24 | # define XED_FLAG_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_FLAG_INVALID_DEFINED 1 27 | #define XED_FLAG_of_DEFINED 1 28 | #define XED_FLAG_sf_DEFINED 1 29 | #define XED_FLAG_zf_DEFINED 1 30 | #define XED_FLAG_af_DEFINED 1 31 | #define XED_FLAG_pf_DEFINED 1 32 | #define XED_FLAG_cf_DEFINED 1 33 | #define XED_FLAG_df_DEFINED 1 34 | #define XED_FLAG_vif_DEFINED 1 35 | #define XED_FLAG_iopl_DEFINED 1 36 | #define XED_FLAG_if_DEFINED 1 37 | #define XED_FLAG_ac_DEFINED 1 38 | #define XED_FLAG_vm_DEFINED 1 39 | #define XED_FLAG_rf_DEFINED 1 40 | #define XED_FLAG_nt_DEFINED 1 41 | #define XED_FLAG_tf_DEFINED 1 42 | #define XED_FLAG_id_DEFINED 1 43 | #define XED_FLAG_vip_DEFINED 1 44 | #define XED_FLAG_fc0_DEFINED 1 45 | #define XED_FLAG_fc1_DEFINED 1 46 | #define XED_FLAG_fc2_DEFINED 1 47 | #define XED_FLAG_fc3_DEFINED 1 48 | #define XED_FLAG_LAST_DEFINED 1 49 | typedef enum { 50 | XED_FLAG_INVALID, 51 | XED_FLAG_of, ///<< overflow flag 52 | XED_FLAG_sf, ///< sign flag 53 | XED_FLAG_zf, ///< zero flag 54 | XED_FLAG_af, ///< auxiliary flag 55 | XED_FLAG_pf, ///< parity flag 56 | XED_FLAG_cf, ///< carry flag 57 | XED_FLAG_df, ///< direction flag 58 | XED_FLAG_vif, ///< virtual interrupt flag 59 | XED_FLAG_iopl, ///< I/O privilege level 60 | XED_FLAG_if, ///< interrupt flag 61 | XED_FLAG_ac, ///< alignment check 62 | XED_FLAG_vm, ///< virtual-8086 mode 63 | XED_FLAG_rf, ///< resume flag 64 | XED_FLAG_nt, ///< nested task 65 | XED_FLAG_tf, ///< traf flag 66 | XED_FLAG_id, ///< ID flag 67 | XED_FLAG_vip, ///< virtual interrupt pending 68 | XED_FLAG_fc0, ///< x87 FC0 flag 69 | XED_FLAG_fc1, ///< x87 FC1 flag 70 | XED_FLAG_fc2, ///< x87 FC2 flag 71 | XED_FLAG_fc3, ///< x87 FC3 flag 72 | XED_FLAG_LAST 73 | } xed_flag_enum_t; 74 | 75 | /// This converts strings to #xed_flag_enum_t types. 76 | /// @param s A C-string. 77 | /// @return #xed_flag_enum_t 78 | /// @ingroup ENUM 79 | XED_DLL_EXPORT xed_flag_enum_t str2xed_flag_enum_t(const char* s); 80 | /// This converts strings to #xed_flag_enum_t types. 81 | /// @param p An enumeration element of type xed_flag_enum_t. 82 | /// @return string 83 | /// @ingroup ENUM 84 | XED_DLL_EXPORT const char* xed_flag_enum_t2str(const xed_flag_enum_t p); 85 | 86 | /// Returns the last element of the enumeration 87 | /// @return xed_flag_enum_t The last element of the enumeration. 88 | /// @ingroup ENUM 89 | XED_DLL_EXPORT xed_flag_enum_t xed_flag_enum_t_last(void); 90 | #endif 91 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-element-type-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-element-type-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_ELEMENT_TYPE_ENUM_H) 24 | # define XED_OPERAND_ELEMENT_TYPE_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPERAND_ELEMENT_TYPE_INVALID_DEFINED 1 27 | #define XED_OPERAND_ELEMENT_TYPE_UINT_DEFINED 1 28 | #define XED_OPERAND_ELEMENT_TYPE_INT_DEFINED 1 29 | #define XED_OPERAND_ELEMENT_TYPE_SINGLE_DEFINED 1 30 | #define XED_OPERAND_ELEMENT_TYPE_DOUBLE_DEFINED 1 31 | #define XED_OPERAND_ELEMENT_TYPE_LONGDOUBLE_DEFINED 1 32 | #define XED_OPERAND_ELEMENT_TYPE_LONGBCD_DEFINED 1 33 | #define XED_OPERAND_ELEMENT_TYPE_STRUCT_DEFINED 1 34 | #define XED_OPERAND_ELEMENT_TYPE_VARIABLE_DEFINED 1 35 | #define XED_OPERAND_ELEMENT_TYPE_FLOAT16_DEFINED 1 36 | #define XED_OPERAND_ELEMENT_TYPE_BFLOAT16_DEFINED 1 37 | #define XED_OPERAND_ELEMENT_TYPE_INT8_DEFINED 1 38 | #define XED_OPERAND_ELEMENT_TYPE_UINT8_DEFINED 1 39 | #define XED_OPERAND_ELEMENT_TYPE_LAST_DEFINED 1 40 | typedef enum { 41 | XED_OPERAND_ELEMENT_TYPE_INVALID, 42 | XED_OPERAND_ELEMENT_TYPE_UINT, ///< Unsigned integer 43 | XED_OPERAND_ELEMENT_TYPE_INT, ///< Signed integer 44 | XED_OPERAND_ELEMENT_TYPE_SINGLE, ///< 32b FP single precision 45 | XED_OPERAND_ELEMENT_TYPE_DOUBLE, ///< 64b FP double precision 46 | XED_OPERAND_ELEMENT_TYPE_LONGDOUBLE, ///< 80b FP x87 47 | XED_OPERAND_ELEMENT_TYPE_LONGBCD, ///< 80b decimal BCD 48 | XED_OPERAND_ELEMENT_TYPE_STRUCT, ///< a structure of various fields 49 | XED_OPERAND_ELEMENT_TYPE_VARIABLE, ///< depends on other fields in the instruction 50 | XED_OPERAND_ELEMENT_TYPE_FLOAT16, ///< 16b floating point 51 | XED_OPERAND_ELEMENT_TYPE_BFLOAT16, ///< bfloat16 floating point 52 | XED_OPERAND_ELEMENT_TYPE_INT8, ///< 8 bit integer 53 | XED_OPERAND_ELEMENT_TYPE_UINT8, ///< 8 bit unsigned integer 54 | XED_OPERAND_ELEMENT_TYPE_LAST 55 | } xed_operand_element_type_enum_t; 56 | 57 | /// This converts strings to #xed_operand_element_type_enum_t types. 58 | /// @param s A C-string. 59 | /// @return #xed_operand_element_type_enum_t 60 | /// @ingroup ENUM 61 | XED_DLL_EXPORT xed_operand_element_type_enum_t str2xed_operand_element_type_enum_t(const char* s); 62 | /// This converts strings to #xed_operand_element_type_enum_t types. 63 | /// @param p An enumeration element of type xed_operand_element_type_enum_t. 64 | /// @return string 65 | /// @ingroup ENUM 66 | XED_DLL_EXPORT const char* xed_operand_element_type_enum_t2str(const xed_operand_element_type_enum_t p); 67 | 68 | /// Returns the last element of the enumeration 69 | /// @return xed_operand_element_type_enum_t The last element of the enumeration. 70 | /// @ingroup ENUM 71 | XED_DLL_EXPORT xed_operand_element_type_enum_t xed_operand_element_type_enum_t_last(void); 72 | #endif 73 | -------------------------------------------------------------------------------- /src/xed/include/xed-decoded-inst.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-decoded-inst.h 19 | /// 20 | 21 | #if !defined(XED_DECODER_STATE_H) 22 | # define XED_DECODER_STATE_H 23 | #include "xed-common-hdrs.h" 24 | #include "xed-common-defs.h" 25 | #include "xed-portability.h" 26 | #include "xed-util.h" 27 | #include "xed-types.h" 28 | #include "xed-inst.h" 29 | #include "xed-flags.h" 30 | #if defined(XED_ENCODER) 31 | # include "xed-encoder-gen-defs.h" //generated 32 | #endif 33 | #include "xed-chip-enum.h" //generated 34 | #include "xed-operand-element-type-enum.h" // a generated file 35 | #include "xed-operand-storage.h" // a generated file 36 | 37 | typedef union { 38 | xed_uint32_t i; 39 | struct { 40 | xed_uint8_t has_modrm; 41 | xed_uint8_t has_disp; 42 | xed_uint8_t has_imm; 43 | } s; 44 | } xed_ild_vars_t; 45 | 46 | struct xed_encoder_vars_s; 47 | struct xed_decoder_vars_s; 48 | /// @ingroup DEC 49 | /// The main container for instructions. After decode, it holds an array of 50 | /// operands with derived information from decode and also valid 51 | /// #xed_inst_t pointer which describes the operand templates and the 52 | /// operand order. See @ref DEC for API documentation. 53 | typedef struct xed_decoded_inst_s { 54 | /// The _operands are storage for information discovered during 55 | /// decoding. They are also used by encode. The accessors for these 56 | /// operands all have the form xed3_operand_{get,set}_*(). They should 57 | /// be considered internal and subject to change over time. It is 58 | /// preferred that you use xed_decoded_inst_*() or the 59 | /// xed_operand_values_*() functions when available. 60 | xed_operand_storage_t _operands; 61 | 62 | #if defined(XED_ENCODER) 63 | /// Used for encode operand ordering. Not set by decode. 64 | xed_uint8_t _operand_order[XED_ENCODE_ORDER_MAX_OPERANDS]; 65 | /// Length of the _operand_order[] array. 66 | xed_uint8_t _n_operand_order; 67 | #endif 68 | xed_uint8_t _decoded_length; 69 | 70 | /// when we decode an instruction, we set the _inst and get the 71 | /// properites of that instruction here. This also points to the 72 | /// operands template array. 73 | const xed_inst_t* _inst; 74 | 75 | // decoder does not change it, encoder does 76 | union { 77 | xed_uint8_t* _enc; 78 | const xed_uint8_t* _dec; 79 | } _byte_array; 80 | 81 | // The ev field is stack allocated by xed_encode(). It is per-encode 82 | // transitory data. 83 | union { 84 | /* user_data is available as a user data storage field after 85 | * decoding. It does not live across re-encodes or re-decodes. */ 86 | xed_uint64_t user_data; 87 | xed_ild_vars_t ild_data; 88 | #if defined(XED_ENCODER) 89 | struct xed_encoder_vars_s* ev; 90 | #endif 91 | } u; 92 | 93 | } xed_decoded_inst_t; 94 | 95 | typedef xed_decoded_inst_t xed_operand_values_t; 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /src/xed/include/xed-print-info.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | #if !defined(XED_PRINT_INFO_H) 20 | # define XED_PRINT_INFO_H 21 | 22 | #include "xed-types.h" 23 | #include "xed-decoded-inst.h" 24 | #include "xed-disas.h" // callback function type 25 | #include "xed-syntax-enum.h" 26 | #include "xed-format-options.h" 27 | 28 | /// @ingroup PRINT 29 | /// This contains the information used by the various disassembly printers. 30 | /// Call xed_init_print_info to initialize the fields. Then change the 31 | /// required and optional fields when required. 32 | typedef struct { 33 | 34 | ///////////////////////////////////////// 35 | // REQUIRED FIELDS - users should set these 36 | ///////////////////////////////////////// 37 | 38 | /// the decoded instruction to print 39 | const xed_decoded_inst_t* p; 40 | 41 | /// pointer to the output buffer 42 | char* buf; 43 | 44 | /// length of the output buffer. (bytes) Must be > 25 to start. 45 | int blen; 46 | 47 | ///////////////////////////////////////// 48 | // OPTIONAL FIELDS - user can set these 49 | ///////////////////////////////////////// 50 | 51 | /// program counter location. Must be zero if not used. (Sometimes 52 | /// instructions are disassembled in a temporary buffer at a different 53 | /// location than where they may or will exist in memory). 54 | xed_uint64_t runtime_address; 55 | 56 | /// disassembly_callback MUST be set to zero if not used! If zero, the 57 | /// default disassembly callback is used (if one has been registered). 58 | xed_disassembly_callback_fn_t disassembly_callback; 59 | 60 | /// passed to disassembly callback. Can be zero if not used. 61 | void* context; 62 | 63 | /// default is Intel-syntax (dest on left) 64 | xed_syntax_enum_t syntax; 65 | 66 | /// 1=indicated the format_options field is valid, 0=use default 67 | /// formatting options from xed_format_set_options(). 68 | int format_options_valid; 69 | xed_format_options_t format_options; 70 | 71 | 72 | ///////////////////////////////////////// 73 | // NONPUBLIC FIELDS - Users should not use these! 74 | ///////////////////////////////////////// 75 | 76 | /// internal, do not use 77 | xed_bool_t emitted; 78 | 79 | /// internal, do not use 80 | unsigned int operand_indx; 81 | 82 | /// internal, do not use 83 | unsigned int skip_operand; 84 | 85 | /// internal, do not use 86 | xed_reg_enum_t extra_index_operand; // for MPX 87 | 88 | /// internal, do not use 89 | xed_bool_t implicit; 90 | 91 | /// internal, do not use 92 | xed_bool_t truncate_eip_eosz16; 93 | 94 | } xed_print_info_t; 95 | 96 | // This function initializes the #xed_print_info_t structure. 97 | // You must still set the required fields of that structure. 98 | /// @ingroup PRINT 99 | XED_DLL_EXPORT void xed_init_print_info(xed_print_info_t* pi); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/xed/include/xed-reg-class-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-reg-class-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_REG_CLASS_ENUM_H) 24 | # define XED_REG_CLASS_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_REG_CLASS_INVALID_DEFINED 1 27 | #define XED_REG_CLASS_BNDCFG_DEFINED 1 28 | #define XED_REG_CLASS_BNDSTAT_DEFINED 1 29 | #define XED_REG_CLASS_BOUND_DEFINED 1 30 | #define XED_REG_CLASS_CR_DEFINED 1 31 | #define XED_REG_CLASS_DR_DEFINED 1 32 | #define XED_REG_CLASS_FLAGS_DEFINED 1 33 | #define XED_REG_CLASS_GPR_DEFINED 1 34 | #define XED_REG_CLASS_GPR16_DEFINED 1 35 | #define XED_REG_CLASS_GPR32_DEFINED 1 36 | #define XED_REG_CLASS_GPR64_DEFINED 1 37 | #define XED_REG_CLASS_GPR8_DEFINED 1 38 | #define XED_REG_CLASS_IP_DEFINED 1 39 | #define XED_REG_CLASS_MASK_DEFINED 1 40 | #define XED_REG_CLASS_MMX_DEFINED 1 41 | #define XED_REG_CLASS_MSR_DEFINED 1 42 | #define XED_REG_CLASS_MXCSR_DEFINED 1 43 | #define XED_REG_CLASS_PSEUDO_DEFINED 1 44 | #define XED_REG_CLASS_PSEUDOX87_DEFINED 1 45 | #define XED_REG_CLASS_SR_DEFINED 1 46 | #define XED_REG_CLASS_TMP_DEFINED 1 47 | #define XED_REG_CLASS_TREG_DEFINED 1 48 | #define XED_REG_CLASS_UIF_DEFINED 1 49 | #define XED_REG_CLASS_X87_DEFINED 1 50 | #define XED_REG_CLASS_XCR_DEFINED 1 51 | #define XED_REG_CLASS_XMM_DEFINED 1 52 | #define XED_REG_CLASS_YMM_DEFINED 1 53 | #define XED_REG_CLASS_ZMM_DEFINED 1 54 | #define XED_REG_CLASS_LAST_DEFINED 1 55 | typedef enum { 56 | XED_REG_CLASS_INVALID, 57 | XED_REG_CLASS_BNDCFG, 58 | XED_REG_CLASS_BNDSTAT, 59 | XED_REG_CLASS_BOUND, 60 | XED_REG_CLASS_CR, 61 | XED_REG_CLASS_DR, 62 | XED_REG_CLASS_FLAGS, 63 | XED_REG_CLASS_GPR, 64 | XED_REG_CLASS_GPR16, 65 | XED_REG_CLASS_GPR32, 66 | XED_REG_CLASS_GPR64, 67 | XED_REG_CLASS_GPR8, 68 | XED_REG_CLASS_IP, 69 | XED_REG_CLASS_MASK, 70 | XED_REG_CLASS_MMX, 71 | XED_REG_CLASS_MSR, 72 | XED_REG_CLASS_MXCSR, 73 | XED_REG_CLASS_PSEUDO, 74 | XED_REG_CLASS_PSEUDOX87, 75 | XED_REG_CLASS_SR, 76 | XED_REG_CLASS_TMP, 77 | XED_REG_CLASS_TREG, 78 | XED_REG_CLASS_UIF, 79 | XED_REG_CLASS_X87, 80 | XED_REG_CLASS_XCR, 81 | XED_REG_CLASS_XMM, 82 | XED_REG_CLASS_YMM, 83 | XED_REG_CLASS_ZMM, 84 | XED_REG_CLASS_LAST 85 | } xed_reg_class_enum_t; 86 | 87 | /// This converts strings to #xed_reg_class_enum_t types. 88 | /// @param s A C-string. 89 | /// @return #xed_reg_class_enum_t 90 | /// @ingroup ENUM 91 | XED_DLL_EXPORT xed_reg_class_enum_t str2xed_reg_class_enum_t(const char* s); 92 | /// This converts strings to #xed_reg_class_enum_t types. 93 | /// @param p An enumeration element of type xed_reg_class_enum_t. 94 | /// @return string 95 | /// @ingroup ENUM 96 | XED_DLL_EXPORT const char* xed_reg_class_enum_t2str(const xed_reg_class_enum_t p); 97 | 98 | /// Returns the last element of the enumeration 99 | /// @return xed_reg_class_enum_t The last element of the enumeration. 100 | /// @ingroup ENUM 101 | XED_DLL_EXPORT xed_reg_class_enum_t xed_reg_class_enum_t_last(void); 102 | #endif 103 | -------------------------------------------------------------------------------- /src/xed/include/xed-types.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-types.h 19 | /// 20 | 21 | 22 | #ifndef XED_TYPES_H 23 | # define XED_TYPES_H 24 | 25 | //////////////////////////////////////////////////////////////////////////// 26 | 27 | #include "xed-common-hdrs.h" 28 | 29 | #if defined(__GNUC__) || defined(__ICC) || defined(__clang__) 30 | # include 31 | # define xed_uint8_t uint8_t 32 | # define xed_uint16_t uint16_t 33 | # define xed_uint32_t uint32_t 34 | # define xed_uint64_t uint64_t 35 | # define xed_int8_t int8_t 36 | # define xed_int16_t int16_t 37 | # define xed_int32_t int32_t 38 | # define xed_int64_t int64_t 39 | #elif defined(_WIN32) 40 | # define xed_uint8_t unsigned __int8 41 | # define xed_uint16_t unsigned __int16 42 | # define xed_uint32_t unsigned __int32 43 | # define xed_uint64_t unsigned __int64 44 | # define xed_int8_t __int8 45 | # define xed_int16_t __int16 46 | # define xed_int32_t __int32 47 | # define xed_int64_t __int64 48 | #else 49 | # error "XED types unsupported platform? Need windows, gcc, or icc." 50 | #endif 51 | 52 | typedef unsigned int xed_uint_t; 53 | typedef int xed_int_t; 54 | typedef unsigned int xed_bits_t; 55 | typedef unsigned int xed_bool_t; 56 | 57 | #if defined(__LP64__) || defined (_M_X64) 58 | typedef xed_uint64_t xed_addr_t; 59 | #else 60 | typedef xed_uint32_t xed_addr_t; 61 | #endif 62 | 63 | 64 | typedef union { 65 | xed_uint8_t byte[2]; 66 | xed_int8_t s_byte[2]; 67 | 68 | struct { 69 | xed_uint8_t b0; /*low 8 bits*/ 70 | xed_uint8_t b1; /*high 8 bits*/ 71 | } b; 72 | xed_int16_t i16; 73 | xed_uint16_t u16; 74 | } xed_union16_t ; 75 | 76 | typedef union { 77 | xed_uint8_t byte[4]; 78 | xed_uint16_t word[2]; 79 | xed_int8_t s_byte[4]; 80 | xed_int16_t s_word[2]; 81 | 82 | struct { 83 | xed_uint8_t b0; /*low 8 bits*/ 84 | xed_uint8_t b1; 85 | xed_uint8_t b2; 86 | xed_uint8_t b3; /*high 8 bits*/ 87 | } b; 88 | 89 | struct { 90 | xed_uint16_t w0; /*low 16 bits*/ 91 | xed_uint16_t w1; /*high 16 bits*/ 92 | } w; 93 | xed_int32_t i32; 94 | xed_uint32_t u32; 95 | } xed_union32_t ; 96 | 97 | typedef union { 98 | xed_uint8_t byte[8]; 99 | xed_uint16_t word[4]; 100 | xed_uint32_t dword[2]; 101 | xed_int8_t s_byte[8]; 102 | xed_int16_t s_word[4]; 103 | xed_int32_t s_dword[2]; 104 | 105 | struct { 106 | xed_uint8_t b0; /*low 8 bits*/ 107 | xed_uint8_t b1; 108 | xed_uint8_t b2; 109 | xed_uint8_t b3; 110 | xed_uint8_t b4; 111 | xed_uint8_t b5; 112 | xed_uint8_t b6; 113 | xed_uint8_t b7; /*high 8 bits*/ 114 | } b; 115 | 116 | struct { 117 | xed_uint16_t w0; /*low 16 bits*/ 118 | xed_uint16_t w1; 119 | xed_uint16_t w2; 120 | xed_uint16_t w3; /*high 16 bits*/ 121 | } w; 122 | struct { 123 | xed_uint32_t lo32; 124 | xed_uint32_t hi32; 125 | } s; 126 | xed_uint64_t u64; 127 | xed_int64_t i64; 128 | } xed_union64_t ; 129 | 130 | //////////////////////////////////////////////////////////////////////////// 131 | #endif 132 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-element-xtype-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-element-xtype-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_ELEMENT_XTYPE_ENUM_H) 24 | # define XED_OPERAND_ELEMENT_XTYPE_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_OPERAND_XTYPE_INVALID_DEFINED 1 27 | #define XED_OPERAND_XTYPE_2BF16_DEFINED 1 28 | #define XED_OPERAND_XTYPE_2F16_DEFINED 1 29 | #define XED_OPERAND_XTYPE_4I8_DEFINED 1 30 | #define XED_OPERAND_XTYPE_4U8_DEFINED 1 31 | #define XED_OPERAND_XTYPE_B80_DEFINED 1 32 | #define XED_OPERAND_XTYPE_BF16_DEFINED 1 33 | #define XED_OPERAND_XTYPE_F16_DEFINED 1 34 | #define XED_OPERAND_XTYPE_F32_DEFINED 1 35 | #define XED_OPERAND_XTYPE_F64_DEFINED 1 36 | #define XED_OPERAND_XTYPE_F80_DEFINED 1 37 | #define XED_OPERAND_XTYPE_I1_DEFINED 1 38 | #define XED_OPERAND_XTYPE_I16_DEFINED 1 39 | #define XED_OPERAND_XTYPE_I32_DEFINED 1 40 | #define XED_OPERAND_XTYPE_I64_DEFINED 1 41 | #define XED_OPERAND_XTYPE_I8_DEFINED 1 42 | #define XED_OPERAND_XTYPE_INT_DEFINED 1 43 | #define XED_OPERAND_XTYPE_STRUCT_DEFINED 1 44 | #define XED_OPERAND_XTYPE_U128_DEFINED 1 45 | #define XED_OPERAND_XTYPE_U16_DEFINED 1 46 | #define XED_OPERAND_XTYPE_U256_DEFINED 1 47 | #define XED_OPERAND_XTYPE_U32_DEFINED 1 48 | #define XED_OPERAND_XTYPE_U64_DEFINED 1 49 | #define XED_OPERAND_XTYPE_U8_DEFINED 1 50 | #define XED_OPERAND_XTYPE_UINT_DEFINED 1 51 | #define XED_OPERAND_XTYPE_VAR_DEFINED 1 52 | #define XED_OPERAND_XTYPE_LAST_DEFINED 1 53 | typedef enum { 54 | XED_OPERAND_XTYPE_INVALID, 55 | XED_OPERAND_XTYPE_2BF16, 56 | XED_OPERAND_XTYPE_2F16, 57 | XED_OPERAND_XTYPE_4I8, 58 | XED_OPERAND_XTYPE_4U8, 59 | XED_OPERAND_XTYPE_B80, 60 | XED_OPERAND_XTYPE_BF16, 61 | XED_OPERAND_XTYPE_F16, 62 | XED_OPERAND_XTYPE_F32, 63 | XED_OPERAND_XTYPE_F64, 64 | XED_OPERAND_XTYPE_F80, 65 | XED_OPERAND_XTYPE_I1, 66 | XED_OPERAND_XTYPE_I16, 67 | XED_OPERAND_XTYPE_I32, 68 | XED_OPERAND_XTYPE_I64, 69 | XED_OPERAND_XTYPE_I8, 70 | XED_OPERAND_XTYPE_INT, 71 | XED_OPERAND_XTYPE_STRUCT, 72 | XED_OPERAND_XTYPE_U128, 73 | XED_OPERAND_XTYPE_U16, 74 | XED_OPERAND_XTYPE_U256, 75 | XED_OPERAND_XTYPE_U32, 76 | XED_OPERAND_XTYPE_U64, 77 | XED_OPERAND_XTYPE_U8, 78 | XED_OPERAND_XTYPE_UINT, 79 | XED_OPERAND_XTYPE_VAR, 80 | XED_OPERAND_XTYPE_LAST 81 | } xed_operand_element_xtype_enum_t; 82 | 83 | /// This converts strings to #xed_operand_element_xtype_enum_t types. 84 | /// @param s A C-string. 85 | /// @return #xed_operand_element_xtype_enum_t 86 | /// @ingroup ENUM 87 | XED_DLL_EXPORT xed_operand_element_xtype_enum_t str2xed_operand_element_xtype_enum_t(const char* s); 88 | /// This converts strings to #xed_operand_element_xtype_enum_t types. 89 | /// @param p An enumeration element of type xed_operand_element_xtype_enum_t. 90 | /// @return string 91 | /// @ingroup ENUM 92 | XED_DLL_EXPORT const char* xed_operand_element_xtype_enum_t2str(const xed_operand_element_xtype_enum_t p); 93 | 94 | /// Returns the last element of the enumeration 95 | /// @return xed_operand_element_xtype_enum_t The last element of the enumeration. 96 | /// @ingroup ENUM 97 | XED_DLL_EXPORT xed_operand_element_xtype_enum_t xed_operand_element_xtype_enum_t_last(void); 98 | #endif 99 | -------------------------------------------------------------------------------- /src/trace/headers/directory_iterator.h: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2017-2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | /* directory_iterator: provides an iterator for walking files in a directory. 34 | */ 35 | 36 | #ifndef _DIRECTORY_ITERATOR_H_ 37 | #define _DIRECTORY_ITERATOR_H_ 1 38 | 39 | #include 40 | #include 41 | #include /* opendir, readdir */ 42 | 43 | #include "../headers//utils.h" 44 | 45 | // Iterates over files: skips sub-directories. 46 | // Returns the basenames of the files (i.e., not absolute paths). 47 | // This class is not thread-safe. 48 | class directory_iterator_t : public std::iterator { 49 | public: 50 | directory_iterator_t() 51 | { 52 | } 53 | virtual ~directory_iterator_t(); 54 | 55 | explicit directory_iterator_t(const std::string &directory); 56 | 57 | std::string 58 | error_string() const 59 | { 60 | return error_descr_; 61 | } 62 | 63 | virtual const std::string &operator*(); 64 | 65 | // To avoid double-dispatch (requires listing all derived types in the base here) 66 | // and RTTI in trying to get the right operators called for subclasses, we 67 | // instead directly check at_eof here. If we end up needing to run code 68 | // and a bool field is not enough we can change this to invoke a virtual 69 | // method is_at_eof(). 70 | virtual bool 71 | operator==(const directory_iterator_t &rhs) const 72 | { 73 | return BOOLS_MATCH(at_eof_, rhs.at_eof_); 74 | } 75 | virtual bool 76 | operator!=(const directory_iterator_t &rhs) const 77 | { 78 | return !BOOLS_MATCH(at_eof_, rhs.at_eof_); 79 | } 80 | 81 | virtual directory_iterator_t & 82 | operator++(); 83 | 84 | virtual bool operator!() 85 | { 86 | return at_eof_; 87 | } 88 | 89 | static bool 90 | is_directory(const std::string &path); 91 | 92 | private: 93 | bool at_eof_ = true; 94 | std::string error_descr_; 95 | std::string cur_file_; 96 | DIR *dir_ = nullptr; 97 | struct dirent *ent_ = nullptr; 98 | }; 99 | 100 | #endif /* _DIRECTORY_ITERATOR_H_ */ 101 | -------------------------------------------------------------------------------- /src/xed/include/xed-encode-direct.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | 19 | 20 | #ifndef XED_ENCODE_DIRECT_H 21 | # define XED_ENCODE_DIRECT_H 22 | #include "xed-common-hdrs.h" 23 | #include "xed-portability.h" 24 | #include "xed-types.h" 25 | #include "xed-error-enum.h" 26 | #include 27 | #include 28 | 29 | /// This structure is filled in by the various XED ENC2 functions. It 30 | /// should not be directly manipulated by user code. 31 | /// @ingroup ENC2 32 | typedef struct { 33 | xed_uint8_t* itext; // supplied by user during init 34 | xed_uint32_t cursor; // where we write next byte 35 | 36 | xed_uint32_t has_sib:1; 37 | xed_uint32_t has_disp8:1; 38 | xed_uint32_t has_disp16:1; 39 | xed_uint32_t has_disp32:1; 40 | 41 | xed_uint32_t rexw:1; // and vex, evex 42 | xed_uint32_t rexr:1; // and vex, evex 43 | xed_uint32_t rexx:1; // and vex, evex 44 | xed_uint32_t rexb:1; // and vex, evex 45 | 46 | xed_uint32_t need_rex:1; // for SIL,DIL,BPL,SPL 47 | xed_uint32_t evexrr:1; 48 | xed_uint32_t vexl:1; 49 | xed_uint32_t evexb:1; // also sae enabler for reg-only & vl=512 50 | 51 | xed_uint32_t evexvv:1; 52 | xed_uint32_t evexz:1; 53 | xed_uint32_t evexll:2; // also rc bits in some case 54 | 55 | xed_uint32_t mod:2; 56 | xed_uint32_t reg:3; 57 | xed_uint32_t rm:3; 58 | xed_uint32_t sibscale:2; 59 | xed_uint32_t sibindex:3; 60 | xed_uint32_t sibbase:3; 61 | xed_uint32_t evexaaa:3; 62 | xed_uint32_t map:3; 63 | xed_uint32_t vexpp:3; // and evex 64 | xed_uint32_t vvvv:4; 65 | xed_uint32_t opcode_srm:3; /// for "partial opcode" instructions 66 | 67 | xed_uint8_t imm8_reg; // for _SE imm8-specified registers. 68 | 69 | } xed_enc2_req_payload_t; 70 | 71 | 72 | /// A wrapper for #xed_enc2_req_payload_t . 73 | /// @ingroup ENC2 74 | typedef union { 75 | xed_enc2_req_payload_t s; 76 | } xed_enc2_req_t; 77 | 78 | /// Zero out a #xed_enc2_req_t structure and set the output pointer. 79 | /// Required before calling and any ENC2 encoding function. 80 | /// @ingroup ENC2 81 | static XED_INLINE void xed_enc2_req_t_init(xed_enc2_req_t* r, xed_uint8_t* output_buffer) { 82 | memset(r, 0, sizeof(xed_enc2_req_t)); 83 | r->s.itext = output_buffer; 84 | } 85 | 86 | /// Returns the number of bytes that were used for the encoding. 87 | /// @ingroup ENC2 88 | static XED_INLINE xed_uint32_t xed_enc2_encoded_length(xed_enc2_req_t* r) { 89 | return r->s.cursor; 90 | } 91 | 92 | 93 | /// Emit a legacy segment prefix byte in to the specified request's output buffer. 94 | /// @ingroup ENC2 95 | XED_DLL_EXPORT void xed_emit_seg_prefix(xed_enc2_req_t* r, 96 | xed_reg_enum_t reg); 97 | 98 | 99 | typedef void (xed_user_abort_handler_t)(const char* format, va_list args); 100 | 101 | /// Set a function taking a variable-number-of-arguments (stdarg) to handle 102 | /// the errors and die. The argument are like printf with a format string 103 | /// followed by a varaible number of arguments. 104 | /// @ingroup ENC2 105 | XED_DLL_EXPORT void xed_enc2_set_error_handler(xed_user_abort_handler_t* fn); 106 | 107 | /// The error handler routine. This function is called by encoder functions 108 | /// upon detecting argument errors. It fist attempts to call the 109 | /// user-registered handler (configured by #xed_enc2_set_error_handler() ), 110 | /// or if no user handler is set, then this function calls printf() and 111 | /// then abort(). If the user handler returns, abort() is still called. 112 | /// @ingroup ENC2 113 | XED_DLL_EXPORT void xed_enc2_error(const char* fmt, ...); 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /src/xed/include/xed-error-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-error-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_ERROR_ENUM_H) 24 | # define XED_ERROR_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_ERROR_NONE_DEFINED 1 27 | #define XED_ERROR_BUFFER_TOO_SHORT_DEFINED 1 28 | #define XED_ERROR_GENERAL_ERROR_DEFINED 1 29 | #define XED_ERROR_INVALID_FOR_CHIP_DEFINED 1 30 | #define XED_ERROR_BAD_REGISTER_DEFINED 1 31 | #define XED_ERROR_BAD_LOCK_PREFIX_DEFINED 1 32 | #define XED_ERROR_BAD_REP_PREFIX_DEFINED 1 33 | #define XED_ERROR_BAD_LEGACY_PREFIX_DEFINED 1 34 | #define XED_ERROR_BAD_REX_PREFIX_DEFINED 1 35 | #define XED_ERROR_BAD_EVEX_UBIT_DEFINED 1 36 | #define XED_ERROR_BAD_MAP_DEFINED 1 37 | #define XED_ERROR_BAD_EVEX_V_PRIME_DEFINED 1 38 | #define XED_ERROR_BAD_EVEX_Z_NO_MASKING_DEFINED 1 39 | #define XED_ERROR_NO_OUTPUT_POINTER_DEFINED 1 40 | #define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED_DEFINED 1 41 | #define XED_ERROR_BAD_MEMOP_INDEX_DEFINED 1 42 | #define XED_ERROR_CALLBACK_PROBLEM_DEFINED 1 43 | #define XED_ERROR_GATHER_REGS_DEFINED 1 44 | #define XED_ERROR_INSTR_TOO_LONG_DEFINED 1 45 | #define XED_ERROR_INVALID_MODE_DEFINED 1 46 | #define XED_ERROR_BAD_EVEX_LL_DEFINED 1 47 | #define XED_ERROR_BAD_REG_MATCH_DEFINED 1 48 | #define XED_ERROR_LAST_DEFINED 1 49 | typedef enum { 50 | XED_ERROR_NONE, ///< There was no error 51 | XED_ERROR_BUFFER_TOO_SHORT, ///< There were not enough bytes in the given buffer 52 | XED_ERROR_GENERAL_ERROR, ///< XED could not decode the given instruction 53 | XED_ERROR_INVALID_FOR_CHIP, ///< The instruciton is not valid for the specified chip 54 | XED_ERROR_BAD_REGISTER, ///< XED could not decode the given instruction because an invalid register encoding was used. 55 | XED_ERROR_BAD_LOCK_PREFIX, ///< A lock prefix was found where none is allowed. 56 | XED_ERROR_BAD_REP_PREFIX, ///< An F2 or F3 prefix was found where none is allowed. 57 | XED_ERROR_BAD_LEGACY_PREFIX, ///< A 66, F2 or F3 prefix was found where none is allowed. 58 | XED_ERROR_BAD_REX_PREFIX, ///< A REX prefix was found where none is allowed. 59 | XED_ERROR_BAD_EVEX_UBIT, ///< An illegal value for the EVEX.U bit was present in the instruction. 60 | XED_ERROR_BAD_MAP, ///< An illegal value for the MAP field was detected in the instruction. 61 | XED_ERROR_BAD_EVEX_V_PRIME, ///< EVEX.V'=0 was detected in a non-64b mode instruction. 62 | XED_ERROR_BAD_EVEX_Z_NO_MASKING, ///< EVEX.Z!=0 when EVEX.aaa==0 63 | XED_ERROR_NO_OUTPUT_POINTER, ///< The output pointer for xed_agen was zero 64 | XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED, ///< One or both of the callbacks for xed_agen were missing. 65 | XED_ERROR_BAD_MEMOP_INDEX, ///< Memop indices must be 0 or 1. 66 | XED_ERROR_CALLBACK_PROBLEM, ///< The register or segment callback for xed_agen experienced a problem 67 | XED_ERROR_GATHER_REGS, ///< The index, dest and mask regs for AVX2 gathers must be different. 68 | XED_ERROR_INSTR_TOO_LONG, ///< Full decode of instruction would exeed 15B. 69 | XED_ERROR_INVALID_MODE, ///< The instruction was not valid for the specified mode 70 | XED_ERROR_BAD_EVEX_LL, ///< EVEX.LL must not ==3 unless using embedded rounding 71 | XED_ERROR_BAD_REG_MATCH, ///< Source registers must not match the destination register for this instruction. 72 | XED_ERROR_LAST 73 | } xed_error_enum_t; 74 | 75 | /// This converts strings to #xed_error_enum_t types. 76 | /// @param s A C-string. 77 | /// @return #xed_error_enum_t 78 | /// @ingroup ENUM 79 | XED_DLL_EXPORT xed_error_enum_t str2xed_error_enum_t(const char* s); 80 | /// This converts strings to #xed_error_enum_t types. 81 | /// @param p An enumeration element of type xed_error_enum_t. 82 | /// @return string 83 | /// @ingroup ENUM 84 | XED_DLL_EXPORT const char* xed_error_enum_t2str(const xed_error_enum_t p); 85 | 86 | /// Returns the last element of the enumeration 87 | /// @return xed_error_enum_t The last element of the enumeration. 88 | /// @ingroup ENUM 89 | XED_DLL_EXPORT xed_error_enum_t xed_error_enum_t_last(void); 90 | #endif 91 | -------------------------------------------------------------------------------- /src/xed/include/xed-iform-map.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-iform-map.h 19 | /// 20 | 21 | #if !defined(XED_IFORM_MAP_H) 22 | # define XED_IFORM_MAP_H 23 | 24 | #include "xed-common-hdrs.h" 25 | #include "xed-types.h" 26 | #include "xed-iform-enum.h" /* generated */ 27 | #include "xed-iclass-enum.h" /* generated */ 28 | #include "xed-category-enum.h" /* generated */ 29 | #include "xed-extension-enum.h" /* generated */ 30 | #include "xed-isa-set-enum.h" /* generated */ 31 | 32 | /// @ingroup IFORM 33 | /// Statically available information about iforms. 34 | /// Values are returned by #xed_iform_map(). 35 | typedef struct xed_iform_info_s { 36 | xed_uint32_t iclass :16; // xed_iclass_enum_t 37 | xed_uint32_t category :8; //xed_category_enum_t 38 | xed_uint32_t extension :8; //xed_extension_enum_t 39 | 40 | xed_uint32_t isa_set :16; //xed_isa_set_enum_t 41 | /* if nonzero, index in to the disassembly string table */ 42 | xed_uint32_t string_table_idx:16; 43 | } xed_iform_info_t; 44 | 45 | 46 | /// @ingroup IFORM 47 | /// Map the #xed_iform_enum_t to a pointer to a #xed_iform_info_t which 48 | /// indicates the #xed_iclass_enum_t, the #xed_category_enum_t and the 49 | /// #xed_extension_enum_t for the iform. Returns 0 if the iform is not a 50 | /// valid iform. 51 | XED_DLL_EXPORT 52 | const xed_iform_info_t* xed_iform_map(xed_iform_enum_t iform); 53 | 54 | /// @ingroup IFORM 55 | /// Return the maximum number of iforms for a particular iclass. This 56 | /// function returns valid data as soon as global data is 57 | /// initialized. (This function does not require a decoded instruction as 58 | /// input). 59 | XED_DLL_EXPORT 60 | xed_uint32_t xed_iform_max_per_iclass(xed_iclass_enum_t iclass); 61 | 62 | /// @ingroup IFORM 63 | /// Return the first of the iforms for a particular iclass. This function 64 | /// returns valid data as soon as global data is initialized. (This 65 | /// function does not require a decoded instruction as input). 66 | XED_DLL_EXPORT 67 | xed_uint32_t xed_iform_first_per_iclass(xed_iclass_enum_t iclass); 68 | 69 | /// @ingroup IFORM 70 | /// Return the iclass for a given iform. This 71 | /// function returns valid data as soon as global data is initialized. (This 72 | /// function does not require a decoded instruction as input). 73 | static 74 | XED_INLINE xed_iclass_enum_t xed_iform_to_iclass(xed_iform_enum_t iform) { 75 | const xed_iform_info_t* ii = xed_iform_map(iform); 76 | if (ii) 77 | return (xed_iclass_enum_t) ii->iclass; 78 | return XED_ICLASS_INVALID; 79 | } 80 | 81 | /// @ingroup IFORM 82 | /// Return the category for a given iform. This 83 | /// function returns valid data as soon as global data is initialized. (This 84 | /// function does not require a decoded instruction as input). 85 | XED_DLL_EXPORT 86 | xed_category_enum_t xed_iform_to_category(xed_iform_enum_t iform); 87 | 88 | /// @ingroup IFORM 89 | /// Return the extension for a given iform. This function returns valid 90 | /// data as soon as global data is initialized. (This function does not 91 | /// require a decoded instruction as input). 92 | XED_DLL_EXPORT 93 | xed_extension_enum_t xed_iform_to_extension(xed_iform_enum_t iform); 94 | 95 | /// @ingroup IFORM 96 | /// Return the isa_set for a given iform. This function returns valid data 97 | /// as soon as global data is initialized. (This function does not require 98 | /// a decoded instruction as input). 99 | XED_DLL_EXPORT 100 | xed_isa_set_enum_t xed_iform_to_isa_set(xed_iform_enum_t iform); 101 | 102 | /// @ingroup IFORM 103 | /// Return a pointer to a character string of the iclass. This 104 | /// translates the internal disambiguated names to the more ambiguous 105 | /// names that people like to see. This returns the ATT SYSV-syntax name. 106 | XED_DLL_EXPORT 107 | char const* xed_iform_to_iclass_string_att(xed_iform_enum_t iform); 108 | 109 | 110 | /// @ingroup IFORM 111 | /// Return a pointer to a character string of the iclass. This 112 | /// translates the internal disambiguated names to the more ambiguous 113 | /// names that people like to see. This returns the Intel-syntax name. 114 | XED_DLL_EXPORT 115 | char const* xed_iform_to_iclass_string_intel(xed_iform_enum_t iform); 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /src/xed/include/xed-operand-storage.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-operand-storage.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_OPERAND_STORAGE_H) 24 | # define XED_OPERAND_STORAGE_H 25 | #include "xed-chip-enum.h" 26 | #include "xed-error-enum.h" 27 | #include "xed-iclass-enum.h" 28 | #include "xed-reg-enum.h" 29 | #include "xed-operand-element-type-enum.h" 30 | typedef struct xed_operand_storage_s { 31 | xed_uint8_t agen; 32 | xed_uint8_t amd3dnow; 33 | xed_uint8_t asz; 34 | xed_uint8_t bcrc; 35 | xed_uint8_t cet; 36 | xed_uint8_t cldemote; 37 | xed_uint8_t df32; 38 | xed_uint8_t df64; 39 | xed_uint8_t dummy; 40 | xed_uint8_t encoder_preferred; 41 | xed_uint8_t encode_force; 42 | xed_uint8_t has_sib; 43 | xed_uint8_t ild_f2; 44 | xed_uint8_t ild_f3; 45 | xed_uint8_t imm0; 46 | xed_uint8_t imm0signed; 47 | xed_uint8_t imm1; 48 | xed_uint8_t lock; 49 | xed_uint8_t lzcnt; 50 | xed_uint8_t mem0; 51 | xed_uint8_t mem1; 52 | xed_uint8_t modep5; 53 | xed_uint8_t modep55c; 54 | xed_uint8_t mode_first_prefix; 55 | xed_uint8_t mode_short_ud0; 56 | xed_uint8_t mpxmode; 57 | xed_uint8_t must_use_evex; 58 | xed_uint8_t needrex; 59 | xed_uint8_t need_sib; 60 | xed_uint8_t norex; 61 | xed_uint8_t no_evex; 62 | xed_uint8_t no_vex; 63 | xed_uint8_t osz; 64 | xed_uint8_t out_of_bytes; 65 | xed_uint8_t p4; 66 | xed_uint8_t prefix66; 67 | xed_uint8_t ptr; 68 | xed_uint8_t realmode; 69 | xed_uint8_t relbr; 70 | xed_uint8_t rex; 71 | xed_uint8_t rexb; 72 | xed_uint8_t rexr; 73 | xed_uint8_t rexrr; 74 | xed_uint8_t rexw; 75 | xed_uint8_t rexx; 76 | xed_uint8_t sae; 77 | xed_uint8_t tzcnt; 78 | xed_uint8_t ubit; 79 | xed_uint8_t using_default_segment0; 80 | xed_uint8_t using_default_segment1; 81 | xed_uint8_t vexdest3; 82 | xed_uint8_t vexdest4; 83 | xed_uint8_t vex_c4; 84 | xed_uint8_t wbnoinvd; 85 | xed_uint8_t zeroing; 86 | xed_uint8_t default_seg; 87 | xed_uint8_t easz; 88 | xed_uint8_t eosz; 89 | xed_uint8_t first_f2f3; 90 | xed_uint8_t has_modrm; 91 | xed_uint8_t last_f2f3; 92 | xed_uint8_t llrc; 93 | xed_uint8_t mod; 94 | xed_uint8_t mode; 95 | xed_uint8_t rep; 96 | xed_uint8_t sibscale; 97 | xed_uint8_t smode; 98 | xed_uint8_t vex_prefix; 99 | xed_uint8_t vl; 100 | xed_uint8_t hint; 101 | xed_uint8_t mask; 102 | xed_uint8_t reg; 103 | xed_uint8_t rm; 104 | xed_uint8_t roundc; 105 | xed_uint8_t seg_ovd; 106 | xed_uint8_t sibbase; 107 | xed_uint8_t sibindex; 108 | xed_uint8_t srm; 109 | xed_uint8_t vexdest210; 110 | xed_uint8_t vexvalid; 111 | xed_uint8_t error; 112 | xed_uint8_t esrc; 113 | xed_uint8_t map; 114 | xed_uint8_t nelem; 115 | xed_uint8_t scale; 116 | xed_uint8_t bcast; 117 | xed_uint8_t need_memdisp; 118 | xed_uint8_t chip; 119 | xed_uint8_t brdisp_width; 120 | xed_uint8_t disp_width; 121 | xed_uint8_t ild_seg; 122 | xed_uint8_t imm1_bytes; 123 | xed_uint8_t imm_width; 124 | xed_uint8_t max_bytes; 125 | xed_uint8_t modrm_byte; 126 | xed_uint8_t nominal_opcode; 127 | xed_uint8_t nprefixes; 128 | xed_uint8_t nrexes; 129 | xed_uint8_t nseg_prefixes; 130 | xed_uint8_t pos_disp; 131 | xed_uint8_t pos_imm; 132 | xed_uint8_t pos_imm1; 133 | xed_uint8_t pos_modrm; 134 | xed_uint8_t pos_nominal_opcode; 135 | xed_uint8_t pos_sib; 136 | xed_uint8_t uimm1; 137 | xed_uint16_t base0; 138 | xed_uint16_t base1; 139 | xed_uint16_t element_size; 140 | xed_uint16_t index; 141 | xed_uint16_t outreg; 142 | xed_uint16_t reg0; 143 | xed_uint16_t reg1; 144 | xed_uint16_t reg2; 145 | xed_uint16_t reg3; 146 | xed_uint16_t reg4; 147 | xed_uint16_t reg5; 148 | xed_uint16_t reg6; 149 | xed_uint16_t reg7; 150 | xed_uint16_t reg8; 151 | xed_uint16_t reg9; 152 | xed_uint16_t seg0; 153 | xed_uint16_t seg1; 154 | xed_uint16_t iclass; 155 | xed_uint16_t mem_width; 156 | xed_uint64_t disp; 157 | xed_uint64_t uimm0; 158 | } xed_operand_storage_t; 159 | #endif 160 | -------------------------------------------------------------------------------- /src/trace/cpps/file_reader.cpp: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2016-2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | #include 34 | #include "../headers/file_reader.h" 35 | #include 36 | /* clang-format off */ /* (make vera++ newline-after-type check happy) */ 37 | template <> 38 | /* clang-format on */ 39 | file_reader_t::~file_reader_t() 40 | { 41 | for (auto fstream : input_files_) { 42 | delete fstream; 43 | } 44 | delete[] thread_eof_; 45 | } 46 | 47 | template <> 48 | bool 49 | file_reader_t::open_single_file(const std::string &path) 50 | { 51 | auto fstream = new std::ifstream(path, std::ifstream::binary); 52 | if (!*fstream) 53 | return false; 54 | VPRINT(this, 1, "Opened input file %s\n", path.c_str()); 55 | input_files_.push_back(fstream); 56 | return true; 57 | } 58 | 59 | template <> 60 | bool 61 | file_reader_t::read_next_thread_entry(size_t thread_index, 62 | OUT trace_entry_t *entry, 63 | OUT bool *eof) 64 | { 65 | //std::cout << "f: " << thread_index << std::endl; 66 | if (!input_files_[thread_index]->read((char *)entry, sizeof(*entry))) { 67 | *eof = input_files_[thread_index]->eof(); 68 | return false; 69 | } 70 | VPRINT(this, 4, "Read from thread #%zd file: type=%s (%d), size=%d, addr=%zu\n", 71 | thread_index, trace_type_names[entry->type], entry->type, entry->size, 72 | entry->addr); 73 | return true; 74 | } 75 | 76 | template <> 77 | bool 78 | file_reader_t::is_complete() 79 | { 80 | // FIXME i#3230: this code is in the middle of refactoring for split thread files. 81 | // We support the is_complete() call from analyzer_multi for a single file for now, 82 | // but may have to abandon this function altogether since gzFile doesn't support it. 83 | bool opened_temporarily = false; 84 | if (input_files_.empty()) { 85 | // Supporting analyzer_multi calling before init() for a single legacy file. 86 | opened_temporarily = true; 87 | if (!input_path_list_.empty() || input_path_.empty() || 88 | directory_iterator_t::is_directory(input_path_)) 89 | return false; // Not supported. 90 | if (!open_single_file(input_path_)) 91 | return false; 92 | } 93 | bool res = false; 94 | for (auto fstream : input_files_) { 95 | res = false; 96 | std::streampos pos = fstream->tellg(); 97 | fstream->seekg(-(int)sizeof(trace_entry_t), fstream->end); 98 | // Avoid reaching eof b/c we can't seek away from it. 99 | if (fstream->read((char *)&entry_copy_.type, sizeof(entry_copy_.type)) && 100 | entry_copy_.type == TRACE_TYPE_FOOTER) 101 | 102 | res = true; 103 | fstream->seekg(pos); 104 | if (!res) 105 | break; 106 | } 107 | if (opened_temporarily) { 108 | // Put things back for init(). 109 | for (auto fstream : input_files_) 110 | delete fstream; 111 | input_files_.clear(); 112 | } 113 | return res; 114 | } 115 | -------------------------------------------------------------------------------- /src/trace/headers/utils.h: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2015-2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | /* utils.h: utilities for cache simulator */ 34 | 35 | #ifndef _UTILS_H_ 36 | #define _UTILS_H_ 1 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | // XXX: perhaps we should use a C++-ish stream approach instead 44 | // This cannot be named ERROR as that conflicts with Windows headers. 45 | #define ERRMSG(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) 46 | 47 | // XXX: can we share w/ core DR? 48 | #define IS_POWER_OF_2(x) ((x) != 0 && ((x) & ((x)-1)) == 0) 49 | 50 | // XXX i#4399: DR should define a DEBUG-only assert. 51 | #ifdef DEBUG 52 | # define ASSERT(x, msg) DR_ASSERT_MSG(x, msg) 53 | #else 54 | # define ASSERT(x, msg) /* Nothing. */ 55 | #endif 56 | 57 | #define BUFFER_SIZE_BYTES(buf) sizeof(buf) 58 | #define BUFFER_SIZE_ELEMENTS(buf) (BUFFER_SIZE_BYTES(buf) / sizeof(buf[0])) 59 | #define BUFFER_LAST_ELEMENT(buf) buf[BUFFER_SIZE_ELEMENTS(buf) - 1] 60 | #define NULL_TERMINATE_BUFFER(buf) BUFFER_LAST_ELEMENT(buf) = 0 61 | #define TESTALL(mask, var) (((mask) & (var)) == (mask)) 62 | #define TESTANY(mask, var) (((mask) & (var)) != 0) 63 | 64 | #if defined(X64) || defined(ARM) 65 | # define IF_REL_ADDRS(x) x 66 | #else 67 | # define IF_REL_ADDRS(x) 68 | #endif 69 | 70 | #define ALIGN_FORWARD(x, alignment) \ 71 | ((((ptr_uint_t)x) + ((alignment)-1)) & (~((ptr_uint_t)(alignment)-1))) 72 | #define ALIGN_BACKWARD(x, alignment) (((ptr_uint_t)x) & (~((ptr_uint_t)(alignment)-1))) 73 | 74 | #define NOTIFY(level, ...) \ 75 | do { \ 76 | if (op_verbose.get_value() >= (level)) \ 77 | dr_fprintf(STDERR, __VA_ARGS__); \ 78 | } while (0) 79 | 80 | #define BOOLS_MATCH(b1, b2) (!!(b1) == !!(b2)) 81 | 82 | #define START_PACKED_STRUCTURE /* nothing */ 83 | #define END_PACKED_STRUCTURE __attribute__((__packed__)) 84 | 85 | #define CONSTEXPR constexpr 86 | 87 | #ifndef __has_cpp_attribute 88 | # define __has_cpp_attribute(x) 0 // Compatibility with non-clang compilers. 89 | #endif 90 | // We annotate to support building with -Wimplicit-fallthrough. 91 | #if __has_cpp_attribute(clang::fallthrough) 92 | # define ANNOTATE_FALLTHROUGH [[clang::fallthrough]] 93 | #elif __has_cpp_attribute(gnu::fallthrough) 94 | # define ANNOTATE_FALLTHROUGH [[gnu::fallthrough]] 95 | #else 96 | # define ANNOTATE_FALLTHROUGH 97 | #endif 98 | 99 | #define DIRSEP "/" 100 | #define ALT_DIRSEP "" 101 | 102 | static inline int 103 | compute_log2(int value) 104 | { 105 | int i; 106 | for (i = 0; i < 31; i++) { 107 | if (value == 1 << i) 108 | return i; 109 | } 110 | // returns -1 if value is not a power of 2. 111 | return -1; 112 | } 113 | 114 | template 115 | std::string 116 | to_hex_string(T integer) 117 | { 118 | std::stringstream sstream; 119 | sstream << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex 120 | << integer; 121 | return sstream.str(); 122 | } 123 | 124 | static inline bool 125 | ends_with(const std::string &str, const std::string &with) 126 | { 127 | size_t pos = str.rfind(with); 128 | if (pos == std::string::npos) 129 | return false; 130 | return (pos + with.size() == str.size()); 131 | } 132 | 133 | static inline bool 134 | starts_with(const std::string &str, const std::string &with) 135 | { 136 | size_t pos = str.find(with); 137 | if (pos == std::string::npos) 138 | return false; 139 | return pos == 0; 140 | } 141 | 142 | #endif /* _UTILS_H_ */ 143 | -------------------------------------------------------------------------------- /src/xed/include/xed-portability.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-portability.h 19 | /// 20 | 21 | #ifndef XED_PORTABILITY_H 22 | # define XED_PORTABILITY_H 23 | # include "xed-common-hdrs.h" 24 | # include "xed-types.h" 25 | 26 | 27 | #define XED_STATIC_CAST(x,y) ((x) (y)) 28 | #define XED_REINTERPRET_CAST(x,y) ((x) (y)) 29 | #define XED_CAST(x,y) ((x) (y)) 30 | 31 | 32 | 33 | XED_DLL_EXPORT xed_uint_t xed_strlen(const char* s); 34 | XED_DLL_EXPORT void xed_strcat(char* dst, const char* src); 35 | XED_DLL_EXPORT void xed_strcpy(char* dst, const char* src); 36 | 37 | /// returns the number of bytes remaining for the next use of 38 | /// #xed_strncpy() or #xed_strncat() . 39 | XED_DLL_EXPORT int xed_strncpy(char* dst, const char* src, int len); 40 | 41 | /// returns the number of bytes remaining for the next use of 42 | /// #xed_strncpy() or #xed_strncat() . 43 | XED_DLL_EXPORT int xed_strncat(char* dst, const char* src, int len); 44 | 45 | #if defined(__INTEL_COMPILER) 46 | # if defined(_WIN32) && defined(_MSC_VER) 47 | # if _MSC_VER >= 1400 48 | # define XED_MSVC8_OR_LATER 1 49 | # endif 50 | # endif 51 | #endif 52 | 53 | /* recognize VC98 */ 54 | #if !defined(__INTEL_COMPILER) 55 | # if defined(_WIN32) && defined(_MSC_VER) 56 | # if _MSC_VER == 1200 57 | # define XED_MSVC6 1 58 | # endif 59 | # endif 60 | # if defined(_WIN32) && defined(_MSC_VER) 61 | # if _MSC_VER == 1310 62 | # define XED_MSVC7 1 63 | # endif 64 | # endif 65 | # if defined(_WIN32) && defined(_MSC_VER) 66 | # if _MSC_VER >= 1400 67 | # define XED_MSVC8_OR_LATER 1 68 | # endif 69 | # if _MSC_VER == 1400 70 | # define XED_MSVC8 1 71 | # endif 72 | # if _MSC_VER == 1500 73 | # define XED_MSVC9 1 74 | # endif 75 | # if _MSC_VER >= 1500 76 | # define XED_MSVC9_OR_LATER 1 77 | # endif 78 | # if _MSC_VER == 1600 79 | # define XED_MSVC10 1 80 | # endif 81 | # if _MSC_VER >= 1600 82 | # define XED_MSVC10_OR_LATER 1 83 | # endif 84 | # endif 85 | #endif 86 | 87 | /* I've had compatibility problems here so I'm using a trivial indirection */ 88 | #if defined(__GNUC__) 89 | # if defined(__CYGWIN__) 90 | /* cygwin's gcc 3.4.4 on windows complains */ 91 | # define XED_FMT_X "%lx" 92 | # define XED_FMT_08X "%08lx" 93 | # define XED_FMT_D "%ld" 94 | # define XED_FMT_U "%lu" 95 | # define XED_FMT_9U "%9lu" 96 | # else 97 | # define XED_FMT_X "%x" 98 | # define XED_FMT_08X "%08x" 99 | # define XED_FMT_D "%d" 100 | # define XED_FMT_U "%u" 101 | # define XED_FMT_9U "%9u" 102 | # endif 103 | #else 104 | # define XED_FMT_X "%x" 105 | # define XED_FMT_08X "%08x" 106 | # define XED_FMT_D "%d" 107 | # define XED_FMT_U "%u" 108 | # define XED_FMT_9U "%9u" 109 | #endif 110 | 111 | // Go write portable code... Sigh 112 | #if defined(__APPLE__) // clang *32b* and 64b 113 | # define XED_FMT_SIZET "%lu" 114 | #elif defined(__LP64__) // 64b gcc, icc 115 | # define XED_FMT_SIZET "%lu" 116 | #elif defined (_M_X64) // 64b msvs, ICL 117 | // MSVS/x64 accepts %llu or %lu, icl/x64 does not) 118 | # define XED_FMT_SIZET "%llu" 119 | #else // 32b everything else 120 | # define XED_FMT_SIZET "%u" 121 | #endif 122 | 123 | #if defined(__GNUC__) && defined(__LP64__) && !defined(__APPLE__) 124 | # define XED_FMT_LX "%lx" 125 | # define XED_FMT_LX_UPPER "%lX" 126 | # define XED_FMT_LU "%lu" 127 | # define XED_FMT_LU12 "%12lu" 128 | # define XED_FMT_LD "%ld" 129 | # define XED_FMT_LX16 "%016lx" 130 | # define XED_FMT_LX16_UPPER "%016lX" 131 | #else 132 | # define XED_FMT_LX "%llx" 133 | # define XED_FMT_LX_UPPER "%llX" 134 | # define XED_FMT_LU "%llu" 135 | # define XED_FMT_LU12 "%12llu" 136 | # define XED_FMT_LD "%lld" 137 | # define XED_FMT_LX16 "%016llx" 138 | # define XED_FMT_LX16_UPPER "%016llX" 139 | #endif 140 | 141 | #if defined(__LP64__) || defined (_M_X64) 142 | # define XED_64B 1 143 | #endif 144 | 145 | #if defined(_M_IA64) 146 | # define XED_IPF 147 | # define XED_FMT_SIZET "%lu" 148 | #endif 149 | 150 | #if defined(__GNUC__) 151 | /* gcc4.2.x has a bug with c99/gnu99 inlining */ 152 | # if __GNUC__ == 4 && __GNUC_MINOR__ == 2 153 | # define XED_INLINE inline 154 | # else 155 | # if __GNUC__ == 2 156 | # define XED_INLINE 157 | # else 158 | # define XED_INLINE inline 159 | # endif 160 | # endif 161 | # define XED_NORETURN __attribute__ ((noreturn)) 162 | # if __GNUC__ == 2 163 | # define XED_NOINLINE 164 | # else 165 | # define XED_NOINLINE __attribute__ ((noinline)) 166 | # endif 167 | #else 168 | # define XED_INLINE __inline 169 | # if defined(XED_MSVC6) 170 | # define XED_NOINLINE 171 | # else 172 | # define XED_NOINLINE __declspec(noinline) 173 | # endif 174 | # define XED_NORETURN __declspec(noreturn) 175 | #endif 176 | 177 | 178 | 179 | #define XED_MAX(a, b) (((a) > (b)) ? (a):(b)) 180 | #define XED_MIN(a, b) (((a) < (b)) ? (a):(b)) 181 | 182 | 183 | 184 | 185 | #endif // XED_PORTABILITY_H 186 | 187 | -------------------------------------------------------------------------------- /src/xed/include/xed-exception-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-exception-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_EXCEPTION_ENUM_H) 24 | # define XED_EXCEPTION_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_EXCEPTION_INVALID_DEFINED 1 27 | #define XED_EXCEPTION_AMX_E1_DEFINED 1 28 | #define XED_EXCEPTION_AMX_E2_DEFINED 1 29 | #define XED_EXCEPTION_AMX_E3_DEFINED 1 30 | #define XED_EXCEPTION_AMX_E4_DEFINED 1 31 | #define XED_EXCEPTION_AMX_E5_DEFINED 1 32 | #define XED_EXCEPTION_AMX_E6_DEFINED 1 33 | #define XED_EXCEPTION_AVX512_E1_DEFINED 1 34 | #define XED_EXCEPTION_AVX512_E10_DEFINED 1 35 | #define XED_EXCEPTION_AVX512_E10NF_DEFINED 1 36 | #define XED_EXCEPTION_AVX512_E11_DEFINED 1 37 | #define XED_EXCEPTION_AVX512_E12_DEFINED 1 38 | #define XED_EXCEPTION_AVX512_E12NP_DEFINED 1 39 | #define XED_EXCEPTION_AVX512_E1NF_DEFINED 1 40 | #define XED_EXCEPTION_AVX512_E2_DEFINED 1 41 | #define XED_EXCEPTION_AVX512_E3_DEFINED 1 42 | #define XED_EXCEPTION_AVX512_E3NF_DEFINED 1 43 | #define XED_EXCEPTION_AVX512_E4_DEFINED 1 44 | #define XED_EXCEPTION_AVX512_E4NF_DEFINED 1 45 | #define XED_EXCEPTION_AVX512_E5_DEFINED 1 46 | #define XED_EXCEPTION_AVX512_E5NF_DEFINED 1 47 | #define XED_EXCEPTION_AVX512_E6_DEFINED 1 48 | #define XED_EXCEPTION_AVX512_E6NF_DEFINED 1 49 | #define XED_EXCEPTION_AVX512_E7NM_DEFINED 1 50 | #define XED_EXCEPTION_AVX512_E7NM128_DEFINED 1 51 | #define XED_EXCEPTION_AVX512_E9NF_DEFINED 1 52 | #define XED_EXCEPTION_AVX512_K20_DEFINED 1 53 | #define XED_EXCEPTION_AVX512_K21_DEFINED 1 54 | #define XED_EXCEPTION_AVX_TYPE_1_DEFINED 1 55 | #define XED_EXCEPTION_AVX_TYPE_11_DEFINED 1 56 | #define XED_EXCEPTION_AVX_TYPE_12_DEFINED 1 57 | #define XED_EXCEPTION_AVX_TYPE_14_DEFINED 1 58 | #define XED_EXCEPTION_AVX_TYPE_2_DEFINED 1 59 | #define XED_EXCEPTION_AVX_TYPE_2D_DEFINED 1 60 | #define XED_EXCEPTION_AVX_TYPE_3_DEFINED 1 61 | #define XED_EXCEPTION_AVX_TYPE_4_DEFINED 1 62 | #define XED_EXCEPTION_AVX_TYPE_4M_DEFINED 1 63 | #define XED_EXCEPTION_AVX_TYPE_5_DEFINED 1 64 | #define XED_EXCEPTION_AVX_TYPE_5L_DEFINED 1 65 | #define XED_EXCEPTION_AVX_TYPE_6_DEFINED 1 66 | #define XED_EXCEPTION_AVX_TYPE_7_DEFINED 1 67 | #define XED_EXCEPTION_AVX_TYPE_8_DEFINED 1 68 | #define XED_EXCEPTION_MMX_FP_DEFINED 1 69 | #define XED_EXCEPTION_MMX_FP_16ALIGN_DEFINED 1 70 | #define XED_EXCEPTION_MMX_MEM_DEFINED 1 71 | #define XED_EXCEPTION_MMX_NOFP_DEFINED 1 72 | #define XED_EXCEPTION_MMX_NOFP2_DEFINED 1 73 | #define XED_EXCEPTION_MMX_NOMEM_DEFINED 1 74 | #define XED_EXCEPTION_SSE_TYPE_1_DEFINED 1 75 | #define XED_EXCEPTION_SSE_TYPE_2_DEFINED 1 76 | #define XED_EXCEPTION_SSE_TYPE_2D_DEFINED 1 77 | #define XED_EXCEPTION_SSE_TYPE_3_DEFINED 1 78 | #define XED_EXCEPTION_SSE_TYPE_4_DEFINED 1 79 | #define XED_EXCEPTION_SSE_TYPE_4M_DEFINED 1 80 | #define XED_EXCEPTION_SSE_TYPE_5_DEFINED 1 81 | #define XED_EXCEPTION_SSE_TYPE_7_DEFINED 1 82 | #define XED_EXCEPTION_LAST_DEFINED 1 83 | typedef enum { 84 | XED_EXCEPTION_INVALID, 85 | XED_EXCEPTION_AMX_E1, 86 | XED_EXCEPTION_AMX_E2, 87 | XED_EXCEPTION_AMX_E3, 88 | XED_EXCEPTION_AMX_E4, 89 | XED_EXCEPTION_AMX_E5, 90 | XED_EXCEPTION_AMX_E6, 91 | XED_EXCEPTION_AVX512_E1, 92 | XED_EXCEPTION_AVX512_E10, 93 | XED_EXCEPTION_AVX512_E10NF, 94 | XED_EXCEPTION_AVX512_E11, 95 | XED_EXCEPTION_AVX512_E12, 96 | XED_EXCEPTION_AVX512_E12NP, 97 | XED_EXCEPTION_AVX512_E1NF, 98 | XED_EXCEPTION_AVX512_E2, 99 | XED_EXCEPTION_AVX512_E3, 100 | XED_EXCEPTION_AVX512_E3NF, 101 | XED_EXCEPTION_AVX512_E4, 102 | XED_EXCEPTION_AVX512_E4NF, 103 | XED_EXCEPTION_AVX512_E5, 104 | XED_EXCEPTION_AVX512_E5NF, 105 | XED_EXCEPTION_AVX512_E6, 106 | XED_EXCEPTION_AVX512_E6NF, 107 | XED_EXCEPTION_AVX512_E7NM, 108 | XED_EXCEPTION_AVX512_E7NM128, 109 | XED_EXCEPTION_AVX512_E9NF, 110 | XED_EXCEPTION_AVX512_K20, 111 | XED_EXCEPTION_AVX512_K21, 112 | XED_EXCEPTION_AVX_TYPE_1, 113 | XED_EXCEPTION_AVX_TYPE_11, 114 | XED_EXCEPTION_AVX_TYPE_12, 115 | XED_EXCEPTION_AVX_TYPE_14, 116 | XED_EXCEPTION_AVX_TYPE_2, 117 | XED_EXCEPTION_AVX_TYPE_2D, 118 | XED_EXCEPTION_AVX_TYPE_3, 119 | XED_EXCEPTION_AVX_TYPE_4, 120 | XED_EXCEPTION_AVX_TYPE_4M, 121 | XED_EXCEPTION_AVX_TYPE_5, 122 | XED_EXCEPTION_AVX_TYPE_5L, 123 | XED_EXCEPTION_AVX_TYPE_6, 124 | XED_EXCEPTION_AVX_TYPE_7, 125 | XED_EXCEPTION_AVX_TYPE_8, 126 | XED_EXCEPTION_MMX_FP, 127 | XED_EXCEPTION_MMX_FP_16ALIGN, 128 | XED_EXCEPTION_MMX_MEM, 129 | XED_EXCEPTION_MMX_NOFP, 130 | XED_EXCEPTION_MMX_NOFP2, 131 | XED_EXCEPTION_MMX_NOMEM, 132 | XED_EXCEPTION_SSE_TYPE_1, 133 | XED_EXCEPTION_SSE_TYPE_2, 134 | XED_EXCEPTION_SSE_TYPE_2D, 135 | XED_EXCEPTION_SSE_TYPE_3, 136 | XED_EXCEPTION_SSE_TYPE_4, 137 | XED_EXCEPTION_SSE_TYPE_4M, 138 | XED_EXCEPTION_SSE_TYPE_5, 139 | XED_EXCEPTION_SSE_TYPE_7, 140 | XED_EXCEPTION_LAST 141 | } xed_exception_enum_t; 142 | 143 | /// This converts strings to #xed_exception_enum_t types. 144 | /// @param s A C-string. 145 | /// @return #xed_exception_enum_t 146 | /// @ingroup ENUM 147 | XED_DLL_EXPORT xed_exception_enum_t str2xed_exception_enum_t(const char* s); 148 | /// This converts strings to #xed_exception_enum_t types. 149 | /// @param p An enumeration element of type xed_exception_enum_t. 150 | /// @return string 151 | /// @ingroup ENUM 152 | XED_DLL_EXPORT const char* xed_exception_enum_t2str(const xed_exception_enum_t p); 153 | 154 | /// Returns the last element of the enumeration 155 | /// @return xed_exception_enum_t The last element of the enumeration. 156 | /// @ingroup ENUM 157 | XED_DLL_EXPORT xed_exception_enum_t xed_exception_enum_t_last(void); 158 | #endif 159 | -------------------------------------------------------------------------------- /src/xed/include/xed-chip-enum.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-chip-enum.h 19 | 20 | // This file was automatically generated. 21 | // Do not edit this file. 22 | 23 | #if !defined(XED_CHIP_ENUM_H) 24 | # define XED_CHIP_ENUM_H 25 | #include "xed-common-hdrs.h" 26 | #define XED_CHIP_INVALID_DEFINED 1 27 | #define XED_CHIP_I86_DEFINED 1 28 | #define XED_CHIP_I86FP_DEFINED 1 29 | #define XED_CHIP_I186_DEFINED 1 30 | #define XED_CHIP_I186FP_DEFINED 1 31 | #define XED_CHIP_I286REAL_DEFINED 1 32 | #define XED_CHIP_I286_DEFINED 1 33 | #define XED_CHIP_I2186FP_DEFINED 1 34 | #define XED_CHIP_I386REAL_DEFINED 1 35 | #define XED_CHIP_I386_DEFINED 1 36 | #define XED_CHIP_I386FP_DEFINED 1 37 | #define XED_CHIP_I486REAL_DEFINED 1 38 | #define XED_CHIP_I486_DEFINED 1 39 | #define XED_CHIP_PENTIUMREAL_DEFINED 1 40 | #define XED_CHIP_PENTIUM_DEFINED 1 41 | #define XED_CHIP_QUARK_DEFINED 1 42 | #define XED_CHIP_PENTIUMMMXREAL_DEFINED 1 43 | #define XED_CHIP_PENTIUMMMX_DEFINED 1 44 | #define XED_CHIP_ALLREAL_DEFINED 1 45 | #define XED_CHIP_PENTIUMPRO_DEFINED 1 46 | #define XED_CHIP_PENTIUM2_DEFINED 1 47 | #define XED_CHIP_PENTIUM3_DEFINED 1 48 | #define XED_CHIP_PENTIUM4_DEFINED 1 49 | #define XED_CHIP_P4PRESCOTT_DEFINED 1 50 | #define XED_CHIP_P4PRESCOTT_NOLAHF_DEFINED 1 51 | #define XED_CHIP_P4PRESCOTT_VTX_DEFINED 1 52 | #define XED_CHIP_MEROM_DEFINED 1 53 | #define XED_CHIP_PENRYN_DEFINED 1 54 | #define XED_CHIP_PENRYN_E_DEFINED 1 55 | #define XED_CHIP_NEHALEM_DEFINED 1 56 | #define XED_CHIP_WESTMERE_DEFINED 1 57 | #define XED_CHIP_BONNELL_DEFINED 1 58 | #define XED_CHIP_SALTWELL_DEFINED 1 59 | #define XED_CHIP_SILVERMONT_DEFINED 1 60 | #define XED_CHIP_VIA_DEFINED 1 61 | #define XED_CHIP_AMD_K10_DEFINED 1 62 | #define XED_CHIP_AMD_BULLDOZER_DEFINED 1 63 | #define XED_CHIP_AMD_PILEDRIVER_DEFINED 1 64 | #define XED_CHIP_AMD_ZEN_DEFINED 1 65 | #define XED_CHIP_AMD_ZENPLUS_DEFINED 1 66 | #define XED_CHIP_AMD_ZEN2_DEFINED 1 67 | #define XED_CHIP_AMD_FUTURE_DEFINED 1 68 | #define XED_CHIP_GOLDMONT_DEFINED 1 69 | #define XED_CHIP_GOLDMONT_PLUS_DEFINED 1 70 | #define XED_CHIP_TREMONT_DEFINED 1 71 | #define XED_CHIP_SNOW_RIDGE_DEFINED 1 72 | #define XED_CHIP_LAKEFIELD_DEFINED 1 73 | #define XED_CHIP_SANDYBRIDGE_DEFINED 1 74 | #define XED_CHIP_IVYBRIDGE_DEFINED 1 75 | #define XED_CHIP_HASWELL_DEFINED 1 76 | #define XED_CHIP_BROADWELL_DEFINED 1 77 | #define XED_CHIP_SKYLAKE_DEFINED 1 78 | #define XED_CHIP_COMET_LAKE_DEFINED 1 79 | #define XED_CHIP_SKYLAKE_SERVER_DEFINED 1 80 | #define XED_CHIP_CASCADE_LAKE_DEFINED 1 81 | #define XED_CHIP_COOPER_LAKE_DEFINED 1 82 | #define XED_CHIP_KNL_DEFINED 1 83 | #define XED_CHIP_KNM_DEFINED 1 84 | #define XED_CHIP_CANNONLAKE_DEFINED 1 85 | #define XED_CHIP_ICE_LAKE_DEFINED 1 86 | #define XED_CHIP_ICE_LAKE_SERVER_DEFINED 1 87 | #define XED_CHIP_TIGER_LAKE_DEFINED 1 88 | #define XED_CHIP_ALDER_LAKE_DEFINED 1 89 | #define XED_CHIP_SAPPHIRE_RAPIDS_DEFINED 1 90 | #define XED_CHIP_GRANITE_RAPIDS_DEFINED 1 91 | #define XED_CHIP_SIERRA_FOREST_DEFINED 1 92 | #define XED_CHIP_GRAND_RIDGE_DEFINED 1 93 | #define XED_CHIP_FUTURE_DEFINED 1 94 | #define XED_CHIP_ALL_DEFINED 1 95 | #define XED_CHIP_LAST_DEFINED 1 96 | typedef enum { 97 | XED_CHIP_INVALID, 98 | XED_CHIP_I86, 99 | XED_CHIP_I86FP, 100 | XED_CHIP_I186, 101 | XED_CHIP_I186FP, 102 | XED_CHIP_I286REAL, 103 | XED_CHIP_I286, 104 | XED_CHIP_I2186FP, 105 | XED_CHIP_I386REAL, 106 | XED_CHIP_I386, 107 | XED_CHIP_I386FP, 108 | XED_CHIP_I486REAL, 109 | XED_CHIP_I486, 110 | XED_CHIP_PENTIUMREAL, 111 | XED_CHIP_PENTIUM, 112 | XED_CHIP_QUARK, 113 | XED_CHIP_PENTIUMMMXREAL, 114 | XED_CHIP_PENTIUMMMX, 115 | XED_CHIP_ALLREAL, 116 | XED_CHIP_PENTIUMPRO, 117 | XED_CHIP_PENTIUM2, 118 | XED_CHIP_PENTIUM3, 119 | XED_CHIP_PENTIUM4, 120 | XED_CHIP_P4PRESCOTT, 121 | XED_CHIP_P4PRESCOTT_NOLAHF, 122 | XED_CHIP_P4PRESCOTT_VTX, 123 | XED_CHIP_MEROM, 124 | XED_CHIP_PENRYN, 125 | XED_CHIP_PENRYN_E, 126 | XED_CHIP_NEHALEM, 127 | XED_CHIP_WESTMERE, 128 | XED_CHIP_BONNELL, 129 | XED_CHIP_SALTWELL, 130 | XED_CHIP_SILVERMONT, 131 | XED_CHIP_VIA, 132 | XED_CHIP_AMD_K10, 133 | XED_CHIP_AMD_BULLDOZER, 134 | XED_CHIP_AMD_PILEDRIVER, 135 | XED_CHIP_AMD_ZEN, 136 | XED_CHIP_AMD_ZENPLUS, 137 | XED_CHIP_AMD_ZEN2, 138 | XED_CHIP_AMD_FUTURE, 139 | XED_CHIP_GOLDMONT, 140 | XED_CHIP_GOLDMONT_PLUS, 141 | XED_CHIP_TREMONT, 142 | XED_CHIP_SNOW_RIDGE, 143 | XED_CHIP_LAKEFIELD, 144 | XED_CHIP_SANDYBRIDGE, 145 | XED_CHIP_IVYBRIDGE, 146 | XED_CHIP_HASWELL, 147 | XED_CHIP_BROADWELL, 148 | XED_CHIP_SKYLAKE, 149 | XED_CHIP_COMET_LAKE, 150 | XED_CHIP_SKYLAKE_SERVER, 151 | XED_CHIP_CASCADE_LAKE, 152 | XED_CHIP_COOPER_LAKE, 153 | XED_CHIP_KNL, 154 | XED_CHIP_KNM, 155 | XED_CHIP_CANNONLAKE, 156 | XED_CHIP_ICE_LAKE, 157 | XED_CHIP_ICE_LAKE_SERVER, 158 | XED_CHIP_TIGER_LAKE, 159 | XED_CHIP_ALDER_LAKE, 160 | XED_CHIP_SAPPHIRE_RAPIDS, 161 | XED_CHIP_GRANITE_RAPIDS, 162 | XED_CHIP_SIERRA_FOREST, 163 | XED_CHIP_GRAND_RIDGE, 164 | XED_CHIP_FUTURE, 165 | XED_CHIP_ALL, 166 | XED_CHIP_LAST 167 | } xed_chip_enum_t; 168 | 169 | /// This converts strings to #xed_chip_enum_t types. 170 | /// @param s A C-string. 171 | /// @return #xed_chip_enum_t 172 | /// @ingroup ENUM 173 | XED_DLL_EXPORT xed_chip_enum_t str2xed_chip_enum_t(const char* s); 174 | /// This converts strings to #xed_chip_enum_t types. 175 | /// @param p An enumeration element of type xed_chip_enum_t. 176 | /// @return string 177 | /// @ingroup ENUM 178 | XED_DLL_EXPORT const char* xed_chip_enum_t2str(const xed_chip_enum_t p); 179 | 180 | /// Returns the last element of the enumeration 181 | /// @return xed_chip_enum_t The last element of the enumeration. 182 | /// @ingroup ENUM 183 | XED_DLL_EXPORT xed_chip_enum_t xed_chip_enum_t_last(void); 184 | #endif 185 | -------------------------------------------------------------------------------- /src/trace/headers/memtrace_stream.h: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | /* memtrace_stream: an interface to access aspects of the full stream of memory 34 | * trace records. 35 | * 36 | * We had considered other avenues for analysis_tool_t to obtain things like 37 | * the record and instruction ordinals within the stream, in the presence of 38 | * skipping: we could add fields to memref but we'd either have to append 39 | * and have them at different offsets for each type or we'd have to break 40 | * compatibility to prepend every time we added more; or we could add parameters 41 | * to process_memref(). Passing an interface to the init routines seems 42 | * the simplest and most flexible. 43 | */ 44 | 45 | #ifndef _MEMTRACE_STREAM_H_ 46 | #define _MEMTRACE_STREAM_H_ 1 47 | 48 | /** 49 | * @file drmemtrace/memtrace_stream.h 50 | * @brief DrMemtrace interface for obtaining information from analysis 51 | * tools on the full stream of memory reference records. 52 | */ 53 | 54 | /** 55 | * This is an interface for obtaining information from analysis tools 56 | * on the full stream of memory reference records. 57 | */ 58 | class memtrace_stream_t { 59 | public: 60 | /** Destructor. */ 61 | virtual ~memtrace_stream_t() 62 | { 63 | } 64 | /** 65 | * Returns the count of #memref_t records from the start of the trace to this point. 66 | * This includes records skipped over and not presented to any tool. 67 | */ 68 | virtual uint64_t 69 | get_record_ordinal() const = 0; 70 | /** 71 | * Returns the count of instructions from the start of the trace to this point. 72 | * This includes instructions skipped over and not presented to any tool. 73 | */ 74 | virtual uint64_t 75 | get_instruction_ordinal() const = 0; 76 | 77 | /** 78 | * Returns a name for the memtrace stream. For stored offline traces, this 79 | * is the base name of the trace on disk. For online traces, this is the name 80 | * of the pipe. 81 | */ 82 | virtual std::string 83 | get_stream_name() const = 0; 84 | 85 | /** 86 | * Returns the value of the last seen #TRACE_MARKER_TYPE_TIMESTAMP marker. 87 | */ 88 | virtual uint64_t 89 | get_last_timestamp() const = 0; 90 | 91 | /** 92 | * Returns the #trace_version_t value from the #TRACE_MARKER_TYPE_VERSION record 93 | * in the trace header. 94 | */ 95 | virtual uint64_t 96 | get_version() const = 0; 97 | 98 | /** 99 | * Returns the OFFLINE_FILE_TYPE_* bitfields of type #offline_file_type_t 100 | * identifying the architecture and other key high-level attributes of the trace 101 | * from the #TRACE_MARKER_TYPE_FILETYPE record in the trace header. 102 | */ 103 | virtual uint64_t 104 | get_filetype() const = 0; 105 | 106 | /** 107 | * Returns the cache line size from the #TRACE_MARKER_TYPE_CACHE_LINE_SIZE record in 108 | * the trace header. 109 | */ 110 | virtual uint64_t 111 | get_cache_line_size() const = 0; 112 | 113 | /** 114 | * Returns the chunk instruction count from the #TRACE_MARKER_TYPE_CHUNK_INSTR_COUNT 115 | * record in the trace header. 116 | */ 117 | virtual uint64_t 118 | get_chunk_instr_count() const = 0; 119 | 120 | /** 121 | * Returns the page size from the #TRACE_MARKER_TYPE_PAGE_SIZE record in 122 | * the trace header. 123 | */ 124 | virtual uint64_t 125 | get_page_size() const = 0; 126 | }; 127 | 128 | /** 129 | * Implementation of memtrace_stream_t useful for mocks in tests. 130 | */ 131 | class default_memtrace_stream_t : public memtrace_stream_t { 132 | public: 133 | default_memtrace_stream_t() 134 | : record_ordinal_(nullptr) 135 | { 136 | } 137 | default_memtrace_stream_t(uint64_t *record_ordinal) 138 | : record_ordinal_(record_ordinal) 139 | { 140 | } 141 | virtual ~default_memtrace_stream_t() 142 | { 143 | } 144 | uint64_t 145 | get_record_ordinal() const override 146 | { 147 | if (record_ordinal_ == nullptr) 148 | return 0; 149 | return *record_ordinal_; 150 | } 151 | uint64_t 152 | get_instruction_ordinal() const override 153 | { 154 | return 0; 155 | } 156 | std::string 157 | get_stream_name() const override 158 | { 159 | return ""; 160 | } 161 | uint64_t 162 | get_last_timestamp() const override 163 | { 164 | return 0; 165 | } 166 | uint64_t 167 | get_version() const override 168 | { 169 | return 0; 170 | } 171 | uint64_t 172 | get_filetype() const override 173 | { 174 | return 0; 175 | } 176 | uint64_t 177 | get_cache_line_size() const override 178 | { 179 | return 0; 180 | } 181 | uint64_t 182 | get_chunk_instr_count() const override 183 | { 184 | return 0; 185 | } 186 | uint64_t 187 | get_page_size() const override 188 | { 189 | return 0; 190 | } 191 | 192 | private: 193 | uint64_t *record_ordinal_; 194 | }; 195 | #endif /* _MEMTRACE_STREAM_H_ */ 196 | -------------------------------------------------------------------------------- /src/xed/include/xed-immdis.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-immdis.h 19 | /// 20 | 21 | 22 | 23 | #ifndef XED_IMMDIS_H 24 | # define XED_IMMDIS_H 25 | 26 | #include "xed-types.h" 27 | #include "xed-common-defs.h" 28 | #include "xed-util.h" 29 | 30 | 31 | //////////////////////////////////////////////////////////////////////////// 32 | // DEFINES 33 | //////////////////////////////////////////////////////////////////////////// 34 | 35 | //////////////////////////////////////////////////////////////////////////// 36 | // TYPES 37 | //////////////////////////////////////////////////////////////////////////// 38 | //////////////////////////////////////////////////////////////////////////// 39 | // PROTOTYPES 40 | //////////////////////////////////////////////////////////////////////////// 41 | 42 | //////////////////////////////////////////////////////////////////////////// 43 | // GLOBALS 44 | //////////////////////////////////////////////////////////////////////////// 45 | 46 | #define XED_MAX_IMMDIS_BYTES 8 47 | 48 | // A union for speed of zeroing 49 | union xed_immdis_values_t 50 | { 51 | xed_uint8_t x[XED_MAX_IMMDIS_BYTES];// STORED LITTLE ENDIAN. BYTE 0 is LSB 52 | xed_uint64_t q; 53 | }; 54 | 55 | /// Stores immediates and displacements for the encoder & decoder. 56 | typedef struct xed_immdis_s { 57 | union xed_immdis_values_t value; 58 | unsigned int currently_used_space :4; // current number of assigned bytes 59 | unsigned int max_allocated_space :4; // max allocation, 4 or 8 60 | xed_bool_t present : 1; 61 | xed_bool_t immediate_is_unsigned : 1; 62 | } xed_immdis_t; 63 | 64 | 65 | 66 | 67 | XED_DLL_EXPORT void xed_immdis_init(xed_immdis_t* p, xed_uint_t max_bytes); 68 | 69 | /// @name Sizes and lengths 70 | //@{ 71 | /// return the number of bytes added 72 | XED_DLL_EXPORT unsigned int xed_immdis_get_bytes(const xed_immdis_t* p) ; 73 | 74 | //@} 75 | 76 | /// @name Accessors for the value of the immediate or displacement 77 | //@{ 78 | XED_DLL_EXPORT xed_int64_t 79 | xed_immdis_get_signed64(const xed_immdis_t* p); 80 | 81 | XED_DLL_EXPORT xed_uint64_t 82 | xed_immdis_get_unsigned64(const xed_immdis_t* p); 83 | 84 | XED_DLL_EXPORT xed_bool_t 85 | xed_immdis_is_zero(const xed_immdis_t* p) ; 86 | 87 | XED_DLL_EXPORT xed_bool_t 88 | xed_immdis_is_one(const xed_immdis_t* p) ; 89 | 90 | /// Access the i'th byte of the immediate 91 | XED_DLL_EXPORT xed_uint8_t xed_immdis_get_byte(const xed_immdis_t* p, unsigned int i) ; 92 | //@} 93 | 94 | /// @name Presence / absence of an immediate or displacement 95 | //@{ 96 | XED_DLL_EXPORT void xed_immdis_set_present(xed_immdis_t* p) ; 97 | 98 | /// True if the object has had a value or individual bytes added to it. 99 | XED_DLL_EXPORT xed_bool_t xed_immdis_is_present(const xed_immdis_t* p) ; 100 | //@} 101 | 102 | 103 | /// @name Initialization and setup 104 | //@{ 105 | XED_DLL_EXPORT void xed_immdis_set_max_len(xed_immdis_t* p, unsigned int mx) ; 106 | XED_DLL_EXPORT void 107 | xed_immdis_zero(xed_immdis_t* p); 108 | 109 | XED_DLL_EXPORT unsigned int xed_immdis_get_max_length(const xed_immdis_t* p) ; 110 | 111 | //@} 112 | 113 | /// @name Signed vs Unsigned 114 | //@{ 115 | /// Return true if signed. 116 | XED_DLL_EXPORT xed_bool_t 117 | xed_immdis_is_unsigned(const xed_immdis_t* p) ; 118 | /// Return true if signed. 119 | XED_DLL_EXPORT xed_bool_t 120 | xed_immdis_is_signed(const xed_immdis_t* p) ; 121 | 122 | /// Set the immediate to be signed; For decoder use only. 123 | XED_DLL_EXPORT void 124 | xed_immdis_set_signed(xed_immdis_t* p) ; 125 | /// Set the immediate to be unsigned; For decoder use only. 126 | XED_DLL_EXPORT void 127 | xed_immdis_set_unsigned( xed_immdis_t* p) ; 128 | //@} 129 | 130 | 131 | /// @name Adding / setting values 132 | //@{ 133 | XED_DLL_EXPORT void 134 | xed_immdis_add_byte(xed_immdis_t* p, xed_uint8_t b); 135 | 136 | 137 | XED_DLL_EXPORT void 138 | xed_immdis_add_byte_array(xed_immdis_t* p, int nb, xed_uint8_t* ba); 139 | 140 | /// Add 1, 2, 4 or 8 bytes depending on the value x and the mask of 141 | /// legal_widths. The default value of legal_widths = 0x5 only stops 142 | /// adding bytes only on 1 or 4 byte quantities - depending on which 143 | /// bytes of x are zero -- as is used for most memory addressing. You 144 | /// can set legal_widths to 0x7 for branches (1, 2 or 4 byte branch 145 | /// displacements). Or if you have an 8B displacement, you can set 146 | /// legal_widths to 0x8. NOTE: add_shortest_width will add up to 147 | /// XED_MAX_IMMDIS_BYTES if the x value requires it. NOTE: 16b memory 148 | /// addressing can have 16b immediates. 149 | XED_DLL_EXPORT void 150 | xed_immdis_add_shortest_width_signed(xed_immdis_t* p, xed_int64_t x, xed_uint8_t legal_widths); 151 | 152 | /// See add_shortest_width_signed() 153 | XED_DLL_EXPORT void 154 | xed_immdis_add_shortest_width_unsigned(xed_immdis_t* p, xed_uint64_t x, xed_uint8_t legal_widths ); 155 | 156 | 157 | /// add an 8 bit value to the byte array 158 | XED_DLL_EXPORT void 159 | xed_immdis_add8(xed_immdis_t* p, xed_int8_t d); 160 | 161 | /// add a 16 bit value to the byte array 162 | XED_DLL_EXPORT void 163 | xed_immdis_add16(xed_immdis_t* p, xed_int16_t d); 164 | 165 | /// add a 32 bit value to the byte array 166 | XED_DLL_EXPORT void 167 | xed_immdis_add32(xed_immdis_t* p, xed_int32_t d); 168 | 169 | /// add a 64 bit value to the byte array. 170 | XED_DLL_EXPORT void 171 | xed_immdis_add64(xed_immdis_t* p, xed_int64_t d); 172 | 173 | //@} 174 | 175 | 176 | /// @name printing / debugging 177 | //@{ 178 | 179 | /// just print the raw bytes in hex with a leading 0x 180 | XED_DLL_EXPORT int xed_immdis_print(const xed_immdis_t* p, char* buf, int buflen); 181 | 182 | /// Print the value as a signed or unsigned number depending on the 183 | /// value of the immediate_is_unsigned variable. 184 | XED_DLL_EXPORT int 185 | xed_immdis_print_signed_or_unsigned(const xed_immdis_t* p, char* buf, int buflen); 186 | 187 | /// print the signed value, appropriate width, with a leading 0x 188 | XED_DLL_EXPORT int 189 | xed_immdis_print_value_signed(const xed_immdis_t* p, char* buf, int buflen); 190 | 191 | /// print the unsigned value, appropriate width, with a leading 0x 192 | XED_DLL_EXPORT int 193 | xed_immdis_print_value_unsigned(const xed_immdis_t* p, char* buf, int buflen); 194 | 195 | #endif 196 | 197 | //@} 198 | 199 | 200 | -------------------------------------------------------------------------------- /src/trace/headers/memref.h: -------------------------------------------------------------------------------- 1 | /* ********************************************************** 2 | * Copyright (c) 2015-2022 Google, Inc. All rights reserved. 3 | * **********************************************************/ 4 | 5 | /* 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of Google, Inc. nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | * DAMAGE. 31 | */ 32 | 33 | /* This is the data format that the simulator and analysis tools take as input. */ 34 | 35 | #ifndef _MEMREF_H_ 36 | #define _MEMREF_H_ 1 37 | 38 | #include 39 | #include // for size_t 40 | #include "../headers/trace_entry.h" 41 | 42 | /** 43 | * @file drmemtrace/memref.h 44 | * @brief DrMemtrace trace entry structures. 45 | */ 46 | 47 | // On some platforms, like MacOS, a thread id is 64 bits. 48 | // We just make both 64 bits to cover all our bases. 49 | typedef int_least64_t memref_pid_t; /**< Process id type. */ 50 | typedef int_least64_t memref_tid_t; /**< Thread id type. */ 51 | 52 | /** A trace entry representing a data load, store, or prefetch. */ 53 | struct _memref_data_t { 54 | trace_type_t type; /**< #TRACE_TYPE_READ, #TRACE_TYPE_WRITE, or type_is_prefetch(). */ 55 | memref_pid_t pid; /**< Process id. */ 56 | memref_tid_t tid; /**< Thread id. */ 57 | addr_t addr; /**< Address of data being loaded or stored. */ 58 | size_t size; /**< Size of data being loaded or stored. */ 59 | addr_t pc; /**< Program counter of instruction performing load or store. */ 60 | }; 61 | 62 | /** A trace entry representing an instruction fetch. */ 63 | struct _memref_instr_t { 64 | trace_type_t type; /**< Matches type_is_i0nstr() or #TRACE_TYPE_INSTR_NO_FETCH. */ 65 | memref_pid_t pid; /**< Process id. */ 66 | memref_tid_t tid; /**< Thread id. */ 67 | addr_t addr; /**< The address of the instruction (i.e., program counter). */ 68 | size_t size; /**< The length of the instruction. */ 69 | /** 70 | * The instruction's raw encoding. This field is only valid when the the file type 71 | * (see #TRACE_MARKER_TYPE_FILETYPE) has #OFFLINE_FILE_TYPE_ENCODINGS set. 72 | * DynamoRIO's decode_from_copy() (or any other decoding library) can be used to 73 | * decode into a higher-level instruction representation. 74 | */ 75 | unsigned char encoding[MAX_ENCODING_LENGTH]; 76 | /** 77 | * Indicates whether the encoding field is the first instance of its kind for this 78 | * address. This can be used to determine when to invalidate cached decoding 79 | * information. This field may be set to true on internal file divisions and 80 | * not only when application code actually changed. 81 | */ 82 | bool encoding_is_new; 83 | }; 84 | 85 | /** A trace entry representing a software-requested explicit cache flush. */ 86 | struct _memref_flush_t { 87 | trace_type_t type; /**< #TRACE_TYPE_INSTR_FLUSH or #TRACE_TYPE_DATA_FLUSH. */ 88 | memref_pid_t pid; /**< Process id. */ 89 | memref_tid_t tid; /**< Thread id. */ 90 | addr_t addr; /**< The start address of the region being flushed. */ 91 | size_t size; /**< The size of the region being flushed. */ 92 | addr_t pc; /**< Program counter of the instruction requesting the flush. */ 93 | }; 94 | 95 | 96 | /** A trace entry representing a thread exit. */ 97 | struct _memref_thread_exit_t { 98 | trace_type_t type; /**< #TRACE_TYPE_THREAD_EXIT. */ 99 | memref_pid_t pid; /**< Process id. */ 100 | memref_tid_t tid; /**< Thread id. */ 101 | }; 102 | 103 | /** 104 | * A trace entry containing metadata identifying some event that occurred at this 105 | * point in the trace. Common markers include timestamp and cpu information for 106 | * certain points in the trace. Another marker type represents a kernel-mediated 107 | * control flow change such as a signal delivery, entry into an APC, callback, or 108 | * exception dispatcher on Windows, or a system call that changes the context such as 109 | * a signal return. 110 | */ 111 | struct _memref_marker_t { 112 | trace_type_t type; /**< #TRACE_TYPE_MARKER. */ 113 | memref_pid_t pid; /**< Process id. */ 114 | memref_tid_t tid; /**< Thread id. */ 115 | trace_marker_type_t marker_type; /**< Identifies the type of marker. */ 116 | uintptr_t marker_value; /**< A value whose meaning depends on the marker type. */ 117 | }; 118 | 119 | /** 120 | * Each trace entry is one of the structures in this union. 121 | * Each entry identifies the originating process and thread. 122 | * Although the pc of each data reference is provided, the trace also guarantees that 123 | * an instruction entry immediately precedes the data references that it is 124 | * responsible for, with no intervening trace entries (unless it is a trace filtered 125 | * with an online first-level cache). 126 | * Offline traces further guarantee that an instruction entry for a branch 127 | * instruction is always followed by an instruction entry for the branch's 128 | * target (with any memory references for the branch in between of course) 129 | * without a thread switch intervening, to make it simpler to identify branch 130 | * targets (again, unless the trace is filtered by an online first-level cache). 131 | * Online traces do not currently guarantee this. 132 | */ 133 | typedef union _memref_t { 134 | // The C standard allows us to reference the type field of any of these, and the 135 | // addr and size fields of data, instr, or flush generically if known to be one 136 | // of those types, due to the shared fields in our union of structs. 137 | struct _memref_data_t data; /**< A data load or store. */ 138 | struct _memref_instr_t instr; /**< An instruction fetch. */ 139 | struct _memref_flush_t flush; /**< A software-initiated cache flush. */ 140 | struct _memref_thread_exit_t exit; /**< A thread exit. */ 141 | struct _memref_marker_t marker; /**< A marker holding metadata. */ 142 | } memref_t; 143 | 144 | #endif /* _MEMREF_H_ */ 145 | -------------------------------------------------------------------------------- /src/xed/include/xed-state.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-state.h 19 | /// 20 | 21 | 22 | 23 | #ifndef XED_STATE_H 24 | # define XED_STATE_H 25 | #include "xed-types.h" 26 | #include "xed-portability.h" 27 | #include "xed-address-width-enum.h" // generated 28 | #include "xed-machine-mode-enum.h" // generated 29 | 30 | 31 | /// Encapsulates machine modes for decoder/encoder requests. 32 | /// It specifies the machine operating mode as a 33 | /// #xed_machine_mode_enum_t 34 | /// for decoding and encoding. The machine mode corresponds to the default 35 | /// data operand width for that mode. For all modes other than the 64b long 36 | /// mode (XED_MACHINE_MODE_LONG_64), a default addressing width, and a 37 | /// stack addressing width must be supplied of type 38 | /// #xed_address_width_enum_t . @ingroup INIT 39 | typedef struct xed_state_s { 40 | /// real architected machine modes 41 | xed_machine_mode_enum_t mmode; 42 | /// for 16b/32b modes 43 | xed_address_width_enum_t stack_addr_width; 44 | } xed_state_t; 45 | 46 | /// @name Initialization 47 | //@{ 48 | /// Constructor. 49 | /// DEPRECATED: use #xed_state_init2(). 50 | /// The mode, and addresses widths are enumerations that specify the number 51 | /// of bits. In 64b mode (#XED_MACHINE_MODE_LONG_64) the address width and 52 | /// stack address widths are 64b (#XED_ADDRESS_WIDTH_64b). In other machine 53 | /// modes, you must specify valid addressing widths. 54 | /// 55 | /// @param p the pointer to the #xed_state_t type 56 | /// @param arg_mmode the machine mode of type #xed_machine_mode_enum_t 57 | /// @param arg_ignored Ignored. The addressing width is now implied by the machine mode implied by arg_mmmode. 58 | /// @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) 59 | /// @ingroup INIT 60 | static XED_INLINE void xed_state_init(xed_state_t* p, 61 | xed_machine_mode_enum_t arg_mmode, 62 | xed_address_width_enum_t arg_ignored, 63 | xed_address_width_enum_t arg_stack_addr_width) { 64 | p->mmode=arg_mmode; 65 | p->stack_addr_width=arg_stack_addr_width; 66 | (void) arg_ignored; //pacify compiler unused arg warning 67 | } 68 | 69 | /// Constructor. 70 | /// The mode, and addresses widths are enumerations that specify the number 71 | /// of bits. In 64b mode (#XED_MACHINE_MODE_LONG_64) the address width and 72 | /// stack address widths are 64b (#XED_ADDRESS_WIDTH_64b). In other machine 73 | /// modes, you must specify valid addressing widths. 74 | /// 75 | /// @param p the pointer to the #xed_state_t type 76 | /// @param arg_mmode the machine mode of type #xed_machine_mode_enum_t 77 | /// @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) 78 | /// @ingroup INIT 79 | static XED_INLINE void xed_state_init2(xed_state_t* p, 80 | xed_machine_mode_enum_t arg_mmode, 81 | xed_address_width_enum_t arg_stack_addr_width) { 82 | p->mmode=arg_mmode; 83 | p->stack_addr_width=arg_stack_addr_width; 84 | } 85 | 86 | /// clear the xed_state_t 87 | /// @ingroup INIT 88 | static XED_INLINE void xed_state_zero(xed_state_t* p) { 89 | p->mmode= XED_MACHINE_MODE_INVALID; 90 | p->stack_addr_width=XED_ADDRESS_WIDTH_INVALID; 91 | } 92 | 93 | //@} 94 | 95 | /// @name Machine mode 96 | //@{ 97 | /// return the machine mode 98 | /// @ingroup INIT 99 | static XED_INLINE xed_machine_mode_enum_t xed_state_get_machine_mode(const xed_state_t* p) { 100 | return p->mmode; 101 | } 102 | 103 | 104 | /// true iff the machine is in LONG_64 mode 105 | /// @ingroup INIT 106 | static XED_INLINE xed_bool_t xed_state_long64_mode(const xed_state_t* p) { 107 | return xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_64; 108 | } 109 | 110 | /// @ingroup INIT 111 | static XED_INLINE xed_bool_t xed_state_real_mode(const xed_state_t* p) { 112 | xed_machine_mode_enum_t mmode = xed_state_get_machine_mode(p); 113 | return ( mmode == XED_MACHINE_MODE_REAL_16 || 114 | mmode == XED_MACHINE_MODE_REAL_32 ); 115 | } 116 | 117 | /// @ingroup INIT 118 | static XED_INLINE xed_bool_t xed_state_mode_width_16(const xed_state_t* p) { 119 | return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LEGACY_16) || 120 | (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_COMPAT_16); 121 | } 122 | 123 | /// @ingroup INIT 124 | static XED_INLINE xed_bool_t xed_state_mode_width_32(const xed_state_t* p) { 125 | return (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LEGACY_32) || 126 | (xed_state_get_machine_mode(p) == XED_MACHINE_MODE_LONG_COMPAT_32); 127 | } 128 | 129 | 130 | /// Set the machine mode which corresponds to the default data operand size 131 | /// @ingroup INIT 132 | static XED_INLINE void xed_state_set_machine_mode( xed_state_t* p, 133 | xed_machine_mode_enum_t arg_mode) { 134 | p->mmode = arg_mode; 135 | } 136 | //@} 137 | 138 | /// @name Address width 139 | //@{ 140 | 141 | /// return the address width 142 | /// @ingroup INIT 143 | static XED_INLINE xed_address_width_enum_t 144 | xed_state_get_address_width(const xed_state_t* p) 145 | { 146 | switch(xed_state_get_machine_mode(p)) { 147 | case XED_MACHINE_MODE_LONG_64: 148 | return XED_ADDRESS_WIDTH_64b; 149 | 150 | case XED_MACHINE_MODE_REAL_16: 151 | case XED_MACHINE_MODE_REAL_32: 152 | /* should be 20b... but if you are working w/real mode then you're 153 | going to have to deal with somehow. Could easily make this be 154 | 20b if anyone cares. */ 155 | return XED_ADDRESS_WIDTH_32b; 156 | 157 | case XED_MACHINE_MODE_LEGACY_32: 158 | case XED_MACHINE_MODE_LONG_COMPAT_32: 159 | return XED_ADDRESS_WIDTH_32b; 160 | case XED_MACHINE_MODE_LEGACY_16: 161 | case XED_MACHINE_MODE_LONG_COMPAT_16: 162 | return XED_ADDRESS_WIDTH_16b; 163 | default: 164 | return XED_ADDRESS_WIDTH_INVALID; 165 | } 166 | } 167 | 168 | //@} 169 | 170 | /// @name Stack address width 171 | //@{ 172 | /// set the STACK address width 173 | /// @ingroup INIT 174 | static XED_INLINE void 175 | xed_state_set_stack_address_width(xed_state_t* p, 176 | xed_address_width_enum_t arg_addr_width) 177 | { 178 | p->stack_addr_width = arg_addr_width; 179 | } 180 | 181 | 182 | /// Return the STACK address width 183 | /// @ingroup INIT 184 | static XED_INLINE xed_address_width_enum_t xed_state_get_stack_address_width(const xed_state_t* p) { 185 | return p->stack_addr_width; 186 | } 187 | //@} 188 | 189 | /// @ingroup INIT 190 | XED_DLL_EXPORT int xed_state_print(const xed_state_t* p, char* buf, int buflen); 191 | 192 | #endif 193 | 194 | -------------------------------------------------------------------------------- /src/xed/include/xed-flags.h: -------------------------------------------------------------------------------- 1 | /* BEGIN_LEGAL 2 | 3 | Copyright (c) 2022 Intel Corporation 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | END_LEGAL */ 18 | /// @file xed-flags.h 19 | /// 20 | 21 | #ifndef XED_FLAGS_H 22 | # define XED_FLAGS_H 23 | 24 | #include "xed-types.h" 25 | #include "xed-portability.h" 26 | #include "xed-flag-enum.h" 27 | #include "xed-flag-action-enum.h" 28 | #include "xed-gen-table-defs.h" 29 | 30 | 31 | //////////////////////////////////////////////////////////////////////////// 32 | /// @ingroup FLAGS 33 | /// a union of flags bits 34 | union xed_flag_set_s { 35 | xed_uint32_t flat; 36 | struct { 37 | xed_uint32_t cf:1; ///< bit 0 38 | xed_uint32_t must_be_1:1; 39 | xed_uint32_t pf:1; 40 | xed_uint32_t must_be_0a:1; 41 | 42 | xed_uint32_t af:1; ///< bit 4 43 | xed_uint32_t must_be_0b:1; 44 | xed_uint32_t zf:1; 45 | xed_uint32_t sf:1; 46 | 47 | xed_uint32_t tf:1; ///< bit 8 48 | xed_uint32_t _if:1; ///< underscore to avoid token clash 49 | xed_uint32_t df:1; 50 | xed_uint32_t of:1; 51 | 52 | xed_uint32_t iopl:2; ///< A 2-bit field, bits 12-13 53 | xed_uint32_t nt:1; 54 | xed_uint32_t must_be_0c:1; 55 | 56 | xed_uint32_t rf:1; ///< bit 16 57 | xed_uint32_t vm:1; 58 | xed_uint32_t ac:1; 59 | xed_uint32_t vif:1; 60 | 61 | xed_uint32_t vip:1; ///< bit 20 62 | xed_uint32_t id:1; ///< bit 21 63 | xed_uint32_t must_be_0d:2; ///< bits 22-23 64 | 65 | xed_uint32_t must_be_0e:4; ///< bits 24-27 66 | 67 | // fc0,fc1,fc2,fc3 are not really part of rflags but I put them 68 | // here to save space. These bits are only used for x87 69 | // instructions. 70 | xed_uint32_t fc0:1; ///< x87 flag FC0 (not really part of rflags) 71 | xed_uint32_t fc1:1; ///< x87 flag FC1 (not really part of rflags) 72 | xed_uint32_t fc2:1; ///< x87 flag FC2 (not really part of rflags) 73 | xed_uint32_t fc3:1; ///< x87 flag FC3 (not really part of rflags) 74 | } s; 75 | 76 | }; 77 | 78 | typedef union xed_flag_set_s xed_flag_set_t; 79 | /// @ingroup FLAGS 80 | /// @name Flag-set accessors 81 | //@{ 82 | /// @ingroup FLAGS 83 | /// print the flag set in the supplied buffer 84 | XED_DLL_EXPORT int xed_flag_set_print(const xed_flag_set_t* p, char* buf, int buflen); 85 | /// @ingroup FLAGS 86 | /// returns true if this object has a subset of the flags of the 87 | /// "other" object. 88 | XED_DLL_EXPORT xed_bool_t xed_flag_set_is_subset_of(const xed_flag_set_t* p, 89 | const xed_flag_set_t* other); 90 | //@} 91 | 92 | 93 | //////////////////////////////////////////////////////////////////////////// 94 | 95 | /// @ingroup FLAGS 96 | /// Associated with each flag field there can be one action. 97 | typedef struct xed_flag_enum_s { 98 | xed_flag_enum_t flag; 99 | // there are at most two actions per flag. The 2nd may be invalid. 100 | xed_flag_action_enum_t action; 101 | } xed_flag_action_t; 102 | 103 | 104 | 105 | 106 | /// @ingroup FLAGS 107 | /// @name Lowest-level flag-action accessors 108 | //@{ 109 | /// @ingroup FLAGS 110 | /// get the name of the flag 111 | XED_DLL_EXPORT xed_flag_enum_t 112 | xed_flag_action_get_flag_name(const xed_flag_action_t* p); 113 | /// @ingroup FLAGS 114 | /// return the action 115 | XED_DLL_EXPORT xed_flag_action_enum_t 116 | xed_flag_action_get_action(const xed_flag_action_t* p, unsigned int i); 117 | /// @ingroup FLAGS 118 | /// returns true if the specified action is invalid. Only the 2nd flag might be invalid. 119 | XED_DLL_EXPORT xed_bool_t 120 | xed_flag_action_action_invalid(const xed_flag_action_enum_t a); 121 | /// @ingroup FLAGS 122 | /// print the flag & actions 123 | XED_DLL_EXPORT int xed_flag_action_print(const xed_flag_action_t* p, char* buf, int buflen); 124 | /// @ingroup FLAGS 125 | /// returns true if either action is a read 126 | XED_DLL_EXPORT xed_bool_t 127 | xed_flag_action_read_flag(const xed_flag_action_t* p ); 128 | /// @ingroup FLAGS 129 | /// returns true if either action is a write 130 | XED_DLL_EXPORT xed_bool_t 131 | xed_flag_action_writes_flag(const xed_flag_action_t* p); 132 | 133 | /// @ingroup FLAGS 134 | /// test to see if the specific action is a read 135 | XED_DLL_EXPORT xed_bool_t 136 | xed_flag_action_read_action( xed_flag_action_enum_t a); 137 | /// @ingroup FLAGS 138 | /// test to see if a specific action is a write 139 | XED_DLL_EXPORT xed_bool_t 140 | xed_flag_action_write_action( xed_flag_action_enum_t a); 141 | //@} 142 | 143 | //////////////////////////////////////////////////////////////////////////// 144 | 145 | /// @ingroup FLAGS 146 | /// A collection of #xed_flag_action_t's and unions of read and written flags 147 | typedef struct xed_simple_flag_s 148 | { 149 | ///number of flag actions associated with this record 150 | xed_uint8_t nflags; 151 | 152 | xed_uint8_t may_write; /* 1/0, only using one bit */ 153 | xed_uint8_t must_write; /* 1/0, only using one bit */ 154 | 155 | ///union of read flags 156 | xed_flag_set_t read; 157 | 158 | /// union of written flags (includes undefined flags); 159 | xed_flag_set_t written; 160 | 161 | /// union of undefined flags; 162 | xed_flag_set_t undefined; 163 | 164 | // index in to the xed_flag_action_table. nflags limits the # of entries. 165 | xed_uint16_t fa_index; 166 | 167 | } xed_simple_flag_t; 168 | 169 | /// @ingroup FLAGS 170 | /// @name Accessing the simple flags (Mid-level access) 171 | //@{ 172 | /// @ingroup FLAGS 173 | /// returns the number of flag-actions 174 | XED_DLL_EXPORT unsigned int 175 | xed_simple_flag_get_nflags(const xed_simple_flag_t* p); 176 | 177 | /// @ingroup FLAGS 178 | /// return union of bits for read flags 179 | XED_DLL_EXPORT const xed_flag_set_t* 180 | xed_simple_flag_get_read_flag_set(const xed_simple_flag_t* p); 181 | 182 | /// @ingroup FLAGS 183 | /// return union of bits for written flags 184 | XED_DLL_EXPORT const xed_flag_set_t* 185 | xed_simple_flag_get_written_flag_set(const xed_simple_flag_t* p); 186 | 187 | 188 | /// @ingroup FLAGS 189 | /// return union of bits for undefined flags 190 | XED_DLL_EXPORT const xed_flag_set_t* 191 | xed_simple_flag_get_undefined_flag_set(const xed_simple_flag_t* p); 192 | 193 | /// @ingroup FLAGS 194 | /// Indicates the flags are only conditionally written. Usually MAY-writes 195 | /// of the flags instructions that are dependent on a REP count. 196 | XED_DLL_EXPORT xed_bool_t xed_simple_flag_get_may_write(const xed_simple_flag_t* p); 197 | 198 | /// @ingroup FLAGS 199 | /// the flags always written 200 | XED_DLL_EXPORT xed_bool_t xed_simple_flag_get_must_write(const xed_simple_flag_t* p); 201 | 202 | /// @ingroup FLAGS 203 | /// return the specific flag-action. Very detailed low level information 204 | XED_DLL_EXPORT const xed_flag_action_t* 205 | xed_simple_flag_get_flag_action(const xed_simple_flag_t* p, unsigned int i); 206 | 207 | /// @ingroup FLAGS 208 | /// boolean test to see if flags are read, scans the flags 209 | XED_DLL_EXPORT xed_bool_t 210 | xed_simple_flag_reads_flags(const xed_simple_flag_t* p); 211 | 212 | /// @ingroup FLAGS 213 | /// boolean test to see if flags are written, scans the flags 214 | XED_DLL_EXPORT xed_bool_t xed_simple_flag_writes_flags(const xed_simple_flag_t* p); 215 | 216 | /// @ingroup FLAGS 217 | /// print the flags 218 | XED_DLL_EXPORT int xed_simple_flag_print(const xed_simple_flag_t* p, char* buf, int buflen); 219 | 220 | /// @ingroup FLAGS 221 | /// Return the flags as a mask 222 | static XED_INLINE unsigned int xed_flag_set_mask(const xed_flag_set_t* p) { 223 | return p->flat; // FIXME: could mask out the X87 flags 224 | } 225 | 226 | //@} 227 | 228 | //////////////////////////////////////////////////////////////////////////// 229 | 230 | 231 | //////////////////////////////////////////////////////////////////////////// 232 | 233 | #endif 234 | --------------------------------------------------------------------------------