From:	CRDGW2::CRDGW2::MRGATE::"SMTP::AI.MIT.EDU::GNULISTS" 25-JUN-1991 14:08:30.88
To:	ARISIA::EVERHART
CC:	
Subj:	srecord generator for a.out files

From:	gnulists@ai.mit.edu@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.101)
	 id AA25266; Tue, 25 Jun 91 13:54:22 EDT
Received: by life.ai.mit.edu (4.1/AI-4.10) id AA09332; Tue, 25 Jun 91 08:48:33 EDT
Return-Path: <gnulists@ai.mit.edu>
Received: from wheat-chex (wheat-chex.ai.mit.edu) by life.ai.mit.edu (4.1/AI-4.10) id AA09298; Tue, 25 Jun 91 08:48:07 EDT
Received: by wheat-chex (4.1/AI-4.10) id AA16700; Tue, 25 Jun 91 08:48:04 EDT
Resent-Date: Sun, 23 Jun 91 15:07:10 edt
Resent-From: gnulists@ai.mit.edu
Resent-Message-Id: <9106251248.AA16700@wheat-chex>
Received: from rutgers.edu by life.ai.mit.edu (4.1/AI-4.10) id AA02681; Sun, 23 Jun 91 22:16:45 EDT
Received: from motown.UUCP by rutgers.edu (5.59/SMI4.0/RU1.4/3.08) with UUCP 
	id AA01992; Sun, 23 Jun 91 22:09:11 EDT
Message-Id: <9106240209.AA01992@rutgers.edu>
Date: Sun, 23 Jun 91 15:07:10 edt
From: pipeline!i386!phw@motown.allied.com
Sender: gnulists@ai.mit.edu
To: help-gcc-request@prep.ai.mit.edu
Subject: srecord generator for a.out files

The following is an S record generator for a.out files.  It has been compiled
and tested on VAX, 386, and Sony News (68030) systems using 680x0 a.out files.
You may have to change some of the defines, like PAGESIZ to match your system.

Pat Wood
Pipeline Associates, Inc.
sun!pipeline!phw
pipeline!phw@motown.com

----------------------------------- cut here ----------------------------------
# To recover, type "sh archive"
echo restoring srec.c
sed 's/^X//' > srec.c <<\XxXxXxXxXx-EOF-XxXxXxXxXx
X#include <stdio.h>
X#include "a.out.h"
X
X#define RECLEN 28
X
Xunsigned char buf[RECLEN * 2];
X
Xmain () {
X	int type, addr;
X	int entry, size;
X	struct exec header;
X	register unsigned char *ptr;
X	register int num;
X	register int checksum;
X
X	read (0, &header, sizeof (header));
X	swaphead (&header);
X
X	if (N_BADMAG (header)) {
X		fprintf (stderr, "bad magic %o\n", header.a_magic);
X		exit (1);
X	}
X
X	size = header.a_text + header.a_data;
X	entry = header.a_entry;
X
X	lseek (0, N_TXTOFF (header), 0);
X
X	printf ("S0030000FC\n");
X	addr = entry;
X	while (size > 0) {
X		num = size > RECLEN ? RECLEN : size;
X		size -= num;
X		read (0, buf, num);
X		/* S1 record */
X		if (addr < 0xFFFF) {
X			printf ("S1%02X%04X", num + 3, addr);
X			checksum = num + 3 + (addr >> 8) + (addr & 0xFF);
X		}
X		/* S2 record */
X		else if (addr < 0xFFFFFF) {
X			printf ("S2%02X%06X", num + 4, addr);
X			checksum = num + 4 + (addr >> 16) + ((addr >> 8) & 0xFF) +
X				   (addr & 0xFF);
X		}
X		addr += num;
X		for (ptr = buf; num--;) {
X			puthex (*ptr);
X			checksum += *ptr++;
X		}
X		printf ("%02X\n", ~checksum & 0xFF);
X	}
X	checksum = ~(3 + (entry >> 8) + (entry & 0xFF)) & 0xFF;
X	printf ("S903%04X%02X\n", entry, checksum);
X}
X
Xstatic char *hexchars = "0123456789ABCDEF";
X
Xputhex (x)
Xint x;
X{
X	putchar (hexchars[x >> 4]);
X	putchar (hexchars[x & 0xF]);
X}
XxXxXxXxXx-EOF-XxXxXxXxXx
echo restoring a.out.h
sed 's/^X//' > a.out.h <<\XxXxXxXxXx-EOF-XxXxXxXxXx
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.  The Berkeley software License Agreement
X * specifies the terms and conditions for redistribution.
X *
X *	@(#)a.out.h	5.1 (Berkeley) 5/30/85
X */
X
X/*
X * Definitions of the a.out header
X * and magic numbers are shared with
X * the kernel.
X */
X#include "exec.h"
X#define	PAGSIZ	4096
X
X/*
X * Macros which take exec structures as arguments and tell whether
X * the file has a reasonable magic number or offsets to text|symbols|strings.
X */
X#define	N_BADMAG(x) \
X    (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
X
X#define	N_TXTOFF(x) \
X	((x).a_magic==ZMAGIC ? PAGSIZ : sizeof (struct exec))
X#define N_SYMOFF(x) \
X	(N_TXTOFF(x) + (x).a_text+(x).a_data + (x).a_trsize+(x).a_drsize)
X#define	N_STROFF(x) \
X	(N_SYMOFF(x) + (x).a_syms)
X
X/*
X * Format of a relocation datum.
X */
Xstruct relocation_info {
X	int	r_address;	/* address which is relocated */
Xunsigned int	r_symbolnum:24,	/* local symbol ordinal */
X		r_pcrel:1, 	/* was relocated pc relative already */
X		r_length:2,	/* 0=byte, 1=word, 2=long */
X		r_extern:1,	/* does not include value of sym referenced */
X		:4;		/* nothing, yet */
X};
X
X/*
X * Format of a symbol table entry; this file is included by <a.out.h>
X * and should be used if you aren't interested the a.out header
X * or relocation information.
X */
Xstruct	nlist {
X	union {
X		char	*n_name;	/* for use when in-core */
X		long	n_strx;		/* index into file string table */
X	} n_un;
Xunsigned char	n_type;		/* type flag, i.e. N_TEXT etc; see below */
X	char	n_other;	/* unused */
X	short	n_desc;		/* see <stab.h> */
Xunsigned long	n_value;	/* value of this symbol (or sdb offset) */
X};
X#define	n_hash	n_desc		/* used internally by ld */
X
X/*
X * Simple values for n_type.
X */
X#define	N_UNDF	0x0		/* undefined */
X#define	N_ABS	0x2		/* absolute */
X#define	N_TEXT	0x4		/* text */
X#define	N_DATA	0x6		/* data */
X#define	N_BSS	0x8		/* bss */
X#define	N_COMM	0x12		/* common (internal to ld) */
X#define	N_FN	0x1f		/* file name symbol */
X
X#define	N_EXT	01		/* external bit, or'ed in */
X#define	N_TYPE	0x1e		/* mask for all the type bits */
X
X/*
X * Sdb entries have some of the N_STAB bits set.
X * These are given in <stab.h>
X */
X#define	N_STAB	0xe0		/* if any of these bits set, a SDB entry */
X
X/*
X * Format for namelist values.
X */
X#define	N_FORMAT	"%08x"
XxXxXxXxXx-EOF-XxXxXxXxXx


