Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1 | /* Interface for libasm. |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 2 | Copyright (C) 2002, 2005 Red Hat, Inc. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 3 | This file is part of Red Hat elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 5 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by the |
| 7 | Free Software Foundation; version 2 of the License. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 8 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 9 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along |
| 15 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
Ulrich Drepper | 1e9ef50 | 2006-04-04 22:29:06 +0000 | [diff] [blame] | 16 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 17 | |
| 18 | Red Hat elfutils is an included package of the Open Invention Network. |
| 19 | An included package of the Open Invention Network is a package for which |
| 20 | Open Invention Network licensees cross-license their patents. No patent |
| 21 | license is granted, either expressly or impliedly, by designation as an |
| 22 | included package. Should you wish to participate in the Open Invention |
| 23 | Network licensing program, please visit www.openinventionnetwork.com |
| 24 | <http://www.openinventionnetwork.com>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 25 | |
| 26 | #ifndef _LIBASM_H |
| 27 | #define _LIBASM_H 1 |
| 28 | |
| 29 | #include <stdbool.h> |
| 30 | #include <stdint.h> |
| 31 | |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 32 | #include <libebl.h> |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | /* Opaque type for the assembler context descriptor. */ |
| 36 | typedef struct AsmCtx AsmCtx_t; |
| 37 | |
| 38 | /* Opaque type for a section. */ |
| 39 | typedef struct AsmScn AsmScn_t; |
| 40 | |
| 41 | /* Opaque type for a section group. */ |
| 42 | typedef struct AsmScnGrp AsmScnGrp_t; |
| 43 | |
| 44 | /* Opaque type for a symbol. */ |
| 45 | typedef struct AsmSym AsmSym_t; |
| 46 | |
| 47 | |
| 48 | #ifdef __cplusplus |
| 49 | extern "C" { |
| 50 | #endif |
| 51 | |
| 52 | /* Create output file and return descriptor for assembler context. If |
| 53 | TEXTP is true the output is an assembler format text file. |
| 54 | Otherwise an object file is created. The MACHINE parameter |
| 55 | corresponds to an EM_ constant from <elf.h>, KLASS specifies the |
| 56 | class (32- or 64-bit), and DATA specifies the byte order (little or |
| 57 | big endian). */ |
Ulrich Drepper | a38998e | 2005-08-03 02:05:39 +0000 | [diff] [blame] | 58 | extern AsmCtx_t *asm_begin (const char *fname, Ebl *ebl, bool textp); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 59 | |
| 60 | /* Abort the operation on the assembler context and free all resources. */ |
| 61 | extern int asm_abort (AsmCtx_t *ctx); |
| 62 | |
| 63 | /* Finalize output file and free all resources. */ |
| 64 | extern int asm_end (AsmCtx_t *ctx); |
| 65 | |
| 66 | |
| 67 | /* Return handle for the named section. If it was not used before |
| 68 | create it. */ |
| 69 | extern AsmScn_t *asm_newscn (AsmCtx_t *ctx, const char *scnname, |
| 70 | GElf_Word type, GElf_Xword flags); |
| 71 | |
| 72 | |
| 73 | /* Similar to 'asm_newscn', but make it part of section group GRP. */ |
| 74 | extern AsmScn_t *asm_newscn_ingrp (AsmCtx_t *ctx, const char *scnname, |
| 75 | GElf_Word type, GElf_Xword flags, |
| 76 | AsmScnGrp_t *grp); |
| 77 | |
| 78 | /* Create new subsection NR in the given section. */ |
| 79 | extern AsmScn_t *asm_newsubscn (AsmScn_t *asmscn, unsigned int nr); |
| 80 | |
| 81 | |
| 82 | /* Return handle for new section group. The signature symbol can be |
| 83 | set later. */ |
| 84 | extern AsmScnGrp_t *asm_newscngrp (AsmCtx_t *ctx, const char *grpname, |
| 85 | AsmSym_t *signature, Elf32_Word flags); |
| 86 | |
| 87 | /* Set or overwrite signature symbol for group. */ |
| 88 | extern int asm_scngrp_newsignature (AsmScnGrp_t *grp, AsmSym_t *signature); |
| 89 | |
| 90 | |
| 91 | /* Add zero terminated string STR of size LEN to (sub)section ASMSCN. */ |
| 92 | extern int asm_addstrz (AsmScn_t *asmscn, const char *str, size_t len); |
| 93 | |
| 94 | /* Add 8-bit signed integer NUM to (sub)section ASMSCN. */ |
| 95 | extern int asm_addint8 (AsmScn_t *asmscn, int8_t num); |
| 96 | |
| 97 | /* Add 8-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 98 | extern int asm_adduint8 (AsmScn_t *asmscn, uint8_t num); |
| 99 | |
| 100 | /* Add 16-bit signed integer NUM to (sub)section ASMSCN. */ |
| 101 | extern int asm_addint16 (AsmScn_t *asmscn, int16_t num); |
| 102 | |
| 103 | /* Add 16-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 104 | extern int asm_adduint16 (AsmScn_t *asmscn, uint16_t num); |
| 105 | |
| 106 | /* Add 32-bit signed integer NUM to (sub)section ASMSCN. */ |
| 107 | extern int asm_addint32 (AsmScn_t *asmscn, int32_t num); |
| 108 | |
| 109 | /* Add 32-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 110 | extern int asm_adduint32 (AsmScn_t *asmscn, uint32_t num); |
| 111 | |
| 112 | /* Add 64-bit signed integer NUM to (sub)section ASMSCN. */ |
| 113 | extern int asm_addint64 (AsmScn_t *asmscn, int64_t num); |
| 114 | |
| 115 | /* Add 64-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 116 | extern int asm_adduint64 (AsmScn_t *asmscn, uint64_t num); |
| 117 | |
| 118 | |
| 119 | /* Add signed little endian base 128 integer NUM to (sub)section ASMSCN. */ |
| 120 | extern int asm_addsleb128 (AsmScn_t *asmscn, int32_t num); |
| 121 | |
| 122 | /* Add unsigned little endian base 128 integer NUM to (sub)section ASMSCN. */ |
| 123 | extern int asm_adduleb128 (AsmScn_t *asmscn, uint32_t num); |
| 124 | |
| 125 | |
| 126 | /* Define new symbol NAME for current position in given section ASMSCN. */ |
| 127 | extern AsmSym_t *asm_newsym (AsmScn_t *asmscn, const char *name, |
| 128 | GElf_Xword size, int type, int binding); |
| 129 | |
| 130 | |
| 131 | /* Define new common symbol NAME with given SIZE and alignment. */ |
| 132 | extern AsmSym_t *asm_newcomsym (AsmCtx_t *ctx, const char *name, |
| 133 | GElf_Xword size, GElf_Addr align); |
| 134 | |
| 135 | /* Define new common symbol NAME with given SIZE, VALUE, TYPE, and BINDING. */ |
| 136 | extern AsmSym_t *asm_newabssym (AsmCtx_t *ctx, const char *name, |
| 137 | GElf_Xword size, GElf_Addr value, |
| 138 | int type, int binding); |
| 139 | |
| 140 | |
| 141 | /* Align (sub)section offset according to VALUE. */ |
| 142 | extern int asm_align (AsmScn_t *asmscn, GElf_Word value); |
| 143 | |
| 144 | /* Set the byte pattern used to fill gaps created by alignment. */ |
| 145 | extern int asm_fill (AsmScn_t *asmscn, void *bytes, size_t len); |
| 146 | |
| 147 | |
| 148 | /* Return ELF descriptor created for the output file of the given context. */ |
| 149 | extern Elf *asm_getelf (AsmCtx_t *ctx); |
| 150 | |
| 151 | |
| 152 | /* Return error code of last failing function call. This value is kept |
| 153 | separately for each thread. */ |
| 154 | extern int asm_errno (void); |
| 155 | |
| 156 | /* Return error string for ERROR. If ERROR is zero, return error string |
| 157 | for most recent error or NULL is none occurred. If ERROR is -1 the |
| 158 | behaviour is similar to the last case except that not NULL but a legal |
| 159 | string is returned. */ |
| 160 | extern const char *asm_errmsg (int __error); |
| 161 | |
| 162 | #ifdef __cplusplus |
| 163 | } |
| 164 | #endif |
| 165 | |
| 166 | #endif /* libasm.h */ |