[comp.unix.questions] S records for SUN2 & 3

news@brl-adm.ARPA (The News System <news>) (04/27/87)

I've tried to reply to this message a couple of times.  An alternate
contact route (U.S. mail or telephone) would have helped.

	>Does anyone out there have a program written that will convert
	>a.out format (preferably Sun ld output) to Motorola S-Records?
	>It would save me some time if I could find one!

The MITRE Corporation has a suite of programs to perform object file
relocation and Motorola "S" record generation for SUN2 and SUN3 format
object modules.   I've enclosed the usage descriptions for the programs
"reloc.c" and "load68.c" for your inspection.  

MITRE produces some software which is in the public domain.  If you are
interested in the source code, please contact me at one of the following
addresses.  We are not permitted to  broadcast the software indiscriminantly
so we must have written requests and establish a minimal dialogue.  The
sources for these programs are small enough that they could transmitted via the
network.  Alternatively, 9 track 1600 bpi tape distribution is available.
I can also arrange for IBM-PC diskette distribution.

					D.A.R.Y.L.	

daryl@gateway.mitre.org
daryl@mitre-gateway.ARPA

Daryl Crandall
The MITRE Corporation
1820 Dolley Madison Blvd.
Mail Stop Z425
McLean VA 22102
(703) 883-7278
------------------------------------------------------------------------
Cut here.  Following module is "load68.man"
------------------------------------------------------------------------
LOAD68									 LOAD68

NAME
	load68 - build Motorola "S" records.

SYNOPSIS
	load68 [-s addr] [-n num] [-l num] [-O] [-E] [-h] [-a] [-D]
	       [-p num] [-t addr] [-d addr] [-o out_file] [in_file]

DESCRIPTION
	Load68 reads a.out format files and converts the text and data sections
	to Motorola "S" records.  Input is read from "stdin" unless "in_file"
	is specified.  The output is sent to "stdout" unless "-o out_file" is
	specified.

	Options:
	   (Note: command line numeric input may be octal, decimal, or
	          hexadecimal)
		
		-s 	if present, requires a following address.  This address
			specifies the relative byte number of the input file
			at which to begin conversion.  Default value is 0.

		-n	if present, requires a following number.  The number
			specifies the number of input file bytes to be
			converted.  Default value is the total number of bytes
			contained in the text and data sections of the input
			file.

		-l	if present, requires a following number.  The number
			specifies the number of file bytes present in each
			"S" record. (usually 16 or 32 but may be as high as
			252.)  Default value is 32.

		-O	if present, specifies that only the odd numbered bytes
			are to be converted.  Mutually exclusive with -E.

		-E	if present, specifies that only the even numbered bytes
			are to be converted.  Mutually exclusive with -O.

		-h	indicates that output will be sent through "stdout"
			to a PM68 device and special processing is enabled
			to properly respond to messages from the PM68.
			This option implies -a option.

		-a	specifies "alternate" record format.  This forces all
			output records to be in the three byte address mode
			which generates S2 and S8 records.  If this option
			is not present, then the address mode is determined
			by the value of the address bytes being output.
			This option is kept for historical reasons only.

		-D	turns on debugging messages which are output to
			a file named "debug.log".  This option used to be
			-d in previous incarnations.

		-p	if present, requires a following number.  The number
			specifies the number of pad bytes to be sent at the
			end of each "S" record.  This is to permit downloading
			to devices which do not implement flow control.

		-r
		-R
		-t	if present, requires a following address.  The address
			specifies the address generated in the first "S" record
			of text section information.  If this option is not
			present then the default address is 0000.  The -r and 
			-R options are identical to -t and are left in for
			compatability with previous versions.


		-d	if present, requires a following address.  The address
			specifies the address generated in the first "S" record
			of data section information.  If this option is not
			present the the default address is calculated to be
			the address of the byte following the end of the text
			section information.

		-o	if present, requires a following file name.  The file
			name specifies where the "S" record output is to be
			sent.  If this option is not present then output
			defaults to "stdout".

NOTES
	This version is tailored for UCB 4.2 UNIX (SUN 3) and is
	operationally identical to the version for (SUN 1.3) which was
	converted from the load68.c program running on the PDP-11/70 
	(MITRE-LAN.ARPA) under UCB UNIX 2.9.  The PDP version had sketchy
	documentation and handled conversion of partial files (-s -n) poorly.
	This version removes all notion of "blocks".  All file addresses and
	sizes are now specified in bytes.

	This version adds the -t and -d options to permit addressing the
	text and data sections independently if required.

	This program can be used in conjunction with the program "reloc"
	to generate "S" records to be sent to a PROM programmer.
		(ex.     ld -r -d file.o -o a.out
			 reloc -t 0xff0000 -d 0x800 a.out | load68 -o file.S)

	This program uses the "stdio.h","a.out.h", include files when
	compiled on a SUN workstation using revisions 1.3 thru 3.0 of
	the Berkely 4.2 UNIX.  SUN's revision 3.0 or greater requires
	include file "sys/exec.h" also.

	The algorithm of this utility relies upon the object file format
	and may have to be modified to accomodate formats significantly
	different than the SUN (Berkely 4.2) format.  Macros defined
	in the "a.out.h" include file are used where possible to increase
	the portability of this code as much as possible.

EXAMPLES
	ld -r -d   file.o -o a.out 
	load68 a.out

	load68 a.out -o file.S

	load68 -t 0xff0000 a.out -o file.S

	load68 -s 0    -n 1000 a.out -o file1.S
	load68 -s 1000 -n 1000 a.out -o file2.S
	load68 -s 2000 -n 1000 a.out -o file3.S
	load68 -s 3000 -n 1000 a.out -o file4.S

	load68 -E a.out -o even_file.S
	load68 -O a.out -o odd_file.S

	load68 -t 0xff0000 -d 0x800 -o file.S -l 16 a.out

DIAGNOSTICS
	All normal diagnostic messages are output through "stderr".  Debug
	messages (-D option) are output to file "debug.log"

	Normal diagnostic messages report the following problems:
		
		Too many pad characters specified with -p option.

		Unrecognized options on command line.

		Inability to open input file.

		Inability to open output file.

		Wrong type of input file.

		Unexpected End_Of_File on input.

		Read errors on input.

		Write errors on output.

BUGS
	The a.out format input file can not be a "demand load format" file.
	The input file must be created by 'ld' using its -r and -d options.

	The S0 record may contain decriptive information.  However in this
	implementation only contains the address of the 1st byte converted.

	Load68 is a poor name, but is kept for historical reasons.

	The two functions (creating "S" records, and downloading to
	devices) should be implemented by separate programs.  Specifically
	the -h option and all the special code for handling the PM68 device
	should be removed!  Also, the -p option is device dependent and 
	should be handled separately.
--------------------------------------------------------------------------
Cut here.  Following module is "reloc.man"
--------------------------------------------------------------------------
RELOC									RELOC

	reloc - relocate a.out file to specified text, data, and bss addresses.
		Used primarily to prepare an object file for downloading.
	
SYNOPSIS
	reloc  [-t xxxxxx] [-d xxxxxx] [-b xxxxxx] [-] [in_file] [-o out_file]

DESCRIPTION
	Reloc reads relocatable object file format (a.out) data from stdin
	or "in_file" and adjusts the "text", "data" and "symbol table"
	sections of the a.out format file.  The relocated object file is written
	to stdout or "out_file".  Any references to addresses within
	the "text", "data", or "bss" segments are adjusted to correspond to
	specified absolute addresses for the "text", "data", and "bss" segments.

	The object file must have been previously loaded with 'ld' using
	the -r (do not strip relocation data), and the -d (satisfy all external
	references) options.

	Reloc does not link in any more relocatable modules.  All references
	must be satisfied before calling "reloc".

	The object file is read into memory and the text & data sections are
	modified to reflect the relocation destinations specified (or assumed)
	by the -t, -d, and -b options for the text, data, and bss sections.  
	The symbol table is adjusted to reflect the changes to the three 
	program sections. 
	
	The relocated file may be used as input to the program "load68" to
	convert the "text" "data", and "symbol table" information into "S"
	record format suitable for downloading.

	The reloc options perform as follows:
	  (Note: All options and parameters MUST be separated by white space.
		 Numeric input may be octal, decimal, or hexadecimal.)
		 (example:  04000, 2048, and 0x800 are equivalent addresses)

		-t if present, requires a following address to relocate
		   the text section to, otherwise it defaults to 0x0000;

		-d if present, requires a following address to relocate
		   the data section to, otherwise it defaults to the end
		   of the text segment.

		-b if present, requires a following address to relocate
		   the bss references to, otherwise it defaults to the end
		   of the data segment.

		-o if present, requires a following file name to direct the
		   relocated object file to.  This option is provided to allow
		   the utility command 'nm' to be used to print the relocated
		   values of the symbol table.  If this option is not present
		   then the relocated object file is output to stdout.

		-  if present specifies that object file input is to be
		   read from stdin.  Otherwise an input filename may
		   be specified for the "in_file" parameter.  If neither "-" nor
		   "in_file" are specified then input is read from "a.out".


NOTES
	This program uses the "stdio.h","a.out.h", include files when
	compiled on a SUN workstation using revisions 1.3 thru 3.0 of
	the Berkely 4.2 UNIX.  SUN's revision 3.0 or greater requires
	include file "sys/exec.h" also.

	The algorithm of this utility relies upon the object file format
	and may have to be modified to accomodate formats significantly
	different than the SUN (Berkely 4.2) format.  Macros defined
	in the "a.out.h" include file are used where possible to increase
	the portability of this code as much as possible.

EXAMPLE
	ld -r -d filename.o -o file_to_be_relocated -lc
	reloc -o relocated_file -t 0xff0000 -d 0x800 file_to_be_relocated
	nm relocated_file

DIAGNOSTICS
	All diagnostic messages are output through stderr.

	Diagnostic messages report the following problems:

		Improper command line format.

		Inability to allocate big buffer to hold object file in memory.

		Inability to open input file.

		Input file larger than buffer.

		Invalid type of input file.

		Unresolved external labels.

		Invalid r_symbolnum values in relocation_info structure.

		Invalid symbol type.

		Byte relocation errors.

		Word relocation errors.

		Long relocation errors.

		Invalid ntype in symbol table.

		Inability to open output file.

BUGS
	Address overflow results in an error message but there is no way
	for the program to determine the name of the variable which is out
	of range. (The r_address field of the relocation_info structure
	does not contain the index to the symbol table as advertised in
	'a.out.h'.  At the time reloc operates on the object file, the r_address
	field contains only the identity of the section that the referenced
	variable resides in.)  The r_address field does index the symbol table
	entry when an external label is unresolved.
***********************************************************************