1/* coff information for Intel 386/486.
2
3   Copyright (C) 2001-2024 Free Software Foundation, Inc.
4
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 3 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18   MA 02110-1301, USA.  */
19
20#define L_LNNO_SIZE 2
21#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
22#include "coff/external.h"
23
24#define COFF_PAGE_SIZE	0x1000
25
26/* Bits for f_flags:
27 	F_RELFLG	Relocation info stripped from file
28 	F_EXEC		File is executable (no unresolved external references)
29 	F_LNNO		Line numbers stripped from file
30 	F_LSYMS		Local symbols stripped from file
31 	F_AR32WR	File has byte ordering of an AR32WR machine (e.g. vax).  */
32
33#define F_RELFLG	(0x0001)
34#define F_EXEC		(0x0002)
35#define F_LNNO		(0x0004)
36#define F_LSYMS		(0x0008)
37
38#define	I386MAGIC	0x14c
39#define I386PTXMAGIC	0x154
40#define I386AIXMAGIC	0x175
41
42/* This is Lynx's all-platform magic number for executables.  */
43
44#define LYNXCOFFMAGIC	0415
45
46/* .NET DLLs XOR the Machine number (above) with an override to
47    indicate that the DLL contains OS-specific machine code rather
48    than just IL or bytecode. See
49    https://github.com/dotnet/coreclr/blob/6f7aa7967c607b8c667518314ab937c0d7547025/src/inc/pedecoder.h#L94-L107. */
50#define IMAGE_FILE_MACHINE_NATIVE_APPLE_OVERRIDE   0x4644
51#define IMAGE_FILE_MACHINE_NATIVE_FREEBSD_OVERRIDE 0xadc4
52#define IMAGE_FILE_MACHINE_NATIVE_LINUX_OVERRIDE   0x7b79
53#define IMAGE_FILE_MACHINE_NATIVE_NETBSD_OVERRIDE  0x1993
54
55/* Used in some .NET DLLs that target a specific OS.  */
56#define I386_APPLE_MAGIC   (I386MAGIC ^ IMAGE_FILE_MACHINE_NATIVE_APPLE_OVERRIDE)
57#define I386_FREEBSD_MAGIC (I386MAGIC ^ IMAGE_FILE_MACHINE_NATIVE_FREEBSD_OVERRIDE)
58#define I386_LINUX_MAGIC   (I386MAGIC ^ IMAGE_FILE_MACHINE_NATIVE_LINUX_OVERRIDE)
59#define I386_NETBSD_MAGIC  (I386MAGIC ^ IMAGE_FILE_MACHINE_NATIVE_NETBSD_OVERRIDE)
60
61#define I386BADMAG(x) (  ((x).f_magic != I386MAGIC) \
62		       && (x).f_magic != I386_APPLE_MAGIC \
63		       && (x).f_magic != I386_FREEBSD_MAGIC \
64		       && (x).f_magic != I386_LINUX_MAGIC \
65		       && (x).f_magic != I386_NETBSD_MAGIC \
66		       && (x).f_magic != I386AIXMAGIC \
67		       && (x).f_magic != I386PTXMAGIC \
68		       && (x).f_magic != LYNXCOFFMAGIC)
69
70#define OMAGIC          0404    /* Object files, eg as output.  */
71#define ZMAGIC          0413    /* Demand load format, eg normal ld output.  */
72#define STMAGIC		0401	/* Target shlib.  */
73#define SHMAGIC		0443	/* Host shlib.  */
74
75/* Define some NT default values.  */
76/*  #define NT_IMAGE_BASE        0x400000 moved to internal.h */
77#define NT_SECTION_ALIGNMENT 0x1000
78#define NT_FILE_ALIGNMENT    0x200
79#define NT_DEF_RESERVE       0x100000
80#define NT_DEF_COMMIT        0x1000
81
82/* Relocation directives.  */
83
84struct external_reloc
85{
86  char r_vaddr[4];
87  char r_symndx[4];
88  char r_type[2];
89};
90
91#define RELOC struct external_reloc
92#define RELSZ 10
93
94/* i386 Relocations.  */
95
96#define R_DIR32		 6
97#define R_IMAGEBASE	 7
98#define R_SECTION	10
99#define R_SECREL32	11
100#define R_RELBYTE	15
101#define R_RELWORD	16
102#define R_RELLONG	17
103#define R_PCRBYTE	18
104#define R_PCRWORD	19
105#define R_PCRLONG	20
106