sh: alignment
authorAlan Cox <alan@linux.intel.com>
Sun, 17 May 2015 15:21:51 +0000 (16:21 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 17 May 2015 15:21:51 +0000 (16:21 +0100)
V7 happens to word pack binaries so that the low bit of the first address
beyond the end of the program is clear. We don't. This causes sh to get
a bit upset 50% of the time you fiddle with it. Instead check the sbrk
value when we start up and sbrk ourselves a byte if needed.

The sh allocator providing it is started on an even address will stay even.

Applications/V7/cmd/sh/blok.c

index f1c3ec7..742e114 100644 (file)
@@ -12,7 +12,6 @@
 
 #include       "defs.h"
 
-
 /*
  *     storage allocator
  *     (circular first fit strategy)
 POS brkincr = BRKINCR;
 BLKPTR blokp;                  /* current search pointer */
 BLKPTR bloktop;                        /* top of arena (last blok) */
-static void *end;              /* end of memory */
+static uint8_t *end;           /* end of memory */
 
 void blokinit(void)
 {
-        end = sbrk(0);         /* Find where space starts */
+        end = setbrk(0);       /* Find where space starts */
+        if (((uint8_t)end) & 1)
+                end = setbrk(1);       /* Align */
         bloktop = BLK(end);
 }
 
@@ -41,21 +42,16 @@ ADDRESS alloc(POS nbytes)
                register BLKPTR p = blokp;
                register BLKPTR q;
                do {
-                       if (!busy(p)
-                           ) {
-                               while (!busy(q = p->word)) {
+                       if (!busy(p)) {
+                               while (!busy(q = p->word))
                                        p->word = q->word;
-                               }
+
                                if (ADR(q) - ADR(p) >= rbytes) {
                                        blokp = BLK(ADR(p) + rbytes);
-                                       if (q > blokp) {
+                                       if (q > blokp)
                                                blokp->word = p->word;
-                                               ;
-                                       }
-                                       p->word =
-                                           BLK(Rcheat(blokp) | BUSY);
+                                       p->word = BLK(Rcheat(blokp) | BUSY);
                                        return (ADR(p + 1));
-                                       ;
                                };
                        }
                        q = p;
@@ -78,7 +74,6 @@ void addblok(POS reqd)
                stakbsy = blokstak;
                bloktop->word = BLK(Rcheat(rndstak) | BUSY);
                bloktop = BLK(rndstak);
-               ;
        }
        reqd += brkincr;
        reqd &= ~(brkincr - 1);