Article View: gnu.gcc.help
Article #52815Re: ROMming gcc 2.1 code
From: phw
Date: Thu, 07 May 1992 20:53
Date: Thu, 07 May 1992 20:53
81 lines
2405 bytes
2405 bytes
Since a few people have asked about generating S-records, here's mine.
It converts BSD-style a.out format files on standard input to Motorola
S-record format on standard output. It has been used successfully with
a 68K emulator and an IDT ROM monitor.
Pat Wood
Pipeline Associates, Inc.
--------------------------------------------
#include <stdio.h>
#include "a.out.h"
#define RECLEN 28
unsigned char buf[RECLEN * 2];
main () {
unsigned int addr;
unsigned int entry, size;
struct exec header;
register unsigned char *ptr;
register int num;
register int checksum;
read (0, &header, sizeof (header));
swaphead (&header);
if (N_BADMAG (header)) {
fprintf (stderr, "bad magic %o\n", header.a_magic);
exit (1);
}
size = header.a_text + header.a_data;
entry = header.a_entry;
lseek (0, N_TXTOFF (header), 0);
printf ("S0030000FC\n");
addr = entry;
while (size > 0) {
num = size > RECLEN ? RECLEN : size;
size -= num;
read (0, buf, num);
if (addr < 0xFFFF) {
/* S1 record */
printf ("S1%02X%04X", num + 3, addr);
checksum = num + 3 + (addr >> 8) + (addr & 0xFF);
}
else if (addr < 0xFFFFFF) {
/* S2 record */
printf ("S2%02X%06X", num + 4, addr);
checksum = num + 4 + (addr >> 16) + ((addr >> 8) & 0xFF) +
(addr & 0xFF);
}
else {
/* S3 record */
printf ("S3%02X%08X", num + 5, addr);
checksum = num + 5 + (addr >> 24) + ((addr >> 16) & 0xFF) +
((addr >> 8) & 0xFF) + (addr & 0xFF);
}
addr += num;
for (ptr = buf; num--;) {
puthex (*ptr);
checksum += *ptr++;
}
printf ("%02X\n", ~checksum & 0xFF);
}
checksum = ~(3 + (entry >> 8) + (entry & 0xFF)) & 0xFF;
printf ("S903%04X%02X\n", entry, checksum);
exit (0);
}
static char *hexchars = "0123456789ABCDEF";
puthex (x)
int x;
{
putchar (hexchars[x >> 4]);
putchar (hexchars[x & 0xF]);
}
Technical Details
Message-ID:
<9205080453.AA17260@motown>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pipeline.UUCP!phwShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,849f3eae083b38ef,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1992-05-07 13:53:18 PST Newsgroups: gnu.gcc.help Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pipeline.UUCP!phw From: phw@pipeline.UUCP Subject: Re: ROMming gcc 2.1 code Message-ID: <9205080453.AA17260@motown> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 7 May 1992 20:53:18 GMT Lines: 84