1181834Sroberto/* SPDX-License-Identifier: GPL-2.0 */ 2280849Scy/* IBM RS/6000 "XCOFF" file definitions for BFD. 3181834Sroberto Copyright (C) 1990, 1991 Free Software Foundation, Inc. 4181834Sroberto FIXME: Can someone provide a transliteration of this name into ASCII? 5181834Sroberto Using the following chars caused a compiler warning on HIUX (so I replaced 6280849Scy them with octal escapes), and isn't useful without an understanding of what 7280849Scy character set it is. 8280849Scy Written by Mimi Ph\373\364ng-Th\345o V\365 of IBM 9181834Sroberto and John Gilmore of Cygnus Support. */ 10280849Scy 11280849Scy/********************** FILE HEADER **********************/ 12280849Scy 13285169Scystruct external_filehdr { 14181834Sroberto char f_magic[2]; /* magic number */ 15280849Scy char f_nscns[2]; /* number of sections */ 16280849Scy char f_timdat[4]; /* time & date stamp */ 17280849Scy char f_symptr[4]; /* file pointer to symtab */ 18181834Sroberto char f_nsyms[4]; /* number of symtab entries */ 19280849Scy char f_opthdr[2]; /* sizeof(optional hdr) */ 20280849Scy char f_flags[2]; /* flags */ 21181834Sroberto}; 22280849Scy 23280849Scy /* IBM RS/6000 */ 24181834Sroberto#define U802WRMAGIC 0730 /* writeable text segments **chh** */ 25280849Scy#define U802ROMAGIC 0735 /* readonly sharable text segments */ 26181834Sroberto#define U802TOCMAGIC 0737 /* readonly text segments and TOC */ 27280849Scy 28280849Scy#define BADMAG(x) \ 29280849Scy ((x).f_magic != U802ROMAGIC && (x).f_magic != U802WRMAGIC && \ 30181834Sroberto (x).f_magic != U802TOCMAGIC) 31181834Sroberto 32181834Sroberto#define FILHDR struct external_filehdr 33181834Sroberto#define FILHSZ 20 34181834Sroberto 35285169Scy 36181834Sroberto/********************** AOUT "OPTIONAL HEADER" **********************/ 37181834Sroberto 38181834Sroberto 39181834Srobertotypedef struct 40181834Sroberto{ 41285169Scy unsigned char magic[2]; /* type of file */ 42280849Scy unsigned char vstamp[2]; /* version stamp */ 43181834Sroberto unsigned char tsize[4]; /* text size in bytes, padded to FW bdry */ 44280849Scy unsigned char dsize[4]; /* initialized data " " */ 45280849Scy unsigned char bsize[4]; /* uninitialized data " " */ 46280849Scy unsigned char entry[4]; /* entry pt. */ 47181834Sroberto unsigned char text_start[4]; /* base of text used for this file */ 48280849Scy unsigned char data_start[4]; /* base of data used for this file */ 49280849Scy unsigned char o_toc[4]; /* address of TOC */ 50280849Scy unsigned char o_snentry[2]; /* section number of entry point */ 51280849Scy unsigned char o_sntext[2]; /* section number of .text section */ 52280849Scy unsigned char o_sndata[2]; /* section number of .data section */ 53280849Scy unsigned char o_sntoc[2]; /* section number of TOC */ 54280849Scy unsigned char o_snloader[2]; /* section number of .loader section */ 55280849Scy unsigned char o_snbss[2]; /* section number of .bss section */ 56280849Scy unsigned char o_algntext[2]; /* .text alignment */ 57280849Scy unsigned char o_algndata[2]; /* .data alignment */ 58280849Scy unsigned char o_modtype[2]; /* module type (??) */ 59280849Scy unsigned char o_cputype[2]; /* cpu type */ 60280849Scy unsigned char o_maxstack[4]; /* max stack size (??) */ 61280849Scy unsigned char o_maxdata[4]; /* max data size (??) */ 62181834Sroberto unsigned char o_resv2[12]; /* reserved */ 63181834Sroberto} 64280849ScyAOUTHDR; 65280849Scy 66280849Scy#define AOUTSZ 72 67280849Scy#define SMALL_AOUTSZ (28) 68280849Scy#define AOUTHDRSZ 72 69280849Scy 70280849Scy#define RS6K_AOUTHDR_OMAGIC 0x0107 /* old: text & data writeable */ 71280849Scy#define RS6K_AOUTHDR_NMAGIC 0x0108 /* new: text r/o, data r/w */ 72280849Scy#define RS6K_AOUTHDR_ZMAGIC 0x010B /* paged: text r/o, both page-aligned */ 73280849Scy 74280849Scy 75181834Sroberto/********************** SECTION HEADER **********************/ 76280849Scy 77280849Scy 78280849Scystruct external_scnhdr { 79280849Scy char s_name[8]; /* section name */ 80280849Scy char s_paddr[4]; /* physical address, aliased s_nlib */ 81280849Scy char s_vaddr[4]; /* virtual address */ 82181834Sroberto char s_size[4]; /* section size */ 83280849Scy char s_scnptr[4]; /* file ptr to raw data for section */ 84181834Sroberto char s_relptr[4]; /* file ptr to relocation */ 85280849Scy char s_lnnoptr[4]; /* file ptr to line numbers */ 86280849Scy char s_nreloc[2]; /* number of relocation entries */ 87181834Sroberto char s_nlnno[2]; /* number of line number entries*/ 88280849Scy char s_flags[4]; /* flags */ 89280849Scy}; 90181834Sroberto 91280849Scy/* 92280849Scy * names of "special" sections 93280849Scy */ 94280849Scy#define _TEXT ".text" 95280849Scy#define _DATA ".data" 96280849Scy#define _BSS ".bss" 97181834Sroberto#define _PAD ".pad" 98280849Scy#define _LOADER ".loader" 99280849Scy 100280849Scy#define SCNHDR struct external_scnhdr 101181834Sroberto#define SCNHSZ 40 102280849Scy 103181834Sroberto/* XCOFF uses a special .loader section with type STYP_LOADER. */ 104280849Scy#define STYP_LOADER 0x1000 105280849Scy 106280849Scy/* XCOFF uses a special .debug section with type STYP_DEBUG. */ 107280849Scy#define STYP_DEBUG 0x2000 108280849Scy 109280849Scy/* XCOFF handles line number or relocation overflow by creating 110280849Scy another section header with STYP_OVRFLO set. */ 111280849Scy#define STYP_OVRFLO 0x8000 112280849Scy 113280849Scy/********************** LINE NUMBERS **********************/ 114280849Scy 115280849Scy/* 1 line number entry for every "breakpointable" source line in a section. 116181834Sroberto * Line numbers are grouped on a per function basis; first entry in a function 117280849Scy * grouping will have l_lnno = 0 and in place of physical address will be the 118280849Scy * symbol table index of the function name. 119181834Sroberto */ 120280849Scystruct external_lineno { 121280849Scy union { 122280849Scy char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/ 123280849Scy char l_paddr[4]; /* (physical) address of line number */ 124280849Scy } l_addr; 125280849Scy char l_lnno[2]; /* line number */ 126181834Sroberto}; 127280849Scy 128280849Scy 129280849Scy#define LINENO struct external_lineno 130280849Scy#define LINESZ 6 131280849Scy 132181834Sroberto 133280849Scy/********************** SYMBOLS **********************/ 134280849Scy 135280849Scy#define E_SYMNMLEN 8 /* # characters in a symbol name */ 136280849Scy#define E_FILNMLEN 14 /* # characters in a file name */ 137280849Scy#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */ 138280849Scy 139280849Scystruct external_syment 140280849Scy{ 141181834Sroberto union { 142280849Scy char e_name[E_SYMNMLEN]; 143280849Scy struct { 144280849Scy char e_zeroes[4]; 145280849Scy char e_offset[4]; 146280849Scy } e; 147280849Scy } e; 148280849Scy char e_value[4]; 149280849Scy char e_scnum[2]; 150280849Scy char e_type[2]; 151280849Scy char e_sclass[1]; 152280849Scy char e_numaux[1]; 153280849Scy}; 154280849Scy 155280849Scy 156280849Scy 157280849Scy#define N_BTMASK (017) 158280849Scy#define N_TMASK (060) 159280849Scy#define N_BTSHFT (4) 160280849Scy#define N_TSHIFT (2) 161280849Scy 162280849Scy 163280849Scyunion external_auxent { 164280849Scy struct { 165280849Scy char x_tagndx[4]; /* str, un, or enum tag indx */ 166280849Scy union { 167181834Sroberto struct { 168280849Scy char x_lnno[2]; /* declaration line number */ 169280849Scy char x_size[2]; /* str/union/array size */ 170181834Sroberto } x_lnsz; 171181834Sroberto char x_fsize[4]; /* size of function */ 172280849Scy } x_misc; 173280849Scy union { 174280849Scy struct { /* if ISFCN, tag, or .bb */ 175280849Scy char x_lnnoptr[4]; /* ptr to fcn line # */ 176280849Scy char x_endndx[4]; /* entry ndx past block end */ 177280849Scy } x_fcn; 178280849Scy struct { /* if ISARY, up to 4 dimen. */ 179181834Sroberto char x_dimen[E_DIMNUM][2]; 180181834Sroberto } x_ary; 181181834Sroberto } x_fcnary; 182181834Sroberto char x_tvndx[2]; /* tv index */ 183181834Sroberto } x_sym; 184285169Scy 185285169Scy union { 186181834Sroberto char x_fname[E_FILNMLEN]; 187181834Sroberto struct { 188181834Sroberto char x_zeroes[4]; 189181834Sroberto char x_offset[4]; 190181834Sroberto } x_n; 191280849Scy } x_file; 192181834Sroberto 193280849Scy struct { 194181834Sroberto char x_scnlen[4]; /* section length */ 195181834Sroberto char x_nreloc[2]; /* # relocation entries */ 196280849Scy char x_nlinno[2]; /* # line numbers */ 197280849Scy } x_scn; 198280849Scy 199285169Scy struct { 200285169Scy char x_tvfill[4]; /* tv fill value */ 201280849Scy char x_tvlen[2]; /* length of .tv */ 202280849Scy char x_tvran[2][2]; /* tv range */ 203280849Scy } x_tv; /* info about .tv section (in auxent of symbol .tv)) */ 204280849Scy 205280849Scy struct { 206280849Scy unsigned char x_scnlen[4]; 207280849Scy unsigned char x_parmhash[4]; 208280849Scy unsigned char x_snhash[2]; 209280849Scy unsigned char x_smtyp[1]; 210280849Scy unsigned char x_smclas[1]; 211280849Scy unsigned char x_stab[4]; 212280849Scy unsigned char x_snstab[2]; 213280849Scy } x_csect; 214181834Sroberto 215181834Sroberto}; 216181834Sroberto 217181834Sroberto#define SYMENT struct external_syment 218285169Scy#define SYMESZ 18 219285169Scy#define AUXENT union external_auxent 220181834Sroberto#define AUXESZ 18 221181834Sroberto#define DBXMASK 0x80 /* for dbx storage mask */ 222181834Sroberto#define SYMNAME_IN_DEBUG(symptr) ((symptr)->n_sclass & DBXMASK) 223181834Sroberto 224181834Sroberto 225280849Scy 226181834Sroberto/********************** RELOCATION DIRECTIVES **********************/ 227280849Scy 228181834Sroberto 229181834Srobertostruct external_reloc { 230280849Scy char r_vaddr[4]; 231280849Scy char r_symndx[4]; 232181834Sroberto char r_size[1]; 233181834Sroberto char r_type[1]; 234181834Sroberto}; 235181834Sroberto 236181834Sroberto 237181834Sroberto#define RELOC struct external_reloc 238#define RELSZ 10 239 240#define DEFAULT_DATA_SECTION_ALIGNMENT 4 241#define DEFAULT_BSS_SECTION_ALIGNMENT 4 242#define DEFAULT_TEXT_SECTION_ALIGNMENT 4 243/* For new sections we haven't heard of before */ 244#define DEFAULT_SECTION_ALIGNMENT 4 245