18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* IBM RS/6000 "XCOFF" file definitions for BFD.
38c2ecf20Sopenharmony_ci   Copyright (C) 1990, 1991 Free Software Foundation, Inc.
48c2ecf20Sopenharmony_ci   FIXME: Can someone provide a transliteration of this name into ASCII?
58c2ecf20Sopenharmony_ci   Using the following chars caused a compiler warning on HIUX (so I replaced
68c2ecf20Sopenharmony_ci   them with octal escapes), and isn't useful without an understanding of what
78c2ecf20Sopenharmony_ci   character set it is.
88c2ecf20Sopenharmony_ci   Written by Mimi Ph\373\364ng-Th\345o V\365 of IBM
98c2ecf20Sopenharmony_ci   and John Gilmore of Cygnus Support.  */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/********************** FILE HEADER **********************/
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistruct external_filehdr {
148c2ecf20Sopenharmony_ci	char f_magic[2];	/* magic number			*/
158c2ecf20Sopenharmony_ci	char f_nscns[2];	/* number of sections		*/
168c2ecf20Sopenharmony_ci	char f_timdat[4];	/* time & date stamp		*/
178c2ecf20Sopenharmony_ci	char f_symptr[4];	/* file pointer to symtab	*/
188c2ecf20Sopenharmony_ci	char f_nsyms[4];	/* number of symtab entries	*/
198c2ecf20Sopenharmony_ci	char f_opthdr[2];	/* sizeof(optional hdr)		*/
208c2ecf20Sopenharmony_ci	char f_flags[2];	/* flags			*/
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci        /* IBM RS/6000 */
248c2ecf20Sopenharmony_ci#define U802WRMAGIC     0730    /* writeable text segments **chh**      */
258c2ecf20Sopenharmony_ci#define U802ROMAGIC     0735    /* readonly sharable text segments      */
268c2ecf20Sopenharmony_ci#define U802TOCMAGIC    0737    /* readonly text segments and TOC       */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define BADMAG(x)	\
298c2ecf20Sopenharmony_ci	((x).f_magic != U802ROMAGIC && (x).f_magic != U802WRMAGIC && \
308c2ecf20Sopenharmony_ci	 (x).f_magic != U802TOCMAGIC)
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define	FILHDR	struct external_filehdr
338c2ecf20Sopenharmony_ci#define	FILHSZ	20
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/********************** AOUT "OPTIONAL HEADER" **********************/
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_citypedef struct
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci  unsigned char	magic[2];	/* type of file			*/
428c2ecf20Sopenharmony_ci  unsigned char	vstamp[2];	/* version stamp		*/
438c2ecf20Sopenharmony_ci  unsigned char	tsize[4];	/* text size in bytes, padded to FW bdry */
448c2ecf20Sopenharmony_ci  unsigned char	dsize[4];	/* initialized data "  "	*/
458c2ecf20Sopenharmony_ci  unsigned char	bsize[4];	/* uninitialized data "   "	*/
468c2ecf20Sopenharmony_ci  unsigned char	entry[4];	/* entry pt.			*/
478c2ecf20Sopenharmony_ci  unsigned char	text_start[4];	/* base of text used for this file */
488c2ecf20Sopenharmony_ci  unsigned char	data_start[4];	/* base of data used for this file */
498c2ecf20Sopenharmony_ci  unsigned char	o_toc[4];	/* address of TOC */
508c2ecf20Sopenharmony_ci  unsigned char	o_snentry[2];	/* section number of entry point */
518c2ecf20Sopenharmony_ci  unsigned char	o_sntext[2];	/* section number of .text section */
528c2ecf20Sopenharmony_ci  unsigned char	o_sndata[2];	/* section number of .data section */
538c2ecf20Sopenharmony_ci  unsigned char	o_sntoc[2];	/* section number of TOC */
548c2ecf20Sopenharmony_ci  unsigned char	o_snloader[2];	/* section number of .loader section */
558c2ecf20Sopenharmony_ci  unsigned char	o_snbss[2];	/* section number of .bss section */
568c2ecf20Sopenharmony_ci  unsigned char	o_algntext[2];	/* .text alignment */
578c2ecf20Sopenharmony_ci  unsigned char	o_algndata[2];	/* .data alignment */
588c2ecf20Sopenharmony_ci  unsigned char	o_modtype[2];	/* module type (??) */
598c2ecf20Sopenharmony_ci  unsigned char o_cputype[2];	/* cpu type */
608c2ecf20Sopenharmony_ci  unsigned char	o_maxstack[4];	/* max stack size (??) */
618c2ecf20Sopenharmony_ci  unsigned char o_maxdata[4];	/* max data size (??) */
628c2ecf20Sopenharmony_ci  unsigned char	o_resv2[12];	/* reserved */
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ciAOUTHDR;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define AOUTSZ 72
678c2ecf20Sopenharmony_ci#define SMALL_AOUTSZ (28)
688c2ecf20Sopenharmony_ci#define AOUTHDRSZ 72
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define	RS6K_AOUTHDR_OMAGIC	0x0107	/* old: text & data writeable */
718c2ecf20Sopenharmony_ci#define	RS6K_AOUTHDR_NMAGIC	0x0108	/* new: text r/o, data r/w */
728c2ecf20Sopenharmony_ci#define	RS6K_AOUTHDR_ZMAGIC	0x010B	/* paged: text r/o, both page-aligned */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/********************** SECTION HEADER **********************/
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistruct external_scnhdr {
798c2ecf20Sopenharmony_ci	char		s_name[8];	/* section name			*/
808c2ecf20Sopenharmony_ci	char		s_paddr[4];	/* physical address, aliased s_nlib */
818c2ecf20Sopenharmony_ci	char		s_vaddr[4];	/* virtual address		*/
828c2ecf20Sopenharmony_ci	char		s_size[4];	/* section size			*/
838c2ecf20Sopenharmony_ci	char		s_scnptr[4];	/* file ptr to raw data for section */
848c2ecf20Sopenharmony_ci	char		s_relptr[4];	/* file ptr to relocation	*/
858c2ecf20Sopenharmony_ci	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
868c2ecf20Sopenharmony_ci	char		s_nreloc[2];	/* number of relocation entries	*/
878c2ecf20Sopenharmony_ci	char		s_nlnno[2];	/* number of line number entries*/
888c2ecf20Sopenharmony_ci	char		s_flags[4];	/* flags			*/
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/*
928c2ecf20Sopenharmony_ci * names of "special" sections
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ci#define _TEXT	".text"
958c2ecf20Sopenharmony_ci#define _DATA	".data"
968c2ecf20Sopenharmony_ci#define _BSS	".bss"
978c2ecf20Sopenharmony_ci#define _PAD	".pad"
988c2ecf20Sopenharmony_ci#define _LOADER	".loader"
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define	SCNHDR	struct external_scnhdr
1018c2ecf20Sopenharmony_ci#define	SCNHSZ	40
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* XCOFF uses a special .loader section with type STYP_LOADER.  */
1048c2ecf20Sopenharmony_ci#define STYP_LOADER 0x1000
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* XCOFF uses a special .debug section with type STYP_DEBUG.  */
1078c2ecf20Sopenharmony_ci#define STYP_DEBUG 0x2000
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* XCOFF handles line number or relocation overflow by creating
1108c2ecf20Sopenharmony_ci   another section header with STYP_OVRFLO set.  */
1118c2ecf20Sopenharmony_ci#define STYP_OVRFLO 0x8000
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/********************** LINE NUMBERS **********************/
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* 1 line number entry for every "breakpointable" source line in a section.
1168c2ecf20Sopenharmony_ci * Line numbers are grouped on a per function basis; first entry in a function
1178c2ecf20Sopenharmony_ci * grouping will have l_lnno = 0 and in place of physical address will be the
1188c2ecf20Sopenharmony_ci * symbol table index of the function name.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_cistruct external_lineno {
1218c2ecf20Sopenharmony_ci	union {
1228c2ecf20Sopenharmony_ci		char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
1238c2ecf20Sopenharmony_ci		char l_paddr[4];	/* (physical) address of line number	*/
1248c2ecf20Sopenharmony_ci	} l_addr;
1258c2ecf20Sopenharmony_ci	char l_lnno[2];	/* line number		*/
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define	LINENO	struct external_lineno
1308c2ecf20Sopenharmony_ci#define	LINESZ	6
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/********************** SYMBOLS **********************/
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
1368c2ecf20Sopenharmony_ci#define E_FILNMLEN	14	/* # characters in a file name		*/
1378c2ecf20Sopenharmony_ci#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistruct external_syment
1408c2ecf20Sopenharmony_ci{
1418c2ecf20Sopenharmony_ci  union {
1428c2ecf20Sopenharmony_ci    char e_name[E_SYMNMLEN];
1438c2ecf20Sopenharmony_ci    struct {
1448c2ecf20Sopenharmony_ci      char e_zeroes[4];
1458c2ecf20Sopenharmony_ci      char e_offset[4];
1468c2ecf20Sopenharmony_ci    } e;
1478c2ecf20Sopenharmony_ci  } e;
1488c2ecf20Sopenharmony_ci  char e_value[4];
1498c2ecf20Sopenharmony_ci  char e_scnum[2];
1508c2ecf20Sopenharmony_ci  char e_type[2];
1518c2ecf20Sopenharmony_ci  char e_sclass[1];
1528c2ecf20Sopenharmony_ci  char e_numaux[1];
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define N_BTMASK	(017)
1588c2ecf20Sopenharmony_ci#define N_TMASK		(060)
1598c2ecf20Sopenharmony_ci#define N_BTSHFT	(4)
1608c2ecf20Sopenharmony_ci#define N_TSHIFT	(2)
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciunion external_auxent {
1648c2ecf20Sopenharmony_ci	struct {
1658c2ecf20Sopenharmony_ci		char x_tagndx[4];	/* str, un, or enum tag indx */
1668c2ecf20Sopenharmony_ci		union {
1678c2ecf20Sopenharmony_ci			struct {
1688c2ecf20Sopenharmony_ci			    char  x_lnno[2]; /* declaration line number */
1698c2ecf20Sopenharmony_ci			    char  x_size[2]; /* str/union/array size */
1708c2ecf20Sopenharmony_ci			} x_lnsz;
1718c2ecf20Sopenharmony_ci			char x_fsize[4];	/* size of function */
1728c2ecf20Sopenharmony_ci		} x_misc;
1738c2ecf20Sopenharmony_ci		union {
1748c2ecf20Sopenharmony_ci			struct {		/* if ISFCN, tag, or .bb */
1758c2ecf20Sopenharmony_ci			    char x_lnnoptr[4];	/* ptr to fcn line # */
1768c2ecf20Sopenharmony_ci			    char x_endndx[4];	/* entry ndx past block end */
1778c2ecf20Sopenharmony_ci			} x_fcn;
1788c2ecf20Sopenharmony_ci			struct {		/* if ISARY, up to 4 dimen. */
1798c2ecf20Sopenharmony_ci			    char x_dimen[E_DIMNUM][2];
1808c2ecf20Sopenharmony_ci			} x_ary;
1818c2ecf20Sopenharmony_ci		} x_fcnary;
1828c2ecf20Sopenharmony_ci		char x_tvndx[2];		/* tv index */
1838c2ecf20Sopenharmony_ci	} x_sym;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	union {
1868c2ecf20Sopenharmony_ci		char x_fname[E_FILNMLEN];
1878c2ecf20Sopenharmony_ci		struct {
1888c2ecf20Sopenharmony_ci			char x_zeroes[4];
1898c2ecf20Sopenharmony_ci			char x_offset[4];
1908c2ecf20Sopenharmony_ci		} x_n;
1918c2ecf20Sopenharmony_ci	} x_file;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	struct {
1948c2ecf20Sopenharmony_ci		char x_scnlen[4];			/* section length */
1958c2ecf20Sopenharmony_ci		char x_nreloc[2];	/* # relocation entries */
1968c2ecf20Sopenharmony_ci		char x_nlinno[2];	/* # line numbers */
1978c2ecf20Sopenharmony_ci	} x_scn;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci        struct {
2008c2ecf20Sopenharmony_ci		char x_tvfill[4];	/* tv fill value */
2018c2ecf20Sopenharmony_ci		char x_tvlen[2];	/* length of .tv */
2028c2ecf20Sopenharmony_ci		char x_tvran[2][2];	/* tv range */
2038c2ecf20Sopenharmony_ci	} x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	struct {
2068c2ecf20Sopenharmony_ci		unsigned char x_scnlen[4];
2078c2ecf20Sopenharmony_ci		unsigned char x_parmhash[4];
2088c2ecf20Sopenharmony_ci		unsigned char x_snhash[2];
2098c2ecf20Sopenharmony_ci		unsigned char x_smtyp[1];
2108c2ecf20Sopenharmony_ci		unsigned char x_smclas[1];
2118c2ecf20Sopenharmony_ci		unsigned char x_stab[4];
2128c2ecf20Sopenharmony_ci		unsigned char x_snstab[2];
2138c2ecf20Sopenharmony_ci	} x_csect;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci#define	SYMENT	struct external_syment
2188c2ecf20Sopenharmony_ci#define	SYMESZ	18
2198c2ecf20Sopenharmony_ci#define	AUXENT	union external_auxent
2208c2ecf20Sopenharmony_ci#define	AUXESZ	18
2218c2ecf20Sopenharmony_ci#define DBXMASK 0x80		/* for dbx storage mask */
2228c2ecf20Sopenharmony_ci#define SYMNAME_IN_DEBUG(symptr) ((symptr)->n_sclass & DBXMASK)
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/********************** RELOCATION DIRECTIVES **********************/
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_cistruct external_reloc {
2308c2ecf20Sopenharmony_ci  char r_vaddr[4];
2318c2ecf20Sopenharmony_ci  char r_symndx[4];
2328c2ecf20Sopenharmony_ci  char r_size[1];
2338c2ecf20Sopenharmony_ci  char r_type[1];
2348c2ecf20Sopenharmony_ci};
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci#define RELOC struct external_reloc
2388c2ecf20Sopenharmony_ci#define RELSZ 10
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci#define DEFAULT_DATA_SECTION_ALIGNMENT 4
2418c2ecf20Sopenharmony_ci#define DEFAULT_BSS_SECTION_ALIGNMENT 4
2428c2ecf20Sopenharmony_ci#define DEFAULT_TEXT_SECTION_ALIGNMENT 4
2438c2ecf20Sopenharmony_ci/* For new sections we haven't heard of before */
2448c2ecf20Sopenharmony_ci#define DEFAULT_SECTION_ALIGNMENT 4
245