syscall_exec: Introduce the notion of both a base and a load address
authorAlan Cox <alan@etchedpixels.co.uk>
Fri, 21 Nov 2014 15:03:32 +0000 (15:03 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Fri, 21 Nov 2014 15:03:32 +0000 (15:03 +0000)
Eg on Z80 our base is 0 but we load at 0x200. On 6502 our base and load
are going to be higher and the same, ditto probably 6809

14 files changed:
Kernel/platform-6502test/config.h
Kernel/platform-dragon/config.h
Kernel/platform-micropack/config.h
Kernel/platform-msx1/config.h
Kernel/platform-msx2/config.h
Kernel/platform-nc100/config.h
Kernel/platform-pcw8256/config.h
Kernel/platform-px4plus/config.h
Kernel/platform-socz80/config.h
Kernel/platform-trs80/config.h
Kernel/platform-z80pack-lite/config.h
Kernel/platform-z80pack/config.h
Kernel/start.c
Kernel/syscall_exec.c

index b82b50c..899b284 100644 (file)
@@ -42,7 +42,8 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0200))  /* also data base */
+#define PROGLOAD    ((char *)(0x0200))
 #define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA */
 
 #define BOOT_TTY 3        /* Set this to default device for stdio, stderr */
index 41eed1c..088b488 100644 (file)
@@ -40,8 +40,9 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((uint8_t *)(0x8000))  /* also data base */
-#define PROGTOP     ((uint8_t *)(0xff00))  /* Top of program */
+#define PROGBASE    ((uint8_t *)(0x0000))  /* also data base */
+#define PROGLOAD    ((uint8_t *)(0x0000))  /* also data base */
+#define PROGTOP     ((uint8_t *)(0x7C00))  /* Top of program */
 
 #define BOOT_TTY (512 + 1)   /* Set this to default device for stdio, stderr */
                           /* In this case, the default is the first TTY device */
index 614d0a2..43d07a9 100644 (file)
@@ -23,7 +23,8 @@
 #define CONFIG_BANKS   1
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* also data base */
+#define PROGLOAD    ((char *)(0x0100))
 #define PROGTOP     ((char *)(0x7D00))  /* Top of program, base of U_DATA */
 #define PROC_SIZE   32           /* Memory needed per process */
 
index b70d226..e902a0b 100644 (file)
@@ -27,7 +27,8 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 50   /* Ticks per second (actually should be dynamic FIXME) */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* also data base */
+#define PROGLOAD    ((char *)(0x0100)) 
 #define PROGTOP     ((char *)(0x7D00))  /* Top of program (uarea stash) */
 
 #define BOOT_TTY (512 + 1)        /* Set this to default device for stdio, stderr */
index abc04bd..8790e83 100644 (file)
@@ -24,7 +24,8 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 50   /* Ticks per second (actually should be dynamic FIXME) */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* also data base */
+#define PROGLOAD    ((char *)(0x0100))
 #define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA */
 
 #define BOOT_TTY (512 + 1)        /* Set this to default device for stdio, stderr */
index 5b6d6f3..8027c79 100644 (file)
@@ -36,7 +36,8 @@
 #endif
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* also data base */
+#define PROGLOAD    ((char *)(0x0100))
 #define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA */
 //#define PROC_SIZE   64         /* Memory needed per process (for now) */
 
index 91e8d25..5175433 100644 (file)
@@ -28,7 +28,8 @@
 #define VT_BOTTOM      31
 
 #define TICKSPERSEC 50   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* memory base of program */
+#define PROGLOAD    ((char *)(0x0100))  /* load base of program */
 #define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA */
 #define PROC_SIZE   64   /* Memory needed per process */
 
index 1e074de..2f8ffdc 100644 (file)
@@ -31,7 +31,8 @@
 /* FIXME: the OVL timer isn't quite 100/sec and we have an accurate 1Hz
    timer available, so needs some tweaking */
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* also data base */
+#define PROGLOAD    ((char *)(0x0100))
 #define PROGTOP     ((char *)(0x4000))  /* Top of program for debug */
 
 #define SWAP_SIZE   0x40       /* 32K in blocks (with uarea means 31K max app size) */
index 3134539..4a53095 100644 (file)
@@ -16,7 +16,8 @@
 
 #define CONFIG_BANKS   4       /* For now lets use 16K banking */
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))
+#define PROGLOAD    ((char *)(0x0100))  /* also data base */
 #define PROGTOP     ((char *)(0xF900))  /* Top of program, base of U_DATA */
 
 #define BOOT_TTY (512 + 1)/* Set this to default device for stdio, stderr */
index e7fc754..80629fe 100644 (file)
@@ -23,7 +23,8 @@
 #define VT_BOTTOM      24
 
 #define TICKSPERSEC 60   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))  /* Base of user  */
+#define PROGLOAD    ((char *)(0x0100))  /* Load and run here
 #define PROGTOP     ((char *)(0xF900))  /* Top of program, base of U_DATA */
 #define PROC_SIZE   64   /* Memory needed per process */
 
index 7b5c3e5..c90b364 100644 (file)
 #undef CONFIG_CPM_EMU
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0100))  /* also data base */
+#define PROGBASE    ((char *)(0x0000))
+#define PROGLOAD    ((char *)(0x0100))  /* also data base */
 #define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA copy */
 
-#define BOOT_TTY 9        /* Set this to default device for stdio, stderr */
+#define BOOT_TTY 513      /* Set this to default device for stdio, stderr */
                           /* In this case, the default is the first TTY device */
 
 /* We need a tidier way to do this from the loader */
index fa5704a..161af1f 100644 (file)
@@ -20,6 +20,7 @@
 #define CONFIG_BANKS   1
 
 #define TICKSPERSEC 100   /* Ticks per second */
+#define PROGLOAD    ((char *)(0x0000))  /* also data base */
 #define PROGBASE    ((char *)(0x0100))  /* also data base */
 #define PROGTOP     ((char *)(0xED00))  /* Top of program, base of U_DATA copy */
 #define PROC_SIZE   60   /* Memory needed per process */
index 0f0fe5d..d6bff31 100644 (file)
@@ -44,7 +44,8 @@ void bufinit(void)
 void create_init(void)
 {
        uint8_t *j;
-       /* userspace: 0x100+ 0   1   2   3   4   5   6   7   8   9   A   B   C */
+       /* userspace: PROGLOAD +
+               0    1    2    3    4   5  6  7  8  9  A  B  C */
        const char arg[] =
            { '/', 'i', 'n', 'i', 't', 0, 0, 1, 1, 0, 0, 0, 0 };
 
@@ -61,13 +62,14 @@ void create_init(void)
                *j = NO_FILE;
        }
        /* Poke the execve arguments into user data space so _execve() can read them back */
-       uput(arg, PROGBASE, sizeof(arg));
+       uput(arg, PROGLOAD, sizeof(arg));
+       /* Poke in arv[0] - FIXME: Endianisms...  */
+       uputw((uint16_t)PROGLOAD + 1, PROGLOAD + 7);
 
        /* Set up things to look like the process is calling _execve() */
-       udata.u_argn = (uint16_t) PROGBASE;
-       /* FIXME - should be relative to PROGBASE... */
-       udata.u_argn1 = 0x107;  /* Arguments (just "/init") */
-       udata.u_argn2 = 0x10b;  /* Environment (none) */
+       udata.u_argn = (uint16_t) PROGLOAD;
+       udata.u_argn1 = (uint16_t)PROGLOAD + 0x7;       /* Arguments (just "/init") */
+       udata.u_argn2 = (uint16_t)PROGLOAD + 0xb;       /* Environment (none) */
 }
 
 void fuzix_main(void)
index b3cf2f5..e6763b1 100644 (file)
@@ -127,13 +127,16 @@ int16_t _execve(void)
        if (ino->c_node.i_mode & SET_GID)
                udata.u_egid = ino->c_node.i_gid;
 
+       /* FIXME: In the execve case we may on some platforms have space
+          below PROGLOAD to clear... */
+
        /* We are definitely going to succeed with the exec,
         * so we can start writing over the old program
         */
-       uput(buf, PROGBASE, 512);       /* Move 1st Block to user bank */
+       uput(buf, PROGLOAD, 512);       /* Move 1st Block to user bank */
        brelse(buf);
 
-       c = ugetc(PROGBASE);
+       c = ugetc(PROGLOAD);
        if (c != 0xC3)
                kprintf("Botched uput\n");
 
@@ -186,7 +189,7 @@ int16_t _execve(void)
         *  same buffer to avoid cycling our small cache on this. Indirect blocks
         *  will still be cached. - Hat tip to Steve Hosgood's OMU for that trick
         */
-       progptr = PROGBASE + 512;       // we copied the first block already
+       progptr = PROGLOAD + 512;       // we copied the first block already
 
        /* Compute this once otherwise each loop we must recalculate this
           as the compiler isn't entitled to assume the loop didn't change it */
@@ -235,7 +238,7 @@ int16_t _execve(void)
                doexec(emu_base);
        else
 #endif
-               doexec(PROGBASE);
+               doexec(PROGLOAD);
 
        // tidy up in various failure modes:
       nogood3: