Subject: Re: netbsd.h for binutils/bfd ...
To: None <tech-ports@netbsd.org>
From: Andrew Cagney <cagney@highland.com.au>
List: tech-ports
Date: 10/20/1994 13:02:32
Hello,

Below is most of `nbsd.h' for binutils-2.5/bfd.  It isn't much use,
however, without a long list of other changes.  I think I can get the
whole lot out the door next week.  I suggest (encourage) people to, at
that time, `review' the whole mess.

					Andrew


/* BFD back-end for NetBSD a.out-ish binaries.
   Copyright (C) 1990, 1991, 1992 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */



/*
 * NOTE:	nbsd-<cpu>.c
 *
 * The following should be defined in the host specific nbsd-<cpu>.c file
 * In the case of TARGETNAME it must start with `a.out` so that GDB knows
 * its an a.out variant.
 *
 *   #define DEFAULT_ARCH             bfd_arch_<cpu>
 *   #define MY(OP)                   CAT(bfd_netbsd_<cpu>_,OP)
 *   #define TARGETNAME               "a.out-<cpu/arch>-netbsd"
 *   #define TARGET_IS_BIG_ENDIAN_P   1 (otherwise do not define)
 *   #define BYTES_IN_WORD            4
 *   #define ARCH	              32
 *   #define PAGE_SIZE                0x1000
 *
 *   #define MACHTYPE_OK(mtype)       ((mtype) == M_<cpu>)
 * xor
 *   #define BFD_AND_EXEC_OK(ABFD, EXEC) ....
 *
 *
 */




/* NetBSD fits its header into the start of its text segment */
#define	N_HEADER_IN_TEXT(x)	1
#define MY_text_includes_header 1

/* NetBSD text segment (for executables) starts one page in */
#define TEXT_START_ADDR         PAGE_SIZE

/* Allignment between NetBSD text (read-only) and data (read-write)
   segments */
#define SEGMENT_SIZE            PAGE_SIZE


/*
 * Note: These macro's assume that the MAGIC number has already been
 *       converted from network to host byte order.
 *
 * Note: This netbsd code is _only_ interested in pure NetBSD a.out
 *       formats.  Old formats such as 386BSD are taken care of separatly.
 *       This make things simple...
 *
 * Note: Most of the below are not defined as ../include/aout/aout64.h
 *       is _more_ correct.
 *
 * Note: See the file NetBSD:/usr/include/a.out.h for an extended
 *	 description of the info field in the header
 */


/* #define N_SHARED_LIB(x) ... */
/* #define N_MAGIC ... */

#define N_MACHTYPE(exec) \
((enum machine_type)(((exec).a_info >> 16) & 0x3ff))

#define N_FLAGS(exec) \
(((exec).a_info >> 26) & 0x3f)

#define N_SET_INFO(exec, magic, type, flags) \
((exec).a_info = ((magic) & 0xffff) \
 | (((int)(type) & 0x3ff) << 16) \
 | (((flags) & 0x3f) << 26))

/* #define N_SET_MAGIC(exec, magic) ... */

#define N_SET_MACHTYPE(exec, machtype) \
((exec).a_info = \
 ((exec).a_info&0xfb00ffff) | ((((int)(machtype))&0x3ff) << 16))

#define N_SET_FLAGS(exec, flags) \
((exec).a_info = \
 ((exec).a_info&0x03ffffff) | (((flags) & 0x3f) << 26))

/* #define N_TXTADDR(exec) ... */
/* #define N_TXTOFF(exec) ... */
/* #define N_ALIGN(exec,x) ... */
/* #define N_DATADDR(exec) ... */
/* #define N_DATOFF(exec) ... */


#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "libaout.h"

#include "aout/aout64.h"
#include "aout/stab_gnu.h"
#include "aout/ar.h"


/*
 * NOTE:
 *
 * With NetBSD, the magic number is always in ntohl's "network" (big-endian)
 * byte order.  Two a.out call backs are used to convert between internal
 * host and external network ordered magic numbers.
 *
 *     MY(fix_incomming_header)
 *     MY(fix_outgoing_header)
 *
 * NOTE:
 *
 * The implementation of fix_outgoing_header is target specific.
 */
#define MY_fix_incomming_header MY(fix_incomming_header)
#define MY_fix_outgoing_header MY(fix_outgoing_header)

static void MY(fix_incomming_header) PARAMS((bfd *abfd,
					     struct internal_exec * execp,
					     struct external_exec *raw_bytes));
static void MY(fix_outgoing_header) PARAMS((bfd *abfd,
					    struct internal_exec *execp,
					    struct external_exec *raw_bytes));


/* This code is common to all the NetBSD hosts, it can't be defined
   here as some of the structures have yet to be defined */
void
MY(fix_incomming_header) (abfd, execp, raw_bytes)
     bfd *abfd;
     struct internal_exec *execp;
     struct external_exec *raw_bytes;
{
  execp->a_info = bfd_getb32(raw_bytes->e_info);
}