rdoff.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2017 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  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
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. /*
  34. * rdoff.h RDOFF Object File manipulation routines header file
  35. */
  36. #ifndef RDOFF_H
  37. #define RDOFF_H 1
  38. /*
  39. * RDOFF definitions. They are used by RDOFF utilities and by NASM's
  40. * 'outrdf2.c' output module.
  41. */
  42. /* RDOFF format revision (currently used only when printing the version) */
  43. #define RDOFF2_REVISION "0.6.1"
  44. /* RDOFF2 file signature */
  45. #define RDOFF2_SIGNATURE "RDOFF2"
  46. /* Maximum size of an import/export label (including trailing zero) */
  47. #define EXIM_LABEL_MAX 256
  48. /* Maximum size of library or module name (including trailing zero) */
  49. #define MODLIB_NAME_MAX 128
  50. /* Maximum number of segments that we can handle in one file */
  51. #define RDF_MAXSEGS 64
  52. /* Record types that may present the RDOFF header */
  53. #define RDFREC_GENERIC 0
  54. #define RDFREC_RELOC 1
  55. #define RDFREC_IMPORT 2
  56. #define RDFREC_GLOBAL 3
  57. #define RDFREC_DLL 4
  58. #define RDFREC_BSS 5
  59. #define RDFREC_SEGRELOC 6
  60. #define RDFREC_FARIMPORT 7
  61. #define RDFREC_MODNAME 8
  62. #define RDFREC_COMMON 10
  63. /*
  64. * Generic record - contains the type and length field, plus a 128 byte
  65. * array 'data'
  66. */
  67. struct GenericRec {
  68. uint8_t type;
  69. uint8_t reclen;
  70. char data[128];
  71. };
  72. /*
  73. * Relocation record
  74. */
  75. struct RelocRec {
  76. uint8_t type; /* must be 1 */
  77. uint8_t reclen; /* content length */
  78. uint8_t segment; /* only 0 for code, or 1 for data supported,
  79. but add 64 for relative refs (ie do not require
  80. reloc @ loadtime, only linkage) */
  81. int32_t offset; /* from start of segment in which reference is loc'd */
  82. uint8_t length; /* 1 2 or 4 bytes */
  83. uint16_t refseg; /* segment to which reference refers to */
  84. };
  85. /*
  86. * Extern/import record
  87. */
  88. struct ImportRec {
  89. uint8_t type; /* must be 2 */
  90. uint8_t reclen; /* content length */
  91. uint8_t flags; /* SYM_* flags (see below) */
  92. uint16_t segment; /* segment number allocated to the label for reloc
  93. records - label is assumed to be at offset zero
  94. in this segment, so linker must fix up with offset
  95. of segment and of offset within segment */
  96. char label[EXIM_LABEL_MAX]; /* zero terminated, should be written to file
  97. until the zero, but not after it */
  98. };
  99. /*
  100. * Public/export record
  101. */
  102. struct ExportRec {
  103. uint8_t type; /* must be 3 */
  104. uint8_t reclen; /* content length */
  105. uint8_t flags; /* SYM_* flags (see below) */
  106. uint8_t segment; /* segment referred to (0/1/2) */
  107. int32_t offset; /* offset within segment */
  108. char label[EXIM_LABEL_MAX]; /* zero terminated as in import */
  109. };
  110. /*
  111. * DLL record
  112. */
  113. struct DLLRec {
  114. uint8_t type; /* must be 4 */
  115. uint8_t reclen; /* content length */
  116. char libname[MODLIB_NAME_MAX]; /* name of library to link with at load time */
  117. };
  118. /*
  119. * BSS record
  120. */
  121. struct BSSRec {
  122. uint8_t type; /* must be 5 */
  123. uint8_t reclen; /* content length */
  124. int32_t amount; /* number of bytes BSS to reserve */
  125. };
  126. /*
  127. * Module name record
  128. */
  129. struct ModRec {
  130. uint8_t type; /* must be 8 */
  131. uint8_t reclen; /* content length */
  132. char modname[MODLIB_NAME_MAX]; /* module name */
  133. };
  134. /*
  135. * Common variable record
  136. */
  137. struct CommonRec {
  138. uint8_t type; /* must be 10 */
  139. uint8_t reclen; /* equals 7+label length */
  140. uint16_t segment; /* segment number */
  141. int32_t size; /* size of common variable */
  142. uint16_t align; /* alignment (power of two) */
  143. char label[EXIM_LABEL_MAX]; /* zero terminated as in import */
  144. };
  145. /* Flags for ExportRec */
  146. #define SYM_DATA 1
  147. #define SYM_FUNCTION 2
  148. #define SYM_GLOBAL 4
  149. #define SYM_IMPORT 8
  150. #endif /* RDOFF_H */