coff.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /**************************************************************************/
  2. /* COFF.H */
  3. /* COFF data structures and related definitions used by the linker */
  4. /**************************************************************************/
  5. /*------------------------------------------------------------------------*/
  6. /* COFF FILE HEADER */
  7. /*------------------------------------------------------------------------*/
  8. struct filehdr {
  9. unsigned short f_magic; /* magic number */
  10. unsigned short f_nscns; /* number of sections */
  11. long f_timdat; /* time & date stamp */
  12. long f_symptr; /* file pointer to symtab */
  13. long f_nsyms; /* number of symtab entries */
  14. unsigned short f_opthdr; /* sizeof(optional hdr) */
  15. unsigned short f_flags; /* flags */
  16. unsigned short f_TargetID; /* for C6x = 0x0099 */
  17. };
  18. /*------------------------------------------------------------------------*/
  19. /* File header flags */
  20. /*------------------------------------------------------------------------*/
  21. #define F_RELFLG 0x01 /* relocation info stripped from file */
  22. #define F_EXEC 0x02 /* file is executable (no unresolved refs) */
  23. #define F_LNNO 0x04 /* line numbers stripped from file */
  24. #define F_LSYMS 0x08 /* local symbols stripped from file */
  25. #define F_GSP10 0x10 /* 34010 version */
  26. #define F_GSP20 0x20 /* 34020 version */
  27. #define F_SWABD 0x40 /* bytes swabbed (in names) */
  28. #define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */
  29. #define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */
  30. #define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */
  31. #define F_PATCH 0x400 /* contains "patch" list in optional header */
  32. #define F_NODF 0x400
  33. #define F_VERSION (F_GSP10 | F_GSP20)
  34. #define F_BYTE_ORDER (F_LITTLE | F_BIG)
  35. #define FILHDR struct filehdr
  36. /* #define FILHSZ sizeof(FILHDR) */
  37. #define FILHSZ 22 /* above rounds to align on 4 bytes which causes problems */
  38. #define COFF_C67_MAGIC 0x00c2
  39. /*------------------------------------------------------------------------*/
  40. /* Macros to recognize magic numbers */
  41. /*------------------------------------------------------------------------*/
  42. #define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic)
  43. #define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE))
  44. #define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x))
  45. /*------------------------------------------------------------------------*/
  46. /* OPTIONAL FILE HEADER */
  47. /*------------------------------------------------------------------------*/
  48. typedef struct aouthdr {
  49. short magic; /* see magic.h */
  50. short vstamp; /* version stamp */
  51. long tsize; /* text size in bytes, padded to FW bdry*/
  52. long dsize; /* initialized data " " */
  53. long bsize; /* uninitialized data " " */
  54. long entrypt; /* entry pt. */
  55. long text_start; /* base of text used for this file */
  56. long data_start; /* base of data used for this file */
  57. } AOUTHDR;
  58. #define AOUTSZ sizeof(AOUTHDR)
  59. /*----------------------------------------------------------------------*/
  60. /* When a UNIX aout header is to be built in the optional header, */
  61. /* the following magic numbers can appear in that header: */
  62. /* */
  63. /* AOUT1MAGIC : default : readonly sharable text segment */
  64. /* AOUT2MAGIC: : writable text segment */
  65. /* PAGEMAGIC : : configured for paging */
  66. /*----------------------------------------------------------------------*/
  67. #define AOUT1MAGIC 0410
  68. #define AOUT2MAGIC 0407
  69. #define PAGEMAGIC 0413
  70. /*------------------------------------------------------------------------*/
  71. /* COMMON ARCHIVE FILE STRUCTURES */
  72. /* */
  73. /* ARCHIVE File Organization: */
  74. /* _______________________________________________ */
  75. /* |__________ARCHIVE_MAGIC_STRING_______________| */
  76. /* |__________ARCHIVE_FILE_MEMBER_1______________| */
  77. /* | | */
  78. /* | Archive File Header "ar_hdr" | */
  79. /* |.............................................| */
  80. /* | Member Contents | */
  81. /* | 1. External symbol directory | */
  82. /* | 2. Text file | */
  83. /* |_____________________________________________| */
  84. /* |________ARCHIVE_FILE_MEMBER_2________________| */
  85. /* | "ar_hdr" | */
  86. /* |.............................................| */
  87. /* | Member Contents (.o or text file) | */
  88. /* |_____________________________________________| */
  89. /* | . . . | */
  90. /* | . . . | */
  91. /* | . . . | */
  92. /* |_____________________________________________| */
  93. /* |________ARCHIVE_FILE_MEMBER_n________________| */
  94. /* | "ar_hdr" | */
  95. /* |.............................................| */
  96. /* | Member Contents | */
  97. /* |_____________________________________________| */
  98. /* */
  99. /*------------------------------------------------------------------------*/
  100. #define COFF_ARMAG "!<arch>\n"
  101. #define SARMAG 8
  102. #define ARFMAG "`\n"
  103. struct ar_hdr /* archive file member header - printable ascii */
  104. {
  105. char ar_name[16]; /* file member name - `/' terminated */
  106. char ar_date[12]; /* file member date - decimal */
  107. char ar_uid[6]; /* file member user id - decimal */
  108. char ar_gid[6]; /* file member group id - decimal */
  109. char ar_mode[8]; /* file member mode - octal */
  110. char ar_size[10]; /* file member size - decimal */
  111. char ar_fmag[2]; /* ARFMAG - string to end header */
  112. };
  113. /*------------------------------------------------------------------------*/
  114. /* SECTION HEADER */
  115. /*------------------------------------------------------------------------*/
  116. struct scnhdr {
  117. char s_name[8]; /* section name */
  118. long s_paddr; /* physical address */
  119. long s_vaddr; /* virtual address */
  120. long s_size; /* section size */
  121. long s_scnptr; /* file ptr to raw data for section */
  122. long s_relptr; /* file ptr to relocation */
  123. long s_lnnoptr; /* file ptr to line numbers */
  124. unsigned int s_nreloc; /* number of relocation entries */
  125. unsigned int s_nlnno; /* number of line number entries */
  126. unsigned int s_flags; /* flags */
  127. unsigned short s_reserved; /* reserved byte */
  128. unsigned short s_page; /* memory page id */
  129. };
  130. #define SCNHDR struct scnhdr
  131. #define SCNHSZ sizeof(SCNHDR)
  132. /*------------------------------------------------------------------------*/
  133. /* Define constants for names of "special" sections */
  134. /*------------------------------------------------------------------------*/
  135. /* #define _TEXT ".text" */
  136. #define _DATA ".data"
  137. #define _BSS ".bss"
  138. #define _CINIT ".cinit"
  139. #define _TV ".tv"
  140. /*------------------------------------------------------------------------*/
  141. /* The low 4 bits of s_flags is used as a section "type" */
  142. /*------------------------------------------------------------------------*/
  143. #define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */
  144. #define STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */
  145. #define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */
  146. #define STYP_GROUP 0x04 /* "grouped" : formed of input sections */
  147. #define STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */
  148. #define STYP_COPY 0x10 /* "copy" : used for C init tables -
  149. not allocated, relocated,
  150. loaded; reloc & lineno
  151. entries processed normally */
  152. #define STYP_TEXT 0x20 /* section contains text only */
  153. #define STYP_DATA 0x40 /* section contains data only */
  154. #define STYP_BSS 0x80 /* section contains bss only */
  155. #define STYP_ALIGN 0x100 /* align flag passed by old version assemblers */
  156. #define ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */
  157. #define ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8))
  158. /*------------------------------------------------------------------------*/
  159. /* RELOCATION ENTRIES */
  160. /*------------------------------------------------------------------------*/
  161. struct reloc
  162. {
  163. long r_vaddr; /* (virtual) address of reference */
  164. short r_symndx; /* index into symbol table */
  165. unsigned short r_disp; /* additional bits for address calculation */
  166. unsigned short r_type; /* relocation type */
  167. };
  168. #define RELOC struct reloc
  169. #define RELSZ 10 /* sizeof(RELOC) */
  170. /*--------------------------------------------------------------------------*/
  171. /* define all relocation types */
  172. /*--------------------------------------------------------------------------*/
  173. #define R_ABS 0 /* absolute address - no relocation */
  174. #define R_DIR16 01 /* UNUSED */
  175. #define R_REL16 02 /* UNUSED */
  176. #define R_DIR24 04 /* UNUSED */
  177. #define R_REL24 05 /* 24 bits, direct */
  178. #define R_DIR32 06 /* UNUSED */
  179. #define R_RELBYTE 017 /* 8 bits, direct */
  180. #define R_RELWORD 020 /* 16 bits, direct */
  181. #define R_RELLONG 021 /* 32 bits, direct */
  182. #define R_PCRBYTE 022 /* 8 bits, PC-relative */
  183. #define R_PCRWORD 023 /* 16 bits, PC-relative */
  184. #define R_PCRLONG 024 /* 32 bits, PC-relative */
  185. #define R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */
  186. #define R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */
  187. #define R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */
  188. #define R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/
  189. #define R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */
  190. #define R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */
  191. #define R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */
  192. #define R_REL13 052 /* DSP: 13 bits, direct */
  193. /*------------------------------------------------------------------------*/
  194. /* LINE NUMBER ENTRIES */
  195. /*------------------------------------------------------------------------*/
  196. struct lineno
  197. {
  198. union
  199. {
  200. long l_symndx ; /* sym. table index of function name
  201. iff l_lnno == 0 */
  202. long l_paddr ; /* (physical) address of line number */
  203. } l_addr ;
  204. unsigned short l_lnno ; /* line number */
  205. };
  206. #define LINENO struct lineno
  207. #define LINESZ 6 /* sizeof(LINENO) */
  208. /*------------------------------------------------------------------------*/
  209. /* STORAGE CLASSES */
  210. /*------------------------------------------------------------------------*/
  211. #define C_EFCN -1 /* physical end of function */
  212. #define C_NULL 0
  213. #define C_AUTO 1 /* automatic variable */
  214. #define C_EXT 2 /* external symbol */
  215. #define C_STAT 3 /* static */
  216. #define C_REG 4 /* register variable */
  217. #define C_EXTDEF 5 /* external definition */
  218. #define C_LABEL 6 /* label */
  219. #define C_ULABEL 7 /* undefined label */
  220. #define C_MOS 8 /* member of structure */
  221. #define C_ARG 9 /* function argument */
  222. #define C_STRTAG 10 /* structure tag */
  223. #define C_MOU 11 /* member of union */
  224. #define C_UNTAG 12 /* union tag */
  225. #define C_TPDEF 13 /* type definition */
  226. #define C_USTATIC 14 /* undefined static */
  227. #define C_ENTAG 15 /* enumeration tag */
  228. #define C_MOE 16 /* member of enumeration */
  229. #define C_REGPARM 17 /* register parameter */
  230. #define C_FIELD 18 /* bit field */
  231. #define C_BLOCK 100 /* ".bb" or ".eb" */
  232. #define C_FCN 101 /* ".bf" or ".ef" */
  233. #define C_EOS 102 /* end of structure */
  234. #define C_FILE 103 /* file name */
  235. #define C_LINE 104 /* dummy sclass for line number entry */
  236. #define C_ALIAS 105 /* duplicate tag */
  237. #define C_HIDDEN 106 /* special storage class for external */
  238. /* symbols in dmert public libraries */
  239. /*------------------------------------------------------------------------*/
  240. /* SYMBOL TABLE ENTRIES */
  241. /*------------------------------------------------------------------------*/
  242. #define SYMNMLEN 8 /* Number of characters in a symbol name */
  243. #define FILNMLEN 14 /* Number of characters in a file name */
  244. #define DIMNUM 4 /* Number of array dimensions in auxiliary entry */
  245. struct syment
  246. {
  247. union
  248. {
  249. char _n_name[SYMNMLEN]; /* old COFF version */
  250. struct
  251. {
  252. long _n_zeroes; /* new == 0 */
  253. long _n_offset; /* offset into string table */
  254. } _n_n;
  255. char *_n_nptr[2]; /* allows for overlaying */
  256. } _n;
  257. long n_value; /* value of symbol */
  258. short n_scnum; /* section number */
  259. unsigned short n_type; /* type and derived type */
  260. char n_sclass; /* storage class */
  261. char n_numaux; /* number of aux. entries */
  262. };
  263. #define n_name _n._n_name
  264. #define n_nptr _n._n_nptr[1]
  265. #define n_zeroes _n._n_n._n_zeroes
  266. #define n_offset _n._n_n._n_offset
  267. /*------------------------------------------------------------------------*/
  268. /* Relocatable symbols have a section number of the */
  269. /* section in which they are defined. Otherwise, section */
  270. /* numbers have the following meanings: */
  271. /*------------------------------------------------------------------------*/
  272. #define N_UNDEF 0 /* undefined symbol */
  273. #define N_ABS -1 /* value of symbol is absolute */
  274. #define N_DEBUG -2 /* special debugging symbol */
  275. #define N_TV (unsigned short)-3 /* needs transfer vector (preload) */
  276. #define P_TV (unsigned short)-4 /* needs transfer vector (postload) */
  277. /*------------------------------------------------------------------------*/
  278. /* The fundamental type of a symbol packed into the low */
  279. /* 4 bits of the word. */
  280. /*------------------------------------------------------------------------*/
  281. #define _EF ".ef"
  282. #define T_NULL 0 /* no type info */
  283. #define T_ARG 1 /* function argument (only used by compiler) */
  284. #define T_CHAR 2 /* character */
  285. #define T_SHORT 3 /* short integer */
  286. #define T_INT 4 /* integer */
  287. #define T_LONG 5 /* long integer */
  288. #define T_FLOAT 6 /* floating point */
  289. #define T_DOUBLE 7 /* double word */
  290. #define T_STRUCT 8 /* structure */
  291. #define T_UNION 9 /* union */
  292. #define T_ENUM 10 /* enumeration */
  293. #define T_MOE 11 /* member of enumeration */
  294. #define T_UCHAR 12 /* unsigned character */
  295. #define T_USHORT 13 /* unsigned short */
  296. #define T_UINT 14 /* unsigned integer */
  297. #define T_ULONG 15 /* unsigned long */
  298. /*------------------------------------------------------------------------*/
  299. /* derived types are: */
  300. /*------------------------------------------------------------------------*/
  301. #define DT_NON 0 /* no derived type */
  302. #define DT_PTR 1 /* pointer */
  303. #define DT_FCN 2 /* function */
  304. #define DT_ARY 3 /* array */
  305. #define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \
  306. ((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\
  307. ((d4) << 10) | ((d5) << 12) | ((d6) << 14))
  308. /*------------------------------------------------------------------------*/
  309. /* type packing constants and macros */
  310. /*------------------------------------------------------------------------*/
  311. #define N_BTMASK_COFF 017
  312. #define N_TMASK_COFF 060
  313. #define N_TMASK1_COFF 0300
  314. #define N_TMASK2_COFF 0360
  315. #define N_BTSHFT_COFF 4
  316. #define N_TSHIFT_COFF 2
  317. #define BTYPE_COFF(x) ((x) & N_BTMASK_COFF)
  318. #define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \
  319. ((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM)
  320. #define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT)
  321. #define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF))
  322. #define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF))
  323. #define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF))
  324. #define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG)
  325. #define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<<N_TSHIFT_COFF)|(DT_PTR<<N_BTSHFT_COFF)|(x&N_BTMASK_COFF))
  326. #define DECREF_COFF(x) ((((x)>>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF))
  327. /*------------------------------------------------------------------------*/
  328. /* AUXILIARY SYMBOL ENTRY */
  329. /*------------------------------------------------------------------------*/
  330. union auxent
  331. {
  332. struct
  333. {
  334. long x_tagndx; /* str, un, or enum tag indx */
  335. union
  336. {
  337. struct
  338. {
  339. unsigned short x_lnno; /* declaration line number */
  340. unsigned short x_size; /* str, union, array size */
  341. } x_lnsz;
  342. long x_fsize; /* size of function */
  343. } x_misc;
  344. union
  345. {
  346. struct /* if ISFCN, tag, or .bb */
  347. {
  348. long x_lnnoptr; /* ptr to fcn line # */
  349. long x_endndx; /* entry ndx past block end */
  350. } x_fcn;
  351. struct /* if ISARY, up to 4 dimen. */
  352. {
  353. unsigned short x_dimen[DIMNUM];
  354. } x_ary;
  355. } x_fcnary;
  356. unsigned short x_regcount; /* number of registers used by func */
  357. } x_sym;
  358. struct
  359. {
  360. char x_fname[FILNMLEN];
  361. } x_file;
  362. struct
  363. {
  364. long x_scnlen; /* section length */
  365. unsigned short x_nreloc; /* number of relocation entries */
  366. unsigned short x_nlinno; /* number of line numbers */
  367. } x_scn;
  368. };
  369. #define SYMENT struct syment
  370. #define SYMESZ 18 /* sizeof(SYMENT) */
  371. #define AUXENT union auxent
  372. #define AUXESZ 18 /* sizeof(AUXENT) */
  373. /*------------------------------------------------------------------------*/
  374. /* NAMES OF "SPECIAL" SYMBOLS */
  375. /*------------------------------------------------------------------------*/
  376. #define _STEXT ".text"
  377. #define _ETEXT "etext"
  378. #define _SDATA ".data"
  379. #define _EDATA "edata"
  380. #define _SBSS ".bss"
  381. #define _END "end"
  382. #define _CINITPTR "cinit"
  383. /*--------------------------------------------------------------------------*/
  384. /* ENTRY POINT SYMBOLS */
  385. /*--------------------------------------------------------------------------*/
  386. #define _START "_start"
  387. #define _MAIN "_main"
  388. /* _CSTART "_c_int00" (defined in params.h) */
  389. #define _TVORIG "_tvorig"
  390. #define _TORIGIN "_torigin"
  391. #define _DORIGIN "_dorigin"
  392. #define _SORIGIN "_sorigin"