objfmt.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * \file libyasm/objfmt.h
  3. * \brief YASM object format module interface.
  4. *
  5. * \license
  6. * Copyright (C) 2001-2007 Peter Johnson
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * - Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * - Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  21. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. * POSSIBILITY OF SUCH DAMAGE.
  28. * \endlicense
  29. */
  30. #ifndef YASM_OBJFMT_H
  31. #define YASM_OBJFMT_H
  32. #ifndef YASM_DOXYGEN
  33. /** Base #yasm_objfmt structure. Must be present as the first element in any
  34. * #yasm_objfmt implementation.
  35. */
  36. typedef struct yasm_objfmt_base {
  37. /** #yasm_objfmt_module implementation for this object format. */
  38. const struct yasm_objfmt_module *module;
  39. } yasm_objfmt_base;
  40. #endif
  41. /** Object format module interface. */
  42. struct yasm_objfmt_module {
  43. /** One-line description of the object format. */
  44. const char *name;
  45. /** Keyword used to select object format. */
  46. const char *keyword;
  47. /** Default output file extension (without the '.').
  48. * NULL means no extension, with no '.', while "" includes the '.'.
  49. */
  50. /*@null@*/ const char *extension;
  51. /** Default (starting) x86 BITS setting. This only appies to the x86
  52. * architecture; other architectures ignore this setting.
  53. */
  54. const unsigned char default_x86_mode_bits;
  55. /** If @ signs should be legal in identifiers. */
  56. const unsigned char id_at_ok;
  57. /** NULL-terminated list of debug format (yasm_dbgfmt) keywords that are
  58. * valid to use with this object format. The null debug format
  59. * (null_dbgfmt, "null") should always be in this list so it's possible to
  60. * have no debug output.
  61. */
  62. const char **dbgfmt_keywords;
  63. /** Default debug format keyword (set even if there's only one available to
  64. * use).
  65. */
  66. const char *default_dbgfmt_keyword;
  67. /** NULL-terminated list of directives. NULL if none. */
  68. /*@null@*/ const yasm_directive *directives;
  69. /** NULL-terminated list of standard macro lookups. NULL if none. */
  70. const yasm_stdmac *stdmacs;
  71. /** Create object format.
  72. * Module-level implementation of yasm_objfmt_create().
  73. * Call yasm_objfmt_create() instead of calling this function.
  74. * \param object object
  75. * \param a architecture in use
  76. * \return NULL if architecture/machine combination not supported.
  77. */
  78. /*@null@*/ /*@only@*/ yasm_objfmt * (*create) (yasm_object *object);
  79. /** Module-level implementation of yasm_objfmt_output().
  80. * Call yasm_objfmt_output() instead of calling this function.
  81. */
  82. void (*output) (yasm_object *o, FILE *f, int all_syms,
  83. yasm_errwarns *errwarns);
  84. /** Module-level implementation of yasm_objfmt_destroy().
  85. * Call yasm_objfmt_destroy() instead of calling this function.
  86. */
  87. void (*destroy) (/*@only@*/ yasm_objfmt *objfmt);
  88. /** Module-level implementation of yasm_objfmt_add_default_section().
  89. * Call yasm_objfmt_add_default_section() instead of calling this function.
  90. */
  91. yasm_section * (*add_default_section) (yasm_object *object);
  92. /** Module-level implementation of yasm_objfmt_init_new_section().
  93. * Call yasm_objfmt_init_new_section() instead of calling this function.
  94. */
  95. void (*init_new_section) (yasm_section *section, unsigned long line);
  96. /** Module-level implementation of yasm_objfmt_section_switch().
  97. * Call yasm_objfmt_section_switch() instead of calling this function.
  98. */
  99. /*@observer@*/ /*@null@*/ yasm_section *
  100. (*section_switch)(yasm_object *object, yasm_valparamhead *valparams,
  101. /*@null@*/ yasm_valparamhead *objext_valparams,
  102. unsigned long line);
  103. /** Module-level implementation of yasm_objfmt_get_special_sym().
  104. * Call yasm_objfmt_get_special_sym() instead of calling this function.
  105. */
  106. /*@observer@*/ /*@null@*/ yasm_symrec *
  107. (*get_special_sym)(yasm_object *object, const char *name,
  108. const char *parser);
  109. /**
  110. * --replace params
  111. */
  112. const char** replace_map;
  113. /**
  114. * Number of elements in replace_map
  115. */
  116. int replace_map_size;
  117. };
  118. /** Create object format.
  119. * \param module object format module
  120. * \param object object
  121. * \return NULL if architecture/machine combination not supported.
  122. */
  123. /*@null@*/ /*@only@*/ yasm_objfmt *yasm_objfmt_create
  124. (const yasm_objfmt_module *module, yasm_object *object);
  125. /** Write out (post-optimized) sections to the object file.
  126. * This function may call yasm_symrec_* functions as necessary (including
  127. * yasm_symrec_traverse()) to retrieve symbolic information.
  128. * \param object object
  129. * \param f output object file
  130. * \param all_syms if nonzero, all symbols should be included in
  131. * the object file
  132. * \param errwarns error/warning set
  133. * \note Errors and warnings are stored into errwarns.
  134. */
  135. void yasm_objfmt_output(yasm_object *object, FILE *f, int all_syms,
  136. yasm_errwarns *errwarns);
  137. /** Cleans up any allocated object format memory.
  138. * \param objfmt object format
  139. */
  140. void yasm_objfmt_destroy(/*@only@*/ yasm_objfmt *objfmt);
  141. /** Add a default section to an object.
  142. * \param object object
  143. * \return Default section.
  144. */
  145. yasm_section *yasm_objfmt_add_default_section(yasm_object *object);
  146. /** Initialize the object-format specific portion of a section. Called
  147. * by yasm_object_get_general(); in general should not be directly called.
  148. * \param section section
  149. * \param line virtual line (from yasm_linemap)
  150. */
  151. void yasm_objfmt_init_new_section(yasm_object *object, unsigned long line);
  152. /** Switch object file sections. The first val of the valparams should
  153. * be the section name. Calls yasm_object_get_general() to actually get
  154. * the section.
  155. * \param object object
  156. * \param valparams value/parameters
  157. * \param objext_valparams object format-specific value/parameters
  158. * \param line virtual line (from yasm_linemap)
  159. * \return NULL on error, otherwise new section.
  160. */
  161. /*@observer@*/ /*@null@*/ yasm_section *yasm_objfmt_section_switch
  162. (yasm_object *object, yasm_valparamhead *valparams,
  163. /*@null@*/ yasm_valparamhead *objext_valparams, unsigned long line);
  164. /** Get a special symbol. Special symbols are generally used to generate
  165. * special relocation types via the WRT mechanism.
  166. * \param object object
  167. * \param name symbol name (not including any parser-specific prefix)
  168. * \param parser parser keyword
  169. * \return NULL if unrecognized, otherwise special symbol.
  170. */
  171. /*@observer@*/ /*@null@*/ yasm_symrec *yasm_objfmt_get_special_sym
  172. (yasm_object *object, const char *name, const char *parser);
  173. #ifndef YASM_DOXYGEN
  174. /* Inline macro implementations for objfmt functions */
  175. #define yasm_objfmt_create(module, object) module->create(object)
  176. #define yasm_objfmt_output(object, f, all_syms, ews) \
  177. ((yasm_objfmt_base *)((object)->objfmt))->module->output \
  178. (object, f, all_syms, ews)
  179. #define yasm_objfmt_destroy(objfmt) \
  180. ((yasm_objfmt_base *)objfmt)->module->destroy(objfmt)
  181. #define yasm_objfmt_section_switch(object, vpms, oe_vpms, line) \
  182. ((yasm_objfmt_base *)((object)->objfmt))->module->section_switch \
  183. (object, vpms, oe_vpms, line)
  184. #define yasm_objfmt_add_default_section(object) \
  185. ((yasm_objfmt_base *)((object)->objfmt))->module->add_default_section \
  186. (object)
  187. #define yasm_objfmt_init_new_section(section, line) \
  188. ((yasm_objfmt_base *)((object)->objfmt))->module->init_new_section \
  189. (section, line)
  190. #define yasm_objfmt_get_special_sym(object, name, parser) \
  191. ((yasm_objfmt_base *)((object)->objfmt))->module->get_special_sym \
  192. (object, name, parser)
  193. #endif
  194. #endif