1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux 1 2 /* This file is derived from the GAS 2.1.4 ass 3 The GAS product is under the GNU General Pu 4 As such, this file is also under that licen 5 6 If the file format changes in the COFF obje 7 subsequently updated to reflect the changes 8 9 The actual loader module only uses a few of 10 set is documented here because I received t 11 more information about COFF, then O'Reilly 12 */ 13 14 #ifndef _UAPI_LINUX_COFF_H 15 #define _UAPI_LINUX_COFF_H 16 17 #define E_SYMNMLEN 8 /* Number of characte 18 #define E_FILNMLEN 14 /* Number of characte 19 #define E_DIMNUM 4 /* Number of array di 20 21 /* 22 * These defines are byte order independent. T 23 * permitted in the structures. Therefore they 24 * and the values loaded from the character po 25 * nice to have it "endian" independent. 26 */ 27 28 /* Load a short int from the following tables 29 #define COFF_SHORT_L(ps) ((short)(((unsigned s 30 ((unsigned s 31 32 /* Load a long int from the following tables w 33 #define COFF_LONG_L(ps) (((long)(((unsigned lo 34 ((unsigned lo 35 ((unsigned lo 36 ((unsigned lo 37 38 /* Load a short int from the following tables 39 #define COFF_SHORT_H(ps) ((short)(((unsigned s 40 ((unsigned s 41 42 /* Load a long int from the following tables w 43 #define COFF_LONG_H(ps) (((long)(((unsigned lo 44 ((unsigned lo 45 ((unsigned lo 46 ((unsigned lo 47 48 /* These may be overridden later by brain dead 49 a big-endian header with little-endian data 50 replacement macro which tests a flag and us 51 as appropriate. */ 52 53 #define COFF_LONG(v) COFF_LONG_L(v) 54 #define COFF_SHORT(v) COFF_SHORT_L(v) 55 56 /*** coff information for Intel 386/486. */ 57 58 /********************** FILE HEADER ********** 59 60 struct COFF_filehdr { 61 char f_magic[2]; /* magic numbe 62 char f_nscns[2]; /* number of s 63 char f_timdat[4]; /* time & date 64 char f_symptr[4]; /* file pointe 65 char f_nsyms[4]; /* number of s 66 char f_opthdr[2]; /* sizeof(opti 67 char f_flags[2]; /* flags 68 }; 69 70 /* 71 * Bits for f_flags: 72 * 73 * F_RELFLG relocation info stripp 74 * F_EXEC file is executable (i 75 * references) 76 * F_LNNO line numbers stripped 77 * F_LSYMS local symbols stripped 78 * F_MINMAL this is a minimal obje 79 * F_UPDATE this is a fully bound 80 * F_SWABD this file has had its 81 * F_AR16WR this file has the byte 82 * (e.g. 11/70) machine 83 * F_AR32WR this file has the byte 84 * (e.g. vax and iNTEL 38 85 * F_AR32W this file has the byte 86 * (e.g. 3b,maxi) 87 * F_PATCH file contains "patch" 88 * F_NODF (minimal file only) no 89 * replaced functions 90 */ 91 92 #define COFF_F_RELFLG 0000001 93 #define COFF_F_EXEC 0000002 94 #define COFF_F_LNNO 0000004 95 #define COFF_F_LSYMS 0000010 96 #define COFF_F_MINMAL 0000020 97 #define COFF_F_UPDATE 0000040 98 #define COFF_F_SWABD 0000100 99 #define COFF_F_AR16WR 0000200 100 #define COFF_F_AR32WR 0000400 101 #define COFF_F_AR32W 0001000 102 #define COFF_F_PATCH 0002000 103 #define COFF_F_NODF 0002000 104 105 #define COFF_I386MAGIC 0x14c /* Lin 106 107 #if 0 /* Perhaps, someday, these formats may 108 #define COFF_I386PTXMAGIC 0x154 109 #define COFF_I386AIXMAGIC 0x175 /* IBM 110 #define COFF_I386BADMAG(x) ((COFF_SHORT((x).f_ 111 && COFF_SHORT((x).f_ 112 && COFF_SHORT((x).f_ 113 #else 114 #define COFF_I386BADMAG(x) (COFF_SHORT((x).f_m 115 #endif 116 117 #define COFF_FILHDR struct COFF_filehdr 118 #define COFF_FILHSZ sizeof(COFF_FILHDR) 119 120 /********************** AOUT "OPTIONAL HEADER" 121 122 /* Linux COFF must have this "optional" header 123 location for the "entry" point. They normal 124 location of the .text section. This is not 125 the use of this "optional" header is not op 126 127 Do not be tempted to assume that the size o 128 a constant and simply index the next byte b 129 Use the 'f_opthdr' field in the main coff h 130 structure actually written to the file!! 131 */ 132 133 typedef struct 134 { 135 char magic[2]; /* type of fil 136 char vstamp[2]; /* version sta 137 char tsize[4]; /* text size i 138 char dsize[4]; /* initialized 139 char bsize[4]; /* uninitializ 140 char entry[4]; /* entry pt. 141 char text_start[4]; /* base of tex 142 char data_start[4]; /* base of dat 143 } 144 COFF_AOUTHDR; 145 146 #define COFF_AOUTSZ (sizeof(COFF_AOUTHDR)) 147 148 #define COFF_STMAGIC 0401 149 #define COFF_OMAGIC 0404 150 #define COFF_JMAGIC 0407 /* dirty text 151 #define COFF_DMAGIC 0410 /* dirty text 152 #define COFF_ZMAGIC 0413 /* The proper 153 #define COFF_SHMAGIC 0443 /* shared libr 154 155 /********************** SECTION HEADER ******* 156 157 struct COFF_scnhdr { 158 char s_name[8]; /* section nam 159 char s_paddr[4]; /* physical ad 160 char s_vaddr[4]; /* virtual add 161 char s_size[4]; /* section siz 162 char s_scnptr[4]; /* file ptr to 163 char s_relptr[4]; /* file ptr to 164 char s_lnnoptr[4]; /* file ptr to 165 char s_nreloc[2]; /* number of r 166 char s_nlnno[2]; /* number of l 167 char s_flags[4]; /* flags 168 }; 169 170 #define COFF_SCNHDR struct COFF_scnhdr 171 #define COFF_SCNHSZ sizeof(COFF_SCNHDR) 172 173 /* 174 * names of "special" sections 175 */ 176 177 #define COFF_TEXT ".text" 178 #define COFF_DATA ".data" 179 #define COFF_BSS ".bss" 180 #define COFF_COMMENT ".comment" 181 #define COFF_LIB ".lib" 182 183 #define COFF_SECT_TEXT 0 /* Section for 184 #define COFF_SECT_DATA 1 /* Section for 185 #define COFF_SECT_BSS 2 /* Section for 186 #define COFF_SECT_REQD 3 /* Minimum numb 187 188 #define COFF_STYP_REG 0x00 /* regular segm 189 #define COFF_STYP_DSECT 0x01 /* dummy segmen 190 #define COFF_STYP_NOLOAD 0x02 /* no-load segm 191 #define COFF_STYP_GROUP 0x04 /* group segmen 192 #define COFF_STYP_PAD 0x08 /* .pad segment 193 #define COFF_STYP_COPY 0x10 /* copy section 194 #define COFF_STYP_TEXT 0x20 /* .text segmen 195 #define COFF_STYP_DATA 0x40 /* .data segmen 196 #define COFF_STYP_BSS 0x80 /* .bss segment 197 #define COFF_STYP_INFO 0x200 /* .comment sec 198 #define COFF_STYP_OVER 0x400 /* overlay sect 199 #define COFF_STYP_LIB 0x800 /* library sect 200 201 /* 202 * Shared libraries have the following section 203 * each library. 204 */ 205 206 struct COFF_slib { 207 char sl_entsz[4]; /* Size of thi 208 char sl_pathndx[4]; /* size of the 209 }; 210 211 #define COFF_SLIBHD struct COFF_slib 212 #define COFF_SLIBSZ sizeof(COFF_SLIBHD) 213 214 /********************** LINE NUMBERS ********* 215 216 /* 1 line number entry for every "breakpointab 217 * Line numbers are grouped on a per function 218 * grouping will have l_lnno = 0 and in place 219 * symbol table index of the function name. 220 */ 221 222 struct COFF_lineno { 223 union { 224 char l_symndx[4]; /* function name symbo 225 char l_paddr[4]; /* (physical) address 226 } l_addr; 227 char l_lnno[2]; /* line number 228 }; 229 230 #define COFF_LINENO struct COFF_lineno 231 #define COFF_LINESZ 6 232 233 /********************** SYMBOLS ************** 234 235 #define COFF_E_SYMNMLEN 8 /* # character 236 #define COFF_E_FILNMLEN 14 /* # character 237 #define COFF_E_DIMNUM 4 /* # array dim 238 239 /* 240 * All symbols and sections have the followin 241 */ 242 243 struct COFF_syment 244 { 245 union { 246 char e_name[E_SYMNMLEN]; /* Symbol name 247 struct { 248 char e_zeroes[4]; /* Leading zer 249 char e_offset[4]; /* Offset if t 250 } e; 251 } e; 252 253 char e_value[4]; /* Value (addr 254 char e_scnum[2]; /* Section num 255 char e_type[2]; /* Type of sec 256 char e_sclass[1]; /* Loader clas 257 char e_numaux[1]; /* Number of a 258 }; 259 260 #define COFF_N_BTMASK (0xf) /* Mask for im 261 #define COFF_N_TMASK (0x30) /* Mask for im 262 #define COFF_N_BTSHFT (4) /* # bits to s 263 #define COFF_N_TSHIFT (2) /* # bits to s 264 265 /* 266 * Auxiliary entries because the main table i 267 */ 268 269 union COFF_auxent { 270 271 /* 272 * Debugger information 273 */ 274 275 struct { 276 char x_tagndx[4]; /* str, un, or 277 union { 278 struct { 279 char x_lnno[2]; /* declaration 280 char x_size[2]; /* str/union/a 281 } x_lnsz; 282 char x_fsize[4]; /* size of fun 283 } x_misc; 284 285 union { 286 struct { /* if ISFCN, t 287 char x_lnnoptr[4]; /* ptr to fcn 288 char x_endndx[4]; /* entry ndx p 289 } x_fcn; 290 291 struct { /* if ISARY, u 292 char x_dimen[E_DIMNUM][2]; 293 } x_ary; 294 } x_fcnary; 295 296 char x_tvndx[2]; /* tv index */ 297 } x_sym; 298 299 /* 300 * Source file names (debugger information) 301 */ 302 303 union { 304 char x_fname[E_FILNMLEN]; 305 struct { 306 char x_zeroes[4]; 307 char x_offset[4]; 308 } x_n; 309 } x_file; 310 311 /* 312 * Section information 313 */ 314 315 struct { 316 char x_scnlen[4]; /* section length */ 317 char x_nreloc[2]; /* # relocation entrie 318 char x_nlinno[2]; /* # line numbers */ 319 } x_scn; 320 321 /* 322 * Transfer vector (branch table) 323 */ 324 325 struct { 326 char x_tvfill[4]; /* tv fill value */ 327 char x_tvlen[2]; /* length of .tv */ 328 char x_tvran[2][2]; /* tv range */ 329 } x_tv; /* info about .tv sect 330 }; 331 332 #define COFF_SYMENT struct COFF_syment 333 #define COFF_SYMESZ 18 334 #define COFF_AUXENT union COFF_auxent 335 #define COFF_AUXESZ 18 336 337 #define COFF_ETEXT "etext" 338 339 /********************** RELOCATION DIRECTIVES 340 341 struct COFF_reloc { 342 char r_vaddr[4]; /* Virtual address o 343 char r_symndx[4]; /* Symbol index in t 344 char r_type[2]; /* Relocation type 345 }; 346 347 #define COFF_RELOC struct COFF_reloc 348 #define COFF_RELSZ 10 349 350 #define COFF_DEF_DATA_SECTION_ALIGNMENT 4 351 #define COFF_DEF_BSS_SECTION_ALIGNMENT 4 352 #define COFF_DEF_TEXT_SECTION_ALIGNMENT 4 353 354 /* For new sections we haven't heard of before 355 #define COFF_DEF_SECTION_ALIGNMENT 4 356 357 #endif /* _UAPI_LINUX_COFF_H */ 358
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.