1/*===-- llvm-c/DisassemblerTypedefs.h -----------------------------*- C -*-===*\ 2|* *| 3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 4|* Exceptions. *| 5|* See https://llvm.org/LICENSE.txt for license information. *| 6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 7|* *| 8|*===----------------------------------------------------------------------===*/ 9 10#ifndef LLVM_C_DISASSEMBLERTYPES_H 11#define LLVM_C_DISASSEMBLERTYPES_H 12 13#include "llvm-c/DataTypes.h" 14#ifdef __cplusplus 15#include <cstddef> 16#else 17#include <stddef.h> 18#endif 19 20/** 21 * @addtogroup LLVMCDisassembler 22 * 23 * @{ 24 */ 25 26/** 27 * An opaque reference to a disassembler context. 28 */ 29typedef void *LLVMDisasmContextRef; 30 31/** 32 * The type for the operand information call back function. This is called to 33 * get the symbolic information for an operand of an instruction. Typically 34 * this is from the relocation information, symbol table, etc. That block of 35 * information is saved when the disassembler context is created and passed to 36 * the call back in the DisInfo parameter. The instruction containing operand 37 * is at the PC parameter. For some instruction sets, there can be more than 38 * one operand with symbolic information. To determine the symbolic operand 39 * information for each operand, the bytes for the specific operand in the 40 * instruction are specified by the Offset parameter and its byte widith is the 41 * OpSize parameter. For instructions sets with fixed widths and one symbolic 42 * operand per instruction, the Offset parameter will be zero and InstSize 43 * parameter will be the instruction width. The information is returned in 44 * TagBuf and is Triple specific with its specific information defined by the 45 * value of TagType for that Triple. If symbolic information is returned the 46 * function * returns 1, otherwise it returns 0. 47 */ 48typedef int (*LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, 49 uint64_t OpSize, uint64_t InstSize, 50 int TagType, void *TagBuf); 51 52/** 53 * The initial support in LLVM MC for the most general form of a relocatable 54 * expression is "AddSymbol - SubtractSymbol + Offset". For some Darwin targets 55 * this full form is encoded in the relocation information so that AddSymbol and 56 * SubtractSymbol can be link edited independent of each other. Many other 57 * platforms only allow a relocatable expression of the form AddSymbol + Offset 58 * to be encoded. 59 * 60 * The LLVMOpInfoCallback() for the TagType value of 1 uses the struct 61 * LLVMOpInfo1. The value of the relocatable expression for the operand, 62 * including any PC adjustment, is passed in to the call back in the Value 63 * field. The symbolic information about the operand is returned using all 64 * the fields of the structure with the Offset of the relocatable expression 65 * returned in the Value field. It is possible that some symbols in the 66 * relocatable expression were assembly temporary symbols, for example 67 * "Ldata - LpicBase + constant", and only the Values of the symbols without 68 * symbol names are present in the relocation information. The VariantKind 69 * type is one of the Target specific #defines below and is used to print 70 * operands like "_foo@GOT", ":lower16:_foo", etc. 71 */ 72struct LLVMOpInfoSymbol1 { 73 uint64_t Present; /* 1 if this symbol is present */ 74 const char *Name; /* symbol name if not NULL */ 75 uint64_t Value; /* symbol value if name is NULL */ 76}; 77 78struct LLVMOpInfo1 { 79 struct LLVMOpInfoSymbol1 AddSymbol; 80 struct LLVMOpInfoSymbol1 SubtractSymbol; 81 uint64_t Value; 82 uint64_t VariantKind; 83}; 84 85/** 86 * The operand VariantKinds for symbolic disassembly. 87 */ 88#define LLVMDisassembler_VariantKind_None 0 /* all targets */ 89 90/** 91 * The ARM target VariantKinds. 92 */ 93#define LLVMDisassembler_VariantKind_ARM_HI16 1 /* :upper16: */ 94#define LLVMDisassembler_VariantKind_ARM_LO16 2 /* :lower16: */ 95 96/** 97 * The ARM64 target VariantKinds. 98 */ 99#define LLVMDisassembler_VariantKind_ARM64_PAGE 1 /* @page */ 100#define LLVMDisassembler_VariantKind_ARM64_PAGEOFF 2 /* @pageoff */ 101#define LLVMDisassembler_VariantKind_ARM64_GOTPAGE 3 /* @gotpage */ 102#define LLVMDisassembler_VariantKind_ARM64_GOTPAGEOFF 4 /* @gotpageoff */ 103#define LLVMDisassembler_VariantKind_ARM64_TLVP 5 /* @tvlppage */ 104#define LLVMDisassembler_VariantKind_ARM64_TLVOFF 6 /* @tvlppageoff */ 105 106/** 107 * The type for the symbol lookup function. This may be called by the 108 * disassembler for things like adding a comment for a PC plus a constant 109 * offset load instruction to use a symbol name instead of a load address value. 110 * It is passed the block information is saved when the disassembler context is 111 * created and the ReferenceValue to look up as a symbol. If no symbol is found 112 * for the ReferenceValue NULL is returned. The ReferenceType of the 113 * instruction is passed indirectly as is the PC of the instruction in 114 * ReferencePC. If the output reference can be determined its type is returned 115 * indirectly in ReferenceType along with ReferenceName if any, or that is set 116 * to NULL. 117 */ 118typedef const char *(*LLVMSymbolLookupCallback)(void *DisInfo, 119 uint64_t ReferenceValue, 120 uint64_t *ReferenceType, 121 uint64_t ReferencePC, 122 const char **ReferenceName); 123/** 124 * The reference types on input and output. 125 */ 126/* No input reference type or no output reference type. */ 127#define LLVMDisassembler_ReferenceType_InOut_None 0 128 129/* The input reference is from a branch instruction. */ 130#define LLVMDisassembler_ReferenceType_In_Branch 1 131/* The input reference is from a PC relative load instruction. */ 132#define LLVMDisassembler_ReferenceType_In_PCrel_Load 2 133 134/* The input reference is from an ARM64::ADRP instruction. */ 135#define LLVMDisassembler_ReferenceType_In_ARM64_ADRP 0x100000001 136/* The input reference is from an ARM64::ADDXri instruction. */ 137#define LLVMDisassembler_ReferenceType_In_ARM64_ADDXri 0x100000002 138/* The input reference is from an ARM64::LDRXui instruction. */ 139#define LLVMDisassembler_ReferenceType_In_ARM64_LDRXui 0x100000003 140/* The input reference is from an ARM64::LDRXl instruction. */ 141#define LLVMDisassembler_ReferenceType_In_ARM64_LDRXl 0x100000004 142/* The input reference is from an ARM64::ADR instruction. */ 143#define LLVMDisassembler_ReferenceType_In_ARM64_ADR 0x100000005 144 145/* The output reference is to as symbol stub. */ 146#define LLVMDisassembler_ReferenceType_Out_SymbolStub 1 147/* The output reference is to a symbol address in a literal pool. */ 148#define LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr 2 149/* The output reference is to a cstring address in a literal pool. */ 150#define LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr 3 151 152/* The output reference is to a Objective-C CoreFoundation string. */ 153#define LLVMDisassembler_ReferenceType_Out_Objc_CFString_Ref 4 154/* The output reference is to a Objective-C message. */ 155#define LLVMDisassembler_ReferenceType_Out_Objc_Message 5 156/* The output reference is to a Objective-C message ref. */ 157#define LLVMDisassembler_ReferenceType_Out_Objc_Message_Ref 6 158/* The output reference is to a Objective-C selector ref. */ 159#define LLVMDisassembler_ReferenceType_Out_Objc_Selector_Ref 7 160/* The output reference is to a Objective-C class ref. */ 161#define LLVMDisassembler_ReferenceType_Out_Objc_Class_Ref 8 162 163/* The output reference is to a C++ symbol name. */ 164#define LLVMDisassembler_ReferenceType_DeMangled_Name 9 165 166/** 167 * @} 168 */ 169 170#endif 171