From e97116c0370426dc3568230df1e31d76a69ed39f Mon Sep 17 00:00:00 2001 From: George Koehler Date: Mon, 16 Jan 2017 18:09:55 -0500 Subject: [PATCH 1/4] Remove some obsolete code that causes a gcc warning. In my OpenBSD/amd64 system, the code becomes if (0) outname.on_valu &= ~(((0xFFFFFFFF)<<32)<<32); The 0xFFFFFFFF is a 32-bit int, so the left shift by 32 is out of range and causes the gcc warning. The intent might be to clear any sign-extended bits, if the assignment outname.on_valu = valu did sign extension. Old C had no unsigned long, so .on_valu would have been long. The code is obsolete because h/out.h now declares .on_valu as uint32_t. --- mach/proto/as/comm6.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 9cb943cba..fdbeb77ff 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -354,8 +354,6 @@ valu_t valu; outname.on_type = type; outname.on_desc = desc; outname.on_valu = valu; - if (sizeof(valu) != sizeof(long)) - outname.on_valu &= ~(((0xFFFFFFFF)<<(4*sizeof(valu_t)))<<(4*sizeof(valu_t))); wr_name(&outname, 1); } From 916d270534fb154d15f0633911bb223a190bf48a Mon Sep 17 00:00:00 2001 From: George Koehler Date: Mon, 16 Jan 2017 22:39:44 -0500 Subject: [PATCH 2/4] Delay inclusion of when compiling comm2.y See issue #1 (https://github.com/davidgiven/ack/issues/1). The file mach/proto/as/comm2.y goes through cpp twice. The _include macro, defined in comm2.y and used in comm0.h, delays the inclusion of system header files. The inclusion of wasn't delayed. This caused multiple inclusions of in FreeBSD and in OpenBSD. Use _include to delay . Also use _include for "arch.h" and "out.h", because h/out.h includes and h/arch.h might include it in the future. Sort the system includes in comm0.h by moving them up to be with . Must include before "mach0.c", because mach/powerpc/as/mach0.c needs it. Must include "mach0.c" before checking ASLD. --- mach/proto/as/comm0.h | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/mach/proto/as/comm0.h b/mach/proto/as/comm0.h index dedafa4c7..2d00c8e45 100644 --- a/mach/proto/as/comm0.h +++ b/mach/proto/as/comm0.h @@ -8,7 +8,21 @@ * All preprocessor based options/constants/functions */ -#include +#ifdef _include +_include +_include +_include +_include +_include +_include +#else +#include +#include +#include +#include +#include +#include +#endif /* ========== ON/OFF options (use #define in mach0.c) ========== */ @@ -80,23 +94,16 @@ separate linker only possible if relocation info produced /* ========== Machine independent type declarations ========== */ #ifdef _include -_include -_include -_include -_include -_include -#else -#include -#include -#include -#include -#include +#ifdef ASLD +_include "arch.h" #endif - +_include "out.h" +#else #ifdef ASLD #include "arch.h" #endif #include "out.h" +#endif #if DEBUG == 0 #define assert(ex) /* nothing */ @@ -265,6 +272,3 @@ typedef struct sect_t sect_t; #define MACHREL_BWR (0) #endif #endif - -extern FILE *fopen(); /* some systems don't have this in stdio.h */ - From ba2a03705e497239fb73c8d030789bd773eca8e5 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Tue, 17 Jan 2017 16:41:29 -0500 Subject: [PATCH 3/4] Use prototypes in mach/proto/as/comm5.c Order the function prototypes in comm1.h to match the order of the function definitions in *.c files. --- mach/proto/as/comm1.h | 33 +++++++++++++--------- mach/proto/as/comm5.c | 66 ++++++++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index 6a40a2e90..b3011ac97 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -104,21 +104,28 @@ extern struct outhead outhead; extern int curr_token; /* forward function declarations */ +/* comm5.c */ +int yylex(void); +void putval(int); +int getval(int); +int nextchar(void); #ifdef ASLD -extern char *readident(); +char *readident(int); #endif -extern char *remember(); -extern item_t *fb_shift(); -extern item_t *fb_alloc(); -extern item_t *item_alloc(); -extern item_t *item_search(); -extern valu_t load(); -extern FILE *ffcreat(); -extern FILE *fftemp(); - -extern void fatal(const char* s, ...); -extern void serror(const char* s, ...); -extern void warning(const char* s, ...); +int hash(char *); +item_t *item_search(char *); +void item_insert(item_t *, int); +item_t *item_alloc(int); +item_t *fb_alloc(int); +item_t *fb_shift(int); +/* comm7.c */ +valu_t load(); +char *remember(); +FILE *ffcreat(); +FILE *fftemp(); +void fatal(const char *, ...); +void serror(const char *, ...); +void warning(const char *, ...); /* ========== Machine dependent C declarations ========== */ diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 7dee7c1a9..9120cea65 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -11,9 +11,16 @@ extern YYSTYPE yylval; -void putval(); +static void readcode(int); +static int induo(int); +static int inident(int); +static int innumber(int); +static int instring(int); +static int inescape(void); +static int infbsym(char *); -yylex() +int +yylex(void) { register c; @@ -71,7 +78,7 @@ yylex() } void -putval(c) +putval(int c) { register valu_t v; register n = 0; @@ -144,7 +151,8 @@ putval(c) putc(*p++, tempfile); } -getval(c) +int +getval(int c) { register n = 0; register valu_t v; @@ -209,7 +217,8 @@ getval(c) /* ---------- lexical scan in pass 1 ---------- */ -nextchar() +int +nextchar(void) { register c; @@ -233,7 +242,8 @@ nextchar() return(c); } -readcode(n) +static void +readcode(int n) { register c; @@ -252,8 +262,8 @@ readcode(n) } while (--n); } -induo(c) -register c; +static int +induo(int c) { static short duo[] = { ('='<<8) | '=', OP_EQ, @@ -277,8 +287,8 @@ register c; static char name[NAMEMAX+1]; -inident(c) -register c; +static int +inident(int c) { register char *p = name; register item_t *ip; @@ -309,8 +319,7 @@ register c; #ifdef ASLD char * -readident(c) -register c; +readident(int c) { register n = NAMEMAX; register char *p = name; @@ -326,8 +335,8 @@ register c; } #endif -innumber(c) -register c; +static int +innumber(int c) { register char *p; register radix; @@ -373,7 +382,8 @@ register c; return(NUMBER); } -instring(termc) +static int +instring(int termc) { register char *p; register c; @@ -412,7 +422,8 @@ instring(termc) return(STRING); } -inescape() +static int +inescape(void) { register c, j, r; @@ -442,8 +453,8 @@ inescape() return(c); } -infbsym(p) -register char *p; +static int +infbsym(char *p) { register lab; register item_t *ip; @@ -469,8 +480,8 @@ ok: return(FBSYM); } -hash(p) -register char *p; +int +hash(char *p) { register unsigned short h; register c; @@ -484,8 +495,7 @@ register char *p; } item_t * -item_search(p) -char *p; +item_search(char *p) { register h; register item_t *ip; @@ -503,15 +513,15 @@ done: return(ip); } -item_insert(ip, h) -item_t *ip; +void +item_insert(item_t *ip, int h) { ip->i_next = hashtab[h]; hashtab[h] = ip; } item_t * -item_alloc(typ) +item_alloc(int typ) { register item_t *ip; static nleft = 0; @@ -532,8 +542,7 @@ item_alloc(typ) } item_t * -fb_alloc(lab) -register lab; +fb_alloc(int lab) { register item_t *ip, *p; @@ -548,8 +557,7 @@ register lab; } item_t * -fb_shift(lab) -register lab; +fb_shift(int lab) { register item_t *ip; From f705339f865948502c2d444e66392edff545986d Mon Sep 17 00:00:00 2001 From: George Koehler Date: Tue, 17 Jan 2017 22:41:11 -0500 Subject: [PATCH 4/4] Allow more tokens in the assembler. I need this so I can add more %token lines to mach/powerpc/as/mach2.c The assembler's tempfile encoded each token in a byte. This only worked with tokens 0 to 127 and 256 and 383. If a token 384 or higher existed, the assembler stopped working. I need tokens 384 and higher. I change the token encoding to a 2-byte little-endian integer. I also change a byte in the string encoding. --- mach/proto/as/comm5.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 9120cea65..1fa84537d 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -22,7 +22,7 @@ static int infbsym(char *); int yylex(void) { - register c; + int c, c0, c1; if (pass == PASS_1) { /* scan the input file */ @@ -59,19 +59,24 @@ yylex(void) /* produce the intermediate token file */ if (c <= 0) return(0); - if (c <= 127) + if (c < 256) { putc(c, tempfile); - else + putc(0, tempfile); + } else { putval(c); + } } else { /* read from intermediate token file */ - c = getc(tempfile); - if (c == EOF) + c0 = getc(tempfile); + if (c0 == EOF) return(0); - if (c > 127) { - c += 128; + c1 = getc(tempfile); + if (c1 == EOF) + return(0); + + c = c0 + (c1 << 8); + if (c >= 256) c = getval(c); - } } curr_token = c; return(c); @@ -84,7 +89,7 @@ putval(int c) register n = 0; register char *p = 0; - assert(c >= 256 && c < 256+128); + assert(c == (c & 0xffff)); switch (c) { case CODE1: n = 1; goto putnum; @@ -99,9 +104,11 @@ putval(int c) break; v >>= 8; } + assert(n <= 4); c = NUMBER0 + n; putnum: - putc(c-128, tempfile); + putc(c, tempfile); + putc(c >> 8, tempfile); v = yylval.y_valu; while (--n >= 0) putc((int) (v >> (n*8)), tempfile); @@ -117,14 +124,15 @@ putval(int c) #endif case STRING: v = stringlen; - putc(c-128, tempfile); + putc(c, tempfile); + putc(c >> 8, tempfile); for (n = 0; n < sizeof(v); n++) { if (v == 0) break; v >>= 8; } - c = NUMBER0 + n; - putc(c-128, tempfile); + assert(n <= 4); + putc(n, tempfile); v = stringlen; while (--n >= 0) putc((int) (v >> (n*8)), tempfile); @@ -146,7 +154,8 @@ putval(int c) n = sizeof(word_t); p = (char *) &yylval.y_word; break; } - putc(c-128, tempfile); + putc(c, tempfile); + putc(c >> 8, tempfile); while (--n >= 0) putc(*p++, tempfile); } @@ -193,7 +202,7 @@ getval(int c) p = (char *) &yylval.y_strp; break; #endif case STRING: - getval(getc(tempfile)+128); + getval(getc(tempfile)+NUMBER0); stringlen = n = yylval.y_valu; p = stringbuf; p[n] = '\0'; break;