Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:14:37

0001 /* Interface for libasm.
0002    Copyright (C) 2002, 2005, 2008 Red Hat, Inc.
0003    This file is part of elfutils.
0004 
0005    This file is free software; you can redistribute it and/or modify
0006    it under the terms of either
0007 
0008      * the GNU Lesser General Public License as published by the Free
0009        Software Foundation; either version 3 of the License, or (at
0010        your option) any later version
0011 
0012    or
0013 
0014      * the GNU General Public License as published by the Free
0015        Software Foundation; either version 2 of the License, or (at
0016        your option) any later version
0017 
0018    or both in parallel, as here.
0019 
0020    elfutils is distributed in the hope that it will be useful, but
0021    WITHOUT ANY WARRANTY; without even the implied warranty of
0022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023    General Public License for more details.
0024 
0025    You should have received copies of the GNU General Public License and
0026    the GNU Lesser General Public License along with this program.  If
0027    not, see <http://www.gnu.org/licenses/>.  */
0028 
0029 #ifndef _LIBASM_H
0030 #define _LIBASM_H 1
0031 
0032 #include <stdbool.h>
0033 #include <stdint.h>
0034 #include <gelf.h>
0035 
0036 typedef struct ebl Ebl;
0037 
0038 
0039 /* Opaque type for the assembler context descriptor.  */
0040 typedef struct AsmCtx AsmCtx_t;
0041 
0042 /* Opaque type for a section.  */
0043 typedef struct AsmScn AsmScn_t;
0044 
0045 /* Opaque type for a section group.  */
0046 typedef struct AsmScnGrp AsmScnGrp_t;
0047 
0048 /* Opaque type for a symbol.  */
0049 typedef struct AsmSym AsmSym_t;
0050 
0051 
0052 /* Opaque type for the disassembler context descriptor.  */
0053 typedef struct DisasmCtx DisasmCtx_t;
0054 
0055 /* Type used for callback functions to retrieve symbol name.  The
0056    symbol reference is in the section designated by the second parameter
0057    at an offset described by the first parameter.  The value is the
0058    third parameter.  */
0059 typedef int (*DisasmGetSymCB_t) (GElf_Addr, Elf32_Word, GElf_Addr, char **,
0060                  size_t *, void *);
0061 
0062 /* Output function callback.  */
0063 typedef int (*DisasmOutputCB_t) (char *, size_t, void *);
0064 
0065 
0066 #ifdef __cplusplus
0067 extern "C" {
0068 #endif
0069 
0070 /* Create output file and return descriptor for assembler context.  If
0071    TEXTP is true the output is an assembler format text file.
0072    Otherwise an object file is created.  The MACHINE parameter
0073    corresponds to an EM_ constant from <elf.h>, KLASS specifies the
0074    class (32- or 64-bit), and DATA specifies the byte order (little or
0075    big endian).  */
0076 extern AsmCtx_t *asm_begin (const char *fname, Ebl *ebl, bool textp);
0077 
0078 /* Abort the operation on the assembler context and free all resources.  */
0079 extern int asm_abort (AsmCtx_t *ctx);
0080 
0081 /* Finalize output file and free all resources.  */
0082 extern int asm_end (AsmCtx_t *ctx);
0083 
0084 
0085 /* Return handle for the named section.  If it was not used before
0086    create it.  */
0087 extern AsmScn_t *asm_newscn (AsmCtx_t *ctx, const char *scnname,
0088                  GElf_Word type, GElf_Xword flags);
0089 
0090 
0091 /* Similar to 'asm_newscn', but make it part of section group GRP.  */
0092 extern AsmScn_t *asm_newscn_ingrp (AsmCtx_t *ctx, const char *scnname,
0093                    GElf_Word type, GElf_Xword flags,
0094                    AsmScnGrp_t *grp);
0095 
0096 /* Create new subsection NR in the given section.  */
0097 extern AsmScn_t *asm_newsubscn (AsmScn_t *asmscn, unsigned int nr);
0098 
0099 
0100 /* Return handle for new section group.  The signature symbol can be
0101    set later.  */
0102 extern AsmScnGrp_t *asm_newscngrp (AsmCtx_t *ctx, const char *grpname,
0103                    AsmSym_t *signature, Elf32_Word flags);
0104 
0105 /* Set or overwrite signature symbol for group.  */
0106 extern int asm_scngrp_newsignature (AsmScnGrp_t *grp, AsmSym_t *signature);
0107 
0108 
0109 /* Add zero terminated string STR of size LEN to (sub)section ASMSCN.  */
0110 extern int asm_addstrz (AsmScn_t *asmscn, const char *str, size_t len);
0111 
0112 /* Add 8-bit signed integer NUM to (sub)section ASMSCN.  */
0113 extern int asm_addint8 (AsmScn_t *asmscn, int8_t num);
0114 
0115 /* Add 8-bit unsigned integer NUM to (sub)section ASMSCN.  */
0116 extern int asm_adduint8 (AsmScn_t *asmscn, uint8_t num);
0117 
0118 /* Add 16-bit signed integer NUM to (sub)section ASMSCN.  */
0119 extern int asm_addint16 (AsmScn_t *asmscn, int16_t num);
0120 
0121 /* Add 16-bit unsigned integer NUM to (sub)section ASMSCN.  */
0122 extern int asm_adduint16 (AsmScn_t *asmscn, uint16_t num);
0123 
0124 /* Add 32-bit signed integer NUM to (sub)section ASMSCN.  */
0125 extern int asm_addint32 (AsmScn_t *asmscn, int32_t num);
0126 
0127 /* Add 32-bit unsigned integer NUM to (sub)section ASMSCN.  */
0128 extern int asm_adduint32 (AsmScn_t *asmscn, uint32_t num);
0129 
0130 /* Add 64-bit signed integer NUM to (sub)section ASMSCN.  */
0131 extern int asm_addint64 (AsmScn_t *asmscn, int64_t num);
0132 
0133 /* Add 64-bit unsigned integer NUM to (sub)section ASMSCN.  */
0134 extern int asm_adduint64 (AsmScn_t *asmscn, uint64_t num);
0135 
0136 
0137 /* Add signed little endian base 128 integer NUM to (sub)section ASMSCN.  */
0138 extern int asm_addsleb128 (AsmScn_t *asmscn, int32_t num);
0139 
0140 /* Add unsigned little endian base 128 integer NUM to (sub)section ASMSCN.  */
0141 extern int asm_adduleb128 (AsmScn_t *asmscn, uint32_t num);
0142 
0143 
0144 /* Define new symbol NAME for current position in given section ASMSCN.  */
0145 extern AsmSym_t *asm_newsym (AsmScn_t *asmscn, const char *name,
0146                  GElf_Xword size, int type, int binding);
0147 
0148 
0149 /* Define new common symbol NAME with given SIZE and alignment.  */
0150 extern AsmSym_t *asm_newcomsym (AsmCtx_t *ctx, const char *name,
0151                 GElf_Xword size, GElf_Addr align);
0152 
0153 /* Define new common symbol NAME with given SIZE, VALUE, TYPE, and BINDING.  */
0154 extern AsmSym_t *asm_newabssym (AsmCtx_t *ctx, const char *name,
0155                 GElf_Xword size, GElf_Addr value,
0156                 int type, int binding);
0157 
0158 
0159 /* Align (sub)section offset according to VALUE.  */
0160 extern int asm_align (AsmScn_t *asmscn, GElf_Word value);
0161 
0162 /* Set the byte pattern used to fill gaps created by alignment.  */
0163 extern int asm_fill (AsmScn_t *asmscn, void *bytes, size_t len);
0164 
0165 
0166 /* Return ELF descriptor created for the output file of the given context.  */
0167 extern Elf *asm_getelf (AsmCtx_t *ctx);
0168 
0169 
0170 /* Return error code of last failing function call.  This value is kept
0171    separately for each thread.  */
0172 extern int asm_errno (void);
0173 
0174 /* Return error string for ERROR.  If ERROR is zero, return error string
0175    for most recent error or NULL is none occurred.  If ERROR is -1 the
0176    behaviour is similar to the last case except that not NULL but a legal
0177    string is returned.  */
0178 extern const char *asm_errmsg (int __error);
0179 
0180 
0181 /* Create context descriptor for disassembler.  */
0182 extern DisasmCtx_t *disasm_begin (Ebl *ebl, Elf *elf, DisasmGetSymCB_t symcb);
0183 
0184 /* Release descriptor for disassembler.  */
0185 extern int disasm_end (DisasmCtx_t *ctx);
0186 
0187 /* Produce of disassembly output for given memory, store text in
0188    provided buffer.  */
0189 extern int disasm_str (DisasmCtx_t *ctx, const uint8_t **startp,
0190                const uint8_t *end, GElf_Addr addr, const char *fmt,
0191                char **bufp, size_t len, void *symcbarg);
0192 
0193 /* Produce disassembly output for given memory and output it using the
0194    given callback functions.  */
0195 extern int disasm_cb (DisasmCtx_t *ctx, const uint8_t **startp,
0196               const uint8_t *end, GElf_Addr addr, const char *fmt,
0197               DisasmOutputCB_t outcb, void *outcbarg, void *symcbarg);
0198 
0199 #ifdef __cplusplus
0200 }
0201 #endif
0202 
0203 #endif  /* libasm.h */