From 5a97e5871e968f653d180a5b9825f2648c9e4484 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 17 May 2015 16:21:51 +0100 Subject: [PATCH] sh: alignment 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 | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Applications/V7/cmd/sh/blok.c b/Applications/V7/cmd/sh/blok.c index f1c3ec7e..742e1147 100644 --- a/Applications/V7/cmd/sh/blok.c +++ b/Applications/V7/cmd/sh/blok.c @@ -12,7 +12,6 @@ #include "defs.h" - /* * storage allocator * (circular first fit strategy) @@ -24,11 +23,13 @@ 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); -- 2.34.1