Initial commit

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
Jeremy Kerr 2012-04-23 17:18:34 +08:00
commit 3b802fe3da
56 changed files with 11469 additions and 0 deletions

4
.gitmodules vendored Normal file
View file

@ -0,0 +1,4 @@
[submodule "lib/ccan"]
path = lib/ccan
url = git://git.ozlabs.org/~ccan/ccan
ignore = all

31
Makefile Normal file
View file

@ -0,0 +1,31 @@
CC = gcc
CPPFLAGS = -I. $(ccan_includes)
CFLAGS = -Wall -Werror -Wextra -ggdb --std=c99
LDFLAGS = -fwhole-program
sbsigntool_objs = sbsigntool.o idc.o image.o
sbverify_objs = sbverify.o image.o
libs = -lbfd -lcrypto
ccan_objs = lib/ccan/libccan.a
ccan_includes = -I./lib/ccan
all: sbsigntool sbverify
sbsigntool: $(sbsigntool_objs) $(ccan_objs)
$(LINK.o) -o $@ $^ $(libs)
sbverify: $(sbverify_objs) $(ccan_objs)
$(LINK.o) -o $@ $^ $(libs)
gen-keyfiles: gen-keyfiles.o $(ccan_objs)
$(LINK.o) -o $@ $^ $(libs)
gen-keyfiles: libs = -luuid
$(ccan_objs):
cd $(@D) && $(MAKE)
clean:
rm -f sbsigntool
rm -f *.o

348
coff/ChangeLog Normal file
View file

@ -0,0 +1,348 @@
2011-06-02 Nick Clifton <nickc@redhat.com>
* i860.h: Fix spelling mistake in comment.
2011-05-04 Tristan Gingold <gingold@adacore.com>
* rs6000.h (union external_auxent): Add x_ftype field.
* rs6k64.h: (struct external_auxent): Remap x_file field.
2011-05-04 Tristan Gingold <gingold@adacore.com>
* rs6000.h (struct external_exceptab): New struct.
(EXCEPTSZ): New macro.
* rs6k64.h: (struct external_exceptab): New struct.
(EXCEPTSZ): New macro.
2011-05-03 Tristan Gingold <gingold@adacore.com>
* rs6000.h (struct external_ldsym): Use E_SYMNMLEN instead of
SYMNMLEN.
2011-04-27 Tristan Gingold <gingold@adacore.com>
* xcoff.h (F_FDPR_PROF, F_FDPR_OPTI, F_DSA, F_VARPG)
(STYP_DWARF, SSUBTYP_DWINFO)
(SSUBTYP_DWLINE, SSUBTYP_DWPBNMS, SSUBTYP_DWPBTYP)
(SSUBTYP_DWARNGE, SSUBTYP_DWABREV, SSUBTYP_DWSTR)
(SSUBTYP_DWRNGES, STYP_TDATA, STYP_TBSS, R_TLS, R_TLS_IE)
(R_TLS_LD, R_TLS_LE, R_TLSM, R_TLSML, R_TOCU, R_TOCL, C_DWARF):
New macros.
2011-03-31 Tristan Gingold <gingold@adacore.com>
* internal.h (C_NULL_VALUE): Define.
2010-06-29 Alan Modra <amodra@gmail.com>
* maxq.h: Delete file.
2010-04-15 Nick Clifton <nickc@redhat.com>
* alpha.h: Update copyright notice to use GPLv3.
* apollo.h: Likewise.
* arm.h: Likewise.
* aux-coff.h: Likewise.
* ecoff.h: Likewise.
* external.h: Likewise.
* go32exe.h: Likewise.
* h8300.h: Likewise.
* h8500.h: Likewise.
* i386.h: Likewise.
* i860.h: Likewise.
* i960.h: Likewise.
* ia64.h: Likewise.
* internal.h: Likewise.
* m68k.h: Likewise.
* m88k.h: Likewise.
* maxq.h: Likewise.
* mcore.h: Likewise.
* mips.h: Likewise.
* mipspe.h: Likewise.
* or32.h: Likewise.
* pe.h: Likewise.
* powerpc.h: Likewise.
* rs6000.h: Likewise.
* rs6k64.h: Likewise.
* sh.h: Likewise.
* sparc.h: Likewise.
* ti.h: Likewise.
* tic30.h: Likewise.
* tic4x.h: Likewise.
* tic54x.h: Likewise.
* tic80.h: Likewise.
* w65.h: Likewise.
* we32k.h: Likewise.
* x86_64.h: Likewise.
* xcoff.h: Likewise.
* z80.h: Likewise.
* z8k.h: Likewise.
2009-12-02 Jerker Bäck <jerker.back@gmail.com>
PR binutils/11017
* i386lh (COFF_PAGE_SIZE): Define.
* x86_64.h (COFF_PAGE_SIZE): Define.
2009-10-17 Arnold Metselaar <arnold.metselaar@planet.nl>
* z80.h: Store alignment requirement in section header, to allow
ld to preserve alignment. Some code was copied from ti.h.
2009-09-05 Martin Thuresson <martin@mtme.org>
* ti.h (GET_LNSZ_SIZE, PUT_LNSZ_SIZE): Updated name of class
variable to in_class to match changes in function that use this
macro.
2009-08-10 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix references past allocated memory for i386-*-go32.
* ti.h (COFF_ADJUST_FILEHDR_IN_POST, COFF_ADJUST_FILEHDR_OUT_POST):
Reference F_TARGET_ID only when !COFF0_P.
2009-08-10 Jan Kratochvil <jan.kratochvil@redhat.com>
Stop using bfd_usrdata in libbfd.
* go32exe.h (struct external_filehdr_go32_exe <stub>, FILHSZ): Replace
STUBSIZE by GO32_STUBSIZE.
(STUBSIZE): Move the definition ...
* internal.h (GO32_STUBSIZE): ... here and rename it.
(struct internal_filehdr <go32stub>, F_GO32STUB): New.
2009-06-03 Ulrich Weigand <uweigand@de.ibm.com>
* symconst.h (btLong64, btULong64, btLongLong64, btULongLong64,
btAdr64, btInt64, btUInt64): New defines.
2009-04-21 Kai Tietz <kai.tietz@onevision.com>
* pe.h (pex64_runtime_function): New structure.
(external_pex64_runtime_function): Likewise.
(pex64_unwind_code): Likewise.
(external_pex64_unwind_code): Likewise.
(pex64_unwind_info): Likewise.
(external_pex64_unwind_info): Likewise.
(external_pex64_scope): Likewise.
(pex64_scope): Likewise.
(pex64_scope_entry): Likewise.
(external_pex64_scope_entry): Likewise.
(PEX64_IS_RUNTIME_FUNCTION_CHAINED): New macro.
(PEX64_GET_UNWINDDATA_UNIFIED_RVA): Likewise.
(PEX64_UNWCODE_CODE): Likewise.
(PEX64_UNWCODE_INFO): Likewise.
(UWOP_...): Add defines for unwind code.
(UNW_FLAG_...): Add defined for unwind info flags.
(PEX64_SCOPE_ENTRY_SIZE): New macro.
(PEX64_UWI_VERSION): Likewise.
(PEX64_UWI_FLAGS): Likewise.
(PEX64_UWI_FRAMEREG): Likewise.
(PEX64_UWI_FRAMEOFF): Likewise.
(PEX64_UWI_SIZEOF_UWCODE_ARRAY): Likewise.
(PEX64_OFFSET_TO_UNWIND_CODE): Likewise.
(PEX64_OFFSET_TO_HANDLER_RVA): Likewise.
(PEX64_OFFSET_TO_SCOPE_COUNT): Likewise.
(PEX64_SCOPE_ENTRY): Likewise.
2009-04-17 H.J. Lu <hongjiu.lu@intel.com>
* pe.h (IMAGE_SUBSYSTEM_EFI_ROM): Renamed to ...
(IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER): This.
2009-04-01 Richard Sandiford <r.sandiford@uk.ibm.com>
* xcoff.h (xcoff_link_hash_table): Move to bfd/xcofflink.c.
2009-03-14 Richard Sandiford <r.sandiford@uk.ibm.com>
* xcoff.h (XCOFF_EXPALL, XCOFF_EXPFULL): New flags.
(xcoff_loader_info): Add auto_export_flags.
2009-03-14 Richard Sandiford <r.sandiford@uk.ibm.com>
* internal.h (C_AIX_WEAKEXT): New macro.
(C_WEAKEXT): Use the GNU definition in the generic part of the file,
and conditionally reset it to C_AIX_WEAKEXT in the XCOFF part of
the file.
(CSECT_SYM_P): New macro.
* xcoff.h (L_WEAK): Define.
(EXTERN_SYM_P): New macro.
2009-03-14 Richard Sandiford <r.sandiford@uk.ibm.com>
* xcoff.h (XCOFF_ALLOCATED): New flag.
2009-03-14 Richard Sandiford <r.sandiford@uk.ibm.com>
* xcoff.h (XCOFF_CALLED, XCOFF_IMPORT): Update comments.
(XCOFF_WAS_UNDEFINED): New flag.
(xcoff_link_hash_table): Add an "rtld" field.
2009-03-14 Dave Korn <dave.korn.cygwin@gmail.com>
* internal.h (struct internal_extra_pe_aouthdr): Correct type
of DllCharacteristics flags field to unsigned.
* pe.h (IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE,
IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE,
IMAGE_DLL_CHARACTERISTICS_NX_COMPAT,
IMAGE_DLLCHARACTERISTICS_NO_ISOLATION,
IMAGE_DLLCHARACTERISTICS_NO_SEH,
IMAGE_DLLCHARACTERISTICS_NO_BIND,
IMAGE_DLLCHARACTERISTICS_WDM_DRIVER,
IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE): New macros to
define flag bit values for DllCharacteristics field of PEAOUTHDR,
PEPAOUTHDR.
2008-12-23 Johan Olmutz Nielsen <jnielsen@ddci.com>
* ti.h (COFF_ADJUST_SCNHDR_OUT_PRE): Define.
2008-06-17 Nick Clifton <nickc@redhat.com>
* ti.h (GET_SCNHDR_NLNNO): Provide an alternative version of this
macro which does not trigger an array bounds warning in gcc.
(PUT_SCNHDR_NLNNO): Likewise.
(GET_SCNHDR_FLAGS): Likewise.
(PUT_SCNHDR_FLAGS): Likewise.
(GET_SCNHDR_PAGE): Likewise.
(PUT_SCNHDR_PAGE): Likewise.
2007-11-05 Danny Smith <dannysmith@users.sourceforge.net>
* pe.h (COFF_ENCODE_ALIGNMENT) Define.
2007-08-02 H.J. Lu <hongjiu.lu@intel.com>
* pe.h (IMAGE_SCN_ALIGN_POWER_BIT_POS): New.
(IMAGE_SCN_ALIGN_POWER_BIT_MASK): Likewise.
(IMAGE_SCN_ALIGN_POWER_NUM): Likewise.
(IMAGE_SCN_ALIGN_POWER_CONST): Likewise.
(IMAGE_SCN_ALIGN_128BYTES): Likewise.
(IMAGE_SCN_ALIGN_256BYTES): Likewise.
(IMAGE_SCN_ALIGN_512BYTES): Likewise.
(IMAGE_SCN_ALIGN_1024BYTES): Likewise.
(IMAGE_SCN_ALIGN_2048BYTES): Likewise.
(IMAGE_SCN_ALIGN_4096BYTES): Likewise.
(IMAGE_SCN_ALIGN_8192BYTES): Likewise.
(IMAGE_SCN_ALIGN_1BYTES): Redefined with
IMAGE_SCN_ALIGN_POWER_CONST.
(IMAGE_SCN_ALIGN_2BYTES): Likewise.
(IMAGE_SCN_ALIGN_4BYTES): Likewise.
(IMAGE_SCN_ALIGN_8BYTES): Likewise.
(IMAGE_SCN_ALIGN_16BYTES): Likewise.
(IMAGE_SCN_ALIGN_32BYTES): Likewise.
(IMAGE_SCN_ALIGN_64BYTES): Likewise.
2007-07-12 Kai Tietz <kai.tietz@onevision.com>
* internal.h (struct internal_syment): Use bfd_hostptr_t for
_n_zeroes and _n_offset fields.
2007-04-27 Alan Modra <amodra@bigpond.net.au>
* rs6000.h: Write Mimi's name in ASCII.
2007-03-19 H.J. Lu <hongjiu.lu@intel.com>
* internal.h (internal_extra_pe_aouthdr): Add Magic,
MajorLinkerVersion, MinorLinkerVersion, SizeOfCode,
SizeOfInitializedData, SizeOfUninitializedData,
AddressOfEntryPoint, BaseOfCode and BaseOfData.
2006-12-05 Michael Tautschnig <tautschn@model.in.tum.de>
Nick Clifton <nickc@redhat.com>
* external.h (struct external_aouthdr): Add ATTRIBUTE_PACKED.
(struct external_syment): Likewise.
(union external_auxent): Likewise.
2006-11-14 Phil Lello <phil.lello@homecall.co.uk>
* pe.h: Added defines for IMAGE_SUBSYSTEM_EFI_ROM and
IMAGE_SUBSYSTEM_XBOX.
* internal.h: Added defines for PE directory entry types.
NB: in internal.h because IMAGE_NUMBEROF_DIRECTORY_ENTRYIES is in
pe.h
2006-09-20 Kai Tietz <Kai.Tietz@onevision.com>
* external.h: Add proper external_aouthdr64 structure (without
data_start member).
(AOUTHDRSZ64): Set according structure size.
(AOUTHDR64): As typedef of external_aouthdr64 structure.
* internal.h: Add relocation identifiers for coff.
* pe.h: Add define IMAGE_FILE_MACHINE_AMD64 the coff signature.
(PEPAOUTHDR): Adjust structure to have proper size (using AOUTHDR64).
(PEPAOUTSZ): Calculated size of 240.
* x86_64.h: Coff information for x86_64 (AMD64).
2006-02-05 Arnold Metselaar <arnold.metselaar@planet.nl>
* internal.h: Add relocation number R_IMM24 for Z80.
2005-10-25 Arnold Metselaar <arnold.metselaar@planet.nl>
* internal.h: Add relocation number for Z80
* z80.h: New file.
2005-08-18 Alan Modra <amodra@bigpond.net.au>
* a29k.h: Delete.
2005-07-14 Daniel Marques <marques@cs.cornell.edu>
* alpha.h (ALPHA_ECOFF_COMPRESSEDMAG): Define.
* ecoff.h (ALPHA_MAGIC_COMPRESSED): Define.
2005-05-10 Nick Clifton <nickc@redhat.com>
* Update the address and phone number of the FSF organization in
the GPL notices in the following files:
a29k.h, alpha.h, apollo.h, arm.h, aux-coff.h, ecoff.h, external.h,
go32exe.h, h8300.h, h8500.h, i386.h, i860.h, i960.h, ia64.h,
internal.h, m68k.h, m88k.h, maxq.h, mcore.h, mips.h, mipspe.h,
or32.h, pe.h, powerpc.h, rs6k64.h, sh.h, sparc.h, ti.h, tic30.h,
tic4x.h, tic54x.h, tic80.h, w65.h, we32k.h, xcoff.h, z8k.h
2005-02-21 Alan Modra <amodra@bigpond.net.au>
* xcoff.h (struct xcoff_loader_info): Warning fix.
2005-01-10 Inderpreet Singh <inderpreetb@noida.hcltech.com>
* maxq.h (F_MAXQ10, F_MAXQ20): Define.
2004-11-08 Inderpreet Singh <inderpreetb@nioda.hcltech.com>
Vineet Sharma <vineets@noida.hcltech.com>
* maxq.h: New file: Defintions for the maxq port.
2004-11-08 Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>
* pe.h (IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY): Define.
(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY): Same.
(IMAGE_WEAK_EXTERN_SEARCH_ALIAS): Same.
2004-08-13 Mark Kettenis <kettenis@gnu.org>
* symconst.h (langMax): Fix typo in comment.
2004-04-23 Chris Demetriou <cgd@broadcom.com>
* mips.h (MIPS_R_RELHI, MIPS_R_RELLO, MIPS_R_SWITCH): Remove
(MIPS_R_PCREL16): Update comment.
* ecoff.h (struct ecoff_value_adjust): Remove structure.
(struct ecoff_debug_info): Remove 'adjust' member.
2004-04-20 DJ Delorie <dj@redhat.com>
* internal.h (R_SECREL32): Add.
For older changes see ChangeLog-9103
Local Variables:
mode: change-log
left-margin: 8
fill-column: 74
version-control: never
End:

1177
coff/ChangeLog-9103 Normal file

File diff suppressed because it is too large Load diff

386
coff/alpha.h Normal file
View file

@ -0,0 +1,386 @@
/* ECOFF support on Alpha machines.
coff/ecoff.h must be included before this file.
Copyright 2001, 2005, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/********************** FILE HEADER **********************/
struct external_filehdr
{
unsigned char f_magic[2]; /* magic number */
unsigned char f_nscns[2]; /* number of sections */
unsigned char f_timdat[4]; /* time & date stamp */
unsigned char f_symptr[8]; /* file pointer to symtab */
unsigned char f_nsyms[4]; /* number of symtab entries */
unsigned char f_opthdr[2]; /* sizeof(optional hdr) */
unsigned char f_flags[2]; /* flags */
};
/* Magic numbers are defined in coff/ecoff.h. */
#define ALPHA_ECOFF_BADMAG(x) \
((x).f_magic != ALPHA_MAGIC && (x).f_magic != ALPHA_MAGIC_BSD)
#define ALPHA_ECOFF_COMPRESSEDMAG(x) \
((x).f_magic == ALPHA_MAGIC_COMPRESSED)
/* The object type is encoded in the f_flags. */
#define F_ALPHA_OBJECT_TYPE_MASK 0x3000
#define F_ALPHA_NO_SHARED 0x1000
#define F_ALPHA_SHARABLE 0x2000
#define F_ALPHA_CALL_SHARED 0x3000
#define FILHDR struct external_filehdr
#define FILHSZ 24
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct external_aouthdr
{
unsigned char magic[2]; /* type of file */
unsigned char vstamp[2]; /* version stamp */
unsigned char bldrev[2]; /* ?? */
unsigned char padding[2]; /* pad to quadword boundary */
unsigned char tsize[8]; /* text size in bytes */
unsigned char dsize[8]; /* initialized data " " */
unsigned char bsize[8]; /* uninitialized data " " */
unsigned char entry[8]; /* entry pt. */
unsigned char text_start[8]; /* base of text used for this file */
unsigned char data_start[8]; /* base of data used for this file */
unsigned char bss_start[8]; /* base of bss used for this file */
unsigned char gprmask[4]; /* bitmask of general registers used */
unsigned char fprmask[4]; /* bitmask of floating point registers used */
unsigned char gp_value[8]; /* value for gp register */
} AOUTHDR;
/* compute size of a header */
#define AOUTSZ 80
#define AOUTHDRSZ 80
/********************** SECTION HEADER **********************/
struct external_scnhdr
{
unsigned char s_name[8]; /* section name */
unsigned char s_paddr[8]; /* physical address, aliased s_nlib */
unsigned char s_vaddr[8]; /* virtual address */
unsigned char s_size[8]; /* section size */
unsigned char s_scnptr[8]; /* file ptr to raw data for section */
unsigned char s_relptr[8]; /* file ptr to relocation */
unsigned char s_lnnoptr[8]; /* file ptr to line numbers */
unsigned char s_nreloc[2]; /* number of relocation entries */
unsigned char s_nlnno[2]; /* number of line number entries*/
unsigned char s_flags[4]; /* flags */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 64
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
unsigned char r_vaddr[8];
unsigned char r_symndx[4];
unsigned char r_bits[4];
};
#define RELOC struct external_reloc
#define RELSZ 16
/* Constants to unpack the r_bits field. The Alpha seems to always be
little endian, so I haven't bothered to define big endian variants
of these. */
#define RELOC_BITS0_TYPE_LITTLE 0xff
#define RELOC_BITS0_TYPE_SH_LITTLE 0
#define RELOC_BITS1_EXTERN_LITTLE 0x01
#define RELOC_BITS1_OFFSET_LITTLE 0x7e
#define RELOC_BITS1_OFFSET_SH_LITTLE 1
#define RELOC_BITS1_RESERVED_LITTLE 0x80
#define RELOC_BITS1_RESERVED_SH_LITTLE 7
#define RELOC_BITS2_RESERVED_LITTLE 0xff
#define RELOC_BITS2_RESERVED_SH_LEFT_LITTLE 1
#define RELOC_BITS3_RESERVED_LITTLE 0x03
#define RELOC_BITS3_RESERVED_SH_LEFT_LITTLE 9
#define RELOC_BITS3_SIZE_LITTLE 0xfc
#define RELOC_BITS3_SIZE_SH_LITTLE 2
/* The r_type field in a reloc is one of the following values. */
#define ALPHA_R_IGNORE 0
#define ALPHA_R_REFLONG 1
#define ALPHA_R_REFQUAD 2
#define ALPHA_R_GPREL32 3
#define ALPHA_R_LITERAL 4
#define ALPHA_R_LITUSE 5
#define ALPHA_R_GPDISP 6
#define ALPHA_R_BRADDR 7
#define ALPHA_R_HINT 8
#define ALPHA_R_SREL16 9
#define ALPHA_R_SREL32 10
#define ALPHA_R_SREL64 11
#define ALPHA_R_OP_PUSH 12
#define ALPHA_R_OP_STORE 13
#define ALPHA_R_OP_PSUB 14
#define ALPHA_R_OP_PRSHIFT 15
#define ALPHA_R_GPVALUE 16
#define ALPHA_R_GPRELHIGH 17
#define ALPHA_R_GPRELLOW 18
#define ALPHA_R_IMMED 19
/* Overloaded reloc value used by Net- and OpenBSD. */
#define ALPHA_R_LITERALSLEAZY 17
/* With ALPHA_R_LITUSE, the r_size field is one of the following values. */
#define ALPHA_R_LU_BASE 1
#define ALPHA_R_LU_BYTOFF 2
#define ALPHA_R_LU_JSR 3
/* With ALPHA_R_IMMED, the r_size field is one of the following values. */
#define ALPHA_R_IMMED_GP_16 1
#define ALPHA_R_IMMED_GP_HI32 2
#define ALPHA_R_IMMED_SCN_HI32 3
#define ALPHA_R_IMMED_BR_HI32 4
#define ALPHA_R_IMMED_LO32 5
/********************** SYMBOLIC INFORMATION **********************/
/* Written by John Gilmore. */
/* ECOFF uses COFF-like section structures, but its own symbol format.
This file defines the symbol format in fields whose size and alignment
will not vary on different host systems. */
/* File header as a set of bytes */
struct hdr_ext
{
unsigned char h_magic[2];
unsigned char h_vstamp[2];
unsigned char h_ilineMax[4];
unsigned char h_idnMax[4];
unsigned char h_ipdMax[4];
unsigned char h_isymMax[4];
unsigned char h_ioptMax[4];
unsigned char h_iauxMax[4];
unsigned char h_issMax[4];
unsigned char h_issExtMax[4];
unsigned char h_ifdMax[4];
unsigned char h_crfd[4];
unsigned char h_iextMax[4];
unsigned char h_cbLine[8];
unsigned char h_cbLineOffset[8];
unsigned char h_cbDnOffset[8];
unsigned char h_cbPdOffset[8];
unsigned char h_cbSymOffset[8];
unsigned char h_cbOptOffset[8];
unsigned char h_cbAuxOffset[8];
unsigned char h_cbSsOffset[8];
unsigned char h_cbSsExtOffset[8];
unsigned char h_cbFdOffset[8];
unsigned char h_cbRfdOffset[8];
unsigned char h_cbExtOffset[8];
};
/* File descriptor external record */
struct fdr_ext
{
unsigned char f_adr[8];
unsigned char f_cbLineOffset[8];
unsigned char f_cbLine[8];
unsigned char f_cbSs[8];
unsigned char f_rss[4];
unsigned char f_issBase[4];
unsigned char f_isymBase[4];
unsigned char f_csym[4];
unsigned char f_ilineBase[4];
unsigned char f_cline[4];
unsigned char f_ioptBase[4];
unsigned char f_copt[4];
unsigned char f_ipdFirst[4];
unsigned char f_cpd[4];
unsigned char f_iauxBase[4];
unsigned char f_caux[4];
unsigned char f_rfdBase[4];
unsigned char f_crfd[4];
unsigned char f_bits1[1];
unsigned char f_bits2[3];
unsigned char f_padding[4];
};
#define FDR_BITS1_LANG_BIG 0xF8
#define FDR_BITS1_LANG_SH_BIG 3
#define FDR_BITS1_LANG_LITTLE 0x1F
#define FDR_BITS1_LANG_SH_LITTLE 0
#define FDR_BITS1_FMERGE_BIG 0x04
#define FDR_BITS1_FMERGE_LITTLE 0x20
#define FDR_BITS1_FREADIN_BIG 0x02
#define FDR_BITS1_FREADIN_LITTLE 0x40
#define FDR_BITS1_FBIGENDIAN_BIG 0x01
#define FDR_BITS1_FBIGENDIAN_LITTLE 0x80
#define FDR_BITS2_GLEVEL_BIG 0xC0
#define FDR_BITS2_GLEVEL_SH_BIG 6
#define FDR_BITS2_GLEVEL_LITTLE 0x03
#define FDR_BITS2_GLEVEL_SH_LITTLE 0
/* We ignore the `reserved' field in bits2. */
/* Procedure descriptor external record */
struct pdr_ext {
unsigned char p_adr[8];
unsigned char p_cbLineOffset[8];
unsigned char p_isym[4];
unsigned char p_iline[4];
unsigned char p_regmask[4];
unsigned char p_regoffset[4];
unsigned char p_iopt[4];
unsigned char p_fregmask[4];
unsigned char p_fregoffset[4];
unsigned char p_frameoffset[4];
unsigned char p_lnLow[4];
unsigned char p_lnHigh[4];
unsigned char p_gp_prologue[1];
unsigned char p_bits1[1];
unsigned char p_bits2[1];
unsigned char p_localoff[1];
unsigned char p_framereg[2];
unsigned char p_pcreg[2];
};
#define PDR_BITS1_GP_USED_BIG 0x80
#define PDR_BITS1_REG_FRAME_BIG 0x40
#define PDR_BITS1_PROF_BIG 0x20
#define PDR_BITS1_RESERVED_BIG 0x1f
#define PDR_BITS1_RESERVED_SH_LEFT_BIG 8
#define PDR_BITS2_RESERVED_BIG 0xff
#define PDR_BITS2_RESERVED_SH_BIG 0
#define PDR_BITS1_GP_USED_LITTLE 0x01
#define PDR_BITS1_REG_FRAME_LITTLE 0x02
#define PDR_BITS1_PROF_LITTLE 0x04
#define PDR_BITS1_RESERVED_LITTLE 0xf8
#define PDR_BITS1_RESERVED_SH_LITTLE 3
#define PDR_BITS2_RESERVED_LITTLE 0xff
#define PDR_BITS2_RESERVED_SH_LEFT_LITTLE 5
/* Line numbers */
struct line_ext {
unsigned char l_line[4];
};
/* Symbol external record */
struct sym_ext {
unsigned char s_value[8];
unsigned char s_iss[4];
unsigned char s_bits1[1];
unsigned char s_bits2[1];
unsigned char s_bits3[1];
unsigned char s_bits4[1];
};
#define SYM_BITS1_ST_BIG 0xFC
#define SYM_BITS1_ST_SH_BIG 2
#define SYM_BITS1_ST_LITTLE 0x3F
#define SYM_BITS1_ST_SH_LITTLE 0
#define SYM_BITS1_SC_BIG 0x03
#define SYM_BITS1_SC_SH_LEFT_BIG 3
#define SYM_BITS1_SC_LITTLE 0xC0
#define SYM_BITS1_SC_SH_LITTLE 6
#define SYM_BITS2_SC_BIG 0xE0
#define SYM_BITS2_SC_SH_BIG 5
#define SYM_BITS2_SC_LITTLE 0x07
#define SYM_BITS2_SC_SH_LEFT_LITTLE 2
#define SYM_BITS2_RESERVED_BIG 0x10
#define SYM_BITS2_RESERVED_LITTLE 0x08
#define SYM_BITS2_INDEX_BIG 0x0F
#define SYM_BITS2_INDEX_SH_LEFT_BIG 16
#define SYM_BITS2_INDEX_LITTLE 0xF0
#define SYM_BITS2_INDEX_SH_LITTLE 4
#define SYM_BITS3_INDEX_SH_LEFT_BIG 8
#define SYM_BITS3_INDEX_SH_LEFT_LITTLE 4
#define SYM_BITS4_INDEX_SH_LEFT_BIG 0
#define SYM_BITS4_INDEX_SH_LEFT_LITTLE 12
/* External symbol external record */
struct ext_ext {
struct sym_ext es_asym;
unsigned char es_bits1[1];
unsigned char es_bits2[3];
unsigned char es_ifd[4];
};
#define EXT_BITS1_JMPTBL_BIG 0x80
#define EXT_BITS1_JMPTBL_LITTLE 0x01
#define EXT_BITS1_COBOL_MAIN_BIG 0x40
#define EXT_BITS1_COBOL_MAIN_LITTLE 0x02
#define EXT_BITS1_WEAKEXT_BIG 0x20
#define EXT_BITS1_WEAKEXT_LITTLE 0x04
/* Dense numbers external record */
struct dnr_ext {
unsigned char d_rfd[4];
unsigned char d_index[4];
};
/* Relative file descriptor */
struct rfd_ext {
unsigned char rfd[4];
};
/* Optimizer symbol external record */
struct opt_ext {
unsigned char o_bits1[1];
unsigned char o_bits2[1];
unsigned char o_bits3[1];
unsigned char o_bits4[1];
struct rndx_ext o_rndx;
unsigned char o_offset[4];
};
#define OPT_BITS2_VALUE_SH_LEFT_BIG 16
#define OPT_BITS2_VALUE_SH_LEFT_LITTLE 0
#define OPT_BITS3_VALUE_SH_LEFT_BIG 8
#define OPT_BITS3_VALUE_SH_LEFT_LITTLE 8
#define OPT_BITS4_VALUE_SH_LEFT_BIG 0
#define OPT_BITS4_VALUE_SH_LEFT_LITTLE 16

125
coff/apollo.h Normal file
View file

@ -0,0 +1,125 @@
/* coff information for Apollo M68K
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define DO_NOT_DEFINE_AOUTHDR
#define L_LNNO_SIZE 2
#include "coff/external.h"
/* Motorola 68000/68008/68010/68020 */
#define MC68MAGIC 0520
#define MC68KWRMAGIC 0520 /* writeable text segments */
#define MC68TVMAGIC 0521
#define MC68KROMAGIC 0521 /* readonly shareable text segments */
#define MC68KPGMAGIC 0522 /* demand paged text segments */
#define M68MAGIC 0210
#define M68TVMAGIC 0211
/* Apollo 68000-based machines have a different magic number. This comes
* from /usr/include/apollo/filehdr.h
*/
#define APOLLOM68KMAGIC 0627
#define OMAGIC M68MAGIC
#define M68KBADMAG(x) (((x).f_magic!=MC68MAGIC) && ((x).f_magic!=MC68KWRMAGIC) && ((x).f_magic!=MC68TVMAGIC) && \
((x).f_magic!=MC68KROMAGIC) && ((x).f_magic!=MC68KPGMAGIC) && ((x).f_magic!=M68MAGIC) && ((x).f_magic!=M68TVMAGIC) && \
((x).f_magic!=APOLLOM68KMAGIC) )
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct
{
char magic[2]; /* type of file */
char vstamp[2]; /* version stamp */
char tsize[4]; /* text size in bytes, padded to FW bdry*/
char dsize[4]; /* initialized data " " */
char bsize[4]; /* uninitialized data " " */
char entry[4]; /* entry pt. */
char text_start[4]; /* base of text used for this file */
char data_start[4]; /* base of data used for this file */
char o_sri[4]; /* Apollo specific - .sri data pointer */
char o_inlib[4]; /* Apollo specific - .inlib data pointer */
char vid[8]; /* Apollo specific - 64 bit version ID */
}
AOUTHDR;
#define APOLLO_COFF_VERSION_NUMBER 1 /* the value of the aouthdr magic */
#define AOUTHDRSZ 44
#define AOUTSZ 44
/* Apollo allowa for larger section names by allowing
them to be in the string table. */
/* If s_zeores is all zeroes, s_offset gives the real
location of the name in the string table. */
#define s_zeroes section_name.s_name
#define s_offset (section_name.s_name+4)
/* More names of "special" sections. */
#define _TV ".tv"
#define _INIT ".init"
#define _FINI ".fini"
#define _LINES ".lines"
#define _BLOCKS ".blocks"
#define _SRI ".sri" /* Static Resource Information (systype,
et al.) */
#define _MIR ".mir" /* Module Information Records */
#define _APTV ".aptv" /* Apollo-style transfer vectors. */
#define _INLIB ".inlib" /* Shared Library information */
#define _RWDI ".rwdi" /* Read/write data initialization directives for
compressed sections */
#define _UNWIND ".unwind" /* Stack unwind information */
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
#ifdef M68K_COFF_OFFSET
char r_offset[4];
#endif
};
#define RELOC struct external_reloc
#ifdef M68K_COFF_OFFSET
#define RELSZ 14
#else
#define RELSZ 10
#endif
/* Apollo specific STYP flags */
#define STYP_RELOCATED_NOT_LOADED 0x00010000 /* Section is relocated normally during linking, but need
not be loaded during program execution */
#define STYP_DEBUG 0x00020000 /* debug section */
#define STYP_OVERLAY 0x00040000 /* Section is overlayed */
#define STYP_INSTRUCTION 0x00200000 /* Section contains executable code */
#define STYP_ZERO 0x00800000 /* Section is initialized to zero */
#define STYP_INSTALLED 0x02000000 /* Section should be installable in KGT */
#define STYP_LOOK_INSTALLED 0x04000000 /* Look for section in KGT */
#define STYP_SECALIGN1 0x08000000 /* Specially aligned section */
#define STYP_SECALIGN2 0x10000000 /* " " " */
#define STYP_COMPRESSED 0x20000000 /* No section data per se (s_scnptr = 0), but there are
initialization directives for it in .rwdi section
(used in conjunction with STYP_BSS) */

128
coff/arm.h Normal file
View file

@ -0,0 +1,128 @@
/* ARM COFF support for BFD.
Copyright 1998, 1999, 2000, 2002, 2003, 2010 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#define COFFARM 1
#define L_LNNO_SIZE 2
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
/* Bits for f_flags:
F_RELFLG relocation info stripped from file
F_EXEC file is executable (no unresolved external references)
F_LNNO line numbers stripped from file
F_LSYMS local symbols stripped from file
F_INTERWORK file supports switching between ARM and Thumb instruction sets
F_INTERWORK_SET the F_INTERWORK bit is valid
F_APCS_FLOAT code passes float arguments in float registers
F_PIC code is reentrant/position-independent
F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax)
F_APCS_26 file uses 26 bit ARM Procedure Calling Standard
F_APCS_SET the F_APCS_26, F_APCS_FLOAT and F_PIC bits have been initialised
F_SOFT_FLOAT code does not use floating point instructions. */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
#define F_INTERWORK (0x0010)
#define F_INTERWORK_SET (0x0020)
#define F_APCS_FLOAT (0x0040)
#undef F_AR16WR
#define F_PIC (0x0080)
#define F_AR32WR (0x0100)
#define F_APCS_26 (0x0400)
#define F_APCS_SET (0x0800)
#define F_SOFT_FLOAT (0x2000)
#define F_VFP_FLOAT (0x4000)
/* Bits stored in flags field of the internal_f structure */
#define F_INTERWORK (0x0010)
#define F_APCS_FLOAT (0x0040)
#define F_PIC (0x0080)
#define F_APCS26 (0x1000)
#define F_ARM_ARCHITECTURE_MASK (0x4000+0x0800+0x0400)
#define F_ARM_2 (0x0400)
#define F_ARM_2a (0x0800)
#define F_ARM_3 (0x0c00)
#define F_ARM_3M (0x4000)
#define F_ARM_4 (0x4400)
#define F_ARM_4T (0x4800)
#define F_ARM_5 (0x4c00)
/*
ARMMAGIC ought to encoded the procesor type,
but it is too late to change it now, instead
the flags field of the internal_f structure
is used as shown above.
XXX - NC 5/6/97. */
#define ARMMAGIC 0xa00 /* I just made this up */
#define ARMBADMAG(x) (((x).f_magic != ARMMAGIC))
#define ARMPEMAGIC 0x1c0
#define THUMBPEMAGIC 0x1c2
#undef ARMBADMAG
#define ARMBADMAG(x) (((x).f_magic != ARMMAGIC) && ((x).f_magic != ARMPEMAGIC) && ((x).f_magic != THUMBPEMAGIC))
#define OMAGIC 0404 /* object files, eg as output */
#define ZMAGIC 0413 /* demand load format, eg normal ld output */
#define STMAGIC 0401 /* target shlib */
#define SHMAGIC 0443 /* host shlib */
/* define some NT default values */
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
/* We use the .rdata section to hold read only data. */
#define _LIT ".rdata"
/********************** RELOCATION DIRECTIVES **********************/
#ifdef ARM_WINCE
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10
#else
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
char r_offset[4];
};
#define RELOC struct external_reloc
#define RELSZ 14
#endif
#define ARM_NOTE_SECTION ".note"

49
coff/aux-coff.h Normal file
View file

@ -0,0 +1,49 @@
/* Modifications of internal.h and m68k.h needed by A/UX
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA.
Suggested by Ian Lance Taylor <ian@cygnus.com> */
#ifndef GNU_COFF_AUX_H
#define GNU_COFF_AUX_H 1
#include "coff/internal.h"
#include "coff/m68k.h"
/* Section contains 64-byte padded pathnames of shared libraries */
#undef STYP_LIB
#define STYP_LIB 0x200
/* Section contains shared library initialization code */
#undef STYP_INIT
#define STYP_INIT 0x400
/* Section contains .ident information */
#undef STYP_IDENT
#define STYP_IDENT 0x800
/* Section types used by bfd and gas not defined (directly) by A/UX */
#undef STYP_OVER
#define STYP_OVER 0
#undef STYP_INFO
#define STYP_INFO STYP_IDENT
/* Traditional name of the section tagged with STYP_LIB */
#define _LIB ".lib"
#endif /* GNU_COFF_AUX_H */

411
coff/ecoff.h Normal file
View file

@ -0,0 +1,411 @@
/* Generic ECOFF support.
This does not include symbol information, found in sym.h and
symconst.h.
Copyright 2001, 2002, 2003, 2004, 2005, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef ECOFF_H
#define ECOFF_H
/* Mips magic numbers used in filehdr. MIPS_MAGIC_LITTLE is used on
little endian machines. MIPS_MAGIC_BIG is used on big endian
machines. Where is MIPS_MAGIC_1 from? */
#define MIPS_MAGIC_1 0x0180
#define MIPS_MAGIC_LITTLE 0x0162
#define MIPS_MAGIC_BIG 0x0160
/* These are the magic numbers used for MIPS code compiled at ISA
level 2. */
#define MIPS_MAGIC_LITTLE2 0x0166
#define MIPS_MAGIC_BIG2 0x0163
/* These are the magic numbers used for MIPS code compiled at ISA
level 3. */
#define MIPS_MAGIC_LITTLE3 0x142
#define MIPS_MAGIC_BIG3 0x140
/* Alpha magic numbers used in filehdr. */
#define ALPHA_MAGIC 0x183
#define ALPHA_MAGIC_BSD 0x185
/* A compressed version of an ALPHA_MAGIC file created by DEC's tools. */
#define ALPHA_MAGIC_COMPRESSED 0x188
/* Magic numbers used in a.out header. */
#define ECOFF_AOUT_OMAGIC 0407 /* not demand paged (ld -N). */
#define ECOFF_AOUT_ZMAGIC 0413 /* demand load format, eg normal ld output */
/* Names of special sections. */
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _RDATA ".rdata"
#define _SDATA ".sdata"
#define _SBSS ".sbss"
#define _LITA ".lita"
#define _LIT4 ".lit4"
#define _LIT8 ".lit8"
#define _LIB ".lib"
#define _INIT ".init"
#define _FINI ".fini"
#define _PDATA ".pdata"
#define _XDATA ".xdata"
#define _GOT ".got"
#define _HASH ".hash"
#define _DYNSYM ".dynsym"
#define _DYNSTR ".dynstr"
#define _RELDYN ".rel.dyn"
#define _CONFLIC ".conflic"
#define _COMMENT ".comment"
#define _LIBLIST ".liblist"
#define _DYNAMIC ".dynamic"
#define _RCONST ".rconst"
/* ECOFF uses some additional section flags. */
#define STYP_RDATA 0x100
#define STYP_SDATA 0x200
#define STYP_SBSS 0x400
#define STYP_GOT 0x1000
#define STYP_DYNAMIC 0x2000
#define STYP_DYNSYM 0x4000
#define STYP_RELDYN 0x8000
#define STYP_DYNSTR 0x10000
#define STYP_HASH 0x20000
#define STYP_LIBLIST 0x40000
#define STYP_CONFLIC 0x100000
#define STYP_ECOFF_FINI 0x1000000
#define STYP_EXTENDESC 0x2000000 /* 0x02FFF000 bits => scn type, rest clr */
#define STYP_LITA 0x4000000
#define STYP_LIT8 0x8000000
#define STYP_LIT4 0x10000000
#define STYP_ECOFF_LIB 0x40000000
#define STYP_ECOFF_INIT 0x80000000
#define STYP_OTHER_LOAD (STYP_ECOFF_INIT | STYP_ECOFF_FINI)
/* extended section types */
#define STYP_COMMENT 0x2100000
#define STYP_RCONST 0x2200000
#define STYP_XDATA 0x2400000
#define STYP_PDATA 0x2800000
/* The linker needs a section to hold small common variables while
linking. There is no convenient way to create it when the linker
needs it, so we always create one for each BFD. We then avoid
writing it out. */
#define SCOMMON ".scommon"
/* If the extern bit in a reloc is 1, then r_symndx is an index into
the external symbol table. If the extern bit is 0, then r_symndx
indicates a section, and is one of the following values. */
#define RELOC_SECTION_NONE 0
#define RELOC_SECTION_TEXT 1
#define RELOC_SECTION_RDATA 2
#define RELOC_SECTION_DATA 3
#define RELOC_SECTION_SDATA 4
#define RELOC_SECTION_SBSS 5
#define RELOC_SECTION_BSS 6
#define RELOC_SECTION_INIT 7
#define RELOC_SECTION_LIT8 8
#define RELOC_SECTION_LIT4 9
#define RELOC_SECTION_XDATA 10
#define RELOC_SECTION_PDATA 11
#define RELOC_SECTION_FINI 12
#define RELOC_SECTION_LITA 13
#define RELOC_SECTION_ABS 14
#define RELOC_SECTION_RCONST 15
#define NUM_RELOC_SECTIONS 16
/********************** STABS **********************/
/* gcc uses mips-tfile to output type information in special stabs
entries. These must match the corresponding definition in
gcc/config/mips.h. At some point, these should probably go into a
shared include file, but currently gcc and gdb do not share any
directories. */
#define CODE_MASK 0x8F300
#define ECOFF_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
#define ECOFF_MARK_STAB(code) ((code)+CODE_MASK)
#define ECOFF_UNMARK_STAB(code) ((code)-CODE_MASK)
#define STABS_SYMBOL "@stabs"
/********************** COFF **********************/
/* gcc also uses mips-tfile to output COFF debugging information.
These are the values it uses when outputting the .type directive.
These should also be in a shared include file. */
#define N_BTMASK (017)
#define N_TMASK (060)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
/********************** AUX **********************/
/* The auxiliary type information is the same on all known ECOFF
targets. I can't see any reason that it would ever change, so I am
going to gamble and define the external structures here, in the
target independent ECOFF header file. The internal forms are
defined in coff/sym.h, which was originally donated by MIPS
Computer Systems. */
/* Type information external record */
struct tir_ext {
unsigned char t_bits1[1];
unsigned char t_tq45[1];
unsigned char t_tq01[1];
unsigned char t_tq23[1];
};
#define TIR_BITS1_FBITFIELD_BIG ((unsigned int) 0x80)
#define TIR_BITS1_FBITFIELD_LITTLE ((unsigned int) 0x01)
#define TIR_BITS1_CONTINUED_BIG ((unsigned int) 0x40)
#define TIR_BITS1_CONTINUED_LITTLE ((unsigned int) 0x02)
#define TIR_BITS1_BT_BIG ((unsigned int) 0x3F)
#define TIR_BITS1_BT_SH_BIG 0
#define TIR_BITS1_BT_LITTLE ((unsigned int) 0xFC)
#define TIR_BITS1_BT_SH_LITTLE 2
#define TIR_BITS_TQ4_BIG ((unsigned int) 0xF0)
#define TIR_BITS_TQ4_SH_BIG 4
#define TIR_BITS_TQ5_BIG ((unsigned int) 0x0F)
#define TIR_BITS_TQ5_SH_BIG 0
#define TIR_BITS_TQ4_LITTLE ((unsigned int) 0x0F)
#define TIR_BITS_TQ4_SH_LITTLE 0
#define TIR_BITS_TQ5_LITTLE ((unsigned int) 0xF0)
#define TIR_BITS_TQ5_SH_LITTLE 4
#define TIR_BITS_TQ0_BIG ((unsigned int) 0xF0)
#define TIR_BITS_TQ0_SH_BIG 4
#define TIR_BITS_TQ1_BIG ((unsigned int) 0x0F)
#define TIR_BITS_TQ1_SH_BIG 0
#define TIR_BITS_TQ0_LITTLE ((unsigned int) 0x0F)
#define TIR_BITS_TQ0_SH_LITTLE 0
#define TIR_BITS_TQ1_LITTLE ((unsigned int) 0xF0)
#define TIR_BITS_TQ1_SH_LITTLE 4
#define TIR_BITS_TQ2_BIG ((unsigned int) 0xF0)
#define TIR_BITS_TQ2_SH_BIG 4
#define TIR_BITS_TQ3_BIG ((unsigned int) 0x0F)
#define TIR_BITS_TQ3_SH_BIG 0
#define TIR_BITS_TQ2_LITTLE ((unsigned int) 0x0F)
#define TIR_BITS_TQ2_SH_LITTLE 0
#define TIR_BITS_TQ3_LITTLE ((unsigned int) 0xF0)
#define TIR_BITS_TQ3_SH_LITTLE 4
/* Relative symbol external record */
struct rndx_ext {
unsigned char r_bits[4];
};
#define RNDX_BITS0_RFD_SH_LEFT_BIG 4
#define RNDX_BITS1_RFD_BIG ((unsigned int) 0xF0)
#define RNDX_BITS1_RFD_SH_BIG 4
#define RNDX_BITS0_RFD_SH_LEFT_LITTLE 0
#define RNDX_BITS1_RFD_LITTLE ((unsigned int) 0x0F)
#define RNDX_BITS1_RFD_SH_LEFT_LITTLE 8
#define RNDX_BITS1_INDEX_BIG ((unsigned int) 0x0F)
#define RNDX_BITS1_INDEX_SH_LEFT_BIG 16
#define RNDX_BITS2_INDEX_SH_LEFT_BIG 8
#define RNDX_BITS3_INDEX_SH_LEFT_BIG 0
#define RNDX_BITS1_INDEX_LITTLE ((unsigned int) 0xF0)
#define RNDX_BITS1_INDEX_SH_LITTLE 4
#define RNDX_BITS2_INDEX_SH_LEFT_LITTLE 4
#define RNDX_BITS3_INDEX_SH_LEFT_LITTLE 12
/* Auxiliary symbol information external record */
union aux_ext {
struct tir_ext a_ti;
struct rndx_ext a_rndx;
unsigned char a_dnLow[4];
unsigned char a_dnHigh[4];
unsigned char a_isym[4];
unsigned char a_iss[4];
unsigned char a_width[4];
unsigned char a_count[4];
};
#define AUX_GET_ANY(bigend, ax, field) \
((bigend) ? bfd_getb32 ((ax)->field) : bfd_getl32 ((ax)->field))
#define AUX_GET_DNLOW(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnLow)
#define AUX_GET_DNHIGH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnHigh)
#define AUX_GET_ISYM(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_isym)
#define AUX_GET_ISS(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_iss)
#define AUX_GET_WIDTH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_width)
#define AUX_GET_COUNT(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_count)
#define AUX_PUT_ANY(bigend, val, ax, field) \
((bigend) \
? (bfd_putb32 ((bfd_vma) (val), (ax)->field), 0) \
: (bfd_putl32 ((bfd_vma) (val), (ax)->field), 0))
#define AUX_PUT_DNLOW(bigend, val, ax) \
AUX_PUT_ANY ((bigend), (val), (ax), a_dnLow)
#define AUX_PUT_DNHIGH(bigend, val, ax) \
AUX_PUT_ANY ((bigend), (val), (ax), a_dnHigh)
#define AUX_PUT_ISYM(bigend, val, ax) \
AUX_PUT_ANY ((bigend), (val), (ax), a_isym)
#define AUX_PUT_ISS(bigend, val, ax) \
AUX_PUT_ANY ((bigend), (val), (ax), a_iss)
#define AUX_PUT_WIDTH(bigend, val, ax) \
AUX_PUT_ANY ((bigend), (val), (ax), a_width)
#define AUX_PUT_COUNT(bigend, val, ax) \
AUX_PUT_ANY ((bigend), (val), (ax), a_count)
/********************** SYMBOLS **********************/
/* For efficiency, gdb deals directly with the unswapped symbolic
information (that way it only takes the time to swap information
that it really needs to read). gdb originally retrieved the
information directly from the BFD backend information, but that
strategy, besides being sort of ugly, does not work for MIPS ELF,
which also uses ECOFF debugging information. This structure holds
pointers to the (mostly) unswapped symbolic information. */
struct ecoff_debug_info
{
/* The swapped ECOFF symbolic header. */
HDRR symbolic_header;
/* Pointers to the unswapped symbolic information. Note that the
pointers to external structures point to different sorts of
information on different ECOFF targets. The ecoff_debug_swap
structure provides the sizes of the structures and the functions
needed to swap the information in and out. These pointers are
all pointers to arrays, not single structures. They will be NULL
if there are no instances of the relevant structure. These
fields are also used by the assembler to output ECOFF debugging
information. */
unsigned char *line;
void *external_dnr; /* struct dnr_ext */
void *external_pdr; /* struct pdr_ext */
void *external_sym; /* struct sym_ext */
void *external_opt; /* struct opt_ext */
union aux_ext *external_aux;
char *ss;
char *ssext;
void *external_fdr; /* struct fdr_ext */
void *external_rfd; /* struct rfd_ext */
void *external_ext; /* struct ext_ext */
/* These fields are used when linking. They may disappear at some
point. */
char *ssext_end;
void *external_ext_end;
/* When linking, this field holds a mapping from the input FDR
numbers to the output numbers, and is used when writing out the
external symbols. It is NULL if no mapping is required. */
RFDT *ifdmap;
/* The swapped FDR information. Currently this is never NULL, but
code using this structure should probably double-check in case
this changes in the future. This is a pointer to an array, not a
single structure. */
FDR *fdr;
};
/* These structures are used by the ECOFF find_nearest_line function. */
struct ecoff_fdrtab_entry
{
/* Base address in .text of this FDR. */
bfd_vma base_addr;
FDR *fdr;
};
struct ecoff_find_line
{
/* Allocated memory to hold function and file names. */
char *find_buffer;
/* FDR table, sorted by address: */
long fdrtab_len;
struct ecoff_fdrtab_entry *fdrtab;
/* Cache entry for most recently found line information. The sect
field is NULL if this cache does not contain valid information. */
struct
{
asection *sect;
bfd_vma start;
bfd_vma stop;
const char *filename;
const char *functionname;
unsigned int line_num;
} cache;
};
/********************** SWAPPING **********************/
/* The generic ECOFF code needs to be able to swap debugging
information in and out in the specific format used by a particular
ECOFF implementation. This structure provides the information
needed to do this. */
struct ecoff_debug_swap
{
/* Symbol table magic number. */
int sym_magic;
/* Alignment of debugging information. E.g., 4. */
bfd_size_type debug_align;
/* Sizes of external symbolic information. */
bfd_size_type external_hdr_size;
bfd_size_type external_dnr_size;
bfd_size_type external_pdr_size;
bfd_size_type external_sym_size;
bfd_size_type external_opt_size;
bfd_size_type external_fdr_size;
bfd_size_type external_rfd_size;
bfd_size_type external_ext_size;
/* Functions to swap in external symbolic data. */
void (*swap_hdr_in) (bfd *, void *, HDRR *);
void (*swap_dnr_in) (bfd *, void *, DNR *);
void (*swap_pdr_in) (bfd *, void *, PDR *);
void (*swap_sym_in) (bfd *, void *, SYMR *);
void (*swap_opt_in) (bfd *, void *, OPTR *);
void (*swap_fdr_in) (bfd *, void *, FDR *);
void (*swap_rfd_in) (bfd *, void *, RFDT *);
void (*swap_ext_in) (bfd *, void *, EXTR *);
void (*swap_tir_in) (int, const struct tir_ext *, TIR *);
void (*swap_rndx_in) (int, const struct rndx_ext *, RNDXR *);
/* Functions to swap out external symbolic data. */
void (*swap_hdr_out) (bfd *, const HDRR *, void *);
void (*swap_dnr_out) (bfd *, const DNR *, void *);
void (*swap_pdr_out) (bfd *, const PDR *, void *);
void (*swap_sym_out) (bfd *, const SYMR *, void *);
void (*swap_opt_out) (bfd *, const OPTR *, void *);
void (*swap_fdr_out) (bfd *, const FDR *, void *);
void (*swap_rfd_out) (bfd *, const RFDT *, void *);
void (*swap_ext_out) (bfd *, const EXTR *, void *);
void (*swap_tir_out) (int, const TIR *, struct tir_ext *);
void (*swap_rndx_out) (int, const RNDXR *, struct rndx_ext *);
/* Function to read symbol data and set up pointers in
ecoff_debug_info structure. The section argument is used for
ELF, not straight ECOFF. */
bfd_boolean (*read_debug_info) (bfd *, asection *, struct ecoff_debug_info *);
};
#endif /* ! defined (ECOFF_H) */

269
coff/external.h Normal file
View file

@ -0,0 +1,269 @@
/* external.h -- External COFF structures
Copyright 2001, 2006, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef COFF_EXTERNAL_H
#define COFF_EXTERNAL_H
#ifndef DO_NOT_DEFINE_FILHDR
/********************** FILE HEADER **********************/
struct external_filehdr
{
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
};
#define FILHDR struct external_filehdr
#define FILHSZ 20
#endif
#ifndef DO_NOT_DEFINE_AOUTHDR
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct external_aouthdr
{
char magic[2]; /* type of file */
char vstamp[2]; /* version stamp */
char tsize[4]; /* text size in bytes, padded to FW bdry*/
char dsize[4]; /* initialized data " " */
char bsize[4]; /* uninitialized data " " */
char entry[4]; /* entry pt. */
char text_start[4]; /* base of text used for this file */
char data_start[4]; /* base of data used for this file */
} ATTRIBUTE_PACKED
AOUTHDR;
#define AOUTHDRSZ 28
#define AOUTSZ 28
typedef struct external_aouthdr64
{
char magic[2]; /* Type of file. */
char vstamp[2]; /* Version stamp. */
char tsize[4]; /* Text size in bytes, padded to FW bdry*/
char dsize[4]; /* Initialized data " ". */
char bsize[4]; /* Uninitialized data " ". */
char entry[4]; /* Entry pt. */
char text_start[4]; /* Base of text used for this file. */
}
AOUTHDR64;
#define AOUTHDRSZ64 24
#endif /* not DO_NOT_DEFINE_AOUTHDR */
#ifndef DO_NOT_DEFINE_SCNHDR
/********************** SECTION HEADER **********************/
struct external_scnhdr
{
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[2]; /* number of relocation entries */
char s_nlnno[2]; /* number of line number entries */
char s_flags[4]; /* flags */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 40
/* Names of "special" sections. */
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _COMMENT ".comment"
#define _LIB ".lib"
#endif /* not DO_NOT_DEFINE_SCNHDR */
#ifndef DO_NOT_DEFINE_LINENO
/********************** LINE NUMBERS **********************/
#ifndef L_LNNO_SIZE
#error L_LNNO_SIZE needs to be defined
#endif
/* 1 line number entry for every "breakpointable" source line in a section.
Line numbers are grouped on a per function basis; first entry in a function
grouping will have l_lnno = 0 and in place of physical address will be the
symbol table index of the function name. */
struct external_lineno
{
union
{
char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
char l_paddr[4]; /* (physical) address of line number */
} l_addr;
char l_lnno[L_LNNO_SIZE]; /* line number */
};
#define LINENO struct external_lineno
#define LINESZ (4 + L_LNNO_SIZE)
#if L_LNNO_SIZE == 4
#define GET_LINENO_LNNO(abfd, ext) H_GET_32 (abfd, (ext->l_lnno))
#define PUT_LINENO_LNNO(abfd, val, ext) H_PUT_32 (abfd, val, (ext->l_lnno))
#endif
#if L_LNNO_SIZE == 2
#define GET_LINENO_LNNO(abfd, ext) H_GET_16 (abfd, (ext->l_lnno))
#define PUT_LINENO_LNNO(abfd, val, ext) H_PUT_16 (abfd, val, (ext->l_lnno))
#endif
#endif /* not DO_NOT_DEFINE_LINENO */
#ifndef DO_NOT_DEFINE_SYMENT
/********************** SYMBOLS **********************/
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#ifndef E_FILNMLEN
#define E_FILNMLEN 14
#endif
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
struct external_syment
{
union
{
char e_name[E_SYMNMLEN];
struct
{
char e_zeroes[4];
char e_offset[4];
} e;
} e;
char e_value[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
} ATTRIBUTE_PACKED ;
#define SYMENT struct external_syment
#define SYMESZ 18
#ifndef N_BTMASK
#define N_BTMASK 0xf
#endif
#ifndef N_TMASK
#define N_TMASK 0x30
#endif
#ifndef N_BTSHFT
#define N_BTSHFT 4
#endif
#ifndef N_TSHIFT
#define N_TSHIFT 2
#endif
#endif /* not DO_NOT_DEFINE_SYMENT */
#ifndef DO_NOT_DEFINE_AUXENT
union external_auxent
{
struct
{
char x_tagndx[4]; /* str, un, or enum tag indx */
union
{
struct
{
char x_lnno[2]; /* declaration line number */
char x_size[2]; /* str/union/array size */
} x_lnsz;
char x_fsize[4]; /* size of function */
} x_misc;
union
{
struct /* if ISFCN, tag, or .bb */
{
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
struct /* if ISARY, up to 4 dimen. */
{
char x_dimen[E_DIMNUM][2];
} x_ary;
} x_fcnary;
char x_tvndx[2]; /* tv index */
} x_sym;
union
{
char x_fname[E_FILNMLEN];
struct
{
char x_zeroes[4];
char x_offset[4];
} x_n;
} x_file;
struct
{
char x_scnlen[4]; /* section length */
char x_nreloc[2]; /* # relocation entries */
char x_nlinno[2]; /* # line numbers */
#ifdef INCLUDE_COMDAT_FIELDS_IN_AUXENT
char x_checksum[4]; /* section COMDAT checksum */
char x_associated[2]; /* COMDAT associated section index */
char x_comdat[1]; /* COMDAT selection number */
#endif
} x_scn;
struct
{
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
} ATTRIBUTE_PACKED ;
#define AUXENT union external_auxent
#define AUXESZ 18
#define _ETEXT "etext"
#endif /* not DO_NOT_DEFINE_AUXENT */
#endif /* COFF_EXTERNAL_H */

36
coff/go32exe.h Normal file
View file

@ -0,0 +1,36 @@
/* COFF information for PC running go32.
Copyright 2001, 2005, 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
struct external_filehdr_go32_exe
{
char stub[GO32_STUBSIZE]; /* the stub to load the image */
/* the standard COFF header */
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
};
#undef FILHDR
#define FILHDR struct external_filehdr_go32_exe
#undef FILHSZ
#define FILHSZ GO32_STUBSIZE+20

55
coff/h8300.h Normal file
View file

@ -0,0 +1,55 @@
/* coff information for Renesas H8/300 and H8/300-H
Copyright 2001, 2003, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 4
#include "coff/external.h"
#define H8300MAGIC 0x8300
#define H8300HMAGIC 0x8301
#define H8300SMAGIC 0x8302
#define H8300HNMAGIC 0x8303
#define H8300SNMAGIC 0x8304
#define H8300BADMAG(x) (((x).f_magic != H8300MAGIC))
#define H8300HBADMAG(x) (((x).f_magic != H8300HMAGIC))
#define H8300SBADMAG(x) (((x).f_magic != H8300SMAGIC))
#define H8300HNBADMAG(x) (((x).f_magic != H8300HNMAGIC))
#define H8300SNBADMAG(x) (((x).f_magic != H8300SNMAGIC))
/* Relocation directives. */
/* The external reloc has an offset field, because some of the reloc
types on the h8 don't have room in the instruction for the entire
offset - eg the strange jump and high page addressing modes. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#define RELOC struct external_reloc
#define RELSZ 16

47
coff/h8500.h Normal file
View file

@ -0,0 +1,47 @@
/* coff information for Renesas H8/500
Copyright 2001, 2003, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 4
#include "coff/external.h"
#define H8500MAGIC 0x8500
#define H8500BADMAG(x) ((0xffff && ((x).f_magic) != H8500MAGIC))
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the h8 don't have room in the instruction for the entire
offset - eg the strange jump and high page addressing modes. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#define RELOC struct external_reloc
#define RELSZ 16

74
coff/i386.h Normal file
View file

@ -0,0 +1,74 @@
/* coff information for Intel 386/486.
Copyright 2001, 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 2
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
#define COFF_PAGE_SIZE 0x1000
/* Bits for f_flags:
F_RELFLG Relocation info stripped from file
F_EXEC File is executable (no unresolved external references)
F_LNNO Line numbers stripped from file
F_LSYMS Local symbols stripped from file
F_AR32WR File has byte ordering of an AR32WR machine (e.g. vax). */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
#define I386MAGIC 0x14c
#define I386PTXMAGIC 0x154
#define I386AIXMAGIC 0x175
/* This is Lynx's all-platform magic number for executables. */
#define LYNXCOFFMAGIC 0415
#define I386BADMAG(x) ( ((x).f_magic != I386MAGIC) \
&& (x).f_magic != I386AIXMAGIC \
&& (x).f_magic != I386PTXMAGIC \
&& (x).f_magic != LYNXCOFFMAGIC)
#define OMAGIC 0404 /* Object files, eg as output. */
#define ZMAGIC 0413 /* Demand load format, eg normal ld output. */
#define STMAGIC 0401 /* Target shlib. */
#define SHMAGIC 0443 /* Host shlib. */
/* Define some NT default values. */
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
/* Relocation directives. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10

87
coff/i860.h Normal file
View file

@ -0,0 +1,87 @@
/* COFF information for the Intel i860.
Copyright 2001, 2003, 2010, 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* This file was hacked from i386.h [dolan@ssd.intel.com] */
#define L_LNNO_SIZE 2
#include "coff/external.h"
/* Bits for f_flags:
F_RELFLG relocation info stripped from file
F_EXEC file is executable (no unresolved external references)
F_LNNO line numbers stripped from file
F_LSYMS local symbols stripped from file
F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax). */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
#define I860MAGIC 0x14d
#define I860BADMAG(x) ((x).f_magic != I860MAGIC)
#undef AOUTSZ
#define AOUTSZ 36
/* FIXME: What are the a.out magic numbers? */
#define _ETEXT "etext"
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10
/* The relocation directory entry types.
PAIR : The low half that follows relates to the preceding HIGH[ADJ].
HIGH : The high half of a 32-bit constant.
LOWn : The low half, insn bits 15..(n-1), 2^n-byte aligned.
SPLITn : The low half, insn bits 20..16 and 10..(n-1), 2^n-byte aligned.
HIGHADJ: Similar to HIGH, but with adjustment.
BRADDR : 26-bit branch displacement.
Note: The Intel assembler manual lists LOW4 as one of the
relocation types, but it appears to be useless for the i860.
We will recognize it anyway, just in case it actually appears in
any object files. */
enum {
COFF860_R_PAIR = 0x1c,
COFF860_R_HIGH = 0x1e,
COFF860_R_LOW0 = 0x1f,
COFF860_R_LOW1 = 0x20,
COFF860_R_LOW2 = 0x21,
COFF860_R_LOW3 = 0x22,
COFF860_R_LOW4 = 0x23,
COFF860_R_SPLIT0 = 0x24,
COFF860_R_SPLIT1 = 0x25,
COFF860_R_SPLIT2 = 0x26,
COFF860_R_HIGHADJ = 0x27,
COFF860_R_BRADDR = 0x28
};

320
coff/i960.h Normal file
View file

@ -0,0 +1,320 @@
/* coff information for 80960. Origins: Intel corp, natch.
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* NOTE: Tagentries (cf TAGBITS) are no longer used by the 960 */
/********************** FILE HEADER **********************/
struct external_filehdr
{
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
};
#define OMAGIC (0407) /* old impure format. data immediately
follows text. both sections are rw. */
#define NMAGIC (0410) /* split i&d, read-only text */
/*
* Intel 80960 (I960) processor flags.
* F_I960TYPE == mask for processor type field.
*/
#define F_I960TYPE (0xf000)
#define F_I960CORE (0x1000)
#define F_I960KB (0x2000)
#define F_I960SB (0x2000)
#define F_I960MC (0x3000)
#define F_I960XA (0x4000)
#define F_I960CA (0x5000)
#define F_I960KA (0x6000)
#define F_I960SA (0x6000)
#define F_I960JX (0x7000)
#define F_I960HX (0x8000)
/** i80960 Magic Numbers
*/
#define I960ROMAGIC (0x160) /* read-only text segments */
#define I960RWMAGIC (0x161) /* read-write text segments */
#define I960BADMAG(x) (((x).f_magic!=I960ROMAGIC) && ((x).f_magic!=I960RWMAGIC))
#define FILHDR struct external_filehdr
#define FILHSZ 20
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct
{
unsigned long phys_addr;
unsigned long bitarray;
} TAGBITS;
typedef struct
{
char magic[2]; /* type of file */
char vstamp[2]; /* version stamp */
char tsize[4]; /* text size in bytes, padded to FW bdry*/
char dsize[4]; /* initialized data " " */
char bsize[4]; /* uninitialized data " " */
char entry[4]; /* entry pt. */
char text_start[4]; /* base of text used for this file */
char data_start[4]; /* base of data used for this file */
char tagentries[4]; /* number of tag entries to follow */
}
AOUTHDR;
/* return a pointer to the tag bits array */
#define TAGPTR(aout) ((TAGBITS *) (&(aout.tagentries)+1))
/* compute size of a header */
/*#define AOUTSZ(aout) (sizeof(AOUTHDR)+(aout.tagentries*sizeof(TAGBITS)))*/
#define AOUTSZ 32
#define AOUTHDRSZ 32
/********************** SECTION HEADER **********************/
struct external_scnhdr
{
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[2]; /* number of relocation entries */
char s_nlnno[2]; /* number of line number entries*/
char s_flags[4]; /* flags */
char s_align[4]; /* section alignment */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 44
/*
* names of "special" sections
*/
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
/********************** LINE NUMBERS **********************/
/* 1 line number entry for every "breakpointable" source line in a section.
* Line numbers are grouped on a per function basis; first entry in a function
* grouping will have l_lnno = 0 and in place of physical address will be the
* symbol table index of the function name.
*/
struct external_lineno
{
union
{
char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
char l_paddr[4]; /* (physical) address of line number */
} l_addr;
char l_lnno[2]; /* line number */
char padding[2]; /* force alignment */
};
#define LINENO struct external_lineno
#define LINESZ 8
/********************** SYMBOLS **********************/
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
struct external_syment
{
union
{
char e_name[E_SYMNMLEN];
struct
{
char e_zeroes[4];
char e_offset[4];
} e;
} e;
char e_value[4];
char e_scnum[2];
char e_flags[2];
char e_type[4];
char e_sclass[1];
char e_numaux[1];
char pad2[2];
};
#define N_BTMASK (0x1f)
#define N_TMASK (0x60)
#define N_BTSHFT (5)
#define N_TSHIFT (2)
union external_auxent
{
struct
{
char x_tagndx[4]; /* str, un, or enum tag indx */
union
{
struct
{
char x_lnno[2]; /* declaration line number */
char x_size[2]; /* str/union/array size */
} x_lnsz;
char x_fsize[4]; /* size of function */
} x_misc;
union
{
struct /* if ISFCN, tag, or .bb */
{
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
struct /* if ISARY, up to 4 dimen. */
{
char x_dimen[E_DIMNUM][2];
} x_ary;
} x_fcnary;
char x_tvndx[2]; /* tv index */
} x_sym;
union
{
char x_fname[E_FILNMLEN];
struct
{
char x_zeroes[4];
char x_offset[4];
} x_n;
} x_file;
struct
{
char x_scnlen[4]; /* section length */
char x_nreloc[2]; /* # relocation entries */
char x_nlinno[2]; /* # line numbers */
} x_scn;
struct
{
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
/******************************************
* I960-specific *2nd* aux. entry formats
******************************************/
struct
{
/* This is a very old typo that keeps getting propagated. */
#define x_stdindx x_stindx
char x_stindx[4]; /* sys. table entry */
} x_sc; /* system call entry */
struct
{
char x_balntry[4]; /* BAL entry point */
} x_bal; /* BAL-callable function */
struct
{
char x_timestamp[4]; /* time stamp */
char x_idstring[20]; /* producer identity string */
} x_ident; /* Producer ident info */
};
#define SYMENT struct external_syment
#define SYMESZ 24
#define AUXENT union external_auxent
#define AUXESZ 24
# define _ETEXT "_etext"
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
char pad[2];
};
/* r_type values for the i960. */
/* The i960 uses R_RELLONG, which is defined in internal.h as 0x11.
It is an absolute 32 bit relocation. */
#define R_IPRMED (0x19) /* 24-bit ip-relative relocation */
#define R_OPTCALL (0x1b) /* 32-bit optimizable call (leafproc/sysproc) */
#define R_OPTCALLX (0x1c) /* 64-bit optimizable call (leafproc/sysproc) */
/* The following relocation types are defined use by relaxing linkers,
which convert 32 bit calls (which require a 64 bit instruction)
into 24 bit calls (which require a 32 bit instruction) when
possible. It will be possible whenever the target of the call is
within a 24 bit range of the call instruction.
It is always safe to ignore these relocations. They only serve to
mark points which the relaxing linker will have to consider. The
assembler must ensure that the correct code is generated even if
the relocations are ignored. In particular, this means that the
R_IPR13 relocation may not appear with an external symbol. */
#define R_IPR13 (0x1d) /* 13 bit ip-relative branch */
#define R_ALIGN (0x1e) /* alignment marker. This has no
associated symbol. Instead, the
r_symndx field indicates the
require alignment at this point in
the file. It must be a power of 2. */
#define RELOC struct external_reloc
#define RELSZ 12

89
coff/ia64.h Normal file
View file

@ -0,0 +1,89 @@
/* coff information for HP/Intel IA-64.
Copyright 2000, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define DO_NOT_DEFINE_AOUTHDR
#define L_LNNO_SIZE 2
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
#define IA64MAGIC 0x200
#define IA64BADMAG(x) (((x).f_magic != IA64MAGIC))
/* Bits for f_flags:
* F_RELFLG relocation info stripped from file
* F_EXEC file is executable (no unresolved external references)
* F_LNNO line numbers stripped from file
* F_LSYMS local symbols stripped from file
* F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax)
*/
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct
{
char magic[2]; /* type of file */
char vstamp[2]; /* version stamp */
char tsize[4]; /* text size in bytes, padded to FW bdry*/
char dsize[4]; /* initialized data " " */
char bsize[4]; /* uninitialized data " " */
char entry[4]; /* entry pt. */
char text_start[4]; /* base of text used for this file */
#ifndef BFD64
char data_start[4]; /* base of data used for this file */
#endif
}
AOUTHDR;
#define PE32MAGIC 0x10b /* 32-bit image */
#define PE32PMAGIC 0x20b /* 32-bit image inside 64-bit address space */
#define PE32PBADMAG(x) (((x).f_magic != PE32PMAGIC))
#define AOUTSZ 108
#define AOUTHDRSZ 108
#define OMAGIC 0404 /* object files, eg as output */
#define ZMAGIC 0413 /* demand load format, eg normal ld output */
#define STMAGIC 0401 /* target shlib */
#define SHMAGIC 0443 /* host shlib */
/* define some NT default values */
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10

828
coff/internal.h Normal file
View file

@ -0,0 +1,828 @@
/* Internal format of COFF object file data structures, for GNU BFD.
This file is part of BFD, the Binary File Descriptor library.
Copyright 1999, 2000, 2001, 2002, 2003, 2004. 2005, 2006, 2007, 2009,
2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef GNU_COFF_INTERNAL_H
#define GNU_COFF_INTERNAL_H 1
/* First, make "signed char" work, even on old compilers. */
#ifndef signed
#ifndef __STDC__
#define signed /**/
#endif
#endif
/********************** FILE HEADER **********************/
/* extra stuff in a PE header. */
struct internal_extra_pe_filehdr
{
/* DOS header data follows for PE stuff */
unsigned short e_magic; /* Magic number, 0x5a4d */
unsigned short e_cblp; /* Bytes on last page of file, 0x90 */
unsigned short e_cp; /* Pages in file, 0x3 */
unsigned short e_crlc; /* Relocations, 0x0 */
unsigned short e_cparhdr; /* Size of header in paragraphs, 0x4 */
unsigned short e_minalloc; /* Minimum extra paragraphs needed, 0x0 */
unsigned short e_maxalloc; /* Maximum extra paragraphs needed, 0xFFFF */
unsigned short e_ss; /* Initial (relative) SS value, 0x0 */
unsigned short e_sp; /* Initial SP value, 0xb8 */
unsigned short e_csum; /* Checksum, 0x0 */
unsigned short e_ip; /* Initial IP value, 0x0 */
unsigned short e_cs; /* Initial (relative) CS value, 0x0 */
unsigned short e_lfarlc; /* File address of relocation table, 0x40 */
unsigned short e_ovno; /* Overlay number, 0x0 */
unsigned short e_res[4]; /* Reserved words, all 0x0 */
unsigned short e_oemid; /* OEM identifier (for e_oeminfo), 0x0 */
unsigned short e_oeminfo; /* OEM information; e_oemid specific, 0x0 */
unsigned short e_res2[10]; /* Reserved words, all 0x0 */
bfd_vma e_lfanew; /* File address of new exe header, 0x80 */
unsigned long dos_message[16]; /* text which always follows dos header */
bfd_vma nt_signature; /* required NT signature, 0x4550 */
};
#define GO32_STUBSIZE 2048
struct internal_filehdr
{
struct internal_extra_pe_filehdr pe;
/* coff-stgo32 EXE stub header before BFD tdata has been allocated.
Its data is kept in INTERNAL_FILEHDR.GO32STUB afterwards.
F_GO32STUB is set iff go32stub contains a valid data. Artifical headers
created in BFD have no pre-set go32stub. */
char go32stub[GO32_STUBSIZE];
/* Standard coff internal info. */
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
long f_timdat; /* time & date stamp */
bfd_vma f_symptr; /* file pointer to symtab */
long f_nsyms; /* number of symtab entries */
unsigned short f_opthdr; /* sizeof(optional hdr) */
unsigned short f_flags; /* flags */
unsigned short f_target_id; /* (TI COFF specific) */
};
/* Bits for f_flags:
F_RELFLG relocation info stripped from file
F_EXEC file is executable (no unresolved external references)
F_LNNO line numbers stripped from file
F_LSYMS local symbols stripped from file
F_AR16WR file is 16-bit little-endian
F_AR32WR file is 32-bit little-endian
F_AR32W file is 32-bit big-endian
F_DYNLOAD rs/6000 aix: dynamically loadable w/imports & exports
F_SHROBJ rs/6000 aix: file is a shared object
F_DLL PE format DLL
F_GO32STUB Field go32stub contains valid data. */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
#define F_AR16WR (0x0080)
#define F_AR32WR (0x0100)
#define F_AR32W (0x0200)
#define F_DYNLOAD (0x1000)
#define F_SHROBJ (0x2000)
#define F_DLL (0x2000)
#define F_GO32STUB (0x4000)
/* Extra structure which is used in the optional header. */
typedef struct _IMAGE_DATA_DIRECTORY
{
bfd_vma VirtualAddress;
long Size;
} IMAGE_DATA_DIRECTORY;
#define PE_EXPORT_TABLE 0
#define PE_IMPORT_TABLE 1
#define PE_RESOURCE_TABLE 2
#define PE_EXCEPTION_TABLE 3
#define PE_CERTIFICATE_TABLE 4
#define PE_BASE_RELOCATION_TABLE 5
#define PE_DEBUG_DATA 6
#define PE_ARCHITECTURE 7
#define PE_GLOBAL_PTR 8
#define PE_TLS_TABLE 9
#define PE_LOAD_CONFIG_TABLE 10
#define PE_BOUND_IMPORT_TABLE 11
#define PE_IMPORT_ADDRESS_TABLE 12
#define PE_DELAY_IMPORT_DESCRIPTOR 13
#define PE_CLR_RUNTIME_HEADER 14
/* DataDirectory[15] is currently reserved, so no define. */
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
/* Default image base for NT. */
#define NT_EXE_IMAGE_BASE 0x400000
#define NT_DLL_IMAGE_BASE 0x10000000
/* Default image base for BeOS. */
#define BEOS_EXE_IMAGE_BASE 0x80000000
#define BEOS_DLL_IMAGE_BASE 0x10000000
/* Extra stuff in a PE aouthdr */
#define PE_DEF_SECTION_ALIGNMENT 0x1000
#ifndef PE_DEF_FILE_ALIGNMENT
# define PE_DEF_FILE_ALIGNMENT 0x200
#endif
struct internal_extra_pe_aouthdr
{
/* FIXME: The following entries are in AOUTHDR. But they aren't
available internally in bfd. We add them here so that objdump
can dump them. */
/* The state of the image file */
short Magic;
/* Linker major version number */
char MajorLinkerVersion;
/* Linker minor version number */
char MinorLinkerVersion;
/* Total size of all code sections */
long SizeOfCode;
/* Total size of all initialized data sections */
long SizeOfInitializedData;
/* Total size of all uninitialized data sections */
long SizeOfUninitializedData;
/* Address of entry point relative to image base. */
bfd_vma AddressOfEntryPoint;
/* Address of the first code section relative to image base. */
bfd_vma BaseOfCode;
/* Address of the first data section relative to image base. */
bfd_vma BaseOfData;
/* PE stuff */
bfd_vma ImageBase; /* address of specific location in memory that
file is located, NT default 0x10000 */
bfd_vma SectionAlignment; /* section alignment default 0x1000 */
bfd_vma FileAlignment; /* file alignment default 0x200 */
short MajorOperatingSystemVersion; /* minimum version of the operating */
short MinorOperatingSystemVersion; /* system req'd for exe, default to 1*/
short MajorImageVersion; /* user defineable field to store version of */
short MinorImageVersion; /* exe or dll being created, default to 0 */
short MajorSubsystemVersion; /* minimum subsystem version required to */
short MinorSubsystemVersion; /* run exe; default to 3.1 */
long Reserved1; /* seems to be 0 */
long SizeOfImage; /* size of memory to allocate for prog */
long SizeOfHeaders; /* size of PE header and section table */
long CheckSum; /* set to 0 */
short Subsystem;
/* type of subsystem exe uses for user interface,
possible values:
1 - NATIVE Doesn't require a subsystem
2 - WINDOWS_GUI runs in Windows GUI subsystem
3 - WINDOWS_CUI runs in Windows char sub. (console app)
5 - OS2_CUI runs in OS/2 character subsystem
7 - POSIX_CUI runs in Posix character subsystem */
unsigned short DllCharacteristics; /* flags for DLL init */
bfd_vma SizeOfStackReserve; /* amount of memory to reserve */
bfd_vma SizeOfStackCommit; /* amount of memory initially committed for
initial thread's stack, default is 0x1000 */
bfd_vma SizeOfHeapReserve; /* amount of virtual memory to reserve and */
bfd_vma SizeOfHeapCommit; /* commit, don't know what to defaut it to */
long LoaderFlags; /* can probably set to 0 */
long NumberOfRvaAndSizes; /* number of entries in next entry, 16 */
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
};
/********************** AOUT "OPTIONAL HEADER" **********************/
struct internal_aouthdr
{
short magic; /* type of file */
short vstamp; /* version stamp */
bfd_vma tsize; /* text size in bytes, padded to FW bdry*/
bfd_vma dsize; /* initialized data " " */
bfd_vma bsize; /* uninitialized data " " */
bfd_vma entry; /* entry pt. */
bfd_vma text_start; /* base of text used for this file */
bfd_vma data_start; /* base of data used for this file */
/* i960 stuff */
unsigned long tagentries; /* number of tag entries to follow */
/* RS/6000 stuff */
bfd_vma o_toc; /* address of TOC */
short o_snentry; /* section number for entry point */
short o_sntext; /* section number for text */
short o_sndata; /* section number for data */
short o_sntoc; /* section number for toc */
short o_snloader; /* section number for loader section */
short o_snbss; /* section number for bss */
short o_algntext; /* max alignment for text */
short o_algndata; /* max alignment for data */
short o_modtype; /* Module type field, 1R,RE,RO */
short o_cputype; /* Encoded CPU type */
bfd_vma o_maxstack; /* max stack size allowed. */
bfd_vma o_maxdata; /* max data size allowed. */
/* ECOFF stuff */
bfd_vma bss_start; /* Base of bss section. */
bfd_vma gp_value; /* GP register value. */
unsigned long gprmask; /* General registers used. */
unsigned long cprmask[4]; /* Coprocessor registers used. */
unsigned long fprmask; /* Floating pointer registers used. */
/* Apollo stuff */
long o_inlib; /* inlib data */
long o_sri; /* Static Resource Information */
long vid[2]; /* Version id */
struct internal_extra_pe_aouthdr pe;
};
/********************** STORAGE CLASSES **********************/
/* This used to be defined as -1, but now n_sclass is unsigned. */
#define C_EFCN 0xff /* physical end of function */
#define C_NULL 0
#define C_AUTO 1 /* automatic variable */
#define C_EXT 2 /* external symbol */
#define C_STAT 3 /* static */
#define C_REG 4 /* register variable */
#define C_EXTDEF 5 /* external definition */
#define C_LABEL 6 /* label */
#define C_ULABEL 7 /* undefined label */
#define C_MOS 8 /* member of structure */
#define C_ARG 9 /* function argument */
#define C_STRTAG 10 /* structure tag */
#define C_MOU 11 /* member of union */
#define C_UNTAG 12 /* union tag */
#define C_TPDEF 13 /* type definition */
#define C_USTATIC 14 /* undefined static */
#define C_ENTAG 15 /* enumeration tag */
#define C_MOE 16 /* member of enumeration */
#define C_REGPARM 17 /* register parameter */
#define C_FIELD 18 /* bit field */
#define C_AUTOARG 19 /* auto argument */
#define C_LASTENT 20 /* dummy entry (end of block) */
#define C_BLOCK 100 /* ".bb" or ".eb" */
#define C_FCN 101 /* ".bf" or ".ef" */
#define C_EOS 102 /* end of structure */
#define C_FILE 103 /* file name */
#define C_LINE 104 /* line # reformatted as symbol table entry */
#define C_ALIAS 105 /* duplicate tag */
#define C_HIDDEN 106 /* ext symbol in dmert public lib */
#define C_WEAKEXT 127 /* weak symbol -- GNU extension. */
/* New storage classes for TI COFF */
#define C_UEXT 19 /* Tentative external definition */
#define C_STATLAB 20 /* Static load time label */
#define C_EXTLAB 21 /* External load time label */
#define C_SYSTEM 23 /* System Wide variable */
/* New storage classes for WINDOWS_NT */
#define C_SECTION 104 /* section name */
#define C_NT_WEAK 105 /* weak external */
/* New storage classes for 80960 */
/* C_LEAFPROC is obsolete. Use C_LEAFEXT or C_LEAFSTAT */
#define C_LEAFPROC 108 /* Leaf procedure, "call" via BAL */
#define C_SCALL 107 /* Procedure reachable via system call */
#define C_LEAFEXT 108 /* External leaf */
#define C_LEAFSTAT 113 /* Static leaf */
#define C_OPTVAR 109 /* Optimized variable */
#define C_DEFINE 110 /* Preprocessor #define */
#define C_PRAGMA 111 /* Advice to compiler or linker */
#define C_SEGMENT 112 /* 80960 segment name */
/* Storage classes for m88k */
#define C_SHADOW 107 /* shadow symbol */
#define C_VERSION 108 /* coff version symbol */
/* New storage classes for RS/6000 */
#define C_HIDEXT 107 /* Un-named external symbol */
#define C_BINCL 108 /* Marks beginning of include file */
#define C_EINCL 109 /* Marks ending of include file */
#define C_AIX_WEAKEXT 111 /* AIX definition of C_WEAKEXT. */
#define C_NULL_VALUE 0x00de1e00 /* Value for a C_NULL deleted entry. */
#if defined _AIX52 || defined AIX_WEAK_SUPPORT
#undef C_WEAKEXT
#define C_WEAKEXT C_AIX_WEAKEXT
#endif
/* storage classes for stab symbols for RS/6000 */
#define C_GSYM (0x80)
#define C_LSYM (0x81)
#define C_PSYM (0x82)
#define C_RSYM (0x83)
#define C_RPSYM (0x84)
#define C_STSYM (0x85)
#define C_TCSYM (0x86)
#define C_BCOMM (0x87)
#define C_ECOML (0x88)
#define C_ECOMM (0x89)
#define C_DECL (0x8c)
#define C_ENTRY (0x8d)
#define C_FUN (0x8e)
#define C_BSTAT (0x8f)
#define C_ESTAT (0x90)
/* Storage classes for Thumb symbols */
#define C_THUMBEXT (128 + C_EXT) /* 130 */
#define C_THUMBSTAT (128 + C_STAT) /* 131 */
#define C_THUMBLABEL (128 + C_LABEL) /* 134 */
#define C_THUMBEXTFUNC (C_THUMBEXT + 20) /* 150 */
#define C_THUMBSTATFUNC (C_THUMBSTAT + 20) /* 151 */
/* True if XCOFF symbols of class CLASS have auxillary csect information. */
#define CSECT_SYM_P(CLASS) \
((CLASS) == C_EXT || (CLASS) == C_AIX_WEAKEXT || (CLASS) == C_HIDEXT)
/********************** SECTION HEADER **********************/
#define SCNNMLEN (8)
struct internal_scnhdr
{
char s_name[SCNNMLEN]; /* section name */
/* Physical address, aliased s_nlib.
In the pei format, this field is the virtual section size
(the size of the section after being loaded int memory),
NOT the physical address. */
bfd_vma s_paddr;
bfd_vma s_vaddr; /* virtual address */
bfd_vma s_size; /* section size */
bfd_vma s_scnptr; /* file ptr to raw data for section */
bfd_vma s_relptr; /* file ptr to relocation */
bfd_vma s_lnnoptr; /* file ptr to line numbers */
unsigned long s_nreloc; /* number of relocation entries */
unsigned long s_nlnno; /* number of line number entries*/
long s_flags; /* flags */
long s_align; /* used on I960 */
unsigned char s_page; /* TI COFF load page */
};
/* s_flags "type". */
#define STYP_REG (0x0000) /* "regular": allocated, relocated, loaded */
#define STYP_DSECT (0x0001) /* "dummy": relocated only*/
#define STYP_NOLOAD (0x0002) /* "noload": allocated, relocated, not loaded */
#define STYP_GROUP (0x0004) /* "grouped": formed of input sections */
#define STYP_PAD (0x0008) /* "padding": not allocated, not relocated, loaded */
#define STYP_COPY (0x0010) /* "copy": for decision function used by field update; not allocated, not relocated,
loaded; reloc & lineno entries processed normally */
#define STYP_TEXT (0x0020) /* section contains text only */
#define S_SHRSEG (0x0020) /* In 3b Update files (output of ogen), sections which appear in SHARED segments of the Pfile
will have the S_SHRSEG flag set by ogen, to inform dufr that updating 1 copy of the proc. will
update all process invocations. */
#define STYP_DATA (0x0040) /* section contains data only */
#define STYP_BSS (0x0080) /* section contains bss only */
#define S_NEWFCN (0x0100) /* In a minimal file or an update file, a new function (as compared with a replaced function) */
#define STYP_INFO (0x0200) /* comment: not allocated not relocated, not loaded */
#define STYP_OVER (0x0400) /* overlay: relocated not allocated or loaded */
#define STYP_LIB (0x0800) /* for .lib: same as INFO */
#define STYP_MERGE (0x2000) /* merge section -- combines with text, data or bss sections only */
#define STYP_REVERSE_PAD (0x4000) /* section will be padded with no-op instructions
wherever padding is necessary and there is a
word of contiguous bytes beginning on a word
boundary. */
#define STYP_LIT 0x8020 /* Literal data (like STYP_TEXT) */
/********************** LINE NUMBERS **********************/
/* 1 line number entry for every "breakpointable" source line in a section.
Line numbers are grouped on a per function basis; first entry in a function
grouping will have l_lnno = 0 and in place of physical address will be the
symbol table index of the function name. */
struct internal_lineno
{
union
{
bfd_signed_vma l_symndx; /* function name symbol index, iff l_lnno == 0*/
bfd_signed_vma l_paddr; /* (physical) address of line number */
} l_addr;
unsigned long l_lnno; /* line number */
};
/********************** SYMBOLS **********************/
#define SYMNMLEN 8 /* # characters in a symbol name */
#define FILNMLEN 14 /* # characters in a file name */
#define DIMNUM 4 /* # array dimensions in auxiliary entry */
struct internal_syment
{
union
{
char _n_name[SYMNMLEN]; /* old COFF version */
struct
{
bfd_hostptr_t _n_zeroes; /* new == 0 */
bfd_hostptr_t _n_offset; /* offset into string table */
} _n_n;
char *_n_nptr[2]; /* allows for overlaying */
} _n;
bfd_vma n_value; /* value of symbol */
short n_scnum; /* section number */
unsigned short n_flags; /* copy of flags from filhdr */
unsigned short n_type; /* type and derived type */
unsigned char n_sclass; /* storage class */
unsigned char n_numaux; /* number of aux. entries */
};
#define n_name _n._n_name
#define n_zeroes _n._n_n._n_zeroes
#define n_offset _n._n_n._n_offset
/* Relocatable symbols have number of the section in which they are defined,
or one of the following: */
#define N_UNDEF ((short)0) /* undefined symbol */
#define N_ABS ((short)-1) /* value of symbol is absolute */
#define N_DEBUG ((short)-2) /* debugging symbol -- value is meaningless */
#define N_TV ((short)-3) /* indicates symbol needs preload transfer vector */
#define P_TV ((short)-4) /* indicates symbol needs postload transfer vector*/
/* Type of a symbol, in low N bits of the word. */
#define T_NULL 0
#define T_VOID 1 /* function argument (only used by compiler) */
#define T_CHAR 2 /* character */
#define T_SHORT 3 /* short integer */
#define T_INT 4 /* integer */
#define T_LONG 5 /* long integer */
#define T_FLOAT 6 /* floating point */
#define T_DOUBLE 7 /* double word */
#define T_STRUCT 8 /* structure */
#define T_UNION 9 /* union */
#define T_ENUM 10 /* enumeration */
#define T_MOE 11 /* member of enumeration*/
#define T_UCHAR 12 /* unsigned character */
#define T_USHORT 13 /* unsigned short */
#define T_UINT 14 /* unsigned integer */
#define T_ULONG 15 /* unsigned long */
#define T_LNGDBL 16 /* long double */
/* Derived types, in n_type. */
#define DT_NON (0) /* no derived type */
#define DT_PTR (1) /* pointer */
#define DT_FCN (2) /* function */
#define DT_ARY (3) /* array */
#define BTYPE(x) ((x) & N_BTMASK)
#define DTYPE(x) (((x) & N_TMASK) >> N_BTSHFT)
#define ISPTR(x) \
(((unsigned long) (x) & N_TMASK) == ((unsigned long) DT_PTR << N_BTSHFT))
#define ISFCN(x) \
(((unsigned long) (x) & N_TMASK) == ((unsigned long) DT_FCN << N_BTSHFT))
#define ISARY(x) \
(((unsigned long) (x) & N_TMASK) == ((unsigned long) DT_ARY << N_BTSHFT))
#define ISTAG(x) \
((x) == C_STRTAG || (x) == C_UNTAG || (x) == C_ENTAG)
#define DECREF(x) \
((((x) >> N_TSHIFT) & ~ N_BTMASK) | ((x) & N_BTMASK))
union internal_auxent
{
struct
{
union
{
long l; /* str, un, or enum tag indx */
struct coff_ptr_struct *p;
} x_tagndx;
union
{
struct
{
unsigned short x_lnno; /* declaration line number */
unsigned short x_size; /* str/union/array size */
} x_lnsz;
long x_fsize; /* size of function */
} x_misc;
union
{
struct
{ /* if ISFCN, tag, or .bb */
bfd_signed_vma x_lnnoptr; /* ptr to fcn line # */
union
{ /* entry ndx past block end */
long l;
struct coff_ptr_struct *p;
} x_endndx;
} x_fcn;
struct
{ /* if ISARY, up to 4 dimen. */
unsigned short x_dimen[DIMNUM];
} x_ary;
} x_fcnary;
unsigned short x_tvndx; /* tv index */
} x_sym;
union
{
char x_fname[FILNMLEN];
struct
{
long x_zeroes;
long x_offset;
} x_n;
} x_file;
struct
{
long x_scnlen; /* section length */
unsigned short x_nreloc; /* # relocation entries */
unsigned short x_nlinno; /* # line numbers */
unsigned long x_checksum; /* section COMDAT checksum for PE */
unsigned short x_associated; /* COMDAT associated section index for PE */
unsigned char x_comdat; /* COMDAT selection number for PE */
} x_scn;
struct
{
long x_tvfill; /* tv fill value */
unsigned short x_tvlen; /* length of .tv */
unsigned short x_tvran[2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
/******************************************
* RS/6000-specific auxent - last auxent for every external symbol
******************************************/
struct
{
union
{ /* csect length or enclosing csect */
bfd_signed_vma l;
struct coff_ptr_struct *p;
} x_scnlen;
long x_parmhash; /* parm type hash index */
unsigned short x_snhash; /* sect num with parm hash */
unsigned char x_smtyp; /* symbol align and type */
/* 0-4 - Log 2 of alignment */
/* 5-7 - symbol type */
unsigned char x_smclas; /* storage mapping class */
long x_stab; /* dbx stab info index */
unsigned short x_snstab; /* sect num with dbx stab */
} x_csect; /* csect definition information */
/* x_smtyp values: */
#define SMTYP_ALIGN(x) ((x) >> 3) /* log2 of alignment */
#define SMTYP_SMTYP(x) ((x) & 0x7) /* symbol type */
/* Symbol type values: */
#define XTY_ER 0 /* External reference */
#define XTY_SD 1 /* Csect definition */
#define XTY_LD 2 /* Label definition */
#define XTY_CM 3 /* .BSS */
#define XTY_EM 4 /* Error message */
#define XTY_US 5 /* "Reserved for internal use" */
/* x_smclas values: */
#define XMC_PR 0 /* Read-only program code */
#define XMC_RO 1 /* Read-only constant */
#define XMC_DB 2 /* Read-only debug dictionary table */
#define XMC_TC 3 /* Read-write general TOC entry */
#define XMC_UA 4 /* Read-write unclassified */
#define XMC_RW 5 /* Read-write data */
#define XMC_GL 6 /* Read-only global linkage */
#define XMC_XO 7 /* Read-only extended operation */
#define XMC_SV 8 /* Read-only supervisor call */
#define XMC_BS 9 /* Read-write BSS */
#define XMC_DS 10 /* Read-write descriptor csect */
#define XMC_UC 11 /* Read-write unnamed Fortran common */
#define XMC_TI 12 /* Read-only traceback index csect */
#define XMC_TB 13 /* Read-only traceback table csect */
/* 14 ??? */
#define XMC_TC0 15 /* Read-write TOC anchor */
#define XMC_TD 16 /* Read-write data in TOC */
/******************************************
* I960-specific *2nd* aux. entry formats
******************************************/
struct
{
/* This is a very old typo that keeps getting propagated. */
#define x_stdindx x_stindx
long x_stindx; /* sys. table entry */
} x_sc; /* system call entry */
struct
{
unsigned long x_balntry; /* BAL entry point */
} x_bal; /* BAL-callable function */
struct
{
unsigned long x_timestamp; /* time stamp */
char x_idstring[20]; /* producer identity string */
} x_ident; /* Producer ident info */
};
/********************** RELOCATION DIRECTIVES **********************/
struct internal_reloc
{
bfd_vma r_vaddr; /* Virtual address of reference */
long r_symndx; /* Index into symbol table */
unsigned short r_type; /* Relocation type */
unsigned char r_size; /* Used by RS/6000 and ECOFF */
unsigned char r_extern; /* Used by ECOFF */
unsigned long r_offset; /* Used by Alpha ECOFF, SPARC, others */
};
/* X86-64 relocations. */
#define R_AMD64_ABS 0 /* Reference is absolute, no relocation is necessary. */
#define R_AMD64_DIR64 1 /* 64-bit address (VA). */
#define R_AMD64_DIR32 2 /* 32-bit address (VA) R_DIR32. */
#define R_AMD64_IMAGEBASE 3 /* 32-bit absolute ref w/o base R_IMAGEBASE. */
#define R_AMD64_PCRLONG 4 /* 32-bit relative address from byte following reloc R_PCRLONG. */
#define R_AMD64_PCRLONG_1 5 /* 32-bit relative address from byte distance 1 from reloc. */
#define R_AMD64_PCRLONG_2 6 /* 32-bit relative address from byte distance 2 from reloc. */
#define R_AMD64_PCRLONG_3 7 /* 32-bit relative address from byte distance 3 from reloc. */
#define R_AMD64_PCRLONG_4 8 /* 32-bit relative address from byte distance 4 from reloc. */
#define R_AMD64_PCRLONG_5 9 /* 32-bit relative address from byte distance 5 from reloc. */
#define R_AMD64_SECTION 10 /* Section index. */
#define R_AMD64_SECREL 11 /* 32 bit offset from base of section containing target R_SECREL. */
#define R_AMD64_SECREL7 12 /* 7 bit unsigned offset from base of section containing target. */
#define R_AMD64_TOKEN 13 /* 32 bit metadata token. */
#define R_AMD64_PCRQUAD 14 /* Pseude PC64 relocation - Note: not specified by MS/AMD but need for gas pc-relative 64bit wide relocation generated by ELF. */
/* i386 Relocations. */
#define R_DIR16 1
#define R_REL24 5
#define R_DIR32 6
#define R_IMAGEBASE 7
#define R_SECREL32 11
#define R_RELBYTE 15
#define R_RELWORD 16
#define R_RELLONG 17
#define R_PCRBYTE 18
#define R_PCRWORD 19
#define R_PCRLONG 20
#define R_PCR24 21
#define R_IPRSHORT 24
#define R_IPRLONG 26
#define R_GETSEG 29
#define R_GETPA 30
#define R_TAGWORD 31
#define R_JUMPTARG 32 /* strange 29k 00xx00xx reloc */
#define R_PARTLS16 32
#define R_PARTMS8 33
#define R_PCR16L 128
#define R_PCR26L 129
#define R_VRT16 130
#define R_HVRT16 131
#define R_LVRT16 132
#define R_VRT32 133
/* This reloc identifies mov.b instructions with a 16bit absolute
address. The linker tries to turn insns with this reloc into
an absolute 8-bit address. */
#define R_MOV16B1 0x41
/* This reloc identifies mov.b instructions which had a 16bit
absolute address which have been shortened into a 8-bit
absolute address. */
#define R_MOV16B2 0x42
/* This reloc identifies jmp insns with a 16bit target address;
the linker tries to turn these insns into bra insns with
an 8bit pc-relative target. */
#define R_JMP1 0x43
/* This reloc identifies a bra with an 8-bit pc-relative
target that was formerly a jmp insn with a 16bit target. */
#define R_JMP2 0x44
/* ??? */
#define R_RELLONG_NEG 0x45
/* This reloc identifies jmp insns with a 24bit target address;
the linker tries to turn these insns into bra insns with
an 8bit pc-relative target. */
#define R_JMPL1 0x46
/* This reloc identifies a bra with an 8-bit pc-relative
target that was formerly a jmp insn with a 24bit target. */
#define R_JMPL2 0x47
/* This reloc identifies mov.b instructions with a 24bit absolute
address. The linker tries to turn insns with this reloc into
an absolute 8-bit address. */
#define R_MOV24B1 0x48
/* This reloc identifies mov.b instructions which had a 24bit
absolute address which have been shortened into a 8-bit
absolute address. */
#define R_MOV24B2 0x49
/* An h8300 memory indirect jump/call. Forces the address of the jump/call
target into the function vector (in page zero), and the address of the
vector entry to be placed in the jump/call instruction. */
#define R_MEM_INDIRECT 0x4a
/* This reloc identifies a 16bit pc-relative branch target which was
shortened into an 8bit pc-relative branch target. */
#define R_PCRWORD_B 0x4b
/* This reloc identifies mov.[wl] instructions with a 32/24 bit
absolute address; the linker may turn this into a mov.[wl]
insn with a 16bit absolute address. */
#define R_MOVL1 0x4c
/* This reloc identifies mov.[wl] insns which formerly had
a 32/24bit absolute address and now have a 16bit absolute address. */
#define R_MOVL2 0x4d
/* This reloc identifies a bCC:8 which will have it's condition
inverted and its target redirected to the target of the branch
in the following insn. */
#define R_BCC_INV 0x4e
/* This reloc identifies a jmp instruction that has been deleted. */
#define R_JMP_DEL 0x4f
/* Z8k modes */
#define R_IMM16 0x01 /* 16 bit abs */
#define R_JR 0x02 /* jr 8 bit disp */
#define R_IMM4L 0x23 /* low nibble */
#define R_IMM8 0x22 /* 8 bit abs */
#define R_IMM32 R_RELLONG /* 32 bit abs */
#define R_CALL R_DA /* Absolute address which could be a callr */
#define R_JP R_DA /* Absolute address which could be a jp */
#define R_REL16 0x04 /* 16 bit PC rel */
#define R_CALLR 0x05 /* callr 12 bit disp */
#define R_SEG 0x10 /* set if in segmented mode */
#define R_IMM4H 0x24 /* high nibble */
#define R_DISP7 0x25 /* djnz displacement */
/* Z80 modes */
#define R_OFF8 0x32 /* 8 bit signed abs, for (i[xy]+d) */
#define R_IMM24 0x33 /* 24 bit abs */
/* R_JR, R_IMM8, R_IMM16, R_IMM32 - as for Z8k */
/* H8500 modes */
#define R_H8500_IMM8 1 /* 8 bit immediate */
#define R_H8500_IMM16 2 /* 16 bit immediate */
#define R_H8500_PCREL8 3 /* 8 bit pcrel */
#define R_H8500_PCREL16 4 /* 16 bit pcrel */
#define R_H8500_HIGH8 5 /* high 8 bits of 24 bit address */
#define R_H8500_LOW16 7 /* low 16 bits of 24 bit immediate */
#define R_H8500_IMM24 6 /* 24 bit immediate */
#define R_H8500_IMM32 8 /* 32 bit immediate */
#define R_H8500_HIGH16 9 /* high 16 bits of 32 bit immediate */
/* W65 modes */
#define R_W65_ABS8 1 /* addr & 0xff */
#define R_W65_ABS16 2 /* addr & 0xffff */
#define R_W65_ABS24 3 /* addr & 0xffffff */
#define R_W65_ABS8S8 4 /* (addr >> 8) & 0xff */
#define R_W65_ABS8S16 5 /* (addr >> 16) & 0xff */
#define R_W65_ABS16S8 6 /* (addr >> 8) & 0ffff */
#define R_W65_ABS16S16 7 /* (addr >> 16) & 0ffff */
#define R_W65_PCR8 8
#define R_W65_PCR16 9
#define R_W65_DP 10 /* direct page 8 bits only */
#endif /* GNU_COFF_INTERNAL_H */

82
coff/m68k.h Normal file
View file

@ -0,0 +1,82 @@
/* coff information for M68K
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef GNU_COFF_M68K_H
#define GNU_COFF_M68K_H 1
#define L_LNNO_SIZE 2
#include "coff/external.h"
/* Motorola 68000/68008/68010/68020 */
#define MC68MAGIC 0520
#define MC68KWRMAGIC 0520 /* writeable text segments */
#define MC68TVMAGIC 0521
#define MC68KROMAGIC 0521 /* readonly shareable text segments */
#define MC68KPGMAGIC 0522 /* demand paged text segments */
#define M68MAGIC 0210
#define M68TVMAGIC 0211
/* This is the magic of the Bull dpx/2 */
#define MC68KBCSMAGIC 0526
/* This is Lynx's all-platform magic number for executables. */
#define LYNXCOFFMAGIC 0415
#define OMAGIC M68MAGIC
/* This intentionally does not include MC68KBCSMAGIC; it only includes
magic numbers which imply that names do not have underscores. */
#define M68KBADMAG(x) (((x).f_magic != MC68MAGIC) \
&& ((x).f_magic != MC68KWRMAGIC) \
&& ((x).f_magic != MC68TVMAGIC) \
&& ((x).f_magic != MC68KROMAGIC) \
&& ((x).f_magic != MC68KPGMAGIC) \
&& ((x).f_magic != M68MAGIC) \
&& ((x).f_magic != M68TVMAGIC) \
&& ((x).f_magic != LYNXCOFFMAGIC))
/* Magic numbers for the a.out header. */
#define PAGEMAGICEXECSWAPPED 0407 /* executable (swapped) */
#define PAGEMAGICPEXECSWAPPED 0410 /* pure executable (swapped) */
#define PAGEMAGICPEXECTSHLIB 0443 /* pure executable (target shared library) */
#define PAGEMAGICPEXECPAGED 0413 /* pure executable (paged) */
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
#ifdef M68K_COFF_OFFSET
char r_offset[4];
#endif
};
#define RELOC struct external_reloc
#ifdef M68K_COFF_OFFSET
#define RELSZ 14
#else
#define RELSZ 10
#endif
#endif /* GNU_COFF_M68K_H */

197
coff/m88k.h Normal file
View file

@ -0,0 +1,197 @@
/* coff information for 88k bcs
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define DO_NOT_DEFINE_SCNHDR
#define L_LNNO_SIZE 4
#define DO_NOT_DEFINE_SYMENT
#define DO_NOT_DEFINE_AUXENT
#include "coff/external.h"
#define MC88MAGIC 0540 /* 88k BCS executable */
#define MC88DMAGIC 0541 /* DG/UX executable */
#define MC88OMAGIC 0555 /* Object file */
#define MC88BADMAG(x) (((x).f_magic != MC88MAGIC) \
&& ((x).f_magic != MC88DMAGIC) \
&& ((x).f_magic != MC88OMAGIC))
#define PAGEMAGIC3 0414 /* Split i&d, zero mapped */
#define PAGEMAGICBCS 0413
/********************** SECTION HEADER **********************/
struct external_scnhdr
{
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[4]; /* number of relocation entries */
char s_nlnno[4]; /* number of line number entries*/
char s_flags[4]; /* flags */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 44
/* Names of "special" sections. */
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _COMMENT ".comment"
/********************** SYMBOLS **********************/
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
struct external_syment
{
union
{
char e_name[E_SYMNMLEN];
struct
{
char e_zeroes[4];
char e_offset[4];
} e;
} e;
char e_value[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
char pad2[2];
};
#define N_BTMASK 017
#define N_TMASK 060
#define N_BTSHFT 4
#define N_TSHIFT 2
/* Note that this isn't the same shape as other coffs */
union external_auxent
{
struct
{
char x_tagndx[4]; /* str, un, or enum tag indx */
/* 4 */
union
{
char x_fsize[4]; /* size of function */
struct
{
char x_lnno[4]; /* declaration line number */
char x_size[4]; /* str/union/array size */
} x_lnsz;
} x_misc;
/* 12 */
union
{
struct /* if ISFCN, tag, or .bb */
{
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
struct /* if ISARY, up to 4 dimen. */
{
char x_dimen[E_DIMNUM][2];
} x_ary;
} x_fcnary;
/* 20 */
} x_sym;
union
{
char x_fname[E_FILNMLEN];
struct
{
char x_zeroes[4];
char x_offset[4];
} x_n;
} x_file;
struct
{
char x_scnlen[4]; /* section length */
char x_nreloc[4]; /* # relocation entries */
char x_nlinno[4]; /* # line numbers */
} x_scn;
struct
{
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
};
#define GET_LNSZ_SIZE(abfd, ext) \
H_GET_32 (abfd, ext->x_sym.x_misc.x_lnsz.x_size)
#define GET_LNSZ_LNNO(abfd, ext) \
H_GET_32 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno)
#define PUT_LNSZ_LNNO(abfd, in, ext) \
H_PUT_32 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno)
#define PUT_LNSZ_SIZE(abfd, in, ext) \
H_PUT_32 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_size)
#define GET_SCN_NRELOC(abfd, ext) \
H_GET_32 (abfd, ext->x_scn.x_nreloc)
#define GET_SCN_NLINNO(abfd, ext) \
H_GET_32 (abfd, ext->x_scn.x_nlinno)
#define PUT_SCN_NRELOC(abfd, in, ext) \
H_PUT_32 (abfd, in, ext->x_scn.x_nreloc)
#define PUT_SCN_NLINNO(abfd, in, ext) \
H_PUT_32 (abfd,in, ext->x_scn.x_nlinno)
#define SYMENT struct external_syment
#define SYMESZ 20
#define AUXENT union external_auxent
#define AUXESZ 20
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
char r_offset[2];
};
#define RELOC struct external_reloc
#define RELSZ 12
#define NO_TVNDX

72
coff/mcore.h Normal file
View file

@ -0,0 +1,72 @@
/* Motorola MCore support for BFD.
Copyright 1999, 2000, 2010 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* This file holds definitions specific to the MCore COFF/PE ABI. */
#ifndef _COFF_MORE_H
#define _COFF_MORE_H
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#define L_LNNO_SIZE 2
#include "coff/external.h"
#define MCOREMAGIC 0xb00 /* I just made this up */
#define MCOREBADMAG(x) (((x).f_magic != MCOREMAGIC))
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
#define IMAGE_REL_MCORE_ABSOLUTE 0x0000
#define IMAGE_REL_MCORE_ADDR32 0x0001
#define IMAGE_REL_MCORE_PCREL_IMM8BY4 0x0002
#define IMAGE_REL_MCORE_PCREL_IMM11BY2 0x0003
#define IMAGE_REL_MCORE_PCREL_IMM4BY2 0x0004
#define IMAGE_REL_MCORE_PCREL_32 0x0005
#define IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2 0x0006
#define IMAGE_REL_MCORE_RVA 0x0007
#define PEMCORE
#define OMAGIC 0404 /* object files, eg as output */
#define ZMAGIC 0413 /* demand load format, eg normal ld output */
#define STMAGIC 0401 /* target shlib */
#define SHMAGIC 0443 /* host shlib */
/* From winnt.h */
#define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
/* Define some NT default values. */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
struct external_reloc
{
char r_vaddr [4];
char r_symndx [4];
char r_type [2];
char r_offset [4];
};
#define RELOC struct external_reloc
#define RELSZ 14
#endif /* __COFF_MCORE_H */

344
coff/mips.h Normal file
View file

@ -0,0 +1,344 @@
/* ECOFF support on MIPS machines.
coff/ecoff.h must be included before this file.
Copyright 1999, 2004, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define DO_NOT_DEFINE_AOUTHDR
#define L_LNNO_SIZE 4
#include "coff/external.h"
/* Magic numbers are defined in coff/ecoff.h. */
#define MIPS_ECOFF_BADMAG(x) (((x).f_magic!=MIPS_MAGIC_1) && \
((x).f_magic!=MIPS_MAGIC_LITTLE) &&\
((x).f_magic!=MIPS_MAGIC_BIG) && \
((x).f_magic!=MIPS_MAGIC_LITTLE2) && \
((x).f_magic!=MIPS_MAGIC_BIG2) && \
((x).f_magic!=MIPS_MAGIC_LITTLE3) && \
((x).f_magic!=MIPS_MAGIC_BIG3))
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct external_aouthdr
{
unsigned char magic[2]; /* type of file */
unsigned char vstamp[2]; /* version stamp */
unsigned char tsize[4]; /* text size in bytes, padded to FW bdry*/
unsigned char dsize[4]; /* initialized data " " */
unsigned char bsize[4]; /* uninitialized data " " */
unsigned char entry[4]; /* entry pt. */
unsigned char text_start[4]; /* base of text used for this file */
unsigned char data_start[4]; /* base of data used for this file */
unsigned char bss_start[4]; /* base of bss used for this file */
unsigned char gprmask[4]; /* ?? */
unsigned char cprmask[4][4]; /* ?? */
unsigned char gp_value[4]; /* value for gp register */
} AOUTHDR;
/* compute size of a header */
#define AOUTSZ 56
#define AOUTHDRSZ 56
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
unsigned char r_vaddr[4];
unsigned char r_bits[4];
};
#define RELOC struct external_reloc
#define RELSZ 8
/* MIPS ECOFF uses a packed 8 byte format for relocs. These constants
are used to unpack the r_bits field. */
#define RELOC_BITS0_SYMNDX_SH_LEFT_BIG 16
#define RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE 0
#define RELOC_BITS1_SYMNDX_SH_LEFT_BIG 8
#define RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE 8
#define RELOC_BITS2_SYMNDX_SH_LEFT_BIG 0
#define RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE 16
/* Originally, ECOFF used four bits for the reloc type and had three
reserved bits. Irix 4 added another bit for the reloc type, which
was easy because it was big endian and one of the spare bits became
the new most significant bit. To make this also work for little
endian ECOFF, we need to wrap one of the reserved bits around to
become the most significant bit of the reloc type. */
#define RELOC_BITS3_TYPE_BIG 0x3E
#define RELOC_BITS3_TYPE_SH_BIG 1
#define RELOC_BITS3_TYPE_LITTLE 0x78
#define RELOC_BITS3_TYPE_SH_LITTLE 3
#define RELOC_BITS3_TYPEHI_LITTLE 0x04
#define RELOC_BITS3_TYPEHI_SH_LITTLE 2
#define RELOC_BITS3_EXTERN_BIG 0x01
#define RELOC_BITS3_EXTERN_LITTLE 0x80
/* The r_type field in a reloc is one of the following values. I
don't know if any other values can appear. These seem to be all
that occur in the Ultrix 4.2 libraries. */
#define MIPS_R_IGNORE 0
#define MIPS_R_REFHALF 1
#define MIPS_R_REFWORD 2
#define MIPS_R_JMPADDR 3
#define MIPS_R_REFHI 4
#define MIPS_R_REFLO 5
#define MIPS_R_GPREL 6
#define MIPS_R_LITERAL 7
/* FIXME: This relocation is used (internally only) to represent branches
when assembling. It should never appear in output files, and
be removed. (It used to be used for embedded-PIC support.) */
#define MIPS_R_PCREL16 12
/********************** STABS **********************/
#define MIPS_IS_STAB ECOFF_IS_STAB
#define MIPS_MARK_STAB ECOFF_MARK_STAB
#define MIPS_UNMARK_STAB ECOFF_UNMARK_STAB
/********************** SYMBOLIC INFORMATION **********************/
/* Written by John Gilmore. */
/* ECOFF uses COFF-like section structures, but its own symbol format.
This file defines the symbol format in fields whose size and alignment
will not vary on different host systems. */
/* File header as a set of bytes */
struct hdr_ext
{
unsigned char h_magic[2];
unsigned char h_vstamp[2];
unsigned char h_ilineMax[4];
unsigned char h_cbLine[4];
unsigned char h_cbLineOffset[4];
unsigned char h_idnMax[4];
unsigned char h_cbDnOffset[4];
unsigned char h_ipdMax[4];
unsigned char h_cbPdOffset[4];
unsigned char h_isymMax[4];
unsigned char h_cbSymOffset[4];
unsigned char h_ioptMax[4];
unsigned char h_cbOptOffset[4];
unsigned char h_iauxMax[4];
unsigned char h_cbAuxOffset[4];
unsigned char h_issMax[4];
unsigned char h_cbSsOffset[4];
unsigned char h_issExtMax[4];
unsigned char h_cbSsExtOffset[4];
unsigned char h_ifdMax[4];
unsigned char h_cbFdOffset[4];
unsigned char h_crfd[4];
unsigned char h_cbRfdOffset[4];
unsigned char h_iextMax[4];
unsigned char h_cbExtOffset[4];
};
/* File descriptor external record */
struct fdr_ext
{
unsigned char f_adr[4];
unsigned char f_rss[4];
unsigned char f_issBase[4];
unsigned char f_cbSs[4];
unsigned char f_isymBase[4];
unsigned char f_csym[4];
unsigned char f_ilineBase[4];
unsigned char f_cline[4];
unsigned char f_ioptBase[4];
unsigned char f_copt[4];
unsigned char f_ipdFirst[2];
unsigned char f_cpd[2];
unsigned char f_iauxBase[4];
unsigned char f_caux[4];
unsigned char f_rfdBase[4];
unsigned char f_crfd[4];
unsigned char f_bits1[1];
unsigned char f_bits2[3];
unsigned char f_cbLineOffset[4];
unsigned char f_cbLine[4];
};
#define FDR_BITS1_LANG_BIG 0xF8
#define FDR_BITS1_LANG_SH_BIG 3
#define FDR_BITS1_LANG_LITTLE 0x1F
#define FDR_BITS1_LANG_SH_LITTLE 0
#define FDR_BITS1_FMERGE_BIG 0x04
#define FDR_BITS1_FMERGE_LITTLE 0x20
#define FDR_BITS1_FREADIN_BIG 0x02
#define FDR_BITS1_FREADIN_LITTLE 0x40
#define FDR_BITS1_FBIGENDIAN_BIG 0x01
#define FDR_BITS1_FBIGENDIAN_LITTLE 0x80
#define FDR_BITS2_GLEVEL_BIG 0xC0
#define FDR_BITS2_GLEVEL_SH_BIG 6
#define FDR_BITS2_GLEVEL_LITTLE 0x03
#define FDR_BITS2_GLEVEL_SH_LITTLE 0
/* We ignore the `reserved' field in bits2. */
/* Procedure descriptor external record */
struct pdr_ext
{
unsigned char p_adr[4];
unsigned char p_isym[4];
unsigned char p_iline[4];
unsigned char p_regmask[4];
unsigned char p_regoffset[4];
unsigned char p_iopt[4];
unsigned char p_fregmask[4];
unsigned char p_fregoffset[4];
unsigned char p_frameoffset[4];
unsigned char p_framereg[2];
unsigned char p_pcreg[2];
unsigned char p_lnLow[4];
unsigned char p_lnHigh[4];
unsigned char p_cbLineOffset[4];
};
/* Runtime procedure table */
struct rpdr_ext
{
unsigned char p_adr[4];
unsigned char p_regmask[4];
unsigned char p_regoffset[4];
unsigned char p_fregmask[4];
unsigned char p_fregoffset[4];
unsigned char p_frameoffset[4];
unsigned char p_framereg[2];
unsigned char p_pcreg[2];
unsigned char p_irpss[4];
unsigned char p_reserved[4];
unsigned char p_exception_info[4];
};
/* Line numbers */
struct line_ext
{
unsigned char l_line[4];
};
/* Symbol external record */
struct sym_ext
{
unsigned char s_iss[4];
unsigned char s_value[4];
unsigned char s_bits1[1];
unsigned char s_bits2[1];
unsigned char s_bits3[1];
unsigned char s_bits4[1];
};
#define SYM_BITS1_ST_BIG 0xFC
#define SYM_BITS1_ST_SH_BIG 2
#define SYM_BITS1_ST_LITTLE 0x3F
#define SYM_BITS1_ST_SH_LITTLE 0
#define SYM_BITS1_SC_BIG 0x03
#define SYM_BITS1_SC_SH_LEFT_BIG 3
#define SYM_BITS1_SC_LITTLE 0xC0
#define SYM_BITS1_SC_SH_LITTLE 6
#define SYM_BITS2_SC_BIG 0xE0
#define SYM_BITS2_SC_SH_BIG 5
#define SYM_BITS2_SC_LITTLE 0x07
#define SYM_BITS2_SC_SH_LEFT_LITTLE 2
#define SYM_BITS2_RESERVED_BIG 0x10
#define SYM_BITS2_RESERVED_LITTLE 0x08
#define SYM_BITS2_INDEX_BIG 0x0F
#define SYM_BITS2_INDEX_SH_LEFT_BIG 16
#define SYM_BITS2_INDEX_LITTLE 0xF0
#define SYM_BITS2_INDEX_SH_LITTLE 4
#define SYM_BITS3_INDEX_SH_LEFT_BIG 8
#define SYM_BITS3_INDEX_SH_LEFT_LITTLE 4
#define SYM_BITS4_INDEX_SH_LEFT_BIG 0
#define SYM_BITS4_INDEX_SH_LEFT_LITTLE 12
/* External symbol external record */
struct ext_ext
{
unsigned char es_bits1[1];
unsigned char es_bits2[1];
unsigned char es_ifd[2];
struct sym_ext es_asym;
};
#define EXT_BITS1_JMPTBL_BIG 0x80
#define EXT_BITS1_JMPTBL_LITTLE 0x01
#define EXT_BITS1_COBOL_MAIN_BIG 0x40
#define EXT_BITS1_COBOL_MAIN_LITTLE 0x02
#define EXT_BITS1_WEAKEXT_BIG 0x20
#define EXT_BITS1_WEAKEXT_LITTLE 0x04
/* Dense numbers external record */
struct dnr_ext
{
unsigned char d_rfd[4];
unsigned char d_index[4];
};
/* Relative file descriptor */
struct rfd_ext
{
unsigned char rfd[4];
};
/* Optimizer symbol external record */
struct opt_ext
{
unsigned char o_bits1[1];
unsigned char o_bits2[1];
unsigned char o_bits3[1];
unsigned char o_bits4[1];
struct rndx_ext o_rndx;
unsigned char o_offset[4];
};
#define OPT_BITS2_VALUE_SH_LEFT_BIG 16
#define OPT_BITS2_VALUE_SH_LEFT_LITTLE 0
#define OPT_BITS3_VALUE_SH_LEFT_BIG 8
#define OPT_BITS3_VALUE_SH_LEFT_LITTLE 8
#define OPT_BITS4_VALUE_SH_LEFT_BIG 0
#define OPT_BITS4_VALUE_SH_LEFT_LITTLE 16

67
coff/mipspe.h Normal file
View file

@ -0,0 +1,67 @@
/* coff information for Windows CE with MIPS VR4111
Copyright 2000, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 2
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
#define MIPS_ARCH_MAGIC_WINCE 0x0166 /* Windows CE - little endian */
#define MIPS_PE_MAGIC 0x010b
#define MIPSBADMAG(x) ((x).f_magic != MIPS_ARCH_MAGIC_WINCE)
/* define some NT default values */
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the h8 don't have room in the instruction for the entire
offset - eg the strange jump and high page addressing modes. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10
/* MIPS PE relocation types. */
#define MIPS_R_ABSOLUTE 0 /* ignored */
#define MIPS_R_REFHALF 1
#define MIPS_R_REFWORD 2
#define MIPS_R_JMPADDR 3
#define MIPS_R_REFHI 4 /* PAIR follows */
#define MIPS_R_REFLO 5
#define MIPS_R_GPREL 6
#define MIPS_R_LITERAL 7 /* same as GPREL */
#define MIPS_R_SECTION 10
#define MIPS_R_SECREL 11
#define MIPS_R_SECRELLO 12
#define MIPS_R_SECRELHI 13 /* PAIR follows */
#define MIPS_R_RVA 34 /* 0x22 */
#define MIPS_R_PAIR 37 /* 0x25 - symndx is really a signed 16-bit addend */

288
coff/or32.h Normal file
View file

@ -0,0 +1,288 @@
/* COFF specification for OpenRISC 1000.
Copyright (C) 1993-2000, 2002, 2010 Free Software Foundation, Inc.
Contributed by David Wood @ New York University.
Modified by Johan Rydberg, <johan.rydberg@netinsight.se>
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef OR32
# define OR32
#endif
/* File Header and related definitions. */
struct external_filehdr
{
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
};
#define FILHDR struct external_filehdr
#define FILHSZ 20
/* Magic numbers for OpenRISC 1000. As it is know we use the
numbers for Am29000.
(AT&T will assign the "real" magic number). */
#define SIPFBOMAGIC 0572 /* Am29000 (Byte 0 is MSB). */
#define SIPRBOMAGIC 0573 /* Am29000 (Byte 0 is LSB). */
#define OR32_MAGIC_BIG SIPFBOMAGIC
#define OR32_MAGIC_LITTLE SIPRBOMAGIC
#define OR32BADMAG(x) (((x).f_magic!=OR32_MAGIC_BIG) && \
((x).f_magic!=OR32_MAGIC_LITTLE))
#define OMAGIC OR32_MAGIC_BIG
/* Optional (a.out) header. */
typedef struct external_aouthdr
{
char magic[2]; /* type of file */
char vstamp[2]; /* version stamp */
char tsize[4]; /* text size in bytes, padded to FW bdry */
char dsize[4]; /* initialized data " " */
char bsize[4]; /* uninitialized data " " */
char entry[4]; /* entry pt. */
char text_start[4]; /* base of text used for this file */
char data_start[4]; /* base of data used for this file */
} AOUTHDR;
#define AOUTSZ 28
#define AOUTHDRSZ 28
/* aouthdr magic numbers. */
#define NMAGIC 0410 /* separate i/d executable. */
#define SHMAGIC 0406 /* NYU/Ultra3 shared data executable
(writable text). */
#define _ETEXT "_etext"
/* Section header and related definitions. */
struct external_scnhdr
{
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[2]; /* number of relocation entries */
char s_nlnno[2]; /* number of line number entries */
char s_flags[4]; /* flags */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 40
/* Names of "special" sections: */
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _LIT ".lit"
/* Section types - with additional section type for global
registers which will be relocatable for the OpenRISC 1000.
In instances where it is necessary for a linker to produce an
output file which contains text or data not based at virtual
address 0, e.g. for a ROM, then the linker should accept
address base information as command input and use PAD sections
to skip over unused addresses. */
#define STYP_BSSREG 0x1200 /* Global register area (like STYP_INFO) */
#define STYP_ENVIR 0x2200 /* Environment (like STYP_INFO) */
#define STYP_ABS 0x4000 /* Absolute (allocated, not reloc, loaded) */
/* Relocation information declaration and related definitions: */
struct external_reloc
{
char r_vaddr[4]; /* (virtual) address of reference */
char r_symndx[4]; /* index into symbol table */
char r_type[2]; /* relocation type */
};
#define RELOC struct external_reloc
#define RELSZ 10 /* sizeof (RELOC) */
/* Relocation types for the OpenRISC 1000: */
#define R_ABS 0 /* reference is absolute */
#define R_IREL 030 /* instruction relative (jmp/call) */
#define R_IABS 031 /* instruction absolute (jmp/call) */
#define R_ILOHALF 032 /* instruction low half (const) */
#define R_IHIHALF 033 /* instruction high half (consth) part 1 */
#define R_IHCONST 034 /* instruction high half (consth) part 2 */
/* constant offset of R_IHIHALF relocation */
#define R_BYTE 035 /* relocatable byte value */
#define R_HWORD 036 /* relocatable halfword value */
#define R_WORD 037 /* relocatable word value */
#define R_IGLBLRC 040 /* instruction global register RC */
#define R_IGLBLRA 041 /* instruction global register RA */
#define R_IGLBLRB 042 /* instruction global register RB */
/*
NOTE:
All the "I" forms refer to 29000 instruction formats. The linker is
expected to know how the numeric information is split and/or aligned
within the instruction word(s). R_BYTE works for instructions, too.
If the parameter to a CONSTH instruction is a relocatable type, two
relocation records are written. The first has an r_type of R_IHIHALF
(33 octal) and a normal r_vaddr and r_symndx. The second relocation
record has an r_type of R_IHCONST (34 octal), a normal r_vaddr (which
is redundant), and an r_symndx containing the 32-bit constant offset
to the relocation instead of the actual symbol table index. This
second record is always written, even if the constant offset is zero.
The constant fields of the instruction are set to zero. */
/* Line number entry declaration and related definitions: */
struct external_lineno
{
union
{
char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
char l_paddr[4]; /* (physical) address of line number */
}
l_addr;
char l_lnno[2]; /* line number */
};
#define LINENO struct external_lineno
#define LINESZ 6 /* sizeof (LINENO) */
/* Symbol entry declaration and related definitions: */
#define E_SYMNMLEN 8 /* Number of characters in a symbol name */
struct external_syment
{
union
{
char e_name[E_SYMNMLEN];
struct
{
char e_zeroes[4];
char e_offset[4];
}
e;
}
e;
char e_value[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
};
#define SYMENT struct external_syment
#define SYMESZ 18
/* Storage class definitions - new classes for global registers: */
#define C_GLBLREG 19 /* global register */
#define C_EXTREG 20 /* external global register */
#define C_DEFREG 21 /* ext. def. of global register */
/* Derived symbol mask/shifts: */
#define N_BTMASK (0xf)
#define N_BTSHFT (4)
#define N_TMASK (0x30)
#define N_TSHIFT (2)
/* Auxiliary symbol table entry declaration and related
definitions. */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
union external_auxent
{
struct
{
char x_tagndx[4]; /* str, un, or enum tag indx */
union
{
struct
{
char x_lnno[2]; /* declaration line number */
char x_size[2]; /* str/union/array size */
}
x_lnsz;
char x_fsize[4]; /* size of function */
}
x_misc;
union
{
struct /* if ISFCN, tag, or .bb */
{
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
}
x_fcn;
struct /* if ISARY, up to 4 dimen. */
{
char x_dimen[E_DIMNUM][2];
}
x_ary;
}
x_fcnary;
char x_tvndx[2]; /* tv index */
}
x_sym;
union
{
char x_fname[E_FILNMLEN];
struct
{
char x_zeroes[4];
char x_offset[4];
}
x_n;
}
x_file;
struct
{
char x_scnlen[4]; /* section length */
char x_nreloc[2]; /* # relocation entries */
char x_nlinno[2]; /* # line numbers */
}
x_scn;
struct
{
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
}
x_tv; /* info about .tv section
(in auxent of symbol .tv)) */
};
#define AUXENT union external_auxent
#define AUXESZ 18

512
coff/pe.h Normal file
View file

@ -0,0 +1,512 @@
/* pe.h - PE COFF header information
Copyright 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2009, 2010
Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _PE_H
#define _PE_H
/* NT specific file attributes. */
#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
#define IMAGE_FILE_16BIT_MACHINE 0x0040
#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
#define IMAGE_FILE_32BIT_MACHINE 0x0100
#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
#define IMAGE_FILE_SYSTEM 0x1000
#define IMAGE_FILE_DLL 0x2000
#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
/* DllCharacteristics flag bits. The inconsistent naming may seem
odd, but that is how they are defined in the PE specification. */
#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
/* Additional flags to be set for section headers to allow the NT loader to
read and write to the section data (to replace the addresses of data in
dlls for one thing); also to execute the section in .text's case. */
#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
#define IMAGE_SCN_MEM_EXECUTE 0x20000000
#define IMAGE_SCN_MEM_READ 0x40000000
#define IMAGE_SCN_MEM_WRITE 0x80000000
/* Section characteristics added for ppc-nt. */
#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
#define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
#define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
#define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
#define IMAGE_SCN_MEM_FARDATA 0x00008000
#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
#define IMAGE_SCN_MEM_16BIT 0x00020000
#define IMAGE_SCN_MEM_LOCKED 0x00040000
#define IMAGE_SCN_MEM_PRELOAD 0x00080000
/* Bit position in the s_flags field where the alignment values start. */
#define IMAGE_SCN_ALIGN_POWER_BIT_POS 20
#define IMAGE_SCN_ALIGN_POWER_BIT_MASK 0x00f00000
#define IMAGE_SCN_ALIGN_POWER_NUM(val) \
(((val) >> IMAGE_SCN_ALIGN_POWER_BIT_POS) - 1)
#define IMAGE_SCN_ALIGN_POWER_CONST(val) \
(((val) + 1) << IMAGE_SCN_ALIGN_POWER_BIT_POS)
#define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_POWER_CONST (0)
#define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_POWER_CONST (1)
#define IMAGE_SCN_ALIGN_4BYTES IMAGE_SCN_ALIGN_POWER_CONST (2)
#define IMAGE_SCN_ALIGN_8BYTES IMAGE_SCN_ALIGN_POWER_CONST (3)
/* Default alignment if no others are specified. */
#define IMAGE_SCN_ALIGN_16BYTES IMAGE_SCN_ALIGN_POWER_CONST (4)
#define IMAGE_SCN_ALIGN_32BYTES IMAGE_SCN_ALIGN_POWER_CONST (5)
#define IMAGE_SCN_ALIGN_64BYTES IMAGE_SCN_ALIGN_POWER_CONST (6)
#define IMAGE_SCN_ALIGN_128BYTES IMAGE_SCN_ALIGN_POWER_CONST (7)
#define IMAGE_SCN_ALIGN_256BYTES IMAGE_SCN_ALIGN_POWER_CONST (8)
#define IMAGE_SCN_ALIGN_512BYTES IMAGE_SCN_ALIGN_POWER_CONST (9)
#define IMAGE_SCN_ALIGN_1024BYTES IMAGE_SCN_ALIGN_POWER_CONST (10)
#define IMAGE_SCN_ALIGN_2048BYTES IMAGE_SCN_ALIGN_POWER_CONST (11)
#define IMAGE_SCN_ALIGN_4096BYTES IMAGE_SCN_ALIGN_POWER_CONST (12)
#define IMAGE_SCN_ALIGN_8192BYTES IMAGE_SCN_ALIGN_POWER_CONST (13)
/* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags */
#define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \
((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER)))
#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
#define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
/* COMDAT selection codes. */
#define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */
#define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */
#define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */
#define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */
#define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */
/* Machine numbers. */
#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
#define IMAGE_FILE_MACHINE_ALPHA 0x0184
#define IMAGE_FILE_MACHINE_ALPHA64 0x0284
#define IMAGE_FILE_MACHINE_AM33 0x01d3
#define IMAGE_FILE_MACHINE_AMD64 0x8664
#define IMAGE_FILE_MACHINE_ARM 0x01c0
#define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
#define IMAGE_FILE_MACHINE_CEE 0xc0ee
#define IMAGE_FILE_MACHINE_CEF 0x0cef
#define IMAGE_FILE_MACHINE_EBC 0x0ebc
#define IMAGE_FILE_MACHINE_I386 0x014c
#define IMAGE_FILE_MACHINE_IA64 0x0200
#define IMAGE_FILE_MACHINE_M32R 0x9041
#define IMAGE_FILE_MACHINE_M68K 0x0268
#define IMAGE_FILE_MACHINE_MIPS16 0x0266
#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
#define IMAGE_FILE_MACHINE_POWERPC 0x01f0
#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
#define IMAGE_FILE_MACHINE_R10000 0x0168
#define IMAGE_FILE_MACHINE_R3000 0x0162
#define IMAGE_FILE_MACHINE_R4000 0x0166
#define IMAGE_FILE_MACHINE_SH3 0x01a2
#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
#define IMAGE_FILE_MACHINE_SH3E 0x01a4
#define IMAGE_FILE_MACHINE_SH4 0x01a6
#define IMAGE_FILE_MACHINE_SH5 0x01a8
#define IMAGE_FILE_MACHINE_THUMB 0x01c2
#define IMAGE_FILE_MACHINE_TRICORE 0x0520
#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
#define IMAGE_FILE_MACHINE_AMD64 0x8664
#define IMAGE_SUBSYSTEM_UNKNOWN 0
#define IMAGE_SUBSYSTEM_NATIVE 1
#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
#define IMAGE_SUBSYSTEM_POSIX_CUI 7
#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
#define IMAGE_SUBSYSTEM_XBOX 14
/* Magic values that are true for all dos/nt implementations. */
#define DOSMAGIC 0x5a4d
#define NT_SIGNATURE 0x00004550
/* NT allows long filenames, we want to accommodate this.
This may break some of the bfd functions. */
#undef FILNMLEN
#define FILNMLEN 18 /* # characters in a file name. */
struct external_PEI_DOS_hdr
{
/* DOS header fields - always at offset zero in the EXE file. */
char e_magic[2]; /* Magic number, 0x5a4d. */
char e_cblp[2]; /* Bytes on last page of file, 0x90. */
char e_cp[2]; /* Pages in file, 0x3. */
char e_crlc[2]; /* Relocations, 0x0. */
char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
char e_ss[2]; /* Initial (relative) SS value, 0x0. */
char e_sp[2]; /* Initial SP value, 0xb8. */
char e_csum[2]; /* Checksum, 0x0. */
char e_ip[2]; /* Initial IP value, 0x0. */
char e_cs[2]; /* Initial (relative) CS value, 0x0. */
char e_lfarlc[2]; /* File address of relocation table, 0x40. */
char e_ovno[2]; /* Overlay number, 0x0. */
char e_res[4][2]; /* Reserved words, all 0x0. */
char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
char e_res2[10][2]; /* Reserved words, all 0x0. */
char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
char dos_message[16][4]; /* Other stuff, always follow DOS header. */
};
struct external_PEI_IMAGE_hdr
{
char nt_signature[4]; /* required NT signature, 0x4550. */
/* From standard header. */
char f_magic[2]; /* Magic number. */
char f_nscns[2]; /* Number of sections. */
char f_timdat[4]; /* Time & date stamp. */
char f_symptr[4]; /* File pointer to symtab. */
char f_nsyms[4]; /* Number of symtab entries. */
char f_opthdr[2]; /* Sizeof(optional hdr). */
char f_flags[2]; /* Flags. */
};
struct external_PEI_filehdr
{
/* DOS header fields - always at offset zero in the EXE file. */
char e_magic[2]; /* Magic number, 0x5a4d. */
char e_cblp[2]; /* Bytes on last page of file, 0x90. */
char e_cp[2]; /* Pages in file, 0x3. */
char e_crlc[2]; /* Relocations, 0x0. */
char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
char e_ss[2]; /* Initial (relative) SS value, 0x0. */
char e_sp[2]; /* Initial SP value, 0xb8. */
char e_csum[2]; /* Checksum, 0x0. */
char e_ip[2]; /* Initial IP value, 0x0. */
char e_cs[2]; /* Initial (relative) CS value, 0x0. */
char e_lfarlc[2]; /* File address of relocation table, 0x40. */
char e_ovno[2]; /* Overlay number, 0x0. */
char e_res[4][2]; /* Reserved words, all 0x0. */
char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
char e_res2[10][2]; /* Reserved words, all 0x0. */
char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
char dos_message[16][4]; /* Other stuff, always follow DOS header. */
/* Note: additional bytes may be inserted before the signature. Use
the e_lfanew field to find the actual location of the NT signature. */
char nt_signature[4]; /* required NT signature, 0x4550. */
/* From standard header. */
char f_magic[2]; /* Magic number. */
char f_nscns[2]; /* Number of sections. */
char f_timdat[4]; /* Time & date stamp. */
char f_symptr[4]; /* File pointer to symtab. */
char f_nsyms[4]; /* Number of symtab entries. */
char f_opthdr[2]; /* Sizeof(optional hdr). */
char f_flags[2]; /* Flags. */
};
#ifdef COFF_IMAGE_WITH_PE
/* The filehdr is only weird in images. */
#undef FILHDR
#define FILHDR struct external_PEI_filehdr
#undef FILHSZ
#define FILHSZ 152
#endif /* COFF_IMAGE_WITH_PE */
/* 32-bit PE a.out header: */
typedef struct
{
AOUTHDR standard;
/* NT extra fields; see internal.h for descriptions. */
char ImageBase[4];
char SectionAlignment[4];
char FileAlignment[4];
char MajorOperatingSystemVersion[2];
char MinorOperatingSystemVersion[2];
char MajorImageVersion[2];
char MinorImageVersion[2];
char MajorSubsystemVersion[2];
char MinorSubsystemVersion[2];
char Reserved1[4];
char SizeOfImage[4];
char SizeOfHeaders[4];
char CheckSum[4];
char Subsystem[2];
char DllCharacteristics[2];
char SizeOfStackReserve[4];
char SizeOfStackCommit[4];
char SizeOfHeapReserve[4];
char SizeOfHeapCommit[4];
char LoaderFlags[4];
char NumberOfRvaAndSizes[4];
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
} PEAOUTHDR;
#undef AOUTSZ
#define AOUTSZ (AOUTHDRSZ + 196)
/* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
(aka data_start) member and that some of the members are 8 instead
of just 4 bytes long. */
typedef struct
{
#ifdef AOUTHDRSZ64
AOUTHDR64 standard;
#else
AOUTHDR standard;
#endif
/* NT extra fields; see internal.h for descriptions. */
char ImageBase[8];
char SectionAlignment[4];
char FileAlignment[4];
char MajorOperatingSystemVersion[2];
char MinorOperatingSystemVersion[2];
char MajorImageVersion[2];
char MinorImageVersion[2];
char MajorSubsystemVersion[2];
char MinorSubsystemVersion[2];
char Reserved1[4];
char SizeOfImage[4];
char SizeOfHeaders[4];
char CheckSum[4];
char Subsystem[2];
char DllCharacteristics[2];
char SizeOfStackReserve[8];
char SizeOfStackCommit[8];
char SizeOfHeapReserve[8];
char SizeOfHeapCommit[8];
char LoaderFlags[4];
char NumberOfRvaAndSizes[4];
/* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
} PEPAOUTHDR;
#ifdef AOUTHDRSZ64
#define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */
#else
#define PEPAOUTSZ 240
#endif
#undef E_FILNMLEN
#define E_FILNMLEN 18 /* # characters in a file name. */
/* Import Tyoes fot ILF format object files.. */
#define IMPORT_CODE 0
#define IMPORT_DATA 1
#define IMPORT_CONST 2
/* Import Name Tyoes for ILF format object files. */
#define IMPORT_ORDINAL 0
#define IMPORT_NAME 1
#define IMPORT_NAME_NOPREFIX 2
#define IMPORT_NAME_UNDECORATE 3
/* Weak external characteristics. */
#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
/* .pdata/.xdata defines and structures for x64 PE+ for exception handling. */
/* .pdata in exception directory. */
struct pex64_runtime_function
{
bfd_vma rva_BeginAddress;
bfd_vma rva_EndAddress;
bfd_vma rva_UnwindData;
unsigned int isChained : 1;
};
struct external_pex64_runtime_function
{
bfd_byte rva_BeginAddress[4];
bfd_byte rva_EndAddress[4];
bfd_byte rva_UnwindData[4];
};
/* If the lowest significant bit is set for rva_UnwindData RVA, it
means that the unified RVA points to another pex64_runtime_function
that this entry shares the unwind_info block with. */
#define PEX64_IS_RUNTIME_FUNCTION_CHAINED(PTR_RTF) \
(((PTR_RTF)->rva_UnwindData & 1) != 0)
#define PEX64_GET_UNWINDDATA_UNIFIED_RVA(PTR_RTF) \
((PTR_RTF)->rva_UnwindData & ~1)
/* The unwind codes. */
#define UWOP_PUSH_NONVOL 0
#define UWOP_ALLOC_LARGE 1
#define UWOP_ALLOC_SMALL 2
#define UWOP_SET_FPREG 3
#define UWOP_SAVE_NONVOL 4
#define UWOP_SAVE_NONVOL_FAR 5
#define UWOP_SAVE_XMM 6
#define UWOP_SAVE_XMM_FAR 7
#define UWOP_SAVE_XMM128 8
#define UWOP_SAVE_XMM128_FAR 9
#define UWOP_PUSH_MACHFRAME 10
struct pex64_unwind_code
{
bfd_vma prologue_offset;
/* Contains Frame offset, or frame allocation size. */
bfd_vma frame_addr;
unsigned int uwop_code : 4;
/* xmm, mm, or standard register from 0 - 15. */
unsigned int reg : 4;
/* Used for UWOP_PUSH_MACHFRAME to indicate optional errorcode stack
argument. */
unsigned int has_errorcode : 1;
};
struct external_pex64_unwind_code
{
bfd_byte dta[2];
};
#define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
#define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
/* The unwind info. */
#define UNW_FLAG_NHANDLER 0
#define UNW_FLAG_EHANDLER 1
#define UNW_FLAG_UHANDLER 2
#define UNW_FLAG_FHANDLER 3
#define UNW_FLAG_CHAININFO 4
#define UNW_FLAG_MASK 0x1f
struct pex64_unwind_info
{
bfd_vma SizeOfBlock;
bfd_byte Version; /* Values from 0 up to 7 are possible. */
bfd_byte Flags; /* Values from 0 up to 31 are possible. */
bfd_vma SizeOfPrologue;
bfd_vma CountOfCodes; /* Amount of pex64_unwind_code elements. */
/* 0 = CFA, 1..15 are index of integer registers. */
unsigned int FrameRegister : 4;
bfd_vma FrameOffset;
bfd_vma sizeofUnwindCodes;
bfd_byte *rawUnwindCodes;
/* Valid for UNW_FLAG_EHANDLER and UNW_FLAG_UHANDLER. */
bfd_vma CountOfScopes;
bfd_byte *rawScopeEntries;
bfd_vma rva_ExceptionHandler; /* UNW_EHANDLER. */
bfd_vma rva_TerminationHandler; /* UNW_FLAG_UHANDLER. */
bfd_vma rva_FrameHandler; /* UNW_FLAG_FHANDLER. */
bfd_vma FrameHandlerArgument; /* UNW_FLAG_FHANDLER. */
bfd_vma rva_FunctionEntry; /* UNW_FLAG_CHAININFO. */
};
struct external_pex64_unwind_info
{
bfd_byte Version_Flags;
bfd_byte SizeOfPrologue;
bfd_byte CountOfCodes;
bfd_byte FrameRegisterOffset;
/* external_pex64_unwind_code array. */
/* bfd_byte handler[4]; */
/* Optional language specific data. */
};
struct external_pex64_scope
{
bfd_vma Count;
};
struct pex64_scope
{
bfd_byte Count[4];
};
struct pex64_scope_entry
{
bfd_vma rva_BeginAddress;
bfd_vma rva_EndAddress;
bfd_vma rva_HandlerAddress;
bfd_vma rva_JumpAddress;
};
#define PEX64_SCOPE_ENTRY_SIZE 16
struct external_pex64_scope_entry
{
bfd_byte rva_BeginAddress[4];
bfd_byte rva_EndAddress[4];
bfd_byte rva_HandlerAddress[4];
bfd_byte rva_JumpAddress[4];
};
#define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
#define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
#define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
#define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
#define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
((((VAL) + 1) & ~1) * 2)
#define PEX64_OFFSET_TO_UNWIND_CODE 0x4
#define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
(PEX64_OFFSET_TO_UNWIND_CODE + \
PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
#define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
(PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
#define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
(PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
PEX64_SCOPE_ENTRY_SIZE * (IDX))
#endif /* _PE_H */

59
coff/powerpc.h Normal file
View file

@ -0,0 +1,59 @@
/* Basic coff information for the PowerPC
Based on coff/rs6000.h, coff/i386.h and others.
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA.
Initial release: Kim Knuttila (krk@cygnus.com) */
#define L_LNNO_SIZE 2
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
/* Bits for f_flags:
F_RELFLG relocation info stripped from file
F_EXEC file is executable (no unresolved external references)
F_LNNO line numbers stripped from file
F_LSYMS local symbols stripped from file
F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax). */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
/* extra NT defines */
#define PPCMAGIC 0760 /* peeked on aa PowerPC Windows NT box */
#define DOSMAGIC 0x5a4d /* from arm.h, i386.h */
#define NT_SIGNATURE 0x00004550 /* from arm.h, i386.h */
/* from winnt.h */
#define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
#define PPCBADMAG(x) ((x).f_magic != PPCMAGIC)
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10

293
coff/rs6000.h Normal file
View file

@ -0,0 +1,293 @@
/* IBM RS/6000 "XCOFF" file definitions for BFD.
Copyright (C) 1990, 1991, 2001, 2010 Free Software Foundation, Inc.
Written by Mimi Phuong-Thao Vo of IBM
and John Gilmore of Cygnus Support.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/********************** FILE HEADER **********************/
struct external_filehdr {
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
};
/* IBM RS/6000 */
#define U802WRMAGIC 0730 /* writeable text segments **chh** */
#define U802ROMAGIC 0735 /* readonly sharable text segments */
#define U802TOCMAGIC 0737 /* readonly text segments and TOC */
#define BADMAG(x) \
((x).f_magic != U802ROMAGIC && (x).f_magic != U802WRMAGIC && \
(x).f_magic != U802TOCMAGIC)
#define FILHDR struct external_filehdr
#define FILHSZ 20
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct
{
unsigned char magic[2]; /* type of file */
unsigned char vstamp[2]; /* version stamp */
unsigned char tsize[4]; /* text size in bytes, padded to FW bdry */
unsigned char dsize[4]; /* initialized data " " */
unsigned char bsize[4]; /* uninitialized data " " */
unsigned char entry[4]; /* entry pt. */
unsigned char text_start[4]; /* base of text used for this file */
unsigned char data_start[4]; /* base of data used for this file */
unsigned char o_toc[4]; /* address of TOC */
unsigned char o_snentry[2]; /* section number of entry point */
unsigned char o_sntext[2]; /* section number of .text section */
unsigned char o_sndata[2]; /* section number of .data section */
unsigned char o_sntoc[2]; /* section number of TOC */
unsigned char o_snloader[2]; /* section number of .loader section */
unsigned char o_snbss[2]; /* section number of .bss section */
unsigned char o_algntext[2]; /* .text alignment */
unsigned char o_algndata[2]; /* .data alignment */
unsigned char o_modtype[2]; /* module type (??) */
unsigned char o_cputype[2]; /* cpu type */
unsigned char o_maxstack[4]; /* max stack size (??) */
unsigned char o_maxdata[4]; /* max data size (??) */
unsigned char o_resv2[12]; /* reserved */
}
AOUTHDR;
#define AOUTSZ 72
#define SMALL_AOUTSZ (28)
#define AOUTHDRSZ 72
/********************** SECTION HEADER **********************/
struct external_scnhdr {
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[2]; /* number of relocation entries */
char s_nlnno[2]; /* number of line number entries*/
char s_flags[4]; /* flags */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 40
/********************** LINE NUMBERS **********************/
/* 1 line number entry for every "breakpointable" source line in a section.
* Line numbers are grouped on a per function basis; first entry in a function
* grouping will have l_lnno = 0 and in place of physical address will be the
* symbol table index of the function name.
*/
struct external_lineno {
union {
char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
char l_paddr[4]; /* (physical) address of line number */
} l_addr;
char l_lnno[2]; /* line number */
};
#define LINENO struct external_lineno
#define LINESZ 6
/********************** SYMBOLS **********************/
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
struct external_syment
{
union {
char e_name[E_SYMNMLEN];
struct {
char e_zeroes[4];
char e_offset[4];
} e;
} e;
char e_value[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
};
#define N_BTMASK (017)
#define N_TMASK (060)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
union external_auxent {
struct {
char x_tagndx[4]; /* str, un, or enum tag indx */
union {
struct {
char x_lnno[2]; /* declaration line number */
char x_size[2]; /* str/union/array size */
} x_lnsz;
char x_fsize[4]; /* size of function */
} x_misc;
union {
struct { /* if ISFCN, tag, or .bb */
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
struct { /* if ISARY, up to 4 dimen. */
char x_dimen[E_DIMNUM][2];
} x_ary;
} x_fcnary;
char x_tvndx[2]; /* tv index */
} x_sym;
struct {
union {
char x_fname[E_FILNMLEN];
struct {
char x_zeroes[4];
char x_offset[4];
} x_n;
} x_n;
char x_ftype[1];
} x_file;
struct {
char x_scnlen[4]; /* section length */
char x_nreloc[2]; /* # relocation entries */
char x_nlinno[2]; /* # line numbers */
} x_scn;
struct {
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
struct {
unsigned char x_scnlen[4];
unsigned char x_parmhash[4];
unsigned char x_snhash[2];
unsigned char x_smtyp[1];
unsigned char x_smclas[1];
unsigned char x_stab[4];
unsigned char x_snstab[2];
} x_csect;
};
#define SYMENT struct external_syment
#define SYMESZ 18
#define AUXENT union external_auxent
#define AUXESZ 18
#define DBXMASK 0x80 /* for dbx storage mask */
#define SYMNAME_IN_DEBUG(symptr) ((symptr)->n_sclass & DBXMASK)
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc {
char r_vaddr[4];
char r_symndx[4];
char r_size[1];
char r_type[1];
};
#define RELOC struct external_reloc
#define RELSZ 10
#define DEFAULT_DATA_SECTION_ALIGNMENT 4
#define DEFAULT_BSS_SECTION_ALIGNMENT 4
#define DEFAULT_TEXT_SECTION_ALIGNMENT 4
/* For new sections we havn't heard of before */
#define DEFAULT_SECTION_ALIGNMENT 4
/* The ldhdr structure. This appears at the start of the .loader
section. */
struct external_ldhdr
{
bfd_byte l_version[4];
bfd_byte l_nsyms[4];
bfd_byte l_nreloc[4];
bfd_byte l_istlen[4];
bfd_byte l_nimpid[4];
bfd_byte l_impoff[4];
bfd_byte l_stlen[4];
bfd_byte l_stoff[4];
};
#define LDHDRSZ (8 * 4)
struct external_ldsym
{
union
{
bfd_byte _l_name[E_SYMNMLEN];
struct
{
bfd_byte _l_zeroes[4];
bfd_byte _l_offset[4];
} _l_l;
} _l;
bfd_byte l_value[4];
bfd_byte l_scnum[2];
bfd_byte l_smtype[1];
bfd_byte l_smclas[1];
bfd_byte l_ifile[4];
bfd_byte l_parm[4];
};
#define LDSYMSZ (8 + 3 * 4 + 2 + 2)
struct external_ldrel
{
bfd_byte l_vaddr[4];
bfd_byte l_symndx[4];
bfd_byte l_rtype[2];
bfd_byte l_rsecnm[2];
};
#define LDRELSZ (2 * 4 + 2 * 2)
struct external_exceptab
{
union {
bfd_byte e_symndx[4];
bfd_byte e_paddr[4];
} e_addr;
bfd_byte e_lang[1];
bfd_byte e_reason[1];
};
#define EXCEPTSZ (4 + 2)

275
coff/rs6k64.h Normal file
View file

@ -0,0 +1,275 @@
/* IBM RS/6000 "XCOFF64" file definitions for BFD.
Copyright (C) 2000, 2001, 2002, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/********************** FILE HEADER **********************/
struct external_filehdr
{
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[8]; /* file pointer to symtab */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
char f_nsyms[4]; /* number of symtab entries */
};
/* IBM RS/6000. */
#define U803XTOCMAGIC 0757 /* Aix 4.3 64-bit XCOFF */
#define U64_TOCMAGIC 0767 /* AIX 5+ 64-bit XCOFF */
#define BADMAG(x) ((x).f_magic != U803XTOCMAGIC && (x).f_magic != U64_TOCMAGIC)
#define FILHDR struct external_filehdr
#define FILHSZ 24
/********************** AOUT "OPTIONAL HEADER" **********************/
typedef struct
{
unsigned char magic[2]; /* type of file */
unsigned char vstamp[2]; /* version stamp */
unsigned char o_debugger[4]; /* reserved */
unsigned char text_start[8]; /* base of text used for this file */
unsigned char data_start[8]; /* base of data used for this file */
unsigned char o_toc[8]; /* address of TOC */
unsigned char o_snentry[2]; /* section number of entry point */
unsigned char o_sntext[2]; /* section number of .text section */
unsigned char o_sndata[2]; /* section number of .data section */
unsigned char o_sntoc[2]; /* section number of TOC */
unsigned char o_snloader[2]; /* section number of .loader section */
unsigned char o_snbss[2]; /* section number of .bss section */
unsigned char o_algntext[2]; /* .text alignment */
unsigned char o_algndata[2]; /* .data alignment */
unsigned char o_modtype[2]; /* module type (??) */
unsigned char o_cputype[2]; /* cpu type */
unsigned char o_resv2[4]; /* reserved */
unsigned char tsize[8]; /* text size bytes, padded to FW bdry */
unsigned char dsize[8]; /* initialized data " " */
unsigned char bsize[8]; /* uninitialized data " " */
unsigned char entry[8]; /* entry pt. */
unsigned char o_maxstack[8]; /* max stack size (??) */
unsigned char o_maxdata[8]; /* max data size (??) */
unsigned char o_resv3[16]; /* reserved */
}
AOUTHDR;
#define AOUTSZ 120
#define SMALL_AOUTSZ (0)
#define AOUTHDRSZ 72
/********************** SECTION HEADER **********************/
struct external_scnhdr
{
char s_name[8]; /* section name */
char s_paddr[8]; /* physical address, aliased s_nlib */
char s_vaddr[8]; /* virtual address */
char s_size[8]; /* section size */
char s_scnptr[8]; /* file ptr to raw data for section */
char s_relptr[8]; /* file ptr to relocation */
char s_lnnoptr[8]; /* file ptr to line numbers */
char s_nreloc[4]; /* number of relocation entries */
char s_nlnno[4]; /* number of line number entries*/
char s_flags[4]; /* flags */
char s_pad[4]; /* padding */
};
#define SCNHDR struct external_scnhdr
#define SCNHSZ 72
/********************** LINE NUMBERS **********************/
/* 1 line number entry for every "breakpointable" source line in a section.
Line numbers are grouped on a per function basis; first entry in a function
grouping will have l_lnno = 0 and in place of physical address will be the
symbol table index of the function name. */
struct external_lineno
{
union
{
char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
char l_paddr[8]; /* (physical) address of line number */
} l_addr;
char l_lnno[4]; /* line number */
};
#define LINENO struct external_lineno
#define LINESZ 12
/********************** SYMBOLS **********************/
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
struct external_syment
{
char e_value[8];
char e_offset[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
};
#define N_BTMASK (017)
#define N_TMASK (060)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
union external_auxent
{
struct {
union {
struct {
char x_lnno[4]; /* declaration line number */
char x_size[2]; /* str/union/array size */
} x_lnsz;
struct {
char x_lnnoptr[8];/* ptr to fcn line */
char x_fsize[4]; /* size of function */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
} x_fcnary;
} x_sym;
struct {
union {
char x_fname[E_FILNMLEN];
struct {
char x_zeroes[4];
char x_offset[4];
char x_pad[6];
} x_n;
} x_n;
unsigned char x_ftype[1];
unsigned char x_resv[2];
} x_file;
struct {
char x_exptr[8];
char x_fsize[4];
char x_endndx[4];
char x_pad[1];
} x_except;
struct {
unsigned char x_scnlen_lo[4];
unsigned char x_parmhash[4];
unsigned char x_snhash[2];
unsigned char x_smtyp[1];
unsigned char x_smclas[1];
unsigned char x_scnlen_hi[4];
unsigned char x_pad[1];
} x_csect;
struct {
char x_pad[17];
char x_auxtype[1];
} x_auxtype;
};
#define SYMENT struct external_syment
#define SYMESZ 18
#define AUXENT union external_auxent
#define AUXESZ 18
#define DBXMASK 0x80 /* for dbx storage mask */
#define SYMNAME_IN_DEBUG(symptr) ((symptr)->n_sclass & DBXMASK)
/* Values for auxtype field in XCOFF64, taken from AIX 4.3 sym.h. */
#define _AUX_EXCEPT 255
#define _AUX_FCN 254
#define _AUX_SYM 253
#define _AUX_FILE 252
#define _AUX_CSECT 251
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[8];
char r_symndx[4];
char r_size[1];
char r_type[1];
};
#define RELOC struct external_reloc
#define RELSZ 14
#define DEFAULT_DATA_SECTION_ALIGNMENT 4
#define DEFAULT_BSS_SECTION_ALIGNMENT 4
#define DEFAULT_TEXT_SECTION_ALIGNMENT 4
/* For new sections we havn't heard of before */
#define DEFAULT_SECTION_ALIGNMENT 4
/* The ldhdr structure. This appears at the start of the .loader
section. */
struct external_ldhdr
{
bfd_byte l_version[4];
bfd_byte l_nsyms[4];
bfd_byte l_nreloc[4];
bfd_byte l_istlen[4];
bfd_byte l_nimpid[4];
bfd_byte l_stlen[4];
bfd_byte l_impoff[8];
bfd_byte l_stoff[8];
bfd_byte l_symoff[8];
bfd_byte l_rldoff[8];
};
#define LDHDRSZ (56)
struct external_ldsym
{
bfd_byte l_value[8];
bfd_byte l_offset[4];
bfd_byte l_scnum[2];
bfd_byte l_smtype[1];
bfd_byte l_smclas[1];
bfd_byte l_ifile[4];
bfd_byte l_parm[4];
};
#define LDSYMSZ (24)
struct external_ldrel
{
bfd_byte l_vaddr[8];
bfd_byte l_rtype[2];
bfd_byte l_rsecnm[2];
bfd_byte l_symndx[4];
};
#define LDRELSZ (16)
struct external_exceptab
{
union {
bfd_byte e_symndx[4];
bfd_byte e_paddr[8];
} e_addr;
bfd_byte e_lang[1];
bfd_byte e_reason[1];
};
#define EXCEPTSZ (10)

148
coff/sh.h Normal file
View file

@ -0,0 +1,148 @@
/* coff information for Renesas SH
Copyright 2000, 2003, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifdef COFF_WITH_PE
#define L_LNNO_SIZE 2
#else
#define L_LNNO_SIZE 4
#endif
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
#define SH_ARCH_MAGIC_BIG 0x0500
#define SH_ARCH_MAGIC_LITTLE 0x0550 /* Little endian SH */
#define SH_ARCH_MAGIC_WINCE 0x01a2 /* Windows CE - little endian */
#define SH_PE_MAGIC 0x010b
#define SHBADMAG(x) \
(((x).f_magic != SH_ARCH_MAGIC_BIG) && \
((x).f_magic != SH_ARCH_MAGIC_WINCE) && \
((x).f_magic != SH_ARCH_MAGIC_LITTLE))
/* Define some NT default values. */
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the h8 don't have room in the instruction for the entire
offset - eg the strange jump and high page addressing modes. */
#ifndef COFF_WITH_PE
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#else
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#endif
#define RELOC struct external_reloc
#ifdef COFF_WITH_PE
#define RELSZ 10
#else
#define RELSZ 16
#endif
/* SH relocation types. Not all of these are actually used. */
#define R_SH_UNUSED 0 /* only used internally */
#define R_SH_IMM32CE 2 /* 32 bit immediate for WinCE */
#define R_SH_PCREL8 3 /* 8 bit pcrel */
#define R_SH_PCREL16 4 /* 16 bit pcrel */
#define R_SH_HIGH8 5 /* high 8 bits of 24 bit address */
#define R_SH_LOW16 7 /* low 16 bits of 24 bit immediate */
#define R_SH_IMM24 6 /* 24 bit immediate */
#define R_SH_PCDISP8BY4 9 /* PC rel 8 bits *4 +ve */
#define R_SH_PCDISP8BY2 10 /* PC rel 8 bits *2 +ve */
#define R_SH_PCDISP8 11 /* 8 bit branch */
#define R_SH_PCDISP 12 /* 12 bit branch */
#define R_SH_IMM32 14 /* 32 bit immediate */
#define R_SH_IMM8 16 /* 8 bit immediate */
#define R_SH_IMAGEBASE 16 /* Windows CE */
#define R_SH_IMM8BY2 17 /* 8 bit immediate *2 */
#define R_SH_IMM8BY4 18 /* 8 bit immediate *4 */
#define R_SH_IMM4 19 /* 4 bit immediate */
#define R_SH_IMM4BY2 20 /* 4 bit immediate *2 */
#define R_SH_IMM4BY4 21 /* 4 bit immediate *4 */
#define R_SH_PCRELIMM8BY2 22 /* PC rel 8 bits *2 unsigned */
#define R_SH_PCRELIMM8BY4 23 /* PC rel 8 bits *4 unsigned */
#define R_SH_IMM16 24 /* 16 bit immediate */
/* The switch table reloc types are used for relaxing. They are
generated for expressions such as
.word L1 - L2
The r_offset field holds the difference between the reloc address
and L2. */
#define R_SH_SWITCH8 33 /* 8 bit switch table entry */
#define R_SH_SWITCH16 25 /* 16 bit switch table entry */
#define R_SH_SWITCH32 26 /* 32 bit switch table entry */
/* The USES reloc type is used for relaxing. The compiler will
generate .uses pseudo-ops when it finds a function call which it
can relax. The r_offset field of the USES reloc holds the PC
relative offset to the instruction which loads the register used in
the function call. */
#define R_SH_USES 27 /* .uses pseudo-op */
/* The COUNT reloc type is used for relaxing. The assembler will
generate COUNT relocs for addresses referred to by the register
loads associated with USES relocs. The r_offset field of the COUNT
reloc holds the number of times the address is referenced in the
object file. */
#define R_SH_COUNT 28 /* Count of constant pool uses */
/* The ALIGN reloc type is used for relaxing. The r_offset field is
the power of two to which subsequent portions of the object file
must be aligned. */
#define R_SH_ALIGN 29 /* .align pseudo-op */
/* The CODE and DATA reloc types are used for aligning load and store
instructions. The assembler will generate a CODE reloc before a
block of instructions. It will generate a DATA reloc before data.
A section should be processed assuming it contains data, unless a
CODE reloc is seen. The only relevant pieces of information in the
CODE and DATA relocs are the section and the address. The symbol
and offset are meaningless. */
#define R_SH_CODE 30 /* start of code */
#define R_SH_DATA 31 /* start of data */
/* The LABEL reloc type is used for aligning load and store
instructions. The assembler will generate a LABEL reloc for each
label within a block of instructions. This permits the linker to
avoid swapping instructions which are the targets of branches. */
#define R_SH_LABEL 32 /* label */
/* NB: R_SH_SWITCH8 is 33 */
#define R_SH_LOOP_START 34
#define R_SH_LOOP_END 35

156
coff/sparc.h Normal file
View file

@ -0,0 +1,156 @@
/* coff information for Sparc.
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* This file is an amalgamation of several standard include files that
define coff format, such as filehdr.h, aouthdr.h, and so forth. In
addition, all datatypes have been translated into character arrays of
(presumed) equivalent size. This is necessary so that this file can
be used with different systems while still yielding the same results. */
#define L_LNNO_SIZE 2
#define DO_NOT_DEFINE_SYMENT
#define DO_NOT_DEFINE_AUXENT
#include "coff/external.h"
#define F_RELFLG (0x0001) /* relocation info stripped */
#define F_EXEC (0x0002) /* file is executable */
#define F_LNNO (0x0004) /* line numbers stripped */
#define F_LSYMS (0x0008) /* local symbols stripped */
#define SPARCMAGIC (0540)
/* This is Lynx's all-platform magic number for executables. */
#define LYNXCOFFMAGIC (0415)
#define OMAGIC 0404 /* object files, eg as output */
#define ZMAGIC 0413 /* demand load format, eg normal ld output */
#define STMAGIC 0401 /* target shlib */
#define SHMAGIC 0443 /* host shlib */
/* More names of "special" sections. */
#define _TV ".tv"
#define _INIT ".init"
#define _FINI ".fini"
/********************** SYMBOLS **********************/
#define E_SYMNMLEN (8) /* # characters in a symbol name */
#define E_FILNMLEN (14) /* # characters in a file name */
#define E_DIMNUM (4) /* # array dimensions in auxiliary entry */
struct external_syment
{
union {
char e_name[E_SYMNMLEN];
struct {
char e_zeroes[4];
char e_offset[4];
} e;
#if 0 /* of doubtful value */
char e_nptr[2][4];
struct {
char e_leading_zero[1];
char e_dbx_type[1];
char e_dbx_desc[2];
} e_dbx;
#endif
} e;
char e_value[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
char padding[2];
};
#define N_BTMASK (0xf)
#define N_TMASK (0x30)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
union external_auxent
{
struct {
char x_tagndx[4]; /* str, un, or enum tag indx */
union {
struct {
char x_lnno[2]; /* declaration line number */
char x_size[2]; /* str/union/array size */
} x_lnsz;
char x_fsize[4]; /* size of function */
} x_misc;
union {
struct { /* if ISFCN, tag, or .bb */
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
struct { /* if ISARY, up to 4 dimen. */
char x_dimen[E_DIMNUM][2];
} x_ary;
} x_fcnary;
char x_tvndx[2]; /* tv index */
} x_sym;
union {
char x_fname[E_FILNMLEN];
struct {
char x_zeroes[4];
char x_offset[4];
} x_n;
} x_file;
struct {
char x_scnlen[4]; /* section length */
char x_nreloc[2]; /* # relocation entries */
char x_nlinno[2]; /* # line numbers */
} x_scn;
struct {
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
} x_tv; /* .tv section info (in auxent of sym .tv)) */
char x_fill[20]; /* forces to 20-byte size */
};
#define SYMENT struct external_syment
#define SYMESZ 20
#define AUXENT union external_auxent
#define AUXESZ 20
#define _ETEXT "etext"
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
char r_spare[2];
char r_offset[4];
};
#define RELOC struct external_reloc
#define RELSZ 16

484
coff/sym.h Normal file
View file

@ -0,0 +1,484 @@
/* Declarations of internal format of MIPS ECOFF symbols.
Originally contributed by MIPS Computer Systems and Third Eye Software.
Changes contributed by Cygnus Support are in the public domain.
This file is just aggregated with the files that make up the GNU
release; it is not considered part of GAS, GDB, or other GNU
programs. */
/*
* |-----------------------------------------------------------|
* | Copyright (c) 1992, 1991, 1990 MIPS Computer Systems, Inc.|
* | MIPS Computer Systems, Inc. grants reproduction and use |
* | rights to all parties, PROVIDED that this comment is |
* | maintained in the copy. |
* |-----------------------------------------------------------|
*/
#ifndef _SYM_H
#define _SYM_H
/* (C) Copyright 1984 by Third Eye Software, Inc.
*
* Third Eye Software, Inc. grants reproduction and use rights to
* all parties, PROVIDED that this comment is maintained in the copy.
*
* Third Eye makes no claims about the applicability of this
* symbol table to a particular use.
*/
/*
* This file contains the definition of the Third Eye Symbol Table.
*
* Symbols are assumed to be in 'encounter order' - i.e. the order that
* the things they represent were encountered by the compiler/assembler/loader.
* EXCEPT for globals! These are assumed to be bunched together,
* probably right after the last 'normal' symbol. Globals ARE sorted
* in ascending order.
*
* -----------------------------------------------------------------------
* A brief word about Third Eye naming/use conventions:
*
* All arrays and index's are 0 based.
* All "ifooMax" values are the highest legal value PLUS ONE. This makes
* them good for allocating arrays, etc. All checks are "ifoo < ifooMax".
*
* "isym" Index into the SYMbol table.
* "ipd" Index into the Procedure Descriptor array.
* "ifd" Index into the File Descriptor array.
* "iss" Index into String Space.
* "cb" Count of Bytes.
* "rgPd" array whose domain is "0..ipdMax-1" and RanGe is PDR.
* "rgFd" array whose domain is "0..ifdMax-1" and RanGe is FDR.
*/
/*
* Symbolic Header (HDR) structure.
* As long as all the pointers are set correctly,
* we don't care WHAT order the various sections come out in!
*
* A file produced solely for the use of CDB will probably NOT have
* any instructions or data areas in it, as these are available
* in the original.
*/
typedef struct {
short magic; /* to verify validity of the table */
short vstamp; /* version stamp */
long ilineMax; /* number of line number entries */
bfd_vma cbLine; /* number of bytes for line number entries */
bfd_vma cbLineOffset; /* offset to start of line number entries*/
long idnMax; /* max index into dense number table */
bfd_vma cbDnOffset; /* offset to start dense number table */
long ipdMax; /* number of procedures */
bfd_vma cbPdOffset; /* offset to procedure descriptor table */
long isymMax; /* number of local symbols */
bfd_vma cbSymOffset; /* offset to start of local symbols*/
long ioptMax; /* max index into optimization symbol entries */
bfd_vma cbOptOffset; /* offset to optimization symbol entries */
long iauxMax; /* number of auxillary symbol entries */
bfd_vma cbAuxOffset; /* offset to start of auxillary symbol entries*/
long issMax; /* max index into local strings */
bfd_vma cbSsOffset; /* offset to start of local strings */
long issExtMax; /* max index into external strings */
bfd_vma cbSsExtOffset; /* offset to start of external strings */
long ifdMax; /* number of file descriptor entries */
bfd_vma cbFdOffset; /* offset to file descriptor table */
long crfd; /* number of relative file descriptor entries */
bfd_vma cbRfdOffset; /* offset to relative file descriptor table */
long iextMax; /* max index into external symbols */
bfd_vma cbExtOffset; /* offset to start of external symbol entries*/
/* If you add machine dependent fields, add them here */
} HDRR, *pHDRR;
#define cbHDRR sizeof(HDRR)
#define hdrNil ((pHDRR)0)
/*
* The FDR and PDR structures speed mapping of address <-> name.
* They are sorted in ascending memory order and are kept in
* memory by CDB at runtime.
*/
/*
* File Descriptor
*
* There is one of these for EVERY FILE, whether compiled with
* full debugging symbols or not. The name of a file should be
* the path name given to the compiler. This allows the user
* to simply specify the names of the directories where the COMPILES
* were done, and we will be able to find their files.
* A field whose comment starts with "R - " indicates that it will be
* setup at runtime.
*/
typedef struct fdr {
bfd_vma adr; /* memory address of beginning of file */
long rss; /* file name (of source, if known) */
long issBase; /* file's string space */
bfd_vma cbSs; /* number of bytes in the ss */
long isymBase; /* beginning of symbols */
long csym; /* count file's of symbols */
long ilineBase; /* file's line symbols */
long cline; /* count of file's line symbols */
long ioptBase; /* file's optimization entries */
long copt; /* count of file's optimization entries */
unsigned short ipdFirst;/* start of procedures for this file */
short cpd; /* count of procedures for this file */
long iauxBase; /* file's auxiliary entries */
long caux; /* count of file's auxiliary entries */
long rfdBase; /* index into the file indirect table */
long crfd; /* count file indirect entries */
unsigned lang: 5; /* language for this file */
unsigned fMerge : 1; /* whether this file can be merged */
unsigned fReadin : 1; /* true if it was read in (not just created) */
unsigned fBigendian : 1;/* if set, was compiled on big endian machine */
/* aux's will be in compile host's sex */
unsigned glevel : 2; /* level this file was compiled with */
unsigned reserved : 22; /* reserved for future use */
bfd_vma cbLineOffset; /* byte offset from header for this file ln's */
bfd_vma cbLine; /* size of lines for this file */
} FDR, *pFDR;
#define cbFDR sizeof(FDR)
#define fdNil ((pFDR)0)
#define ifdNil -1
#define ifdTemp 0
#define ilnNil -1
/*
* Procedure Descriptor
*
* There is one of these for EVERY TEXT LABEL.
* If a procedure is in a file with full symbols, then isym
* will point to the PROC symbols, else it will point to the
* global symbol for the label.
*/
typedef struct pdr {
bfd_vma adr; /* memory address of start of procedure */
long isym; /* start of local symbol entries */
long iline; /* start of line number entries*/
long regmask; /* save register mask */
long regoffset; /* save register offset */
long iopt; /* start of optimization symbol entries*/
long fregmask; /* save floating point register mask */
long fregoffset; /* save floating point register offset */
long frameoffset; /* frame size */
short framereg; /* frame pointer register */
short pcreg; /* offset or reg of return pc */
long lnLow; /* lowest line in the procedure */
long lnHigh; /* highest line in the procedure */
bfd_vma cbLineOffset; /* byte offset for this procedure from the fd base */
/* These fields are new for 64 bit ECOFF. */
unsigned gp_prologue : 8; /* byte size of GP prologue */
unsigned gp_used : 1; /* true if the procedure uses GP */
unsigned reg_frame : 1; /* true if register frame procedure */
unsigned prof : 1; /* true if compiled with -pg */
unsigned reserved : 13; /* reserved: must be zero */
unsigned localoff : 8; /* offset of local variables from vfp */
} PDR, *pPDR;
#define cbPDR sizeof(PDR)
#define pdNil ((pPDR) 0)
#define ipdNil -1
/*
* The structure of the runtime procedure descriptor created by the loader
* for use by the static exception system.
*/
/*
* If 0'd out because exception_info chokes Visual C++ and because there
* don't seem to be any references to this structure elsewhere in gdb.
*/
#if 0
typedef struct runtime_pdr {
bfd_vma adr; /* memory address of start of procedure */
long regmask; /* save register mask */
long regoffset; /* save register offset */
long fregmask; /* save floating point register mask */
long fregoffset; /* save floating point register offset */
long frameoffset; /* frame size */
short framereg; /* frame pointer register */
short pcreg; /* offset or reg of return pc */
long irpss; /* index into the runtime string table */
long reserved;
struct exception_info *exception_info;/* pointer to exception array */
} RPDR, *pRPDR;
#define cbRPDR sizeof(RPDR)
#define rpdNil ((pRPDR) 0)
#endif
/*
* Line Numbers
*
* Line Numbers are segregated from the normal symbols because they
* are [1] smaller , [2] are of no interest to your
* average loader, and [3] are never needed in the middle of normal
* scanning and therefore slow things down.
*
* By definition, the first LINER for any given procedure will have
* the first line of a procedure and represent the first address.
*/
typedef long LINER, *pLINER;
#define lineNil ((pLINER)0)
#define cbLINER sizeof(LINER)
#define ilineNil -1
/*
* The Symbol Structure (GFW, to those who Know!)
*/
typedef struct {
long iss; /* index into String Space of name */
bfd_vma value; /* value of symbol */
unsigned st : 6; /* symbol type */
unsigned sc : 5; /* storage class - text, data, etc */
unsigned reserved : 1; /* reserved */
unsigned index : 20; /* index into sym/aux table */
} SYMR, *pSYMR;
#define symNil ((pSYMR)0)
#define cbSYMR sizeof(SYMR)
#define isymNil -1
#define indexNil 0xfffff
#define issNil -1
#define issNull 0
/* The following converts a memory resident string to an iss.
* This hack is recognized in SbFIss, in sym.c of the debugger.
*/
#define IssFSb(sb) (0x80000000 | ((unsigned long)(sb)))
/* E X T E R N A L S Y M B O L R E C O R D
*
* Same as the SYMR except it contains file context to determine where
* the index is.
*/
typedef struct ecoff_extr {
unsigned jmptbl:1; /* symbol is a jump table entry for shlibs */
unsigned cobol_main:1; /* symbol is a cobol main procedure */
unsigned weakext:1; /* symbol is weak external */
unsigned reserved:13; /* reserved for future use */
int ifd; /* where the iss and index fields point into */
SYMR asym; /* symbol for the external */
} EXTR, *pEXTR;
#define extNil ((pEXTR)0)
#define cbEXTR sizeof(EXTR)
/* A U X I L L A R Y T Y P E I N F O R M A T I O N */
/*
* Type Information Record
*/
typedef struct {
unsigned fBitfield : 1; /* set if bit width is specified */
unsigned continued : 1; /* indicates additional TQ info in next AUX */
unsigned bt : 6; /* basic type */
unsigned tq4 : 4;
unsigned tq5 : 4;
/* ---- 16 bit boundary ---- */
unsigned tq0 : 4;
unsigned tq1 : 4; /* 6 type qualifiers - tqPtr, etc. */
unsigned tq2 : 4;
unsigned tq3 : 4;
} TIR, *pTIR;
#define cbTIR sizeof(TIR)
#define tiNil ((pTIR)0)
#define itqMax 6
/*
* Relative symbol record
*
* If the rfd field is 4095, the index field indexes into the global symbol
* table.
*/
typedef struct {
unsigned rfd : 12; /* index into the file indirect table */
unsigned index : 20; /* index int sym/aux/iss tables */
} RNDXR, *pRNDXR;
#define cbRNDXR sizeof(RNDXR)
#define rndxNil ((pRNDXR)0)
/* dense numbers or sometimes called block numbers are stored in this type,
* a rfd of 0xffffffff is an index into the global table.
*/
typedef struct {
unsigned long rfd; /* index into the file table */
unsigned long index; /* index int sym/aux/iss tables */
} DNR, *pDNR;
#define cbDNR sizeof(DNR)
#define dnNil ((pDNR)0)
/*
* Auxillary information occurs only if needed.
* It ALWAYS occurs in this order when present.
isymMac used by stProc only
TIR type info
TIR additional TQ info (if first TIR was not enough)
rndx if (bt == btStruct,btUnion,btEnum,btSet,btRange,
btTypedef):
rsym.index == iaux for btSet or btRange
else rsym.index == isym
dimLow btRange, btSet
dimMac btRange, btSet
rndx0 As many as there are tq arrays
dimLow0
dimHigh0
...
rndxMax-1
dimLowMax-1
dimHighMax-1
width in bits if (bit field), width in bits.
*/
#define cAuxMax (6 + (idimMax*3))
/* a union of all possible info in the AUX universe */
typedef union {
TIR ti; /* type information record */
RNDXR rndx; /* relative index into symbol table */
long dnLow; /* low dimension */
long dnHigh; /* high dimension */
long isym; /* symbol table index (end of proc) */
long iss; /* index into string space (not used) */
long width; /* width for non-default sized struc fields */
long count; /* count of ranges for variant arm */
} AUXU, *pAUXU;
#define cbAUXU sizeof(AUXU)
#define auxNil ((pAUXU)0)
#define iauxNil -1
/*
* Optimization symbols
*
* Optimization symbols contain some overlap information with the normal
* symbol table. In particular, the proc information
* is somewhat redundant but necessary to easily find the other information
* present.
*
* All of the offsets are relative to the beginning of the last otProc
*/
typedef struct {
unsigned ot: 8; /* optimization type */
unsigned value: 24; /* address where we are moving it to */
RNDXR rndx; /* points to a symbol or opt entry */
unsigned long offset; /* relative offset this occured */
} OPTR, *pOPTR;
#define optNil ((pOPTR) 0)
#define cbOPTR sizeof(OPTR)
#define ioptNil -1
/*
* File Indirect
*
* When a symbol is referenced across files the following procedure is used:
* 1) use the file index to get the File indirect entry.
* 2) use the file indirect entry to get the File descriptor.
* 3) add the sym index to the base of that file's sym table
*
*/
typedef long RFDT, *pRFDT;
#define cbRFDT sizeof(RFDT)
#define rfdNil -1
/*
* The file indirect table in the mips loader is known as an array of FITs.
* This is done to keep the code in the loader readable in the area where
* these tables are merged. Note this is only a name change.
*/
typedef long FIT, *pFIT;
#define cbFIT sizeof(FIT)
#define ifiNil -1
#define fiNil ((pFIT) 0)
#ifdef _LANGUAGE_PASCAL
#define ifdNil -1
#define ilnNil -1
#define ipdNil -1
#define ilineNil -1
#define isymNil -1
#define indexNil 16#fffff
#define issNil -1
#define issNull 0
#define itqMax 6
#define iauxNil -1
#define ioptNil -1
#define rfdNil -1
#define ifiNil -1
#endif /* _LANGUAGE_PASCAL */
/* Dense numbers
*
* Rather than use file index, symbol index pairs to represent symbols
* and globals, we use dense number so that they can be easily embeded
* in intermediate code and the programs that process them can
* use direct access tabls instead of hash table (which would be
* necesary otherwise because of the sparse name space caused by
* file index, symbol index pairs. Dense number are represented
* by RNDXRs.
*/
/*
* The following table defines the meaning of each SYM field as
* a function of the "st". (scD/B == scData OR scBss)
*
* Note: the value "isymMac" is used by symbols that have the concept
* of enclosing a block of related information. This value is the
* isym of the first symbol AFTER the end associated with the primary
* symbol. For example if a procedure was at isym==90 and had an
* isymMac==155, the associated end would be at isym==154, and the
* symbol at 155 would probably (although not necessarily) be the
* symbol for the next procedure. This allows rapid skipping over
* internal information of various sorts. "stEnd"s ALWAYS have the
* isym of the primary symbol that started the block.
*
ST SC VALUE INDEX
-------- ------ -------- ------
stFile scText address isymMac
stLabel scText address ---
stGlobal scD/B address iaux
stStatic scD/B address iaux
stParam scAbs offset iaux
stLocal scAbs offset iaux
stProc scText address iaux (isymMac is first AUX)
stStaticProc scText address iaux (isymMac is first AUX)
stMember scNil ordinal --- (if member of enum)
(mipsread thinks the case below has a bit, not byte, offset.)
stMember scNil byte offset iaux (if member of struct/union)
stMember scBits bit offset iaux (bit field spec)
stBlock scText address isymMac (text block)
(the code seems to think that rather than scNil, we see scInfo for
the two cases below.)
stBlock scNil cb isymMac (struct/union member define)
stBlock scNil cMembers isymMac (enum member define)
(New types added by SGI to simplify things:)
stStruct scInfo cb isymMac (struct type define)
stUnion scInfo cb isymMac (union type define)
stEnum scInfo cMembers isymMac (enum type define)
stEnd scText address isymStart
stEnd scNil ------- isymStart (struct/union/enum)
stTypedef scNil ------- iaux
stRegReloc sc??? value old register number
stForward sc??? new address isym to original symbol
stConstant scInfo value --- (scalar)
stConstant scInfo iss --- (complex, e.g. string)
*
*/
#endif

184
coff/symconst.h Normal file
View file

@ -0,0 +1,184 @@
/* Declarations of constants for internal format of MIPS ECOFF symbols.
Originally contributed by MIPS Computer Systems and Third Eye Software.
Changes contributed by Cygnus Support are in the public domain.
This file is just aggregated with the files that make up the GNU
release; it is not considered part of GAS, GDB, or other GNU
programs. */
/*
* |-----------------------------------------------------------|
* | Copyright (c) 1992, 1991, 1990 MIPS Computer Systems, Inc.|
* | MIPS Computer Systems, Inc. grants reproduction and use |
* | rights to all parties, PROVIDED that this comment is |
* | maintained in the copy. |
* |-----------------------------------------------------------|
*/
/* (C) Copyright 1984 by Third Eye Software, Inc.
*
* Third Eye Software, Inc. grants reproduction and use rights to
* all parties, PROVIDED that this comment is maintained in the copy.
*
* Third Eye makes no claims about the applicability of this
* symbol table to a particular use.
*/
/* glevels for field in FDR */
#define GLEVEL_0 2
#define GLEVEL_1 1
#define GLEVEL_2 0 /* for upward compat reasons. */
#define GLEVEL_3 3
/* magic number fo symheader */
#define magicSym 0x7009
/* The Alpha uses this value instead, for some reason. */
#define magicSym2 0x1992
/* Language codes */
#define langC 0
#define langPascal 1
#define langFortran 2
#define langAssembler 3 /* one Assembley inst might map to many mach */
#define langMachine 4
#define langNil 5
#define langAda 6
#define langPl1 7
#define langCobol 8
#define langStdc 9 /* FIXME: Collides with SGI langCplusplus */
#define langCplusplus 9 /* FIXME: Collides with langStdc */
#define langCplusplusV2 10 /* SGI addition */
#define langMax 11 /* maximum allowed 32 -- 5 bits */
/* The following are value definitions for the fields in the SYMR */
/*
* Storage Classes
*/
#define scNil 0
#define scText 1 /* text symbol */
#define scData 2 /* initialized data symbol */
#define scBss 3 /* un-initialized data symbol */
#define scRegister 4 /* value of symbol is register number */
#define scAbs 5 /* value of symbol is absolute */
#define scUndefined 6 /* who knows? */
#define scCdbLocal 7 /* variable's value is IN se->va.?? */
#define scBits 8 /* this is a bit field */
#define scCdbSystem 9 /* variable's value is IN CDB's address space */
#define scDbx 9 /* overlap dbx internal use */
#define scRegImage 10 /* register value saved on stack */
#define scInfo 11 /* symbol contains debugger information */
#define scUserStruct 12 /* address in struct user for current process */
#define scSData 13 /* load time only small data */
#define scSBss 14 /* load time only small common */
#define scRData 15 /* load time only read only data */
#define scVar 16 /* Var parameter (fortran,pascal) */
#define scCommon 17 /* common variable */
#define scSCommon 18 /* small common */
#define scVarRegister 19 /* Var parameter in a register */
#define scVariant 20 /* Variant record */
#define scSUndefined 21 /* small undefined(external) data */
#define scInit 22 /* .init section symbol */
#define scBasedVar 23 /* Fortran or PL/1 ptr based var */
#define scXData 24 /* exception handling data */
#define scPData 25 /* Procedure section */
#define scFini 26 /* .fini section */
#define scRConst 27 /* .rconst section */
#define scMax 32
/*
* Symbol Types
*/
#define stNil 0 /* Nuthin' special */
#define stGlobal 1 /* external symbol */
#define stStatic 2 /* static */
#define stParam 3 /* procedure argument */
#define stLocal 4 /* local variable */
#define stLabel 5 /* label */
#define stProc 6 /* " " Procedure */
#define stBlock 7 /* beginnning of block */
#define stEnd 8 /* end (of anything) */
#define stMember 9 /* member (of anything - struct/union/enum */
#define stTypedef 10 /* type definition */
#define stFile 11 /* file name */
#define stRegReloc 12 /* register relocation */
#define stForward 13 /* forwarding address */
#define stStaticProc 14 /* load time only static procs */
#define stConstant 15 /* const */
#define stStaParam 16 /* Fortran static parameters */
/* These new symbol types have been recently added to SGI machines. */
#define stStruct 26 /* Beginning of block defining a struct type */
#define stUnion 27 /* Beginning of block defining a union type */
#define stEnum 28 /* Beginning of block defining an enum type */
#define stIndirect 34 /* Indirect type specification */
/* Pseudo-symbols - internal to debugger */
#define stStr 60 /* string */
#define stNumber 61 /* pure number (ie. 4 NOR 2+2) */
#define stExpr 62 /* 2+2 vs. 4 */
#define stType 63 /* post-coersion SER */
#define stMax 64
/* definitions for fields in TIR */
/* type qualifiers for ti.tq0 -> ti.(itqMax-1) */
#define tqNil 0 /* bt is what you see */
#define tqPtr 1 /* pointer */
#define tqProc 2 /* procedure */
#define tqArray 3 /* duh */
#define tqFar 4 /* longer addressing - 8086/8 land */
#define tqVol 5 /* volatile */
#define tqConst 6 /* const */
#define tqMax 8
/* basic types as seen in ti.bt */
#define btNil 0 /* undefined (also, enum members) */
#define btAdr 1 /* address - integer same size as pointer */
#define btChar 2 /* character */
#define btUChar 3 /* unsigned character */
#define btShort 4 /* short */
#define btUShort 5 /* unsigned short */
#define btInt 6 /* int */
#define btUInt 7 /* unsigned int */
#define btLong 8 /* long */
#define btULong 9 /* unsigned long */
#define btFloat 10 /* float (real) */
#define btDouble 11 /* Double (real) */
#define btStruct 12 /* Structure (Record) */
#define btUnion 13 /* Union (variant) */
#define btEnum 14 /* Enumerated */
#define btTypedef 15 /* defined via a typedef, isymRef points */
#define btRange 16 /* subrange of int */
#define btSet 17 /* pascal sets */
#define btComplex 18 /* fortran complex */
#define btDComplex 19 /* fortran double complex */
#define btIndirect 20 /* forward or unnamed typedef */
#define btFixedDec 21 /* Fixed Decimal */
#define btFloatDec 22 /* Float Decimal */
#define btString 23 /* Varying Length Character String */
#define btBit 24 /* Aligned Bit String */
#define btPicture 25 /* Picture */
#define btVoid 26 /* void */
#define btLongLong 27 /* long long */
#define btULongLong 28 /* unsigned long long */
#define btLong64 30 /* long (64-bit) */
#define btULong64 31 /* unsigned long (64-bit) */
#define btLongLong64 32 /* long long (64-bit) */
#define btULongLong64 33 /* unsigned long long (64-bit) */
#define btAdr64 34 /* address (64-bit) */
#define btInt64 35 /* int (64-bit) */
#define btUInt64 36 /* unsigned int (64-bit) */
#define btMax 64
#if (_MFG == _MIPS)
/* optimization type codes */
#define otNil 0
#define otReg 1 /* move var to reg */
#define otBlock 2 /* begin basic block */
#define otProc 3 /* procedure */
#define otInline 4 /* inline procedure */
#define otEnd 5 /* whatever you started */
#define otMax 6 /* KEEP UP TO DATE */
#endif /* (_MFG == _MIPS) */

558
coff/ti.h Normal file
View file

@ -0,0 +1,558 @@
/* COFF information for TI COFF support. Definitions in this file should be
customized in a target-specific file, and then this file included (see
tic54x.h for an example).
Copyright 2000, 2001, 2002, 2003, 2005, 2008, 2009, 2010
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef COFF_TI_H
#define COFF_TI_H
/* Note "coff/external.h is not used because TI adds extra fields to the structures. */
/********************** FILE HEADER **********************/
struct external_filehdr
{
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
char f_target_id[2]; /* magic no. (TI COFF-specific) */
};
/* COFF0 has magic number in f_magic, and omits f_target_id from the file
header; for later versions, f_magic is 0xC1 for COFF1 and 0xC2 for COFF2
and the target-specific magic number is found in f_target_id */
#define TICOFF0MAGIC TI_TARGET_ID
#define TICOFF1MAGIC 0x00C1
#define TICOFF2MAGIC 0x00C2
#define TICOFF_AOUT_MAGIC 0x0108 /* magic number in optional header */
#define TICOFF 1 /* customize coffcode.h */
/* The target_id field changes depending on the particular CPU target */
/* for COFF0, the target id appeared in f_magic, where COFFX magic is now */
#ifndef TI_TARGET_ID
#error "TI_TARGET_ID needs to be defined for your CPU"
#endif
/* Which bfd_arch to use... */
#ifndef TICOFF_TARGET_ARCH
#error "TICOFF_TARGET_ARCH needs to be defined for your CPU"
#endif
#ifndef TICOFF_TARGET_MACHINE_GET
#define TICOFF_TARGET_MACHINE_GET(FLAGS) 0
#endif
#ifndef TICOFF_TARGET_MACHINE_SET
#define TICOFF_TARGET_MACHINE_SET(FLAGSP, MACHINE)
#endif
/* Default to COFF2 for file output */
#ifndef TICOFF_DEFAULT_MAGIC
#define TICOFF_DEFAULT_MAGIC TICOFF2MAGIC
#endif
/* This value is made available in the rare case where a bfd is unavailable */
#ifndef OCTETS_PER_BYTE_POWER
#error "OCTETS_PER_BYTE_POWER not defined for this CPU"
#else
#define OCTETS_PER_BYTE (1<<OCTETS_PER_BYTE_POWER)
#endif
/* default alignment is on a byte (not octet!) boundary */
#ifndef COFF_DEFAULT_SECTION_ALIGNMENT_POWER
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 0
#endif
/* TI COFF encodes the section alignment in the section header flags */
#define COFF_ALIGN_IN_SECTION_HEADER 1
#define COFF_ALIGN_IN_S_FLAGS 1
/* requires a power-of-two argument */
#define COFF_ENCODE_ALIGNMENT(S,X) ((S).s_flags |= (((unsigned)(X)&0xF)<<8))
/* result is a power of two */
#define COFF_DECODE_ALIGNMENT(X) (((X)>>8)&0xF)
#define COFF0_P(ABFD) (bfd_coff_filhsz(ABFD) == FILHSZ_V0)
#define COFF2_P(ABFD) (bfd_coff_scnhsz(ABFD) != SCNHSZ_V01)
#define COFF0_BADMAG(x) ((x).f_magic != TICOFF0MAGIC)
#define COFF1_BADMAG(x) ((x).f_magic != TICOFF1MAGIC || (x).f_target_id != TI_TARGET_ID)
#define COFF2_BADMAG(x) ((x).f_magic != TICOFF2MAGIC || (x).f_target_id != TI_TARGET_ID)
/* we need to read/write an extra field in the coff file header */
#ifndef COFF_ADJUST_FILEHDR_IN_POST
#define COFF_ADJUST_FILEHDR_IN_POST(abfd, src, dst) \
do \
{ \
if (!COFF0_P (abfd)) \
((struct internal_filehdr *)(dst))->f_target_id = \
H_GET_16 (abfd, ((FILHDR *)(src))->f_target_id); \
} \
while (0)
#endif
#ifndef COFF_ADJUST_FILEHDR_OUT_POST
#define COFF_ADJUST_FILEHDR_OUT_POST(abfd, src, dst) \
do \
{ \
if (!COFF0_P (abfd)) \
H_PUT_16 (abfd, ((struct internal_filehdr *)(src))->f_target_id, \
((FILHDR *)(dst))->f_target_id); \
} \
while (0)
#endif
#define FILHDR struct external_filehdr
#define FILHSZ 22
#define FILHSZ_V0 20 /* COFF0 omits target_id field */
/* File header flags */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_VERS (0x0010) /* TMS320C4x code */
/* F_LSYMS needs to be redefined in your source file */
#define F_LSYMS_TICOFF (0x0010) /* normal COFF is 0x8 */
#define F_10 0x00 /* file built for TMS320C1x devices */
#define F_20 0x10 /* file built for TMS320C2x devices */
#define F_25 0x20 /* file built for TMS320C2x/C5x devices */
#define F_LENDIAN 0x0100 /* 16 bits/word, LSB first */
#define F_SYMMERGE 0x1000 /* duplicate symbols were removed */
/********************** OPTIONAL HEADER **********************/
typedef struct
{
char magic[2]; /* type of file (0x108) */
char vstamp[2]; /* version stamp */
char tsize[4]; /* text size in bytes, padded to FW bdry*/
char dsize[4]; /* initialized data " " */
char bsize[4]; /* uninitialized data " " */
char entry[4]; /* entry pt. */
char text_start[4]; /* base of text used for this file */
char data_start[4]; /* base of data used for this file */
}
AOUTHDR;
#define AOUTHDRSZ 28
#define AOUTSZ 28
/********************** SECTION HEADER **********************/
/* COFF0, COFF1 */
struct external_scnhdr_v01 {
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size (in WORDS) */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[2]; /* number of relocation entries */
char s_nlnno[2]; /* number of line number entries*/
char s_flags[2]; /* flags */
char s_reserved[1]; /* reserved */
char s_page[1]; /* section page number (LOAD) */
};
/* COFF2 */
struct external_scnhdr {
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size (in WORDS) */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[4]; /* number of relocation entries */
char s_nlnno[4]; /* number of line number entries*/
char s_flags[4]; /* flags */
char s_reserved[2]; /* reserved */
char s_page[2]; /* section page number (LOAD) */
};
/*
* Special section flags
*/
/* TI COFF defines these flags;
STYP_CLINK: the section should be excluded from the final
linker output if there are no references found to any symbol in the section
STYP_BLOCK: the section should be blocked, i.e. if the section would cross
a page boundary, it is started at a page boundary instead.
TI COFF puts the section alignment power of two in the section flags
e.g. 2**N is alignment, flags |= (N & 0xF) << 8
*/
#define STYP_CLINK (0x4000)
#define STYP_BLOCK (0x1000)
#define STYP_ALIGN (0x0F00) /* TI COFF stores section alignment here */
#define SCNHDR_V01 struct external_scnhdr_v01
#define SCNHDR struct external_scnhdr
#define SCNHSZ_V01 40 /* for v0 and v1 */
#define SCNHSZ 48
/* COFF2 changes the offsets and sizes of these fields
Assume we're dealing with the COFF2 scnhdr structure, and adjust
accordingly. Note: The GNU C versions of some of these macros
are necessary in order to avoid compile time warnings triggered
gcc's array bounds checking. The PUT_SCNHDR_PAGE macro also has
the advantage on not evaluating LOC twice. */
#define GET_SCNHDR_NRELOC(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, LOC))
#define PUT_SCNHDR_NRELOC(ABFD, VAL, LOC) \
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, LOC))
#ifdef __GNUC__
#define GET_SCNHDR_NLNNO(ABFD, LOC) \
({ \
int nlnno; \
char * ptr = (LOC); \
if (COFF2_P (ABFD)) \
nlnno = H_GET_32 (ABFD, ptr); \
else \
nlnno = H_GET_16 (ABFD, ptr - 2); \
nlnno; \
})
#define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
do \
{ \
char * ptr = (LOC); \
if (COFF2_P (ABFD)) \
H_PUT_32 (ABFD, VAL, ptr); \
else \
H_PUT_16 (ABFD, VAL, ptr - 2); \
} \
while (0)
#define GET_SCNHDR_FLAGS(ABFD, LOC) \
({ \
int flags; \
char * ptr = (LOC); \
if (COFF2_P (ABFD)) \
flags = H_GET_32 (ABFD, ptr); \
else \
flags = H_GET_16 (ABFD, ptr - 4); \
flags; \
})
#define PUT_SCNHDR_FLAGS(ABFD, VAL, LOC) \
do \
{ \
char * ptr = (LOC); \
if (COFF2_P (ABFD)) \
H_PUT_32 (ABFD, VAL, ptr); \
else \
H_PUT_16 (ABFD, VAL, ptr - 4); \
} \
while (0)
#define GET_SCNHDR_PAGE(ABFD, LOC) \
({ \
unsigned page; \
char * ptr = (LOC); \
if (COFF2_P (ABFD)) \
page = H_GET_16 (ABFD, ptr); \
else \
page = (unsigned) H_GET_8 (ABFD, ptr - 7); \
page; \
})
/* On output, make sure that the "reserved" field is zero. */
#define PUT_SCNHDR_PAGE(ABFD, VAL, LOC) \
do \
{ \
char * ptr = (LOC); \
if (COFF2_P (ABFD)) \
H_PUT_16 (ABFD, VAL, ptr); \
else \
{ \
H_PUT_8 (ABFD, VAL, ptr - 7); \
H_PUT_8 (ABFD, 0, ptr - 8); \
} \
} \
while (0)
#else
#define GET_SCNHDR_NLNNO(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 2))
#define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 2))
#define GET_SCNHDR_FLAGS(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 4))
#define PUT_SCNHDR_FLAGS(ABFD, VAL, LOC) \
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 4))
#define GET_SCNHDR_PAGE(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_16 (ABFD, LOC) : (unsigned) H_GET_8 (ABFD, (LOC) - 7))
/* On output, make sure that the "reserved" field is zero. */
#define PUT_SCNHDR_PAGE(ABFD, VAL, LOC) \
(COFF2_P (ABFD) \
? H_PUT_16 (ABFD, VAL, LOC) \
: H_PUT_8 (ABFD, VAL, (LOC) - 7), H_PUT_8 (ABFD, 0, (LOC) - 8))
#endif
/* TI COFF stores section size as number of bytes (address units, not octets),
so adjust to be number of octets, which is what BFD expects */
#define GET_SCNHDR_SIZE(ABFD, SZP) \
(H_GET_32 (ABFD, SZP) * bfd_octets_per_byte (ABFD))
#define PUT_SCNHDR_SIZE(ABFD, SZ, SZP) \
H_PUT_32 (ABFD, (SZ) / bfd_octets_per_byte (ABFD), SZP)
#define COFF_ADJUST_SCNHDR_IN_POST(ABFD, EXT, INT) \
do \
{ \
((struct internal_scnhdr *)(INT))->s_page = \
GET_SCNHDR_PAGE (ABFD, ((SCNHDR *)(EXT))->s_page); \
} \
while (0)
/* The entire scnhdr may not be assigned.
Ensure that everything is initialized. */
#define COFF_ADJUST_SCNHDR_OUT_PRE(ABFD, INT, EXT) \
do \
{ \
memset((EXT), 0, sizeof (SCNHDR)); \
} \
while (0)
/* The line number and reloc overflow checking in coff_swap_scnhdr_out in
coffswap.h doesn't use PUT_X for s_nlnno and s_nreloc.
Due to different sized v0/v1/v2 section headers, we have to re-write these
fields.
*/
#define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT) \
do \
{ \
PUT_SCNHDR_NLNNO (ABFD, ((struct internal_scnhdr *)(INT))->s_nlnno, \
((SCNHDR *)(EXT))->s_nlnno); \
PUT_SCNHDR_NRELOC (ABFD, ((struct internal_scnhdr *)(INT))->s_nreloc,\
((SCNHDR *)(EXT))->s_nreloc); \
PUT_SCNHDR_FLAGS (ABFD, ((struct internal_scnhdr *)(INT))->s_flags, \
((SCNHDR *)(EXT))->s_flags); \
PUT_SCNHDR_PAGE (ABFD, ((struct internal_scnhdr *)(INT))->s_page, \
((SCNHDR *)(EXT))->s_page); \
} \
while (0)
/*
* names of "special" sections
*/
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _CINIT ".cinit" /* initialized C data */
#define _SCONST ".const" /* constants */
#define _SWITCH ".switch" /* switch tables */
#define _STACK ".stack" /* C stack */
#define _SYSMEM ".sysmem" /* used for malloc et al. syscalls */
/********************** LINE NUMBERS **********************/
/* 1 line number entry for every "breakpointable" source line in a section.
* Line numbers are grouped on a per function basis; first entry in a function
* grouping will have l_lnno = 0 and in place of physical address will be the
* symbol table index of the function name.
*/
struct external_lineno {
union {
char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
char l_paddr[4]; /* (physical) address of line number */
} l_addr;
char l_lnno[2]; /* line number */
};
#define LINENO struct external_lineno
#define LINESZ 6
/********************** SYMBOLS **********************/
/* NOTE: this is what a local label looks like in assembly source; what it
looks like in COFF output is undefined */
#define TICOFF_LOCAL_LABEL_P(NAME) \
((NAME[0] == '$' && NAME[1] >= '0' && NAME[1] <= '9' && NAME[2] == '\0') \
|| NAME[strlen(NAME)-1] == '?')
#define E_SYMNMLEN 8 /* # characters in a symbol name */
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
struct external_syment
{
union {
char e_name[E_SYMNMLEN];
struct {
char e_zeroes[4];
char e_offset[4];
} e;
} e;
char e_value[4];
char e_scnum[2];
char e_type[2];
char e_sclass[1];
char e_numaux[1];
};
#define N_BTMASK (017)
#define N_TMASK (060)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
union external_auxent {
struct {
char x_tagndx[4]; /* str, un, or enum tag indx */
union {
struct {
char x_lnno[2]; /* declaration line number */
char x_size[2]; /* str/union/array size */
} x_lnsz;
char x_fsize[4]; /* size of function */
} x_misc;
union {
struct { /* if ISFCN, tag, or .bb */
char x_lnnoptr[4]; /* ptr to fcn line # */
char x_endndx[4]; /* entry ndx past block end */
} x_fcn;
struct { /* if ISARY, up to 4 dimen. */
char x_dimen[E_DIMNUM][2];
} x_ary;
} x_fcnary;
char x_tvndx[2]; /* tv index */
} x_sym;
union {
char x_fname[E_FILNMLEN];
struct {
char x_zeroes[4];
char x_offset[4];
} x_n;
} x_file;
struct {
char x_scnlen[4]; /* section length */
char x_nreloc[2]; /* # relocation entries */
char x_nlinno[2]; /* # line numbers */
} x_scn;
struct {
char x_tvfill[4]; /* tv fill value */
char x_tvlen[2]; /* length of .tv */
char x_tvran[2][2]; /* tv range */
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */
};
#define SYMENT struct external_syment
#define SYMESZ 18
#define AUXENT union external_auxent
#define AUXESZ 18
/* section lengths are in target bytes (not host bytes) */
#define GET_SCN_SCNLEN(ABFD, EXT) \
(H_GET_32 (ABFD, (EXT)->x_scn.x_scnlen) * bfd_octets_per_byte (ABFD))
#define PUT_SCN_SCNLEN(ABFD, INT, EXT) \
H_PUT_32 (ABFD, (INT) / bfd_octets_per_byte (ABFD), (EXT)->x_scn.x_scnlen)
/* lnsz size is in bits in COFF file, in bytes in BFD */
#define GET_LNSZ_SIZE(abfd, ext) \
(H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size) / (in_class != C_FIELD ? 8 : 1))
#define PUT_LNSZ_SIZE(abfd, in, ext) \
H_PUT_16 (abfd, ((in_class != C_FIELD) ? (in) * 8 : (in)), \
ext->x_sym.x_misc.x_lnsz.x_size)
/* TI COFF stores offsets for MOS and MOU in bits; BFD expects bytes
Also put the load page flag of the section into the symbol value if it's an
address. */
#ifndef NEEDS_PAGE
#define NEEDS_PAGE(X) 0
#define PAGE_MASK 0
#endif
#define COFF_ADJUST_SYM_IN_POST(ABFD, EXT, INT) \
do \
{ \
struct internal_syment *dst = (struct internal_syment *)(INT); \
if (dst->n_sclass == C_MOS || dst->n_sclass == C_MOU) \
dst->n_value /= 8; \
else if (NEEDS_PAGE (dst->n_sclass)) { \
asection *scn = coff_section_from_bfd_index (abfd, dst->n_scnum); \
dst->n_value |= (scn->lma & PAGE_MASK); \
} \
} \
while (0)
#define COFF_ADJUST_SYM_OUT_POST(ABFD, INT, EXT) \
do \
{ \
struct internal_syment *src = (struct internal_syment *)(INT); \
SYMENT *dst = (SYMENT *)(EXT); \
if (src->n_sclass == C_MOU || src->n_sclass == C_MOS) \
H_PUT_32 (abfd, src->n_value * 8, dst->e_value); \
else if (NEEDS_PAGE (src->n_sclass)) { \
H_PUT_32 (abfd, src->n_value &= ~PAGE_MASK, dst->e_value); \
} \
} \
while (0)
/* Detect section-relative absolute symbols so they get flagged with a sym
index of -1.
*/
#define SECTION_RELATIVE_ABSOLUTE_SYMBOL_P(RELOC, SECT) \
((*(RELOC)->sym_ptr_ptr)->section->output_section == (SECT) \
&& (RELOC)->howto->name[0] == 'A')
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc_v0
{
char r_vaddr[4];
char r_symndx[2];
char r_reserved[2];
char r_type[2];
};
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_reserved[2]; /* extended pmad byte for COFF2 */
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ_V0 10 /* FIXME -- coffcode.h needs fixing */
#define RELSZ 12 /* for COFF1/2 */
/* various relocation types. */
#define R_ABS 0x0000 /* no relocation */
#define R_REL13 0x002A /* 13-bit direct reference (???) */
#define R_PARTLS7 0x0028 /* 7 LSBs of an address */
#define R_PARTMS9 0x0029 /* 9MSBs of an address */
#define R_EXTWORD 0x002B /* 23-bit direct reference */
#define R_EXTWORD16 0x002C /* 16-bit direct reference to 23-bit addr*/
#define R_EXTWORDMS7 0x002D /* upper 7 bits of 23-bit address */
#endif /* COFF_TI_H */

51
coff/tic30.h Normal file
View file

@ -0,0 +1,51 @@
/* coff information for Texas Instruments TMS320C3X
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 4
#include "coff/external.h"
#define TIC30MAGIC 0xC000
#define TIC30BADMAG(x) (((x).f_magic != TIC30MAGIC))
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the z8k don't have room in the instruction for the entire
offset - eg with segments */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#define RELOC struct external_reloc
#define RELSZ 16
/* TMS320C30 relocation types. */
#define R_TIC30_ABS16 0x100 /* 16 bit absolute. */
#define R_TIC30_ABS24 0x101 /* 24 bit absolute. */
#define R_TIC30_ABS32 0x102 /* 32 bit absolute. */
#define R_TIC30_LDP 0x103 /* LDP bits 23-16 to 7-0. */
#define R_TIC30_PC16 0x104 /* 16 bit pc relative. */

47
coff/tic4x.h Normal file
View file

@ -0,0 +1,47 @@
/* TI COFF information for Texas Instruments TMS320C4X/C3X.
This file customizes the settings in coff/ti.h.
Copyright 2002, 2003, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef COFF_TIC4X_H
#define COFF_TIC4X_H
#define TIC4X_TARGET_ID 0x0093
/* Octets per byte, as a power of two. */
#define TI_TARGET_ID TIC4X_TARGET_ID
#define OCTETS_PER_BYTE_POWER 2
/* Add to howto to get absolute/sect-relative version. */
#define HOWTO_BANK 6
#define TICOFF_TARGET_ARCH bfd_arch_tic4x
/* We use COFF2. */
#define TICOFF_DEFAULT_MAGIC TICOFF2MAGIC
#define TICOFF_TARGET_MACHINE_GET(FLAGS) \
(((FLAGS) & F_VERS) ? bfd_mach_tic4x : bfd_mach_tic3x)
#define TICOFF_TARGET_MACHINE_SET(FLAGSP, MACHINE) \
do \
{ \
if ((MACHINE) == bfd_mach_tic4x) \
*(FLAGSP) |= F_VERS; \
} \
while (0)
#include "coff/ti.h"
#endif /* COFF_TIC4X_H */

60
coff/tic54x.h Normal file
View file

@ -0,0 +1,60 @@
/* TI COFF information for Texas Instruments TMS320C54X.
This file customizes the settings in coff/ti.h.
Copyright 2000, 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef COFF_TIC54X_H
#define COFF_TIC54X_H
#define TIC54X_TARGET_ID 0x98
#define TIC54XALGMAGIC 0x009B /* c54x algebraic assembler output */
#define TIC5X_TARGET_ID 0x92
#define TI_TARGET_ID TIC54X_TARGET_ID
#define OCTETS_PER_BYTE_POWER 1 /* octets per byte, as a power of two */
#define HOWTO_BANK 6 /* add to howto to get absolute/sect-relative version */
#define TICOFF_TARGET_ARCH bfd_arch_tic54x
#define TICOFF_DEFAULT_MAGIC TICOFF1MAGIC /* we use COFF1 for compatibility */
/* Page macros
The first GDB port requires flags in its remote memory access commands to
distinguish between data/prog space. Hopefully we can make this go away
eventually. Stuff the page in the upper bits of a 32-bit address, since
the c5x family only uses 16 or 23 bits.
c2x, c5x and most c54x devices have 16-bit addresses, but the c548 has
23-bit program addresses. Make sure the page flags don't interfere.
These flags are used by GDB to identify the destination page for
addresses.
*/
/* Recognized load pages (by common convention). */
#define PG_PROG 0x0 /* PROG page */
#define PG_DATA 0x1 /* DATA page */
#define PG_IO 0x2 /* I/O page */
/** Indicate whether the given storage class requires a page flag. */
#define NEEDS_PAGE(X) ((X)==C_EXT)
#define PAGE_MASK 0xFF000000
#define ADDR_MASK 0x00FFFFFF
#define PG_TO_FLAG(p) (((unsigned long)(p) & 0xFF) << 24)
#define FLAG_TO_PG(f) (((f) >> 24) & 0xFF)
#include "coff/ti.h"
#endif /* COFF_TIC54X_H */

123
coff/tic80.h Normal file
View file

@ -0,0 +1,123 @@
/* coff information for TI TMS320C80 (MVP)
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define DO_NOT_DEFINE_FILHDR
#define DO_NOT_DEFINE_SCNHDR
#define L_LNNO_SIZE 2
#include "coff/external.h"
/********************** FILE HEADER **********************/
struct external_filehdr
{
char f_magic[2]; /* magic number */
char f_nscns[2]; /* number of sections */
char f_timdat[4]; /* time & date stamp */
char f_symptr[4]; /* file pointer to symtab */
char f_nsyms[4]; /* number of symtab entries */
char f_opthdr[2]; /* sizeof(optional hdr) */
char f_flags[2]; /* flags */
char f_target_id[2];/* target id (TIc80 specific) */
};
#define TIC80_ARCH_MAGIC 0x0C1 /* Goes in the file header magic number field */
#define TIC80_TARGET_ID 0x95 /* Goes in the target id field */
#define TIC80BADMAG(x) ((x).f_magic != TIC80_ARCH_MAGIC)
#define FILHDR struct external_filehdr
#define FILHSZ 22
#define TIC80_AOUTHDR_MAGIC 0x108 /* Goes in the optional file header magic number field */
/********************** SECTION HEADER **********************/
struct external_scnhdr
{
char s_name[8]; /* section name */
char s_paddr[4]; /* physical address, aliased s_nlib */
char s_vaddr[4]; /* virtual address */
char s_size[4]; /* section size */
char s_scnptr[4]; /* file ptr to raw data for section */
char s_relptr[4]; /* file ptr to relocation */
char s_lnnoptr[4]; /* file ptr to line numbers */
char s_nreloc[2]; /* number of relocation entries */
char s_nlnno[2]; /* number of line number entries*/
char s_flags[2]; /* flags */
char s_reserved[1]; /* reserved (TIc80 specific) */
char s_mempage[1]; /* memory page number (TIc80) */
};
/* Names of "special" sections. */
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _CINIT ".cinit"
#define _CONST ".const"
#define _SWITCH ".switch"
#define _STACK ".stack"
#define _SYSMEM ".sysmem"
#define SCNHDR struct external_scnhdr
#define SCNHSZ 40
/* FIXME - need to correlate external_auxent with
TIc80 Code Generation Tools User's Guide, CG:A-25 */
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the h8 don't have room in the instruction for the entire
offset - eg the strange jump and high page addressing modes. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_reserved[2];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 12
/* TIc80 relocation types. */
#define R_ABS 0x00 /* Absolute address - no relocation */
#define R_RELLONGX 0x11 /* PP: 32 bits, direct */
#define R_PPBASE 0x34 /* PP: Global base address type */
#define R_PPLBASE 0x35 /* PP: Local base address type */
#define R_PP15 0x38 /* PP: Global 15 bit offset */
#define R_PP15W 0x39 /* PP: Global 15 bit offset divided by 4 */
#define R_PP15H 0x3A /* PP: Global 15 bit offset divided by 2 */
#define R_PP16B 0x3B /* PP: Global 16 bit offset for bytes */
#define R_PPL15 0x3C /* PP: Local 15 bit offset */
#define R_PPL15W 0x3D /* PP: Local 15 bit offset divided by 4 */
#define R_PPL15H 0x3E /* PP: Local 15 bit offset divided by 2 */
#define R_PPL16B 0x3F /* PP: Local 16 bit offset for bytes */
#define R_PPN15 0x40 /* PP: Global 15 bit negative offset */
#define R_PPN15W 0x41 /* PP: Global 15 bit negative offset divided by 4 */
#define R_PPN15H 0x42 /* PP: Global 15 bit negative offset divided by 2 */
#define R_PPN16B 0x43 /* PP: Global 16 bit negative byte offset */
#define R_PPLN15 0x44 /* PP: Local 15 bit negative offset */
#define R_PPLN15W 0x45 /* PP: Local 15 bit negative offset divided by 4 */
#define R_PPLN15H 0x46 /* PP: Local 15 bit negative offset divided by 2 */
#define R_PPLN16B 0x47 /* PP: Local 16 bit negative byte offset */
#define R_MPPCR15W 0x4E /* MP: 15 bit PC-relative divided by 4 */
#define R_MPPCR 0x4F /* MP: 32 bit PC-relative divided by 4 */

47
coff/w65.h Normal file
View file

@ -0,0 +1,47 @@
/* coff information for WDC 65816
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 4
#include "coff/external.h"
#define W65MAGIC 0x6500
#define W65BADMAG(x) (((x).f_magic != W65MAGIC))
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the w65 don't have room in the instruction for the entire
offset - eg the strange jump and high page addressing modes */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#define RELOC struct external_reloc
#define RELSZ 16

62
coff/we32k.h Normal file
View file

@ -0,0 +1,62 @@
/* coff information for we32k
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 2
#include "coff/external.h"
/* Bits for f_flags:
F_RELFLG relocation info stripped from file
F_EXEC file is executable (no unresolved external references)
F_LNNO line numbers stripped from file
F_LSYMS local symbols stripped from file
F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax). */
#define F_RELFLG (0x0001)
#define F_EXEC (0x0002)
#define F_LNNO (0x0004)
#define F_LSYMS (0x0008)
#define F_BM32B (0020000)
#define F_BM32MAU (0040000)
#define WE32KMAGIC 0x170 /* we32k sans transfer vector */
#define FBOMAGIC 0x170 /* we32k sans transfer vector */
#define MTVMAGIC 0x171 /* we32k with transfer vector */
#define RBOMAGIC 0x172 /* reserved */
#define WE32KBADMAG(x) ( ((x).f_magic != WE32KMAGIC) \
&& ((x).f_magic != FBOMAGIC) \
&& ((x).f_magic != RBOMAGIC) \
&& ((x).f_magic != MTVMAGIC))
/* More names of "special" sections. */
#define _TV ".tv"
#define _INIT ".init"
#define _FINI ".fini"
/********************** RELOCATION DIRECTIVES **********************/
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10

57
coff/x86_64.h Normal file
View file

@ -0,0 +1,57 @@
/* COFF information for AMD 64.
Copyright 2006, 2009, 2010 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA.
Written by Kai Tietz, OneVision Software GmbH&CoKg. */
#define L_LNNO_SIZE 2
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
#include "coff/external.h"
#define COFF_PAGE_SIZE 0x1000
#define AMD64MAGIC 0x8664
#define AMD64BADMAG(x) ((x).f_magic != AMD64MAGIC)
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
#define OMAGIC 0404 /* Object files, eg as output. */
#define ZMAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC /* Demand load format, eg normal ld output 0x10b. */
#define STMAGIC 0401 /* Target shlib. */
#define SHMAGIC 0443 /* Host shlib. */
/* Define some NT default values. */
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h. */
#define NT_SECTION_ALIGNMENT 0x1000
#define NT_FILE_ALIGNMENT 0x200
#define NT_DEF_RESERVE 0x100000
#define NT_DEF_COMMIT 0x1000
/* Relocation directives. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_type[2];
};
#define RELOC struct external_reloc
#define RELSZ 10

643
coff/xcoff.h Normal file
View file

@ -0,0 +1,643 @@
/* Internal format of XCOFF object file data structures for BFD.
Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005,
2009, 2010 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef _INTERNAL_XCOFF_H
#define _INTERNAL_XCOFF_H
/* XCOFF specific f_flags. */
/* File was profiled with fdpr. */
#define F_FDPR_PROF 0x0010
/* File was reordered with fdpr. */
#define F_FDPR_OPTI 0x0020
/* File use very large program support. */
#define F_DSA 0x0040
/* One aux header specifying medium page sizes is non-zero. */
#define F_VARPG 0x0100
/* Read/write sections are non-executable. */
#define F_NONEXEC 0x8000
/* Linker */
/* Names of "special" sections. */
#define _TEXT ".text"
#define _DATA ".data"
#define _BSS ".bss"
#define _PAD ".pad"
#define _LOADER ".loader"
#define _EXCEPT ".except"
#define _TYPCHK ".typchk"
/* XCOFF uses special .dwXXX sections with the type STYP_DWARF. */
#define STYP_DWARF 0x0010
/* High-order 16-bits dwarf subtypes. */
#define SSUBTYP_DWINFO 0x10000
#define SSUBTYP_DWLINE 0x20000
#define SSUBTYP_DWPBNMS 0x30000
#define SSUBTYP_DWPBTYP 0x40000
#define SSUBTYP_DWARNGE 0x50000
#define SSUBTYP_DWABREV 0x60000
#define SSUBTYP_DWSTR 0x70000
#define SSUBTYP_DWRNGES 0x80000
/* XCOFF uses a special .loader section with type STYP_LOADER. */
#define STYP_LOADER 0x1000
/* Specifies an exception section. A section of this type provides
information to identify the reason that a trap or ececptin occured within
and executable object program */
#define STYP_EXCEPT 0x0100
/* Specifies an initialized thread-local data section. */
#define STYP_TDATA 0x0400
/* Specifies an uninitialized thread-local data section. */
#define STYP_TBSS 0x0800
/* XCOFF uses a special .debug section with type STYP_DEBUG. */
#define STYP_DEBUG 0x2000
/* Specifies a type check section. A section of this type contains parameter
argument type check strings used by the AIX binder. */
#define STYP_TYPCHK 0x4000
/* XCOFF handles line number or relocation overflow by creating
another section header with STYP_OVRFLO set. */
#define STYP_OVRFLO 0x8000
#define RS6K_AOUTHDR_OMAGIC 0x0107 /* old: text & data writeable */
#define RS6K_AOUTHDR_NMAGIC 0x0108 /* new: text r/o, data r/w */
#define RS6K_AOUTHDR_ZMAGIC 0x010B /* paged: text r/o, both page-aligned */
/* XCOFF relocation types.
The relocations are described in the function
xcoff[64]_ppc_relocate_section in coff64-rs6000.c and coff-rs6000.c */
#define R_POS (0x00)
#define R_NEG (0x01)
#define R_REL (0x02)
#define R_TOC (0x03)
#define R_RTB (0x04)
#define R_GL (0x05)
#define R_TCL (0x06)
#define R_BA (0x08)
#define R_BR (0x0a)
#define R_RL (0x0c)
#define R_RLA (0x0d)
#define R_REF (0x0f)
#define R_TRL (0x12)
#define R_TRLA (0x13)
#define R_RRTBI (0x14)
#define R_RRTBA (0x15)
#define R_CAI (0x16)
#define R_CREL (0x17)
#define R_RBA (0x18)
#define R_RBAC (0x19)
#define R_RBR (0x1a)
#define R_RBRC (0x1b)
#define R_TLS (0x20)
#define R_TLS_IE (0x21)
#define R_TLS_LD (0x22)
#define R_TLS_LE (0x23)
#define R_TLSM (0x24)
#define R_TLSML (0x25)
#define R_TOCU (0x30)
#define R_TOCL (0x31)
/* Storage class #defines, from /usr/include/storclass.h that are not already
defined in internal.h */
/* Comment string in .info section */
#define C_INFO 110
/* Dwarf symbol. */
#define C_DWARF 112
/* Auxillary Symbol Entries */
/* x_smtyp values: */
#define SMTYP_ALIGN(x) ((x) >> 3) /* log2 of alignment */
#define SMTYP_SMTYP(x) ((x) & 0x7) /* symbol type */
/* Symbol type values: */
#define XTY_ER 0 /* External reference */
#define XTY_SD 1 /* Csect definition */
#define XTY_LD 2 /* Label definition */
#define XTY_CM 3 /* .BSS */
#define XTY_EM 4 /* Error message */
#define XTY_US 5 /* "Reserved for internal use" */
/* x_smclas values: */
#define XMC_PR 0 /* Read-only program code */
#define XMC_RO 1 /* Read-only constant */
#define XMC_DB 2 /* Read-only debug dictionary table */
#define XMC_TC 3 /* Read-write general TOC entry */
#define XMC_UA 4 /* Read-write unclassified */
#define XMC_RW 5 /* Read-write data */
#define XMC_GL 6 /* Read-only global linkage */
#define XMC_XO 7 /* Read-only extended operation */
#define XMC_SV 8 /* Read-only supervisor call */
#define XMC_BS 9 /* Read-write BSS */
#define XMC_DS 10 /* Read-write descriptor csect */
#define XMC_UC 11 /* Read-write unnamed Fortran common */
#define XMC_TI 12 /* Read-only traceback index csect */
#define XMC_TB 13 /* Read-only traceback table csect */
/* 14 ??? */
#define XMC_TC0 15 /* Read-write TOC anchor */
#define XMC_TD 16 /* Read-write data in TOC */
#define XMC_SV64 17 /* Read-only 64 bit supervisor call */
#define XMC_SV3264 18 /* Read-only 32 or 64 bit supervisor call */
/* The ldhdr structure. This appears at the start of the .loader
section. */
struct internal_ldhdr
{
/* The version number:
1 : 32 bit
2 : 64 bit */
unsigned long l_version;
/* The number of symbol table entries. */
bfd_size_type l_nsyms;
/* The number of relocation table entries. */
bfd_size_type l_nreloc;
/* The length of the import file string table. */
bfd_size_type l_istlen;
/* The number of import files. */
bfd_size_type l_nimpid;
/* The offset from the start of the .loader section to the first
entry in the import file table. */
bfd_size_type l_impoff;
/* The length of the string table. */
bfd_size_type l_stlen;
/* The offset from the start of the .loader section to the first
entry in the string table. */
bfd_size_type l_stoff;
/* The offset to start of the symbol table, only in XCOFF64 */
bfd_vma l_symoff;
/* The offset to the start of the relocation table, only in XCOFF64 */
bfd_vma l_rldoff;
};
/* The ldsym structure. This is used to represent a symbol in the
.loader section. */
struct internal_ldsym
{
union
{
/* The symbol name if <= SYMNMLEN characters. */
char _l_name[SYMNMLEN];
struct
{
/* Zero if the symbol name is more than SYMNMLEN characters. */
long _l_zeroes;
/* The offset in the string table if the symbol name is more
than SYMNMLEN characters. */
long _l_offset;
}
_l_l;
}
_l;
/* The symbol value. */
bfd_vma l_value;
/* The symbol section number. */
short l_scnum;
/* The symbol type and flags. */
char l_smtype;
/* The symbol storage class. */
char l_smclas;
/* The import file ID. */
bfd_size_type l_ifile;
/* Offset to the parameter type check string. */
bfd_size_type l_parm;
};
/* These flags are for the l_smtype field (the lower three bits are an
XTY_* value). */
/* Imported symbol. */
#define L_IMPORT (0x40)
/* Entry point. */
#define L_ENTRY (0x20)
/* Exported symbol. */
#define L_EXPORT (0x10)
/* Weak symbol. */
#define L_WEAK (0x08)
/* The ldrel structure. This is used to represent a reloc in the
.loader section. */
struct internal_ldrel
{
/* The reloc address. */
bfd_vma l_vaddr;
/* The symbol table index in the .loader section symbol table. */
bfd_size_type l_symndx;
/* The relocation type and size. */
short l_rtype;
/* The section number this relocation applies to. */
short l_rsecnm;
};
/* An entry in the XCOFF linker hash table. */
struct xcoff_link_hash_entry
{
struct bfd_link_hash_entry root;
/* Symbol index in output file. Set to -1 initially. Set to -2 if
there is a reloc against this symbol. */
long indx;
/* If we have created a TOC entry for this symbol, this is the .tc
section which holds it. */
asection *toc_section;
union
{
/* If we have created a TOC entry (the XCOFF_SET_TOC flag is
set), this is the offset in toc_section. */
bfd_vma toc_offset;
/* If the TOC entry comes from an input file, this is set to the
symbol index of the C_HIDEXT XMC_TC or XMC_TD symbol. */
long toc_indx;
}
u;
/* If this symbol is a function entry point which is called, this
field holds a pointer to the function descriptor. If this symbol
is a function descriptor, this field holds a pointer to the
function entry point. */
struct xcoff_link_hash_entry *descriptor;
/* The .loader symbol table entry, if there is one. */
struct internal_ldsym *ldsym;
/* If XCOFF_BUILT_LDSYM is set, this is the .loader symbol table
index. If XCOFF_BUILD_LDSYM is clear, and XCOFF_IMPORT is set,
this is the l_ifile value. */
long ldindx;
/* Some linker flags. */
unsigned long flags;
/* The storage mapping class. */
unsigned char smclas;
};
/* Flags for xcoff_link_hash_entry. */
/* Symbol is referenced by a regular object. */
#define XCOFF_REF_REGULAR 0x00000001
/* Symbol is defined by a regular object. */
#define XCOFF_DEF_REGULAR 0x00000002
/* Symbol is defined by a dynamic object. */
#define XCOFF_DEF_DYNAMIC 0x00000004
/* Symbol is used in a reloc being copied into the .loader section. */
#define XCOFF_LDREL 0x00000008
/* Symbol is the entry point. */
#define XCOFF_ENTRY 0x00000010
/* Symbol is for a function and is the target of a relocation.
The relocation may or may not be a branch-type relocation. */
#define XCOFF_CALLED 0x00000020
/* Symbol needs the TOC entry filled in. */
#define XCOFF_SET_TOC 0x00000040
/* Symbol is implicitly or explicitly imported. */
#define XCOFF_IMPORT 0x00000080
/* Symbol is explicitly exported. */
#define XCOFF_EXPORT 0x00000100
/* Symbol has been processed by xcoff_build_ldsyms. */
#define XCOFF_BUILT_LDSYM 0x00000200
/* Symbol is mentioned by a section which was not garbage collected. */
#define XCOFF_MARK 0x00000400
/* Symbol size is recorded in size_list list from hash table. */
#define XCOFF_HAS_SIZE 0x00000800
/* Symbol is a function descriptor. */
#define XCOFF_DESCRIPTOR 0x00001000
/* Multiple definitions have been for the symbol. */
#define XCOFF_MULTIPLY_DEFINED 0x00002000
/* Symbol is the __rtinit symbol. */
#define XCOFF_RTINIT 0x00004000
/* Symbol is an imported 32 bit syscall. */
#define XCOFF_SYSCALL32 0x00008000
/* Symbol is an imported 64 bit syscall. */
#define XCOFF_SYSCALL64 0x00010000
/* Symbol was not explicitly defined by the time it was marked. */
#define XCOFF_WAS_UNDEFINED 0x00020000
/* We have assigned an output XCOFF entry to this symbol. */
#define XCOFF_ALLOCATED 0x00040000
/* The XCOFF linker hash table. */
#define XCOFF_NUMBER_OF_SPECIAL_SECTIONS 6
#define XCOFF_SPECIAL_SECTION_TEXT 0
#define XCOFF_SPECIAL_SECTION_ETEXT 1
#define XCOFF_SPECIAL_SECTION_DATA 2
#define XCOFF_SPECIAL_SECTION_EDATA 3
#define XCOFF_SPECIAL_SECTION_END 4
#define XCOFF_SPECIAL_SECTION_END2 5
/* These flags indicate which of -bexpall and -bexpfull are in effect. */
#define XCOFF_EXPALL 1
#define XCOFF_EXPFULL 2
/* This structure is used to pass information through
xcoff_link_hash_traverse. */
struct xcoff_loader_info
{
/* Set if a problem occurred. */
bfd_boolean failed;
/* Output BFD. */
bfd *output_bfd;
/* Link information structure. */
struct bfd_link_info *info;
/* A mask of XCOFF_EXPALL and XCOFF_EXPFULL flags. */
unsigned int auto_export_flags;
/* Number of ldsym structures. */
size_t ldsym_count;
/* Size of string table. */
size_t string_size;
/* String table. */
char *strings;
/* Allocated size of string table. */
size_t string_alc;
};
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
from smaller values. Start with zero, widen, *then* decrement. */
#define MINUS_ONE (((bfd_vma) 0) - 1)
/* __rtinit, from /usr/include/rtinit.h. */
struct __rtinit
{
/* Pointer to runtime linker.
XXX: Is the parameter really void? */
int (*rtl) (void);
/* Offset to array of init functions, 0 if none. */
int init_offset;
/* Offset to array of fini functions, 0 if none. */
int fini_offset;
/* Size of __RTINIT_DESCRIPTOR. This value should be used instead of
sizeof(__RTINIT_DESCRIPTOR). */
int __rtinit_descriptor_size;
};
#define RTINIT_DESCRIPTOR_SIZE (12)
struct __rtinit_descriptor
{
/* Init/fini function. */
int f;
/* Offset, relative to the start of the __rtinit symbol, to name of the
function. */
int name_offset;
/* Flags */
unsigned char flags;
};
/* Archive */
#define XCOFFARMAG "<aiaff>\012"
#define XCOFFARMAGBIG "<bigaf>\012"
#define SXCOFFARMAG 8
/* The size of the ascii archive elements */
#define XCOFFARMAG_ELEMENT_SIZE 12
#define XCOFFARMAGBIG_ELEMENT_SIZE 20
/* This terminates an XCOFF archive member name. */
#define XCOFFARFMAG "`\012"
#define SXCOFFARFMAG 2
/* XCOFF archives start with this (printable) structure. */
struct xcoff_ar_file_hdr
{
/* Magic string. */
char magic[SXCOFFARMAG];
/* Offset of the member table (decimal ASCII string). */
char memoff[XCOFFARMAG_ELEMENT_SIZE];
/* Offset of the global symbol table (decimal ASCII string). */
char symoff[XCOFFARMAG_ELEMENT_SIZE];
/* Offset of the first member in the archive (decimal ASCII string). */
char firstmemoff[XCOFFARMAG_ELEMENT_SIZE];
/* Offset of the last member in the archive (decimal ASCII string). */
char lastmemoff[XCOFFARMAG_ELEMENT_SIZE];
/* Offset of the first member on the free list (decimal ASCII
string). */
char freeoff[XCOFFARMAG_ELEMENT_SIZE];
};
#define SIZEOF_AR_FILE_HDR (SXCOFFARMAG + 5 * XCOFFARMAG_ELEMENT_SIZE)
/* This is the equivalent data structure for the big archive format. */
struct xcoff_ar_file_hdr_big
{
/* Magic string. */
char magic[SXCOFFARMAG];
/* Offset of the member table (decimal ASCII string). */
char memoff[XCOFFARMAGBIG_ELEMENT_SIZE];
/* Offset of the global symbol table for 32-bit objects (decimal ASCII
string). */
char symoff[XCOFFARMAGBIG_ELEMENT_SIZE];
/* Offset of the global symbol table for 64-bit objects (decimal ASCII
string). */
char symoff64[XCOFFARMAGBIG_ELEMENT_SIZE];
/* Offset of the first member in the archive (decimal ASCII string). */
char firstmemoff[XCOFFARMAGBIG_ELEMENT_SIZE];
/* Offset of the last member in the archive (decimal ASCII string). */
char lastmemoff[XCOFFARMAGBIG_ELEMENT_SIZE];
/* Offset of the first member on the free list (decimal ASCII
string). */
char freeoff[XCOFFARMAGBIG_ELEMENT_SIZE];
};
#define SIZEOF_AR_FILE_HDR_BIG (SXCOFFARMAG + 6 * XCOFFARMAGBIG_ELEMENT_SIZE)
/* Each XCOFF archive member starts with this (printable) structure. */
struct xcoff_ar_hdr
{
/* File size not including the header (decimal ASCII string). */
char size[XCOFFARMAG_ELEMENT_SIZE];
/* File offset of next archive member (decimal ASCII string). */
char nextoff[XCOFFARMAG_ELEMENT_SIZE];
/* File offset of previous archive member (decimal ASCII string). */
char prevoff[XCOFFARMAG_ELEMENT_SIZE];
/* File mtime (decimal ASCII string). */
char date[12];
/* File UID (decimal ASCII string). */
char uid[12];
/* File GID (decimal ASCII string). */
char gid[12];
/* File mode (octal ASCII string). */
char mode[12];
/* Length of file name (decimal ASCII string). */
char namlen[4];
/* This structure is followed by the file name. The length of the
name is given in the namlen field. If the length of the name is
odd, the name is followed by a null byte. The name and optional
null byte are followed by XCOFFARFMAG, which is not included in
namlen. The contents of the archive member follow; the number of
bytes is given in the size field. */
};
#define SIZEOF_AR_HDR (3 * XCOFFARMAG_ELEMENT_SIZE + 4 * 12 + 4)
/* The equivalent for the big archive format. */
struct xcoff_ar_hdr_big
{
/* File size not including the header (decimal ASCII string). */
char size[XCOFFARMAGBIG_ELEMENT_SIZE];
/* File offset of next archive member (decimal ASCII string). */
char nextoff[XCOFFARMAGBIG_ELEMENT_SIZE];
/* File offset of previous archive member (decimal ASCII string). */
char prevoff[XCOFFARMAGBIG_ELEMENT_SIZE];
/* File mtime (decimal ASCII string). */
char date[12];
/* File UID (decimal ASCII string). */
char uid[12];
/* File GID (decimal ASCII string). */
char gid[12];
/* File mode (octal ASCII string). */
char mode[12];
/* Length of file name (decimal ASCII string). */
char namlen[4];
/* This structure is followed by the file name. The length of the
name is given in the namlen field. If the length of the name is
odd, the name is followed by a null byte. The name and optional
null byte are followed by XCOFFARFMAG, which is not included in
namlen. The contents of the archive member follow; the number of
bytes is given in the size field. */
};
#define SIZEOF_AR_HDR_BIG (3 * XCOFFARMAGBIG_ELEMENT_SIZE + 4 * 12 + 4)
/* We often have to distinguish between the old and big file format.
Make it a bit cleaner. We can use `xcoff_ardata' here because the
`hdr' member has the same size and position in both formats.
<bigaf> is the default format, return TRUE even when xcoff_ardata is
NULL. */
#ifndef SMALL_ARCHIVE
/* Creates big archives by default */
#define xcoff_big_format_p(abfd) \
((NULL != bfd_ardata (abfd) && NULL == xcoff_ardata (abfd)) || \
((NULL != bfd_ardata (abfd)) && \
(NULL != xcoff_ardata (abfd)) && \
(xcoff_ardata (abfd)->magic[1] == 'b')))
#else
/* Creates small archives by default. */
#define xcoff_big_format_p(abfd) \
(((NULL != bfd_ardata (abfd)) && \
(NULL != xcoff_ardata (abfd)) && \
(xcoff_ardata (abfd)->magic[1] == 'b')))
#endif
/* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
artdata structure. Similar for the big archive. */
#define xcoff_ardata(abfd) \
((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
#define xcoff_ardata_big(abfd) \
((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
/* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
archive element. Similar for the big archive. */
#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
#define arch_xhdr(bfd) \
((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
#define arch_xhdr_big(bfd) \
((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
/* True if symbols of class CLASS are external. */
#define EXTERN_SYM_P(CLASS) \
((CLASS) == C_EXT || (CLASS) == C_AIX_WEAKEXT)
#endif /* _INTERNAL_XCOFF_H */

60
coff/z80.h Normal file
View file

@ -0,0 +1,60 @@
/* coff information for Zilog Z80
Copyright 2005, 2010 Free Software Foundation, Inc.
Contributed by Arnold Metselaar <arnold_m@operamail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#define L_LNNO_SIZE 4
#include "coff/external.h"
/* z80 backend does not use dots in section names. */
#undef _TEXT
#define _TEXT "text"
#undef _DATA
#define _DATA "data"
#undef _BSS
#define _BSS "bss"
/* Type of cpu is stored in flags. */
#define F_MACHMASK 0xF000
/* Z80 COFF encodes the section alignment in the section header flags */
#define COFF_ALIGN_IN_SECTION_HEADER 1
#define COFF_ALIGN_IN_S_FLAGS 1
#define F_ALGNMASK 0x0F00
/* requires a power-of-two argument */
#define COFF_ENCODE_ALIGNMENT(S,X) ((S).s_flags |= (((unsigned)(X)&0xF)<<8))
/* result is a power of two */
#define COFF_DECODE_ALIGNMENT(X) (((X)>>8)&0xF)
#define Z80MAGIC 0x805A
#define Z80BADMAG(x) (((x).f_magic != Z80MAGIC))
/* Relocation directives. */
/* This format actually has more bits than we need. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#define RELOC struct external_reloc
#define RELSZ 16

49
coff/z8k.h Normal file
View file

@ -0,0 +1,49 @@
/* coff information for Zilog Z800N
Copyright 2001, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#define L_LNNO_SIZE 4
#include "coff/external.h"
/* Type of cpu is stored in flags */
#define F_Z8001 0x1000
#define F_Z8002 0x2000
#define F_MACHMASK 0xf000
#define Z8KMAGIC 0x8000
#define Z8KBADMAG(x) (((x).f_magic != Z8KMAGIC))
/********************** RELOCATION DIRECTIVES **********************/
/* The external reloc has an offset field, because some of the reloc
types on the z8k don't have room in the instruction for the entire
offset - eg with segments. */
struct external_reloc
{
char r_vaddr[4];
char r_symndx[4];
char r_offset[4];
char r_type[2];
char r_stuff[2];
};
#define RELOC struct external_reloc
#define RELSZ 16

198
gen-keyfiles.c Normal file
View file

@ -0,0 +1,198 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <endian.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <uuid/uuid.h>
#include "ccan/talloc/talloc.h"
struct efi_guid {
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
};
#if __BYTE_ORDER != __LITTLE_ENDIAN
#error Only little-endian machines are supported currently
#endif
const struct efi_guid x509_guid = { 0xa5c059a1, 0x94e4, 0x4aa7, \
{ 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72 } };
struct efi_signature_data {
struct efi_guid SignatureOwner;
uint8_t SignatureData[];
};
struct efi_signature_list {
struct efi_guid SignatureType;
uint32_t SignatureListSize;
uint32_t SignatureHeaderSize;
uint32_t SignatureSize;
/* this can follow directly, as we don't have a header */
struct efi_signature_data Signatures[];
};
struct keydata {
void *buf;
unsigned int size;
};
static void uuid_to_efi_guid(uuid_t u, struct efi_guid *e)
{
/* The UUID is in raw format, so no byte-swapping is required */
memcpy(e, u, sizeof(*e));
}
static struct keydata *slurp_file(const char *filename)
{
unsigned int bytes_read;
struct stat statbuf;
struct keydata *keydata;
int rc, fd;
keydata = talloc(NULL, struct keydata);
if (!keydata) {
perror("talloc(keydata)");
return NULL;
}
fd = open(filename, O_RDONLY);
if (fd < 0) {
perror("open");
goto err_free;
}
rc = fstat(fd, &statbuf);
if (rc) {
perror("fstat");
goto err_close;
}
keydata->size = statbuf.st_size;
keydata->buf = talloc_size(keydata, keydata->size);
if (!keydata->buf) {
perror("talloc(buf)");
goto err_close;
}
for (bytes_read = 0; bytes_read < keydata->size; bytes_read += rc) {
rc = read(fd, keydata->buf + bytes_read,
keydata->size - bytes_read);
if (rc < 0) {
perror("read");
break;
}
if (rc == 0)
break;
}
if (bytes_read < keydata->size) {
fprintf(stderr, "error reading input file\n");
goto err_close;
}
close(fd);
return keydata;
err_close:
close(fd);
err_free:
talloc_free(keydata);
return NULL;
}
static int write_file(const char *filename, void *buf, unsigned int size)
{
int fd, rc;
fd = open(filename, O_WRONLY | O_CREAT, 0644);
if (fd < 0) {
perror("open");
return -1;
}
rc = write(fd, buf, size);
if (rc != (int)size) {
perror("write");
rc = -1;
} else
rc = 0;
close(fd);
return rc;
}
static int write_output(const char *basename,
struct efi_signature_list *siglist)
{
char *filename;
/* write list */
filename = talloc_asprintf(NULL, "%s.siglist", basename);
write_file(filename, siglist, siglist->SignatureListSize);
talloc_free(filename);
/* write single entry data */
filename = talloc_asprintf(NULL, "%s.sigdata", basename);
write_file(filename, siglist->Signatures, siglist->SignatureSize);
talloc_free(filename);
return 0;
}
int main(int argc, char **argv)
{
struct efi_signature_list *siglist;
struct efi_signature_data *sigdata;
struct keydata *keydata;
const char *filename;
int rc, siglist_size;
uuid_t owner_uuid;
if (argc != 3) {
fprintf(stderr, "usage: %s <owner-uuid> <keyfile>\n", argv[0]);
return EXIT_FAILURE;
}
rc = uuid_parse(argv[1], owner_uuid);
if (rc) {
fprintf(stderr, "failed to parse uuid '%s'\n", argv[1]);
return EXIT_FAILURE;
}
filename = argv[2];
keydata = slurp_file(filename);
if (!keydata)
return EXIT_FAILURE;
siglist_size =
sizeof(struct efi_signature_list) +
sizeof(struct efi_signature_data) +
keydata->size;
siglist = talloc_size(keydata, siglist_size);
siglist->SignatureType = x509_guid;
siglist->SignatureListSize = siglist_size;
siglist->SignatureHeaderSize = 0;
siglist->SignatureSize = sizeof(struct efi_signature_data) +
keydata->size;
sigdata = siglist->Signatures;
uuid_to_efi_guid(owner_uuid, &sigdata->SignatureOwner);
memcpy(sigdata->SignatureData, keydata->buf, keydata->size);
write_output(filename, siglist);
return 0;
}

192
idc.c Normal file
View file

@ -0,0 +1,192 @@
#include <stdint.h>
#include <openssl/asn1t.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/pkcs7.h>
#include <openssl/x509.h>
#include <ccan/talloc/talloc.h>
#include "idc.h"
typedef struct idc_type_value {
ASN1_OBJECT *type;
ASN1_TYPE *value;
} IDC_TYPE_VALUE;
ASN1_SEQUENCE(IDC_TYPE_VALUE) = {
ASN1_SIMPLE(IDC_TYPE_VALUE, type, ASN1_OBJECT),
ASN1_OPT(IDC_TYPE_VALUE, value, ASN1_ANY),
} ASN1_SEQUENCE_END(IDC_TYPE_VALUE);
IMPLEMENT_ASN1_FUNCTIONS(IDC_TYPE_VALUE);
typedef struct idc_string {
int type;
union {
ASN1_BMPSTRING *unicode;
ASN1_IA5STRING *ascii;
} value;
} IDC_STRING;
ASN1_CHOICE(IDC_STRING) = {
ASN1_IMP(IDC_STRING, value.unicode, ASN1_BMPSTRING, 0),
ASN1_IMP(IDC_STRING, value.ascii, ASN1_IA5STRING, 1),
} ASN1_CHOICE_END(IDC_STRING);
IMPLEMENT_ASN1_FUNCTIONS(IDC_STRING);
typedef struct idc_link {
int type;
union {
ASN1_NULL *url;
ASN1_NULL *moniker;
IDC_STRING *file;
} value;
} IDC_LINK;
ASN1_CHOICE(IDC_LINK) = {
ASN1_IMP(IDC_LINK, value.url, ASN1_NULL, 0),
ASN1_IMP(IDC_LINK, value.moniker, ASN1_NULL, 1),
ASN1_EXP(IDC_LINK, value.file, IDC_STRING, 2),
} ASN1_CHOICE_END(IDC_LINK);
IMPLEMENT_ASN1_FUNCTIONS(IDC_LINK);
typedef struct idc_pe_image_data {
ASN1_BIT_STRING *flags;
IDC_LINK *file;
} IDC_PEID;
ASN1_SEQUENCE(IDC_PEID) = {
ASN1_SIMPLE(IDC_PEID, flags, ASN1_BIT_STRING),
ASN1_EXP(IDC_PEID, file, IDC_LINK, 0),
} ASN1_SEQUENCE_END(IDC_PEID);
IMPLEMENT_ASN1_FUNCTIONS(IDC_PEID);
typedef struct idc_digest {
X509_ALGOR *alg;
ASN1_OCTET_STRING *digest;
} IDC_DIGEST;
ASN1_SEQUENCE(IDC_DIGEST) = {
ASN1_SIMPLE(IDC_DIGEST, alg, X509_ALGOR),
ASN1_SIMPLE(IDC_DIGEST, digest, ASN1_OCTET_STRING),
} ASN1_SEQUENCE_END(IDC_DIGEST)
IMPLEMENT_ASN1_FUNCTIONS(IDC_DIGEST)
typedef struct idc {
IDC_TYPE_VALUE *data;
IDC_DIGEST *digest;
} IDC;
ASN1_SEQUENCE(IDC) = {
ASN1_SIMPLE(IDC, data, IDC_TYPE_VALUE),
ASN1_SIMPLE(IDC, digest, IDC_DIGEST),
} ASN1_SEQUENCE_END(IDC)
IMPLEMENT_ASN1_FUNCTIONS(IDC)
static int type_set_sequence(void *ctx, ASN1_TYPE *type,
void *s, const ASN1_ITEM *it)
{
uint8_t *seq_data, *tmp;
ASN1_OCTET_STRING *os;
ASN1_STRING *seq = s;
int len;
os = ASN1_STRING_new();
len = ASN1_item_i2d((ASN1_VALUE *)seq, NULL, it);
tmp = seq_data = talloc_array(ctx, uint8_t, len);
ASN1_item_i2d((ASN1_VALUE *)seq, &tmp, it);
ASN1_STRING_set(os, seq_data, len);
ASN1_TYPE_set(type, V_ASN1_SEQUENCE, os);
return 0;
}
const char obsolete[] = {
0x00, 0x3c, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x4f, 0x00, 0x62,
0x00, 0x73, 0x00, 0x6f, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x74,
0x00, 0x65, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e
};
int IDC_set(PKCS7 *p7, PKCS7_SIGNER_INFO *si, struct image *image)
{
uint8_t *buf, *tmp, sha[SHA256_DIGEST_LENGTH];
int idc_nid, peid_nid, len, rc;
IDC_PEID *peid;
ASN1_STRING *s;
ASN1_TYPE *t;
BIO *sigbio;
IDC *idc;
idc_nid = OBJ_create("1.3.6.1.4.1.311.2.1.4",
"spcIndirectDataContext",
"Indirect Data Context");
peid_nid = OBJ_create("1.3.6.1.4.1.311.2.1.15",
"spcPEImageData",
"PE Image Data");
image_hash_sha256(image, sha);
idc = IDC_new();
peid = IDC_PEID_new();
peid->file = IDC_LINK_new();
peid->file->type = 2;
peid->file->value.file = IDC_STRING_new();
peid->file->value.file->type = 0;
peid->file->value.file->value.unicode = ASN1_STRING_new();
ASN1_STRING_set(peid->file->value.file->value.unicode,
obsolete, sizeof(obsolete));
idc->data->type = OBJ_nid2obj(peid_nid);
idc->data->value = ASN1_TYPE_new();
type_set_sequence(NULL, idc->data->value, peid, &IDC_PEID_it);
idc->digest->alg->parameter = ASN1_TYPE_new();
idc->digest->alg->algorithm = OBJ_nid2obj(NID_sha256);
idc->digest->alg->parameter->type = V_ASN1_NULL;
ASN1_OCTET_STRING_set(idc->digest->digest, sha, sizeof(sha));
len = i2d_IDC(idc, NULL);
tmp = buf = talloc_array(NULL, uint8_t, len);
i2d_IDC(idc, &tmp);
/* Add the contentType authenticated attribute */
PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT,
OBJ_nid2obj(idc_nid));
/* Because the PKCS7 lib has a hard time dealing with non-standard
* data types, we create a temporary BIO to hold the signed data, so
* that the top-level PKCS7 object calculates the correct hash...
*/
sigbio = PKCS7_dataInit(p7, NULL);
BIO_write(sigbio, buf+2, len-2);
/* ... then we finalise the p7 content, which does the actual
* signing ... */
rc = PKCS7_dataFinal(p7, sigbio);
if (!rc) {
fprintf(stderr, "dataFinal failed\n");
ERR_print_errors_fp(stderr);
return -1;
}
/* ... and we replace the content with the actual IDC ASN type. */
t = ASN1_TYPE_new();
s = ASN1_STRING_new();
ASN1_STRING_set(s, buf, len);
ASN1_TYPE_set(t, V_ASN1_SEQUENCE, s);
PKCS7_set0_type_other(p7->d.sign->contents, idc_nid, t);
return 0;
}

11
idc.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef IDC_H
#define IDC_H
#include "image.h"
#include <openssl/pkcs7.h>
int IDC_set(PKCS7 *p7, PKCS7_SIGNER_INFO *si, struct image *image);
#endif /* IDC_H */

349
image.c Normal file
View file

@ -0,0 +1,349 @@
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <ccan/talloc/talloc.h>
#include <openssl/sha.h>
#include "image.h"
#define DATA_DIR_CERT_TABLE 4
struct image *image_load(const char *filename)
{
unsigned int bytes_read;
struct stat statbuf;
struct image *image;
int rc;
image = talloc(NULL, struct image);
if (!image) {
perror("talloc(image)");
return NULL;
}
image->fd = open(filename, O_RDONLY);
if (image->fd < 0) {
perror("open");
goto err;
}
rc = fstat(image->fd, &statbuf);
if (rc) {
perror("fstat");
goto err;
}
image->size = statbuf.st_size;
image->buf = talloc_size(image, image->size);
if (!image->buf) {
perror("talloc(buf)");
goto err;
}
for (bytes_read = 0; bytes_read < image->size; bytes_read += rc) {
rc = read(image->fd, image->buf + bytes_read,
image->size - bytes_read);
if (rc < 0) {
perror("read");
break;
}
if (rc == 0)
break;
}
if (bytes_read < image->size) {
fprintf(stderr, "error reading input file\n");
goto err;
}
lseek(image->fd, 0, SEEK_SET);
return image;
err:
talloc_free(image);
return NULL;
}
int image_pecoff_parse(struct image *image)
{
char nt_sig[] = {'P', 'E', 0, 0};
size_t size = image->size;
uint32_t addr;
/* sanity checks */
if (size < sizeof(*image->doshdr)) {
fprintf(stderr, "file is too small for DOS header\n");
return -1;
}
image->doshdr = image->buf;
if (image->doshdr->e_magic[0] != 0x4d
|| image->doshdr->e_magic[1] != 0x5a) {
fprintf(stderr, "Invalid DOS header magic\n");
return -1;
}
addr = *(uint32_t *)image->doshdr->e_lfanew;
if (addr >= image->size) {
fprintf(stderr, "pehdr is beyond end of file [0x%08x]\n",
addr);
return -1;
}
if (addr + sizeof(*image->pehdr) > image->size) {
fprintf(stderr, "File not large enough to contain pehdr\n");
return -1;
}
image->pehdr = image->buf + addr;
if (memcmp(image->pehdr->nt_signature, nt_sig, sizeof(nt_sig))) {
fprintf(stderr, "Invalid PE header signature\n");
return -1;
}
if (*(uint16_t *)image->pehdr->f_magic != AMD64MAGIC) {
fprintf(stderr, "Invalid PE header magic for x86_64\n");
return -1;
}
if (*(uint16_t *)image->pehdr->f_opthdr != sizeof(*image->aouthdr)) {
fprintf(stderr, "Invalid a.out header size\n");
return -1;
}
if (image->size < sizeof(*image->doshdr) + sizeof(*image->pehdr)
+ sizeof(*image->aouthdr)) {
fprintf(stderr, "file is too small for a.out header\n");
return -1;
}
/* a.out header directly follows PE header */
image->aouthdr = (void *)(image->pehdr+1);
if (image->aouthdr->standard.magic[0] != 0x0b ||
image->aouthdr->standard.magic[1] != 0x02) {
fprintf(stderr, "Invalid a.out machine type\n");
return -1;
}
image->data_dir = (void *)image->aouthdr->DataDirectory;
image->data_dir_sigtable = &image->data_dir[DATA_DIR_CERT_TABLE];
image->checksum = (uint32_t *)image->aouthdr->CheckSum;
image->cert_table_size = image->data_dir_sigtable->size;
if (image->cert_table_size)
image->cert_table = image->buf + image->data_dir_sigtable->addr;
else
image->cert_table = NULL;
image->sections = *(uint16_t *)image->pehdr->f_nscns;
image->scnhdr = (void *)(image->aouthdr+1);
return 0;
}
static int align_up(int size, int align)
{
return (size + align - 1) & ~(align - 1);
}
static int cmp_regions(const void *p1, const void *p2)
{
const struct region *r1 = p1, *r2 = p2;
if (r1->data < r2->data)
return -1;
if (r1->data > r2->data)
return 1;
return 0;
}
static void set_region_from_range(struct region *region, void *start, void *end)
{
region->data = start;
region->size = end - start;
}
int image_find_regions(struct image *image)
{
struct region *regions;
uint32_t align;
size_t bytes;
int i;
align = *(uint32_t *)image->aouthdr->FileAlignment;
/* now we know where the checksum and cert table data is, we can
* construct regions that need to be signed */
bytes = 0;
image->n_checksum_regions = 0;
image->checksum_regions = NULL;
image->n_checksum_regions = 3;
image->checksum_regions = talloc_zero_array(image,
struct region,
image->n_checksum_regions);
/* first region: beginning to checksum field */
regions = image->checksum_regions;
set_region_from_range(&regions[0], image->buf, image->checksum);
regions[0].name = "begin->cksum";
bytes += regions[0].size;
bytes += sizeof(*image->checksum);
/* second region: end of checksum to certificate table entry */
set_region_from_range(&regions[1],
image->checksum + 1,
image->data_dir_sigtable
);
regions[1].name = "cksum->datadir[CERT]";
bytes += regions[1].size;
bytes += sizeof(struct data_dir_entry);
/* third region: end of checksum to end of headers */
set_region_from_range(&regions[2],
(void *)image->data_dir_sigtable
+ sizeof(struct data_dir_entry),
image->buf +
*(uint32_t *)image->aouthdr->SizeOfHeaders);
regions[2].name = "datadir[CERT]->headers";
bytes += regions[2].size;
/* add COFF sections */
for (i = 0; i < image->sections; i++) {
uint32_t file_offset, file_size;
file_offset = *(uint32_t *)image->scnhdr[i].s_scnptr;
file_size = *(uint32_t *)image->scnhdr[i].s_size;
if (!file_size)
continue;
image->n_checksum_regions++;
image->checksum_regions = talloc_realloc(image,
image->checksum_regions,
struct region,
image->n_checksum_regions);
regions = image->checksum_regions;
regions[i + 3].data = image->buf + file_offset;
regions[i + 3].size = align_up(file_size, align);
regions[i + 3].name = talloc_strndup(image->checksum_regions,
image->scnhdr[i].s_name, 8);
bytes += regions[i + 3].size;
}
if (bytes != image->size) {
fprintf(stderr, "warning: data remaining[%zd vs %zd]: gaps "
"between PE/COFF sections?\n",
bytes, image->size);
}
qsort(image->checksum_regions, image->n_checksum_regions,
sizeof(struct region), cmp_regions);
return 0;
}
int image_hash_sha256(struct image *image, uint8_t digest[])
{
struct region *region;
SHA256_CTX ctx;
int rc, i, n;
rc = SHA256_Init(&ctx);
if (!rc)
return -1;
n = 0;
for (i = 0; i < image->n_checksum_regions; i++) {
region = &image->checksum_regions[i];
n += region->size;
#if 0
printf("sum region: 0x%04lx -> 0x%04lx [0x%04x bytes]\n",
region->data - image->buf,
region->data - image->buf - 1 + region->size,
region->size);
#endif
rc = SHA256_Update(&ctx, region->data, region->size);
if (!rc)
return -1;
}
rc = SHA256_Final(digest, &ctx);
return !rc;
}
static int write_buf(int fd, void *buf, int size)
{
int bytes_written, rc;
for (bytes_written = 0; bytes_written < size;) {
rc = write(fd, buf + bytes_written, size - bytes_written);
if (rc <= 0) {
perror("write");
return -1;
}
bytes_written += rc;
}
return 0;
}
int image_write_signed(struct image *image, const char *filename)
{
struct cert_table_header cert_table_header;
int fd, rc, len, padlen;
uint8_t pad[8];
cert_table_header.size = image->sigsize;
cert_table_header.revision = 0x0200; /* = revision 2 */
cert_table_header.type = 0x0002; /* PKCS signedData */
len = sizeof(cert_table_header) + image->sigsize;
/* pad to sizeof(pad)-byte boundary */
padlen = align_up(len, sizeof(pad)) - len;
/* update the image to contain signature data */
image->data_dir_sigtable->addr = image->size;
image->data_dir_sigtable->size = len + padlen;
fd = open(filename, O_WRONLY | O_CREAT, 0644);
if (fd < 0) {
perror("open");
return -1;
}
rc = write_buf(fd, image->buf, image->size);
if (rc)
goto out;
rc = write_buf(fd, &cert_table_header, sizeof(cert_table_header));
if (rc)
goto out;
rc = write_buf(fd, image->sigbuf, image->sigsize);
if (rc)
goto out;
if (padlen) {
memset(pad, 0, sizeof(pad));
rc = write_buf(fd, pad, padlen);
}
out:
close(fd);
return rc;
}

68
image.h Normal file
View file

@ -0,0 +1,68 @@
#ifndef IMAGE_H
#define IMAGE_H
#include <stdint.h>
#include <bfd.h>
#define DO_NOT_DEFINE_LINENO
#include "coff/x86_64.h"
#include "coff/external.h"
#include "coff/pe.h"
struct region {
void *data;
int size;
char *name;
};
struct image {
int fd;
void *buf;
size_t size;
/* Pointers to interesting parts of the image */
uint32_t *checksum;
struct external_PEI_DOS_hdr *doshdr;
struct external_PEI_IMAGE_hdr *pehdr;
PEPAOUTHDR *aouthdr;
struct data_dir_entry *data_dir;
struct data_dir_entry *data_dir_sigtable;
struct external_scnhdr *scnhdr;
int sections;
void *cert_table;
int cert_table_size;
/* Regions that are included in the image hash: populated
* during image parsing, then used during the hash process.
*/
struct region *checksum_regions;
int n_checksum_regions;
/* Generated signature */
void *sigbuf;
size_t sigsize;
};
struct data_dir_entry {
uint32_t addr;
uint32_t size;
} __attribute__((packed));
struct cert_table_header {
uint32_t size;
uint16_t revision;
uint16_t type;
} __attribute__((packed));
struct image *image_load(const char *filename);
int image_pecoff_parse(struct image *image);
int image_find_regions(struct image *image);
int image_hash_sha256(struct image *image, uint8_t digest[]);
int image_write_signed(struct image *image, const char *filename);
#endif /* IMAGE_H */

1
lib/ccan Submodule

@ -0,0 +1 @@
Subproject commit 5887216aa53cdb4709e9658462c4d4b2141ef91a

958
libcoff.h Normal file
View file

@ -0,0 +1,958 @@
/* DO NOT EDIT! -*- buffer-read-only: t -*- This file is automatically
generated from "libcoff-in.h" and "coffcode.h".
Run "make headers" in your build bfd/ to regenerate. */
/* BFD COFF object file private structure.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#include "bfdlink.h"
/* Object file tdata; access macros. */
#define coff_data(bfd) ((bfd)->tdata.coff_obj_data)
#define obj_pe(bfd) (coff_data (bfd)->pe)
#define obj_symbols(bfd) (coff_data (bfd)->symbols)
#define obj_sym_filepos(bfd) (coff_data (bfd)->sym_filepos)
#define obj_relocbase(bfd) (coff_data (bfd)->relocbase)
#define obj_raw_syments(bfd) (coff_data (bfd)->raw_syments)
#define obj_raw_syment_count(bfd) (coff_data (bfd)->raw_syment_count)
#define obj_convert(bfd) (coff_data (bfd)->conversion_table)
#define obj_conv_table_size(bfd) (coff_data (bfd)->conv_table_size)
#define obj_coff_external_syms(bfd) (coff_data (bfd)->external_syms)
#define obj_coff_keep_syms(bfd) (coff_data (bfd)->keep_syms)
#define obj_coff_strings(bfd) (coff_data (bfd)->strings)
#define obj_coff_keep_strings(bfd) (coff_data (bfd)->keep_strings)
#define obj_coff_sym_hashes(bfd) (coff_data (bfd)->sym_hashes)
#define obj_coff_strings_written(bfd) (coff_data (bfd)->strings_written)
#define obj_coff_local_toc_table(bfd) (coff_data (bfd)->local_toc_sym_map)
/* `Tdata' information kept for COFF files. */
typedef struct coff_tdata
{
struct coff_symbol_struct *symbols; /* Symtab for input bfd. */
unsigned int *conversion_table;
int conv_table_size;
file_ptr sym_filepos;
struct coff_ptr_struct *raw_syments;
unsigned long raw_syment_count;
/* These are only valid once writing has begun. */
long int relocbase;
/* These members communicate important constants about the symbol table
to GDB's symbol-reading code. These `constants' unfortunately vary
from coff implementation to implementation... */
unsigned local_n_btmask;
unsigned local_n_btshft;
unsigned local_n_tmask;
unsigned local_n_tshift;
unsigned local_symesz;
unsigned local_auxesz;
unsigned local_linesz;
/* The unswapped external symbols. May be NULL. Read by
_bfd_coff_get_external_symbols. */
void * external_syms;
/* If this is TRUE, the external_syms may not be freed. */
bfd_boolean keep_syms;
/* The string table. May be NULL. Read by
_bfd_coff_read_string_table. */
char *strings;
/* If this is TRUE, the strings may not be freed. */
bfd_boolean keep_strings;
/* If this is TRUE, the strings have been written out already. */
bfd_boolean strings_written;
/* Is this a PE format coff file? */
int pe;
/* Used by the COFF backend linker. */
struct coff_link_hash_entry **sym_hashes;
/* Used by the pe linker for PowerPC. */
int *local_toc_sym_map;
struct bfd_link_info *link_info;
/* Used by coff_find_nearest_line. */
void * line_info;
/* A place to stash dwarf2 info for this bfd. */
void * dwarf2_find_line_info;
/* The timestamp from the COFF file header. */
long timestamp;
/* Copy of some of the f_flags bits in the COFF filehdr structure,
used by ARM code. */
flagword flags;
/* coff-stgo32 EXE stub header after BFD tdata has been allocated. Its data
is kept in internal_filehdr.go32stub beforehand. */
char *go32stub;
} coff_data_type;
/* Tdata for pe image files. */
typedef struct pe_tdata
{
coff_data_type coff;
struct internal_extra_pe_aouthdr pe_opthdr;
int dll;
int has_reloc_section;
int dont_strip_reloc;
bfd_boolean (*in_reloc_p) (bfd *, reloc_howto_type *);
flagword real_flags;
} pe_data_type;
#define pe_data(bfd) ((bfd)->tdata.pe_obj_data)
/* Tdata for XCOFF files. */
struct xcoff_tdata
{
/* Basic COFF information. */
coff_data_type coff;
/* TRUE if this is an XCOFF64 file. */
bfd_boolean xcoff64;
/* TRUE if a large a.out header should be generated. */
bfd_boolean full_aouthdr;
/* TOC value. */
bfd_vma toc;
/* Index of section holding TOC. */
int sntoc;
/* Index of section holding entry point. */
int snentry;
/* .text alignment from optional header. */
int text_align_power;
/* .data alignment from optional header. */
int data_align_power;
/* modtype from optional header. */
short modtype;
/* cputype from optional header. */
short cputype;
/* maxdata from optional header. */
bfd_vma maxdata;
/* maxstack from optional header. */
bfd_vma maxstack;
/* Used by the XCOFF backend linker. */
asection **csects;
long *debug_indices;
unsigned int *lineno_counts;
unsigned int import_file_id;
};
#define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data)
/* We take the address of the first element of an asymbol to ensure that the
macro is only ever applied to an asymbol. */
#define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
/* The used_by_bfd field of a section may be set to a pointer to this
structure. */
struct coff_section_tdata
{
/* The relocs, swapped into COFF internal form. This may be NULL. */
struct internal_reloc *relocs;
/* If this is TRUE, the relocs entry may not be freed. */
bfd_boolean keep_relocs;
/* The section contents. This may be NULL. */
bfd_byte *contents;
/* If this is TRUE, the contents entry may not be freed. */
bfd_boolean keep_contents;
/* Information cached by coff_find_nearest_line. */
bfd_vma offset;
unsigned int i;
const char *function;
/* Optional information about a COMDAT entry; NULL if not COMDAT. */
struct coff_comdat_info *comdat;
int line_base;
/* A pointer used for .stab linking optimizations. */
void * stab_info;
/* Available for individual backends. */
void * tdata;
};
/* An accessor macro for the coff_section_tdata structure. */
#define coff_section_data(abfd, sec) \
((struct coff_section_tdata *) (sec)->used_by_bfd)
/* Tdata for sections in XCOFF files. This is used by the linker. */
struct xcoff_section_tdata
{
/* Used for XCOFF csects created by the linker; points to the real
XCOFF section which contains this csect. */
asection *enclosing;
/* The lineno_count field for the enclosing section, because we are
going to clobber it there. */
unsigned int lineno_count;
/* The first and last symbol indices for symbols used by this csect. */
unsigned long first_symndx;
unsigned long last_symndx;
};
/* An accessor macro the xcoff_section_tdata structure. */
#define xcoff_section_data(abfd, sec) \
((struct xcoff_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
/* Tdata for sections in PE files. */
struct pei_section_tdata
{
/* The virtual size of the section. */
bfd_size_type virt_size;
/* The PE section flags. */
long pe_flags;
};
/* An accessor macro for the pei_section_tdata structure. */
#define pei_section_data(abfd, sec) \
((struct pei_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
/* COFF linker hash table entries. */
struct coff_link_hash_entry
{
struct bfd_link_hash_entry root;
/* Symbol index in output file. Set to -1 initially. Set to -2 if
there is a reloc against this symbol. */
long indx;
/* Symbol type. */
unsigned short type;
/* Symbol class. */
unsigned char symbol_class;
/* Number of auxiliary entries. */
char numaux;
/* BFD to take auxiliary entries from. */
bfd *auxbfd;
/* Pointer to array of auxiliary entries, if any. */
union internal_auxent *aux;
/* Flag word; legal values follow. */
unsigned short coff_link_hash_flags;
/* Symbol is a PE section symbol. */
#define COFF_LINK_HASH_PE_SECTION_SYMBOL (01)
};
/* COFF linker hash table. */
struct coff_link_hash_table
{
struct bfd_link_hash_table root;
/* A pointer to information used to link stabs in sections. */
struct stab_info stab_info;
};
/* Look up an entry in a COFF linker hash table. */
#define coff_link_hash_lookup(table, string, create, copy, follow) \
((struct coff_link_hash_entry *) \
bfd_link_hash_lookup (&(table)->root, (string), (create), \
(copy), (follow)))
/* Traverse a COFF linker hash table. */
#define coff_link_hash_traverse(table, func, info) \
(bfd_link_hash_traverse \
(&(table)->root, \
(bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func), \
(info)))
/* Get the COFF linker hash table from a link_info structure. */
#define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
/* Functions in coffgen.c. */
extern const bfd_target *coff_object_p
(bfd *);
extern struct bfd_section *coff_section_from_bfd_index
(bfd *, int);
extern long coff_get_symtab_upper_bound
(bfd *);
extern long coff_canonicalize_symtab
(bfd *, asymbol **);
extern int coff_count_linenumbers
(bfd *);
extern struct coff_symbol_struct *coff_symbol_from
(bfd *, asymbol *);
extern bfd_boolean coff_renumber_symbols
(bfd *, int *);
extern void coff_mangle_symbols
(bfd *);
extern bfd_boolean coff_write_symbols
(bfd *);
extern bfd_boolean coff_write_linenumbers
(bfd *);
extern alent *coff_get_lineno
(bfd *, asymbol *);
extern asymbol *coff_section_symbol
(bfd *, char *);
extern bfd_boolean _bfd_coff_get_external_symbols
(bfd *);
extern const char *_bfd_coff_read_string_table
(bfd *);
extern bfd_boolean _bfd_coff_free_symbols
(bfd *);
extern struct coff_ptr_struct *coff_get_normalized_symtab
(bfd *);
extern long coff_get_reloc_upper_bound
(bfd *, sec_ptr);
extern asymbol *coff_make_empty_symbol
(bfd *);
extern void coff_print_symbol
(bfd *, void * filep, asymbol *, bfd_print_symbol_type);
extern void coff_get_symbol_info
(bfd *, asymbol *, symbol_info *ret);
extern bfd_boolean _bfd_coff_is_local_label_name
(bfd *, const char *);
extern asymbol *coff_bfd_make_debug_symbol
(bfd *, void *, unsigned long);
extern bfd_boolean coff_find_nearest_line
(bfd *, asection *, asymbol **, bfd_vma, const char **,
const char **, unsigned int *);
extern bfd_boolean coff_find_inliner_info
(bfd *, const char **, const char **, unsigned int *);
extern int coff_sizeof_headers
(bfd *, struct bfd_link_info *);
extern bfd_boolean bfd_coff_reloc16_relax_section
(bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
extern bfd_byte *bfd_coff_reloc16_get_relocated_section_contents
(bfd *, struct bfd_link_info *, struct bfd_link_order *,
bfd_byte *, bfd_boolean, asymbol **);
extern bfd_vma bfd_coff_reloc16_get_value
(arelent *, struct bfd_link_info *, asection *);
extern void bfd_perform_slip
(bfd *, unsigned int, asection *, bfd_vma);
/* Functions and types in cofflink.c. */
#define STRING_SIZE_SIZE 4
/* We use a hash table to merge identical enum, struct, and union
definitions in the linker. */
/* Information we keep for a single element (an enum value, a
structure or union field) in the debug merge hash table. */
struct coff_debug_merge_element
{
/* Next element. */
struct coff_debug_merge_element *next;
/* Name. */
const char *name;
/* Type. */
unsigned int type;
/* Symbol index for complex type. */
long tagndx;
};
/* A linked list of debug merge entries for a given name. */
struct coff_debug_merge_type
{
/* Next type with the same name. */
struct coff_debug_merge_type *next;
/* Class of type. */
int type_class;
/* Symbol index where this type is defined. */
long indx;
/* List of elements. */
struct coff_debug_merge_element *elements;
};
/* Information we store in the debug merge hash table. */
struct coff_debug_merge_hash_entry
{
struct bfd_hash_entry root;
/* A list of types with this name. */
struct coff_debug_merge_type *types;
};
/* The debug merge hash table. */
struct coff_debug_merge_hash_table
{
struct bfd_hash_table root;
};
/* Initialize a COFF debug merge hash table. */
#define coff_debug_merge_hash_table_init(table) \
(bfd_hash_table_init (&(table)->root, _bfd_coff_debug_merge_hash_newfunc, \
sizeof (struct coff_debug_merge_hash_entry)))
/* Free a COFF debug merge hash table. */
#define coff_debug_merge_hash_table_free(table) \
(bfd_hash_table_free (&(table)->root))
/* Look up an entry in a COFF debug merge hash table. */
#define coff_debug_merge_hash_lookup(table, string, create, copy) \
((struct coff_debug_merge_hash_entry *) \
bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
/* Information we keep for each section in the output file when doing
a relocatable link. */
struct coff_link_section_info
{
/* The relocs to be output. */
struct internal_reloc *relocs;
/* For each reloc against a global symbol whose index was not known
when the reloc was handled, the global hash table entry. */
struct coff_link_hash_entry **rel_hashes;
};
/* Information that we pass around while doing the final link step. */
struct coff_final_link_info
{
/* General link information. */
struct bfd_link_info *info;
/* Output BFD. */
bfd *output_bfd;
/* Used to indicate failure in traversal routine. */
bfd_boolean failed;
/* If doing "task linking" set only during the time when we want the
global symbol writer to convert the storage class of defined global
symbols from global to static. */
bfd_boolean global_to_static;
/* Hash table for long symbol names. */
struct bfd_strtab_hash *strtab;
/* When doing a relocatable link, an array of information kept for
each output section, indexed by the target_index field. */
struct coff_link_section_info *section_info;
/* Symbol index of last C_FILE symbol (-1 if none). */
long last_file_index;
/* Contents of last C_FILE symbol. */
struct internal_syment last_file;
/* Symbol index of first aux entry of last .bf symbol with an empty
endndx field (-1 if none). */
long last_bf_index;
/* Contents of last_bf_index aux entry. */
union internal_auxent last_bf;
/* Hash table used to merge debug information. */
struct coff_debug_merge_hash_table debug_merge;
/* Buffer large enough to hold swapped symbols of any input file. */
struct internal_syment *internal_syms;
/* Buffer large enough to hold sections of symbols of any input file. */
asection **sec_ptrs;
/* Buffer large enough to hold output indices of symbols of any
input file. */
long *sym_indices;
/* Buffer large enough to hold output symbols for any input file. */
bfd_byte *outsyms;
/* Buffer large enough to hold external line numbers for any input
section. */
bfd_byte *linenos;
/* Buffer large enough to hold any input section. */
bfd_byte *contents;
/* Buffer large enough to hold external relocs of any input section. */
bfd_byte *external_relocs;
/* Buffer large enough to hold swapped relocs of any input section. */
struct internal_reloc *internal_relocs;
};
/* Most COFF variants have no way to record the alignment of a
section. This struct is used to set a specific alignment based on
the name of the section. */
struct coff_section_alignment_entry
{
/* The section name. */
const char *name;
/* This is either (unsigned int) -1, indicating that the section
name must match exactly, or it is the number of letters which
must match at the start of the name. */
unsigned int comparison_length;
/* These macros may be used to fill in the first two fields in a
structure initialization. */
#define COFF_SECTION_NAME_EXACT_MATCH(name) (name), ((unsigned int) -1)
#define COFF_SECTION_NAME_PARTIAL_MATCH(name) (name), (sizeof (name) - 1)
/* Only use this entry if the default section alignment for this
target is at least that much (as a power of two). If this field
is COFF_ALIGNMENT_FIELD_EMPTY, it should be ignored. */
unsigned int default_alignment_min;
/* Only use this entry if the default section alignment for this
target is no greater than this (as a power of two). If this
field is COFF_ALIGNMENT_FIELD_EMPTY, it should be ignored. */
unsigned int default_alignment_max;
#define COFF_ALIGNMENT_FIELD_EMPTY ((unsigned int) -1)
/* The desired alignment for this section (as a power of two). */
unsigned int alignment_power;
};
extern struct bfd_hash_entry *_bfd_coff_link_hash_newfunc
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
extern bfd_boolean _bfd_coff_link_hash_table_init
(struct coff_link_hash_table *, bfd *,
struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *),
unsigned int);
extern struct bfd_link_hash_table *_bfd_coff_link_hash_table_create
(bfd *);
extern const char *_bfd_coff_internal_syment_name
(bfd *, const struct internal_syment *, char *);
extern bfd_boolean _bfd_coff_section_already_linked
(bfd *, asection *, struct bfd_link_info *);
extern bfd_boolean _bfd_coff_link_add_symbols
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_coff_final_link
(bfd *, struct bfd_link_info *);
extern struct internal_reloc *_bfd_coff_read_internal_relocs
(bfd *, asection *, bfd_boolean, bfd_byte *, bfd_boolean,
struct internal_reloc *);
extern bfd_boolean _bfd_coff_generic_relocate_section
(bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
struct internal_reloc *, struct internal_syment *, asection **);
extern struct bfd_hash_entry *_bfd_coff_debug_merge_hash_newfunc
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
extern bfd_boolean _bfd_coff_write_global_sym
(struct bfd_hash_entry *, void *);
extern bfd_boolean _bfd_coff_write_task_globals
(struct coff_link_hash_entry *, void *);
extern bfd_boolean _bfd_coff_link_input_bfd
(struct coff_final_link_info *, bfd *);
extern bfd_boolean _bfd_coff_reloc_link_order
(bfd *, struct coff_final_link_info *, asection *,
struct bfd_link_order *);
#define coff_get_section_contents_in_window \
_bfd_generic_get_section_contents_in_window
/* Functions in xcofflink.c. */
extern long _bfd_xcoff_get_dynamic_symtab_upper_bound
(bfd *);
extern long _bfd_xcoff_canonicalize_dynamic_symtab
(bfd *, asymbol **);
extern long _bfd_xcoff_get_dynamic_reloc_upper_bound
(bfd *);
extern long _bfd_xcoff_canonicalize_dynamic_reloc
(bfd *, arelent **, asymbol **);
extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create
(bfd *);
extern void _bfd_xcoff_bfd_link_hash_table_free
(struct bfd_link_hash_table *);
extern bfd_boolean _bfd_xcoff_bfd_link_add_symbols
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_xcoff_bfd_final_link
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_xcoff_define_common_symbol
(bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
extern bfd_boolean _bfd_ppc_xcoff_relocate_section
(bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
struct internal_reloc *, struct internal_syment *, asection **);
/* Functions in coff-ppc.c. FIXME: These are called by pe.em in the
linker, and so should start with bfd and be declared in bfd.h. */
extern bfd_boolean ppc_allocate_toc_section
(struct bfd_link_info *);
extern bfd_boolean ppc_process_before_allocation
(bfd *, struct bfd_link_info *);
/* Extracted from coffcode.h. */
typedef struct coff_ptr_struct
{
/* Remembers the offset from the first symbol in the file for
this symbol. Generated by coff_renumber_symbols. */
unsigned int offset;
/* Should the value of this symbol be renumbered. Used for
XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */
unsigned int fix_value : 1;
/* Should the tag field of this symbol be renumbered.
Created by coff_pointerize_aux. */
unsigned int fix_tag : 1;
/* Should the endidx field of this symbol be renumbered.
Created by coff_pointerize_aux. */
unsigned int fix_end : 1;
/* Should the x_csect.x_scnlen field be renumbered.
Created by coff_pointerize_aux. */
unsigned int fix_scnlen : 1;
/* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
index into the line number entries. Set by coff_slurp_symbol_table. */
unsigned int fix_line : 1;
/* The container for the symbol structure as read and translated
from the file. */
union
{
union internal_auxent auxent;
struct internal_syment syment;
} u;
} combined_entry_type;
/* Each canonical asymbol really looks like this: */
typedef struct coff_symbol_struct
{
/* The actual symbol which the rest of BFD works with */
asymbol symbol;
/* A pointer to the hidden information for this symbol */
combined_entry_type *native;
/* A pointer to the linenumber information for this symbol */
struct lineno_cache_entry *lineno;
/* Have the line numbers been relocated yet ? */
bfd_boolean done_lineno;
} coff_symbol_type;
/* COFF symbol classifications. */
enum coff_symbol_classification
{
/* Global symbol. */
COFF_SYMBOL_GLOBAL,
/* Common symbol. */
COFF_SYMBOL_COMMON,
/* Undefined symbol. */
COFF_SYMBOL_UNDEFINED,
/* Local symbol. */
COFF_SYMBOL_LOCAL,
/* PE section symbol. */
COFF_SYMBOL_PE_SECTION
};
typedef struct
{
void (*_bfd_coff_swap_aux_in)
(bfd *, void *, int, int, int, int, void *);
void (*_bfd_coff_swap_sym_in)
(bfd *, void *, void *);
void (*_bfd_coff_swap_lineno_in)
(bfd *, void *, void *);
unsigned int (*_bfd_coff_swap_aux_out)
(bfd *, void *, int, int, int, int, void *);
unsigned int (*_bfd_coff_swap_sym_out)
(bfd *, void *, void *);
unsigned int (*_bfd_coff_swap_lineno_out)
(bfd *, void *, void *);
unsigned int (*_bfd_coff_swap_reloc_out)
(bfd *, void *, void *);
unsigned int (*_bfd_coff_swap_filehdr_out)
(bfd *, void *, void *);
unsigned int (*_bfd_coff_swap_aouthdr_out)
(bfd *, void *, void *);
unsigned int (*_bfd_coff_swap_scnhdr_out)
(bfd *, void *, void *);
unsigned int _bfd_filhsz;
unsigned int _bfd_aoutsz;
unsigned int _bfd_scnhsz;
unsigned int _bfd_symesz;
unsigned int _bfd_auxesz;
unsigned int _bfd_relsz;
unsigned int _bfd_linesz;
unsigned int _bfd_filnmlen;
bfd_boolean _bfd_coff_long_filenames;
bfd_boolean _bfd_coff_long_section_names;
bfd_boolean (*_bfd_coff_set_long_section_names)
(bfd *, int);
unsigned int _bfd_coff_default_section_alignment_power;
bfd_boolean _bfd_coff_force_symnames_in_strings;
unsigned int _bfd_coff_debug_string_prefix_length;
void (*_bfd_coff_swap_filehdr_in)
(bfd *, void *, void *);
void (*_bfd_coff_swap_aouthdr_in)
(bfd *, void *, void *);
void (*_bfd_coff_swap_scnhdr_in)
(bfd *, void *, void *);
void (*_bfd_coff_swap_reloc_in)
(bfd *abfd, void *, void *);
bfd_boolean (*_bfd_coff_bad_format_hook)
(bfd *, void *);
bfd_boolean (*_bfd_coff_set_arch_mach_hook)
(bfd *, void *);
void * (*_bfd_coff_mkobject_hook)
(bfd *, void *, void *);
bfd_boolean (*_bfd_styp_to_sec_flags_hook)
(bfd *, void *, const char *, asection *, flagword *);
void (*_bfd_set_alignment_hook)
(bfd *, asection *, void *);
bfd_boolean (*_bfd_coff_slurp_symbol_table)
(bfd *);
bfd_boolean (*_bfd_coff_symname_in_debug)
(bfd *, struct internal_syment *);
bfd_boolean (*_bfd_coff_pointerize_aux_hook)
(bfd *, combined_entry_type *, combined_entry_type *,
unsigned int, combined_entry_type *);
bfd_boolean (*_bfd_coff_print_aux)
(bfd *, FILE *, combined_entry_type *, combined_entry_type *,
combined_entry_type *, unsigned int);
void (*_bfd_coff_reloc16_extra_cases)
(bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
bfd_byte *, unsigned int *, unsigned int *);
int (*_bfd_coff_reloc16_estimate)
(bfd *, asection *, arelent *, unsigned int,
struct bfd_link_info *);
enum coff_symbol_classification (*_bfd_coff_classify_symbol)
(bfd *, struct internal_syment *);
bfd_boolean (*_bfd_coff_compute_section_file_positions)
(bfd *);
bfd_boolean (*_bfd_coff_start_final_link)
(bfd *, struct bfd_link_info *);
bfd_boolean (*_bfd_coff_relocate_section)
(bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
struct internal_reloc *, struct internal_syment *, asection **);
reloc_howto_type *(*_bfd_coff_rtype_to_howto)
(bfd *, asection *, struct internal_reloc *,
struct coff_link_hash_entry *, struct internal_syment *,
bfd_vma *);
bfd_boolean (*_bfd_coff_adjust_symndx)
(bfd *, struct bfd_link_info *, bfd *, asection *,
struct internal_reloc *, bfd_boolean *);
bfd_boolean (*_bfd_coff_link_add_one_symbol)
(struct bfd_link_info *, bfd *, const char *, flagword,
asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
struct bfd_link_hash_entry **);
bfd_boolean (*_bfd_coff_link_output_has_begun)
(bfd *, struct coff_final_link_info *);
bfd_boolean (*_bfd_coff_final_link_postscript)
(bfd *, struct coff_final_link_info *);
bfd_boolean (*_bfd_coff_print_pdata)
(bfd *, void *);
} bfd_coff_backend_data;
#define coff_backend_info(abfd) \
((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
#define bfd_coff_swap_sym_in(a,e,i) \
((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
#define bfd_coff_swap_lineno_in(a,e,i) \
((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
#define bfd_coff_swap_reloc_out(abfd, i, o) \
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
#define bfd_coff_swap_lineno_out(abfd, i, o) \
((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
#define bfd_coff_swap_sym_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
#define bfd_coff_swap_filehdr_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
#define bfd_coff_long_filenames(abfd) \
(coff_backend_info (abfd)->_bfd_coff_long_filenames)
#define bfd_coff_long_section_names(abfd) \
(coff_backend_info (abfd)->_bfd_coff_long_section_names)
#define bfd_coff_set_long_section_names(abfd, enable) \
((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
#define bfd_coff_default_section_alignment_power(abfd) \
(coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
#define bfd_coff_swap_filehdr_in(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
#define bfd_coff_swap_reloc_in(abfd, i, o) \
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
#define bfd_coff_bad_format_hook(abfd, filehdr) \
((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
(abfd, filehdr, aouthdr))
#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
(abfd, scnhdr, name, section, flags_ptr))
#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
#define bfd_coff_slurp_symbol_table(abfd)\
((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
#define bfd_coff_symname_in_debug(abfd, sym)\
((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
#define bfd_coff_force_symnames_in_strings(abfd)\
(coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
#define bfd_coff_debug_string_prefix_length(abfd)\
(coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
((coff_backend_info (abfd)->_bfd_coff_print_aux)\
(abfd, file, base, symbol, aux, indaux))
#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
reloc, data, src_ptr, dst_ptr)\
((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
(abfd, section, reloc, shrink, link_info))
#define bfd_coff_classify_symbol(abfd, sym)\
((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
(abfd, sym))
#define bfd_coff_compute_section_file_positions(abfd)\
((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
(abfd))
#define bfd_coff_start_final_link(obfd, info)\
((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
(obfd, info))
#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
(obfd, info, ibfd, o, con, rel, isyms, secs))
#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
(abfd, sec, rel, h, sym, addendp))
#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
(obfd, info, ibfd, sec, rel, adjustedp))
#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
value, string, cp, coll, hashp)\
((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
(info, abfd, name, flags, section, value, string, cp, coll, hashp))
#define bfd_coff_link_output_has_begun(a,p) \
((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
#define bfd_coff_final_link_postscript(a,p) \
((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
#define bfd_coff_have_print_pdata(a) \
(coff_backend_info (a)->_bfd_coff_print_pdata)
#define bfd_coff_print_pdata(a,p) \
((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
/* Macro: Returns true if the bfd is a PE executable as opposed to a
PE object file. */
#define bfd_pei_p(abfd) \
(CONST_STRNEQ ((abfd)->xvec->name, "pei-"))

59
pkcs7-simple.c Normal file
View file

@ -0,0 +1,59 @@
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/pkcs7.h>
static const char *keyfile = "keys/archive-subkey-private.key";
static const char *certfile = "keys/archive-subkey-public.crt";
int main(void)
{
uint8_t data[] = {'m', 'e', 'e', 'p'};
ERR_load_crypto_strings();
OpenSSL_add_all_digests();
BIO *stdout_bio = BIO_new_fd(STDOUT_FILENO, 0);
BIO *privkey_bio = BIO_new_file(keyfile, "r");
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(privkey_bio, NULL, NULL, NULL);
if (!pkey) {
fprintf(stderr, "error reading private key %s\n", keyfile);
return EXIT_FAILURE;
}
if (0)
EVP_PKEY_print_public(stdout_bio, pkey, 4, NULL);
BIO *cert_bio = BIO_new_file(certfile, "r");
X509 *cert = PEM_read_bio_X509(cert_bio, NULL, NULL, NULL);
if (!pkey) {
fprintf(stderr, "error reading certificate %s\n", certfile);
return EXIT_FAILURE;
}
BIO *bio = BIO_new_mem_buf(data, sizeof(data));
PKCS7 *p7 = PKCS7_sign(cert, pkey, NULL, bio, PKCS7_BINARY);
ERR_print_errors_fp(stdout);
int ofd = open("out.pkcs7", O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (ofd < 0) {
perror("open");
return EXIT_FAILURE;
}
BIO *out_bio = BIO_new_fd(ofd, 1);
i2d_PKCS7_bio_stream(out_bio, p7, NULL, 0);
ERR_print_errors_fp(stdout);
return EXIT_SUCCESS;
}

162
sbsigntool.c Normal file
View file

@ -0,0 +1,162 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <getopt.h>
#include <openssl/pem.h>
#include <openssl/pkcs7.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <ccan/talloc/talloc.h>
#include "idc.h"
#include "image.h"
struct sign_context {
struct image *image;
const char *infilename;
const char *outfilename;
int verbose;
};
static struct option options[] = {
{ "output", required_argument, NULL, 'o' },
{ "cert", required_argument, NULL, 'c' },
{ "key", required_argument, NULL, 'k' },
{ "verbose", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 },
};
static void usage(const char *progname)
{
fprintf(stderr, "usage: %s <efi-boot-image>\n", progname);
}
static void set_default_outfilename(struct sign_context *ctx)
{
ctx->outfilename = talloc_asprintf(ctx, "%s.signed", ctx->infilename);
}
int main(int argc, char **argv)
{
const char *keyfilename, *certfilename;
struct sign_context *ctx;
uint8_t *buf;
int rc, c;
ctx = talloc_zero(NULL, struct sign_context);
keyfilename = NULL;
certfilename = NULL;
for (;;) {
int idx;
c = getopt_long(argc, argv, "o:c:k:v", options, &idx);
if (c == -1)
break;
switch (c) {
case 'o':
ctx->outfilename = talloc_strdup(ctx, optarg);
break;
case 'c':
certfilename = optarg;
break;
case 'k':
keyfilename = optarg;
break;
case 'd':
ctx->verbose = 1;
break;
}
}
if (argc != optind + 1) {
usage(argv[0]);
return EXIT_FAILURE;
}
ctx->infilename = argv[optind];
if (!ctx->outfilename)
set_default_outfilename(ctx);
if (!certfilename) {
fprintf(stderr,
"error: No certificate specified (with --cert)\n");
usage(argv[0]);
return EXIT_FAILURE;
}
if (!keyfilename) {
fprintf(stderr,
"error: No key specified (with --key)\n");
usage(argv[0]);
return EXIT_FAILURE;
}
ctx->image = image_load(ctx->infilename);
if (!ctx->image)
return EXIT_FAILURE;
talloc_steal(ctx, ctx->image);
image_pecoff_parse(ctx->image);
image_find_regions(ctx->image);
ERR_load_crypto_strings();
OpenSSL_add_all_digests();
BIO *privkey_bio = BIO_new_file(keyfilename, "r");
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(privkey_bio, NULL, NULL, NULL);
if (!pkey) {
fprintf(stderr, "error reading private key %s\n", keyfilename);
return EXIT_FAILURE;
}
BIO *cert_bio = BIO_new_file(certfilename, "r");
X509 *cert = PEM_read_bio_X509(cert_bio, NULL, NULL, NULL);
if (!pkey) {
fprintf(stderr, "error reading certificate %s\n", certfilename);
return EXIT_FAILURE;
}
const EVP_MD *md = EVP_get_digestbyname("SHA256");
/* set up the PKCS7 object */
PKCS7 *p7 = PKCS7_new();
PKCS7_set_type(p7, NID_pkcs7_signed);
PKCS7_SIGNER_INFO *si = PKCS7_sign_add_signer(p7, cert,
pkey, md, PKCS7_BINARY);
PKCS7_content_new(p7, NID_pkcs7_data);
rc = IDC_set(p7, si, ctx->image);
if (rc)
return EXIT_FAILURE;
ctx->image->sigsize = i2d_PKCS7(p7, NULL);
ctx->image->sigbuf = buf = talloc_array(ctx->image,
uint8_t, ctx->image->sigsize);
i2d_PKCS7(p7, &buf);
ERR_print_errors_fp(stdout);
image_write_signed(ctx->image, ctx->outfilename);
talloc_free(ctx);
return EXIT_SUCCESS;
}

12
sbsigntool.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef SBSIGNTOOL_H
#define SBSIGNTOOL_H
struct sign_context {
struct image *image;
const char *infilename;
const char *outfilename;
int verbose;
}
#endif /* SBSIGNTOOL_H */

65
sbverify.c Normal file
View file

@ -0,0 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include "image.h"
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/pkcs7.h>
int main(int argc, char **argv)
{
struct cert_table_header *header;
struct image *image;
uint8_t *idcbuf, tmp;
const uint8_t *buf;
int idclen, rc;
BIO *idcbio;
PKCS7 *p7;
if (argc != 2) {
fprintf(stderr, "usage: %s <boot-image>\n", argv[0]);
return EXIT_FAILURE;
}
image = image_load(argv[1]);
image_pecoff_parse(image);
header = image->buf + image->data_dir_sigtable->addr;
ERR_load_crypto_strings();
OpenSSL_add_all_digests();
buf = (void *)(header + 1);
p7 = d2i_PKCS7(NULL, &buf, header->size);
idcbuf = p7->d.sign->contents->d.other->value.asn1_string->data;
/* we don't include the type and length data in the hash */
tmp = idcbuf[1];
if (!(tmp & 0x80)) {
idclen = tmp & 0x7f;
idcbuf += 2;
} else if ((tmp & 0x82) == 0x82) {
idclen = (idcbuf[2] << 8) +
idcbuf[3];
idcbuf += 4;
}
idcbio = BIO_new(BIO_s_mem());
BIO_write(idcbio, idcbuf, idclen);
rc = PKCS7_verify(p7, NULL, NULL, idcbio, NULL,
PKCS7_BINARY | PKCS7_NOVERIFY);
if (!rc) {
printf("PKCS7 verification failed\n");
ERR_print_errors_fp(stderr);
} else {
printf("Signature verification OK\n");
}
return rc ? EXIT_SUCCESS : EXIT_FAILURE;
}

2
test.c Normal file
View file

@ -0,0 +1,2 @@
#include <openssl/asn1.h>

10
verify.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "image.h"
int main(int argc, char **argv)
{
return EXIT_SUCCESS;
}