Files
vt1200/tools/as34/as34-port.patch
T
arti 6338095683 tools: add as34/ld34 TMS34010 binutils, ported to 64-bit Linux
Andrew Morton's Unix-hosted assembler/linker for the TMS34010, fetched from the gsptools archive and patched to build on x86-64. The K&R sources silently truncate pointers there: implicit int parameter declarations and fixed-argument printf wrappers. The patch fixes those and the flex 2.6 yy_init mismatch.

hello.as34.g is harness/hello-world/hello.asm in as34 syntax. as34/ld34 reproduce the GSPA-built payload byte-for-byte (82 bytes, md5 db91788991ebba476b55a11127a36475), and the MAME hello.lua run reports the same markers, the same 1024-word VRAM block and a byte-identical frame.

build.sh downloads the upstream tarball at build time (sha256 pinned); the tree is not vendored.
2026-10-22 14:19:14 +03:00

354 lines
6.8 KiB
Diff

--- a/binutils/as34/as.l
+++ b/binutils/as34/as.l
@@ -268,7 +268,9 @@
yyGetReady()
{
-#ifdef BISON
- yy_init = 1;
-#endif
+ /* The original flex 2.5 code set yy_init = 1 here, because the old
+ * skeleton created its input buffer some other way. With flex 2.6,
+ * setting yy_init without a buffer leaves yy_c_buf_p NULL. Leave the
+ * flag alone: yylex initialises normally on first use, and YY_INPUT
+ * (am_input) supplies bytes from linebuf, not from yyin. */
}
--- a/binutils/as34/as.y
+++ b/binutils/as34/as.y
@@ -96,12 +96,12 @@
return 0;
}
-emitslcode(pexpr)
+emitslcode(expr *pexpr)
{
return doemitl(pexpr, 0);
}
-emitnslcode(pexpr)
+emitnslcode(expr *pexpr)
{
return doemitl(pexpr, 1);
}
@@ -120,11 +120,11 @@
emitsl(mode ? ~(pexpr->abspart) : pexpr->abspart);
}
-emitswcode(pexpr)
+emitswcode(expr *pexpr)
{
return doemitw(pexpr, 0);
}
-emitnswcode(pexpr)
+emitnswcode(expr *pexpr)
{
return doemitw(pexpr, 1);
}
--- a/binutils/as34/main.c
+++ b/binutils/as34/main.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdarg.h>
#include "link.h"
#include "branches.h"
@@ -46,7 +47,7 @@
#define QS_INSQUOTE 1
#define QS_INDQUOTE 2
-char *imalloc(), *mkstr(), *malloc();
+#include <stdlib.h>
main(argc, argv)
int argc;
@@ -284,7 +285,7 @@
for (inci = 0; inci < ninclpaths; inci++)
{
path = imalloc(strlen(inclpaths[inci]) +
- strlen(copyfile) + 2);
+ strlen(copyfile) + 2, "include path");
sprintf(path, "%s/%s", inclpaths[inci], copyfile);
if ((inputfiles[incldepth + 1] = fopen(path, "r"))
== NULL)
@@ -388,14 +389,15 @@
* Error handler
*/
-eprintf(str, p1, p2, p3, p4)
-char *str;
-int p1, p2, p3, p4;
+void eprintf(char *str, ...)
{
char buf[300];
+ va_list ap;
nerrors++;
- sprintf(buf, str, p1, p2, p3, p4);
+ va_start(ap, str);
+ vsnprintf(buf, sizeof buf, str, ap);
+ va_end(ap);
ameprintf("%s: %s:%d: %s\n", ourname, filenames[incldepth], linenos[incldepth], buf);
if (listing && pass2)
{
@@ -469,15 +471,18 @@
}
char *
-imalloc(nbytes, str, p1, p2)
-char *str;
+imalloc(int nbytes, char *str, ...)
{
char *ret;
+ va_list ap;
+
ret = (char *)malloc(nbytes);
if (ret == 0)
{
char buf[300];
- sprintf(buf, str, p1, p2);
+ va_start(ap, str);
+ vsnprintf(buf, sizeof buf, str, ap);
+ va_end(ap);
eprintf("Cannot allocate memory for %s\n", buf);
exit(-1);
}
@@ -503,53 +508,23 @@
VERSION >> 4, VERSION & 15);
}
-amprintf(str, p1, p2, p3, p4, p5, p6)
-char *str;
+void amprintf(char *str, ...)
{
-#ifdef A1616
- char buf[1000];
- register char *cp;
+ va_list ap;
- sprintf(buf, str, p1, p2, p3, p4, p5, p6);
- cp = buf;
- while (*cp)
- {
- if (*cp != '\r')
- {
- if (*cp == '\n')
- putchar('\r');
- putchar(*cp);
- }
- cp++;
- }
-#else
- printf(str, p1, p2, p3, p4, p5, p6);
-#endif
+ va_start(ap, str);
+ vprintf(str, ap);
+ va_end(ap);
}
-ameprintf(str, p1, p2, p3, p4, p5, p6)
-char *str;
+void ameprintf(char *str, ...)
{
-#ifdef A1616
- char buf[1000];
- register char *cp;
+ va_list ap;
- sprintf(buf, str, p1, p2, p3, p4, p5, p6);
- cp = buf;
- while (*cp)
- {
- if (*cp != '\r')
- {
- if (*cp == '\n')
- putc('\r', stderr);
- putc(*cp, stderr);
- }
- cp++;
- }
-#else
- fprintf(stderr, str, p1, p2, p3, p4, p5, p6);
-#endif
+ va_start(ap, str);
+ vfprintf(stderr, str, ap);
+ va_end(ap);
}
#ifdef A1616
--- a/binutils/as34/reloc.c
+++ b/binutils/as34/reloc.c
@@ -35,7 +35,10 @@
greloc areloc;
if (cursection > 1)
- exit(eprintf("Panic in emitreloc"));
+ {
+ eprintf("Panic in emitreloc");
+ exit(1);
+ }
if (pass2)
{
areloc.offset = offset;
@@ -62,7 +65,7 @@
} filesegs[3];
-openfiles(name)
+openfiles(char *name)
{
outfd = creat(name, 0666);
filesegs[0].filepos = LINKHDRSIZE;
@@ -315,7 +318,7 @@
close(outfd);
}
-Xwrite(fd, buf, nbytes)
+Xwrite(int fd, char *buf, int nbytes)
{
if (write(fd, buf, nbytes) != nbytes)
{
--- a/binutils/as34/support.c
+++ b/binutils/as34/support.c
@@ -278,5 +278,5 @@
char *file;
{
fprintf(stderr, "PANIC at %s:%d\n", file, line);
- abort(1);
+ abort();
}
--- a/binutils/as34/sym.c
+++ b/binutils/as34/sym.c
@@ -53,7 +53,10 @@
register int i;
if (inname == (char *)0)
- exit(eprintf("Panic1 in addsym"));
+ {
+ eprintf("Panic1 in addsym");
+ exit(1);
+ }
s = mksym();
s->n.name = inname;
--- a/binutils/ld34/gld.h
+++ b/binutils/ld34/gld.h
@@ -67,11 +67,11 @@
arfile *mkaddarfile(arfile **plist, char *name);
void readGoFile(gofile *pgofile, int readTextDataRelocStab);
void doexit(int code);
-void *imalloc();
+void *imalloc(size_t, char *, ...);
char *mkstr(char *s);
-void amprintf();
-void ameprintf();
-void amfprintf();
+void amprintf(char *, ...);
+void ameprintf(char *, ...);
+void amfprintf(FILE *, char *, ...);
void pass1(void);
void addtomastersymtab(gofile *pgofile);
void addonesym(symbol *psymbol, gofile *pgofile);
--- a/binutils/ld34/pass2.c
+++ b/binutils/ld34/pass2.c
@@ -356,9 +356,9 @@
static int
hash(char *name)
{
- register int res = 0;
+ register unsigned int res = 0;
while (*name)
- res = res * 33 + *name++;
+ res = res * 33 + (unsigned char)*name++;
return res & HASHSIZE;
}
--- a/binutils/ld34/source.c
+++ b/binutils/ld34/source.c
@@ -90,7 +90,7 @@
char *_name = name;
fixName(&_name);
- name = imalloc(strlen(sp->path) + strlen(_name) + 2);
+ name = imalloc(strlen(sp->path) + strlen(_name) + 2, "source path");
sprintf(name, "%s/%s", sp->path, _name);
fd = open(name, O_RDONLY);
free(name);
--- a/binutils/ld34/utils.c
+++ b/binutils/ld34/utils.c
@@ -1,5 +1,6 @@
#include <sys/types.h>
#include <stdio.h>
+#include <stdarg.h>
#include <link.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -267,16 +268,18 @@
}
void *
-imalloc(nbytes, m, p1, p2, p3)
-char *m;
+imalloc(size_t nbytes, char *m, ...)
{
char buf[400];
char *p;
+ va_list ap;
p = (char *)malloc(nbytes);
if (p == 0)
{
- sprintf(buf, m, p1, p2, p3);
+ va_start(ap, m);
+ vsnprintf(buf, sizeof buf, m, ap);
+ va_end(ap);
ameprintf("Not enough memory to allocate %s\n", buf);
doexit(-1);
}
@@ -295,26 +298,34 @@
}
void
-amprintf(str, p1, p2, p3, p4, p5, p6)
-char *str;
+amprintf(char *str, ...)
{
- amfprintf(stdout, str, p1, p2, p3, p4, p5, p6);
+ va_list ap;
+
+ va_start(ap, str);
+ vfprintf(stdout, str, ap);
+ va_end(ap);
}
void
-ameprintf(str, p1, p2, p3, p4, p5, p6)
-char *str;
+ameprintf(char *str, ...)
{
- amfprintf(stderr, "%s: ", ourname);
- amfprintf(stderr, str, p1, p2, p3, p4, p5, p6);
+ va_list ap;
+
+ fprintf(stderr, "%s: ", ourname);
+ va_start(ap, str);
+ vfprintf(stderr, str, ap);
+ va_end(ap);
}
void
-amfprintf(stream, str, p1, p2, p3, p4, p5, p6)
-FILE *stream;
-char *str;
+amfprintf(FILE *stream, char *str, ...)
{
- fprintf(stream, str, p1, p2, p3, p4, p5, p6);
+ va_list ap;
+
+ va_start(ap, str);
+ vfprintf(stream, str, ap);
+ va_end(ap);
fflush(stream);
}