### XED Disassembly Example (PUSH) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example shows the disassembly of a 'PUSH' instruction with an immediate value. It provides details about the instruction's class, category, form, ISA set, and attributes. ```bash % xed -d 6a00 ICLASS: PUSH CATEGORY: PUSH EXTENSION: BASE IFORM: PUSH_IMMb ISA_SET: I186 ATTRIBUTES: FIXED_BASE0 SCALABLE STACKPUSH0 SHORT: push 0x0 ``` -------------------------------- ### REP Prefix API Example (xed-rep-string.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html Shows the usage of the REP prefix APIs. This functionality allows for the conversion between REP prefixed instructions and their non-REP variants (and vice versa), simplifying string operation handling. ```c /* * @brief REP prefix API example * * Shows the use of the REP prefix APIs, which basically returns the non-REP variant of a REP ICLASS and vice versa. */ // Source code for xed-rep-string.c would be included here. ``` -------------------------------- ### XED Disassembly Example (ADD) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example demonstrates using XED for disassembly, specifically showing the 'ADD' instruction with memory and register operands. It outputs the instruction class, category, extension,iform, ISA set, attributes, and a short disassembly. ```bash % xed -d 0000 ICLASS: ADD CATEGORY: BINARY EXTENSION: BASE IFORM: ADD_MEMb_GPR8 ISA_SET: I86 ATTRIBUTES: BYTEOP LOCKABLE SHORT: add byte ptr [eax], al ``` -------------------------------- ### XED Encoding Example (ADD with Memory) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example demonstrates encoding an 'ADD' instruction involving a memory operand with a scaled index. It details the request parameters, operand order, and the generated machine code. ```bash % xed -e ADD EAX MEM4:ESP,EBX,4 Request: ADD EASZ:2, MEM0:dword ptr [ESP+EBX*4], MEM_WIDTH:4, MODE:1, REG0:EAX, SMODE:1 OPERAND ORDER: REG0 MEM0 Encodable! 03049C .byte 0x03,0x04,0x9c ``` -------------------------------- ### xed-enc Example: PUSH RAX Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example demonstrates using 'xed-enc' to encode a 'PUSH RAX' instruction in 64-bit mode. It shows the resulting encode request and the generated machine code. ```bash % obj/xed-enc -64 PUSH/64 RAX Encode request: PUSH EOSZ:3, MODE:2, REG0:RAX, SMODE:2 OPERAND ORDER: REG0 Encodable! 50 ``` -------------------------------- ### XED Encoding Example (ADD EAX EBX) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example shows how to use XED to encode an instruction. It takes the instruction mnemonic and operands as input and outputs the request details, operand order, and the resulting byte sequence. ```bash % xed -e ADD EAX EBX Request: ADD MODE:1, REG0:EAX, REG1:EBX, SMODE:1 OPERAND ORDER: REG0 REG1 Encodable! 01D8 .byte 0x01,0xd8 ``` -------------------------------- ### Example: Creating LEA Instruction with ENC2 Checked Interface Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__ENC2.html Provides a C function signature example for creating a 64-bit LEA instruction using the ENC2 checked interface. It takes a pointer to an output buffer and declares variables for destination, base, and index registers. ```c xed_uint32_t create_lea_64b(xed_uint8_t* output_buffer) { xed_reg_enum_t dest, base, index; // ... implementation details ... } ``` -------------------------------- ### XED Encoding Example (MOV with Memory) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example demonstrates encoding a 'MOV' instruction that moves data from memory to a register. It outlines the request parameters, operand order, and the resulting byte sequence. ```bash % xed -e MOV EAX MEM4:SS:ESP Request: MOV EASZ:2, MEM0:dword ptr SS[ESP], MEM_WIDTH:4, MODE:1, REG0:EAX, SMODE:1 OPERAND ORDER: REG0 MEM0 Encodable! 8B0424 .byte 0x8b,0x04,0x24 ``` -------------------------------- ### XED Encoding Example (CCMPB) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example demonstrates encoding the 'CCMPB' instruction in 64-bit mode with specific register operands and a DFV value. It shows the request details and the generated machine code. ```bash % xed -64 -set DFV 14 -e CCMPB r8b r9b Request: CCMPB DFV:14, MODE:2, REG0:R8B, REG1:R9B, SMODE:2 OPERAND ORDER: REG0 REG1 Encodable! 6254740238C8 .byte 0x62,0x54,0x74,0x02,0x38,0xc8 ``` -------------------------------- ### Minimal x86 Instruction Decoding with Intel XED (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html This example demonstrates the minimal setup required to decode an x86 instruction using the Intel XED library. It initializes the XED tables, sets the machine mode, and then attempts to decode a small byte sequence, printing the result and any errors encountered. It iterates through different byte lengths to show how XED handles partial or invalid instructions. ```c #include "xed/xed-interface.h" #include #include int main(int argc, char** argv); int main(int argc, char** argv) { xed_machine_mode_enum_t mmode; xed_address_width_enum_t stack_addr_width; xed_bool_t long_mode = 0; // create the decoded instruction, and fill in the machine mode (dstate) // make up a simple 2Byte instruction to decode unsigned int bytes = 0; unsigned char itext[15] = { 0xf, 0x85, 0x99, 0x00, 0x00, 0x00 }; // initialize the XED tables -- one time. xed_tables_init(); // Test api_check by passing an invalid iclass. // With api_check enabled (default): aborts with a diagnostic message. // With api_check disabled (--no-api-check build): survives and continues. // Usage: xed-dec-min --test-api-check if (argc >= 2 && strcmp(argv[1], "--test-api-check") == 0) { xed_iform_max_per_iclass(XED_ICLASS_INVALID); printf("api_check did NOT abort (checks disabled)\n"); return 0; } // The state of the machine -- required for decoding if (long_mode) { mmode=XED_MACHINE_MODE_LONG_64; stack_addr_width = XED_ADDRESS_WIDTH_64b; } else { mmode=XED_MACHINE_MODE_LEGACY_32; stack_addr_width = XED_ADDRESS_WIDTH_32b; } // This is a test of error handling. I vary the instuction length from // 0 bytes to 15 bytes. Normally, you should send in 15 bytes of itext // unless you are near the end of a page and don't want to take a page // fault or tlb miss. Note, you have to reinitialize the xedd each time // you try to decode in to it. // Try different instruction lengths to see when XED recognizes an // instruction as valid. for(bytes = 0;bytes<=15;bytes++) { xed_error_enum_t xed_error; xed_decoded_inst_t xedd; xed_decoded_inst_zero(&xedd); xed_decoded_inst_set_mode(&xedd, mmode, stack_addr_width); xed_error = xed_decode(&xedd, XED_STATIC_CAST(const xed_uint8_t*,itext), bytes); printf("%d %s\n",(int)bytes, xed_error_enum_t2str(xed_error)); } (void) argc; (void) argv; //pacify compiler return 0; } ``` -------------------------------- ### Accessing Intel® XED Tables Example (xed-tables.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html This example demonstrates how to access Intel® XED's internal tables. These tables contain static data for all Intel® XED-supported instructions, providing insights into the library's data structures. ```c /* * @brief Example accessing Intel® XED internal tables * * An example that shows how to access Intel® XED's internal tables, which contain static data for all Intel® XED-supported instructions. */ // Source code for xed-tables.c would be included here. ``` -------------------------------- ### Compile xed-dec-min Example with GCC Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html This snippet shows how to compile the 'xed-dec-min.c' example using GCC. It requires specifying include paths for the XED kit and linking against the XED library. The output is an executable file named 'xed-dec-min'. ```bash # Compile the C file into an object file gcc -Ipath-to-xed-kit/include -Ipath-to-xed-kit/examples \ -c path-to-xed-kit/examples/xed-dec-min.c # Link the object file with the XED library to create an executable gcc -o xed-dec-min xed-dec-min.o path-to-xed-kit/lib/libxed.a ``` -------------------------------- ### Link Intel XED Library (Linux/macOS) (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/index.html This example demonstrates the linker command for Linux and macOS systems to include the Intel XED library. It specifies the library path and the library name. ```shell -L/path/to/xed-kit-name/lib -lxed ``` -------------------------------- ### Decoder with Features Example (xed-dec-control.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html A simple decoder example demonstrating different disassembly output formats and the usage of new decode-with-features APIs. It provides descriptive examples of advanced decoding capabilities. ```c /* * @brief Decoder example with different disassembly output formats * * A simple decoder example with different disassembly output formats. It contains highly descriptive usages of the new decode-with-features APIs. */ // Source code for xed-dec-control.c would be included here. ``` -------------------------------- ### Environment Initialization Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env.env_t-class.html Initializes the build environment, optionally setting default knobs and verbosity. ```APIDOC ## __init__ (Constructor) ### Description Build up the environment for compilation. ### Method __init__ ### Parameters * **init_verbose** (int) - Optional - Verbosity level for initialization. * **default_knobs** (bool) - Optional - Whether to set default knobs. ``` -------------------------------- ### Direct Encoder Example (xed-enc-direct.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html A straightforward, non-dynamic encoder example that utilizes the high-level encoding API. It provides a simple way to perform encoding operations without complex setup. ```c /* * @brief Simple non-dynamic encoder example * * A simple non-dynamic encoder example using the high-level encoding API. */ // Source code for xed-enc-direct.c would be included here. ``` -------------------------------- ### Instruction Length Decoder Example (xed-dec-ild.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html An example focused on using the instruction length decoder API. This example specifically loads only the xed-ild library, demonstrating its standalone usage for determining instruction lengths. ```c /* * @brief Instruction length decoder API example * * An example for using the instruction length decoder API. This example loads only the xed-ild library. */ // Source code for xed-dec-ild.c would be included here. ``` -------------------------------- ### GET /xed/operand/get_map Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the map operand from a decoded instruction. ```APIDOC ## GET /xed3_operand_get_map ### Description Accesses the map operand field from the decoded instruction structure. ### Method GET ### Parameters #### Request Body - **d** (xed_decoded_inst_t*) - Required - Pointer to the decoded instruction. ### Response #### Success Response (200) - **map** (xed_bits_t) - The map value associated with the instruction. ``` -------------------------------- ### Environment Configuration and File Handling Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env.env_t-class.html Functions for initializing the build environment, handling configuration files, and manipulating file extensions. ```APIDOC ## make_derived_flags(self) ### Description Assembles any derived flags. This must be called by builder functions before they perform their expansion. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) [Response details not specified] #### Response Example ```json { "example": "response_body" } ``` ## make_obj(self, flist) ### Description Takes a file or list of files and returns a file or list of files with the OBJEXT extension from the environment. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "flist": "source.c" } ``` ### Response #### Success Response (200) - **string**: Filename with a suffix specified by %(OBJEXT)s. #### Response Example ```json { "example": "source.obj" } ``` ## parse_args(self, user_default_options=None) ### Description Initializes the environment from command-line arguments. This calls update() with the results of command-line processing. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "user_default_options": { "option1": "value1" } } ``` ### Response #### Success Response (200) [Response details not specified] #### Response Example ```json { "example": "response_body" } ``` ## rc_file(self, rc_file, res_file=None) ### Description Indirection function for creating RES files from RC files on Windows. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "rc_file": "input.rc", "res_file": "output.res" } ``` ### Response #### Success Response (200) [Response details not specified] #### Response Example ```json { "example": "response_body" } ``` ## remove_from_var(self, var, value) ### Description Removes a substring or list entry from a specified environment variable. This is the opposite of add_to_var(). ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "var": "PATH", "value": "/usr/local/bin" } ``` ### Response #### Success Response (200) [Response details not specified] #### Response Example ```json { "example": "response_body" } ``` ## resuffix(self, fn, newext) ### Description Replaces the suffix of a filename or list of filenames with a new extension. The new extension should include the dot if desired. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "fn": "document.txt", "newext": ".md" } ``` ### Response #### Success Response (200) - **string**: The filename with the new suffix. #### Response Example ```json { "example": "document.md" } ``` ## set_compiler_env(self, compiler_family=None) ### Description Initializes the build environment based on the compiler environment variable setting. Adds in the "extra" flags from the environment. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "compiler_family": "gnu" } ``` ### Response #### Success Response (200) [Response details not specified] #### Response Example ```json { "example": "response_body" } ``` ## set_defaults(self, dct) ### Description Applies a dictionary of defaults to the environment. Any extra bindings and targets should be listed in the 'args' list option of the dictionary. ### Method [Method not specified, likely internal] ### Endpoint [Endpoint not specified] ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "dct": { "option1": "value1", "args": ["target1", "target2"] } } ``` ### Response #### Success Response (200) [Response details not specified] #### Response Example ```json { "example": "response_body" } ``` ``` -------------------------------- ### Verbose Startup Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env.env_t-class.html Controls verbose startup behavior. ```APIDOC ## verbose_startup ### Description Controls verbose startup behavior. ### Method verbose_startup ``` -------------------------------- ### GET /xed/util/itoa_bin Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Converts an integer value into its binary string representation. ```APIDOC ## GET /xed/itoa_bin ### Description Converts the input value f into its binary representation as a string and stores it in the provided buffer. ### Method GET ### Parameters #### Query Parameters - **f** (xed_uint64_t) - Required - The integer value to convert. - **bits_to_print** (xed_uint_t) - Required - Number of bits to represent. - **buflen** (xed_uint_t) - Required - Size of the destination buffer. ### Response #### Success Response (200) - **result** (int) - Returns 0 on success. - **buf** (char*) - The resulting binary string. ``` -------------------------------- ### Address Generation Example (xed-dec-agen.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html Creates an artificial AGEN (address generation) calculator for testing purposes. This example serves as a valuable demonstration of how to use the xed_agen API for address calculation logic. ```c /* * @brief Artificial AGEN calculator example * * Creates an artificial AGEN (address generation) calculator for testing and works as a valuable example for using xed_agen API. */ // Source code for xed-dec-agen.c would be included here. ``` -------------------------------- ### Main Intel® XED Example (xed.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html The primary example demonstrating most of Intel® XED's capabilities, including decoding, encoding, image file reading, and chip-check APIs. It serves as a comprehensive introduction to the library's features. ```c /* * @brief Main Intel® XED example * * This is the main Intel® XED example. It's a complete example touching down on most of Intel® XED's capabilities and APIs, including decoding, encoding, image file reading and chip-check APIs and functionality. */ // Source code for xed.c would be included here. ``` -------------------------------- ### GET /xed/operand/immediate Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the unsigned immediate value from a decoded instruction instance. ```APIDOC ## GET /xed/decoded_inst_get_unsigned_immediate ### Description Retrieves the unsigned immediate value from a previously decoded x86 instruction. ### Method GET ### Parameters #### Request Body - **p** (xed_decoded_inst_t*) - Required - Pointer to the decoded instruction structure. ### Response #### Success Response (200) - **value** (xed_uint64_t) - The unsigned immediate value extracted from the instruction. ### Response Example { "value": 42 } ``` -------------------------------- ### Get Instruction Attribute (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves a specific attribute of a decoded instruction. This function is exported by the XED library. ```c XED_DLL_EXPORT xed_uint32_t xed_inst_get_attribute(const xed_inst_t *p, xed_attribute_enum_t attr) { // Implementation details omitted for brevity } ``` -------------------------------- ### Decoder Example (xed-dec.c) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__EXAMPLES.html A detailed decoder example showcasing most decode APIs. It's recommended for understanding instruction decoding and metadata extraction, including prefixes, CPUID leaves, and operand details. Supports EVEX/VEX bit info and CPUID-based defeaturing. ```c /* * @brief Quintessential decoder example * * A quintessential decoder example that uses most of the decode APIs. It is recommended for users who want to deeply understand the numerous APIs for decoded instructions and their usages. This example supports emitting detailed instruction metadata: prefixes, CPUID leaves, rounding modes, branch-hints, flags, operands and more. This example can also elaborate on EVEX/VEX prefix bit info using a specified verbosity mode. It supports CPUID-based defeaturing as well. */ // Source code for xed-dec.c would be included here. ``` -------------------------------- ### Building Intel XED on Windows with GCC (Cygwin) Source: https://github.com/intelxed/intelxed.github.io/blob/master/build-manual/index.html This demonstrates how to build Intel XED on Windows using GCC within a Cygwin environment. It involves running the mfile.py script with the --compiler=gnu option. Note that Cygwin builds may use Cygwin's Python, which can lead to single-threaded builds due to known issues. ```bash # From a cygwin window using GCC ../xed/mfile.py --compiler=gnu examples ``` -------------------------------- ### Get Effective Address Width (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the effective address width from operand values. This function is exported by the XED library. ```c XED_DLL_EXPORT xed_uint32_t xed_operand_values_get_effective_address_width(const xed_operand_values_t *p) { // Implementation details omitted for brevity } ``` -------------------------------- ### Get Instruction Map (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the instruction map from a decoded instruction. This function is part of the operand accessor utilities in XED. ```c static XED_INLINE xed_bits_t xed3_operand_get_map(const xed_decoded_inst_t *d) { // Implementation details omitted for brevity } ``` -------------------------------- ### Building Intel XED on Windows with MSVS Source: https://github.com/intelxed/intelxed.github.io/blob/master/build-manual/index.html Instructions for building Intel XED on Windows using MSVS. This involves configuring the environment by running appropriate BAT files (e.g., vcvars32.bat, vcvarsamd64.bat) and then executing the build script from a command prompt or cygwin window. Specific MSVS versions can be selected using the --msvs-version option. ```bash # Using win32 python from cmd.exe C:/Python3/python ../xed/mfile.py examples # Using MSVS with a specific version from cmd.exe C:/Python3/python ../xed/mfile.py --setup-msvs --msvs-version 10 examples # From a cygwin window using MSVS (ensure MSVS environment is set up) ../xed/mfile.py examples ``` -------------------------------- ### xed-enc Example: MOV with Memory and Immediate Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__CMDLINE.html This example shows how to use 'xed-enc' to encode a 'MOV' instruction that moves an immediate value into memory. It details the encode request, including memory and immediate operand specifications, and the resulting machine code. ```bash % obj/xed-enc MOV MEM4:EAX IMM:11223344 Encode request: MOV EASZ:2, IMM0:0x11223344, IMM_WIDTH:32, MEM0:dword ptr [EAX], MEM_WIDTH:4, MODE:1, SMODE:1 OPERAND ORDER: MEM0 IMM0 Encodable! C70044332211 ``` -------------------------------- ### Get REXX4 Operand (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the REXX4 operand from a decoded instruction. This function is part of the operand accessor utilities in XED. ```c static XED_INLINE xed_bits_t xed3_operand_get_rexx4(const xed_decoded_inst_t *d) { // Implementation details omitted for brevity } ``` -------------------------------- ### Get Unsigned Immediate Value (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the unsigned immediate value from a decoded instruction. This function is exported by the XED library. ```c XED_DLL_EXPORT xed_uint64_t xed_decoded_inst_get_unsigned_immediate(const xed_decoded_inst_t *p) { // Implementation details omitted for brevity } ``` -------------------------------- ### Initialize Environment and Command Line Parser Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env-pysrc.html Initializes the environment defaults and sets up the OptionParser with common and default build knobs. This ensures that the environment is pre-configured with standard build parameters. ```python self.env_defaults = mbuild_env_defaults self.update_dict(mbuild_env_defaults) self.parser = optparse.OptionParser() self.parser.set_defaults(**mbuild_env_defaults) if default_knobs: self.add_common_knobs() self.add_default_knobs() ``` -------------------------------- ### Get VEXDEST4 Operand (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the VEXDEST4 operand from a decoded instruction. This function is part of the operand accessor utilities in XED. ```c static XED_INLINE xed_bits_t xed3_operand_get_vexdest4(const xed_decoded_inst_t *d) { // Implementation details omitted for brevity } ``` -------------------------------- ### Build Configuration and Linking Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env.env_t-class.html Methods for configuring the build environment, including setting compiler defaults, creating object files, and handling static/shared library linking. ```python def link(self, objs, exename, relocate=False): # Indirection function for linking objects pass def make_obj(self, flist): # Converts a list of files to object files using the environment's OBJEXT pass def set_compiler_env(self, compiler_family=None): # Initializes build environment based on compiler settings pass ``` -------------------------------- ### ENC2 Build Process and Library Generation Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__ENC2.html Describes how ENC2 libraries are built using the '--enc2' switch, resulting in separate directories for different configurations (e.g., m64-a64, m32-a32). It lists the generated static libraries (.a) and header files (.h) for checked and unchecked interfaces. ```text Build switch: --enc2 Configurations: enc2-m64-a64, enc2-m32-a32 Libraries: libxed-chk-enc2-*.a, libxed-enc2-*.a Headers: xed-chk-enc2-*.h, xed-enc2-*.h ``` -------------------------------- ### Get REX2 Operand (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the REX2 operand from a decoded instruction. This function is part of the operand accessor utilities in XED. ```c static XED_INLINE xed_bits_t xed3_operand_get_rex2(const xed_decoded_inst_t *d) { // Implementation details omitted for brevity } ``` -------------------------------- ### Zero Initialize XED State Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Initializes an xed_state_t structure to zero. This is a common setup step before using XED decoding functions. ```c static XED_INLINE void xed_state_zero(xed_state_t *p) ``` -------------------------------- ### Building Intel XED Encoder Libraries Source: https://github.com/intelxed/intelxed.github.io/blob/master/build-manual/index.html This option enables the creation of additional encoder libraries. It requires referencing the Intel XED reference manual for detailed ENC2 information. Building with these options can significantly increase compilation time. The generated libraries and headers are placed in the build directory's wkit/{include,lib} or the installed kit. ```bash # Build additional encoder libraries ./mfile.py --enc2 # Build tests for every encode function ./mfile.py --enc2-test ``` -------------------------------- ### Get Operand Visibility from Operand (C/C++) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the visibility attribute of an operand within an instruction. This is an inline function for accessing operand details. ```c static XED_INLINE xed_operand_visibility_enum_t xed_operand_operand_visibility(const xed_operand_t *p) ``` -------------------------------- ### Mbuild Environment and MSVS Module Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/identifier-index.html Details functions for environment setup and Microsoft Visual Studio integration. ```APIDOC ## Mbuild Environment and MSVS Module ### Description Functions for managing build environments and integrating with MSVS. ### Endpoints #### Functions in `mbuild.env.env_t` - **set_defaults()**: Sets default environment variables. - **supplement_pattern(pattern)**: Supplements a pattern in the environment. #### Functions in `mbuild.msvs` - **set_env(env_vars)**: Sets environment variables for MSVS. - **set_env_list(env_vars_list)**: Sets a list of environment variables for MSVS. - **set_msvs_env()**: Sets MSVS environment variables. ``` -------------------------------- ### Initialize and Encode LEA Instruction (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__ENC2.html Demonstrates initializing an xed_enc2_req_t structure, setting registers, scale, and displacement for a LEA instruction, and then encoding it. It also shows how to retrieve the encoded length. ```c xed_uint_t scale; int32_t disp32; xed_enc2_req_t request; xed_enc2_req_t_init(&request, output_buffer); dest = XED_REG_R11; base = XED_REG_R12; index = XED_REG_R13; scale = 1; disp32 = 0x11223344; xed_enc_lea_rm_q_bisd32_a64_chk(&request, dest, base, index, scale, disp32); return xed_enc2_encoded_length(&request); ``` -------------------------------- ### Get Operand from Operand (C/C++) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the enumeration value representing an operand's width. This function is part of the instruction decoding utilities. ```c static XED_INLINE xed_operand_width_enum_t xed_operand_width(const xed_operand_t *p) ``` -------------------------------- ### Intel XED mfile.py Help Output Source: https://github.com/intelxed/intelxed.github.io/blob/master/build-manual/index.html This displays the usage and available options for the mfile.py build script. It covers options for controlling build concurrency, directories, verbosity, compiler selection, build types (debug, shared, static), optimization levels, and extra compiler/linker flags. ```bash % ./mfile.py --help Usage: mfile.py [options] Options: -h, --help show this help message and exit -j JOBS, --jobs=JOBS Number of concurrent worker threads to use. --mbuild-version Emit the version information --build-dir=BUILD_DIR Build directory, default is 'obj' --src-dir=SRC_DIR The directory where the sources are located. --gen-dir=GEN_DIR The directory where generated sources are assumed to be located. -v VERBOSE, --verbose=VERBOSE Verbosity level. Defaults to value passed to env_t() --compiler=COMPILER Compiler (ms,gnu,clang). Default is gnu on linux and ms on windows. --debug Debug build --shared Shared DLL build --static Statically link executables --opt=OPT Optimization level noopt, 0, 1, 2, 3 -s, --silent Silence all but the most important messages --extra-defines=EXTRA_DEFINES Extra preprocessor defines --extra-flags=EXTRA_FLAGS Extra values for CXXFLAGS and CCFLAGS --extra-cxxflags=EXTRA_CXXFLAGS Extra values for CXXFLAGS --extra-ccflags=EXTRA_CCFLAGS Extra values for CCFLAGS --extra-linkflags=EXTRA_LINKFLAGS Extra values for LINKFLAGS --extra-libs=EXTRA_LIBS Extra values for LIBS --toolchain=TOOLCHAIN Compiler toolchain --vc-dir=VC_DIR MSVS Compiler VC directory. For finding libraries and setting the toolchain --msvs-version=MSVS_VERSION, --msvc-version=MSVS_VERSION, --msvsversion=MSVS_VERSION, --msvcversion=MSVS_VERSION MSVS version 6=VC98, 7=VS .Net 2003, 8=VS 2005, 9=VS2008, 10=VS 2010/DEV10, 11=VS2012/DEV11, 12=VS2013, 14=VS2015, 15=VS2017, 16=VS2019, 17=VS2022. This sets certain flags and idioms for quirks in some compilers. --setup-msvc, --setup-msvs, --msvs-setup, --msvc-setup Use the value of the --msvc-version to initialize the MSVC configuration. --gcc-version=GCC_VERSION, --gccversion=GCC_VERSION, --gcc-ver=GCC_VERSION GCC version, with dots as in 2.96, 3.4.3, 4.2.0, etc. --cc=CC full path to C compiler ``` -------------------------------- ### Get Operand Name from Operand (C/C++) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the enumeration value representing the name of an operand. This function is part of the instruction decoding utilities. ```c static XED_INLINE xed_operand_enum_t xed_operand_name(const xed_operand_t *p) ``` -------------------------------- ### Get Maximum XED Attribute Value Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Returns the maximum value for an attribute in the XED instruction set. This can be used for validation or range checking. ```c XED_DLL_EXPORT unsigned int xed_attribute_max(void) ``` -------------------------------- ### POST /static_lib Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env-pysrc.html Creates a static library from a collection of object files. ```APIDOC ## POST /static_lib ### Description Creates a static library from object files using the STATIC_LIBRARY_BUILDER. ### Method POST ### Endpoint /static_lib ### Parameters #### Request Body - **objs** (list of strings) - Required - Filenames to include - **libname** (string) - Required - Output library name - **relocate** (bool) - Optional - If true, relocate to build directory ### Response #### Success Response (200) - **plan_t** (object) - An input for the DAG ``` -------------------------------- ### Get XED Instruction Pointer Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves a pointer to the XED instruction structure from a decoded instruction. This allows access to more detailed instruction information. ```c static const XED_INLINE xed_inst_t * xed_decoded_inst_inst(const xed_decoded_inst_t *p) ``` -------------------------------- ### Command Definition and Initialization Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.work_queue-pysrc.html Defines a command to be executed, setting up its properties such as the command itself, arguments, environment variables, and I/O redirection. ```APIDOC ## POST /commands ### Description Initializes a new command object with specified parameters. This includes the command to run, optional arguments, environment variables, input/output file names, and execution control flags. ### Method POST ### Endpoint /commands ### Parameters #### Request Body - **command** (string or list) - Required - The command to execute. Can be a string or a list of strings/functions. - **name** (string) - Optional - A name for the command. - **shell_executable** (string) - Optional - The shell executable to use. - **args** (list) - Optional - Arguments for the command. - **xenv** (dict) - Optional - Environment variables for the command. - **osenv** (dict) - Optional - Operating system environment variables. - **directory** (string) - Optional - The working directory for the command. - **unbufferred** (bool) - Optional - If true, the output will be unbuffered. - **output_file_name** (string) - Optional - File name for stderr/stdout. - **show_output** (bool) - Optional - Whether to show the output. Defaults to True. - **input_file_name** (string) - Optional - File name for stdin. - **seconds** (integer) - Optional - Timeout in seconds for the command. ### Request Example ```json { "command": "echo 'Hello, World!'", "name": "hello_world", "output_file_name": "output.log", "show_output": true } ``` ### Response #### Success Response (200) - **command_id** (string) - The unique identifier for the created command. #### Response Example ```json { "command_id": "cmd_12345" } ``` ``` -------------------------------- ### Get Segment Register (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the segment register associated with a memory operand in a decoded instruction. This function is exported by the XED library. ```c XED_DLL_EXPORT xed_reg_enum_t xed_decoded_inst_get_seg_reg(const xed_decoded_inst_t *p, unsigned int mem_idx) { // Implementation details omitted for brevity } ``` -------------------------------- ### Get Register Class (C) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Returns the register class of a given register. This function is exported and takes an xed_reg_enum_t as input, returning an xed_reg_class_enum_t. ```c XED_DLL_EXPORT xed_reg_class_enum_t xed_reg_class(xed_reg_enum_t r) ``` -------------------------------- ### Compile and Create Static Library Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env.env_t-class.html Builds all provided source files, compiles them, and then links them into a static library. It adds these steps to a DAG. The DAG can be passed to a work queue. ```python def compile_and_static_lib(self, dag, sources, libname): """Build all the sources by adding them to the dag. Use the suffixes to figure out how to handle the files.""" pass ``` -------------------------------- ### mbuild Environment Variable Substitution Example (Python) Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild-pysrc.html Demonstrates dynamic substitution of environment variables in mbuild, including recursive expansion and dictionary-based lookups. This allows for flexible build configurations based on command-line arguments or script settings. ```python #BEGIN_LEGAL # #Copyright (c) 2016 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #END_LEGAL # __init__.py # Mark Charney """This is mbuild: a simple portable dependence-based build-system written in python. mbuild is a python-based build system very similar to scons with some philosophical features of make. mbuild exposes the scan and build phases allowing them to be repeated as necessary. Multiple DAGs can be built, one during each scan phase. Conceptually there are 3 major components to mbuild: - The environment L{env_t} - The directed acyclic graph L{dag_t} - The work queue L{work_queue_t} Using the environment L{env_t} you customize your build configuration and construct names for your source files, object files, executables, etc. The environment contains builder methods that create L{plan_t} objects. There are builders for C, C++, static and dynamic libraries, assembly files and linking programs. The environment and builders support string substitution. The L{plan_t} objects are passed to the L{dag_t} which stores the dependences that order execution. The L{plan_t} objects describe work that needs to be done. Plans typically contain a command line strings (with all substitutions done), but can also be python functions that will be executed during the build. Using the L{plan_t} objects, the L{dag_t} creates L{command_t} objects that are passed to the L{work_queue_t} to ultimately build the target or targets. Your build file can have multiple environments, DAGS and work queues. Using the environment dictionary ================================ You can bind or augmenting environment variables from the command line. For example, one can say C{build_cpu=ia32} on an x86-64 system to change the default compilation behavior. Similarly, one can say C{CXXFLAGS+=-g} to add the C{-g} flag to the existing C{CXXFLAGS} variable. Dynamic substitution is also used. Patterns of the form %(I{string})s will substitute I{string} dynamically before it is used. The expansion can happen directly from the environment and is recursive. The expansion can also use dictionaries that are variables in the environment. A dictionary in the environment is really a tuple of the key-variable and the dictionary itself. For example:: env['opt_flag'] = ( 'opt', {'noopt':'', '0':'%(OPTOPT)s0', '1':'%(OPTOPT)s1', '2':'%(OPTOPT)s2', '3':'%(OPTOPT)s3', '4':'%(OPTOPT)s4'} ) env['OPTOPT'] = ( 'compiler', { 'gnu':'-O', 'ms':'/O'}) env['CXXFLAGS'] += ' %(opt_flag)s' The C{OPTOPT} variable depends on C{env['compiler']}. If C{env['compiler']='gnu'} then C{env['OPTOPT']} expands to C{-O}. If C{env['compiler']='ms'} then C{env['OPTOPT']} expands to C{/O}. If the C{opt} variable is set "C{opt=3}" on the command line, or equivalently if C{env['opt']='3'} is set in the script, then if the C{env['compiler']='gnu'} in the environment at the time of expansion, then the flag in the C{CXXFLAGS} will be C{-O3}. If C{env['compiler']='ms'} at the time of expansion, then the optimization flag would be C{/O3}. If C{opt=noopt} (on the command line) then there will be no optimization flag in the C{CXXFLAGS}. Introspection ============= The L{command_t} that are executed during the build have their output (stdout/stderr) stored in the L{dag_t}. After a build it is possible to collect the commands using the L{dag_t.results} function and analyze the output. This is very handy for test and validation suites. """ ``` -------------------------------- ### Get Chip Features using XED Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Fills an xed_chip_features_t structure with the features of a specified CPU chip. This function is used to query hardware capabilities. ```c XED_DLL_EXPORT void xed_get_chip_features(xed_chip_features_t *p, xed_chip_enum_t chip) ``` -------------------------------- ### Get Vector Length in Bits for XED Instruction Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Returns the vector length in bits for a decoded XED instruction. This is important for SIMD and vector processing. ```c XED_DLL_EXPORT xed_uint_t xed_decoded_inst_vector_length_bits(xed_decoded_inst_t const *const p) ``` -------------------------------- ### Prepare Command for Execution Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.util-pysrc.html Tokenizes command strings for POSIX systems or returns the raw string for Windows to prevent path character issues. ```python def _prepare_cmd(cmd): if on_native_windows(): return cmd else: return shlex.split(cmd) ``` -------------------------------- ### Get Zeroing Behavior for XED Operand Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the zeroing behavior for a specific operand in a decoded XED instruction. This is relevant for certain vector instructions. ```c static XED_INLINE xed_bits_t xed3_operand_get_zeroing(const xed_decoded_inst_t *d) ``` -------------------------------- ### Get Scale for XED Memory Operand Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the scale factor for a memory operand within a decoded XED instruction. This is crucial for address calculation. ```c XED_DLL_EXPORT xed_uint_t xed_decoded_inst_get_scale(const xed_decoded_inst_t *p, unsigned int mem_idx) ``` -------------------------------- ### POST /link Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/mbuild.env-pysrc.html Links multiple object files into an executable binary. ```APIDOC ## POST /link ### Description Links an executable from a list of object files. Uses the LINK_BUILDER environment variable. ### Method POST ### Endpoint /link ### Parameters #### Request Body - **objs** (list of strings) - Required - Filenames to link - **exename** (string) - Required - Output filename - **relocate** (bool) - Optional - If true, prefix exename with build directory ### Response #### Success Response (200) - **plan_t** (object) - An input for the DAG ``` -------------------------------- ### Initialize Search and Navigation UI Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/globals.html Initializes the search box, navigation tree, and UI components for the Doxygen-generated documentation site. This script relies on jQuery to ensure the DOM is ready before executing initialization functions. ```javascript var searchBox = new SearchBox("searchBox", "search",false,'Search'); $(function() { initMenu('',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); $(document).ready(function(){ initNavTree('globals.html',''); initResizable(); }); ``` -------------------------------- ### Get Number of Operands from Instruction (C/C++) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Returns the total number of operands for a given XED instruction. This is an inline function for efficient retrieval of instruction metadata. ```c static XED_INLINE unsigned int xed_inst_noperands(const xed_inst_t *p) ``` -------------------------------- ### Get Second Immediate from Decoded Instruction (C/C++) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Retrieves the value of the second immediate operand from a decoded XED instruction. This is an inline function for quick access. ```c static XED_INLINE xed_uint8_t xed_decoded_inst_get_second_immediate(const xed_decoded_inst_t *p) ``` -------------------------------- ### Get No APX from Decoded Instruction (C/C++) Source: https://github.com/intelxed/intelxed.github.io/blob/master/ref-manual/group__SMALLEXAMPLES.html Extracts the 'no APX' information from a decoded XED instruction. This is an inline function for efficient access to instruction properties. ```c static XED_INLINE xed_bits_t xed3_operand_get_no_apx(const xed_decoded_inst_t *d) ``` -------------------------------- ### Environment Management (mbuild.env) Source: https://github.com/intelxed/intelxed.github.io/blob/master/mbuild/identifier-index.html Classes and methods for managing build environments, including CPU detection and linking. ```APIDOC ## GET /mbuild/env/number_of_cpus ### Description Retrieves the number of available CPUs in the current environment. ### Method GET ### Endpoint mbuild.env.env_t.number_of_cpus() ### Response #### Success Response (200) - **count** (integer) - The number of detected CPUs. ## POST /mbuild/env/link ### Description Performs a linking operation within the build environment. ### Method POST ### Endpoint mbuild.env.env_t.link(target, source) ### Request Body - **target** (string) - Required - The destination path. - **source** (string) - Required - The source file or object. ```