From: Alan Cox Date: Fri, 21 Nov 2014 15:03:32 +0000 (+0000) Subject: syscall_exec: Introduce the notion of both a base and a load address X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7fa7cb94a6141763395376008bd7c3984d0fbff1;p=FUZIX.git syscall_exec: Introduce the notion of both a base and a load address 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 --- diff --git a/Kernel/platform-6502test/config.h b/Kernel/platform-6502test/config.h index b82b50cf..899b284e 100644 --- a/Kernel/platform-6502test/config.h +++ b/Kernel/platform-6502test/config.h @@ -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 */ diff --git a/Kernel/platform-dragon/config.h b/Kernel/platform-dragon/config.h index 41eed1c0..088b4888 100644 --- a/Kernel/platform-dragon/config.h +++ b/Kernel/platform-dragon/config.h @@ -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 */ diff --git a/Kernel/platform-micropack/config.h b/Kernel/platform-micropack/config.h index 614d0a21..43d07a94 100644 --- a/Kernel/platform-micropack/config.h +++ b/Kernel/platform-micropack/config.h @@ -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 */ diff --git a/Kernel/platform-msx1/config.h b/Kernel/platform-msx1/config.h index b70d226b..e902a0b9 100644 --- a/Kernel/platform-msx1/config.h +++ b/Kernel/platform-msx1/config.h @@ -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 */ diff --git a/Kernel/platform-msx2/config.h b/Kernel/platform-msx2/config.h index abc04bd4..8790e83f 100644 --- a/Kernel/platform-msx2/config.h +++ b/Kernel/platform-msx2/config.h @@ -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 */ diff --git a/Kernel/platform-nc100/config.h b/Kernel/platform-nc100/config.h index 5b6d6f36..8027c79c 100644 --- a/Kernel/platform-nc100/config.h +++ b/Kernel/platform-nc100/config.h @@ -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) */ diff --git a/Kernel/platform-pcw8256/config.h b/Kernel/platform-pcw8256/config.h index 91e8d255..5175433f 100644 --- a/Kernel/platform-pcw8256/config.h +++ b/Kernel/platform-pcw8256/config.h @@ -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 */ diff --git a/Kernel/platform-px4plus/config.h b/Kernel/platform-px4plus/config.h index 1e074de6..2f8ffdcc 100644 --- a/Kernel/platform-px4plus/config.h +++ b/Kernel/platform-px4plus/config.h @@ -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) */ diff --git a/Kernel/platform-socz80/config.h b/Kernel/platform-socz80/config.h index 31345392..4a53095d 100644 --- a/Kernel/platform-socz80/config.h +++ b/Kernel/platform-socz80/config.h @@ -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 */ diff --git a/Kernel/platform-trs80/config.h b/Kernel/platform-trs80/config.h index e7fc754d..80629fe5 100644 --- a/Kernel/platform-trs80/config.h +++ b/Kernel/platform-trs80/config.h @@ -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 */ diff --git a/Kernel/platform-z80pack-lite/config.h b/Kernel/platform-z80pack-lite/config.h index 7b5c3e5f..c90b364d 100644 --- a/Kernel/platform-z80pack-lite/config.h +++ b/Kernel/platform-z80pack-lite/config.h @@ -12,10 +12,11 @@ #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 */ diff --git a/Kernel/platform-z80pack/config.h b/Kernel/platform-z80pack/config.h index fa5704ad..161af1fe 100644 --- a/Kernel/platform-z80pack/config.h +++ b/Kernel/platform-z80pack/config.h @@ -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 */ diff --git a/Kernel/start.c b/Kernel/start.c index 0f0fe5d0..d6bff316 100644 --- a/Kernel/start.c +++ b/Kernel/start.c @@ -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) diff --git a/Kernel/syscall_exec.c b/Kernel/syscall_exec.c index b3cf2f5a..e6763b1f 100644 --- a/Kernel/syscall_exec.c +++ b/Kernel/syscall_exec.c @@ -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: