nxflat.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /****************************************************************************
  2. * include/nxflat.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_NXFLAT_H
  21. #define __INCLUDE_NXFLAT_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <stdint.h>
  28. /****************************************************************************
  29. * Pre-processor Definitions
  30. ****************************************************************************/
  31. #define NXFLAT_MAX_STRING_SIZE 64 /* Largest size of string (w/zterminator) */
  32. #define NXFLAT_MAGIC "NxFT" /* NXFLAT magic number */
  33. /****************************************************************************
  34. * Public Types
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * The NXFLAT file header
  38. *
  39. * The elements within this structure are stored in network order (i.e.,
  40. * ntohs() and ntohl() should be used to access fields within the
  41. * header.
  42. ****************************************************************************/
  43. struct nxflat_hdr_s
  44. {
  45. /* The "magic number" identifying the file type. This field should contain
  46. * "NxFT". NOTE that there is no other versioning information other than
  47. * this magic number.
  48. */
  49. char h_magic[4];
  50. /* The following fields provide the memory map for the nxflat binary.
  51. *
  52. * h_entry - Offset to the first executable insruction from
  53. * the beginning of the file.
  54. * h_datastart - Offset to the beginning of the data segment from
  55. * the beginning of the file. This field can also
  56. * interpreted as the size of the ISpace segment.
  57. * h_dataend - Offset to the end of the data segment from the
  58. * beginning of the file.
  59. * h_bssend - Offset to the end of bss segment from the beginning
  60. * of the file.
  61. *
  62. * The text segment can be considered to be the contiguous (unrelocated)
  63. * address space range from address zero through (but not including)
  64. * h_datastart.
  65. *
  66. * The size of the data/bss segment includes (as a minimum) the data
  67. * and bss regions (bss_end - data_start) as well as the size of the
  68. * stack. At run time, this region will also include program arguments
  69. * and environment variables.
  70. *
  71. * The bss segment is data_end through bss_end.
  72. */
  73. uint32_t h_entry;
  74. uint32_t h_datastart;
  75. uint32_t h_dataend;
  76. uint32_t h_bssend;
  77. /* Size of stack, in bytes */
  78. uint32_t h_stacksize;
  79. /* Relocation entries:
  80. *
  81. * h_relocstart - Offset to the beginning of an array of relocation
  82. * records (struct nxflat_reloc). The offset is
  83. * relative to the start of the file
  84. */
  85. uint32_t h_relocstart; /* Offset of relocation records */
  86. /* Imported symbol table (NOTE no symbols are exported):
  87. *
  88. * h_importsymbols - Offset to the beginning of an array of imported
  89. * symbol structures (struct nxflat_import_s). The
  90. * h_importsymbols offset is relative to the
  91. * beginning of the file. Each entry of the
  92. * array contains an uint32_t offset (again from
  93. * the beginning of the file) to the name of
  94. * a symbol string. This string is null-terminated.
  95. */
  96. uint32_t h_importsymbols; /* Offset to list of imported symbols */
  97. /* 16-bit counts
  98. *
  99. * h_reloccount - The number of relocation records in the array
  100. * h_importcount - The number of records in the h_importsymbols array.
  101. */
  102. uint16_t h_reloccount; /* Number of relocation records */
  103. uint16_t h_importcount; /* Number of imported symbols */
  104. };
  105. /****************************************************************************
  106. * NXFLAT Relocation types.
  107. *
  108. * The relocation records are an array of the following type.
  109. ****************************************************************************/
  110. struct nxflat_reloc_s
  111. {
  112. uint32_t r_info; /* Bit-encoded relocation info */
  113. };
  114. /* Pack the type and the offset into one 32-bit value */
  115. #define NXFLAT_RELOC(t,o) (((uint32_t)((t) & 3) << 30) | ((o) & 0x3fffffff))
  116. /* The top three bits of the relocation info is the relocation type (see the
  117. * NXFLAT_RELOC_TYPE_* definitions below. This is an unsigned value.
  118. */
  119. #define NXFLAT_RELOC_TYPE(r) ((uint32_t)(r) >> 30)
  120. /* The bottom 28 bits of the relocation info is the (non-negative) offset
  121. * into the D-Space that needs the fixup.
  122. */
  123. #define NXFLAT_RELOC_OFFSET(r) ((uint32_t)(r) & 0x3fffffff)
  124. /* These are possible values for the relocation type:
  125. *
  126. * NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
  127. * into I-Space at the offset.
  128. * Fixup: Add mapped I-Space address to the
  129. * offset.
  130. * NXFLAT_RELOC_TYPE_REL32D Meaning: Object file contains a 32-bit offset
  131. * into D-Space at the offset.
  132. * Fixup: Add allocated D-Space address to the
  133. * offset.
  134. * NXFLAT_RELOC_TYPE_REL32ID Meaning: Object file contains a 32-bit offset
  135. * into I-Space at the offset that will
  136. * unfortunately be references relative
  137. * to the GOT
  138. * Fixup: Add allocated the mapped I-Space
  139. * address MINUS the allocated D-Space
  140. * address to the offset.
  141. */
  142. #define NXFLAT_RELOC_TYPE_REL32I 0
  143. #define NXFLAT_RELOC_TYPE_REL32D 1
  144. #undef NXFLAT_RELOC_TYPE_REL32ID /* May not need */
  145. #define NXFLAT_RELOC_TYPE_NUM 2 /* Number of relocation types */
  146. /****************************************************************************
  147. * NXFLAT Imported symbol type
  148. *
  149. * The imported symbols are an array of the following type. The fields
  150. * in each element are stored in native machine order.
  151. ****************************************************************************/
  152. struct nxflat_import_s
  153. {
  154. uint32_t i_funcname; /* Offset to name of imported function */
  155. uint32_t i_funcaddress; /* Resolved address of imported function */
  156. };
  157. #endif /* __INCLUDE_NXFLAT_H */