execve: per CPU magic, also allow for different program base
authorAlan Cox <alan@etchedpixels.co.uk>
Sun, 23 Nov 2014 22:36:10 +0000 (22:36 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Sun, 23 Nov 2014 22:36:10 +0000 (22:36 +0000)
Use different magic numbers for different CPU types. Note that we need to
pass some kind of base info and check it in future (or support relocatable
binaries ?)

As noted by Atsidaev our handling of some of this was rather confused. We
now pass the size (top - PROGBASE) to the allocator. This sort of assumes for
6502 we'll set 0x0200 (or higher) entry and 0x0000 base and something similar
for 6809.

zx128 will still need a custom banking module eventually. Once someone
beats SDCC into banking the kernel code that can mostly live in 2 (or 3)
16K banks in an interface 2 cartridge with banking support then it can
use 0x8000-0xBFFF and lazy memcpy it from another page (or even exchange
two pages) on a taskswitch between two different 32K apps.

See: http://www.fruitcake.plus.com/Sinclair/Interface2/Cartridges/Interface2_RC_Custom.htm#SoftwarePaging

Kernel/cpu-6502/cpu.h
Kernel/cpu-6809/cpu.h
Kernel/cpu-z80/cpu.h
Kernel/include/kernel.h
Kernel/syscall_exec.c

index 208cb2a..f2cf506 100644 (file)
@@ -20,6 +20,8 @@ extern void *memcpy(void *, void *, size_t);
 extern void *memset(void *, int, size_t);
 extern size_t strlen(const char *);
 
+#define EMAGIC    0x4C    /* Header of executable (JMP) */
+
 #define staticfast     static
 
 /* FIXME: need to add 64bit helper/struct magic for this compiler */
index 13489f1..575896f 100644 (file)
@@ -16,6 +16,7 @@ extern void ei(void);
 extern irqflags_t di(void);
 extern void irqrestore(irqflags_t f);
 
+#define EMAGIC    0x0E    /* Header of executable  (JMP) */
 
 extern void *memcpy(void *, void *, size_t);
 extern void *memset(void *, int, size_t);
index 26697f9..e7774d5 100644 (file)
@@ -16,6 +16,9 @@ typedef uint16_t irqflags_t;
 extern irqflags_t di(void);
 extern void irqrestore(irqflags_t f);
 
+/* Z80 binaries start with a JP */
+#define EMAGIC    0xc3    /* Header of executable */
+
 /* compiler provides optimised versions of these: */
 #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka)
 #define memcpy(dst, src, n) __builtin_memcpy(dst, src, n)
index eadaee6..018923c 100644 (file)
@@ -54,7 +54,6 @@ From UZI by Doug Braun and UZI280 by Stefan Nitschke.
 
 #define NSIGS    32      /* Number of signals <= 32 */
 #define ROOTINODE 1       /* Inode # of / for all mounted filesystems. */
-#define EMAGIC    0xc3    /* Header of executable */
 #define CMAGIC    24721   /* Random number for cinode c_magic */
 #define SMOUNTED  12742   /* Magic number to specify mounted filesystem */
 
index 8e3bf36..2fb54e5 100644 (file)
@@ -58,12 +58,15 @@ int16_t _execve(void)
        /* Read in the first block of the new program */
        buf = bread(ino->c_dev, bmap(ino, 0, 1), 0);
 
-    /****************************************
-     * Get magic number into var magic
-     * C3    : executable file no C/D sep.
-     * 00FF  :     "        "  with C/D sep. (not supported in FUZIX)
-     * other : maybe shell script (nogood2)
-     ****************************************/
+       /* Magic numbers
+               0xC3 xx xx      - Z80 with 0x100 entry
+               0x4C xx xx      - 6502
+               0x0E xx xx      - 6809
+
+          others TBD
+
+          FIXME: need to modify header design to include base addr page
+       */
        if ((*buf & 0xff) != EMAGIC) {
                udata.u_error = ENOEXEC;
                goto nogood2;
@@ -99,7 +102,7 @@ int16_t _execve(void)
        }
 
        /* Binary doesn't fit */
-       if (top < ino->c_node.i_size + 1024) {
+       if (top - PROGBASE < ino->c_node.i_size + 1024) {
                udata.u_error = ENOMEM;
                goto nogood2;
        }
@@ -114,7 +117,7 @@ int16_t _execve(void)
                goto nogood3;   /* SN */
 
        /* This must be the last test as it makes changes if it works */
-       if (pagemap_realloc(top))
+       if (pagemap_realloc(top - PROGBASE))
                goto nogood3;
 
        /* From this point on we are commmited to the exec() completing */