coff.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* coff.h: Definitions for COFF object files
  2. Copyright (C) 2002-2003 Sebastian Reichelt
  3. Copyright (C) 2005 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #ifndef COFF_H
  16. #define COFF_H
  17. #include "../generic.h"
  18. #include "../integers.h"
  19. // *** File Mapping Definitions ***
  20. #define COFF_MACHINE_M68K 0x150
  21. #define COFF_FLAG_32BIT_BE 0x0200
  22. #define COFF_FLAG_NO_LINE_NUMBERS 0x0004
  23. // File Header
  24. typedef struct ATTRIBUTE_PACKED {
  25. TI2 Machine;
  26. TI2 SectionCount;
  27. TI4 TimeStamp;
  28. TI4 PSymbols;
  29. TI4 SymbolCount;
  30. TI2 OptHdrSize;
  31. TI2 Flags;
  32. } COFF_HEADER;
  33. #define COFF_SECTION_NAME_LEN 8
  34. // Section Header
  35. typedef struct ATTRIBUTE_PACKED {
  36. char Name[COFF_SECTION_NAME_LEN];
  37. TI4 PhysicalAddress;
  38. TI4 VirtualAddress;
  39. TI4 Size;
  40. TI4 PData;
  41. TI4 PRelocs;
  42. TI4 PLines;
  43. TI2 RelocCount;
  44. TI2 LineCount;
  45. TI4 Flags;
  46. } COFF_SECTION;
  47. typedef COFF_SECTION COFF_SECTIONS[];
  48. // Section Flags
  49. #define COFF_SECTION_TEXT 0x20
  50. #define COFF_SECTION_DATA 0x40
  51. #define COFF_SECTION_BSS 0x80
  52. #ifdef COFF_TIGCC_EXTENSIONS
  53. #define COFF_SECTION_MERGEABLE 0x1000000
  54. #define COFF_SECTION_UNALIGNED 0x2000000
  55. #endif
  56. // Symbol Name
  57. // (either directly or in string table)
  58. typedef union ATTRIBUTE_PACKED {
  59. struct ATTRIBUTE_PACKED {
  60. ZI4 Zero; // Check this with IsZero.
  61. TI4 StringOffset; // If Zero is really zero, this is an offset into the string table.
  62. } StringRef;
  63. char Name[8]; // Otherwise, this is the name of the symbol.
  64. } SYM_NAME;
  65. // Symbol Entry
  66. typedef struct ATTRIBUTE_PACKED {
  67. SYM_NAME Name;
  68. TI4 Value;
  69. TI2 Section;
  70. TI2 Type;
  71. TI1 Class;
  72. TI1 AuxSymbolCount;
  73. } COFF_SYMBOL;
  74. typedef COFF_SYMBOL COFF_SYMBOLS[];
  75. #define COFF_SYMBOL_EXTERNAL 0x02
  76. #define COFF_SYMBOL_LABEL 0x06
  77. // Reloc Entry
  78. typedef struct ATTRIBUTE_PACKED {
  79. TI4 Location;
  80. TI4 Symbol;
  81. TI2 Type;
  82. } COFF_RELOC;
  83. typedef COFF_RELOC COFF_RELOCS[];
  84. #define COFF_RELOC_DIR2 0x01
  85. #define COFF_RELOC_DIR4 0x06
  86. #define COFF_RELOC_ABS1 0x0F
  87. #define COFF_RELOC_ABS2 0x10
  88. #define COFF_RELOC_ABS4 0x11
  89. #define COFF_RELOC_REL1 0x12
  90. #define COFF_RELOC_REL2 0x13
  91. #define COFF_RELOC_REL4 0x14
  92. #define COFF_RELOC_ABS4_NEG 0x45
  93. #ifdef COFF_TIGCC_EXTENSIONS
  94. #define COFF_RELOC_ABS2_NEG 0x7161
  95. #define COFF_RELOC_ABS1_NEG 0x7162
  96. #define COFF_RELOC_UNOPTIMIZABLE 0x8000
  97. #endif
  98. // Line Number Entry
  99. typedef struct ATTRIBUTE_PACKED {
  100. TI4 LineAddress;
  101. TI2 LineNumber;
  102. } COFF_LINE_NUM;
  103. typedef COFF_LINE_NUM COFF_LINE_NUMS[];
  104. // *** Helping Definitions ***
  105. typedef struct {
  106. FILE_PTR PSections;
  107. COUNT SectionCount;
  108. FILE_PTR PSymbols;
  109. COUNT SymbolCount;
  110. FILE_PTR PStrings;
  111. } COFF_INFO;
  112. #define CreateCoffInfo(Header,Info) \
  113. ({ \
  114. (Info).PSections = sizeof (Header) + ReadTI2 ((Header).OptHdrSize); \
  115. (Info).SectionCount = ReadTI2 ((Header).SectionCount); \
  116. (Info).PSymbols = ReadTI4 ((Header).PSymbols); \
  117. (Info).SymbolCount = ReadTI4 ((Header).SymbolCount); \
  118. (Info).PStrings = (Info).PSymbols + (Info).SymbolCount * sizeof (COFF_SYMBOL); \
  119. })
  120. // *** File Type Check ***
  121. // Check whether a file has the COFF format.
  122. #define IsCOFFFile(File,FileSize) (((FileSize) >= ((SIZE) (sizeof (COFF_HEADER)))) && ((File) [0] == 0x01) && ((File) [1] == 0x50))
  123. #endif