1130812Smarcel/* This file is a modified version of 'a.out.h'.  It is to be used in all
2130812Smarcel   GNU tools modified to support the i80960 (or tools that operate on
3130812Smarcel   object files created by such tools).
4130812Smarcel
5130812Smarcel   Copyright 2001 Free Software Foundation, Inc.
6130812Smarcel
7130812Smarcel   This program is free software; you can redistribute it and/or modify
8130812Smarcel   it under the terms of the GNU General Public License as published by
9130812Smarcel   the Free Software Foundation; either version 2 of the License, or
10130812Smarcel   (at your option) any later version.
11130812Smarcel
12130812Smarcel   This program is distributed in the hope that it will be useful,
13130812Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
14130812Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15130812Smarcel   GNU General Public License for more details.
16130812Smarcel
17130812Smarcel   You should have received a copy of the GNU General Public License
18130812Smarcel   along with this program; if not, write to the Free Software
19130812Smarcel   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20130812Smarcel
21130812Smarcel/* All i80960 development is done in a CROSS-DEVELOPMENT environment.  I.e.,
22130812Smarcel   object code is generated on, and executed under the direction of a symbolic
23130812Smarcel   debugger running on, a host system.  We do not want to be subject to the
24130812Smarcel   vagaries of which host it is or whether it supports COFF or a.out format,
25130812Smarcel   or anything else.  We DO want to:
26130812Smarcel
27130812Smarcel  	o always generate the same format object files, regardless of host.
28130812Smarcel
29130812Smarcel 	o have an 'a.out' header that we can modify for our own purposes
30130812Smarcel 	  (the 80960 is typically an embedded processor and may require
31130812Smarcel 	  enhanced linker support that the normal a.out.h header can't
32130812Smarcel 	  accommodate).
33130812Smarcel
34130812Smarcel  As for byte-ordering, the following rules apply:
35130812Smarcel
36130812Smarcel 	o Text and data that is actually downloaded to the target is always
37130812Smarcel 	  in i80960 (little-endian) order.
38130812Smarcel
39130812Smarcel 	o All other numbers (in the header, symbols, relocation directives)
40130812Smarcel 	  are in host byte-order:  object files CANNOT be lifted from a
41130812Smarcel 	  little-end host and used on a big-endian (or vice versa) without
42130812Smarcel 	  modification.
43130812Smarcel  ==> THIS IS NO LONGER TRUE USING BFD.  WE CAN GENERATE ANY BYTE ORDER
44130812Smarcel      FOR THE HEADER, AND READ ANY BYTE ORDER.  PREFERENCE WOULD BE TO
45130812Smarcel      USE LITTLE-ENDIAN BYTE ORDER THROUGHOUT, REGARDLESS OF HOST.  <==
46130812Smarcel
47130812Smarcel 	o The downloader ('comm960') takes care to generate a pseudo-header
48130812Smarcel 	  with correct (i80960) byte-ordering before shipping text and data
49130812Smarcel 	  off to the NINDY monitor in the target systems.  Symbols and
50130812Smarcel 	  relocation info are never sent to the target.  */
51130812Smarcel
52130812Smarcel#define BMAGIC	0415
53130812Smarcel/* We don't accept the following (see N_BADMAG macro).
54130812Smarcel   They're just here so GNU code will compile.  */
55130812Smarcel#define	OMAGIC	0407		/* old impure format */
56130812Smarcel#define	NMAGIC	0410		/* read-only text */
57130812Smarcel#define	ZMAGIC	0413		/* demand load format */
58130812Smarcel
59130812Smarcel/* FILE HEADER
60130812Smarcel  	All 'lengths' are given as a number of bytes.
61130812Smarcel  	All 'alignments' are for relinkable files only;  an alignment of
62130812Smarcel  		'n' indicates the corresponding segment must begin at an
63130812Smarcel  		address that is a multiple of (2**n).  */
64130812Smarcelstruct external_exec
65130812Smarcel  {
66130812Smarcel    /* Standard stuff */
67130812Smarcel    unsigned char e_info[4];	/* Identifies this as a b.out file */
68130812Smarcel    unsigned char e_text[4];	/* Length of text */
69130812Smarcel    unsigned char e_data[4];	/* Length of data */
70130812Smarcel    unsigned char e_bss[4];	/* Length of uninitialized data area */
71130812Smarcel    unsigned char e_syms[4];	/* Length of symbol table */
72130812Smarcel    unsigned char e_entry[4];	/* Runtime start address */
73130812Smarcel    unsigned char e_trsize[4];	/* Length of text relocation info */
74130812Smarcel    unsigned char e_drsize[4];	/* Length of data relocation info */
75130812Smarcel
76130812Smarcel    /* Added for i960 */
77130812Smarcel    unsigned char e_tload[4];	/* Text runtime load address */
78130812Smarcel    unsigned char e_dload[4];	/* Data runtime load address */
79130812Smarcel    unsigned char e_talign[1];	/* Alignment of text segment */
80130812Smarcel    unsigned char e_dalign[1];	/* Alignment of data segment */
81130812Smarcel    unsigned char e_balign[1];	/* Alignment of bss segment */
82130812Smarcel    unsigned char e_relaxable[1];/* Assembled with enough info to allow linker to relax */
83130812Smarcel  };
84130812Smarcel
85130812Smarcel#define	EXEC_BYTES_SIZE	(sizeof (struct external_exec))
86130812Smarcel
87130812Smarcel/* These macros use the a_xxx field names, since they operate on the exec
88130812Smarcel   structure after it's been byte-swapped and realigned on the host machine.  */
89130812Smarcel#define N_BADMAG(x)	(((x).a_info)!=BMAGIC)
90130812Smarcel#define N_TXTOFF(x)	EXEC_BYTES_SIZE
91130812Smarcel#define N_DATOFF(x)	( N_TXTOFF(x) + (x).a_text )
92130812Smarcel#define N_TROFF(x)	( N_DATOFF(x) + (x).a_data )
93130812Smarcel#define N_TRELOFF	N_TROFF
94130812Smarcel#define N_DROFF(x)	( N_TROFF(x) + (x).a_trsize )
95130812Smarcel#define N_DRELOFF	N_DROFF
96130812Smarcel#define N_SYMOFF(x)	( N_DROFF(x) + (x).a_drsize )
97130812Smarcel#define N_STROFF(x)	( N_SYMOFF(x) + (x).a_syms )
98130812Smarcel#define N_DATADDR(x)	( (x).a_dload )
99130812Smarcel
100130812Smarcel/* Address of text segment in memory after it is loaded.  */
101130812Smarcel#if !defined (N_TXTADDR)
102130812Smarcel#define N_TXTADDR(x) 0
103130812Smarcel#endif
104130812Smarcel
105130812Smarcel/* A single entry in the symbol table.  */
106130812Smarcelstruct nlist
107130812Smarcel  {
108130812Smarcel    union
109130812Smarcel      {
110130812Smarcel	char*          n_name;
111130812Smarcel	struct nlist * n_next;
112130812Smarcel	long	       n_strx;	/* Index into string table	*/
113130812Smarcel      } n_un;
114130812Smarcel
115130812Smarcel    unsigned char n_type;	/* See below				*/
116130812Smarcel    char	  n_other;	/* Used in i80960 support -- see below	*/
117130812Smarcel    short	  n_desc;
118130812Smarcel    unsigned long n_value;
119130812Smarcel  };
120130812Smarcel
121130812Smarcel
122130812Smarcel/* Legal values of n_type.  */
123130812Smarcel#define N_UNDF	0	/* Undefined symbol	*/
124130812Smarcel#define N_ABS	2	/* Absolute symbol	*/
125130812Smarcel#define N_TEXT	4	/* Text symbol		*/
126130812Smarcel#define N_DATA	6	/* Data symbol		*/
127130812Smarcel#define N_BSS	8	/* BSS symbol		*/
128130812Smarcel#define N_FN	31	/* Filename symbol	*/
129130812Smarcel
130130812Smarcel#define N_EXT	1	/* External symbol (OR'd in with one of above)	*/
131130812Smarcel#define N_TYPE	036	/* Mask for all the type bits			*/
132130812Smarcel#define N_STAB	0340	/* Mask for all bits used for SDB entries 	*/
133130812Smarcel
134130812Smarcel/* MEANING OF 'n_other'
135130812Smarcel
136130812Smarcel  If non-zero, the 'n_other' fields indicates either a leaf procedure or
137130812Smarcel  a system procedure, as follows:
138130812Smarcel
139130812Smarcel 	1 <= n_other <= 32 :
140130812Smarcel 		The symbol is the entry point to a system procedure.
141130812Smarcel 		'n_value' is the address of the entry, as for any other
142130812Smarcel 		procedure.  The system procedure number (which can be used in
143130812Smarcel 		a 'calls' instruction) is (n_other-1).  These entries come from
144130812Smarcel 		'.sysproc' directives.
145130812Smarcel
146130812Smarcel 	n_other == N_CALLNAME
147130812Smarcel 		the symbol is the 'call' entry point to a leaf procedure.
148130812Smarcel 		The *next* symbol in the symbol table must be the corresponding
149130812Smarcel 		'bal' entry point to the procedure (see following).  These
150130812Smarcel 		entries come from '.leafproc' directives in which two different
151130812Smarcel 		symbols are specified (the first one is represented here).
152130812Smarcel
153130812Smarcel
154130812Smarcel 	n_other == N_BALNAME
155130812Smarcel 		the symbol is the 'bal' entry point to a leaf procedure.
156130812Smarcel 		These entries result from '.leafproc' directives in which only
157130812Smarcel 		one symbol is specified, or in which the same symbol is
158130812Smarcel 		specified twice.
159130812Smarcel
160130812Smarcel  Note that an N_CALLNAME entry *must* have a corresponding N_BALNAME entry,
161130812Smarcel  but not every N_BALNAME entry must have an N_CALLNAME entry.  */
162130812Smarcel#define N_CALLNAME	((char)-1)
163130812Smarcel#define N_BALNAME	((char)-2)
164130812Smarcel#define IS_CALLNAME(x)	(N_CALLNAME == (x))
165130812Smarcel#define IS_BALNAME(x)	(N_BALNAME == (x))
166130812Smarcel#define IS_OTHER(x)	((x)>0 && (x) <=32)
167130812Smarcel
168130812Smarcel#define b_out_relocation_info relocation_info
169130812Smarcelstruct relocation_info
170130812Smarcel  {
171130812Smarcel    int	 r_address;	/* File address of item to be relocated.  */
172130812Smarcel    unsigned
173130812Smarcel#define r_index r_symbolnum
174130812Smarcel    r_symbolnum:24,	/* Index of symbol on which relocation is based,
175130812Smarcel			   if r_extern is set.  Otherwise set to
176130812Smarcel			   either N_TEXT, N_DATA, or N_BSS to
177130812Smarcel			   indicate section on which relocation is
178130812Smarcel			   based.  */
179130812Smarcel      r_pcrel:1,	/* 1 => relocate PC-relative; else absolute
180130812Smarcel			   On i960, pc-relative implies 24-bit
181130812Smarcel			   address, absolute implies 32-bit.  */
182130812Smarcel      r_length:2,	/* Number of bytes to relocate:
183130812Smarcel			   0 => 1 byte
184130812Smarcel			   1 => 2 bytes -- used for 13 bit pcrel
185130812Smarcel			   2 => 4 bytes.  */
186130812Smarcel      r_extern:1,
187130812Smarcel      r_bsr:1,		/* Something for the GNU NS32K assembler.  */
188130812Smarcel      r_disp:1,		/* Something for the GNU NS32K assembler.  */
189130812Smarcel      r_callj:1,	/* 1 if relocation target is an i960 'callj'.  */
190130812Smarcel      r_relaxable:1;	/* 1 if enough info is left to relax the data.  */
191130812Smarcel};
192