elf32.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /****************************************************************************
  2. * tools/cxd56/elf32.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_ELF32_H
  21. #define __INCLUDE_ELF32_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <stdint.h>
  26. /****************************************************************************
  27. * Pre-processor Definitions
  28. ****************************************************************************/
  29. #define EI_NIDENT 16 /* Size of e_ident[] */
  30. #define ELF32_ST_BIND(i) ((i) >> 4)
  31. #define ELF32_ST_TYPE(i) ((i) & 0xf)
  32. #define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))
  33. /* Definitions for Elf32_Rel*::r_info */
  34. #define ELF32_R_SYM(i) ((i) >> 8)
  35. #define ELF32_R_TYPE(i) ((i) & 0xff)
  36. #define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))
  37. #define ELF_R_SYM(i) ELF32_R_SYM(i)
  38. /****************************************************************************
  39. * Public Type Definitions
  40. ****************************************************************************/
  41. /* Figure 4.2: 32-Bit Data Types */
  42. typedef uint32_t Elf32_Addr; /* Unsigned program address */
  43. typedef uint16_t Elf32_Half; /* Unsigned medium integer */
  44. typedef uint32_t Elf32_Off; /* Unsigned file offset */
  45. typedef int32_t Elf32_Sword; /* Signed large integer */
  46. typedef uint32_t Elf32_Word; /* Unsigned large integer */
  47. /* Figure 4-3: ELF Header */
  48. typedef struct
  49. {
  50. unsigned char e_ident[EI_NIDENT];
  51. Elf32_Half e_type;
  52. Elf32_Half e_machine;
  53. Elf32_Word e_version;
  54. Elf32_Addr e_entry;
  55. Elf32_Off e_phoff;
  56. Elf32_Off e_shoff;
  57. Elf32_Word e_flags;
  58. Elf32_Half e_ehsize;
  59. Elf32_Half e_phentsize;
  60. Elf32_Half e_phnum;
  61. Elf32_Half e_shentsize;
  62. Elf32_Half e_shnum;
  63. Elf32_Half e_shstrndx;
  64. } Elf32_Ehdr;
  65. /* Figure 4-8: Section Header */
  66. typedef struct
  67. {
  68. Elf32_Word sh_name;
  69. Elf32_Word sh_type;
  70. Elf32_Word sh_flags;
  71. Elf32_Addr sh_addr;
  72. Elf32_Off sh_offset;
  73. Elf32_Word sh_size;
  74. Elf32_Word sh_link;
  75. Elf32_Word sh_info;
  76. Elf32_Word sh_addralign;
  77. Elf32_Word sh_entsize;
  78. } Elf32_Shdr;
  79. /* Figure 4-15: Symbol Table Entry */
  80. typedef struct
  81. {
  82. Elf32_Word st_name;
  83. Elf32_Addr st_value;
  84. Elf32_Word st_size;
  85. unsigned char st_info;
  86. unsigned char st_other;
  87. Elf32_Half st_shndx;
  88. } Elf32_Sym;
  89. /* Figure 4-19: Relocation Entries */
  90. typedef struct
  91. {
  92. Elf32_Addr r_offset;
  93. Elf32_Word r_info;
  94. } Elf32_Rel;
  95. typedef struct
  96. {
  97. Elf32_Addr r_offset;
  98. Elf32_Word r_info;
  99. Elf32_Sword r_addend;
  100. } Elf32_Rela;
  101. /* Figure 5-1: Program Header */
  102. typedef struct
  103. {
  104. Elf32_Word p_type;
  105. Elf32_Off p_offset;
  106. Elf32_Addr p_vaddr;
  107. Elf32_Addr p_paddr;
  108. Elf32_Word p_filesz;
  109. Elf32_Word p_memsz;
  110. Elf32_Word p_flags;
  111. Elf32_Word p_align;
  112. } Elf32_Phdr;
  113. /* Figure 5-9: Dynamic Structure */
  114. typedef struct
  115. {
  116. Elf32_Sword d_tag;
  117. union
  118. {
  119. Elf32_Word d_val;
  120. Elf32_Addr d_ptr;
  121. } d_un;
  122. } Elf32_Dyn;
  123. typedef Elf32_Addr Elf_Addr;
  124. typedef Elf32_Ehdr Elf_Ehdr;
  125. typedef Elf32_Rel Elf_Rel;
  126. typedef Elf32_Rela Elf_Rela;
  127. typedef Elf32_Sym Elf_Sym;
  128. typedef Elf32_Shdr Elf_Shdr;
  129. typedef Elf32_Word Elf_Word;
  130. #endif /* __INCLUDE_ELF32_H */