sh: correct end and use sbrk() rather than v7 linkages
authorAlan Cox <alan@linux.intel.com>
Sat, 16 May 2015 20:39:04 +0000 (21:39 +0100)
committerAlan Cox <alan@linux.intel.com>
Sat, 16 May 2015 20:39:04 +0000 (21:39 +0100)
With this change the v7 Bourne shell now runs, even on 32K userspace boxes.

Later she added quite a few things (see
http://heirloom.cvs.sourceforge.net/heirloom/heirloom-sh/) however most of
those are memory expensive.

Probably we should add the use of '#' as a comment character as this is
nowdays considered normal.

Of the other features - an external test suits our memory size better,
while the later builtins aren't that useful and again have size issues. Only
unset cannot be external and might be useful.

Of the late features it might be nice to get 8bit clean

-

Applications/V7/cmd/sh/blok.c
Applications/V7/cmd/sh/defs.h
Applications/V7/cmd/sh/glob.c
Applications/V7/cmd/sh/main.c

index e1b012f..f1c3ec7 100644 (file)
 #define busy(x)        (Rcheat((x)->word)&BUSY)
 
 POS brkincr = BRKINCR;
-BLKPTR blokp;                  /*current search pointer */
-BLKPTR bloktop = BLK(end);     /*top of arena (last blok) */
-
+BLKPTR blokp;                  /* current search pointer */
+BLKPTR bloktop;                        /* top of arena (last blok) */
+static void *end;              /* end of memory */
 
+void blokinit(void)
+{
+        end = sbrk(0);         /* Find where space starts */
+        bloktop = BLK(end);
+}
 
 ADDRESS alloc(POS nbytes)
 {
index 3fbb884..19ecbb0 100644 (file)
@@ -267,8 +267,6 @@ extern const char badexec[];
 extern const char notfound[];
 extern const char badfile[];
 
-extern address end[];
-
 #include       "ctype.h"
 
 /* args.c */
@@ -278,6 +276,7 @@ extern DOLPTR freeargs(DOLPTR blk);
 extern void clearup(void);
 extern DOLPTR useargs(void);
 /* blok.c */
+void blokinit(void);
 ADDRESS alloc(POS nbytes);
 extern void addblok(POS reqd);
 extern void sh_free(void *ap);
index 1011da8..cdd0923 100644 (file)
@@ -26,7 +26,6 @@ ARGPTR wdarg;
 BOOL reserv;
 int wdnum;
 BOOL trapnote;
-address end[1];                /* FIXME */
 int serial;
 BLKPTR stakbsy;
 STKPTR stakbas;
index 06102c4..ac4b9d6 100644 (file)
@@ -32,6 +32,8 @@ int main(int c, const char *v[])
        register int rflag = ttyflg;
 
        /* initialise storage allocation */
+       blokinit();
+
        stdsigs();
 
        setbrk(BRKINCR);