types: rework the types for the BASE/TOP configurations
authorAlan Cox <alan@etchedpixels.co.uk>
Sat, 22 Nov 2014 00:12:34 +0000 (00:12 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Sat, 22 Nov 2014 00:12:34 +0000 (00:12 +0000)
This makes it a fair bit cleaner

24 files changed:
Kernel/include/kernel.h
Kernel/platform-6502test/config.h
Kernel/platform-dragon/config.h
Kernel/platform-micropack/config.h
Kernel/platform-micropack/main.c
Kernel/platform-micropack/z80pack.s
Kernel/platform-msx1/config.h
Kernel/platform-msx1/msx1.s
Kernel/platform-msx2/config.h
Kernel/platform-msx2/msx2.s
Kernel/platform-nc100/config.h
Kernel/platform-pcw8256/config.h
Kernel/platform-trs80/config.h
Kernel/platform-trs80/main.c
Kernel/platform-trs80/trs80.s
Kernel/platform-z80pack/config.h
Kernel/platform-z80pack/main.c
Kernel/platform-zx128/config.h
Kernel/platform-zx128/main.c
Kernel/platform-zx128/zx128.s
Kernel/simple.c
Kernel/single.c
Kernel/start.c
Kernel/syscall_exec.c

index f741d2c..eadaee6 100644 (file)
@@ -554,7 +554,7 @@ COMMON int _uzero(uint8_t *user, usize_t count);
 
 /* platform/tricks.s */
 COMMON void switchout(void);
-COMMON void doexec(void *start_addr);
+COMMON void doexec(uint16_t start_addr);
 COMMON void switchin(ptptr process);
 COMMON int16_t dofork(ptptr child);
 
@@ -701,7 +701,8 @@ CODE2 uint8_t *swapout_prepare_uarea(ptptr p);
 CODE2 uint8_t *swapin_prepare_uarea(ptptr p);
 CODE2 void map_init(void);
 CODE2 void platform_idle(void);
-extern uint8_t *ramtop;             /* Note: ramtop must be in common in some cases */
+/* Will need a uptr_t eventually */
+extern uint16_t ramtop;             /* Note: ramtop must be in common in some cases */
 CODE2 extern void platform_interrupt(void);
 
 CODE2 int16_t __exit(void);        /* FUZIX system call 0 */
index 899b284..8029327 100644 (file)
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#define PROGBASE    ((char *)(0x0200))  /* also data base */
-#define PROGLOAD    ((char *)(0x0200))
-#define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA */
+#define PROGBASE    0x0200  /* also data base */
+#define PROGLOAD    0x0200
+#define PROGTOP     0xF000  /* Top of program, base of U_DATA */
 
-#define BOOT_TTY 3        /* 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 */
                             /* Temp FIXME set to serial port for debug ease */
 
index 088b488..385367f 100644 (file)
@@ -40,9 +40,9 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#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 PROGBASE    0x0000  /* also data base */
+#define PROGLOAD    0x0000  /* also data base */
+#define PROGTOP     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 43d07a9..db5e915 100644 (file)
 #define CONFIG_BANKS   1
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#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 */
+#define PROGBASE    0x0000     /* also data base */
+#define PROGLOAD    0x0100
+#define PROGTOP     0x7D00     /* Top of program, base of U_DATA */
+#define PROC_SIZE   32         /* Memory needed per process */
 
 #define SWAP_SIZE   0x40       /* 32K in blocks (we actually don't need the low 256) */
 #define SWAPBASE    0x0000     /* We swap the lot in one, include the */
index cf1cd2a..0413eca 100644 (file)
@@ -4,7 +4,7 @@
 #include <printf.h>
 #include <devtty.h>
 
-uint8_t *ramtop = PROGTOP;
+uint16_t ramtop = PROGTOP;
 
 /* On idle we spin checking for the terminals. Gives us more responsiveness
    for the polled ports */
index 2952e48..beadff2 100644 (file)
@@ -17,6 +17,7 @@
             .globl init_hardware
             .globl _program_vectors
             .globl _system_tick_counter
+           .globl _kernel_flag
 
            .globl map_kernel
            .globl map_process
@@ -147,3 +148,7 @@ map_restore:
 outchar:
            out (0x01), a
             ret
+
+; needs to be common
+_kernel_flag:
+          .db 1
index e902a0b..5219f2e 100644 (file)
@@ -27,9 +27,9 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 50   /* Ticks per second (actually should be dynamic FIXME) */
-#define PROGBASE    ((char *)(0x0000))  /* also data base */
-#define PROGLOAD    ((char *)(0x0100)) 
-#define PROGTOP     ((char *)(0x7D00))  /* Top of program (uarea stash) */
+#define PROGBASE    0x0000  /* also data base */
+#define PROGLOAD    0x0100 
+#define PROGTOP     0x7D00  /* Top of program (uarea stash) */
 
 #define BOOT_TTY (512 + 1)        /* Set this to default device for stdio, stderr */
                           /* In this case, the default is the first TTY device */
index 61b703b..cb4c85c 100644 (file)
@@ -15,6 +15,7 @@
            .globl map_save
            .globl map_restore
            .globl _slot_table
+           .globl _kernel_flag
 
            ; video driver
            .globl _vtinit
@@ -78,6 +79,10 @@ _trap_reboot:
            di
            halt
 
+_kernel_flag:
+          .db 1
+
+
 ; -----------------------------------------------------------------------------
 ; KERNEL MEMORY BANK (below 0xF000, only accessible when the kernel is mapped)
 ; -----------------------------------------------------------------------------
index 8790e83..f5a0c83 100644 (file)
@@ -24,9 +24,9 @@
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 50   /* Ticks per second (actually should be dynamic FIXME) */
-#define PROGBASE    ((char *)(0x0000))  /* also data base */
-#define PROGLOAD    ((char *)(0x0100))
-#define PROGTOP     ((char *)(0xF000))  /* Top of program, base of U_DATA */
+#define PROGBASE    0x0000  /* also data base */
+#define PROGLOAD    0x0100
+#define PROGTOP     0xF000  /* Top of program, base of U_DATA */
 
 #define BOOT_TTY (512 + 1)        /* Set this to default device for stdio, stderr */
                           /* In this case, the default is the first TTY device */
index b42a506..58efd6c 100644 (file)
@@ -14,6 +14,7 @@
            .globl map_process_always
            .globl map_save
            .globl map_restore
+           .globl _kernel_flag
 
            ; video driver
            .globl _vtinit
@@ -78,6 +79,9 @@ _trap_reboot:
            di
            halt
 
+_kernel_flag:
+           .db 1
+
 ; -----------------------------------------------------------------------------
 ; KERNEL MEMORY BANK (below 0xF000, only accessible when the kernel is mapped)
 ; -----------------------------------------------------------------------------
index 8027c79..fd35a20 100644 (file)
@@ -1,6 +1,10 @@
 /* NC100 or NC200 - your choice */
 #define CONFIG_NC200
 
+#ifdef CONFIG_NC200
+#define CONFIG_CPM_EMU
+#endif
+
 /* Enable to make ^Z dump the inode table for debug */
 #undef CONFIG_IDUMP
 /* Enable to make ^A drop back into the monitor */
 #endif
 
 #define TICKSPERSEC 100   /* Ticks per second */
-#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) */
+#define PROGBASE    0x0000     /* also data base */
+#define PROGLOAD    0x0100
+#define PROGTOP     0xF000     /* Top of program, base of U_DATA */
 
 #define BOOT_TTY (512+1)  /* Set this to default device for stdio, stderr */
                           /* In this case, the default is the first TTY device */
index 5175433..e652afa 100644 (file)
@@ -8,6 +8,8 @@
 #define CONFIG_MULTI
 /* Single tasking */
 #undef CONFIG_SINGLETASK
+/* CPM emulation capable */
+#define CONFIG_CPM_EMU
 /* 16K reported page size */
 #define CONFIG_PAGE_SIZE       16
 /* We use flexible 16K banks so use the helper */
 #define VT_BOTTOM      31
 
 #define TICKSPERSEC 50   /* Ticks per second */
-#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 */
+#define PROGBASE    0x0000     /* memory base of program */
+#define PROGLOAD    0x0100     /* load base of program */
+#define PROGTOP     0xF000     /* Top of program, base of U_DATA */
+#define PROC_SIZE   64         /* Memory needed per process */
 
 #define SWAP_SIZE   0x80       /* 64K in blocks (we actually don't need the low 256) */
 #define SWAPBASE    0x0000     /* We swap the lot in one, include the */
index 80629fe..b0f385e 100644 (file)
@@ -23,9 +23,9 @@
 #define VT_BOTTOM      24
 
 #define TICKSPERSEC 60   /* Ticks per second */
-#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 PROGBASE    0x0000  /* Base of user  */
+#define PROGLOAD    0x0100  /* Load and run here */
+#define PROGTOP     0xF900  /* Top of program, base of U_DATA */
 #define PROC_SIZE   64   /* Memory needed per process */
 
 #define SWAP_SIZE   0x80       /* 64K in blocks (we actually don't need quite all) */
index 7ba957b..1859ec1 100644 (file)
@@ -4,7 +4,7 @@
 #include <printf.h>
 #include <devtty.h>
 
-uint8_t *ramtop = PROGTOP;
+uint16_t ramtop = PROGTOP;
 
 /* On idle we spin checking for the terminals. Gives us more responsiveness
    for the polled ports */
index 3672603..6247f35 100644 (file)
@@ -16,6 +16,7 @@
            .globl map_save
            .globl map_restore
            .globl platform_interrupt_all
+           .globl _kernel_flag
 
             ; exported debugging tools
             .globl _trap_monitor
@@ -120,6 +121,8 @@ opsave:         .db 0x36
 _opreg:            .db 0x36    ; kernel map, 80 columns
 _modout:    .db 0x50   ; 80 column, sound enabled, altchars off,
                        ; external I/O enabled, 4MHz
+_kernel_flag:
+           .db 1       ; We start in kernel mode
 
 _program_vectors:
             ; we are called, with interrupts disabled, by both newproc() and crt0
index 161af1f..e66238d 100644 (file)
@@ -20,9 +20,9 @@
 #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 PROGLOAD    0x0000  /* also data base */
+#define PROGBASE    0x0100  /* also data base */
+#define PROGTOP     0xED00  /* Top of program, base of U_DATA copy */
 #define PROC_SIZE   60   /* Memory needed per process */
 
 #define SWAP_SIZE   0x78       /* 60K in blocks (we actually don't need the low 256) */
index 1567072..79c9de0 100644 (file)
@@ -4,7 +4,7 @@
 #include <printf.h>
 #include <devtty.h>
 
-uint8_t *ramtop = PROGTOP;
+uint16_t ramtop = PROGTOP;
 
 
 void pagemap_init(void)
index 5efb322..68e75db 100644 (file)
@@ -17,7 +17,9 @@
 #define CONFIG_FONT8X8
 #define CONFIG_FONT8X8SMALL
 
-/* We have 1 bank at C000 with 6 possible pages to map, but I'm not sure if CONFIG_BANK_FIXED is our choise. */
+/* We have 1 bank at C000 with 6 possible pages to map, but I'm not sure
+   if CONFIG_BANK_FIXED is our choice. */
+
 /* Fixed banking */
 #define CONFIG_BANK_FIXED
 /* 6 16K banks, 1 is for kernel needs */
 #define VT_BOTTOM      23
 
 #define TICKSPERSEC 50   /* Ticks per second */
-#define PROGBASE    ((char *)(0xC000))  /* also data base */
-#define PROGTOP     ((char *)(0xFFFF))  /* Top of program, base of U_DATA copy */
+#define PROGBASE    0xC000  /* also data base */
+#define PROGLOAD    0xC000  /* also data base */
+#define PROGTOP     0xFD00  /* Top of program, base of U_DATA copy */
 #define PROC_SIZE   16   /* Memory needed per process */
 
 #define UDATA_BLOCKS   0       /* We swap the stash not the uarea */
 #define UDATA_SWAPSIZE 0
 
-#define BOOT_TTY (1)      /* Set this to default device for stdio, stderr */
+#define BOOT_TTY (512+1)  /* 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 1567072..79c9de0 100644 (file)
@@ -4,7 +4,7 @@
 #include <printf.h>
 #include <devtty.h>
 
-uint8_t *ramtop = PROGTOP;
+uint16_t ramtop = PROGTOP;
 
 
 void pagemap_init(void)
index 6167657..766ee4e 100644 (file)
@@ -25,6 +25,8 @@
         .globl map_save
         .globl map_restore
 
+       .globl _kernel_flag
+
         .globl _fd_bankcmd
 
         ; exported debugging tools
@@ -170,3 +172,6 @@ map_store:
 outchar:
         out (#0x15), A
         ret
+
+_kernel_flag:
+       .db 1
index 81a7a66..5df4d0d 100644 (file)
@@ -22,14 +22,14 @@ int pagemap_alloc(ptptr p)
 
 int pagemap_realloc(uint16_t size)
 {
-  if (size >= (uint16_t) ramtop)
+  if (size >= ramtop)
     return ENOMEM;
   return 0;
 }
 
 uint16_t pagemap_mem_used(void)
 {
-  return ((uint16_t)(PROGTOP - PROGBASE)) >> 10;
+  return (PROGTOP - PROGBASE) >> 10;
 }
 
 void pagemap_init(void)
index a8bf9fb..585bb7d 100644 (file)
@@ -127,7 +127,7 @@ static int count(uint8_t ** sp, uint16_t * lp)
 
 static int do_swap_out(uint8_t * s, uint16_t l)
 {
-       uint8_t *p = ramtop - 1;
+       uint8_t *p = (uint8_t *)(ramtop - 1);
 
 //  Xpanic("do_swap_out ");
 //  Xout((uint16_t)s);
@@ -164,10 +164,10 @@ static int do_swap_out(uint8_t * s, uint16_t l)
        *p-- = (uint16_t) ramtop >> 8;
        *p = (uint16_t) ramtop & 0xFF;
 //  Xpanic("Ramtop was ");
-//  Xout((uint16_t)ramtop);
-       ramtop = p;
+//  Xout(ramtop);
+       ramtop = (uint16_t)p;
 //  Xpanic(" now ");
-//  Xout((uint16_t)ramtop);
+//  Xout(ramtop);
 //  Xpanic("\r\n");
        s;
        l;
@@ -212,7 +212,9 @@ static void unpack(uint8_t * d, uint8_t * p, uint16_t l)
 
 static void do_swap_in(uint8_t * d, uint16_t l)
 {
-       uint8_t *p = (uint8_t *) (ramtop[0] | (((uint16_t) ramtop[1]) << 8));   /* Recover old base pointer */
+       uint8_t *p;
+       p = (uint8_t *) ramtop;
+       p = (uint8_t *) (p[0] | (((uint16_t) p[1]) << 8));      /* Recover old base pointer */
 //  Xout(ramtop[1]);
 //  Xout(ramtop[2]);
 //  Xpanic("Entry Ramtop: ");
@@ -220,7 +222,7 @@ static void do_swap_in(uint8_t * d, uint16_t l)
 //  Xpanic("New Ramtop: ");
 //  Xout((uint16_t)p);
        unpack(d, p, l);
-       ramtop = p;
+       ramtop = (uint16_t)p;
 //  Xpanic("\r\n");
 }
 #endif
@@ -233,7 +235,7 @@ static void Xmemcpy(uint8_t * d, uint8_t * s, uint16_t l)
 
 static int do_swap_out(uint8_t * p, uint16_t l)
 {
-       uint16_t room = (uint16_t) ramtop - udata.u_top;
+       uint16_t room = ramtop - udata.u_top;
        uint8_t *d;
 
        Xpanic("len ");
@@ -244,7 +246,7 @@ static int do_swap_out(uint8_t * p, uint16_t l)
                return -1;
        ramtop -= l + 2;
        Xpanic("ramtop now ");
-       Xout((uint16_t) ramtop);
+       Xout(ramtop);
        d = (uint8_t *) ramtop;
        d[0] = l & 0xFF;
        d[1] = l >> 8;
@@ -269,7 +271,7 @@ static void do_swap_in(uint8_t * d, uint16_t l)
 
 int swapout(ptptr p)
 {
-       uint8_t *oldtop = ramtop;
+       uint16_t oldtop = ramtop;
        p;
 //  Xpanic("Swapout");
 //  Xout((uint16_t)udata.u_ptab);
index d6bff31..abb490d 100644 (file)
@@ -62,14 +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, PROGLOAD, sizeof(arg));
+       uput(arg, (void *)PROGLOAD, sizeof(arg));
        /* Poke in arv[0] - FIXME: Endianisms...  */
-       uputw((uint16_t)PROGLOAD + 1, PROGLOAD + 7);
+       uputw(PROGLOAD+1 , (void *)(PROGLOAD + 7));
 
        /* Set up things to look like the process is calling _execve() */
-       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) */
+       udata.u_argn = PROGLOAD;
+       udata.u_argn1 = PROGLOAD + 0x7; /* Arguments (just "/init") */
+       udata.u_argn2 = PROGLOAD + 0xb; /* Environment (none) */
 }
 
 void fuzix_main(void)
index e6763b1..8e3bf36 100644 (file)
@@ -35,13 +35,13 @@ int16_t _execve(void)
        staticfast struct s_argblk *abuf, *ebuf;
        int16_t (**sigp) ();
        int argc;
-       uint16_t emu_size, emu_copy;
-       uint8_t *progptr, *emu_ptr, *emu_base;
+       uint16_t emu_size, emu_copy, progptr;
+       uint16_t emu_ptr, emu_base;
        staticfast uint16_t top;
        uint8_t c;
        uint16_t blocks;
 
-       top = (uint16_t)ramtop;
+       top = ramtop;
 
        if (!(ino = n_open(name, NULLINOPTR)))
                return (-1);
@@ -76,7 +76,7 @@ int16_t _execve(void)
        if (buf[3] == 'F' && buf[4] == 'Z' && buf[5] == 'X' && buf[6] == '1') {
                top = buf[7] | ((unsigned int)buf[8] << 8);
                if (top == 0)   /* Legacy 'all space' binary */
-                       top = (uint16_t)ramtop;
+                       top = ramtop;
                emu_ino = 0;    // no emulation, thanks
        } else {
 #ifdef CONFIG_CPM_EMU
@@ -88,7 +88,7 @@ int16_t _execve(void)
                        udata.u_error = ENOEXEC;
                        goto nogood2;
                }
-               top = (uint16_t)ramtop;
+               top = ramtop;
 #else
                emu_size;
                emu_copy;
@@ -133,10 +133,10 @@ int16_t _execve(void)
        /* We are definitely going to succeed with the exec,
         * so we can start writing over the old program
         */
-       uput(buf, PROGLOAD, 512);       /* Move 1st Block to user bank */
+       uput(buf, (uint8_t *)PROGLOAD, 512);    /* Move 1st Block to user bank */
        brelse(buf);
 
-       c = ugetc(PROGLOAD);
+       c = ugetc((uint8_t *)PROGLOAD);
        if (c != 0xC3)
                kprintf("Botched uput\n");
 
@@ -150,15 +150,14 @@ int16_t _execve(void)
        if (emu_ino) {
                emu_size = emu_ino->c_node.i_size;
                // round up to nearest multiple of 256 bytes, fit it in below ramtop
-               emu_ptr =
-                   (char *) (udata.u_top - ((emu_size + 255) & 0xff00));
+               emu_ptr = udata.u_top - ((emu_size + 255) & 0xff00);
                emu_base = emu_ptr;
                blk = 0;
 
                while (emu_size) {
                        buf = bread(emu_ino->c_dev, bmap(emu_ino, blk, 1), 0);  // read block
                        emu_copy = min(512, emu_size);
-                       uput(buf, emu_ptr, emu_copy);   // copy to userspace
+                       uput(buf, (uint8_t *)emu_ptr, emu_copy);        // copy to userspace
                        bufdiscard((bufptr) buf);
                        brelse((bufptr) buf);   // release block
                        // adjust pointers
@@ -174,11 +173,11 @@ int16_t _execve(void)
                 * of process memory
                 */
 
-               uzero(emu_ptr, top - emu_ptr);
+               uzero((uint8_t *)emu_ptr, top - emu_ptr);
        } else
 #endif
        {
-               emu_base = (uint8_t *)top;
+               emu_base = top;
        }
 
        /* emu_base now points at the byte after the last byte the program can occupy */
@@ -197,7 +196,7 @@ int16_t _execve(void)
 
        for (blk = 1; blk <= blocks; ++blk) {
                buf = bread(ino->c_dev, bmap(ino, blk, 1), 0);
-               uput(buf, progptr, 512);
+               uput(buf, (uint8_t *)progptr, 512);
                bufdiscard((bufptr) buf);
                brelse((bufptr) buf);
                progptr += 512;
@@ -206,7 +205,7 @@ int16_t _execve(void)
        udata.u_break = (int) progptr;  //  Set initial break for program
 
        // zero all remaining process memory above the last block loaded.
-       uzero(progptr, emu_base - progptr);
+       uzero((uint8_t *)progptr, emu_base - progptr);
 
        // Turn off caught signals
        for (sigp = udata.u_sigvec; sigp < udata.u_sigvec + NSIGS; ++sigp)