Path: blob/master/dep/zydis/include/Zydis/Register.h
6242 views
/***************************************************************************************************12Zyan Disassembler Library (Zydis)34Original Author : Florian Bernd56* Permission is hereby granted, free of charge, to any person obtaining a copy7* of this software and associated documentation files (the "Software"), to deal8* in the Software without restriction, including without limitation the rights9* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10* copies of the Software, and to permit persons to whom the Software is11* furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included in all14* copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22* SOFTWARE.2324***************************************************************************************************/2526/**27* @file28* Utility functions and constants for registers.29*/3031#ifndef ZYDIS_REGISTER_H32#define ZYDIS_REGISTER_H3334#include <Zycore/Defines.h>35#include <Zycore/Types.h>36#include <Zydis/Defines.h>37#include <Zydis/SharedTypes.h>38#include <Zydis/ShortString.h>3940#ifdef __cplusplus41extern "C" {42#endif4344/* ============================================================================================== */45/* Enums and types */46/* ============================================================================================== */4748/* ---------------------------------------------------------------------------------------------- */49/* Registers */50/* ---------------------------------------------------------------------------------------------- */5152#include <Zydis/Generated/EnumRegister.h>5354/* ---------------------------------------------------------------------------------------------- */55/* Register kinds */56/* ---------------------------------------------------------------------------------------------- */5758/**59* Defines the `ZydisRegisterKind` enum.60*61* Please note that this enum does not contain a matching entry for all values of the62* `ZydisRegister` enum, but only for those registers where it makes sense to logically group them63* for decoding/encoding purposes.64*65* These are mainly the registers that can be identified by an id within their corresponding66* register-class.67*/68typedef enum ZydisRegisterKind_69{70ZYDIS_REGKIND_INVALID,71ZYDIS_REGKIND_GPR,72ZYDIS_REGKIND_X87,73ZYDIS_REGKIND_MMX,74ZYDIS_REGKIND_VR,75ZYDIS_REGKIND_TMM,76ZYDIS_REGKIND_SEGMENT,77ZYDIS_REGKIND_TEST,78ZYDIS_REGKIND_CONTROL,79ZYDIS_REGKIND_DEBUG,80ZYDIS_REGKIND_MASK,81ZYDIS_REGKIND_BOUND,8283/**84* Maximum value of this enum.85*/86ZYDIS_REGKIND_MAX_VALUE = ZYDIS_REGKIND_BOUND,87/**88* The minimum number of bits required to represent all values of this enum.89*/90ZYDIS_REGKIND_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REGKIND_MAX_VALUE)91} ZydisRegisterKind;9293/* ---------------------------------------------------------------------------------------------- */94/* Register classes */95/* ---------------------------------------------------------------------------------------------- */9697/**98* Defines the `ZydisRegisterClass` enum.99*100* Please note that this enum does not contain a matching entry for all values of the101* `ZydisRegister` enum, but only for those registers where it makes sense to logically group them102* for decoding/encoding purposes.103*104* These are mainly the registers that can be identified by an id within their corresponding105* register-class. The `IP` and `FLAGS` values are exceptions to this rule.106*/107typedef enum ZydisRegisterClass_108{109ZYDIS_REGCLASS_INVALID,110/**111* 8-bit general-purpose registers.112*/113ZYDIS_REGCLASS_GPR8,114/**115* 16-bit general-purpose registers.116*/117ZYDIS_REGCLASS_GPR16,118/**119* 32-bit general-purpose registers.120*/121ZYDIS_REGCLASS_GPR32,122/**123* 64-bit general-purpose registers.124*/125ZYDIS_REGCLASS_GPR64,126/**127* Floating point legacy registers.128*/129ZYDIS_REGCLASS_X87,130/**131* Floating point multimedia registers.132*/133ZYDIS_REGCLASS_MMX,134/**135* 128-bit vector registers.136*/137ZYDIS_REGCLASS_XMM,138/**139* 256-bit vector registers.140*/141ZYDIS_REGCLASS_YMM,142/**143* 512-bit vector registers.144*/145ZYDIS_REGCLASS_ZMM,146/**147* Matrix registers.148*/149ZYDIS_REGCLASS_TMM,150/*151* Flags registers.152*/153ZYDIS_REGCLASS_FLAGS,154/**155* Instruction-pointer registers.156*/157ZYDIS_REGCLASS_IP,158/**159* Segment registers.160*/161ZYDIS_REGCLASS_SEGMENT,162/**163* Table registers.164*/165ZYDIS_REGCLASS_TABLE,166/**167* Test registers.168*/169ZYDIS_REGCLASS_TEST,170/**171* Control registers.172*/173ZYDIS_REGCLASS_CONTROL,174/**175* Debug registers.176*/177ZYDIS_REGCLASS_DEBUG,178/**179* Mask registers.180*/181ZYDIS_REGCLASS_MASK,182/**183* Bound registers.184*/185ZYDIS_REGCLASS_BOUND,186187/**188* Maximum value of this enum.189*/190ZYDIS_REGCLASS_MAX_VALUE = ZYDIS_REGCLASS_BOUND,191/**192* The minimum number of bits required to represent all values of this enum.193*/194ZYDIS_REGCLASS_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REGCLASS_MAX_VALUE)195} ZydisRegisterClass;196197/* ---------------------------------------------------------------------------------------------- */198/* Register width */199/* ---------------------------------------------------------------------------------------------- */200201/**202* Defines the `ZydisRegisterWidth` data-type.203*/204typedef ZyanU16 ZydisRegisterWidth;205206/* ---------------------------------------------------------------------------------------------- */207/* Register context */208/* ---------------------------------------------------------------------------------------------- */209210/**211* Defines the `ZydisRegisterContext` struct.212*/213typedef struct ZydisRegisterContext_214{215/**216* The values stored in the register context.217*/218ZyanU64 values[ZYDIS_REGISTER_MAX_VALUE + 1];219} ZydisRegisterContext;220221/* ---------------------------------------------------------------------------------------------- */222223/* ============================================================================================== */224/* Exported functions */225/* ============================================================================================== */226227/**228* @addtogroup register Register229* Functions allowing retrieval of information about registers.230* @{231*/232233/* ---------------------------------------------------------------------------------------------- */234/* Register */235/* ---------------------------------------------------------------------------------------------- */236237/**238* Returns the register specified by the `register_class` and `id` tuple.239*240* @param register_class The register class.241* @param id The register id.242*243* @return The register specified by the `register_class` and `id` tuple or `ZYDIS_REGISTER_NONE`,244* if an invalid parameter was passed.245*/246ZYDIS_EXPORT ZydisRegister ZydisRegisterEncode(ZydisRegisterClass register_class, ZyanU8 id);247248/**249* Returns the id of the specified register.250*251* @param reg The register.252*253* @return The id of the specified register, or -1 if an invalid parameter was passed.254*/255ZYDIS_EXPORT ZyanI8 ZydisRegisterGetId(ZydisRegister reg);256257/**258* Returns the register-class of the specified register.259*260* @param reg The register.261*262* @return The register-class of the specified register.263*/264ZYDIS_EXPORT ZydisRegisterClass ZydisRegisterGetClass(ZydisRegister reg);265266/**267* Returns the width of the specified register.268*269* @param mode The active machine mode.270* @param reg The register.271*272* @return The width of the specified register, or `ZYDIS_REGISTER_NONE` if the register is273* invalid for the active machine-mode.274*/275ZYDIS_EXPORT ZydisRegisterWidth ZydisRegisterGetWidth(ZydisMachineMode mode, ZydisRegister reg);276277/**278* Returns the largest enclosing register of the given register.279*280* @param mode The active machine mode.281* @param reg The register.282*283* @return The largest enclosing register of the given register, or `ZYDIS_REGISTER_NONE` if the284* register is invalid for the active machine-mode or does not have an enclosing-register.285*/286ZYDIS_EXPORT ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode,287ZydisRegister reg);288289/**290* Returns the specified register string.291*292* @param reg The register.293*294* @return The register string or `ZYAN_NULL`, if an invalid register was passed.295*/296ZYDIS_EXPORT const char* ZydisRegisterGetString(ZydisRegister reg);297298/**299* Returns the specified register string as `ZydisShortString`.300*301* @param reg The register.302*303* @return The register string or `ZYAN_NULL`, if an invalid register was passed.304*305* The `buffer` of the returned struct is guaranteed to be zero-terminated in this special case.306*/307ZYDIS_EXPORT const ZydisShortString* ZydisRegisterGetStringWrapped(ZydisRegister reg);308309/* ---------------------------------------------------------------------------------------------- */310/* Register class */311/* ---------------------------------------------------------------------------------------------- */312313/**314* Returns the width of the specified register-class.315*316* @param mode The active machine mode.317* @param register_class The register class.318*319* @return The width of the specified register.320*/321ZYDIS_EXPORT ZydisRegisterWidth ZydisRegisterClassGetWidth(ZydisMachineMode mode,322ZydisRegisterClass register_class);323324/* ---------------------------------------------------------------------------------------------- */325326/**327* @}328*/329330/* ============================================================================================== */331332#ifdef __cplusplus333}334#endif335336#endif /* ZYDIS_REGISTER_H */337338339