Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Interface for libasm. |
| 2 | Copyright (C) 2002 Red Hat, Inc. |
| 3 | |
| 4 | This program is Open Source software; you can redistribute it and/or |
| 5 | modify it under the terms of the Open Software License version 1.0 as |
| 6 | published by the Open Source Initiative. |
| 7 | |
| 8 | You should have received a copy of the Open Software License along |
| 9 | with this program; if not, you may obtain a copy of the Open Software |
| 10 | License version 1.0 from http://www.opensource.org/licenses/osl.php or |
| 11 | by writing the Open Source Initiative c/o Lawrence Rosen, Esq., |
| 12 | 3001 King Ranch Road, Ukiah, CA 95482. */ |
| 13 | |
| 14 | #ifndef _LIBASM_H |
| 15 | #define _LIBASM_H 1 |
| 16 | |
| 17 | #include <stdbool.h> |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | #include <gelf.h> |
| 21 | |
| 22 | |
| 23 | /* Opaque type for the assembler context descriptor. */ |
| 24 | typedef struct AsmCtx AsmCtx_t; |
| 25 | |
| 26 | /* Opaque type for a section. */ |
| 27 | typedef struct AsmScn AsmScn_t; |
| 28 | |
| 29 | /* Opaque type for a section group. */ |
| 30 | typedef struct AsmScnGrp AsmScnGrp_t; |
| 31 | |
| 32 | /* Opaque type for a symbol. */ |
| 33 | typedef struct AsmSym AsmSym_t; |
| 34 | |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | /* Create output file and return descriptor for assembler context. If |
| 41 | TEXTP is true the output is an assembler format text file. |
| 42 | Otherwise an object file is created. The MACHINE parameter |
| 43 | corresponds to an EM_ constant from <elf.h>, KLASS specifies the |
| 44 | class (32- or 64-bit), and DATA specifies the byte order (little or |
| 45 | big endian). */ |
| 46 | extern AsmCtx_t *asm_begin (const char *fname, bool textp, int machine, |
| 47 | int klass, int data); |
| 48 | |
| 49 | /* Abort the operation on the assembler context and free all resources. */ |
| 50 | extern int asm_abort (AsmCtx_t *ctx); |
| 51 | |
| 52 | /* Finalize output file and free all resources. */ |
| 53 | extern int asm_end (AsmCtx_t *ctx); |
| 54 | |
| 55 | |
| 56 | /* Return handle for the named section. If it was not used before |
| 57 | create it. */ |
| 58 | extern AsmScn_t *asm_newscn (AsmCtx_t *ctx, const char *scnname, |
| 59 | GElf_Word type, GElf_Xword flags); |
| 60 | |
| 61 | |
| 62 | /* Similar to 'asm_newscn', but make it part of section group GRP. */ |
| 63 | extern AsmScn_t *asm_newscn_ingrp (AsmCtx_t *ctx, const char *scnname, |
| 64 | GElf_Word type, GElf_Xword flags, |
| 65 | AsmScnGrp_t *grp); |
| 66 | |
| 67 | /* Create new subsection NR in the given section. */ |
| 68 | extern AsmScn_t *asm_newsubscn (AsmScn_t *asmscn, unsigned int nr); |
| 69 | |
| 70 | |
| 71 | /* Return handle for new section group. The signature symbol can be |
| 72 | set later. */ |
| 73 | extern AsmScnGrp_t *asm_newscngrp (AsmCtx_t *ctx, const char *grpname, |
| 74 | AsmSym_t *signature, Elf32_Word flags); |
| 75 | |
| 76 | /* Set or overwrite signature symbol for group. */ |
| 77 | extern int asm_scngrp_newsignature (AsmScnGrp_t *grp, AsmSym_t *signature); |
| 78 | |
| 79 | |
| 80 | /* Add zero terminated string STR of size LEN to (sub)section ASMSCN. */ |
| 81 | extern int asm_addstrz (AsmScn_t *asmscn, const char *str, size_t len); |
| 82 | |
| 83 | /* Add 8-bit signed integer NUM to (sub)section ASMSCN. */ |
| 84 | extern int asm_addint8 (AsmScn_t *asmscn, int8_t num); |
| 85 | |
| 86 | /* Add 8-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 87 | extern int asm_adduint8 (AsmScn_t *asmscn, uint8_t num); |
| 88 | |
| 89 | /* Add 16-bit signed integer NUM to (sub)section ASMSCN. */ |
| 90 | extern int asm_addint16 (AsmScn_t *asmscn, int16_t num); |
| 91 | |
| 92 | /* Add 16-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 93 | extern int asm_adduint16 (AsmScn_t *asmscn, uint16_t num); |
| 94 | |
| 95 | /* Add 32-bit signed integer NUM to (sub)section ASMSCN. */ |
| 96 | extern int asm_addint32 (AsmScn_t *asmscn, int32_t num); |
| 97 | |
| 98 | /* Add 32-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 99 | extern int asm_adduint32 (AsmScn_t *asmscn, uint32_t num); |
| 100 | |
| 101 | /* Add 64-bit signed integer NUM to (sub)section ASMSCN. */ |
| 102 | extern int asm_addint64 (AsmScn_t *asmscn, int64_t num); |
| 103 | |
| 104 | /* Add 64-bit unsigned integer NUM to (sub)section ASMSCN. */ |
| 105 | extern int asm_adduint64 (AsmScn_t *asmscn, uint64_t num); |
| 106 | |
| 107 | |
| 108 | /* Add signed little endian base 128 integer NUM to (sub)section ASMSCN. */ |
| 109 | extern int asm_addsleb128 (AsmScn_t *asmscn, int32_t num); |
| 110 | |
| 111 | /* Add unsigned little endian base 128 integer NUM to (sub)section ASMSCN. */ |
| 112 | extern int asm_adduleb128 (AsmScn_t *asmscn, uint32_t num); |
| 113 | |
| 114 | |
| 115 | /* Define new symbol NAME for current position in given section ASMSCN. */ |
| 116 | extern AsmSym_t *asm_newsym (AsmScn_t *asmscn, const char *name, |
| 117 | GElf_Xword size, int type, int binding); |
| 118 | |
| 119 | |
| 120 | /* Define new common symbol NAME with given SIZE and alignment. */ |
| 121 | extern AsmSym_t *asm_newcomsym (AsmCtx_t *ctx, const char *name, |
| 122 | GElf_Xword size, GElf_Addr align); |
| 123 | |
| 124 | /* Define new common symbol NAME with given SIZE, VALUE, TYPE, and BINDING. */ |
| 125 | extern AsmSym_t *asm_newabssym (AsmCtx_t *ctx, const char *name, |
| 126 | GElf_Xword size, GElf_Addr value, |
| 127 | int type, int binding); |
| 128 | |
| 129 | |
| 130 | /* Align (sub)section offset according to VALUE. */ |
| 131 | extern int asm_align (AsmScn_t *asmscn, GElf_Word value); |
| 132 | |
| 133 | /* Set the byte pattern used to fill gaps created by alignment. */ |
| 134 | extern int asm_fill (AsmScn_t *asmscn, void *bytes, size_t len); |
| 135 | |
| 136 | |
| 137 | /* Return ELF descriptor created for the output file of the given context. */ |
| 138 | extern Elf *asm_getelf (AsmCtx_t *ctx); |
| 139 | |
| 140 | |
| 141 | /* Return error code of last failing function call. This value is kept |
| 142 | separately for each thread. */ |
| 143 | extern int asm_errno (void); |
| 144 | |
| 145 | /* Return error string for ERROR. If ERROR is zero, return error string |
| 146 | for most recent error or NULL is none occurred. If ERROR is -1 the |
| 147 | behaviour is similar to the last case except that not NULL but a legal |
| 148 | string is returned. */ |
| 149 | extern const char *asm_errmsg (int __error); |
| 150 | |
| 151 | #ifdef __cplusplus |
| 152 | } |
| 153 | #endif |
| 154 | |
| 155 | #endif /* libasm.h */ |