diff --git a/src/stinkr/s.h b/src/stinkr/s.h index a2d9a872..c676af15 100644 --- a/src/stinkr/s.h +++ b/src/stinkr/s.h @@ -1,7 +1,7 @@ -# include "c.defs" +# include # define PAGE_SHIFT 10 -# ifdef tops20 +# ifndef ITS # define PAGE_SHIFT 9 # endif @@ -11,7 +11,7 @@ # define ORIGIN_0 0100 # define ORIGIN_1 0400000 -# ifdef tops20 +# ifndef ITS # define ORIGIN_0 0140 # endif @@ -83,3 +83,7 @@ typedef struct _progent progent; # define wleft(w) ((w)>>18) # define wright(w) ((w)&0777777) # define wcons(l,r) (((l)<<18)|((r)&0777777)) + +# define LHALF halves (0777777, 0) +# define RHALF 0777777 +# define ACFIELD halves (0740, 0) diff --git a/src/stinkr/sjob.c b/src/stinkr/sjob.c index df35bc33..4d051799 100644 --- a/src/stinkr/sjob.c +++ b/src/stinkr/sjob.c @@ -28,7 +28,7 @@ jinit () while (--jnwindow >= 0) {jcpage[jnwindow] = -1; - jwpage[jnwindow] = pg_get (1); + jwpage[jnwindow] = pgget (1); jwindow[jnwindow] = jwpage[jnwindow] << PAGE_SHIFT; } jnwindow = 0; diff --git a/src/stinkr/sjob10.c b/src/stinkr/sjob10.c index 0dbf8677..26ab4e54 100644 --- a/src/stinkr/sjob10.c +++ b/src/stinkr/sjob10.c @@ -14,6 +14,8 @@ int jbhandle (j) {return (j_ch (j)); } +pgget (n) {return (pg_get (n));} + pgwzero (jch, p) int jch; int p; diff --git a/src/stinkr/sjob20.c b/src/stinkr/sjob20.c index b5d011cb..e10b469d 100644 --- a/src/stinkr/sjob20.c +++ b/src/stinkr/sjob20.c @@ -29,24 +29,7 @@ int j_kill (j) {_KFORK (j); } -int pg_get (n) - - {static int space[(NWINDOW+1)*PAGE_SIZE]; - /* space used for windows */ - static int *sp {space}; - /* pointer to next available page */ - - int i, pn; - i = sp; - if (i & PAGE_MASK) /* sp hasn't been aligned yet */ - {i =+ PAGE_MASK; - i =& ~PAGE_MASK; - } - pn = i >> PAGE_SHIFT; /* page number of allocated page */ - i =+ PAGE_SIZE; /* advance to next page */ - sp = i; - return (pn); - } +pgget (n) {return (pg_get (n) >> PAGE_SHIFT);} pgwzero (jch, p) int jch; diff --git a/src/stinkr/sload.c b/src/stinkr/sload.c index ee9debba..dcb77f20 100644 --- a/src/stinkr/sload.c +++ b/src/stinkr/sload.c @@ -88,7 +88,7 @@ leprog () } } -getval (n, sub) name n; int sub; +getval (value, n, sub) name n; int value, sub; {symbol s; int swap, action, flags, global; @@ -100,28 +100,32 @@ getval (n, sub) name n; int sub; if (!global) {error ("reference to local symbol %x not implemented", n); - return (0); + return (value); } s = symfind (n); if (symdefined (s)) - {int val; + {int val, nval; val = symvalue (s); if (swap) val = wswap (val); if (sub) val = -val; - switch (action) { - case fa_word: break; - case fa_right: val =& 0777777; break; - case fa_left: val =& ~0777777; break; - case fa_ac: val =& 0740000000; break; - } - return (val); + nval = compute_fixup (action, value, val); + if (debug) cprint (" changed %o => %o", value, nval); + return (nval); } if (ovflag) {error ("%x undefined in assignment", n); - return (0); + return (value); } symaddfix (s, fixcons (sub, swap, action, loc)); - return (0); + return (value); + } + +int fmasks [] {halves (0777777, 0777777), RHALF, LHALF, ACFIELD}; + +int compute_fixup (kind, old, new) + + {kind = fmasks[kind]; + return ((old & ~kind) | (((old & kind) + (new & kind)) & kind)); } linkreq (n, chain) name n; int chain; @@ -224,14 +228,23 @@ reloc (l) {int n, o; + if (l < 0 || l >= 01000000) + {error ("bad relocatable value"); + return (0); + } + n = nvsegs - 1; + if (l >= segvorg[n] + segvsiz[n]) return (creloc[0] + l - 01000000); n = nvsegs; - while (--n >= 0) if ((o = l - segvorg[n]) >= 0) break; - if (o<0) + while (--n >= 0) + if ((o = l - segvorg[n]) >= 0) break; + if (n < 0) {error ("virtual address %o not in any segment", l); return (0); } + if (o > segvsiz[n]) /* permit label at end of segment */ + error ("virtual address %o beyond end of segment", l); n = creloc[n] + o; - if (n<0 || n>=01000000) + if (n < 0 || n >= 01000000) {error ("address wraparound"); n =& 0777777; } @@ -242,7 +255,7 @@ char *actnam[] {"word", "right half of", "left half of", "AC of"}; dofixup (f, val) fixup f; - {int lc, action, sub, swap; + {int lc, action, sub, swap, oval, nval; sub = fixsub (f); swap = fixswap (f); action = fixact (f); @@ -251,11 +264,7 @@ dofixup (f, val) fixup f; actnam[action], lc, val); if (swap) {val = wswap (val); if (debug) cprint (" (swap)");} if (sub) {val = -val; if (debug) cprint (" (subtract)");} - switch (action) { - case fa_word: break; - case fa_right: val =& 0777777; break; - case fa_left: val =& ~0777777; break; - case fa_ac: val =& 0740000000; break; - } - jwrite (lc, jread (lc) + val); + oval = jread (lc); + jwrite (lc, nval = compute_fixup (action, oval, val)); + if (debug) cprint (" changed %o => %o", oval, nval); } diff --git a/src/stinkr/sread.c b/src/stinkr/sread.c index 87ad81ea..ce8d21e9 100644 --- a/src/stinkr/sread.c +++ b/src/stinkr/sread.c @@ -416,23 +416,27 @@ standard() codeword =<< 3; data = *blkp++; switch (code) { - case 0: value =+ data; outval (); - continue; - case 1: value =+ wcons(wleft(data),reloc(wright(data))); + + case 0: value = add_both (value, data); outval (); continue; - case 2: value =+ wcons(reloc(wleft(data)),wright(data)); + case 1: data = wcons(wleft(data), reloc(wright(data))); + value = add_both (value, data); outval (); continue; - case 3: value =+ wcons(reloc(wleft(data)), - reloc(wright(data))); + case 2: data = wcons(reloc(wleft(data)), wright(data)); + value = add_both (value, data); + outval (); + continue; + case 3: data = wcons(reloc(wleft(data)), reloc(wright(data))); + value = add_both (value, data); outval (); continue; case 4: sym = data; - value =+ getval (sym, 0); + value = getval (value, sym, 0); continue; case 5: sym = data; - value =+ getval (sym, 1); + value = getval (value, sym, 1); continue; case 6: linkreq (data, *blkp++); continue; @@ -459,6 +463,10 @@ standard() } } +int add_both (x, y) + + {return (wcons (wleft(x) + wleft(y), wright(x) + wright(y)));} + outval () {if (ovflag) diff --git a/src/stinkr/stinkr.c b/src/stinkr/stinkr.c index 0be4daba..8f172ba7 100644 --- a/src/stinkr/stinkr.c +++ b/src/stinkr/stinkr.c @@ -341,11 +341,20 @@ int sopen (fnbuf, m, o) char fnbuf[], *o; } f = copen (fnbuf, m, o); if (f == OPENLOSS) - {cprint ("\nUnable to open %s\n", fnbuf); - cprint ("Use what filename instead ('*' to ignore)? "); - gets (temp); - if (temp[0] == '*' && temp[1] == 0) return (OPENLOSS); - if (temp[0]) stcpy (temp, fnbuf); + {char *p, c; + f = copen ("", 'w'); + cprint (f, "\nUnable to open %s\n", fnbuf); + cprint (f, "Use what filename instead\ + ('*' to ignore)? "); + cclose (f); + f = copen ("", 'r'); + p = temp; + while ((c = cgetc (f)) && c != '\n') *p++ = c; + *p++ = 0; + cclose (f); + if (temp[0] == 0 || (temp[0] == '*' && temp[1] == 0)) + return (OPENLOSS); + stcpy (temp, fnbuf); } else return (f); }