From 67cda9e22fc01b03a6c53d294ee8814a834745dc Mon Sep 17 00:00:00 2001 From: cjhjacobs Date: Wed, 18 May 2011 19:19:19 +0200 Subject: [PATCH 01/11] Fixed bug reported on tack-devel mailing list on 20-3-2011 --- util/ass/ass80.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/ass/ass80.c b/util/ass/ass80.c index 66e5a31e..614dbaf4 100644 --- a/util/ass/ass80.c +++ b/util/ass/ass80.c @@ -189,7 +189,13 @@ cons_t xgetarb(l,f) int l; FILE *f ; { shift=0 ; val=0 ; while ( l-- ) { - val += ((cons_t)(c = ctrunc(xgetc(f))))< 8 && ((shift>>3)&1)) { From ff34b6bce780d2e67891fb50437a585a3c09955b Mon Sep 17 00:00:00 2001 From: Ceriel Jacobs Date: Wed, 15 Jun 2011 10:56:58 +0200 Subject: [PATCH 02/11] Fixed CFU --- util/int/do_conv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/int/do_conv.c b/util/int/do_conv.c index 6752933a..cab003fe 100644 --- a/util/int/do_conv.c +++ b/util/int/do_conv.c @@ -357,22 +357,22 @@ DoCFU() wtrap(WILLCONV, EILLINS); } f = fpop(4L); - npush((long) f, 2L); + npush((unsigned long) f, 2L); return; case 44: f = fpop(4L); - npush((long) f, 4L); + npush((unsigned long) f, 4L); return; case 82: if (wsize == 4) { wtrap(WILLCONV, EILLINS); } f = fpop(8L); - npush((long) f, 2L); + npush((unsigned long) f, 2L); return; case 84: f = fpop(8L); - npush((long) f, 4L); + npush((unsigned long) f, 4L); return; default: wtrap(WILLCONV, EILLINS); From b9c194b2105377378f3dada643aa8ae3717bc9ad Mon Sep 17 00:00:00 2001 From: Ceriel Jacobs Date: Wed, 15 Jun 2011 11:13:48 +0200 Subject: [PATCH 03/11] Added atol() that ignores overflow, so that unsigned long constants are dealt with properly --- util/ass/assci.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/util/ass/assci.c b/util/ass/assci.c index 52a6484e..d3d0b969 100644 --- a/util/ass/assci.c +++ b/util/ass/assci.c @@ -849,8 +849,28 @@ extxcon(header) { return ; } +/* Added atol() that ignores overflow. --Ceriel */ +long atol(s) + register char *s; +{ + register long total = 0; + register unsigned digit; + int minus = 0; + + while (*s == ' ' || *s == '\t') s++; + if (*s == '+') s++; + else if (*s == '-') { + s++; + minus = 1; + } + while ((digit = *s++ - '0') < 10) { + total *= 10; + total += digit; + } + return(minus ? -total : total); +} + extvcon(header) { - extern long atol() ; /* * generate data for a constant initialized by a string. */ From f07a93357c642943cdea58b0dc4ce45398a7fe5f Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 27 Feb 2012 22:36:36 +0000 Subject: [PATCH 04/11] Fix a 64-bitness issue (removed some untyped K&R C code that assumed ints and pointers were the same size). --- util/ack/util.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/util/ack/util.c b/util/ack/util.c index 6c8f1a68..530e4ccb 100644 --- a/util/ack/util.c +++ b/util/ack/util.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include "ack.h" @@ -83,19 +84,26 @@ char *firstblank(str) char *str ; { } /* VARARGS1 */ -fatal(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; { +void fatal(const char* fmt, ...) +{ /* Fatal internal error */ + va_list ap; + va_start(ap, fmt); fprintf(STDOUT,"%s: fatal internal error, ",progname) ; - fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7); + vfprintf(STDOUT, fmt, ap); fprintf(STDOUT,"\n") ; quit(-2) ; } /* VARARGS1 */ -vprint(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; { +void vprint(const char* fmt, ...) +{ /* Diagnostic print, no auto NL */ - fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7); + va_list ap; + va_start(ap, fmt); + vfprintf(STDOUT, fmt, ap); + va_end(ap); } #ifdef DEBUG From ab55ecefee4636ccada068c38de4def2d3f338dc Mon Sep 17 00:00:00 2001 From: George Koehler Date: Fri, 7 Sep 2012 15:53:13 -0400 Subject: [PATCH 05/11] Fix cemcom.ansi for 64-bit hosts. Hosts with sizeof(arith) == sizeof(long) == 8 need to set full_mask[1] through full_mask[8]. Because MAXSIZE == 8, we only had full_mask[0] through full_mask[7]. This fix declares arith full_mask[MAXSIZE + 1] and prevents a fatal error: "array full_mask too small for this machine" --- lang/cem/cemcom.ansi/ch3mon.c | 2 +- lang/cem/cemcom.ansi/ch7mon.c | 2 +- lang/cem/cemcom.ansi/cstoper.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lang/cem/cemcom.ansi/ch3mon.c b/lang/cem/cemcom.ansi/ch3mon.c index 41b27740..40cc4402 100644 --- a/lang/cem/cemcom.ansi/ch3mon.c +++ b/lang/cem/cemcom.ansi/ch3mon.c @@ -20,7 +20,7 @@ #include "sizes.h" extern char options[]; -extern arith full_mask[/*MAXSIZE*/]; /* cstoper.c */ +extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */ char *symbol2str(); ch3mon(oper, expp) diff --git a/lang/cem/cemcom.ansi/ch7mon.c b/lang/cem/cemcom.ansi/ch7mon.c index ab3e3864..f7962904 100644 --- a/lang/cem/cemcom.ansi/ch7mon.c +++ b/lang/cem/cemcom.ansi/ch7mon.c @@ -18,7 +18,7 @@ #include "def.h" extern char options[]; -extern arith full_mask[/*MAXSIZE*/]; /* cstoper.c */ +extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */ char *symbol2str(); ch7mon(oper, expp) diff --git a/lang/cem/cemcom.ansi/cstoper.c b/lang/cem/cemcom.ansi/cstoper.c index ddd7bf68..c86f122b 100644 --- a/lang/cem/cemcom.ansi/cstoper.c +++ b/lang/cem/cemcom.ansi/cstoper.c @@ -16,7 +16,8 @@ #include "Lpars.h" #include "assert.h" -arith full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ +/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ +arith full_mask[MAXSIZE + 1]; #ifndef NOCROSS arith max_int; /* maximum integer on target machine */ arith max_unsigned; /* maximum unsigned on target machine */ @@ -247,7 +248,7 @@ init_cst() while (!(bt < 0)) { bt = (bt << 8) + 0377, i++; - if (i == MAXSIZE) + if (i > MAXSIZE) fatal("array full_mask too small for this machine"); full_mask[i] = bt; } From 0f8745dc8db46673a8bb76c875fe334f02337eba Mon Sep 17 00:00:00 2001 From: George Koehler Date: Fri, 7 Sep 2012 16:28:10 -0400 Subject: [PATCH 06/11] Fix more functions in util/ack for 64-bit hosts. This continues the fix from changeset aabde0589450. We must use va_list to forward the arguments, because some of the arguments might be 64-bit pointers. A pointer does not fit in an int. --- util/ack/util.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/util/ack/util.c b/util/ack/util.c index 530e4ccb..a3d2d051 100644 --- a/util/ack/util.c +++ b/util/ack/util.c @@ -116,30 +116,38 @@ prns(s) register char *s ; { #endif /* VARARGS1 */ -fuerror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; { +void fuerror(const char *fmt, ...) { /* Fatal user error */ + va_list ap; + va_start(ap, fmt); fprintf(STDOUT,"%s: ",progname) ; - fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7); + vfprintf(STDOUT, fmt, ap); fprintf(STDOUT,"\n") ; quit(-1) ; } /* VARARGS1 */ -werror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; { +void werror(const char *fmt, ...) { /* Warning user error, w_flag */ + va_list ap; if ( w_flag ) return ; + va_start(ap, fmt); fprintf(STDOUT,"%s: warning, ",progname) ; - fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7); + vfprintf(STDOUT, fmt, ap); fprintf(STDOUT,"\n") ; + va_end(ap); } /* VARARGS1 */ -error(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; { +void error(const char *fmt, ...) { /* User error, it is the callers responsibility to quit */ + va_list ap; + va_start(ap, fmt); fprintf(STDOUT,"%s: ",progname) ; - fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7); + vfprintf(STDOUT, fmt, ap); fprintf(STDOUT,"\n") ; n_error++ ; + va_end(ap); } do_flush() { From eff81b46874d66c9dda762b632927ca7c60029e5 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sun, 16 Sep 2012 19:57:07 -0400 Subject: [PATCH 07/11] Fix fit16i() for systems with 64-bit long. (long)0xFFFF8000 had expanded to 0x00000000FFFF8000. With (long)(-0x8000), the compiler now extends the negative sign. --- modules/src/em_code/k/em.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/em_code/k/em.c b/modules/src/em_code/k/em.c index 75260725..73f0c688 100644 --- a/modules/src/em_code/k/em.c +++ b/modules/src/em_code/k/em.c @@ -26,7 +26,7 @@ C_magic() } /*** the compact code generating routines ***/ -#define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF) +#define fit16i(x) ((x) >= (long)(-0x8000) && (x) <= (long)0x7FFF) #define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ C_pt_ilb(l) From c56e850ecae805aecc85be585547f96a9911cd89 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Mon, 17 Sep 2012 16:04:55 -0400 Subject: [PATCH 08/11] Delete old and unused files from modules/src/em_code --- modules/src/em_code/e/.distr | 2 - modules/src/em_code/e/C_failed.c | 12 --- modules/src/em_code/e/em.c | 159 ----------------------------- modules/src/em_code/e/em_private.h | 37 ------- modules/src/em_code/io.c | 143 -------------------------- modules/src/em_code/k/.distr | 2 - modules/src/em_code/k/C_failed.c | 12 --- modules/src/em_code/k/em.c | 151 --------------------------- modules/src/em_code/k/em_private.h | 41 -------- 9 files changed, 559 deletions(-) delete mode 100644 modules/src/em_code/e/.distr delete mode 100644 modules/src/em_code/e/C_failed.c delete mode 100644 modules/src/em_code/e/em.c delete mode 100644 modules/src/em_code/e/em_private.h delete mode 100644 modules/src/em_code/io.c delete mode 100644 modules/src/em_code/k/.distr delete mode 100644 modules/src/em_code/k/C_failed.c delete mode 100644 modules/src/em_code/k/em.c delete mode 100644 modules/src/em_code/k/em_private.h diff --git a/modules/src/em_code/e/.distr b/modules/src/em_code/e/.distr deleted file mode 100644 index 66366f55..00000000 --- a/modules/src/em_code/e/.distr +++ /dev/null @@ -1,2 +0,0 @@ -em.c -em_private.h diff --git a/modules/src/em_code/e/C_failed.c b/modules/src/em_code/e/C_failed.c deleted file mode 100644 index 9b3cd21f..00000000 --- a/modules/src/em_code/e/C_failed.c +++ /dev/null @@ -1,12 +0,0 @@ -/* $Header$ */ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -#include - -C_failed() -{ - sys_write(STDERR,"write failed\n",13); - sys_stop(S_EXIT); -} diff --git a/modules/src/em_code/e/em.c b/modules/src/em_code/e/em.c deleted file mode 100644 index 4c79fa88..00000000 --- a/modules/src/em_code/e/em.c +++ /dev/null @@ -1,159 +0,0 @@ -/* $Header$ */ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* EM CODE OUTPUT ROUTINES */ - -#include "io.c" -#include "em_private.h" - -/* - The C_pt_*() functions serve as formatting functions of the - various EM language constructs. - See "Description of a Machine Architecture for use with - Block Structured Languages" par. 11.2 for the meaning of these - names. -*/ - -C_magic() -{ -} - -/*** the readable code generating routines ***/ - -static -wrs(s) - register char *s; -{ - while (*s) { - C_putbyte(*s++); - } -} - -C_pt_dnam(s) - char *s; -{ - wrs(s); -} - -C_pt_ilb(l) - label l; -{ - char buf[16]; - - sprint(buf, "*%ld", (long) l); - wrs(buf); -} - -extern char em_mnem[][4]; -extern char em_pseu[][4]; - -C_pt_op(x) -{ - C_putbyte(' '); - wrs(em_mnem[x - sp_fmnem]); - C_putbyte(' '); -} - -C_pt_cst(l) - arith l; -{ - char buf[16]; - - sprint(buf, "%ld", (long) l); - wrs(buf); -} - -C_pt_scon(x, y) - char *x; - arith y; -{ - char xbuf[1024]; - register char *p; - char *bts2str(); - - C_putbyte('\''); - p = bts2str(x, (int) y, xbuf); - while (*p) { - if (*p == '\'') { - C_putbyte('\\'); - } - C_putbyte(*p++); - } - C_putbyte('\''); -} - -C_pt_ps(x) -{ - C_putbyte(' '); - wrs(em_pseu[x - sp_fpseu]); - C_putbyte(' '); -} - -C_pt_dlb(l) - label l; -{ - char buf[16]; - - sprint(buf, ".%ld", (long) l); - wrs(buf); -} - -C_pt_doff(l, v) - label l; - arith v; -{ - char buf[16]; - - C_pt_dlb(l); - if (v != 0) { - sprint(buf,"+%ld", (long) v); - wrs(buf); - } -} - -C_pt_noff(s, v) - char *s; - arith v; -{ - char buf[16]; - - wrs(s); - if (v != 0) { - sprint(buf,"+%ld", (long) v); - wrs(buf); - } -} - -C_pt_pnam(s) - char *s; -{ - C_putbyte('$'); - wrs(s); -} - -C_pt_dfilb(l) - label l; -{ - char buf[16]; - - sprint(buf, "%ld", (long) l); - wrs(buf); -} - -C_pt_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */ - int sp; - char *v; - arith sz; -{ - int ch = sp == sp_icon ? 'I' : sp == sp_ucon ? 'U' : 'F'; - - wrs(v); - C_putbyte(ch); - C_pt_cst(sz); -} - -C_pt_nl() { C_putbyte('\n'); } -C_pt_comma() { C_putbyte(','); } -C_pt_ccend() { C_putbyte('?'); } diff --git a/modules/src/em_code/e/em_private.h b/modules/src/em_code/e/em_private.h deleted file mode 100644 index 7a89d673..00000000 --- a/modules/src/em_code/e/em_private.h +++ /dev/null @@ -1,37 +0,0 @@ -/* $Header$ */ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* private inclusion file */ - -#include -#include - -/* include the EM description files */ -#include -#include -#include -#include - -/* macros used in the definitions of the interface functions C_* */ -#define OP(x) C_pt_op(x) -#define CST(x) C_pt_cst(x) -#define DCST(x) C_pt_cst(x) -#define SCON(x,y) C_pt_scon((x), (y)) -#define PS(x) C_pt_ps(x) -#define DLB(x) C_pt_dlb(x) -#define DFDLB(x) C_pt_dlb(x) -#define ILB(x) C_pt_ilb(x) -#define DFILB(x) C_pt_dfilb(x) -#define NOFF(x,y) C_pt_noff((x), (y)) -#define DOFF(x,y) C_pt_doff((x), (y)) -#define PNAM(x) C_pt_pnam(x) -#define DNAM(x) C_pt_dnam(x) -#define DFDNAM(x) C_pt_dnam(x) -#define CEND() -#define CCEND() C_pt_ccend() -#define WCON(x,y,z) C_pt_wcon((x), (y), (z)) -#define COMMA() C_pt_comma() -#define NL() C_pt_nl() -#define CILB(x) C_pt_ilb(x) diff --git a/modules/src/em_code/io.c b/modules/src/em_code/io.c deleted file mode 100644 index 8e59e570..00000000 --- a/modules/src/em_code/io.c +++ /dev/null @@ -1,143 +0,0 @@ -/* $Header$ */ - -/* I/O part of em_code module. - Also contains C_open, C_close -*/ -#include -#include -#include -#include "insert.h" - -int C_ontmpfile = 0; -int C_sequential = 1; -Part *C_curr_part; -Part *C_stable[TABSIZ]; -char *C_tmpdir = TMP_DIR; -int (*C_outpart)(), (*C_swtout)(), (*C_swttmp)(); - -#ifdef INCORE -char *C_BASE; -#endif - -File *C_ofp; - -#ifndef INCORE -File *C_tfr, *C_old_ofp; -char *C_tmpfile; -char *strcpy(), *strcat(); -char *C_ibuf = 0; -long C_current_out; -#endif - -#if BUFSIZ <= 1024 && BIGMACHINE -#define BUFFERSIZ 8*BUFSIZ -#else -#define BUFFERSIZ BUFSIZ -#endif - -static char obuf[BUFFERSIZ]; -char *C_top = &obuf[BUFFERSIZ]; -char *C_old_top; -char *C_old_opp; -#ifdef INCORE -char *C_current_out = obuf; -#else -char *C_opp = obuf; -#endif - -C_flush() { -#ifdef INCORE - static unsigned int bufsiz; - - if (C_ontmpfile) { - if (C_BASE == 0) { - C_BASE = Malloc(BUFFERSIZ); - bufsiz = BUFFERSIZ; - C_current_out = C_BASE; - } - else { - C_BASE = Srealloc(C_BASE, (bufsiz << 1)); - C_current_out = C_BASE + bufsiz; - bufsiz <<= 1; - } - C_top = C_BASE + bufsiz; - return; - } -#endif - if (C_opp != obuf && sys_write(C_ofp, obuf, C_opp - obuf) == 0) { - C_failed(); - } - C_opp = obuf; -} - -#ifndef INCORE -#define Xputbyte(c) if (C_ontmpfile) C_current_out++; put(c) -#else -#define Xputbyte(c) put(c) -#endif - -C_putbyte(c) - int c; -{ - Xputbyte(c); -} - -#define C_putbyte Xputbyte - -C_init(w, p) - arith w, p; -{ -} - -C_open(nm) - char *nm; -{ - /* Open file "nm" for output - */ - - if (nm == 0) - C_ofp = STDOUT; /* standard output */ - else - if (sys_open(nm, OP_WRITE, &C_ofp) == 0) - return 0; - return 1; -} - -C_close() -{ - /* Finish the code-generation. - */ - -#ifndef INCORE - C_flush(); - if (C_tmpfile) { - (*C_swttmp)(); - sys_close(C_ofp); -#else - if (C_BASE) { -#endif - if (C_curr_part) { - C_curr_part->p_parts->pp_end = C_current_out - C_BASE; - } - (*C_swtout)(); - if (! C_sequential) { - (*C_outpart)(0); - } -#ifndef INCORE - sys_close(C_tfr); - sys_remove(C_tmpfile); - if (C_ibuf) free(C_ibuf); -#else - free(C_BASE); -#endif - } - C_flush(); - if (C_ofp != STDOUT) - sys_close(C_ofp); - C_ofp = 0; -} - -C_busy() -{ - return C_ofp != 0; /* true if code is being generated */ -} diff --git a/modules/src/em_code/k/.distr b/modules/src/em_code/k/.distr deleted file mode 100644 index 66366f55..00000000 --- a/modules/src/em_code/k/.distr +++ /dev/null @@ -1,2 +0,0 @@ -em.c -em_private.h diff --git a/modules/src/em_code/k/C_failed.c b/modules/src/em_code/k/C_failed.c deleted file mode 100644 index 9b3cd21f..00000000 --- a/modules/src/em_code/k/C_failed.c +++ /dev/null @@ -1,12 +0,0 @@ -/* $Header$ */ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -#include - -C_failed() -{ - sys_write(STDERR,"write failed\n",13); - sys_stop(S_EXIT); -} diff --git a/modules/src/em_code/k/em.c b/modules/src/em_code/k/em.c deleted file mode 100644 index 73f0c688..00000000 --- a/modules/src/em_code/k/em.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* $Header$ */ -/* EM CODE OUTPUT ROUTINES */ - -#include "io.c" -#include "em_private.h" - -#define put8(x) C_putbyte(x) -#define put16(x) put8((int) x); put8((int) (x >> 8)) -#define put32(x) put16((int) x); put16((int) (x >> 16)) - -/* - The C_pt_*() functions serve as formatting functions of the - various EM language constructs. - See "Description of a Machine Architecture for use with - Block Structured Languages" par. 11.2 for the meaning of these - names. -*/ - -C_magic() -{ - put16(sp_magic); -} - -/*** the compact code generating routines ***/ -#define fit16i(x) ((x) >= (long)(-0x8000) && (x) <= (long)0x7FFF) -#define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ - -C_pt_ilb(l) - register label l; -{ - if (fit8u(l)) { - put8(sp_ilb1); - put8(l); - } - else { - put8(sp_ilb2); - put16(l); - } -} - -C_pt_dlb(l) - register label l; -{ - if (fit8u(l)) { - put8(sp_dlb1); - put8(l); - } - else { - put8(sp_dlb2); - put16((int)l); - } -} - -C_pt_cst(l) - register arith l; -{ - if (l >= (arith) -sp_zcst0 && l < (arith) (sp_ncst0 - sp_zcst0)) { - /* we can convert 'l' to an int because its value - can be stored in a byte. - */ - put8((int)l + (sp_zcst0 + sp_fcst0)); - } - else - if (fit16i(l)) { /* the cast from long to int causes no trouble here */ - put8(sp_cst2); - put16((int) l); - } - else { - put8(sp_cst4); - put32(l); - } -} - -C_pt_doff(l, v) - label l; - arith v; -{ - if (v == 0) { - C_pt_dlb(l); - } - else { - put8(sp_doff); - C_pt_dlb(l); - C_pt_cst(v); - } -} - -C_pt_noff(s, v) - char *s; - arith v; -{ - if (v == 0) { - C_pt_dnam(s); - } - else { - put8(sp_doff); - C_pt_dnam(s); - C_pt_cst(v); - } -} - -C_pt_dnam(s) - char *s; -{ - put8(sp_dnam); - C_pt_str(s); -} - -C_pt_pnam(s) - char *s; -{ - put8(sp_pnam); - C_pt_str(s); -} - -C_pt_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */ - int sp; - char *v; - arith sz; -{ - /* how 'bout signextension int --> long ??? */ - put8(sp); - C_pt_cst(sz); - C_pt_str(v); -} - -C_pt_str(s) - register char *s; -{ - register int len; - - C_pt_cst((arith) (len = strlen(s))); - while (--len >= 0) { - put8(*s++); - } -} - -C_pt_scon(b, n) - register char *b; - register arith n; -{ - put8(sp_scon); - C_pt_cst(n); - while (--n >= 0) { - put8(*b++); - } -} diff --git a/modules/src/em_code/k/em_private.h b/modules/src/em_code/k/em_private.h deleted file mode 100644 index 9ac1da39..00000000 --- a/modules/src/em_code/k/em_private.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $Header$ */ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * See the copyright notice in the ACK home directory, in the file "Copyright". - */ -/* private inclusion file */ - -#include -#include - -/* include the EM description files */ -#include -#include -#include -#include - -/* macros used in the definitions of the interface functions C_* */ -#define OP(x) C_pt_op(x) -#define CST(x) C_pt_cst(x) -#define DCST(x) C_pt_cst(x) -#define SCON(x,y) C_pt_scon((x), (y)) -#define PS(x) C_pt_ps(x) -#define DLB(x) C_pt_dlb(x) -#define DFDLB(x) C_pt_dlb(x) -#define ILB(x) C_pt_ilb(x) -#define DFILB(x) C_pt_ilb(x) -#define NOFF(x,y) C_pt_noff((x), (y)) -#define DOFF(x,y) C_pt_doff((x), (y)) -#define PNAM(x) C_pt_pnam(x) -#define DNAM(x) C_pt_dnam(x) -#define DFDNAM(x) C_pt_dnam(x) -#define CEND() C_pt_cend() -#define CCEND() C_pt_cend() -#define WCON(x,y,z) C_pt_wcon((x), (y), (z)) -#define COMMA() -#define NL() -#define CILB(x) CST((arith) x) - -#define C_pt_cend() C_putbyte(sp_cend) -#define C_pt_op(x) C_putbyte(x) -#define C_pt_ps(x) C_putbyte(x) From a44e18bb1e9fc4d9e2dde5c8220cf4db5d3f3caf Mon Sep 17 00:00:00 2001 From: George Koehler Date: Wed, 19 Sep 2012 23:39:51 -0400 Subject: [PATCH 09/11] *Again* fix fit16i() for systems with 64-bit long. I already did this in abebf1586c06, but I edited the wrong file. Then in edddc6b7cd17, I deleted that file. By fixing fit16i(), I can now compile ACK for OpenBSD/amd64. --- modules/src/em_code/em.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/em_code/em.c b/modules/src/em_code/em.c index 8a2f16e4..f13ab28d 100644 --- a/modules/src/em_code/em.c +++ b/modules/src/em_code/em.c @@ -353,7 +353,7 @@ C_magic() } /*** the compact code generating routines ***/ -#define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF) +#define fit16i(x) ((x) >= (long)(-0x8000) && (x) <= (long)0x7FFF) #define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ void From 2dbbacfad97eaf2874e4d7bd86fced6d2f7c5520 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Fri, 21 Sep 2012 22:51:12 -0400 Subject: [PATCH 10/11] Prevent division by zero in aslod. rhead() and rsect() had assumed sizeof(long) == 4, but OpenBSD/amd64 has sizeof(long) == 8. The problem revealed itself when sect->os_lign became zero, and align() divided by zero. --- util/amisc/aslod.c | 54 ++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/util/amisc/aslod.c b/util/amisc/aslod.c index b3408800..e436438b 100644 --- a/util/amisc/aslod.c +++ b/util/amisc/aslod.c @@ -140,42 +140,29 @@ void emits(struct outsect* section) } -void iconvert(char* buf, char* str, char* fmt) -{ - register char *nf, *ni, *no ; - int last, i ; - long value ; - ni=buf ; no=str ; nf=fmt ; - while ( last = *nf++ ) { - last -= '0' ; - if ( last<1 || last >9 ) fatal("illegal out.h format string\n"); - value=0 ; - i=last ; - while ( i-- ) { - value = (value<<8) + (ni[i]&0xFF) ; - } - switch ( last ) { - case 0 : break ; - case 1 : *no= value ; break ; - case 2 : *(unsigned short *)no = value ; break ; - case 4 : *(long *)no = value ; break ; - default : - fatal("illegal out.h format string\n"); - } - ni += last ; no += last ; - } -} +/* Macros from modules/src/object/obj.h */ +#define Xchar(ch) ((ch) & 0377) +#define uget2(c) (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8)) +#define get4(c) (uget2(c) | ((long) uget2((c)+2) << 16)) /* Read the ack.out file header. */ int rhead(FILE* f, struct outhead* head) { - char buf[sizeof(struct outhead)]; + char buf[SZ_HEAD], *c; if (fread(buf, sizeof(buf), 1, f) != 1) return 0; - - iconvert(buf, (char*) head, SF_HEAD); + + c = buf; + head->oh_magic = uget2(c); c += 2; + head->oh_stamp = uget2(c); c += 2; + head->oh_flags = uget2(c); c += 2; + head->oh_nsect = uget2(c); c += 2; + head->oh_nrelo = uget2(c); c += 2; + head->oh_nname = uget2(c); c += 2; + head->oh_nemit = get4(c); c += 4; + head->oh_nchar = get4(c); return 1; } @@ -183,12 +170,17 @@ int rhead(FILE* f, struct outhead* head) int rsect(FILE* f, struct outsect* sect) { - char buf[sizeof(struct outsect)]; + char buf[SZ_SECT], *c; if (fread(buf, sizeof(buf), 1, f) != 1) return 0; - - iconvert(buf, (char*) sect, SF_SECT); + + c = buf; + sect->os_base = get4(c); c += 4; + sect->os_size = get4(c); c += 4; + sect->os_foff = get4(c); c += 4; + sect->os_flen = get4(c); c += 4; + sect->os_lign = get4(c); return 1 ; } From f1cdb32025ac91a2ae3e2432983129821fa92f24 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sun, 23 Sep 2012 14:43:22 -0400 Subject: [PATCH 11/11] Allow pc86 bootloader to boot from more floppy drives. When the bootloader probes the drive geometry, the BIOS can clobber the es register. If this happens, the bootloader loads the program to the wrong address, and jumps off the code. This happens with an emulated floppy drive in Bochs or QEMU, but not with an emulated hard disk. --- plat/pc86/boot.s | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plat/pc86/boot.s b/plat/pc86/boot.s index d517c1e4..53480969 100644 --- a/plat/pc86/boot.s +++ b/plat/pc86/boot.s @@ -23,7 +23,7 @@ ! If you ever need to change the boot code, this needs adjusting. I recommend ! a hex editor. -PADDING = 0xB9 +PADDING = 0xB7 ! Some definitions. @@ -45,8 +45,8 @@ start2: mov ax, cs mov ds, ax - mov es, ax mov ss, ax + ! Defer setting es until after probing the drive. ! Initialise the stack, which will start at the top of our segment and work ! down. @@ -65,10 +65,13 @@ start2: call write_string ! Probe the drive to figure out its geometry. + ! This might clobber es. - push dx + push dx mov ax, 0x0800 ! service number int 0x13 + mov ax, cs ! restore es + mov es, ax pop ax jc cant_boot